diff --git a/CHANGELOG.md b/CHANGELOG.md index a876b3a9fe9..0bd77bc57eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (light-clients/06-solomachine) [\#6888](https://github.com/cosmos/ibc-go/pull/6888) Remove `TypeClientMisbehaviour` constant and the `Type` method on `Misbehaviour`. * (light-clients/06-solomachine, light-clients/07-tendermint) [\#6891](https://github.com/cosmos/ibc-go/pull/6891) The `VerifyMembership` and `VerifyNonMembership` functions of solomachine's `ClientState` have been made private. The `VerifyMembership`, `VerifyNonMembership`, `GetTimestampAtHeight`, `Status` and `Initialize` functions of tendermint's `ClientState` have been made private. * (core/04-channel) [\#6902](https://github.com/cosmos/ibc-go/pull/6902) Add channel version to core application callbacks. +* (core/03-connection, core/02-client) [\#6937](https://github.com/cosmos/ibc-go/pull/6937) Remove 'ConsensusHost' interface, also removing self client and consensus state validation in the connection handshake. * (core/24-host) [\#6882](https://github.com/cosmos/ibc-go/issues/6882) All functions ending in `Path` have been removed from 24-host in favour of their sybling functions ending in `Key`. ### State Machine Breaking diff --git a/docs/docs/01-ibc/02-integration.md b/docs/docs/01-ibc/02-integration.md index 9d6142a7e6c..5af103bdf6e 100644 --- a/docs/docs/01-ibc/02-integration.md +++ b/docs/docs/01-ibc/02-integration.md @@ -98,7 +98,6 @@ func NewApp(...args) *App { appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), - ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index 68f0cd912d1..2d6af42cda7 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -17,6 +17,7 @@ There are four sections based on the four potential user groups of this document - [API removals](#api-removals) - [02-client](#02-client) - [03-connection](#03-connection) + - [Removal of self client and consensus state from connection handshake](#removal-of-self-client-and-consensus-state-from-connection-handshake) - [04-channel](#04-channel) - [05-port](#05-port) - [23-commitment](#23-commitment) @@ -57,6 +58,17 @@ govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). ## IBC core +- Because the self client and consensus state validation has been removed from the connection handshake (see section [Removal of self client and consensus state from connection handshake](#removal-of-self-client-and-consensus-state-from-connection-handshake) for more details), the IBC core keeper does not need the staking keeper anymore to introspect the (self) past historical info at a given height and construct the expected consensus state at that height. Thus, the signature of IBC core keeper constructor function `NewKeeper` has been updated: + +```diff +func NewKeeper( + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace, +- stakingKeeper clienttypes.StakingKeeper, + upgradeKeeper clienttypes.UpgradeKeeper, + scopedKeeper capabilitykeeper.ScopedKeeper, authority string, +) *Keeper +``` + ### API removals - The [`exported.ChannelI`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/exported/channel.go#L3-L11) and [`exported.CounterpartyChannelI`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/exported/channel.go#L13-L19) interfaces have been removed. Please use the concrete types. @@ -64,6 +76,7 @@ govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). - The [`Router` reference](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/keeper/keeper.go#L35) has been removed from the IBC core keeper in [#6138](https://github.com/cosmos/ibc-go/pull/6138). Please use `PortKeeper.Router` instead. - The [composite interface `QueryServer`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/types/query.go#L14-L19) has been removed from package `core/types`. Please use the granular `QueryServer` interfaces for IBC submodules directly. - The [`TypeClientMisbehaviour` constant](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/exported/client.go#L17) has been removed. +- The function [`SetConsensusHost`](https://github.com/cosmos/ibc-go/blob/v8.3.0/modules/core/keeper/keeper.go#L88-L96) has been removed because the self client and consensus state validation has been removed from the connection handshake. See section [Removal of self client and consensus state from connection handshake](#removal-of-self-client-and-consensus-state-from-connection-handshake) for more details. ### 02-client @@ -71,12 +84,52 @@ govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). - The function [`CreateLocalhostClient`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/02-client/keeper/keeper.go#L56) has been removed. The localhost client is now stateless. - The function [`NewClientProposalHandler`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/02-client/proposal_handler.go#L18) has been removed in [#6777](https://github.com/cosmos/ibc-go/pull/6777). - The deprecated [`ClientUpdateProposal` and `UpgradeProposal` messages](https://github.com/cosmos/ibc-go/blob/v8.0.0/proto/ibc/core/client/v1/client.proto#L67-L113) have been removed in [\#6782](https://github.com/cosmos/ibc-go/pull/6782). Please use [`MsgRecoverClient`](https://github.com/cosmos/ibc-go/blob/release/v9.0.x/proto/ibc/core/client/v1/tx.proto#L125-L138) and [`MsgIBCSoftwareUpgrade`](https://github.com/cosmos/ibc-go/blob/release/v9.0.x/proto/ibc/core/client/v1/tx.proto#L143-L158) respectively instead. +- Because the self client and consensus state validation has been removed from the connection handshake (see section [Removal of self client and consensus state from connection handshake](#removal-of-self-client-and-consensus-state-from-connection-handshake) for more details): + - The [ConsensusHost interface](https://github.com/cosmos/ibc-go/blob/v8.3.0/modules/core/02-client/types/client.go#L25-L29) has been removed. + - The function [`SetConsensusHost`](https://github.com/cosmos/ibc-go/blob/v8.3.0/modules/core/02-client/keeper/keeper.go#L61-L68) has been removed. + - The functions [`GetSelfConsensusState` and `ValidateSelfClient`](https://github.com/cosmos/ibc-go/blob/v8.3.0/modules/core/02-client/keeper/keeper.go#L256-L269) have been removed. ### 03-connection - The [functions `GetState()`, `GetClientID()`, `GetCounterparty()`, `GetVersions()`, and `GetDelayPeriod()`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/03-connection/types/connection.go#L25-L48) of the `Connection` type have been removed. - The [functions `GetClientID()`, `GetConnectionID()`, and `GetPrefix()`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/03-connection/types/connection.go#L79-L92) of the `Counterparty` type have been removed. +#### Removal of self client and consensus state from connection handshake + +The `ConnectionOpenTry` and `ConnectionOpenAck` handlers no longer validate that the light client on counterparty chain has a valid representation of the executing chain's consensus protocol (please see [#1128](https://github.com/cosmos/ibc/pull/1128) in cosmos/ibc repository for an exhaustive explanation of the reasoning). + +- The fields `client_state`, `proof_client`, `proof_consensus`, `consensus_height` and `host_consensus_state_proof` of `MsgConnectionOpenTry` and `MsgConnectionOpenAck` have been deprecated, and the signature of the constructor functions [`NewMsgConnectionOpenTry`](https://github.com/cosmos/ibc-go/blob/release/v9.0.x/modules/core/03-connection/types/msgs.go#L78) and [`NewMsgConnectionOpenTry`](https://github.com/cosmos/ibc-go/blob/release/v9.0.x/modules/core/03-connection/types/msgs.go#L165) has been accordingly updated: + +```diff +func NewMsgConnectionOpenTry( + clientID, counterpartyConnectionID, counterpartyClientID string, +- counterpartyClient exported.ClientState, + counterpartyPrefix commitmenttypes.MerklePrefix, + counterpartyVersions []*Version, delayPeriod uint64, + initProof []byte, +- clientProof []byte, +- consensusProof []byte, + proofHeight lienttypes.Height, +- consensusHeight clienttypes.Height, + signer string, +) *MsgConnectionOpenTry + +func NewMsgConnectionOpenAck( + connectionID, counterpartyConnectionID string, +- counterpartyClient exported.ClientState, + tryProof []byte, +- clientProof []byte, +- consensusProof []byte, + proofHeight clienttypes.Height, +- consensusHeight clienttypes.Height, + version *Version, + signer string, +) *MsgConnectionOpenAck +``` + +- The functions [`VerifyClientState` and `VerifyClientConsensusState`](https://github.com/cosmos/ibc-go/blob/v8.3.0/modules/core/03-connection/keeper/verify.go#L20-L101) have been removed. +- The function [`UnpackInterfaces`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/03-connection/types/msgs.go#L166) has been removed. + ### 04-channel - The utility function [`QueryLatestConsensusState`](https://github.com/cosmos/ibc-go/blob/v8.0.0/modules/core/04-channel/client/utils/utils.go#L130) of the CLI has been removed. @@ -375,6 +428,19 @@ func AssertEvents( clientQueryServer := clientkeeper.NewQueryServer(app.IBCKeeper.ClientKeeper) ``` +- The signature of the function `QueryConnectionHandshakeProof` has changed, since the validation of self client and consensus state has been remove from the connection handshake: + +```diff +func (endpoint *Endpoint) QueryConnectionHandshakeProof() ( +- clientState exported.ClientState, clientProof, +- consensusProof []byte, consensusHeight clienttypes.Height, + connectionProof []byte, proofHeight clienttypes.Height, +) +``` + +- The functions [`GenerateClientStateProof` and `GenerateConsensusStateProof`](https://github.com/cosmos/ibc-go/blob/v8.0.0/testing/solomachine.go#L513-L547) +have been removed. + ### API deprecation notice - The testing package functions `Setup`, `SetupClients`, `SetupConnections`, `CreateConnections`, and `CreateChannels` of the `Coordinator` type have been deprecated and will be removed in v10. Please use the new functions `Setup`, `SetupClients`, `SetupConnections`, `CreateConnections`, `CreateChannels` of the `Path` type. diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index 9a89526745e..931a51ce690 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -405,7 +405,7 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) // NOTE: The mock ContractKeeper is only created for testing. diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 02bc0e9e18f..4f551220a7e 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -27,13 +27,12 @@ type Keeper struct { storeKey storetypes.StoreKey cdc codec.BinaryCodec router *types.Router - consensusHost types.ConsensusHost legacySubspace types.ParamSubspace upgradeKeeper types.UpgradeKeeper } // NewKeeper creates a new NewKeeper instance -func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, consensusHost types.ConsensusHost, uk types.UpgradeKeeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, uk types.UpgradeKeeper) *Keeper { router := types.NewRouter() localhostModule := localhost.NewLightClientModule(cdc, key) router.AddRoute(exported.Localhost, localhostModule) @@ -42,7 +41,6 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace ty storeKey: key, cdc: cdc, router: router, - consensusHost: consensusHost, legacySubspace: legacySubspace, upgradeKeeper: uk, } @@ -90,15 +88,6 @@ func (k *Keeper) Route(ctx sdk.Context, clientID string) (exported.LightClientMo return clientModule, nil } -// SetConsensusHost sets a custom ConsensusHost for self client state and consensus state validation. -func (k *Keeper) SetConsensusHost(consensusHost types.ConsensusHost) { - if consensusHost == nil { - panic(errors.New("cannot set a nil self consensus host")) - } - - k.consensusHost = consensusHost -} - // GenerateClientIdentifier returns the next client identifier. func (k *Keeper) GenerateClientIdentifier(ctx sdk.Context, clientType string) string { nextClientSeq := k.GetNextClientSequence(ctx) @@ -315,21 +304,6 @@ func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) return k.GetClientConsensusState(ctx, clientID, clientModule.LatestHeight(ctx, clientID)) } -// GetSelfConsensusState introspects the (self) past historical info at a given height -// and returns the expected consensus state at that height. -// For now, can only retrieve self consensus states for the current revision -func (k *Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - return k.consensusHost.GetSelfConsensusState(ctx, height) -} - -// ValidateSelfClient validates the client parameters for a client of the running chain. -// This function is only used to validate the client state the counterparty stores for this chain. -// NOTE: If the client type is not of type Tendermint then delegate to a custom client validator function. -// This allows support for non-Tendermint clients, for example 08-wasm clients. -func (k *Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { - return k.consensusHost.ValidateSelfClient(ctx, clientState) -} - // VerifyMembership retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height. func (k *Keeper) VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error { clientModule, err := k.Route(ctx, clientID) diff --git a/modules/core/02-client/types/client.go b/modules/core/02-client/types/client.go index 993f43d570a..6e3df24694e 100644 --- a/modules/core/02-client/types/client.go +++ b/modules/core/02-client/types/client.go @@ -11,7 +11,6 @@ import ( errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -22,12 +21,6 @@ var ( _ codectypes.UnpackInterfacesMessage = (*ConsensusStateWithHeight)(nil) ) -// ConsensusHost defines an interface used to validate an IBC ClientState and ConsensusState against the host chain's underlying consensus parameters. -type ConsensusHost interface { - GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) - ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error -} - // NewIdentifiedClientState creates a new IdentifiedClientState instance func NewIdentifiedClientState(clientID string, clientState exported.ClientState) IdentifiedClientState { msg, ok := clientState.(proto.Message) diff --git a/modules/core/02-client/types/expected_keepers.go b/modules/core/02-client/types/expected_keepers.go index ed4caa5e881..914dfd080f8 100644 --- a/modules/core/02-client/types/expected_keepers.go +++ b/modules/core/02-client/types/expected_keepers.go @@ -2,21 +2,13 @@ package types import ( "context" - "time" upgradetypes "cosmossdk.io/x/upgrade/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// StakingKeeper expected staking keeper -type StakingKeeper interface { - GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error) - UnbondingTime(ctx context.Context) (time.Duration, error) -} - // UpgradeKeeper expected upgrade keeper type UpgradeKeeper interface { GetUpgradePlan(ctx context.Context) (plan upgradetypes.Plan, err error) diff --git a/modules/core/03-connection/keeper/events_test.go b/modules/core/03-connection/keeper/events_test.go index 8c718da8545..43ceaacdbd7 100644 --- a/modules/core/03-connection/keeper/events_test.go +++ b/modules/core/03-connection/keeper/events_test.go @@ -48,13 +48,12 @@ func (suite *KeeperTestSuite) TestMsgConnectionOpenTryEvents() { suite.Require().NoError(path.EndpointB.UpdateClient()) - counterpartyClient, clientProof, consensusProof, consensusHeight, initProof, proofHeight := path.EndpointB.QueryConnectionHandshakeProof() + initProof, proofHeight := path.EndpointB.QueryConnectionHandshakeProof() msg := types.NewMsgConnectionOpenTry( path.EndpointB.ClientID, path.EndpointB.Counterparty.ConnectionID, path.EndpointB.Counterparty.ClientID, - counterpartyClient, path.EndpointB.Counterparty.Chain.GetPrefix(), []*types.Version{ibctesting.ConnectionVersion}, path.EndpointB.ConnectionConfig.DelayPeriod, - initProof, clientProof, consensusProof, - proofHeight, consensusHeight, + path.EndpointB.Counterparty.Chain.GetPrefix(), []*types.Version{ibctesting.ConnectionVersion}, + path.EndpointB.ConnectionConfig.DelayPeriod, initProof, proofHeight, path.EndpointB.Chain.SenderAccount.GetAddress().String(), ) @@ -88,13 +87,11 @@ func (suite *KeeperTestSuite) TestMsgConnectionOpenAckEvents() { suite.Require().NoError(path.EndpointA.UpdateClient()) - counterpartyClient, clientProof, consensusProof, consensusHeight, tryProof, proofHeight := path.EndpointA.QueryConnectionHandshakeProof() + tryProof, proofHeight := path.EndpointA.QueryConnectionHandshakeProof() msg := types.NewMsgConnectionOpenAck( - path.EndpointA.ConnectionID, path.EndpointA.Counterparty.ConnectionID, counterpartyClient, - tryProof, clientProof, consensusProof, - proofHeight, consensusHeight, - ibctesting.ConnectionVersion, + path.EndpointA.ConnectionID, path.EndpointA.Counterparty.ConnectionID, + tryProof, proofHeight, ibctesting.ConnectionVersion, path.EndpointA.Chain.SenderAccount.GetAddress().String(), ) diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index e43733e4ed9..1e646b787e3 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -9,7 +9,6 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -67,37 +66,13 @@ func (k *Keeper) ConnOpenTry( counterparty types.Counterparty, // counterpartyConnectionIdentifier, counterpartyPrefix and counterpartyClientIdentifier delayPeriod uint64, clientID string, // clientID of chainA - clientState exported.ClientState, // clientState that chainA has for chainB counterpartyVersions []*types.Version, // supported versions of chain A initProof []byte, // proof that chainA stored connectionEnd in state (on ConnOpenInit) - clientProof []byte, // proof that chainA stored a light client of chainB - consensusProof []byte, // proof that chainA stored chainB's consensus state at consensus height proofHeight exported.Height, // height at which relayer constructs proof of A storing connectionEnd in state - consensusHeight exported.Height, // latest height of chain B which chain A has stored in its chain B client ) (string, error) { // generate a new connection connectionID := k.GenerateConnectionIdentifier(ctx) - // check that the consensus height the counterparty chain is using to store a representation - // of this chain's consensus state is at a height in the past - selfHeight := clienttypes.GetSelfHeight(ctx) - if consensusHeight.GTE(selfHeight) { - return "", errorsmod.Wrapf( - ibcerrors.ErrInvalidHeight, - "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, - ) - } - - // validate client parameters of a chainB client stored on chainA - if err := k.clientKeeper.ValidateSelfClient(ctx, clientState); err != nil { - return "", err - } - - expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) - if err != nil { - return "", errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) - } - // expectedConnection defines Chain A's ConnectionEnd // NOTE: chain A's counterparty is chain B (i.e where this code is executed) // NOTE: chainA and chainB must have the same delay period @@ -124,18 +99,6 @@ func (k *Keeper) ConnOpenTry( return "", err } - // Check that ChainA stored the clientState provided in the msg - if err := k.VerifyClientState(ctx, connection, proofHeight, clientProof, clientState); err != nil { - return "", err - } - - // Check that ChainA stored the correct ConsensusState of chainB at the given consensusHeight - if err := k.VerifyClientConsensusState( - ctx, connection, proofHeight, consensusHeight, consensusProof, expectedConsensusState, - ); err != nil { - return "", err - } - // store connection in chainB state if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { return "", errorsmod.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID) @@ -158,25 +121,11 @@ func (k *Keeper) ConnOpenTry( func (k *Keeper) ConnOpenAck( ctx sdk.Context, connectionID string, - clientState exported.ClientState, // client state for chainA on chainB version *types.Version, // version that ChainB chose in ConnOpenTry counterpartyConnectionID string, tryProof []byte, // proof that connectionEnd was added to ChainB state in ConnOpenTry - clientProof []byte, // proof of client state on chainB for chainA - consensusProof []byte, // proof that chainB has stored ConsensusState of chainA on its client proofHeight exported.Height, // height that relayer constructed proofTry - consensusHeight exported.Height, // latest height of chainA that chainB has stored on its chainA client ) error { - // check that the consensus height the counterparty chain is using to store a representation - // of this chain's consensus state is at a height in the past - selfHeight := clienttypes.GetSelfHeight(ctx) - if consensusHeight.GTE(selfHeight) { - return errorsmod.Wrapf( - ibcerrors.ErrInvalidHeight, - "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, - ) - } - // Retrieve connection connection, found := k.GetConnection(ctx, connectionID) if !found { @@ -199,17 +148,6 @@ func (k *Keeper) ConnOpenAck( ) } - // validate client parameters of a chainA client stored on chainB - if err := k.clientKeeper.ValidateSelfClient(ctx, clientState); err != nil { - return err - } - - // Retrieve chainA's consensus state at consensusheight - expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) - if err != nil { - return errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) - } - prefix := k.GetCommitmentPrefix() expectedCounterparty := types.NewCounterparty(connection.ClientId, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes())) expectedConnection := types.NewConnectionEnd(types.TRYOPEN, connection.Counterparty.ClientId, expectedCounterparty, []*types.Version{version}, connection.DelayPeriod) @@ -222,18 +160,6 @@ func (k *Keeper) ConnOpenAck( return err } - // Check that ChainB stored the clientState provided in the msg - if err := k.VerifyClientState(ctx, connection, proofHeight, clientProof, clientState); err != nil { - return err - } - - // Ensure that ChainB has stored the correct ConsensusState for chainA at the consensusHeight - if err := k.VerifyClientConsensusState( - ctx, connection, proofHeight, consensusHeight, consensusProof, expectedConsensusState, - ); err != nil { - return err - } - k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", types.INIT, "new-state", types.OPEN) defer telemetry.IncrCounter(1, "ibc", "connection", "open-ack") diff --git a/modules/core/03-connection/keeper/handshake_test.go b/modules/core/03-connection/keeper/handshake_test.go index f697a2cf27a..e233c68fbe3 100644 --- a/modules/core/03-connection/keeper/handshake_test.go +++ b/modules/core/03-connection/keeper/handshake_test.go @@ -3,15 +3,9 @@ package keeper_test import ( "time" - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" - "github.com/cosmos/ibc-go/v9/modules/core/exported" - ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" - "github.com/cosmos/ibc-go/v9/testing/mock" ) // TestConnOpenInit - chainA initializes (INIT state) a connection with @@ -97,11 +91,9 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { // connection on chainA is INIT func (suite *KeeperTestSuite) TestConnOpenTry() { var ( - path *ibctesting.Path - delayPeriod uint64 - versions []*types.Version - consensusHeight exported.Height - counterpartyClient exported.ClientState + path *ibctesting.Path + delayPeriod uint64 + versions []*types.Version ) testCases := []struct { @@ -112,9 +104,6 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { {"success", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) }, true}, {"success with delay period", func() { err := path.EndpointA.ConnOpenInit() @@ -129,111 +118,22 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { suite.coordinator.CommitBlock(suite.chainA) err = path.EndpointB.UpdateClient() suite.Require().NoError(err) - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) }, true}, - {"invalid counterparty client", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - - // Set an invalid client of chainA on chainB - tmClient, ok := counterpartyClient.(*ibctm.ClientState) - suite.Require().True(ok) - tmClient.ChainId = "wrongchainid" - - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID, tmClient) - }, false}, - {"consensus height >= latest height", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - - consensusHeight = clienttypes.GetSelfHeight(suite.chainB.GetContext()) - }, false}, - {"self consensus state not found", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - - consensusHeight = clienttypes.NewHeight(0, 1) - }, false}, {"counterparty versions is empty", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - versions = nil }, false}, {"counterparty versions don't have a match", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - version := types.NewVersion("0.0", nil) versions = []*types.Version{version} }, false}, {"connection state verification failed", func() { // chainA connection not created - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - }, false}, - {"client state verification failed", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - - // modify counterparty client without setting in store so it still passes validate but fails proof verification - tmClient, ok := counterpartyClient.(*ibctm.ClientState) - suite.Require().True(ok) - tmClient.LatestHeight, ok = tmClient.LatestHeight.Increment().(clienttypes.Height) - suite.Require().True(ok) - }, false}, - {"consensus state verification failed", func() { - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - - // give chainA wrong consensus state for chainB - consState, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetLatestClientConsensusState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - tmConsState, ok := consState.(*ibctm.ConsensusState) - suite.Require().True(ok) - - tmConsState.Timestamp = time.Now() - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState(suite.chainA.GetContext(), path.EndpointA.ClientID, path.EndpointA.GetClientLatestHeight(), tmConsState) - - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - }, false}, - {"override self consensus host", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainA to pass as counterpartyClient - counterpartyClient = suite.chainA.GetClientState(path.EndpointA.ClientID) - - mockValidator := mock.ConsensusHost{ - ValidateSelfClientFn: func(ctx sdk.Context, clientState exported.ClientState) error { - return mock.MockApplicationCallbackError - }, - } - - suite.chainB.App.GetIBCKeeper().SetConsensusHost(&mockValidator) }, false}, } @@ -241,10 +141,9 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { tc := tc suite.Run(tc.msg, func() { - suite.SetupTest() // reset - consensusHeight = clienttypes.ZeroHeight() // may be changed in malleate - versions = types.GetCompatibleVersions() // may be changed in malleate - delayPeriod = 0 // may be changed in malleate + suite.SetupTest() // reset + versions = types.GetCompatibleVersions() // may be changed in malleate + delayPeriod = 0 // may be changed in malleate path = ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupClients() @@ -259,22 +158,9 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { connectionKey := host.ConnectionKey(path.EndpointA.ConnectionID) initProof, proofHeight := suite.chainA.QueryProof(connectionKey) - if consensusHeight.IsZero() { - // retrieve consensus state height to provide proof for - consensusHeight = path.EndpointA.GetClientLatestHeight() - } - - consensusKey := host.FullConsensusStateKey(path.EndpointA.ClientID, consensusHeight) - consensusProof, _ := suite.chainA.QueryProof(consensusKey) - - // retrieve proof of counterparty clientstate on chainA - clientKey := host.FullClientStateKey(path.EndpointA.ClientID) - clientProof, _ := suite.chainA.QueryProof(clientKey) - connectionID, err := suite.chainB.App.GetIBCKeeper().ConnectionKeeper.ConnOpenTry( - suite.chainB.GetContext(), counterparty, delayPeriod, path.EndpointB.ClientID, counterpartyClient, - versions, initProof, clientProof, consensusProof, - proofHeight, consensusHeight, + suite.chainB.GetContext(), counterparty, delayPeriod, path.EndpointB.ClientID, + versions, initProof, proofHeight, ) if tc.expPass { @@ -292,10 +178,8 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { // the initialization (TRYINIT) of the connection on Chain B (ID #2). func (suite *KeeperTestSuite) TestConnOpenAck() { var ( - path *ibctesting.Path - consensusHeight exported.Height - version *types.Version - counterpartyClient exported.ClientState + path *ibctesting.Path + version *types.Version ) testCases := []struct { @@ -309,57 +193,20 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) }, true}, - {"invalid counterparty client", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - err = path.EndpointB.ConnOpenTry() - suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - - // Set an invalid client of chainA on chainB - tmClient, ok := counterpartyClient.(*ibctm.ClientState) - suite.Require().True(ok) - tmClient.ChainId = "wrongchainid" - - suite.chainB.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainB.GetContext(), path.EndpointB.ClientID, tmClient) - }, false}, - {"consensus height >= latest height", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - - err = path.EndpointB.ConnOpenTry() - suite.Require().NoError(err) - - consensusHeight = clienttypes.GetSelfHeight(suite.chainA.GetContext()) - }, false}, {"connection not found", func() { // connections are never created - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) }, false}, {"invalid counterparty connection ID", func() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) // modify connB to set counterparty connection identifier to wrong identifier - path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.Counterparty.ConnectionId = "badconnectionid" }) + path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.Counterparty.ConnectionId = ibctesting.InvalidID }) + path.EndpointB.ConnectionID = ibctesting.InvalidID err = path.EndpointA.UpdateClient() suite.Require().NoError(err) @@ -372,9 +219,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) @@ -386,9 +230,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) @@ -398,9 +239,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) @@ -411,9 +249,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) @@ -423,69 +258,15 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) version = types.NewVersion(types.DefaultIBCVersionIdentifier, []string{"ORDER_ORDERED", "ORDER_UNORDERED", "ORDER_DAG"}) }, false}, - {"self consensus state not found", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - - err = path.EndpointB.ConnOpenTry() - suite.Require().NoError(err) - - consensusHeight = clienttypes.NewHeight(0, 1) - }, false}, {"connection state verification failed", func() { // chainB connection is not in INIT err := path.EndpointA.ConnOpenInit() suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - }, false}, - {"client state verification failed", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - - // modify counterparty client without setting in store so it still passes validate but fails proof verification - tmClient, ok := counterpartyClient.(*ibctm.ClientState) - suite.Require().True(ok) - tmClient.LatestHeight, ok = tmClient.LatestHeight.Increment().(clienttypes.Height) - suite.Require().True(ok) - - err = path.EndpointB.ConnOpenTry() - suite.Require().NoError(err) - }, false}, - {"consensus state verification failed", func() { - err := path.EndpointA.ConnOpenInit() - suite.Require().NoError(err) - - // retrieve client state of chainB to pass as counterpartyClient - counterpartyClient = suite.chainB.GetClientState(path.EndpointB.ClientID) - - // give chainB wrong consensus state for chainA - consState, found := suite.chainB.App.GetIBCKeeper().ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), path.EndpointB.ClientID) - suite.Require().True(found) - - tmConsState, ok := consState.(*ibctm.ConsensusState) - suite.Require().True(ok) - - tmConsState.Timestamp = tmConsState.Timestamp.Add(time.Second) - suite.chainB.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState(suite.chainB.GetContext(), path.EndpointB.ClientID, path.EndpointB.GetClientLatestHeight(), tmConsState) - - err = path.EndpointB.ConnOpenTry() - suite.Require().NoError(err) }, false}, } @@ -494,7 +275,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { suite.Run(tc.msg, func() { suite.SetupTest() // reset version = types.GetCompatibleVersions()[0] // must be explicitly changed in malleate - consensusHeight = clienttypes.ZeroHeight() // must be explicitly changed in malleate path = ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupClients() @@ -507,20 +287,9 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { connectionKey := host.ConnectionKey(path.EndpointB.ConnectionID) tryProof, proofHeight := suite.chainB.QueryProof(connectionKey) - if consensusHeight.IsZero() { - // retrieve consensus state height to provide proof for - consensusHeight = path.EndpointB.GetClientLatestHeight() - } - consensusKey := host.FullConsensusStateKey(path.EndpointB.ClientID, consensusHeight) - consensusProof, _ := suite.chainB.QueryProof(consensusKey) - - // retrieve proof of counterparty clientstate on chainA - clientKey := host.FullClientStateKey(path.EndpointB.ClientID) - clientProof, _ := suite.chainB.QueryProof(clientKey) - err = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.ConnOpenAck( - suite.chainA.GetContext(), path.EndpointA.ConnectionID, counterpartyClient, version, path.EndpointB.ConnectionID, - tryProof, clientProof, consensusProof, proofHeight, consensusHeight, + suite.chainA.GetContext(), path.EndpointA.ConnectionID, version, + path.EndpointB.ConnectionID, tryProof, proofHeight, ) if tc.expPass { diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 34db455dc10..a46f4cf0a99 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -15,79 +15,6 @@ import ( "github.com/cosmos/ibc-go/v9/modules/core/exported" ) -// VerifyClientState verifies a proof of a client state of the running machine -// stored on the target machine -func (k *Keeper) VerifyClientState( - ctx sdk.Context, - connection types.ConnectionEnd, - height exported.Height, - proof []byte, - clientState exported.ClientState, -) error { - clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - - merklePath := commitmenttypes.NewMerklePath(host.FullClientStateKey(connection.Counterparty.ClientId)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) - if err != nil { - return err - } - - bz, err := k.cdc.MarshalInterface(clientState) - if err != nil { - return err - } - - if err := k.clientKeeper.VerifyMembership( - ctx, clientID, height, - 0, 0, // skip delay period checks for non-packet processing verification - proof, merklePath, bz, - ); err != nil { - return errorsmod.Wrapf(err, "failed client state verification for target client: %s", clientID) - } - - return nil -} - -// VerifyClientConsensusState verifies a proof of the consensus state of the -// specified client stored on the target machine. -func (k *Keeper) VerifyClientConsensusState( - ctx sdk.Context, - connection types.ConnectionEnd, - height exported.Height, - consensusHeight exported.Height, - proof []byte, - consensusState exported.ConsensusState, -) error { - clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - - merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStateKey(connection.Counterparty.ClientId, consensusHeight)) - merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) - if err != nil { - return err - } - - bz, err := k.cdc.MarshalInterface(consensusState) - if err != nil { - return err - } - - if err := k.clientKeeper.VerifyMembership( - ctx, clientID, height, - 0, 0, // skip delay period checks for non-packet processing verification - proof, merklePath, bz, - ); err != nil { - return errorsmod.Wrapf(err, "failed consensus state verification for client (%s)", clientID) - } - - return nil -} - // VerifyConnectionState verifies a proof of the connection state of the // specified connection end stored on the target machine. func (k *Keeper) VerifyConnectionState( diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index c3e2e02a2de..4177aebbbce 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -16,142 +16,6 @@ import ( var defaultTimeoutHeight = clienttypes.NewHeight(1, 100000) -// TestVerifyClientState verifies a client state of chainA -// stored on path.EndpointB (which is on chainB) -func (suite *KeeperTestSuite) TestVerifyClientState() { - var ( - path *ibctesting.Path - heightDiff uint64 - ) - cases := []struct { - name string - malleate func() - expPass bool - }{ - {"verification success", func() {}, true}, - {"client state not found", func() { - path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, - {"consensus state for proof height not found", func() { - heightDiff = 5 - }, false}, - {"verification failed", func() { - counterpartyClient, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) - suite.Require().True(ok) - counterpartyClient.ChainId = "wrongChainID" - path.EndpointB.SetClientState(counterpartyClient) - }, false}, - {"client status is not active - client is expired", func() { - clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) - suite.Require().True(ok) - clientState.FrozenHeight = clienttypes.NewHeight(0, 1) - path.EndpointA.SetClientState(clientState) - }, false}, - } - - for _, tc := range cases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - heightDiff = 0 // must be explicitly changed - - path = ibctesting.NewPath(suite.chainA, suite.chainB) - path.SetupConnections() - - tc.malleate() - - counterpartyClient, clientProof := path.EndpointB.QueryClientStateProof() - proofHeight := clienttypes.NewHeight(1, uint64(suite.chainB.GetContext().BlockHeight()-1)) - - connection := path.EndpointA.GetConnection() - - err := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.VerifyClientState( - suite.chainA.GetContext(), connection, - malleateHeight(proofHeight, heightDiff), clientProof, counterpartyClient, - ) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - }) - } -} - -// TestVerifyClientConsensusState verifies that the consensus state of -// chainA stored on path.EndpointB.ClientID (which is on chainB) matches the consensus -// state for chainA at that height. -func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { - var ( - path *ibctesting.Path - heightDiff uint64 - ) - cases := []struct { - name string - malleate func() - expPass bool - }{ - {"verification success", func() {}, true}, - {"client state not found", func() { - path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID }) - }, false}, - {"consensus state not found", func() { - heightDiff = 5 - }, false}, - {"verification failed", func() { - // give chainB wrong consensus state for chainA - consState, found := suite.chainB.App.GetIBCKeeper().ClientKeeper.GetLatestClientConsensusState(suite.chainB.GetContext(), path.EndpointB.ClientID) - suite.Require().True(found) - - tmConsState, ok := consState.(*ibctm.ConsensusState) - suite.Require().True(ok) - - tmConsState.Timestamp = time.Now() - suite.chainB.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState(suite.chainB.GetContext(), path.EndpointB.ClientID, path.EndpointB.GetClientLatestHeight(), tmConsState) - - suite.coordinator.CommitBlock(suite.chainB) - }, false}, - {"client status is not active - client is expired", func() { - clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) - suite.Require().True(ok) - clientState.FrozenHeight = clienttypes.NewHeight(0, 1) - path.EndpointA.SetClientState(clientState) - }, false}, - } - - for _, tc := range cases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - heightDiff = 0 // must be explicitly changed in malleate - path = ibctesting.NewPath(suite.chainA, suite.chainB) - path.SetupConnections() - - tc.malleate() - - connection := path.EndpointA.GetConnection() - proof, consensusHeight := suite.chainB.QueryConsensusStateProof(path.EndpointB.ClientID) - proofHeight := clienttypes.NewHeight(1, uint64(suite.chainB.GetContext().BlockHeight()-1)) - consensusState, err := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetSelfConsensusState(suite.chainA.GetContext(), consensusHeight) - suite.Require().NoError(err) - - err = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.VerifyClientConsensusState( - suite.chainA.GetContext(), connection, - malleateHeight(proofHeight, heightDiff), consensusHeight, proof, consensusState, - ) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - }) - } -} - // TestVerifyConnectionState verifies the connection state of the connection // on chainB. The connections on chainA and chainB are fully opened. func (suite *KeeperTestSuite) TestVerifyConnectionState() { diff --git a/modules/core/03-connection/types/connection_test.go b/modules/core/03-connection/types/connection_test.go index 0bfae042558..ba88f05b8e9 100644 --- a/modules/core/03-connection/types/connection_test.go +++ b/modules/core/03-connection/types/connection_test.go @@ -12,7 +12,6 @@ import ( ) var ( - chainID = "gaiamainnet" connectionID = "connection-0" clientID = "clientidone" connectionID2 = "connectionidtwo" diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index a0eb8ccb71f..ff13cf0d742 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -12,8 +12,6 @@ type ClientKeeper interface { GetClientStatus(ctx sdk.Context, clientID string) exported.Status GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) - GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) - ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index 79a741d3429..ed69c34bcf8 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -3,7 +3,6 @@ package types import ( errorsmod "cosmossdk.io/errors" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -25,9 +24,6 @@ var ( _ sdk.HasValidateBasic = (*MsgConnectionOpenAck)(nil) _ sdk.HasValidateBasic = (*MsgConnectionOpenTry)(nil) _ sdk.HasValidateBasic = (*MsgUpdateParams)(nil) - - _ codectypes.UnpackInterfacesMessage = (*MsgConnectionOpenTry)(nil) - _ codectypes.UnpackInterfacesMessage = (*MsgConnectionOpenAck)(nil) ) // NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance. It sets the @@ -77,25 +73,18 @@ func (msg MsgConnectionOpenInit) ValidateBasic() error { // NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance func NewMsgConnectionOpenTry( clientID, counterpartyConnectionID, counterpartyClientID string, - counterpartyClient exported.ClientState, counterpartyPrefix commitmenttypes.MerklePrefix, counterpartyVersions []*Version, delayPeriod uint64, - initProof, clientProof, consensusProof []byte, - proofHeight, consensusHeight clienttypes.Height, signer string, + initProof []byte, proofHeight clienttypes.Height, signer string, ) *MsgConnectionOpenTry { counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix) - protoAny, _ := clienttypes.PackClientState(counterpartyClient) return &MsgConnectionOpenTry{ ClientId: clientID, - ClientState: protoAny, Counterparty: counterparty, CounterpartyVersions: counterpartyVersions, DelayPeriod: delayPeriod, ProofInit: initProof, - ProofClient: clientProof, - ProofConsensus: consensusProof, ProofHeight: proofHeight, - ConsensusHeight: consensusHeight, Signer: signer, } } @@ -106,9 +95,6 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { return errorsmod.Wrap(clienttypes.ErrInvalidClientType, "localhost connection handshakes are disallowed") } - if msg.PreviousConnectionId != "" { - return errorsmod.Wrap(ErrInvalidConnectionIdentifier, "previous connection identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") - } if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { return errorsmod.Wrap(err, "invalid client ID") } @@ -116,16 +102,6 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(msg.Counterparty.ConnectionId); err != nil { return errorsmod.Wrap(err, "invalid counterparty connection ID") } - if msg.ClientState == nil { - return errorsmod.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") - } - clientState, err := clienttypes.UnpackClientState(msg.ClientState) - if err != nil { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) - } - if err := clientState.Validate(); err != nil { - return errorsmod.Wrap(err, "counterparty client is invalid") - } if len(msg.CounterpartyVersions) == 0 { return errorsmod.Wrap(ibcerrors.ErrInvalidVersion, "empty counterparty versions") } @@ -140,55 +116,28 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { if len(msg.ProofInit) == 0 { return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") } - if len(msg.ProofClient) == 0 { - return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") - } - if len(msg.ProofConsensus) == 0 { - return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") - } - if msg.ConsensusHeight.IsZero() { - return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "consensus height must be non-zero") - } - _, err = sdk.AccAddressFromBech32(msg.Signer) + _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Counterparty.ValidateBasic() } -// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgConnectionOpenTry) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - return unpacker.UnpackAny(msg.ClientState, new(exported.ClientState)) -} - // NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance func NewMsgConnectionOpenAck( - connectionID, counterpartyConnectionID string, counterpartyClient exported.ClientState, - tryProof, clientProof, consensusProof []byte, - proofHeight, consensusHeight clienttypes.Height, - version *Version, - signer string, + connectionID, counterpartyConnectionID string, tryProof []byte, + proofHeight clienttypes.Height, version *Version, signer string, ) *MsgConnectionOpenAck { - protoAny, _ := clienttypes.PackClientState(counterpartyClient) return &MsgConnectionOpenAck{ ConnectionId: connectionID, CounterpartyConnectionId: counterpartyConnectionID, - ClientState: protoAny, ProofTry: tryProof, - ProofClient: clientProof, - ProofConsensus: consensusProof, ProofHeight: proofHeight, - ConsensusHeight: consensusHeight, Version: version, Signer: signer, } } -// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces -func (msg MsgConnectionOpenAck) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - return unpacker.UnpackAny(msg.ClientState, new(exported.ClientState)) -} - // ValidateBasic implements sdk.Msg func (msg MsgConnectionOpenAck) ValidateBasic() error { if !IsValidConnectionID(msg.ConnectionId) { @@ -200,29 +149,10 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { if err := ValidateVersion(msg.Version); err != nil { return err } - if msg.ClientState == nil { - return errorsmod.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") - } - clientState, err := clienttypes.UnpackClientState(msg.ClientState) - if err != nil { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) - } - if err := clientState.Validate(); err != nil { - return errorsmod.Wrap(err, "counterparty client is invalid") - } if len(msg.ProofTry) == 0 { return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") } - if len(msg.ProofClient) == 0 { - return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") - } - if len(msg.ProofConsensus) == 0 { - return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") - } - if msg.ConsensusHeight.IsZero() { - return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "consensus height must be non-zero") - } - _, err = sdk.AccAddressFromBech32(msg.Signer) + _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index 60d1edb3ec1..6e6b741bd3f 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -3,7 +3,6 @@ package types_test import ( "fmt" "testing" - "time" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" @@ -19,11 +18,9 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ibc "github.com/cosmos/ibc-go/v9/modules/core" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" - ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" "github.com/cosmos/ibc-go/v9/testing/simapp" ) @@ -121,48 +118,23 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) - clientState := ibctm.NewClientState( - chainID, ibctm.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, - ) - protoAny, err := clienttypes.PackClientState(clientState) - suite.Require().NoError(err) - - // Pack consensus state into any to test unpacking error - consState := ibctm.NewConsensusState( - time.Now(), commitmenttypes.NewMerkleRoot([]byte("root")), []byte("nextValsHash"), - ) - invalidAny := clienttypes.MustPackConsensusState(consState) - counterparty := types.NewCounterparty("connectiontotest", "clienttotest", prefix) - - // invalidClientState fails validateBasic - invalidClient := ibctm.NewClientState( - chainID, ibctm.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clienttypes.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, - ) - testCases := []struct { name string msg *types.MsgConnectionOpenTry expPass bool }{ - {"non empty connection ID", &types.MsgConnectionOpenTry{"connection-0", "clienttotesta", protoAny, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, - {"localhost client ID", types.NewMsgConnectionOpenTry(exported.LocalhostClientID, "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid client ID", types.NewMsgConnectionOpenTry("test/iris", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("clienttotesta", "ibc/test", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "test/conn1", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid nil counterparty client", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", nil, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"invalid client unpacking", &types.MsgConnectionOpenTry{"", "clienttotesta", invalidAny, counterparty, 500, []*types.Version{ibctesting.ConnectionVersion}, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, - {"counterparty failed validate", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", invalidClient, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty counterparty prefix", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, emptyPrefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty counterpartyVersions", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty proofInit", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, emptyProof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty proofClient", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, emptyProof, suite.proof, clientHeight, clientHeight, signer), false}, - {"empty proofConsensus", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, emptyProof, clientHeight, clientHeight, signer), false}, - {"invalid consensusHeight", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clienttypes.ZeroHeight(), signer), false}, - {"empty singer", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ""), false}, - {"invalid version", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{{}}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"too many counterparty versions", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, make([]*types.Version, types.MaxCounterpartyVersionsLength+1), 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"too many features in counterparty version", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{{"v1", make([]string, types.MaxFeaturesLength+1)}}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), false}, - {"success", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", clientState, prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, signer), true}, + {"success", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, signer), true}, + {"localhost client ID", types.NewMsgConnectionOpenTry(exported.LocalhostClientID, "connectiontotest", "clienttotest", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, signer), false}, + {"invalid client ID", types.NewMsgConnectionOpenTry("test/iris", "connectiontotest", "clienttotest", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, signer), false}, + {"invalid counterparty connection ID", types.NewMsgConnectionOpenTry("clienttotesta", "ibc/test", "clienttotest", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, signer), false}, + {"invalid counterparty client ID", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "test/conn1", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, signer), false}, + {"empty counterparty prefix", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", emptyPrefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, signer), false}, + {"empty counterpartyVersions", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, []*types.Version{}, 500, suite.proof, clientHeight, signer), false}, + {"empty proofInit", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, emptyProof, clientHeight, signer), false}, + {"empty singer", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, []*types.Version{ibctesting.ConnectionVersion}, 500, suite.proof, clientHeight, ""), false}, + {"invalid version", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, []*types.Version{{}}, 500, suite.proof, clientHeight, signer), false}, + {"too many counterparty versions", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, make([]*types.Version, types.MaxCounterpartyVersionsLength+1), 500, suite.proof, clientHeight, signer), false}, + {"too many features in counterparty version", types.NewMsgConnectionOpenTry("clienttotesta", "connectiontotest", "clienttotest", prefix, []*types.Version{{"v1", make([]string, types.MaxFeaturesLength+1)}}, 500, suite.proof, clientHeight, signer), false}, } for _, tc := range testCases { @@ -178,39 +150,17 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { } func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { - clientState := ibctm.NewClientState( - chainID, ibctm.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, - ) - - // Pack consensus state into any to test unpacking error - consState := ibctm.NewConsensusState( - time.Now(), commitmenttypes.NewMerkleRoot([]byte("root")), []byte("nextValsHash"), - ) - invalidAny := clienttypes.MustPackConsensusState(consState) - - // invalidClientState fails validateBasic - invalidClient := ibctm.NewClientState( - chainID, ibctm.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clienttypes.ZeroHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, - ) - connectionID := "connection-0" - testCases := []struct { name string msg *types.MsgConnectionOpenAck expPass bool }{ - {"invalid connection ID", types.NewMsgConnectionOpenAck("test/conn1", connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"invalid counterparty connection ID", types.NewMsgConnectionOpenAck(connectionID, "test/conn1", clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"invalid nil counterparty client", types.NewMsgConnectionOpenAck(connectionID, connectionID, nil, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"invalid unpacking counterparty client", &types.MsgConnectionOpenAck{connectionID, connectionID, ibctesting.ConnectionVersion, invalidAny, clientHeight, suite.proof, suite.proof, suite.proof, clientHeight, signer, nil}, false}, - {"counterparty client failed validate", types.NewMsgConnectionOpenAck(connectionID, connectionID, invalidClient, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"empty proofTry", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, emptyProof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"empty proofClient", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, emptyProof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"empty proofConsensus", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, emptyProof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), false}, - {"invalid consensusHeight", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clienttypes.ZeroHeight(), ibctesting.ConnectionVersion, signer), false}, - {"invalid version", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, &types.Version{}, signer), false}, - {"empty signer", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, ""), false}, - {"success", types.NewMsgConnectionOpenAck(connectionID, connectionID, clientState, suite.proof, suite.proof, suite.proof, clientHeight, clientHeight, ibctesting.ConnectionVersion, signer), true}, + {"success", types.NewMsgConnectionOpenAck(connectionID, connectionID, suite.proof, clientHeight, ibctesting.ConnectionVersion, signer), true}, + {"invalid connection ID", types.NewMsgConnectionOpenAck("test/conn1", connectionID, suite.proof, clientHeight, ibctesting.ConnectionVersion, signer), false}, + {"invalid counterparty connection ID", types.NewMsgConnectionOpenAck(connectionID, "test/conn1", suite.proof, clientHeight, ibctesting.ConnectionVersion, signer), false}, + {"empty proofTry", types.NewMsgConnectionOpenAck(connectionID, connectionID, emptyProof, clientHeight, ibctesting.ConnectionVersion, signer), false}, + {"invalid version", types.NewMsgConnectionOpenAck(connectionID, connectionID, suite.proof, clientHeight, &types.Version{}, signer), false}, + {"empty signer", types.NewMsgConnectionOpenAck(connectionID, connectionID, suite.proof, clientHeight, ibctesting.ConnectionVersion, ""), false}, } for _, tc := range testCases { diff --git a/modules/core/03-connection/types/tx.pb.go b/modules/core/03-connection/types/tx.pb.go index 070ba6e6250..6576333d522 100644 --- a/modules/core/03-connection/types/tx.pb.go +++ b/modules/core/03-connection/types/tx.pb.go @@ -117,8 +117,9 @@ var xxx_messageInfo_MsgConnectionOpenInitResponse proto.InternalMessageInfo type MsgConnectionOpenTry struct { ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` // Deprecated: this field is unused. Crossing hellos are no longer supported in core IBC. - PreviousConnectionId string `protobuf:"bytes,2,opt,name=previous_connection_id,json=previousConnectionId,proto3" json:"previous_connection_id,omitempty"` // Deprecated: Do not use. - ClientState *types.Any `protobuf:"bytes,3,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty"` + PreviousConnectionId string `protobuf:"bytes,2,opt,name=previous_connection_id,json=previousConnectionId,proto3" json:"previous_connection_id,omitempty"` // Deprecated: Do not use. + // Deprecated: this field is unused. + ClientState *types.Any `protobuf:"bytes,3,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty"` // Deprecated: Do not use. Counterparty Counterparty `protobuf:"bytes,4,opt,name=counterparty,proto3" json:"counterparty"` DelayPeriod uint64 `protobuf:"varint,5,opt,name=delay_period,json=delayPeriod,proto3" json:"delay_period,omitempty"` CounterpartyVersions []*Version `protobuf:"bytes,6,rep,name=counterparty_versions,json=counterpartyVersions,proto3" json:"counterparty_versions,omitempty"` @@ -126,14 +127,15 @@ type MsgConnectionOpenTry struct { // proof of the initialization the connection on Chain A: `UNINITIALIZED -> // INIT` ProofInit []byte `protobuf:"bytes,8,opt,name=proof_init,json=proofInit,proto3" json:"proof_init,omitempty"` - // proof of client state included in message - ProofClient []byte `protobuf:"bytes,9,opt,name=proof_client,json=proofClient,proto3" json:"proof_client,omitempty"` - // proof of client consensus state - ProofConsensus []byte `protobuf:"bytes,10,opt,name=proof_consensus,json=proofConsensus,proto3" json:"proof_consensus,omitempty"` - ConsensusHeight types1.Height `protobuf:"bytes,11,opt,name=consensus_height,json=consensusHeight,proto3" json:"consensus_height"` - Signer string `protobuf:"bytes,12,opt,name=signer,proto3" json:"signer,omitempty"` - // optional proof data for host state machines that are unable to introspect their own consensus state - HostConsensusStateProof []byte `protobuf:"bytes,13,opt,name=host_consensus_state_proof,json=hostConsensusStateProof,proto3" json:"host_consensus_state_proof,omitempty"` + // Deprecated: this field is unused. + ProofClient []byte `protobuf:"bytes,9,opt,name=proof_client,json=proofClient,proto3" json:"proof_client,omitempty"` // Deprecated: Do not use. + // Deprecated: this field is unused. + ProofConsensus []byte `protobuf:"bytes,10,opt,name=proof_consensus,json=proofConsensus,proto3" json:"proof_consensus,omitempty"` // Deprecated: Do not use. + // Deprecated: this field is unused. + ConsensusHeight *types1.Height `protobuf:"bytes,11,opt,name=consensus_height,json=consensusHeight,proto3" json:"consensus_height,omitempty"` // Deprecated: Do not use. + Signer string `protobuf:"bytes,12,opt,name=signer,proto3" json:"signer,omitempty"` + // Deprecated: this field is unused. + HostConsensusStateProof []byte `protobuf:"bytes,13,opt,name=host_consensus_state_proof,json=hostConsensusStateProof,proto3" json:"host_consensus_state_proof,omitempty"` // Deprecated: Do not use. } func (m *MsgConnectionOpenTry) Reset() { *m = MsgConnectionOpenTry{} } @@ -209,22 +211,24 @@ var xxx_messageInfo_MsgConnectionOpenTryResponse proto.InternalMessageInfo // MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to // acknowledge the change of connection state to TRYOPEN on Chain B. type MsgConnectionOpenAck struct { - ConnectionId string `protobuf:"bytes,1,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` - CounterpartyConnectionId string `protobuf:"bytes,2,opt,name=counterparty_connection_id,json=counterpartyConnectionId,proto3" json:"counterparty_connection_id,omitempty"` - Version *Version `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` - ClientState *types.Any `protobuf:"bytes,4,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty"` - ProofHeight types1.Height `protobuf:"bytes,5,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` + ConnectionId string `protobuf:"bytes,1,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + CounterpartyConnectionId string `protobuf:"bytes,2,opt,name=counterparty_connection_id,json=counterpartyConnectionId,proto3" json:"counterparty_connection_id,omitempty"` + Version *Version `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + // Deprecated: this field is unused. + ClientState *types.Any `protobuf:"bytes,4,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty"` // Deprecated: Do not use. + ProofHeight types1.Height `protobuf:"bytes,5,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` // proof of the initialization the connection on Chain B: `UNINITIALIZED -> // TRYOPEN` ProofTry []byte `protobuf:"bytes,6,opt,name=proof_try,json=proofTry,proto3" json:"proof_try,omitempty"` - // proof of client state included in message - ProofClient []byte `protobuf:"bytes,7,opt,name=proof_client,json=proofClient,proto3" json:"proof_client,omitempty"` - // proof of client consensus state - ProofConsensus []byte `protobuf:"bytes,8,opt,name=proof_consensus,json=proofConsensus,proto3" json:"proof_consensus,omitempty"` - ConsensusHeight types1.Height `protobuf:"bytes,9,opt,name=consensus_height,json=consensusHeight,proto3" json:"consensus_height"` - Signer string `protobuf:"bytes,10,opt,name=signer,proto3" json:"signer,omitempty"` - // optional proof data for host state machines that are unable to introspect their own consensus state - HostConsensusStateProof []byte `protobuf:"bytes,11,opt,name=host_consensus_state_proof,json=hostConsensusStateProof,proto3" json:"host_consensus_state_proof,omitempty"` + // Deprecated: this field is unused. + ProofClient []byte `protobuf:"bytes,7,opt,name=proof_client,json=proofClient,proto3" json:"proof_client,omitempty"` // Deprecated: Do not use. + // Deprecated: this field is unused. + ProofConsensus []byte `protobuf:"bytes,8,opt,name=proof_consensus,json=proofConsensus,proto3" json:"proof_consensus,omitempty"` // Deprecated: Do not use. + // Deprecated: this field is unused. + ConsensusHeight *types1.Height `protobuf:"bytes,9,opt,name=consensus_height,json=consensusHeight,proto3" json:"consensus_height,omitempty"` // Deprecated: Do not use. + Signer string `protobuf:"bytes,10,opt,name=signer,proto3" json:"signer,omitempty"` + // Deprecated: this field is unused. + HostConsensusStateProof []byte `protobuf:"bytes,11,opt,name=host_consensus_state_proof,json=hostConsensusStateProof,proto3" json:"host_consensus_state_proof,omitempty"` // Deprecated: Do not use. } func (m *MsgConnectionOpenAck) Reset() { *m = MsgConnectionOpenAck{} } @@ -474,65 +478,66 @@ func init() { func init() { proto.RegisterFile("ibc/core/connection/v1/tx.proto", fileDescriptor_5d00fde5fc97399e) } var fileDescriptor_5d00fde5fc97399e = []byte{ - // 928 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0x41, 0x6f, 0xe3, 0x44, - 0x14, 0xc7, 0xe3, 0xd6, 0x49, 0x9b, 0x97, 0x2c, 0x85, 0x51, 0xda, 0x7a, 0xbd, 0xac, 0x93, 0x2d, - 0x48, 0xad, 0x56, 0xd4, 0xde, 0xee, 0x82, 0xd8, 0x85, 0x5e, 0xda, 0x5c, 0xa8, 0x50, 0x61, 0x65, - 0xca, 0x1e, 0xb8, 0x44, 0x89, 0x33, 0x75, 0x47, 0x6d, 0x3c, 0x96, 0xc7, 0x09, 0x6b, 0x4e, 0x08, - 0x2e, 0x48, 0x5c, 0xf8, 0x08, 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xd1, 0x46, 0x36, 0x5b, 0x06, 0x19, 0x6a, 0x43, 0xdd, 0x0f, 0x28, 0x3d, 0xed, - 0x9c, 0x61, 0xe2, 0x9e, 0x85, 0xda, 0x0a, 0xdf, 0x88, 0x9e, 0x29, 0x26, 0xb8, 0x1f, 0xed, 0x99, - 0x5f, 0x70, 0x85, 0xb4, 0x5f, 0xe3, 0x59, 0x22, 0x84, 0xee, 0x02, 0x88, 0x22, 0xc4, 0x23, 0xa1, - 0xb6, 0xda, 0x52, 0x76, 0xea, 0x76, 0x95, 0x47, 0x38, 0xea, 0xf7, 0x92, 0x35, 0x44, 0x2d, 0xad, - 0xca, 0x05, 0xa2, 0x42, 0x9b, 0x87, 0xd0, 0x36, 0xac, 0x49, 0x49, 0xcc, 0x81, 0xc7, 0x86, 0x4c, - 0x03, 0xae, 0x7a, 0x47, 0xa8, 0x92, 0x28, 0xfa, 0x12, 0xde, 0x4d, 0x25, 0x89, 0xe7, 0x5a, 0x41, - 0xcf, 0x6b, 0x69, 0xa6, 0xf4, 0x3d, 0x06, 0xb7, 0x9e, 0x05, 0x17, 0x7d, 0x0e, 0xfa, 0x19, 0x65, - 0xe1, 0xd8, 0x8c, 0xc0, 0xa3, 0xc3, 0xbd, 0x68, 0xb7, 0xb8, 0xb1, 0xcd, 0x58, 0x91, 0xfa, 0xe2, - 0x54, 0x3c, 0x8d, 0x1f, 0xcf, 0x52, 0x6f, 0xc0, 0xfb, 0x79, 0x4c, 0xa7, 0xd0, 0xff, 0xa9, 0xe6, - 0x40, 0x7f, 0xe0, 0x9c, 0xa3, 0x0f, 0xe0, 0xd6, 0x24, 0xce, 0x02, 0xfc, 0xba, 0x93, 0x45, 0x78, - 0x1f, 0xf4, 0x09, 0x2c, 0x72, 0x0e, 0x80, 0xad, 0x65, 0x15, 0x13, 0x07, 0xe0, 0x06, 0x2f, 0x86, - 0xe9, 0xb3, 0xa3, 0x16, 0x3d, 0x3b, 0xd3, 0xc8, 0x95, 0xdf, 0x04, 0x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e1, - 0x0c, 0xfb, 0xe8, 0x67, 0x05, 0xd6, 0xf3, 0xc1, 0x7f, 0x50, 0xb8, 0x9e, 0xcc, 0xd0, 0x1f, 0x2f, - 0x9a, 0x91, 0xba, 0x08, 0x60, 0x43, 0x30, 0x31, 0x96, 0x49, 0x2e, 0xb7, 0xaf, 0xa9, 0x99, 0xc5, - 0x48, 0xb7, 0x0a, 0x0a, 0x93, 0x35, 0xf5, 0xf2, 0x8f, 0xaf, 0x5f, 0xdc, 0x57, 0x0e, 0x9f, 0xbd, - 0xbc, 0x34, 0x94, 0x57, 0x97, 0x86, 0xf2, 0xef, 0xa5, 0xa1, 0xfc, 0x76, 0x65, 0x94, 0x5e, 0x5d, - 0x19, 0xa5, 0xbf, 0xaf, 0x8c, 0xd2, 0x77, 0xfb, 0x2e, 0x09, 0xcf, 0x86, 0x3d, 0xd3, 0xa1, 0x03, - 0x4b, 0x5e, 0x9a, 0x49, 0xcf, 0xd9, 0x75, 0xa9, 0x35, 0x7a, 0x62, 0x0d, 0x68, 0x7f, 0x78, 0x81, - 0x99, 0xb8, 0xf4, 0x3e, 0x78, 0xb4, 0x9b, 0xb9, 0xf7, 0x86, 0x91, 0x8f, 0x59, 0xaf, 0xc2, 0x5f, - 0xf8, 0x8f, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x65, 0xfc, 0xe6, 0xbf, 0x0b, 0x00, 0x00, + // 935 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0xcd, 0x6e, 0xe3, 0x54, + 0x14, 0xc7, 0xe3, 0x36, 0x49, 0x9b, 0x93, 0x0c, 0x85, 0xab, 0xb4, 0xf5, 0x78, 0x18, 0x27, 0x14, + 0xd0, 0x54, 0x03, 0xb5, 0xa7, 0x33, 0x20, 0xcd, 0x40, 0x25, 0xd4, 0x66, 0x43, 0x17, 0x85, 0x91, + 0x29, 0xb3, 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, 0xe1, 0x9d, 0xe9, 0x73, 0xf8, + 0xe3, 0xb9, 0x63, 0x1d, 0x87, 0xb1, 0xf1, 0xc9, 0x22, 0xea, 0xd9, 0x0b, 0x73, 0x70, 0xe6, 0x5f, + 0x78, 0xdf, 0x3d, 0x5b, 0x60, 0xe1, 0x0c, 0xfb, 0xe8, 0x67, 0x0d, 0xd6, 0xf3, 0xc1, 0x7f, 0x30, + 0x77, 0x3c, 0xe5, 0x61, 0x3c, 0x5e, 0xd4, 0x23, 0xcd, 0x22, 0x84, 0x0d, 0xc9, 0xc4, 0x48, 0xa6, + 0xb8, 0xbc, 0x77, 0x45, 0xcc, 0x2c, 0x46, 0x86, 0x3d, 0xa7, 0x30, 0x59, 0xd3, 0x28, 0xfd, 0xf8, + 0xe6, 0xc5, 0x7d, 0xed, 0xe0, 0xd9, 0xcb, 0x0b, 0x53, 0x7b, 0x75, 0x61, 0x6a, 0xaf, 0x2f, 0x4c, + 0xed, 0xb7, 0x4b, 0xb3, 0xf0, 0xea, 0xd2, 0x2c, 0xfc, 0x79, 0x69, 0x16, 0xbe, 0xdb, 0xf3, 0x48, + 0x74, 0x3a, 0xe8, 0x5a, 0x2e, 0xed, 0xdb, 0xea, 0x42, 0x4d, 0xba, 0xee, 0x8e, 0x47, 0xed, 0xe1, + 0x13, 0xbb, 0x4f, 0x7b, 0x83, 0x73, 0xcc, 0xe4, 0x85, 0xf8, 0xc1, 0xa3, 0x9d, 0xcc, 0x9d, 0x38, + 0x8a, 0x03, 0xcc, 0xba, 0x65, 0xf1, 0xfb, 0x7f, 0xf4, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x81, + 0x77, 0x9b, 0x70, 0xdb, 0x0b, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -894,16 +899,18 @@ func (m *MsgConnectionOpenTry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x62 } - { - size, err := m.ConsensusHeight.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if m.ConsensusHeight != nil { + { + size, err := m.ConsensusHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x5a } - i-- - dAtA[i] = 0x5a if len(m.ProofConsensus) > 0 { i -= len(m.ProofConsensus) copy(dAtA[i:], m.ProofConsensus) @@ -1050,16 +1057,18 @@ func (m *MsgConnectionOpenAck) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x52 } - { - size, err := m.ConsensusHeight.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if m.ConsensusHeight != nil { + { + size, err := m.ConsensusHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x4a } - i-- - dAtA[i] = 0x4a if len(m.ProofConsensus) > 0 { i -= len(m.ProofConsensus) copy(dAtA[i:], m.ProofConsensus) @@ -1384,8 +1393,10 @@ func (m *MsgConnectionOpenTry) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.ConsensusHeight.Size() - n += 1 + l + sovTx(uint64(l)) + if m.ConsensusHeight != nil { + l = m.ConsensusHeight.Size() + n += 1 + l + sovTx(uint64(l)) + } l = len(m.Signer) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -1442,8 +1453,10 @@ func (m *MsgConnectionOpenAck) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.ConsensusHeight.Size() - n += 1 + l + sovTx(uint64(l)) + if m.ConsensusHeight != nil { + l = m.ConsensusHeight.Size() + n += 1 + l + sovTx(uint64(l)) + } l = len(m.Signer) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -2157,6 +2170,9 @@ func (m *MsgConnectionOpenTry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + if m.ConsensusHeight == nil { + m.ConsensusHeight = &types1.Height{} + } if err := m.ConsensusHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2627,6 +2643,9 @@ func (m *MsgConnectionOpenAck) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + if m.ConsensusHeight == nil { + m.ConsensusHeight = &types1.Height{} + } if err := m.ConsensusHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 0e89feee358..fed78a94888 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -34,14 +34,10 @@ type Keeper struct { // NewKeeper creates a new ibc Keeper func NewKeeper( cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace, - consensusHost clienttypes.ConsensusHost, upgradeKeeper clienttypes.UpgradeKeeper, + upgradeKeeper clienttypes.UpgradeKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, authority string, ) *Keeper { // panic if any of the keepers passed in is empty - if isEmpty(consensusHost) { - panic(errors.New("cannot initialize IBC keeper: empty consensus host")) - } - if isEmpty(upgradeKeeper) { panic(errors.New("cannot initialize IBC keeper: empty upgrade keeper")) } @@ -54,7 +50,7 @@ func NewKeeper( panic(errors.New("authority must be non-empty")) } - clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, consensusHost, upgradeKeeper) + clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, upgradeKeeper) connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper(scopedKeeper) channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper) @@ -74,15 +70,6 @@ func (k *Keeper) Codec() codec.BinaryCodec { return k.cdc } -// SetConsensusHost sets a custom ConsensusHost for self client state and consensus state validation. -func (k *Keeper) SetConsensusHost(consensusHost clienttypes.ConsensusHost) { - if consensusHost == nil { - panic(errors.New("cannot set a nil self consensus host")) - } - - k.ClientKeeper.SetConsensusHost(consensusHost) -} - // SetRouter sets the Router in IBC Keeper and seals it. The method panics if // there is an existing router that's already sealed. func (k *Keeper) SetRouter(rtr *porttypes.Router) { diff --git a/modules/core/keeper/keeper_test.go b/modules/core/keeper/keeper_test.go index 282a8a4bc34..ff7fb8b8f11 100644 --- a/modules/core/keeper/keeper_test.go +++ b/modules/core/keeper/keeper_test.go @@ -1,21 +1,16 @@ package keeper_test import ( - "context" "testing" - "time" testifysuite "github.com/stretchr/testify/suite" upgradekeeper "cosmossdk.io/x/upgrade/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper" - ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -44,24 +39,10 @@ func TestKeeperTestSuite(t *testing.T) { testifysuite.Run(t, new(KeeperTestSuite)) } -// MockStakingKeeper implements clienttypes.StakingKeeper used in ibckeeper.NewKeeper -type MockStakingKeeper struct { - mockField string -} - -func (MockStakingKeeper) GetHistoricalInfo(_ context.Context, _ int64) (stakingtypes.HistoricalInfo, error) { - return stakingtypes.HistoricalInfo{}, nil -} - -func (MockStakingKeeper) UnbondingTime(_ context.Context) (time.Duration, error) { - return 0, nil -} - // Test ibckeeper.NewKeeper used to initialize IBCKeeper when creating an app instance. // It verifies if ibckeeper.NewKeeper panic when any of the keepers passed in is empty. func (suite *KeeperTestSuite) TestNewKeeper() { var ( - consensusHost clienttypes.ConsensusHost upgradeKeeper clienttypes.UpgradeKeeper scopedKeeper capabilitykeeper.ScopedKeeper newIBCKeeperFn func() @@ -72,12 +53,6 @@ func (suite *KeeperTestSuite) TestNewKeeper() { malleate func() expPass bool }{ - {"failure: empty consensus host value", func() { - consensusHost = &ibctm.ConsensusHost{} - }, false}, - {"failure: nil consensus host value", func() { - consensusHost = nil - }, false}, {"failure: empty upgrade keeper value", func() { emptyUpgradeKeeperValue := upgradekeeper.Keeper{} @@ -99,18 +74,12 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().AppCodec(), suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), - consensusHost, upgradeKeeper, scopedKeeper, "", // authority ) } }, false}, - {"success: replace stakingKeeper with non-empty MockStakingKeeper", func() { - // use a different implementation of clienttypes.StakingKeeper - mockStakingKeeper := MockStakingKeeper{"not empty"} - consensusHost = ibctm.NewConsensusHost(mockStakingKeeper) - }, true}, } for _, tc := range testCases { @@ -124,14 +93,12 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().AppCodec(), suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), - consensusHost, upgradeKeeper, scopedKeeper, suite.chainA.App.GetIBCKeeper().GetAuthority(), ) } - consensusHost = ibctm.NewConsensusHost(suite.chainA.GetSimApp().StakingKeeper) upgradeKeeper = suite.chainA.GetSimApp().UpgradeKeeper scopedKeeper = suite.chainA.GetSimApp().ScopedIBCKeeper diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 2f9a2acc7be..046271e3b39 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -150,15 +150,9 @@ func (k *Keeper) ConnectionOpenInit(goCtx context.Context, msg *connectiontypes. func (k *Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenTry) (*connectiontypes.MsgConnectionOpenTryResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - targetClient, err := clienttypes.UnpackClientState(msg.ClientState) - if err != nil { - return nil, err - } - if _, err := k.ConnectionKeeper.ConnOpenTry( - ctx, msg.Counterparty, msg.DelayPeriod, msg.ClientId, targetClient, - msg.CounterpartyVersions, msg.ProofInit, msg.ProofClient, msg.ProofConsensus, - msg.ProofHeight, msg.ConsensusHeight, + ctx, msg.Counterparty, msg.DelayPeriod, msg.ClientId, + msg.CounterpartyVersions, msg.ProofInit, msg.ProofHeight, ); err != nil { return nil, errorsmod.Wrap(err, "connection handshake open try failed") } @@ -170,15 +164,9 @@ func (k *Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.M func (k *Keeper) ConnectionOpenAck(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenAck) (*connectiontypes.MsgConnectionOpenAckResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - targetClient, err := clienttypes.UnpackClientState(msg.ClientState) - if err != nil { - return nil, err - } - if err := k.ConnectionKeeper.ConnOpenAck( - ctx, msg.ConnectionId, targetClient, msg.Version, msg.CounterpartyConnectionId, - msg.ProofTry, msg.ProofClient, msg.ProofConsensus, - msg.ProofHeight, msg.ConsensusHeight, + ctx, msg.ConnectionId, msg.Version, msg.CounterpartyConnectionId, + msg.ProofTry, msg.ProofHeight, ); err != nil { return nil, errorsmod.Wrap(err, "connection handshake open ack failed") } diff --git a/modules/light-clients/07-tendermint/consensus_host.go b/modules/light-clients/07-tendermint/consensus_host.go deleted file mode 100644 index fb7d8dc66a3..00000000000 --- a/modules/light-clients/07-tendermint/consensus_host.go +++ /dev/null @@ -1,138 +0,0 @@ -package tendermint - -import ( - "context" - "reflect" - "time" - - errorsmod "cosmossdk.io/errors" - upgradetypes "cosmossdk.io/x/upgrade/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/cometbft/cometbft/light" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" - "github.com/cosmos/ibc-go/v9/modules/core/exported" -) - -var _ clienttypes.ConsensusHost = (*ConsensusHost)(nil) - -// ConsensusHost implements the 02-client clienttypes.ConsensusHost interface. -type ConsensusHost struct { - stakingKeeper StakingKeeper -} - -// StakingKeeper defines an expected interface for the tendermint ConsensusHost. -type StakingKeeper interface { - GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error) - UnbondingTime(ctx context.Context) (time.Duration, error) -} - -// NewConsensusHost creates and returns a new ConsensusHost for tendermint consensus. -func NewConsensusHost(stakingKeeper clienttypes.StakingKeeper) clienttypes.ConsensusHost { - if stakingKeeper == nil { - panic("staking keeper cannot be nil") - } - - return &ConsensusHost{ - stakingKeeper: stakingKeeper, - } -} - -// GetSelfConsensusState implements the 02-client clienttypes.ConsensusHost interface. -func (c *ConsensusHost) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - selfHeight, ok := height.(clienttypes.Height) - if !ok { - return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", clienttypes.Height{}, height) - } - - // check that height revision matches chainID revision - revision := clienttypes.ParseChainID(ctx.ChainID()) - if revision != height.GetRevisionNumber() { - return nil, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "chainID revision number does not match height revision number: expected %d, got %d", revision, height.GetRevisionNumber()) - } - - histInfo, err := c.stakingKeeper.GetHistoricalInfo(ctx, int64(selfHeight.RevisionHeight)) - if err != nil { - return nil, errorsmod.Wrapf(err, "height %d", selfHeight.RevisionHeight) - } - - consensusState := &ConsensusState{ - Timestamp: histInfo.Header.Time, - Root: commitmenttypes.NewMerkleRoot(histInfo.Header.GetAppHash()), - NextValidatorsHash: histInfo.Header.NextValidatorsHash, - } - - return consensusState, nil -} - -// ValidateSelfClient implements the 02-client clienttypes.ConsensusHost interface. -func (c *ConsensusHost) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { - tmClient, ok := clientState.(*ClientState) - if !ok { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", &ClientState{}, tmClient) - } - - if !tmClient.FrozenHeight.IsZero() { - return clienttypes.ErrClientFrozen - } - - if ctx.ChainID() != tmClient.ChainId { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "invalid chain-id. expected: %s, got: %s", - ctx.ChainID(), tmClient.ChainId) - } - - revision := clienttypes.ParseChainID(ctx.ChainID()) - - // client must be in the same revision as executing chain - if tmClient.LatestHeight.RevisionNumber != revision { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client is not in the same revision as the chain. expected revision: %d, got: %d", - tmClient.LatestHeight.RevisionNumber, revision) - } - - selfHeight := clienttypes.NewHeight(revision, uint64(ctx.BlockHeight())) - if tmClient.LatestHeight.GTE(selfHeight) { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client has LatestHeight %d greater than or equal to chain height %d", - tmClient.LatestHeight, selfHeight) - } - - expectedProofSpecs := commitmenttypes.GetSDKSpecs() - if !reflect.DeepEqual(expectedProofSpecs, tmClient.ProofSpecs) { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client has invalid proof specs. expected: %v got: %v", - expectedProofSpecs, tmClient.ProofSpecs) - } - - if err := light.ValidateTrustLevel(tmClient.TrustLevel.ToTendermint()); err != nil { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "trust-level invalid: %v", err) - } - - expectedUbdPeriod, err := c.stakingKeeper.UnbondingTime(ctx) - if err != nil { - return errorsmod.Wrapf(err, "failed to retrieve unbonding period") - } - - if expectedUbdPeriod != tmClient.UnbondingPeriod { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "invalid unbonding period. expected: %s, got: %s", - expectedUbdPeriod, tmClient.UnbondingPeriod) - } - - if tmClient.UnbondingPeriod < tmClient.TrustingPeriod { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unbonding period must be greater than trusting period. unbonding period (%d) < trusting period (%d)", - tmClient.UnbondingPeriod, tmClient.TrustingPeriod) - } - - if len(tmClient.UpgradePath) != 0 { - // For now, SDK IBC implementation assumes that upgrade path (if defined) is defined by SDK upgrade module - expectedUpgradePath := []string{upgradetypes.StoreKey, upgradetypes.KeyUpgradedIBCState} - if !reflect.DeepEqual(expectedUpgradePath, tmClient.UpgradePath) { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "upgrade path must be the upgrade path defined by upgrade module. expected %v, got %v", - expectedUpgradePath, tmClient.UpgradePath) - } - } - - return nil -} diff --git a/modules/light-clients/07-tendermint/consensus_host_test.go b/modules/light-clients/07-tendermint/consensus_host_test.go deleted file mode 100644 index f0dca0148df..00000000000 --- a/modules/light-clients/07-tendermint/consensus_host_test.go +++ /dev/null @@ -1,249 +0,0 @@ -package tendermint_test - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - "github.com/cosmos/ibc-go/v9/modules/core/exported" - solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" - ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v9/testing" - "github.com/cosmos/ibc-go/v9/testing/mock" -) - -func (suite *TendermintTestSuite) TestGetSelfConsensusState() { - var height clienttypes.Height - - cases := []struct { - name string - malleate func() - expError error - }{ - { - name: "zero height", - malleate: func() {}, - expError: clienttypes.ErrInvalidHeight, - }, - { - name: "height > latest height", - malleate: func() { - height = clienttypes.NewHeight(1, uint64(suite.chainA.GetContext().BlockHeight())+1) - }, - expError: stakingtypes.ErrNoHistoricalInfo, - }, - { - name: "pruned historical info", - malleate: func() { - height = clienttypes.NewHeight(1, uint64(suite.chainA.GetContext().BlockHeight())-1) - - err := suite.chainA.GetSimApp().StakingKeeper.DeleteHistoricalInfo(suite.chainA.GetContext(), int64(height.GetRevisionHeight())) - suite.Require().NoError(err) - }, - expError: stakingtypes.ErrNoHistoricalInfo, - }, - { - name: "custom consensus host: failure", - malleate: func() { - consensusHost := &mock.ConsensusHost{ - GetSelfConsensusStateFn: func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - return nil, mock.MockApplicationCallbackError - }, - } - suite.chainA.GetSimApp().GetIBCKeeper().SetConsensusHost(consensusHost) - }, - expError: mock.MockApplicationCallbackError, - }, - { - name: "custom consensus host: success", - malleate: func() { - consensusHost := &mock.ConsensusHost{ - GetSelfConsensusStateFn: func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - return &solomachine.ConsensusState{}, nil - }, - } - suite.chainA.GetSimApp().GetIBCKeeper().SetConsensusHost(consensusHost) - }, - expError: nil, - }, - { - name: "latest height - 1", - malleate: func() { - height = clienttypes.NewHeight(1, uint64(suite.chainA.GetContext().BlockHeight())-1) - }, - expError: nil, - }, - { - name: "latest height", - malleate: func() { - // historical info is set on BeginBlock in x/staking, which is now encapsulated within the FinalizeBlock abci method, - // thus, we do not have historical info for current height due to how the ibctesting library operates. - // ibctesting calls app.Commit() as a final step on NextBlock and we invoke test code before FinalizeBlock is called at the current height once again. - err := suite.chainA.GetSimApp().StakingKeeper.TrackHistoricalInfo(suite.chainA.GetContext()) - suite.Require().NoError(err) - - height = clienttypes.GetSelfHeight(suite.chainA.GetContext()) - }, - expError: nil, - }, - } - - for i, tc := range cases { - tc := tc - suite.Run(tc.name, func() { - suite.SetupTest() - - height = clienttypes.ZeroHeight() - - tc.malleate() - - cs, err := suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.GetSelfConsensusState(suite.chainA.GetContext(), height) - - expPass := tc.expError == nil - if expPass { - suite.Require().NoError(err, "Case %d should have passed: %s", i, tc.name) - suite.Require().NotNil(cs, "Case %d should have passed: %s", i, tc.name) - } else { - suite.Require().ErrorIs(err, tc.expError, "Case %d should have failed: %s", i, tc.name) - suite.Require().Nil(cs, "Case %d should have failed: %s", i, tc.name) - } - }) - } -} - -func (suite *TendermintTestSuite) TestValidateSelfClient() { - testClientHeight := clienttypes.GetSelfHeight(suite.chainA.GetContext()) - testClientHeight.RevisionHeight-- - - var clientState exported.ClientState - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - name: "success", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: nil, - }, - { - name: "success with nil UpgradePath", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), nil) - }, - expError: nil, - }, - { - name: "success with custom self validator: solomachine", - malleate: func() { - clientState = solomachine.NewClientState(1, &solomachine.ConsensusState{}) - - smConsensusHost := &mock.ConsensusHost{ - ValidateSelfClientFn: func(ctx sdk.Context, clientState exported.ClientState) error { - smClientState, ok := clientState.(*solomachine.ClientState) - suite.Require().True(ok) - suite.Require().Equal(uint64(1), smClientState.Sequence) - - return nil - }, - } - - // add mock validation logic - suite.chainA.App.GetIBCKeeper().SetConsensusHost(smConsensusHost) - }, - expError: nil, - }, - { - name: "frozen client", - malleate: func() { - clientState = &ibctm.ClientState{ChainId: suite.chainA.ChainID, TrustLevel: ibctm.DefaultTrustLevel, TrustingPeriod: trustingPeriod, UnbondingPeriod: ubdPeriod, MaxClockDrift: maxClockDrift, FrozenHeight: testClientHeight, LatestHeight: testClientHeight, ProofSpecs: commitmenttypes.GetSDKSpecs(), UpgradePath: ibctesting.UpgradePath} - }, - expError: clienttypes.ErrClientFrozen, - }, - { - name: "incorrect chainID", - malleate: func() { - clientState = ibctm.NewClientState("gaiatestnet", ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid client height", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clienttypes.GetSelfHeight(suite.chainA.GetContext()).Increment().(clienttypes.Height), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid client type", - malleate: func() { - clientState = solomachine.NewClientState(0, &solomachine.ConsensusState{}) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid client revision", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clienttypes.NewHeight(1, 5), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid proof specs", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, nil, ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid trust level", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.Fraction{Numerator: 0, Denominator: 1}, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid unbonding period", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+10, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid trusting period", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, ubdPeriod+10, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "invalid upgrade path", - malleate: func() { - clientState = ibctm.NewClientState(suite.chainA.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), []string{"bad", "upgrade", "path"}) - }, - expError: clienttypes.ErrInvalidClient, - }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(tc.name, func() { - suite.SetupTest() - - tc.malleate() - - err := suite.chainA.App.GetIBCKeeper().ClientKeeper.ValidateSelfClient(suite.chainA.GetContext(), clientState) - - expPass := tc.expError == nil - if expPass { - suite.Require().NoError(err, "expected valid client for case: %s", tc.name) - } else { - suite.Require().Error(err, "expected invalid client for case: %s", tc.name) - } - }) - } -} diff --git a/modules/light-clients/08-wasm/CHANGELOG.md b/modules/light-clients/08-wasm/CHANGELOG.md index f07b5e94080..b2babf7b08c 100644 --- a/modules/light-clients/08-wasm/CHANGELOG.md +++ b/modules/light-clients/08-wasm/CHANGELOG.md @@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking +* [\#6937](https://github.com/cosmos/ibc-go/pull/6937) Remove `WasmConsensusHost` implementation of the `ConsensusHost` interface. + ### State Machine Breaking ### Improvements diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index 801b35a9ecc..1ebf3d9fd35 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -412,7 +412,7 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) govConfig := govtypes.DefaultConfig() diff --git a/modules/light-clients/08-wasm/types/consensus_host.go b/modules/light-clients/08-wasm/types/consensus_host.go deleted file mode 100644 index 2cdfe189243..00000000000 --- a/modules/light-clients/08-wasm/types/consensus_host.go +++ /dev/null @@ -1,77 +0,0 @@ -package types - -import ( - "errors" - - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v9/modules/core/exported" -) - -// WasmConsensusHost implements the 02-client types.ConsensusHost interface. -type WasmConsensusHost struct { - cdc codec.BinaryCodec - delegate clienttypes.ConsensusHost -} - -var _ clienttypes.ConsensusHost = (*WasmConsensusHost)(nil) - -// NewWasmConsensusHost creates and returns a new ConsensusHost for wasm wrapped consensus client state and consensus state self validation. -func NewWasmConsensusHost(cdc codec.BinaryCodec, delegate clienttypes.ConsensusHost) (*WasmConsensusHost, error) { - if cdc == nil { - return nil, errors.New("wasm consensus host codec is nil") - } - - if delegate == nil { - return nil, errors.New("wasm delegate consensus host is nil") - } - - return &WasmConsensusHost{ - cdc: cdc, - delegate: delegate, - }, nil -} - -// GetSelfConsensusState implements the 02-client types.ConsensusHost interface. -func (w *WasmConsensusHost) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - consensusState, err := w.delegate.GetSelfConsensusState(ctx, height) - if err != nil { - return nil, err - } - - // encode consensusState to wasm.ConsensusState.Data - bz, err := w.cdc.MarshalInterface(consensusState) - if err != nil { - return nil, err - } - - wasmConsensusState := &ConsensusState{ - Data: bz, - } - - return wasmConsensusState, nil -} - -// ValidateSelfClient implements the 02-client types.ConsensusHost interface. -func (w *WasmConsensusHost) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { - wasmClientState, ok := clientState.(*ClientState) - if !ok { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client must be a wasm client, expected: %T, got: %T", ClientState{}, wasmClientState) - } - - if wasmClientState.Data == nil { - return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm client state data is nil") - } - - // unmarshal the wasmClientState bytes into the ClientState interface and call self validation - var unwrappedClientState exported.ClientState - if err := w.cdc.UnmarshalInterface(wasmClientState.Data, &unwrappedClientState); err != nil { - return err - } - - return w.delegate.ValidateSelfClient(ctx, unwrappedClientState) -} diff --git a/modules/light-clients/08-wasm/types/consensus_host_test.go b/modules/light-clients/08-wasm/types/consensus_host_test.go deleted file mode 100644 index d85c8143191..00000000000 --- a/modules/light-clients/08-wasm/types/consensus_host_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package types_test - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - wasmtesting "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing" - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v9/modules/core/exported" - ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" - "github.com/cosmos/ibc-go/v9/testing/mock" -) - -func (suite *TypesTestSuite) TestGetSelfConsensusState() { - var ( - consensusHost clienttypes.ConsensusHost - consensusState exported.ConsensusState - height clienttypes.Height - ) - - cases := []struct { - name string - malleate func() - expError error - }{ - { - name: "success", - malleate: func() {}, - expError: nil, - }, - { - name: "failure: delegate error", - malleate: func() { - consensusHost.(*mock.ConsensusHost).GetSelfConsensusStateFn = func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - return nil, mock.MockApplicationCallbackError - } - }, - expError: mock.MockApplicationCallbackError, - }, - } - - for i, tc := range cases { - tc := tc - suite.Run(tc.name, func() { - suite.SetupTest() - height = clienttypes.ZeroHeight() - - wrappedClientConsensusStateBz := clienttypes.MustMarshalConsensusState(suite.chainA.App.AppCodec(), wasmtesting.MockTendermintClientConsensusState) - consensusState = types.NewConsensusState(wrappedClientConsensusStateBz) - - consensusHost = &mock.ConsensusHost{ - GetSelfConsensusStateFn: func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - return consensusState, nil - }, - } - - tc.malleate() - - var err error - consensusHost, err = types.NewWasmConsensusHost(suite.chainA.Codec, consensusHost) - suite.Require().NoError(err) - - suite.chainA.App.GetIBCKeeper().SetConsensusHost(consensusHost) - - cs, err := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetSelfConsensusState(suite.chainA.GetContext(), height) - - expPass := tc.expError == nil - if expPass { - suite.Require().NoError(err, "Case %d should have passed: %s", i, tc.name) - suite.Require().NotNil(cs, "Case %d should have passed: %s", i, tc.name) - suite.Require().NotNil(cs.(*types.ConsensusState).Data, "Case %d should have passed: %s", i, tc.name) - } else { - suite.Require().ErrorIs(err, tc.expError, "Case %d should have failed: %s", i, tc.name) - suite.Require().Nil(cs, "Case %d should have failed: %s", i, tc.name) - } - }) - } -} - -func (suite *TypesTestSuite) TestValidateSelfClient() { - var ( - mockChecksum = []byte("checksum") - clientState exported.ClientState - consensusHost clienttypes.ConsensusHost - ) - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - name: "success", - malleate: func() {}, - expError: nil, - }, - { - name: "failure: invalid data", - malleate: func() { - clientState = types.NewClientState(nil, wasmtesting.Code, clienttypes.ZeroHeight()) - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "failure: invalid clientstate type", - malleate: func() { - clientState = &ibctm.ClientState{} - }, - expError: clienttypes.ErrInvalidClient, - }, - { - name: "failure: delegate error propagates", - malleate: func() { - consensusHost.(*mock.ConsensusHost).ValidateSelfClientFn = func(ctx sdk.Context, clientState exported.ClientState) error { - return mock.MockApplicationCallbackError - } - }, - expError: mock.MockApplicationCallbackError, - }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(tc.name, func() { - suite.SetupTest() - - clientState = types.NewClientState(wasmtesting.CreateMockClientStateBz(suite.chainA.Codec, mockChecksum), wasmtesting.Code, clienttypes.ZeroHeight()) - consensusHost = &mock.ConsensusHost{} - - tc.malleate() - - var err error - consensusHost, err = types.NewWasmConsensusHost(suite.chainA.Codec, consensusHost) - suite.Require().NoError(err) - - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetConsensusHost(consensusHost) - - err = suite.chainA.App.GetIBCKeeper().ClientKeeper.ValidateSelfClient(suite.chainA.GetContext(), clientState) - - expPass := tc.expError == nil - if expPass { - suite.Require().NoError(err, "expected valid client for case: %s", tc.name) - } else { - suite.Require().ErrorIs(err, tc.expError, "expected %s got %s", tc.expError, err) - } - }) - } -} diff --git a/proto/ibc/core/connection/v1/tx.proto b/proto/ibc/core/connection/v1/tx.proto index b0cd777d1b8..151f72fb2d0 100644 --- a/proto/ibc/core/connection/v1/tx.proto +++ b/proto/ibc/core/connection/v1/tx.proto @@ -59,23 +59,25 @@ message MsgConnectionOpenTry { string client_id = 1; // Deprecated: this field is unused. Crossing hellos are no longer supported in core IBC. - string previous_connection_id = 2 [deprecated = true]; - google.protobuf.Any client_state = 3; - Counterparty counterparty = 4 [(gogoproto.nullable) = false]; - uint64 delay_period = 5; - repeated Version counterparty_versions = 6; - ibc.core.client.v1.Height proof_height = 7 [(gogoproto.nullable) = false]; + string previous_connection_id = 2 [deprecated = true]; + // Deprecated: this field is unused. + google.protobuf.Any client_state = 3 [deprecated = true]; + Counterparty counterparty = 4 [(gogoproto.nullable) = false]; + uint64 delay_period = 5; + repeated Version counterparty_versions = 6; + ibc.core.client.v1.Height proof_height = 7 [(gogoproto.nullable) = false]; // proof of the initialization the connection on Chain A: `UNINITIALIZED -> // INIT` bytes proof_init = 8; - // proof of client state included in message - bytes proof_client = 9; - // proof of client consensus state - bytes proof_consensus = 10; - ibc.core.client.v1.Height consensus_height = 11 [(gogoproto.nullable) = false]; + // Deprecated: this field is unused. + bytes proof_client = 9 [deprecated = true]; + // Deprecated: this field is unused. + bytes proof_consensus = 10 [deprecated = true]; + // Deprecated: this field is unused. + ibc.core.client.v1.Height consensus_height = 11 [deprecated = true]; string signer = 12; - // optional proof data for host state machines that are unable to introspect their own consensus state - bytes host_consensus_state_proof = 13; + // Deprecated: this field is unused. + bytes host_consensus_state_proof = 13 [deprecated = true]; } // MsgConnectionOpenTryResponse defines the Msg/ConnectionOpenTry response type. @@ -88,22 +90,24 @@ message MsgConnectionOpenAck { option (gogoproto.goproto_getters) = false; - string connection_id = 1; - string counterparty_connection_id = 2; - Version version = 3; - google.protobuf.Any client_state = 4; - ibc.core.client.v1.Height proof_height = 5 [(gogoproto.nullable) = false]; + string connection_id = 1; + string counterparty_connection_id = 2; + Version version = 3; + // Deprecated: this field is unused. + google.protobuf.Any client_state = 4 [deprecated = true]; + ibc.core.client.v1.Height proof_height = 5 [(gogoproto.nullable) = false]; // proof of the initialization the connection on Chain B: `UNINITIALIZED -> // TRYOPEN` bytes proof_try = 6; - // proof of client state included in message - bytes proof_client = 7; - // proof of client consensus state - bytes proof_consensus = 8; - ibc.core.client.v1.Height consensus_height = 9 [(gogoproto.nullable) = false]; + // Deprecated: this field is unused. + bytes proof_client = 7 [deprecated = true]; + // Deprecated: this field is unused. + bytes proof_consensus = 8 [deprecated = true]; + // Deprecated: this field is unused. + ibc.core.client.v1.Height consensus_height = 9 [deprecated = true]; string signer = 10; - // optional proof data for host state machines that are unable to introspect their own consensus state - bytes host_consensus_state_proof = 11; + // Deprecated: this field is unused. + bytes host_consensus_state_proof = 11 [deprecated = true]; } // MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type. @@ -143,4 +147,4 @@ message MsgUpdateParams { } // MsgUpdateParamsResponse defines the MsgUpdateParams response type. -message MsgUpdateParamsResponse {} \ No newline at end of file +message MsgUpdateParamsResponse {} diff --git a/simapp/app.go b/simapp/app.go index 89cf28c63b8..c40fc75e681 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -404,7 +404,7 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) govConfig := govtypes.DefaultConfig() diff --git a/testing/endpoint.go b/testing/endpoint.go index a790cdd8be7..92bad3331c3 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -244,13 +244,12 @@ func (endpoint *Endpoint) ConnOpenTry() error { err := endpoint.UpdateClient() require.NoError(endpoint.Chain.TB, err) - counterpartyClient, clientProof, consensusProof, consensusHeight, initProof, proofHeight := endpoint.QueryConnectionHandshakeProof() + initProof, proofHeight := endpoint.QueryConnectionHandshakeProof() msg := connectiontypes.NewMsgConnectionOpenTry( endpoint.ClientID, endpoint.Counterparty.ConnectionID, endpoint.Counterparty.ClientID, - counterpartyClient, endpoint.Counterparty.Chain.GetPrefix(), []*connectiontypes.Version{ConnectionVersion}, endpoint.ConnectionConfig.DelayPeriod, - initProof, clientProof, consensusProof, - proofHeight, consensusHeight, + endpoint.Counterparty.Chain.GetPrefix(), []*connectiontypes.Version{ConnectionVersion}, + endpoint.ConnectionConfig.DelayPeriod, initProof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String(), ) res, err := endpoint.Chain.SendMsgs(msg) @@ -271,13 +270,11 @@ func (endpoint *Endpoint) ConnOpenAck() error { err := endpoint.UpdateClient() require.NoError(endpoint.Chain.TB, err) - counterpartyClient, clientProof, consensusProof, consensusHeight, tryProof, proofHeight := endpoint.QueryConnectionHandshakeProof() + tryProof, proofHeight := endpoint.QueryConnectionHandshakeProof() msg := connectiontypes.NewMsgConnectionOpenAck( - endpoint.ConnectionID, endpoint.Counterparty.ConnectionID, counterpartyClient, // testing doesn't use flexible selection - tryProof, clientProof, consensusProof, - proofHeight, consensusHeight, - ConnectionVersion, + endpoint.ConnectionID, endpoint.Counterparty.ConnectionID, // testing doesn't use flexible selection + tryProof, proofHeight, ConnectionVersion, endpoint.Chain.SenderAccount.GetAddress().String(), ) return endpoint.Chain.sendMsgs(msg) @@ -300,33 +297,15 @@ func (endpoint *Endpoint) ConnOpenConfirm() error { } // QueryConnectionHandshakeProof returns all the proofs necessary to execute OpenTry or Open Ack of -// the connection handshakes. It returns the counterparty client state, proof of the counterparty -// client state, proof of the counterparty consensus state, the consensus state height, proof of -// the counterparty connection, and the proof height for all the proofs returned. +// the connection handshakes. It returns the proof of the counterparty connection and the proof height. func (endpoint *Endpoint) QueryConnectionHandshakeProof() ( - clientState exported.ClientState, clientProof, - consensusProof []byte, consensusHeight clienttypes.Height, connectionProof []byte, proofHeight clienttypes.Height, ) { - // obtain the client state on the counterparty chain - clientState = endpoint.Counterparty.Chain.GetClientState(endpoint.Counterparty.ClientID) - - // query proof for the client state on the counterparty - clientKey := host.FullClientStateKey(endpoint.Counterparty.ClientID) - clientProof, proofHeight = endpoint.Counterparty.QueryProof(clientKey) - - var ok bool - consensusHeight, ok = endpoint.Counterparty.GetClientLatestHeight().(clienttypes.Height) - require.True(endpoint.Chain.TB, ok) - // query proof for the consensus state on the counterparty - consensusKey := host.FullConsensusStateKey(endpoint.Counterparty.ClientID, consensusHeight) - consensusProof, _ = endpoint.Counterparty.QueryProofAtHeight(consensusKey, proofHeight.GetRevisionHeight()) - // query proof for the connection on the counterparty connectionKey := host.ConnectionKey(endpoint.Counterparty.ConnectionID) - connectionProof, _ = endpoint.Counterparty.QueryProofAtHeight(connectionKey, proofHeight.GetRevisionHeight()) + connectionProof, proofHeight = endpoint.Counterparty.QueryProof(connectionKey) - return clientState, clientProof, consensusProof, consensusHeight, connectionProof, proofHeight + return connectionProof, proofHeight } var sequenceNumber int diff --git a/testing/mock/consensus_host.go b/testing/mock/consensus_host.go deleted file mode 100644 index 00d0773a3cc..00000000000 --- a/testing/mock/consensus_host.go +++ /dev/null @@ -1,31 +0,0 @@ -package mock - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v9/modules/core/exported" -) - -var _ clienttypes.ConsensusHost = (*ConsensusHost)(nil) - -type ConsensusHost struct { - GetSelfConsensusStateFn func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) - ValidateSelfClientFn func(ctx sdk.Context, clientState exported.ClientState) error -} - -func (cv *ConsensusHost) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { - if cv.GetSelfConsensusStateFn == nil { - return nil, nil - } - - return cv.GetSelfConsensusStateFn(ctx, height) -} - -func (cv *ConsensusHost) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { - if cv.ValidateSelfClientFn == nil { - return nil - } - - return cv.ValidateSelfClientFn(ctx, clientState) -} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index dca117000b3..6ebf791d319 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -367,7 +367,7 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) govConfig := govtypes.DefaultConfig() diff --git a/testing/solomachine.go b/testing/solomachine.go index 4b57ae2dac1..cca8908a33a 100644 --- a/testing/solomachine.go +++ b/testing/solomachine.go @@ -24,7 +24,6 @@ import ( host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" - ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ) var ( @@ -287,18 +286,9 @@ func (solo *Solomachine) ConnOpenInit(chain *TestChain, clientID string) string func (solo *Solomachine) ConnOpenAck(chain *TestChain, clientID, connectionID string) { tryProof := solo.GenerateConnOpenTryProof(clientID, connectionID) - clientState := ibctm.NewClientState(chain.ChainID, DefaultTrustLevel, TrustingPeriod, UnbondingPeriod, MaxClockDrift, chain.LatestCommittedHeader.GetHeight().(clienttypes.Height), commitmenttypes.GetSDKSpecs(), UpgradePath) - clientProof := solo.GenerateClientStateProof(clientState) - - consensusState := chain.LatestCommittedHeader.ConsensusState() - consensusHeight := chain.LatestCommittedHeader.GetHeight() - consensusProof := solo.GenerateConsensusStateProof(consensusState, consensusHeight) - msgConnOpenAck := connectiontypes.NewMsgConnectionOpenAck( - connectionID, connectionIDSolomachine, clientState, - tryProof, clientProof, consensusProof, - clienttypes.ZeroHeight(), clientState.LatestHeight, - ConnectionVersion, + connectionID, connectionIDSolomachine, tryProof, + clienttypes.ZeroHeight(), ConnectionVersion, chain.SenderAccount.GetAddress().String(), ) @@ -513,42 +503,6 @@ func (solo *Solomachine) GenerateProof(signBytes *solomachine.SignBytes) []byte return proof } -// GenerateClientStateProof generates the proof of the client state required for the connection open try and ack handshake steps. -// The client state should be the self client states of the tendermint chain. -func (solo *Solomachine) GenerateClientStateProof(clientState exported.ClientState) []byte { - data, err := clienttypes.MarshalClientState(solo.cdc, clientState) - require.NoError(solo.t, err) - - path := host.FullClientStateKey(clientIDSolomachine) - signBytes := &solomachine.SignBytes{ - Sequence: solo.Sequence, - Timestamp: solo.Time, - Diversifier: solo.Diversifier, - Path: path, - Data: data, - } - - return solo.GenerateProof(signBytes) -} - -// GenerateConsensusStateProof generates the proof of the consensus state required for the connection open try and ack handshake steps. -// The consensus state should be the self consensus states of the tendermint chain. -func (solo *Solomachine) GenerateConsensusStateProof(consensusState exported.ConsensusState, consensusHeight exported.Height) []byte { - data, err := clienttypes.MarshalConsensusState(solo.cdc, consensusState) - require.NoError(solo.t, err) - - path := host.FullConsensusStateKey(clientIDSolomachine, consensusHeight) - signBytes := &solomachine.SignBytes{ - Sequence: solo.Sequence, - Timestamp: solo.Time, - Diversifier: solo.Diversifier, - Path: path, - Data: data, - } - - return solo.GenerateProof(signBytes) -} - // GenerateConnOpenTryProof generates the proofTry required for the connection open ack handshake step. // The clientID, connectionID provided represent the clientID and connectionID created on the counterparty chain, that is the tendermint chain. func (solo *Solomachine) GenerateConnOpenTryProof(counterpartyClientID, counterpartyConnectionID string) []byte {