Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use submit-legacy-proposal for consumer additions #1236

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 55 additions & 14 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
volumetypes "github.com/docker/docker/api/types/volume"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/tidwall/sjson"
"go.uber.org/zap"
"golang.org/x/mod/semver"
"golang.org/x/sync/errgroup"
Expand All @@ -43,6 +44,7 @@ import (

icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
"github.com/strangelove-ventures/interchaintest/v8/blockdb"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand Down Expand Up @@ -883,24 +885,63 @@ func (tn *ChainNode) SendIBCTransfer(
}

func (tn *ChainNode) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (string, error) {
propBz, err := json.Marshal(prop)
if err != nil {
return "", err
}
cosmosChain := (tn.Chain).(*CosmosChain)
if !tn.HasCommand(ctx, "tx", "gov", "submit-legacy-proposal", "consumer-addition") {
authority, err := cosmosChain.GetGovernanceAddress(ctx)
if err != nil {
return "", err
}
ccvProp := &providertypes.MsgConsumerAddition{
ChainId: prop.ChainId,
InitialHeight: prop.InitialHeight,
GenesisHash: prop.GenesisHash,
BinaryHash: prop.BinaryHash,
SpawnTime: prop.SpawnTime,
UnbondingPeriod: prop.UnbondingPeriod,
CcvTimeoutPeriod: prop.CcvTimeoutPeriod,
TransferTimeoutPeriod: prop.TransferTimeoutPeriod,
ConsumerRedistributionFraction: prop.ConsumerRedistributionFraction,
BlocksPerDistributionTransmission: prop.BlocksPerDistributionTransmission,
HistoricalEntries: prop.HistoricalEntries,
DistributionTransmissionChannel: prop.DistributionTransmissionChannel,
Top_N: prop.TopN,
ValidatorsPowerCap: prop.ValidatorsPowerCap,
ValidatorSetCap: prop.ValidatorSetCap,
Allowlist: prop.Allowlist,
Denylist: prop.Denylist,
Authority: authority,
AllowInactiveVals: prop.AllowInactiveVals,
MinStake: prop.MinStake,
}
propObj, err := cosmosChain.BuildProposal([]ProtoMessage{ccvProp}, prop.Title, prop.Summary, "ipfs://CID", prop.Deposit, "", false)
if err != nil {
return "", err
}
return tn.SubmitProposal(ctx, keyName, propObj)
} else {
propBz, err := json.Marshal(prop)
if err != nil {
return "", err
}
propBz, err = sjson.SetBytes(propBz, "metadata", "ipfs://CID")
if err != nil {
return "", err
}

fileName := "proposal_" + dockerutil.RandLowerCaseLetterString(4) + ".json"
fileName := "proposal_" + dockerutil.RandLowerCaseLetterString(4) + ".json"

fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName)
if err := fw.WriteFile(ctx, tn.VolumeName, fileName, propBz); err != nil {
return "", fmt.Errorf("failure writing proposal json: %w", err)
}
fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName)
if err := fw.WriteFile(ctx, tn.VolumeName, fileName, propBz); err != nil {
return "", fmt.Errorf("failure writing proposal json: %w", err)
}

filePath := filepath.Join(tn.HomeDir(), fileName)
filePath := filepath.Join(tn.HomeDir(), fileName)

return tn.ExecTx(ctx, keyName,
"gov", "submit-legacy-proposal", "consumer-addition", filePath,
"--gas", "auto",
)
return tn.ExecTx(ctx, keyName,
"gov", "submit-legacy-proposal", "consumer-addition", filePath,
"--gas", "auto",
)
}
}

func (tn *ChainNode) GetTransaction(clientCtx client.Context, txHash string) (*sdk.TxResponse, error) {
Expand Down
4 changes: 4 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ func (c *CosmosChain) GetGasFeesInNativeDenom(gasPaid int64) int64 {
return int64(math.Ceil(fees))
}

func (c *CosmosChain) ChangeBinary(ctx context.Context, binary string) {
c.cfg.Bin = binary
}

func (c *CosmosChain) UpgradeVersion(ctx context.Context, cli *client.Client, containerRepo, version string) {
c.cfg.Images[0].Version = version
for _, n := range c.Validators {
Expand Down
20 changes: 17 additions & 3 deletions chain/cosmos/ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi
return err
}

consumerID := c.cfg.ChainID
consumerChains, _, err := c.Provider.GetNode().ExecQuery(ctx, "provider", "list-consumer-chains")
if err != nil {
return err
}
consumerChain := gjson.GetBytes(consumerChains, fmt.Sprintf("chains.#(chain_id=%q)", c.cfg.ChainID))
if consumerChain.Get("consumer_id").Exists() {
consumerID = consumerChain.Get("consumer_id").String()
}

// Copy provider priv val keys to these nodes
for i, val := range c.Provider.Validators {
i := i
Expand All @@ -265,7 +275,7 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi
return fmt.Errorf("failed to get consumer validator pubkey: %w", err)
}
keyStr := strings.TrimSpace(string(key))
_, err = c.Provider.Validators[i].ExecTx(ctx, valKey, "provider", "assign-consensus-key", c.cfg.ChainID, keyStr)
_, err = c.Provider.Validators[i].ExecTx(ctx, valKey, "provider", "assign-consensus-key", consumerID, keyStr)
if err != nil {
return fmt.Errorf("failed to assign consumer validator pubkey: %w", err)
}
Expand All @@ -289,7 +299,11 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi
if err != nil {
return fmt.Errorf("failed to query proposed chains: %w", err)
}
spawnTime := gjson.GetBytes(proposals, fmt.Sprintf("proposals.#(messages.0.content.chain_id==%q).messages.0.content.spawn_time", c.cfg.ChainID)).Time()
msgContent := gjson.GetBytes(proposals, fmt.Sprintf("proposals.#(messages.0.content.chain_id==%q).messages.0.content", c.cfg.ChainID))
if !msgContent.Exists() {
msgContent = gjson.GetBytes(proposals, fmt.Sprintf("proposals.#(messages.0.value.chain_id==%q).messages.0.value", c.cfg.ChainID))
}
spawnTime := msgContent.Get("spawn_time").Time()
c.log.Info("Waiting for chain to spawn", zap.Time("spawn_time", spawnTime), zap.String("chain_id", c.cfg.ChainID))
time.Sleep(time.Until(spawnTime))
if err := testutil.WaitForBlocks(ctx, 2, c.Provider); err != nil {
Expand All @@ -309,7 +323,7 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi
return err
}

ccvStateMarshaled, _, err := c.Provider.GetNode().ExecQuery(ctx, "provider", "consumer-genesis", c.cfg.ChainID)
ccvStateMarshaled, _, err := c.Provider.GetNode().ExecQuery(ctx, "provider", "consumer-genesis", consumerID)
if err != nil {
return fmt.Errorf("failed to query provider for ccv state: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion chain/cosmos/module_gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (tn *ChainNode) UpgradeProposal(ctx context.Context, keyName string, prop S
},
}

proposal, err := cosmosChain.BuildProposal([]ProtoMessage{&msg}, prop.Title, prop.Description, "", prop.Deposit, prop.Proposer, prop.Expedited)
proposal, err := cosmosChain.BuildProposal([]ProtoMessage{&msg}, prop.Title, prop.Description, "ipfs://CID", prop.Deposit, prop.Proposer, prop.Expedited)
if err != nil {
return "", err
}
Expand Down
5 changes: 3 additions & 2 deletions examples/ibc/ics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
"golang.org/x/mod/semver"
)

var (
icsVersions = []string{"v3.1.0", "v3.3.0", "v4.0.0"}
icsVersions = []string{"v3.1.0", "v3.3.0", "v4.0.0", "v5.0.0"}
vals = 2
fNodes = 0
providerChainID = "provider-1"
Expand Down Expand Up @@ -60,7 +61,7 @@ func icsTest(t *testing.T, version string, rly ibc.RelayerImplementation) {
ctx := context.Background()

consumerBechPrefix := "cosmos"
if version == "v4.0.0" {
if semver.Compare(version, "v4.0.0") >= 0 {
consumerBechPrefix = "consumer"
}

Expand Down
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.2
replace (
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0
github.com/cosmos/interchain-security/v5 => github.com/cosmos/interchain-security/v5 v5.0.0-20240806104629-29327696b8e6
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7
)
Expand All @@ -24,10 +25,10 @@ require (
github.com/cometbft/cometbft v0.38.10
github.com/cosmos/cosmos-sdk v0.50.8
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.5.0
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.3.2
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74
github.com/cosmos/ibc-go/v8 v8.4.0
github.com/cosmos/interchain-security/v5 v5.0.0-20240806104629-29327696b8e6
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.1
github.com/docker/docker v24.0.9+incompatible
Expand All @@ -47,13 +48,14 @@ require (
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
github.com/tidwall/gjson v1.17.3
github.com/tidwall/sjson v1.2.5
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.24.0
golang.org/x/mod v0.18.0
golang.org/x/mod v0.20.0
golang.org/x/sync v0.7.0
golang.org/x/tools v0.22.0
google.golang.org/grpc v1.65.0
Expand All @@ -71,9 +73,9 @@ require (
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/x/evidence v0.1.0 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
cosmossdk.io/x/tx v0.13.4 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
Expand All @@ -92,7 +94,6 @@ require (
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/datadriven v1.0.3-0.20230801171734-e384cf455877 // indirect
Expand All @@ -101,7 +102,7 @@ require (
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/cometbft/cometbft-db v0.12.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
Expand All @@ -119,9 +120,8 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -148,11 +148,12 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down Expand Up @@ -228,15 +229,15 @@ require (
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
Expand All @@ -251,7 +252,7 @@ require (
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand All @@ -261,11 +262,11 @@ require (
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
Expand Down
Loading