Skip to content

Commit

Permalink
ics: PollForProposalStatus for 25 blocks (from 10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 7, 2024
1 parent d38c1cc commit 1604e2e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
23 changes: 0 additions & 23 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"math/rand"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 40 additions & 6 deletions chain/cosmos/ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1604e2e

Please sign in to comment.