diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 88c01468b..25d1b71b1 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -17,8 +17,6 @@ import ( "time" sdkmath "cosmossdk.io/math" - abcitypes "github.com/cometbft/cometbft/abci/types" - crypto "github.com/cometbft/cometbft/proto/tendermint/crypto" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -32,11 +30,7 @@ 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" - commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" - ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" - ccvconsumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client" - ccvprovidertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" dockertypes "github.com/docker/docker/api/types" volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" @@ -1267,75 +1261,16 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi } } - providerHeight, err := c.Provider.Height(ctx) - if err != nil { - return fmt.Errorf("failed to query provider height") - } - providerHeightInt64 := int64(providerHeight) - - block, err := c.Provider.getFullNode().Client.Block(ctx, &providerHeightInt64) - if err != nil { - return fmt.Errorf("failed to query provider block to initialize consumer client") - } - genbz, err := validator0.GenesisFileContent(ctx) if err != nil { return err } - nextValidatorsHash := block.Block.NextValidatorsHash - timestamp := block.Block.Time - rootHash := block.Block.AppHash - - page := int(1) - perPage := int(1000) - providerVals, err := c.Provider.getFullNode().Client.Validators(ctx, &providerHeightInt64, &page, &perPage) + ccvStateMarshaled, _, err := c.Provider.GetNode().ExecQuery(ctx, "provider", "consumer-genesis", c.cfg.ChainID) if err != nil { - return fmt.Errorf("failed to get provider validators: %w", err) + return fmt.Errorf("failed to query provider for ccv state: %w", err) } - initialVals := make([]abcitypes.ValidatorUpdate, len(providerVals.Validators)) - for i, val := range providerVals.Validators { - initialVals[i] = abcitypes.ValidatorUpdate{ - PubKey: crypto.PublicKey{Sum: &crypto.PublicKey_Ed25519{Ed25519: val.PubKey.Bytes()}}, - Power: val.VotingPower, - } - } - - providerCfg := c.Provider.Config() - - clientState := ibctmtypes.NewClientState( - providerCfg.ChainID, - ibctmtypes.DefaultTrustLevel, - DefaultProviderUnbondingPeriod/2, - DefaultProviderUnbondingPeriod, // Needs to match provider unbonding period - ccvprovidertypes.DefaultMaxClockDrift, - clienttypes.Height{ - RevisionHeight: uint64(providerHeight), - RevisionNumber: clienttypes.ParseChainID(providerCfg.ChainID), - }, - commitmenttypes.GetSDKSpecs(), - defaultUpgradePath, - ) - - root := commitmenttypes.MerkleRoot{ - Hash: rootHash, - } - - consensusState := ibctmtypes.NewConsensusState(timestamp, root, nextValidatorsHash) - - ccvState := ccvconsumertypes.NewInitialGenesisState( - clientState, - consensusState, - initialVals, - ccvconsumertypes.DefaultGenesisState().GetParams(), - ) - - ccvState.Params.Enabled = true - - ccvStateMarshaled, err := c.cfg.EncodingConfig.Codec.MarshalJSON(ccvState) - c.log.Info("BEFORE MIGRATION!", zap.String("GEN", string(ccvStateMarshaled))) - consumerICS := c.GetNode().ICSVersion(ctx) providerICS := c.Provider.GetNode().ICSVersion(ctx) ccvStateMarshaled, err = c.transformCCVState(ctx, ccvStateMarshaled, consumerICS, providerICS, chainCfg.InterchainSecurityConfig) diff --git a/examples/ibc/ics_test.go b/examples/ibc/ics_test.go index 4bd2b34a9..4b7b710c8 100644 --- a/examples/ibc/ics_test.go +++ b/examples/ibc/ics_test.go @@ -87,25 +87,23 @@ func TestICS(t *testing.T) { }) require.NoError(t, err, "failed to build interchain") - // err = testutil.WaitForBlocks(ctx, 5, provider, consumer) - // require.NoError(t, err, "failed to wait for blocks") - // get provider node stakingVals, err := provider.StakingQueryValidators(ctx, stakingttypes.BondStatusBonded) require.NoError(t, err) - valOne := stakingVals[0] + + providerVal := stakingVals[0] denom := provider.Config().Denom // Perform validator delegation // The delegation must be >1,000,000 utoken as this is = 1 power in tendermint. t.Run("perform provider delegation to complete channel to the consumer", func(t *testing.T) { - beforeDel, err := provider.StakingQueryDelegationsTo(ctx, valOne.OperatorAddress) + beforeDel, err := provider.StakingQueryDelegationsTo(ctx, providerVal.OperatorAddress) require.NoError(t, err) - err = provider.GetNode().StakingDelegate(ctx, "validator", valOne.OperatorAddress, fmt.Sprintf("1000000%s", denom)) + err = provider.GetNode().StakingDelegate(ctx, "validator", providerVal.OperatorAddress, fmt.Sprintf("1000000%s", denom)) require.NoError(t, err, "failed to delegate from validator") - afterDel, err := provider.StakingQueryDelegationsTo(ctx, valOne.OperatorAddress) + afterDel, err := provider.StakingQueryDelegationsTo(ctx, providerVal.OperatorAddress) require.NoError(t, err) require.Greater(t, afterDel[0].Balance.Amount.Int64(), beforeDel[0].Balance.Amount.Int64()) })