From 1604e2e4ced05468e9f95e5441b0d5ae5e98b9fe Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Wed, 7 Aug 2024 16:48:33 -0500 Subject: [PATCH] ics: `PollForProposalStatus` for 25 blocks (from 10) --- chain/cosmos/chain_node.go | 23 ------------------ chain/cosmos/cosmos_chain.go | 11 --------- chain/cosmos/ics.go | 46 +++++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 5b3e5fb7e..337048cad 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -11,7 +11,6 @@ import ( "math/rand" "os" "path" - "path/filepath" "strconv" "strings" "sync" @@ -42,7 +41,6 @@ import ( "google.golang.org/grpc/credentials/insecure" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client" "github.com/strangelove-ventures/interchaintest/v8/blockdb" "github.com/strangelove-ventures/interchaintest/v8/dockerutil" "github.com/strangelove-ventures/interchaintest/v8/ibc" @@ -894,27 +892,6 @@ func (tn *ChainNode) SendIBCTransfer( return tn.ExecTx(ctx, keyName, command...) } -func (tn *ChainNode) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (string, error) { - propBz, err := json.Marshal(prop) - if err != nil { - return "", err - } - - 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) - } - - filePath := filepath.Join(tn.HomeDir(), fileName) - - 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) { // Retry because sometimes the tx is not committed to state yet. var txResp *sdk.TxResponse diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 75287c3f6..99b1a99db 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -26,7 +26,6 @@ import ( paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // nolint:staticcheck chanTypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client" dockertypes "github.com/docker/docker/api/types" volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" @@ -128,7 +127,6 @@ func (c *CosmosChain) WithPreStartNodes(preStartNodes func(*CosmosChain)) { c.preStartNodes = preStartNodes } - // GetCodec returns the codec for the chain. func (c *CosmosChain) GetCodec() *codec.ProtoCodec { return c.cdc @@ -505,15 +503,6 @@ func (c *CosmosChain) QueryBankMetadata(ctx context.Context, denom string) (*Ban return c.getFullNode().QueryBankMetadata(ctx, denom) } -// ConsumerAdditionProposal submits a legacy governance proposal to add a consumer to the chain. -func (c *CosmosChain) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (tx TxProposal, _ error) { - txHash, err := c.getFullNode().ConsumerAdditionProposal(ctx, keyName, prop) - if err != nil { - return tx, fmt.Errorf("failed to submit consumer addition proposal: %w", err) - } - return c.txProposal(txHash) -} - func (c *CosmosChain) txProposal(txHash string) (tx TxProposal, _ error) { txResp, err := c.GetTransaction(txHash) if err != nil { diff --git a/chain/cosmos/ics.go b/chain/cosmos/ics.go index c6743dbf9..9b65d05f1 100644 --- a/chain/cosmos/ics.go +++ b/chain/cosmos/ics.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path" + "path/filepath" "strconv" "strings" "time" @@ -83,6 +84,36 @@ func (c *CosmosChain) FinishICSProviderSetup(ctx context.Context, r ibc.Relayer, return c.FlushPendingICSPackets(ctx, r, eRep, ibcPath) } +// ConsumerAdditionProposal submits a legacy governance proposal to add a consumer to the chain. +func (c *CosmosChain) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (tx TxProposal, _ error) { + txHash, err := c.getFullNode().ConsumerAdditionProposal(ctx, keyName, prop) + if err != nil { + return tx, fmt.Errorf("failed to submit consumer addition proposal: %w", err) + } + return c.txProposal(txHash) +} + +func (tn *ChainNode) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (string, error) { + propBz, err := json.Marshal(prop) + if err != nil { + return "", err + } + + 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) + } + + filePath := filepath.Join(tn.HomeDir(), fileName) + + return tn.ExecTx(ctx, keyName, + "gov", "submit-legacy-proposal", "consumer-addition", filePath, + "--gas", "auto", + ) +} + // FlushPendingICSPackets flushes the pending ICS packets to the consumer chain from the "provider" port. func (c *CosmosChain) FlushPendingICSPackets(ctx context.Context, r ibc.Relayer, eRep *testreporter.RelayerExecReporter, ibcPath string) error { channels, err := r.GetChannels(ctx, eRep, c.cfg.ChainID) @@ -196,7 +227,7 @@ func (c *CosmosChain) StartProvider(testName string, ctx context.Context, additi return err } - _, err = PollForProposalStatus(ctx, c, height, height+10, propID, govv1beta1.StatusPassed) + _, err = PollForProposalStatus(ctx, c, height, height+25, propID, govv1beta1.StatusPassed) if err != nil { return fmt.Errorf("proposal status did not change to passed in expected number of blocks: %w", err) } @@ -292,9 +323,12 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi spawnTime := gjson.GetBytes(proposals, fmt.Sprintf("proposals.#(messages.0.content.chain_id==%q).messages.0.content.spawn_time", c.cfg.ChainID)).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 { - return err - } + // TODO: do we need? + // if err := testutil.WaitForBlocks(ctx, 2, c.Provider); err != nil { + // return err + // } + + c.log.Info("Exec") validator0 := c.Validators[0] @@ -405,8 +439,8 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi return err } - // Wait for 5 blocks before considering the chains "started" - return testutil.WaitForBlocks(ctx, 5, c.getFullNode()) + // Wait for 2 blocks before considering the chains "started" + return testutil.WaitForBlocks(ctx, 2, c.getFullNode()) } func (c *CosmosChain) transformCCVState(ctx context.Context, ccvState []byte, consumerVersion, providerVersion string, icsCfg ibc.ICSConfig) ([]byte, error) {