From eb51dff486b34d176d9b2c8ca3f7fb24a4ae4d21 Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 2 Sep 2024 13:38:06 +0200 Subject: [PATCH 1/3] chore: context cleanup (4/n) (#7217) * migrate context part 1 * ++ * ++ * ++ * ++ * ++fafo * p2 * capability changes * fix capability * remove todos * linting * build * more context cleanup * more cleanup * fix unwrap * chore(linter): fix linter madness * chore: replace TODOs with issue number * chore(linter): fix linter madness * Update modules/apps/27-interchain-accounts/host/keeper/relay.go * chore: remove todo in favour of migrations issue * Update modules/apps/27-interchain-accounts/host/keeper/migrations.go --------- Co-authored-by: DimitrisJim Co-authored-by: Damian Nolan --- .../controller/keeper/export_test.go | 4 +- .../controller/keeper/migrations.go | 7 ++- .../controller/keeper/relay.go | 7 ++- .../host/ibc_module_test.go | 2 +- .../host/keeper/export_test.go | 4 +- .../host/keeper/genesis.go | 7 +-- .../host/keeper/migrations.go | 7 ++- .../host/keeper/relay.go | 2 +- .../host/keeper/relay_test.go | 3 +- modules/apps/29-fee/keeper/genesis.go | 6 +- .../02-client/migrations/v7/solomachine.go | 36 ++++++------ modules/core/03-connection/genesis.go | 6 +- modules/core/03-connection/keeper/events.go | 22 +++++--- .../core/03-connection/keeper/handshake.go | 11 ++-- .../03-connection/migrations/v7/localhost.go | 6 +- modules/core/04-channel/genesis.go | 7 +-- modules/core/04-channel/keeper/events.go | 56 +++++++++++-------- modules/core/04-channel/keeper/handshake.go | 22 ++++---- modules/core/04-channel/keeper/packet.go | 21 ++++--- modules/core/04-channel/keeper/timeout.go | 9 ++- modules/core/04-channel/keeper/upgrade.go | 54 +++++++++--------- .../07-tendermint/migrations/migrations.go | 5 +- modules/light-clients/07-tendermint/store.go | 6 +- 23 files changed, 170 insertions(+), 140 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go index 154d8d3aee6..c580aa61005 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go @@ -5,12 +5,12 @@ package keeper */ import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" ) // GetAppMetadata is a wrapper around getAppMetadata to allow the function to be directly called in tests. -func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) { +func (k Keeper) GetAppMetadata(ctx context.Context, portID, channelID string) (icatypes.Metadata, error) { return k.getAppMetadata(ctx, portID, channelID) } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index ad69ceacc65..bd43a02c420 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" controllertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types" @@ -19,11 +21,12 @@ func NewMigrator(k *Keeper) Migrator { } // MigrateParams migrates the controller submodule's parameters from the x/params to self store. -func (m Migrator) MigrateParams(ctx sdk.Context) error { +func (m Migrator) MigrateParams(ctx context.Context) error { if m.keeper != nil { params := controllertypes.DefaultParams() if m.keeper.legacySubspace != nil { - m.keeper.legacySubspace.GetParamSetIfExists(ctx, ¶ms) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + m.keeper.legacySubspace.GetParamSetIfExists(sdkCtx, ¶ms) } m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated ica/controller submodule to self-manage params") diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index 04e29aa82a5..d33f82c5da4 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -24,11 +24,11 @@ import ( // Prior to v6.x.x of ibc-go, the controller module was only functional as middleware, with authentication performed // by the underlying application. For a full summary of the changes in v6.x.x, please see ADR009. // This API will be removed in later releases. -func (k Keeper) SendTx(ctx sdk.Context, _ *capabilitytypes.Capability, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { +func (k Keeper) SendTx(ctx context.Context, _ *capabilitytypes.Capability, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { return k.sendTx(ctx, connectionID, portID, icaPacketData, timeoutTimestamp) } -func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { +func (k Keeper) sendTx(ctx context.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { if !k.GetParams(ctx).ControllerEnabled { return 0, types.ErrControllerSubModuleDisabled } @@ -38,7 +38,8 @@ func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketDa return 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) } - if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp { + sdkCtx := sdk.UnwrapSDKContext(ctx) + if uint64(sdkCtx.BlockTime().UnixNano()) >= timeoutTimestamp { return 0, icatypes.ErrInvalidTimeoutTimestamp } diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index ba88fbdd3fa..7ef5894ad4d 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -785,7 +785,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() { } } -func (suite *InterchainAccountsTestSuite) fundICAWallet(ctx sdk.Context, portID string, amount sdk.Coins) { +func (suite *InterchainAccountsTestSuite) fundICAWallet(ctx context.Context, portID string, amount sdk.Coins) { interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, ibctesting.FirstConnectionID, portID) suite.Require().True(found) diff --git a/modules/apps/27-interchain-accounts/host/keeper/export_test.go b/modules/apps/27-interchain-accounts/host/keeper/export_test.go index 0d33f9e5006..c9916e1b3b4 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/export_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/export_test.go @@ -5,13 +5,13 @@ package keeper */ import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" ) // GetAppMetadata is a wrapper around getAppMetadata to allow the function to be directly called in tests. -func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) { +func (k Keeper) GetAppMetadata(ctx context.Context, portID, channelID string) (icatypes.Metadata, error) { return k.getAppMetadata(ctx, portID, channelID) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 4af3cbe7f39..9fc935907a4 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -1,17 +1,16 @@ package keeper import ( + "context" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - genesistypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/genesis/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ) // InitGenesis initializes the interchain accounts host application state from a provided genesis state -func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisState) { +func InitGenesis(ctx context.Context, keeper Keeper, state genesistypes.HostGenesisState) { keeper.setPort(ctx, state.Port) // generate port capability if it does not already exist @@ -40,7 +39,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS } // ExportGenesis returns the interchain accounts host exported genesis -func ExportGenesis(ctx sdk.Context, keeper Keeper) genesistypes.HostGenesisState { +func ExportGenesis(ctx context.Context, keeper Keeper) genesistypes.HostGenesisState { return genesistypes.NewHostGenesisState( keeper.GetAllActiveChannels(ctx), keeper.GetAllInterchainAccounts(ctx), diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go index 1dcc95fd71c..ea0fb9374f5 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types" @@ -19,11 +21,12 @@ func NewMigrator(k *Keeper) Migrator { } // MigrateParams migrates the host submodule's parameters from the x/params to self store. -func (m Migrator) MigrateParams(ctx sdk.Context) error { +func (m Migrator) MigrateParams(ctx context.Context) error { if m.keeper != nil { params := types.DefaultParams() if m.keeper.legacySubspace != nil { - m.keeper.legacySubspace.GetParamSetIfExists(ctx, ¶ms) + sdkCtx := sdk.UnwrapSDKContext(ctx) + m.keeper.legacySubspace.GetParamSetIfExists(sdkCtx, ¶ms) } if err := params.Validate(); err != nil { return err diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index cc395a1197a..1cfaf2d9cfe 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -131,7 +131,7 @@ func (k Keeper) authenticateTx(ctx context.Context, msgs []sdk.Msg, connectionID // Attempts to get the message handler from the router and if found will then execute the message. // If the message execution is successful, the proto marshaled message response will be returned. -func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error) { +func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error) { // TODO: https://github.com/cosmos/ibc-go/issues/7223 handler := k.msgRouter.Handler(msg) if handler == nil { return nil, icatypes.ErrInvalidRoute diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go index b4cbacfcf01..75e5962854a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "fmt" "strings" "time" @@ -886,7 +887,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() { } } -func (suite *KeeperTestSuite) fundICAWallet(ctx sdk.Context, portID string, amount sdk.Coins) { +func (suite *KeeperTestSuite) fundICAWallet(ctx context.Context, portID string, amount sdk.Coins) { interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, ibctesting.FirstConnectionID, portID) suite.Require().True(found) diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index 913f24c72fd..c407238f772 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -1,13 +1,13 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types" ) // InitGenesis initializes the fee middleware application state from a provided genesis state -func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { +func (k Keeper) InitGenesis(ctx context.Context, state types.GenesisState) { for _, identifiedFees := range state.IdentifiedFees { k.SetFeesInEscrow(ctx, identifiedFees.PacketId, types.NewPacketFees(identifiedFees.PacketFees)) } @@ -30,7 +30,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { } // ExportGenesis returns the fee middleware application exported genesis -func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { +func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { return &types.GenesisState{ IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), FeeEnabledChannels: k.GetAllFeeEnabledChannels(ctx), diff --git a/modules/core/02-client/migrations/v7/solomachine.go b/modules/core/02-client/migrations/v7/solomachine.go index c350fc53d77..7999b9279d8 100644 --- a/modules/core/02-client/migrations/v7/solomachine.go +++ b/modules/core/02-client/migrations/v7/solomachine.go @@ -1,6 +1,7 @@ package v7 import ( + "context" "errors" storetypes "cosmossdk.io/store/types" @@ -8,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -63,7 +63,7 @@ func (ClientState) GetLatestHeight() exported.Height { } // Status panics! -func (ClientState) Status(_ sdk.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status { +func (ClientState) Status(_ context.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status { panic(errors.New("legacy solo machine is deprecated")) } @@ -73,51 +73,51 @@ func (ClientState) Validate() error { } // Initialize panics! -func (ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ConsensusState) error { +func (ClientState) Initialize(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ConsensusState) error { panic(errors.New("legacy solo machine is deprecated")) } // CheckForMisbehaviour panics! -func (ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) bool { +func (ClientState) CheckForMisbehaviour(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) bool { panic(errors.New("legacy solo machine is deprecated")) } // UpdateStateOnMisbehaviour panics! func (*ClientState) UpdateStateOnMisbehaviour( - _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, + _ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) { panic(errors.New("legacy solo machine is deprecated")) } // VerifyClientMessage panics! func (*ClientState) VerifyClientMessage( - _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, + _ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) error { panic(errors.New("legacy solo machine is deprecated")) } // UpdateState panis! -func (*ClientState) UpdateState(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) []exported.Height { +func (*ClientState) UpdateState(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) []exported.Height { panic(errors.New("legacy solo machine is deprecated")) } // CheckHeaderAndUpdateState panics! func (*ClientState) CheckHeaderAndUpdateState( - _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, + _ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) (exported.ClientState, exported.ConsensusState, error) { panic(errors.New("legacy solo machine is deprecated")) } // CheckMisbehaviourAndUpdateState panics! func (ClientState) CheckMisbehaviourAndUpdateState( - _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, + _ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) (exported.ClientState, error) { panic(errors.New("legacy solo machine is deprecated")) } // CheckSubstituteAndUpdateState panics! func (ClientState) CheckSubstituteAndUpdateState( - ctx sdk.Context, _ codec.BinaryCodec, _, _ storetypes.KVStore, + ctx context.Context, _ codec.BinaryCodec, _, _ storetypes.KVStore, _ exported.ClientState, ) error { panic(errors.New("legacy solo machine is deprecated")) @@ -125,7 +125,7 @@ func (ClientState) CheckSubstituteAndUpdateState( // VerifyUpgradeAndUpdateState panics! func (ClientState) VerifyUpgradeAndUpdateState( - _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, + _ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientState, _ exported.ConsensusState, _, _ []byte, ) error { panic(errors.New("legacy solo machine is deprecated")) @@ -150,7 +150,7 @@ func (ClientState) VerifyClientConsensusState( // VerifyPacketCommitment panics! func (ClientState) VerifyPacketCommitment( - sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, + context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, uint64, uint64, exported.Prefix, []byte, string, string, uint64, []byte, ) error { @@ -159,7 +159,7 @@ func (ClientState) VerifyPacketCommitment( // VerifyPacketAcknowledgement panics! func (ClientState) VerifyPacketAcknowledgement( - sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, + context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, uint64, uint64, exported.Prefix, []byte, string, string, uint64, []byte, ) error { @@ -168,7 +168,7 @@ func (ClientState) VerifyPacketAcknowledgement( // VerifyPacketReceiptAbsence panics! func (ClientState) VerifyPacketReceiptAbsence( - sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, + context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, uint64, uint64, exported.Prefix, []byte, string, string, uint64, ) error { @@ -177,7 +177,7 @@ func (ClientState) VerifyPacketReceiptAbsence( // VerifyNextSequenceRecv panics! func (ClientState) VerifyNextSequenceRecv( - sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, + context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, uint64, uint64, exported.Prefix, []byte, string, string, uint64, ) error { @@ -186,14 +186,14 @@ func (ClientState) VerifyNextSequenceRecv( // GetTimestampAtHeight panics! func (ClientState) GetTimestampAtHeight( - sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, + context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, ) (uint64, error) { panic(errors.New("legacy solo machine is deprecated")) } // VerifyMembership panics! func (*ClientState) VerifyMembership( - ctx sdk.Context, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, height exported.Height, @@ -208,7 +208,7 @@ func (*ClientState) VerifyMembership( // VerifyNonMembership panics! func (*ClientState) VerifyNonMembership( - ctx sdk.Context, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, height exported.Height, diff --git a/modules/core/03-connection/genesis.go b/modules/core/03-connection/genesis.go index 91b6d5a9bdf..a7fbfb4e5d7 100644 --- a/modules/core/03-connection/genesis.go +++ b/modules/core/03-connection/genesis.go @@ -1,7 +1,7 @@ package connection import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" @@ -9,7 +9,7 @@ import ( // InitGenesis initializes the ibc connection submodule's state from a provided genesis // state. -func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) { +func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { for _, connection := range gs.Connections { conn := types.NewConnectionEnd(connection.State, connection.ClientId, connection.Counterparty, connection.Versions, connection.DelayPeriod) k.SetConnection(ctx, connection.Id, conn) @@ -24,7 +24,7 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) { } // ExportGenesis returns the ibc connection submodule's exported genesis. -func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) types.GenesisState { +func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { return types.GenesisState{ Connections: k.GetAllConnections(ctx), ClientConnectionPaths: k.GetAllClientConnectionPaths(ctx), diff --git a/modules/core/03-connection/keeper/events.go b/modules/core/03-connection/keeper/events.go index 0e5cb03eade..04d0bb4851d 100644 --- a/modules/core/03-connection/keeper/events.go +++ b/modules/core/03-connection/keeper/events.go @@ -1,14 +1,17 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" ) // emitConnectionOpenInitEvent emits a connection open init event -func emitConnectionOpenInitEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitConnectionOpenInitEvent(ctx context.Context, connectionID string, clientID string, counterparty types.Counterparty) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenInit, sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), @@ -23,8 +26,9 @@ func emitConnectionOpenInitEvent(ctx sdk.Context, connectionID string, clientID } // emitConnectionOpenTryEvent emits a connection open try event -func emitConnectionOpenTryEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitConnectionOpenTryEvent(ctx context.Context, connectionID string, clientID string, counterparty types.Counterparty) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenTry, sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), @@ -40,8 +44,9 @@ func emitConnectionOpenTryEvent(ctx sdk.Context, connectionID string, clientID s } // emitConnectionOpenAckEvent emits a connection open acknowledge event -func emitConnectionOpenAckEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitConnectionOpenAckEvent(ctx context.Context, connectionID string, connectionEnd types.ConnectionEnd) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenAck, sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), @@ -57,8 +62,9 @@ func emitConnectionOpenAckEvent(ctx sdk.Context, connectionID string, connection } // emitConnectionOpenConfirmEvent emits a connection open confirm event -func emitConnectionOpenConfirmEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitConnectionOpenConfirmEvent(ctx context.Context, connectionID string, connectionEnd types.ConnectionEnd) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeConnectionOpenConfirm, sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index 1e646b787e3..0b52d58991a 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -1,10 +1,11 @@ package keeper import ( + "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" - 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" @@ -18,7 +19,7 @@ import ( // NOTE: Msg validation verifies the supplied identifiers and ensures that the counterparty // connection identifier is empty. func (k *Keeper) ConnOpenInit( - ctx sdk.Context, + ctx context.Context, clientID string, counterparty types.Counterparty, // counterpartyPrefix, counterpartyClientIdentifier version *types.Version, @@ -62,7 +63,7 @@ func (k *Keeper) ConnOpenInit( // - Here chain A acts as the counterparty // - Identifiers are checked on msg validation func (k *Keeper) ConnOpenTry( - ctx sdk.Context, + ctx context.Context, counterparty types.Counterparty, // counterpartyConnectionIdentifier, counterpartyPrefix and counterpartyClientIdentifier delayPeriod uint64, clientID string, // clientID of chainA @@ -119,7 +120,7 @@ func (k *Keeper) ConnOpenTry( // // NOTE: Identifiers are checked on msg validation. func (k *Keeper) ConnOpenAck( - ctx sdk.Context, + ctx context.Context, connectionID string, version *types.Version, // version that ChainB chose in ConnOpenTry counterpartyConnectionID string, @@ -180,7 +181,7 @@ func (k *Keeper) ConnOpenAck( // // NOTE: Identifiers are checked on msg validation. func (k *Keeper) ConnOpenConfirm( - ctx sdk.Context, + ctx context.Context, connectionID string, ackProof []byte, // proof that connection opened on ChainA during ConnOpenAck proofHeight exported.Height, // height that relayer constructed proofAck diff --git a/modules/core/03-connection/migrations/v7/localhost.go b/modules/core/03-connection/migrations/v7/localhost.go index 76f768402de..6c85a1f837d 100644 --- a/modules/core/03-connection/migrations/v7/localhost.go +++ b/modules/core/03-connection/migrations/v7/localhost.go @@ -1,11 +1,9 @@ package v7 -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) +import "context" // MigrateLocalhostConnection creates the sentinel localhost connection end to enable // localhost ibc functionality. -func MigrateLocalhostConnection(ctx sdk.Context, connectionKeeper ConnectionKeeper) { +func MigrateLocalhostConnection(ctx context.Context, connectionKeeper ConnectionKeeper) { connectionKeeper.CreateSentinelLocalhostConnection(ctx) } diff --git a/modules/core/04-channel/genesis.go b/modules/core/04-channel/genesis.go index 905b66bdd6f..416d5cacfd6 100644 --- a/modules/core/04-channel/genesis.go +++ b/modules/core/04-channel/genesis.go @@ -1,17 +1,16 @@ package channel import ( + "context" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" ) // InitGenesis initializes the ibc channel submodule's state from a provided genesis // state. -func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) { +func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { if err := gs.Params.Validate(); err != nil { panic(fmt.Sprintf("invalid ibc channel genesis state parameters: %v", err)) } @@ -42,7 +41,7 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) { } // ExportGenesis returns the ibc channel submodule's exported genesis. -func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) types.GenesisState { +func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { return types.GenesisState{ Channels: k.GetAllChannels(ctx), Acknowledgements: k.GetAllPacketAcks(ctx), diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index 6b7de9e973f..fad33c9808b 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "encoding/hex" "fmt" @@ -11,8 +12,9 @@ import ( ) // emitChannelOpenInitEvent emits a channel open init event -func emitChannelOpenInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelOpenInitEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenInit, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -29,8 +31,9 @@ func emitChannelOpenInitEvent(ctx sdk.Context, portID string, channelID string, } // emitChannelOpenTryEvent emits a channel open try event -func emitChannelOpenTryEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelOpenTryEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenTry, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -48,8 +51,9 @@ func emitChannelOpenTryEvent(ctx sdk.Context, portID string, channelID string, c } // emitChannelOpenAckEvent emits a channel open acknowledge event -func emitChannelOpenAckEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelOpenAckEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenAck, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -66,8 +70,9 @@ func emitChannelOpenAckEvent(ctx sdk.Context, portID string, channelID string, c } // emitChannelOpenConfirmEvent emits a channel open confirm event -func emitChannelOpenConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelOpenConfirmEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelOpenConfirm, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -84,8 +89,9 @@ func emitChannelOpenConfirmEvent(ctx sdk.Context, portID string, channelID strin } // emitChannelCloseInitEvent emits a channel close init event -func emitChannelCloseInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelCloseInitEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelCloseInit, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -102,8 +108,9 @@ func emitChannelCloseInitEvent(ctx sdk.Context, portID string, channelID string, } // emitChannelCloseConfirmEvent emits a channel close confirm event -func emitChannelCloseConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelCloseConfirmEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelCloseConfirm, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -202,8 +209,9 @@ func emitWriteAcknowledgementEvent(ctx sdk.Context, packet types.Packet, channel // emitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time // a packet is acknowledged for a certain sequence and for all duplicate acknowledgements. -func emitAcknowledgePacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitAcknowledgePacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeAcknowledgePacket, sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()), @@ -228,8 +236,9 @@ func emitAcknowledgePacketEvent(ctx sdk.Context, packet types.Packet, channel ty // emitTimeoutPacketEvent emits a timeout packet event. It will be emitted both the first time a packet // is timed out for a certain sequence and for all duplicate timeouts. -func emitTimeoutPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitTimeoutPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeTimeoutPacket, sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()), @@ -250,8 +259,9 @@ func emitTimeoutPacketEvent(ctx sdk.Context, packet types.Packet, channel types. } // emitChannelClosedEvent emits a channel closed event. -func emitChannelClosedEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelClosedEvent(ctx context.Context, packet types.Packet, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelClosed, sdk.NewAttribute(types.AttributeKeyPortID, packet.GetSourcePort()), @@ -381,8 +391,9 @@ func EmitChannelUpgradeTimeoutEvent(ctx sdk.Context, portID string, channelID st } // EmitErrorReceiptEvent emits an error receipt event -func EmitErrorReceiptEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel, err error) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitErrorReceiptEvent(ctx context.Context, portID string, channelID string, channel types.Channel, err error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeError, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -418,8 +429,9 @@ func EmitChannelUpgradeCancelEvent(ctx sdk.Context, portID string, channelID str } // emitChannelFlushCompleteEvent emits an flushing event. -func emitChannelFlushCompleteEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitChannelFlushCompleteEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelFlushComplete, sdk.NewAttribute(types.AttributeKeyPortID, portID), diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 0105fb211b5..a9551cb0f3d 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -1,12 +1,12 @@ package keeper import ( + "context" "fmt" errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -21,7 +21,7 @@ import ( // a module on another chain. The counterparty channel identifier is validated to be // empty in msg validation. func (k *Keeper) ChanOpenInit( - ctx sdk.Context, + ctx context.Context, order types.Order, connectionHops []string, portID string, @@ -74,7 +74,7 @@ func (k *Keeper) ChanOpenInit( // The channel is set in state and all the associated Send and Recv sequences are set to 1. // An event is emitted for the handshake step. func (k *Keeper) WriteOpenInitChannel( - ctx sdk.Context, + ctx context.Context, portID, channelID string, order types.Order, @@ -99,7 +99,7 @@ func (k *Keeper) WriteOpenInitChannel( // ChanOpenTry is called by a module to accept the first step of a channel opening // handshake initiated by a module on another chain. func (k *Keeper) ChanOpenTry( - ctx sdk.Context, + ctx context.Context, order types.Order, connectionHops []string, portID string, @@ -181,7 +181,7 @@ func (k *Keeper) ChanOpenTry( // The channel is set in state. If a previous channel state did not exist, all the Send and Recv // sequences are set to 1. An event is emitted for the handshake step. func (k *Keeper) WriteOpenTryChannel( - ctx sdk.Context, + ctx context.Context, portID, channelID string, order types.Order, @@ -207,7 +207,7 @@ func (k *Keeper) WriteOpenTryChannel( // ChanOpenAck is called by the handshake-originating module to acknowledge the // acceptance of the initial request by the counterparty module on the other chain. func (k *Keeper) ChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, chanCap *capabilitytypes.Capability, @@ -256,7 +256,7 @@ func (k *Keeper) ChanOpenAck( // WriteOpenAckChannel writes an updated channel state for the successful OpenAck handshake step. // An event is emitted for the handshake step. func (k *Keeper) WriteOpenAckChannel( - ctx sdk.Context, + ctx context.Context, portID, channelID, counterpartyVersion, @@ -282,7 +282,7 @@ func (k *Keeper) WriteOpenAckChannel( // ChanOpenConfirm is called by the handshake-accepting module to confirm the acknowledgement // of the handshake-originating module on the other chain and finish the channel opening handshake. func (k *Keeper) ChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, chanCap *capabilitytypes.Capability, @@ -333,7 +333,7 @@ func (k *Keeper) ChanOpenConfirm( // WriteOpenConfirmChannel writes an updated channel state for the successful OpenConfirm handshake step. // An event is emitted for the handshake step. func (k *Keeper) WriteOpenConfirmChannel( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) { @@ -359,7 +359,7 @@ func (k *Keeper) WriteOpenConfirmChannel( // ChanCloseInit is called by either module to close their end of the channel. Once // closed, channels cannot be reopened. func (k *Keeper) ChanCloseInit( - ctx sdk.Context, + ctx context.Context, portID, channelID string, chanCap *capabilitytypes.Capability, @@ -405,7 +405,7 @@ func (k *Keeper) ChanCloseInit( // ChanCloseConfirm is called by the counterparty module to close their end of the // channel, since the other end has been closed. func (k *Keeper) ChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, chanCap *capabilitytypes.Capability, diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index b7677740ef8..aab49c00697 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -104,7 +104,7 @@ func (k *Keeper) SendPacket( // RecvPacket is called by a module in order to receive & process an IBC packet // sent on the corresponding channel end on the counterparty chain. func (k *Keeper) RecvPacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet types.Packet, proof []byte, @@ -169,7 +169,8 @@ func (k *Keeper) RecvPacket( } // check if packet timed out by comparing it with the latest height of the chain - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) timeout := types.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) if timeout.Elapsed(selfHeight, selfTimestamp) { return "", errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "packet timeout elapsed") @@ -201,14 +202,14 @@ func (k *Keeper) RecvPacket( ) // emit an event that the relayer can query for - emitRecvPacketEvent(ctx, packet, channel) + emitRecvPacketEvent(sdkCtx, packet, channel) return channel.Version, nil } // applyReplayProtection ensures a packet has not already been received // and performs the necessary state changes to ensure it cannot be received again. -func (k *Keeper) applyReplayProtection(ctx sdk.Context, packet types.Packet, channel types.Channel) error { +func (k *Keeper) applyReplayProtection(ctx context.Context, packet types.Packet, channel types.Channel) error { // REPLAY PROTECTION: The recvStartSequence will prevent historical proofs from allowing replay // attacks on packets processed in previous lifecycles of a channel. After a successful channel // upgrade all packets under the recvStartSequence will have been processed and thus should be @@ -218,6 +219,7 @@ func (k *Keeper) applyReplayProtection(ctx sdk.Context, packet types.Packet, cha return errorsmod.Wrap(types.ErrPacketReceived, "packet already processed in previous channel upgrade") } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 switch channel.Ordering { case types.UNORDERED: // REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received @@ -225,7 +227,7 @@ func (k *Keeper) applyReplayProtection(ctx sdk.Context, packet types.Packet, cha // by the increase of the recvStartSequence. _, found := k.GetPacketReceipt(ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) if found { - emitRecvPacketEvent(ctx, packet, channel) + emitRecvPacketEvent(sdkCtx, packet, channel) // This error indicates that the packet has already been relayed. Core IBC will // treat this error as a no-op in order to prevent an entire relay transaction // from failing and consuming unnecessary fees. @@ -249,7 +251,7 @@ func (k *Keeper) applyReplayProtection(ctx sdk.Context, packet types.Packet, cha } if packet.GetSequence() < nextSequenceRecv { - emitRecvPacketEvent(ctx, packet, channel) + emitRecvPacketEvent(sdkCtx, packet, channel) // This error indicates that the packet has already been relayed. Core IBC will // treat this error as a no-op in order to prevent an entire relay transaction // from failing and consuming unnecessary fees. @@ -357,7 +359,7 @@ func (k *Keeper) WriteAcknowledgement( // which is no longer necessary since the packet has been received and acted upon. // It will also increment NextSequenceAck in case of ORDERED channels. func (k *Keeper) AcknowledgePacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet types.Packet, acknowledgement []byte, @@ -488,10 +490,11 @@ func (k *Keeper) AcknowledgePacket( // FLUSHING state. It checks if the upgrade has timed out and if so, aborts the upgrade. If all // packets have completed their lifecycle, it sets the channel state to FLUSHCOMPLETE and // emits a channel_flush_complete event. Returns true if the upgrade was aborted, false otherwise. -func (k *Keeper) handleFlushState(ctx sdk.Context, packet types.Packet, channel types.Channel) { +func (k *Keeper) handleFlushState(ctx context.Context, packet types.Packet, channel types.Channel) { if counterpartyUpgrade, found := k.GetCounterpartyUpgrade(ctx, packet.GetSourcePort(), packet.GetSourceChannel()); found { timeout := counterpartyUpgrade.Timeout - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) if timeout.Elapsed(selfHeight, selfTimestamp) { // packet flushing timeout has expired, abort the upgrade diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 99d38a9657e..06f93974e98 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -2,12 +2,11 @@ package keeper import ( "bytes" + "context" "strconv" errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" @@ -23,7 +22,7 @@ import ( // perform appropriate state transitions. Its intended usage is within the // ante handler. func (k *Keeper) TimeoutPacket( - ctx sdk.Context, + ctx context.Context, packet types.Packet, proof []byte, proofHeight exported.Height, @@ -131,7 +130,7 @@ func (k *Keeper) TimeoutPacket( // // CONTRACT: this function must be called in the IBC handler func (k *Keeper) TimeoutExecuted( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet types.Packet, ) error { @@ -192,7 +191,7 @@ func (k *Keeper) TimeoutExecuted( // which an unreceived packet was addressed has been closed, so the packet will // never be received (even if the timeoutHeight has not yet been reached). func (k *Keeper) TimeoutOnClose( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet types.Packet, proof, diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 2fd44ca10b5..cee41cbf4f0 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "reflect" "slices" @@ -20,7 +21,7 @@ import ( // ChanUpgradeInit is called by a module to initiate a channel upgrade handshake with // a module on another chain. func (k *Keeper) ChanUpgradeInit( - ctx sdk.Context, + ctx context.Context, portID string, channelID string, upgradeFields types.UpgradeFields, @@ -45,7 +46,7 @@ func (k *Keeper) ChanUpgradeInit( // WriteUpgradeInitChannel writes a channel which has successfully passed the UpgradeInit handshake step. // An event is emitted for the handshake step. -func (k *Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string) (types.Channel, types.Upgrade) { +func (k *Keeper) WriteUpgradeInitChannel(ctx context.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-init") channel, found := k.GetChannel(ctx, portID, channelID) @@ -74,7 +75,7 @@ func (k *Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID stri // ChanUpgradeTry is called by a module to accept the first step of a channel upgrade handshake initiated by // a module on another chain. If this function is successful, the proposed upgrade will be returned. If the upgrade fails, the upgrade sequence will still be incremented but an error will be returned. func (k *Keeper) ChanUpgradeTry( - ctx sdk.Context, + ctx context.Context, portID, channelID string, proposedConnectionHops []string, @@ -223,7 +224,7 @@ func (k *Keeper) ChanUpgradeTry( // WriteUpgradeTryChannel writes the channel end and upgrade to state after successfully passing the UpgradeTry handshake step. // An event is emitted for the handshake step. -func (k *Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string) (types.Channel, types.Upgrade) { +func (k *Keeper) WriteUpgradeTryChannel(ctx context.Context, portID, channelID string, upgrade types.Upgrade, upgradeVersion string) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-try") channel, found := k.GetChannel(ctx, portID, channelID) @@ -252,7 +253,7 @@ func (k *Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID strin // // A -> Init (OPEN), B -> Init (OPEN) -> A -> Try (FLUSHING), B -> Try (FLUSHING), A -> Ack (begins in FLUSHING) func (k *Keeper) ChanUpgradeAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyUpgrade types.Upgrade, @@ -340,7 +341,8 @@ func (k *Keeper) ChanUpgradeAck( } timeout := counterpartyUpgrade.Timeout - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) if timeout.Elapsed(selfHeight, selfTimestamp) { return types.NewUpgradeError(channel.UpgradeSequence, errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "counterparty upgrade timeout elapsed")) @@ -352,7 +354,7 @@ func (k *Keeper) ChanUpgradeAck( // WriteUpgradeAckChannel writes a channel which has successfully passed the UpgradeAck handshake step as well as // setting the upgrade for that channel. // An event is emitted for the handshake step. -func (k *Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) (types.Channel, types.Upgrade) { +func (k *Keeper) WriteUpgradeAckChannel(ctx context.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-ack") channel, found := k.GetChannel(ctx, portID, channelID) @@ -383,7 +385,7 @@ func (k *Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID strin // ChanUpgradeConfirm is called on the chain which is on FLUSHING after chanUpgradeAck is called on the counterparty. // This will inform the TRY chain of the timeout set on ACK by the counterparty. If the timeout has already exceeded, we will write an error receipt and restore. func (k *Keeper) ChanUpgradeConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannelState types.State, @@ -462,7 +464,8 @@ func (k *Keeper) ChanUpgradeConfirm( } timeout := counterpartyUpgrade.Timeout - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) if timeout.Elapsed(selfHeight, selfTimestamp) { return types.NewUpgradeError(channel.UpgradeSequence, errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "counterparty upgrade timeout elapsed")) @@ -475,7 +478,7 @@ func (k *Keeper) ChanUpgradeConfirm( // If the channel has no in-flight packets, its state is updated to indicate that flushing has completed. Otherwise, the counterparty upgrade is set // and the channel state is left unchanged. // An event is emitted for the handshake step. -func (k *Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) types.Channel { +func (k *Keeper) WriteUpgradeConfirmChannel(ctx context.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) types.Channel { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-confirm") channel, found := k.GetChannel(ctx, portID, channelID) @@ -498,7 +501,7 @@ func (k *Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID s // This method should only be called after both channels have flushed any in-flight packets. // This method should only be called directly by the core IBC message server. func (k *Keeper) ChanUpgradeOpen( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannelState types.State, @@ -589,7 +592,7 @@ func (k *Keeper) ChanUpgradeOpen( // WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel, and sets the channel state back to OPEN. This can be called in one of two cases: // - In the UpgradeConfirm step of the handshake if both sides have already flushed all in-flight packets. // - In the UpgradeOpen step of the handshake. -func (k *Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) types.Channel { +func (k *Keeper) WriteUpgradeOpenChannel(ctx context.Context, portID, channelID string) types.Channel { channel, found := k.GetChannel(ctx, portID, channelID) if !found { panic(fmt.Errorf("could not find existing channel when updating channel state, channelID: %s, portID: %s", channelID, portID)) @@ -651,7 +654,7 @@ func (k *Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID stri // ChanUpgradeCancel is called by the msg server to prove that an error receipt was written on the counterparty // which constitutes a valid situation where the upgrade should be cancelled. An error is returned if sufficient evidence // for cancelling the upgrade has not been provided. -func (k *Keeper) ChanUpgradeCancel(ctx sdk.Context, portID, channelID string, errorReceipt types.ErrorReceipt, errorReceiptProof []byte, proofHeight clienttypes.Height) error { +func (k *Keeper) ChanUpgradeCancel(ctx context.Context, portID, channelID string, errorReceipt types.ErrorReceipt, errorReceiptProof []byte, proofHeight clienttypes.Height) error { channel, found := k.GetChannel(ctx, portID, channelID) if !found { return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) @@ -709,7 +712,7 @@ func (k *Keeper) ChanUpgradeCancel(ctx sdk.Context, portID, channelID string, er // WriteUpgradeCancelChannel writes a channel which has canceled the upgrade process.Auxiliary upgrade state is // also deleted. -func (k *Keeper) WriteUpgradeCancelChannel(ctx sdk.Context, portID, channelID string, sequence uint64) { +func (k *Keeper) WriteUpgradeCancelChannel(ctx context.Context, portID, channelID string, sequence uint64) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-cancel") channel, found := k.GetChannel(ctx, portID, channelID) @@ -728,7 +731,7 @@ func (k *Keeper) WriteUpgradeCancelChannel(ctx sdk.Context, portID, channelID st // ChanUpgradeTimeout times out an outstanding upgrade. // This should be used by the initialising chain when the counterparty chain has not responded to an upgrade proposal within the specified timeout period. func (k *Keeper) ChanUpgradeTimeout( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannel types.Channel, counterpartyChannelProof []byte, @@ -824,7 +827,7 @@ func (k *Keeper) ChanUpgradeTimeout( // Auxiliary upgrade state is also deleted. // An event is emitted for the handshake step. func (k *Keeper) WriteUpgradeTimeoutChannel( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) (types.Channel, types.Upgrade) { defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-timeout") @@ -849,7 +852,7 @@ func (k *Keeper) WriteUpgradeTimeoutChannel( // startFlushing will set the upgrade last packet send and continue blocking the upgrade from continuing until all // in-flight packets have been flushed. -func (k *Keeper) startFlushing(ctx sdk.Context, portID, channelID string, upgrade *types.Upgrade) error { +func (k *Keeper) startFlushing(ctx context.Context, portID, channelID string, upgrade *types.Upgrade) error { channel, found := k.GetChannel(ctx, portID, channelID) if !found { return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) @@ -880,13 +883,14 @@ func (k *Keeper) startFlushing(ctx sdk.Context, portID, channelID string, upgrad } // getAbsoluteUpgradeTimeout returns the absolute timeout for the given upgrade. -func (k *Keeper) getAbsoluteUpgradeTimeout(ctx sdk.Context) types.Timeout { +func (k *Keeper) getAbsoluteUpgradeTimeout(ctx context.Context) types.Timeout { upgradeTimeout := k.GetParams(ctx).UpgradeTimeout - return types.NewTimeout(clienttypes.ZeroHeight(), uint64(ctx.BlockTime().UnixNano())+upgradeTimeout.Timestamp) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + return types.NewTimeout(clienttypes.ZeroHeight(), uint64(sdkCtx.BlockTime().UnixNano())+upgradeTimeout.Timestamp) } // checkForUpgradeCompatibility checks performs stateful validation of self upgrade fields relative to counterparty upgrade. -func (k *Keeper) checkForUpgradeCompatibility(ctx sdk.Context, upgradeFields, counterpartyUpgradeFields types.UpgradeFields) error { +func (k *Keeper) checkForUpgradeCompatibility(ctx context.Context, upgradeFields, counterpartyUpgradeFields types.UpgradeFields) error { // assert that both sides propose the same channel ordering if upgradeFields.Ordering != counterpartyUpgradeFields.Ordering { return errorsmod.Wrapf(types.ErrIncompatibleCounterpartyUpgrade, "expected upgrade ordering (%s) to match counterparty upgrade ordering (%s)", upgradeFields.Ordering, counterpartyUpgradeFields.Ordering) @@ -924,7 +928,7 @@ func (k *Keeper) checkForUpgradeCompatibility(ctx sdk.Context, upgradeFields, co // - the proposed connection hops do not exist // - the proposed version is non-empty (checked in UpgradeFields.ValidateBasic()) // - the proposed connection hops are not open -func (k *Keeper) validateSelfUpgradeFields(ctx sdk.Context, proposedUpgrade types.UpgradeFields, channel types.Channel) error { +func (k *Keeper) validateSelfUpgradeFields(ctx context.Context, proposedUpgrade types.UpgradeFields, channel types.Channel) error { currentFields := extractUpgradeFields(channel) if reflect.DeepEqual(proposedUpgrade, currentFields) { @@ -973,7 +977,7 @@ func extractUpgradeFields(channel types.Channel) types.UpgradeFields { // MustAbortUpgrade will restore the channel state to its pre-upgrade state so that upgrade is aborted. // Any unnecessary state is deleted and an error receipt is written. // This function is expected to always succeed, a panic will occur if an error occurs. -func (k *Keeper) MustAbortUpgrade(ctx sdk.Context, portID, channelID string, err error) { +func (k *Keeper) MustAbortUpgrade(ctx context.Context, portID, channelID string, err error) { if err := k.abortUpgrade(ctx, portID, channelID, err); err != nil { panic(err) } @@ -983,7 +987,7 @@ func (k *Keeper) MustAbortUpgrade(ctx sdk.Context, portID, channelID string, err // All upgrade information associated with the upgrade attempt is deleted and an upgrade error // receipt is written for that upgrade attempt. This prevents the upgrade handshake from continuing // on our side and provides proof for the counterparty to safely abort the upgrade. -func (k *Keeper) abortUpgrade(ctx sdk.Context, portID, channelID string, err error) error { +func (k *Keeper) abortUpgrade(ctx context.Context, portID, channelID string, err error) error { if err == nil { return errorsmod.Wrap(types.ErrInvalidUpgradeError, "cannot abort upgrade handshake with nil error") } @@ -1011,7 +1015,7 @@ func (k *Keeper) abortUpgrade(ctx sdk.Context, portID, channelID string, err err // restoreChannel will restore the channel state to its pre-upgrade state so that upgrade is aborted. // When an upgrade attempt is aborted, the upgrade information must be deleted. This prevents us // from continuing an upgrade handshake after we cancel an upgrade attempt. -func (k *Keeper) restoreChannel(ctx sdk.Context, portID, channelID string, upgradeSequence uint64, channel types.Channel) types.Channel { +func (k *Keeper) restoreChannel(ctx context.Context, portID, channelID string, upgradeSequence uint64, channel types.Channel) types.Channel { channel.State = types.OPEN channel.UpgradeSequence = upgradeSequence @@ -1024,7 +1028,7 @@ func (k *Keeper) restoreChannel(ctx sdk.Context, portID, channelID string, upgra } // WriteErrorReceipt will write an error receipt from the provided UpgradeError. -func (k *Keeper) WriteErrorReceipt(ctx sdk.Context, portID, channelID string, upgradeError *types.UpgradeError) { +func (k *Keeper) WriteErrorReceipt(ctx context.Context, portID, channelID string, upgradeError *types.UpgradeError) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { panic(errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)) diff --git a/modules/light-clients/07-tendermint/migrations/migrations.go b/modules/light-clients/07-tendermint/migrations/migrations.go index b1ab4f0eea6..c5457f6e684 100644 --- a/modules/light-clients/07-tendermint/migrations/migrations.go +++ b/modules/light-clients/07-tendermint/migrations/migrations.go @@ -1,10 +1,11 @@ package migrations import ( + "context" + 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" @@ -13,7 +14,7 @@ import ( // PruneExpiredConsensusStates prunes all expired tendermint consensus states. This function // may optionally be called during in-place store migrations. The ibc store key must be provided. -func PruneExpiredConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, clientKeeper ClientKeeper) (int, error) { +func PruneExpiredConsensusStates(ctx context.Context, cdc codec.BinaryCodec, clientKeeper ClientKeeper) (int, error) { var clientIDs []string clientKeeper.IterateClientStates(ctx, []byte(exported.Tendermint), func(clientID string, _ exported.ClientState) bool { clientIDs = append(clientIDs, clientID) diff --git a/modules/light-clients/07-tendermint/store.go b/modules/light-clients/07-tendermint/store.go index db6dcc64bb0..ef89b8de780 100644 --- a/modules/light-clients/07-tendermint/store.go +++ b/modules/light-clients/07-tendermint/store.go @@ -265,7 +265,7 @@ func GetPreviousConsensusState(clientStore storetypes.KVStore, cdc codec.BinaryC // client store. If a consensus state is expired, it is deleted and its metadata // is deleted. The number of consensus states pruned is returned. func PruneAllExpiredConsensusStates( - ctx sdk.Context, clientStore storetypes.KVStore, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, clientState *ClientState, ) int { var heights []exported.Height @@ -275,8 +275,8 @@ func PruneAllExpiredConsensusStates( if !found { // consensus state should always be found return true } - - if clientState.IsExpired(consState.Timestamp, ctx.BlockTime()) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + if clientState.IsExpired(consState.Timestamp, sdkCtx.BlockTime()) { heights = append(heights, height) } From eb9bcc33a170fd4fd1e705ed4c3c933128e07573 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Mon, 2 Sep 2024 13:25:19 +0100 Subject: [PATCH 2/3] chore (api)!: remove capabilities from channel handshakes (#7232) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * almost all tests working * fix last tests * solve merge error * remove newline * fix comment * docstring * docs * Update modules/core/keeper/msg_server.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * pr feedback * change error message * forgot to save a file... * merge error --------- Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- CHANGELOG.md | 1 + docs/docs/05-migrations/14-v9-to-v10.md | 1 + .../controller/ibc_middleware.go | 12 +- .../controller/ibc_middleware_test.go | 104 ++------ .../controller/keeper/handshake.go | 2 - .../controller/keeper/handshake_test.go | 10 +- .../27-interchain-accounts/host/ibc_module.go | 5 +- .../host/ibc_module_test.go | 8 +- .../host/keeper/handshake.go | 9 - .../host/keeper/handshake_test.go | 25 +- modules/apps/29-fee/ibc_middleware.go | 11 +- modules/apps/29-fee/ibc_middleware_test.go | 21 +- modules/apps/callbacks/ibc_middleware.go | 7 +- modules/apps/transfer/ibc_module.go | 14 - modules/apps/transfer/ibc_module_test.go | 27 +- modules/core/04-channel/keeper/handshake.go | 76 +----- .../core/04-channel/keeper/handshake_test.go | 198 ++------------ modules/core/04-channel/keeper/packet.go | 24 +- modules/core/04-channel/keeper/packet_test.go | 102 +------- modules/core/04-channel/keeper/timeout.go | 20 -- .../core/04-channel/keeper/timeout_test.go | 77 +----- modules/core/05-port/keeper/keeper.go | 15 +- modules/core/05-port/types/module.go | 3 - modules/core/05-port/types/router.go | 11 +- modules/core/ante/ante.go | 8 +- modules/core/ante/ante_test.go | 10 - modules/core/keeper/msg_server.go | 247 +++++------------- modules/core/keeper/msg_server_test.go | 57 ---- testing/mock/ibc_app.go | 3 - testing/mock/ibc_module.go | 24 +- testing/mock/middleware.go | 24 +- 31 files changed, 184 insertions(+), 972 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b9c2e0e64..6b855ca1a03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7213) Remove capabilities from `SendPacket`. * (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7225) Remove capabilities from `WriteAcknowledgement`. +* (core, apps) [\#7232](https://github.com/cosmos/ibc-go/pull/7232) Remove capabilities from channel handshake methods. ### State Machine Breaking diff --git a/docs/docs/05-migrations/14-v9-to-v10.md b/docs/docs/05-migrations/14-v9-to-v10.md index 2e257f1b16c..bfebba37e8d 100644 --- a/docs/docs/05-migrations/14-v9-to-v10.md +++ b/docs/docs/05-migrations/14-v9-to-v10.md @@ -20,6 +20,7 @@ There are four sections based on the four potential user groups of this document - (TODO: expand later) Removal of capabilities in `SendPacket` [\#7213](https://github.com/cosmos/ibc-go/pull/7213). - (TODO: expand later) Removal of capabilities in `WriteAcknowledgement` [\#7225](https://github.com/cosmos/ibc-go/pull/7213). +- (TODO: expand later) Removal of capabilities in channel handshake methods [\#7232](https://github.com/cosmos/ibc-go/pull/7232). ### ICS27 - Interchain Accounts diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index c697d86dc90..e90ebbb723e 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -8,14 +8,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -63,7 +61,6 @@ func (im IBCMiddleware) OnChanOpenInit( connectionHops []string, portID string, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { @@ -71,20 +68,16 @@ func (im IBCMiddleware) OnChanOpenInit( return "", types.ErrControllerSubModuleDisabled } - version, err := im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version) + version, err := im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, counterparty, version) if err != nil { return "", err } - if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } - // call underlying app's OnChanOpenInit callback with the passed in version // the version returned is discarded as the ica-auth module does not have permission to edit the version string. // ics27 will always return the version string containing the Metadata struct which is created during the `RegisterInterchainAccount` call. if im.app != nil && im.keeper.IsMiddlewareEnabled(ctx, portID, connectionHops[0]) { - if _, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, nil, counterparty, version); err != nil { + if _, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, counterparty, version); err != nil { return "", err } } @@ -99,7 +92,6 @@ func (IBCMiddleware) OnChanOpenTry( connectionHops []string, portID, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go index 11951cbe655..86be4431c7a 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -12,7 +12,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller" controllerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types" @@ -128,26 +127,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { { "success", func() {}, nil, }, - { - "ICA auth module does not claim channel capability", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, - counterparty channeltypes.Counterparty, version string, - ) (string, error) { - if chanCap != nil { - return "", fmt.Errorf("channel capability should be nil") - } - - return version, nil - } - }, nil, - }, { "ICA auth module modification of channel version is ignored", func() { // NOTE: explicitly modify the channel version via the auth module callback, // ensuring the expected JSON encoded metadata is not modified upon return suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, + portID, channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error) { return "invalid-version", nil @@ -162,7 +147,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { { "ICA auth module callback fails", func() { suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, + portID, channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error) { return "", fmt.Errorf("mock ica auth fails") @@ -179,7 +164,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, + portID, channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error) { return "", fmt.Errorf("error should be unreachable") @@ -203,9 +188,6 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { portID, err := icatypes.NewControllerPortID(TestOwnerAddress) suite.Require().NoError(err) - portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID) - suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID)) //nolint:errcheck // checking this error isn't needed for the test - path.EndpointA.ChannelConfig.PortID = portID path.EndpointA.ChannelID = ibctesting.FirstChannelID @@ -226,13 +208,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { // ensure channel on chainA is set in state suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, *channel) - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - chanCap, err := suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) if isNilApp { @@ -240,7 +216,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { } version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.Version, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel.Counterparty, channel.Version, ) if tc.expErr == nil { @@ -286,20 +262,14 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenTry() { suite.Require().Error(err) - // call application callback directly - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointB.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointB.ChannelConfig.PortID) suite.Require().True(ok) counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - chanCap, found := suite.chainA.App.GetScopedIBCKeeper().GetCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().True(found) version, err := cbs.OnChanOpenTry( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.Order, []string{path.EndpointA.ConnectionID}, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterparty, path.EndpointB.ChannelConfig.Version, ) suite.Require().Error(err) @@ -377,10 +347,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) err = cbs.OnChanOpenAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelID, path.EndpointB.ChannelConfig.Version) @@ -437,11 +404,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenConfirm() { suite.Require().Error(err) - // call application callback directly - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) err = cbs.OnChanOpenConfirm( @@ -462,10 +425,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseInit() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) err = cbs.OnChanCloseInit( @@ -512,10 +472,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() { suite.Require().NoError(err) tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) if isNilApp { @@ -561,10 +519,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) packet := channeltypes.NewPacket( @@ -674,10 +629,7 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) if isNilApp { @@ -771,10 +723,7 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) if isNilApp { @@ -860,10 +809,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) cbs, ok := app.(porttypes.UpgradableModule) suite.Require().True(ok) @@ -903,10 +849,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeTry() { suite.Require().NoError(err) // call application callback directly - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) cbs, ok := app.(porttypes.UpgradableModule) suite.Require().True(ok) @@ -988,10 +931,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) cbs, ok := app.(porttypes.UpgradableModule) suite.Require().True(ok) @@ -1078,10 +1018,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeOpen() { tc.malleate() // malleate mutates test data - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + app, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) cbs, ok := app.(porttypes.UpgradableModule) suite.Require().True(ok) @@ -1196,10 +1133,7 @@ func (suite *InterchainAccountsTestSuite) TestGetAppVersion() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().NoError(err) - - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) + cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(path.EndpointA.ChannelConfig.PortID) suite.Require().True(ok) controllerStack, ok := cbs.(porttypes.ICS4Wrapper) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 8e0ca30a1f3..b339997acb6 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -7,7 +7,6 @@ import ( errorsmod "cosmossdk.io/errors" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -25,7 +24,6 @@ func (k Keeper) OnChanOpenInit( connectionHops []string, portID string, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index abc062b1649..9ed3dd5a22f 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -1,11 +1,9 @@ package keeper_test import ( - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -19,7 +17,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { var ( channel *channeltypes.Channel path *ibctesting.Path - chanCap *capabilitytypes.Capability metadata icatypes.Metadata expectedVersion string ) @@ -274,8 +271,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { portID, err := icatypes.NewControllerPortID(TestOwnerAddress) suite.Require().NoError(err) - portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID) - suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID)) //nolint:errcheck // this error check isn't needed for tests path.EndpointA.ChannelConfig.PortID = portID // default values @@ -299,11 +294,8 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { tc.malleate() // malleate mutates test data - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - version, err := suite.chainA.GetSimApp().ICAControllerKeeper.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.Version, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel.Counterparty, channel.Version, ) expPass := tc.expError == nil diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 0181a6a65b8..e23b0514e59 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" @@ -43,7 +42,6 @@ func (IBCModule) OnChanOpenInit( _ []string, _ string, _ string, - _ *capabilitytypes.Capability, _ channeltypes.Counterparty, _ string, ) (string, error) { @@ -57,7 +55,6 @@ func (im IBCModule) OnChanOpenTry( connectionHops []string, portID, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { @@ -65,7 +62,7 @@ func (im IBCModule) OnChanOpenTry( return "", types.ErrHostSubModuleDisabled } - return im.keeper.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) + return im.keeper.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, counterparty, counterpartyVersion) } // OnChanOpenAck implements the IBCModule interface diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index 7ef5894ad4d..68dba2a2623 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -15,7 +15,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" icahost "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" @@ -162,7 +161,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { "success: ICA auth module callback returns error", func() { // mock module callback should not be called on host side suite.chainB.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenTry = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, + portID, channelID string, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { return "", fmt.Errorf("mock ica auth fails") @@ -208,14 +207,11 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { module, _, err := suite.chainB.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID) suite.Require().NoError(err) - chanCap, err := suite.chainB.App.GetScopedIBCKeeper().NewCapability(suite.chainB.GetContext(), host.ChannelCapabilityPath(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) - suite.Require().NoError(err) - cbs, ok := suite.chainB.App.GetIBCKeeper().PortKeeper.Route(module) suite.Require().True(ok) version, err := cbs.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.ConnectionHops, - path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version, + path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel.Counterparty, path.EndpointA.ChannelConfig.Version, ) if tc.expErr == nil { diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 6ab2c7dd2e9..19d126218b3 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -9,12 +9,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ) // OnChanOpenTry performs basic validation of the ICA channel @@ -27,7 +25,6 @@ func (k Keeper) OnChanOpenTry( connectionHops []string, portID, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { @@ -70,12 +67,6 @@ func (k Keeper) OnChanOpenTry( // be overwritten with the correct one before the metadata is returned. } - // On the host chain the capability may only be claimed during the OnChanOpenTry - // The capability being claimed in OpenInit is for a controller chain (the port is different) - if err = k.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", errorsmod.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) - } - var accAddress sdk.AccAddress interchainAccAddr, found := k.GetInterchainAccountAddress(ctx, metadata.HostConnectionId, counterparty.PortId) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index ab70bcb85b1..53279b724a0 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -5,13 +5,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" hosttypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -48,7 +46,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { var ( channel *channeltypes.Channel path *ibctesting.Path - chanCap *capabilitytypes.Capability metadata icatypes.Metadata ) @@ -68,8 +65,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // create interchain account // undo setup path.EndpointB.ChannelID = "" - err := suite.chainB.App.GetScopedIBCKeeper().ReleaseCapability(suite.chainB.GetContext(), chanCap) - suite.Require().NoError(err) suite.openAndCloseChannel(path) }, @@ -81,8 +76,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // create interchain account // undo setup path.EndpointB.ChannelID = "" - err := suite.chainB.App.GetScopedIBCKeeper().ReleaseCapability(suite.chainB.GetContext(), chanCap) - suite.Require().NoError(err) suite.openAndCloseChannel(path) @@ -141,8 +134,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // create interchain account // undo setup path.EndpointB.ChannelID = "" - err := suite.chainB.App.GetScopedIBCKeeper().ReleaseCapability(suite.chainB.GetContext(), chanCap) - suite.Require().NoError(err) suite.openAndCloseChannel(path) @@ -161,8 +152,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // create interchain account // undo setup path.EndpointB.ChannelID = "" - err := suite.chainB.App.GetScopedIBCKeeper().ReleaseCapability(suite.chainB.GetContext(), chanCap) - suite.Require().NoError(err) suite.openAndCloseChannel(path) @@ -253,15 +242,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { }, icatypes.ErrInvalidVersion, }, - { - "capability already claimed", - func() { - path.EndpointB.SetChannel(*channel) - err := suite.chainB.GetSimApp().ScopedICAHostKeeper.ClaimCapability(suite.chainB.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) - suite.Require().NoError(err) - }, - capabilitytypes.ErrOwnerClaimed, - }, { "active channel already set (OPEN state)", func() { @@ -325,13 +305,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { Version: string(versionBytes), } - chanCap, err = suite.chainB.App.GetScopedIBCKeeper().NewCapability(suite.chainB.GetContext(), host.ChannelCapabilityPath(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) - suite.Require().NoError(err) - tc.malleate() // malleate mutates test data version, err := suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenTry(suite.chainB.GetContext(), channel.Ordering, channel.ConnectionHops, - path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version, + path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel.Counterparty, path.EndpointA.ChannelConfig.Version, ) if tc.expErr == nil { diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 58a12f00511..08d8c227a3f 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -9,7 +9,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/keeper" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -47,7 +46,6 @@ func (im IBCMiddleware) OnChanOpenInit( connectionHops []string, portID string, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { @@ -66,7 +64,7 @@ func (im IBCMiddleware) OnChanOpenInit( // lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying // application. return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, - chanCap, counterparty, version) + counterparty, version) } versionMetadata = metadata } @@ -75,7 +73,7 @@ func (im IBCMiddleware) OnChanOpenInit( return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) } - appVersion, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, versionMetadata.AppVersion) + appVersion, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, counterparty, versionMetadata.AppVersion) if err != nil { return "", err } @@ -101,7 +99,6 @@ func (im IBCMiddleware) OnChanOpenTry( connectionHops []string, portID, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { @@ -110,7 +107,7 @@ func (im IBCMiddleware) OnChanOpenTry( // Since it is valid for fee version to not be specified, the above middleware version may be for a middleware // lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying // application. - return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) + return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, counterparty, counterpartyVersion) } if versionMetadata.FeeVersion != types.Version { @@ -120,7 +117,7 @@ func (im IBCMiddleware) OnChanOpenTry( im.keeper.SetFeeEnabled(ctx, portID, channelID) // call underlying app's OnChanOpenTry callback with the app versions - appVersion, err := im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, versionMetadata.AppVersion) + appVersion, err := im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, counterparty, versionMetadata.AppVersion) if err != nil { return "", err } diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index 6fb19d3d1ac..f8d301d7f2c 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -11,14 +11,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibcfee "github.com/cosmos/ibc-go/v9/modules/apps/29-fee" feekeeper "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/keeper" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -88,7 +86,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() { // setup mock callback suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenInit = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, + portID, channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error) { if version != ibcmock.Version { @@ -111,14 +109,11 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() { module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort) suite.Require().NoError(err) - chanCap, err := suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)) - suite.Require().NoError(err) - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) suite.Require().True(ok) version, err := cbs.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, - suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, channel.Version) + suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, counterparty, channel.Version) if tc.expErr == nil { // check if the channel is fee enabled. If so version string should include metaData @@ -188,7 +183,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() { // setup mock callback suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenTry = func(ctx context.Context, order channeltypes.Order, connectionHops []string, - portID, channelID string, chanCap *capabilitytypes.Capability, + portID, channelID string, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { if counterpartyVersion != ibcmock.Version { @@ -197,13 +192,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() { return ibcmock.Version, nil } - var ( - chanCap *capabilitytypes.Capability - ok bool - ) - - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)) - suite.Require().NoError(err) + var ok bool suite.path.EndpointA.ChannelID = ibctesting.FirstChannelID @@ -223,7 +212,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() { suite.Require().True(ok) _, err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, - suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, tc.cpVersion) + suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, counterparty, tc.cpVersion) if tc.expErr == nil { suite.Require().NoError(err) diff --git a/modules/apps/callbacks/ibc_middleware.go b/modules/apps/callbacks/ibc_middleware.go index 74b6f44a237..9bc8789ecca 100644 --- a/modules/apps/callbacks/ibc_middleware.go +++ b/modules/apps/callbacks/ibc_middleware.go @@ -11,7 +11,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/callbacks/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" @@ -338,11 +337,10 @@ func (im IBCMiddleware) OnChanOpenInit( connectionHops []string, portID, channelID string, - channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { - return im.app.OnChanOpenInit(ctx, channelOrdering, connectionHops, portID, channelID, channelCap, counterparty, version) + return im.app.OnChanOpenInit(ctx, channelOrdering, connectionHops, portID, channelID, counterparty, version) } // OnChanOpenTry defers to the underlying application @@ -351,11 +349,10 @@ func (im IBCMiddleware) OnChanOpenTry( channelOrdering channeltypes.Order, connectionHops []string, portID, channelID string, - channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { - return im.app.OnChanOpenTry(ctx, channelOrdering, connectionHops, portID, channelID, channelCap, counterparty, counterpartyVersion) + return im.app.OnChanOpenTry(ctx, channelOrdering, connectionHops, portID, channelID, counterparty, counterpartyVersion) } // OnChanOpenAck defers to the underlying application diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index ac2aaf890db..c6445645c23 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -11,13 +11,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/internal/events" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/keeper" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -79,7 +77,6 @@ func (im IBCModule) OnChanOpenInit( connectionHops []string, portID string, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { @@ -96,11 +93,6 @@ func (im IBCModule) OnChanOpenInit( return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected one of %s, got %s", types.SupportedVersions, version) } - // Claim channel capability passed back by IBC module - if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } - return version, nil } @@ -111,7 +103,6 @@ func (im IBCModule) OnChanOpenTry( connectionHops []string, portID, channelID string, - chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { @@ -119,11 +110,6 @@ func (im IBCModule) OnChanOpenTry( return "", err } - // OpenTry must claim the channelCapability that IBC passes into the callback - if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } - if !slices.Contains(types.SupportedVersions, counterpartyVersion) { im.keeper.Logger(ctx).Debug("invalid counterparty version, proposing latest app version", "counterpartyVersion", counterpartyVersion, "version", types.V2) return types.V2, nil diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 266565b66d1..fb35ea90c78 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -10,14 +10,12 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/transfer" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -27,7 +25,6 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() { var ( channel *channeltypes.Channel path *ibctesting.Path - chanCap *capabilitytypes.Capability counterparty channeltypes.Counterparty ) @@ -77,12 +74,6 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() { channel.Version = "version" //nolint:goconst }, types.ErrInvalidVersion, "", }, - { - "capability already claimed", func() { - err := suite.chainA.GetSimApp().ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - }, capabilitytypes.ErrOwnerClaimed, "", - }, } for _, tc := range testCases { @@ -103,15 +94,11 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() { Version: types.V2, } - var err error - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.TransferPort, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - tc.malleate() // explicitly change fields in channel and testChannel transferModule := transfer.NewIBCModule(suite.chainA.GetSimApp().TransferKeeper) version, err := transferModule.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, counterparty, channel.Version, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, counterparty, channel.Version, ) expPass := tc.expError == nil @@ -129,7 +116,6 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() { func (suite *TransferTestSuite) TestOnChanOpenTry() { var ( channel *channeltypes.Channel - chanCap *capabilitytypes.Capability path *ibctesting.Path counterparty channeltypes.Counterparty counterpartyVersion string @@ -160,12 +146,6 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() { path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(math.MaxUint32 + 1) }, types.ErrMaxTransferChannels, "", }, - { - "failure: capability already claimed", func() { - err := suite.chainA.GetSimApp().ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - }, capabilitytypes.ErrOwnerClaimed, "", - }, { "failure: invalid order - ORDERED", func() { channel.Ordering = channeltypes.ORDERED @@ -201,16 +181,13 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() { module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.TransferPort) suite.Require().NoError(err) - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(ibctesting.TransferPort, path.EndpointA.ChannelID)) - suite.Require().NoError(err) - cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(module) suite.Require().True(ok) tc.malleate() // explicitly change fields in channel and testChannel version, err := cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.ConnectionHops, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, counterpartyVersion, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel.Counterparty, counterpartyVersion, ) expPass := tc.expError == nil if expPass { diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index a9551cb0f3d..635b178e067 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -8,12 +8,9 @@ import ( "github.com/cosmos/cosmos-sdk/telemetry" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -25,19 +22,18 @@ func (k *Keeper) ChanOpenInit( order types.Order, connectionHops []string, portID string, - portCap *capabilitytypes.Capability, counterparty types.Counterparty, version string, -) (string, *capabilitytypes.Capability, error) { +) (string, error) { // connection hop length checked on msg.ValidateBasic() connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0]) if !found { - return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) + return "", errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } getVersions := connectionEnd.Versions if len(getVersions) != 1 { - return "", nil, errorsmod.Wrapf( + return "", errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: %v", getVersions, @@ -45,7 +41,7 @@ func (k *Keeper) ChanOpenInit( } if !connectiontypes.VerifySupportedFeature(getVersions[0], order.String()) { - return "", nil, errorsmod.Wrapf( + return "", errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "connection version %s does not support channel ordering: %s", getVersions[0], order.String(), @@ -53,21 +49,12 @@ func (k *Keeper) ChanOpenInit( } if status := k.clientKeeper.GetClientStatus(ctx, connectionEnd.ClientId); status != exported.Active { - return "", nil, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) - } - - if !k.portKeeper.Authenticate(ctx, portCap, portID) { - return "", nil, errorsmod.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) + return "", errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", connectionEnd.ClientId, status) } channelID := k.GenerateChannelIdentifier(ctx) - capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) - if err != nil { - return "", nil, errorsmod.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) - } - - return channelID, capKey, nil + return channelID, nil } // WriteOpenInitChannel writes a channel which has successfully passed the OpenInit handshake step. @@ -103,36 +90,31 @@ func (k *Keeper) ChanOpenTry( order types.Order, connectionHops []string, portID string, - portCap *capabilitytypes.Capability, counterparty types.Counterparty, counterpartyVersion string, initProof []byte, proofHeight exported.Height, -) (string, *capabilitytypes.Capability, error) { +) (string, error) { // connection hops only supports a single connection if len(connectionHops) != 1 { - return "", nil, errorsmod.Wrapf(types.ErrTooManyConnectionHops, "expected 1, got %d", len(connectionHops)) + return "", errorsmod.Wrapf(types.ErrTooManyConnectionHops, "expected 1, got %d", len(connectionHops)) } // generate a new channel channelID := k.GenerateChannelIdentifier(ctx) - if !k.portKeeper.Authenticate(ctx, portCap, portID) { - return "", nil, errorsmod.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) - } - connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0]) if !found { - return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) + return "", errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } if connectionEnd.State != connectiontypes.OPEN { - return "", nil, errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectionEnd.State) + return "", errorsmod.Wrapf(connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectionEnd.State) } getVersions := connectionEnd.Versions if len(getVersions) != 1 { - return "", nil, errorsmod.Wrapf( + return "", errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: %v", getVersions, @@ -140,7 +122,7 @@ func (k *Keeper) ChanOpenTry( } if !connectiontypes.VerifySupportedFeature(getVersions[0], order.String()) { - return "", nil, errorsmod.Wrapf( + return "", errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "connection version %s does not support channel ordering: %s", getVersions[0], order.String(), @@ -161,20 +143,10 @@ func (k *Keeper) ChanOpenTry( ctx, connectionEnd, proofHeight, initProof, counterparty.PortId, counterparty.ChannelId, expectedChannel, ); err != nil { - return "", nil, err - } - - var ( - capKey *capabilitytypes.Capability - err error - ) - - capKey, err = k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) - if err != nil { - return "", nil, errorsmod.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) + return "", err } - return channelID, capKey, nil + return channelID, nil } // WriteOpenTryChannel writes a channel which has successfully passed the OpenTry handshake step. @@ -210,7 +182,6 @@ func (k *Keeper) ChanOpenAck( ctx context.Context, portID, channelID string, - chanCap *capabilitytypes.Capability, counterpartyVersion, counterpartyChannelID string, tryProof []byte, @@ -225,10 +196,6 @@ func (k *Keeper) ChanOpenAck( return errorsmod.Wrapf(types.ErrInvalidChannelState, "channel state should be INIT (got %s)", channel.State) } - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) - } - connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) @@ -285,7 +252,6 @@ func (k *Keeper) ChanOpenConfirm( ctx context.Context, portID, channelID string, - chanCap *capabilitytypes.Capability, ackProof []byte, proofHeight exported.Height, ) error { @@ -301,10 +267,6 @@ func (k *Keeper) ChanOpenConfirm( ) } - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) - } - connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) @@ -362,12 +324,7 @@ func (k *Keeper) ChanCloseInit( ctx context.Context, portID, channelID string, - chanCap *capabilitytypes.Capability, ) error { - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) - } - channel, found := k.GetChannel(ctx, portID, channelID) if !found { return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) @@ -408,15 +365,10 @@ func (k *Keeper) ChanCloseConfirm( ctx context.Context, portID, channelID string, - chanCap *capabilitytypes.Capability, initProof []byte, proofHeight exported.Height, counterpartyUpgradeSequence uint64, ) error { - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) - } - channel, found := k.GetChannel(ctx, portID, channelID) if !found { return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) diff --git a/modules/core/04-channel/keeper/handshake_test.go b/modules/core/04-channel/keeper/handshake_test.go index 35bdf3783b8..96b0bb74ded 100644 --- a/modules/core/04-channel/keeper/handshake_test.go +++ b/modules/core/04-channel/keeper/handshake_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "fmt" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -21,13 +20,11 @@ type testCase = struct { // TestChanOpenInit tests the OpenInit handshake call for channels. It uses message passing // to enter into the appropriate state and then calls ChanOpenInit directly. The channel is -// being created on chainA. The port capability must be created on chainA before ChanOpenInit -// can succeed. +// being created on chainA. func (suite *KeeperTestSuite) TestChanOpenInit() { var ( path *ibctesting.Path features []string - portCap *capabilitytypes.Capability expErrorMsgSubstring string ) @@ -35,22 +32,12 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { {"success", func() { path.SetupConnections() features = []string{"ORDER_ORDERED", "ORDER_UNORDERED"} - suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) }, true}, - {"channel already exists", func() { - path.Setup() - }, false}, {"connection doesn't exist", func() { // any non-empty values path.EndpointA.ConnectionID = "connection-0" path.EndpointB.ConnectionID = "connection-0" }, false}, - {"capability is incorrect", func() { - path.SetupConnections() - features = []string{"ORDER_ORDERED", "ORDER_UNORDERED"} - portCap = capabilitytypes.NewCapability(3) - }, false}, {"connection version not negotiated", func() { path.SetupConnections() @@ -60,8 +47,6 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { }) features = []string{"ORDER_ORDERED", "ORDER_UNORDERED"} - suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) }, false}, {"connection does not support ORDERED channels", func() { path.SetupConnections() @@ -73,8 +58,6 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // NOTE: Opening UNORDERED channels is still expected to pass but ORDERED channels should fail features = []string{"ORDER_UNORDERED"} - suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) }, true}, { msg: "unauthorized client", @@ -87,9 +70,6 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { params := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetParams(suite.chainA.GetContext()) params.AllowedClients = []string{} suite.chainA.App.GetIBCKeeper().ClientKeeper.SetParams(suite.chainA.GetContext(), params) - - suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) }, }, } @@ -109,9 +89,9 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { counterparty := types.NewCounterparty(ibctesting.MockPort, ibctesting.FirstChannelID) - channelID, capability, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.ChanOpenInit( + channelID, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.ChanOpenInit( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.Order, []string{path.EndpointA.ConnectionID}, - path.EndpointA.ChannelConfig.PortID, portCap, counterparty, path.EndpointA.ChannelConfig.Version, + path.EndpointA.ChannelConfig.PortID, counterparty, path.EndpointA.ChannelConfig.Version, ) // check if order is supported by channel to determine expected behaviour @@ -126,19 +106,10 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // asserting the channel handshake initiation succeeded if tc.expPass && orderSupported { suite.Require().NoError(err) - suite.Require().NotNil(capability) suite.Require().Equal(types.FormatChannelIdentifier(0), channelID) - - chanCap, ok := suite.chainA.App.GetScopedIBCKeeper().GetCapability( - suite.chainA.GetContext(), - host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, channelID), - ) - suite.Require().True(ok, "could not retrieve channel capability after successful ChanOpenInit") - suite.Require().Equal(chanCap.String(), capability.String(), "channel capability is not correct") } else { suite.Require().Error(err) suite.Require().Contains(err.Error(), expErrorMsgSubstring) - suite.Require().Nil(capability) suite.Require().Equal("", channelID) } } @@ -148,12 +119,10 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { // TestChanOpenTry tests the OpenTry handshake call for channels. It uses message passing // to enter into the appropriate state and then calls ChanOpenTry directly. The channel -// is being created on chainB. The port capability must be created on chainB before -// ChanOpenTry can succeed. +// is being created on chainB. func (suite *KeeperTestSuite) TestChanOpenTry() { var ( path *ibctesting.Path - portCap *capabilitytypes.Capability heightDiff uint64 ) @@ -163,23 +132,13 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { path.SetChannelOrdered() err := path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - - suite.chainB.CreatePortCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainB.GetPortCapability(ibctesting.MockPort) }, true}, {"connection doesn't exist", func() { path.EndpointA.ConnectionID = ibctesting.FirstConnectionID path.EndpointB.ConnectionID = ibctesting.FirstConnectionID - - // pass capability check - suite.chainB.CreatePortCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainB.GetPortCapability(ibctesting.MockPort) }, false}, {"connection is not OPEN", func() { path.SetupClients() - // pass capability check - suite.chainB.CreatePortCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainB.GetPortCapability(ibctesting.MockPort) err := path.EndpointB.ConnOpenInit() suite.Require().NoError(err) @@ -190,23 +149,11 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { err := path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - suite.chainB.CreatePortCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainB.GetPortCapability(ibctesting.MockPort) - heightDiff = 3 // consensus state doesn't exist at this height }, false}, {"channel verification failed", func() { // not creating a channel on chainA will result in an invalid proof of existence path.SetupConnections() - portCap = suite.chainB.GetPortCapability(ibctesting.MockPort) - }, false}, - {"port capability not found", func() { - path.SetupConnections() - path.SetChannelOrdered() - err := path.EndpointA.ChanOpenInit() - suite.Require().NoError(err) - - portCap = capabilitytypes.NewCapability(3) }, false}, {"connection version not negotiated", func() { path.SetupConnections() @@ -218,9 +165,6 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.Versions = append(c.Versions, connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"})) }) - - suite.chainB.CreatePortCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainB.GetPortCapability(ibctesting.MockPort) }, false}, {"connection does not support ORDERED channels", func() { path.SetupConnections() @@ -228,13 +172,10 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { err := path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - // modify connA versions to only support UNORDERED channels - path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { + // modify connB versions to only support UNORDERED channels + path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.Versions = []*connectiontypes.Version{connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"})} }) - - suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort) - portCap = suite.chainA.GetPortCapability(ibctesting.MockPort) }, false}, } @@ -258,22 +199,15 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { channelKey := host.ChannelKey(counterparty.PortId, counterparty.ChannelId) proof, proofHeight := suite.chainA.QueryProof(channelKey) - channelID, capability, err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanOpenTry( + channelID, err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanOpenTry( suite.chainB.GetContext(), types.ORDERED, []string{path.EndpointB.ConnectionID}, - path.EndpointB.ChannelConfig.PortID, portCap, counterparty, path.EndpointA.ChannelConfig.Version, + path.EndpointB.ChannelConfig.PortID, counterparty, path.EndpointA.ChannelConfig.Version, proof, malleateHeight(proofHeight, heightDiff), ) if tc.expPass { suite.Require().NoError(err) - suite.Require().NotNil(capability) - - chanCap, ok := suite.chainB.App.GetScopedIBCKeeper().GetCapability( - suite.chainB.GetContext(), - host.ChannelCapabilityPath(path.EndpointB.ChannelConfig.PortID, channelID), - ) - suite.Require().True(ok, "could not retrieve channel capability after successful ChanOpenTry") - suite.Require().Equal(chanCap.String(), capability.String(), "channel capability is not correct") + suite.Require().NotEmpty(channelID) } else { suite.Require().Error(err) } @@ -288,7 +222,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { var ( path *ibctesting.Path counterpartyChannelID string - channelCap *capabilitytypes.Capability heightDiff uint64 ) @@ -301,8 +234,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success with empty stored counterparty channel ID", func() { path.SetupConnections() @@ -322,14 +253,11 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { counterpartyChannelID = path.EndpointB.ChannelID suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel) - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"channel doesn't exist", func() {}, false}, {"channel state is not INIT", func() { // create fully open channels on both chains path.Setup() - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"connection not found", func() { path.SetupConnections() @@ -340,8 +268,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - // set the channel's connection hops to wrong connection ID channel := path.EndpointA.GetChannel() channel.ConnectionHops[0] = doesnotexist @@ -358,9 +284,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"consensus state not found", func() { path.SetupConnections() @@ -372,8 +295,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - heightDiff = 3 // consensus state doesn't exist at this height }, false}, {"invalid counterparty channel identifier", func() { @@ -387,8 +308,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { suite.Require().NoError(err) counterpartyChannelID = "otheridentifier" - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"channel verification failed", func() { // chainB is INIT, chainA in TRYOPEN @@ -400,19 +319,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { err = path.EndpointA.ChanOpenTry() suite.Require().NoError(err) - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, - {"channel capability not found", func() { - path.SetupConnections() - path.SetChannelOrdered() - err := path.EndpointA.ChanOpenInit() - suite.Require().NoError(err) - - err = path.EndpointB.ChanOpenTry() - suite.Require().NoError(err) - - channelCap = capabilitytypes.NewCapability(6) }, false}, } @@ -440,7 +346,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { proof, proofHeight := suite.chainB.QueryProof(channelKey) err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.ChanOpenAck( - suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channelCap, path.EndpointB.ChannelConfig.Version, counterpartyChannelID, + suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.Version, counterpartyChannelID, proof, malleateHeight(proofHeight, heightDiff), ) @@ -459,7 +365,6 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { func (suite *KeeperTestSuite) TestChanOpenConfirm() { var ( path *ibctesting.Path - channelCap *capabilitytypes.Capability heightDiff uint64 ) testCases := []testCase{ @@ -475,14 +380,11 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err = path.EndpointA.ChanOpenAck() suite.Require().NoError(err) - - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, true}, {"channel doesn't exist", func() {}, false}, {"channel state is not TRYOPEN", func() { // create fully open channels on both chains path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"connection not found", func() { path.SetupConnections() @@ -497,8 +399,6 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err = path.EndpointA.ChanOpenAck() suite.Require().NoError(err) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - // set the channel's connection hops to wrong connection ID channel := path.EndpointB.GetChannel() channel.ConnectionHops[0] = doesnotexist @@ -509,9 +409,6 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err := path.EndpointB.ConnOpenInit() suite.Require().NoError(err) - - suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, ibctesting.FirstChannelID) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, ibctesting.FirstChannelID) }, false}, {"consensus state not found", func() { path.SetupConnections() @@ -526,8 +423,6 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err = path.EndpointA.ChanOpenAck() suite.Require().NoError(err) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - heightDiff = 3 }, false}, {"channel verification failed", func() { @@ -540,23 +435,6 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - }, false}, - {"channel capability not found", func() { - path.SetupConnections() - path.SetChannelOrdered() - - err := path.EndpointA.ChanOpenInit() - suite.Require().NoError(err) - - err = path.EndpointB.ChanOpenTry() - suite.Require().NoError(err) - - err = path.EndpointA.ChanOpenAck() - suite.Require().NoError(err) - - channelCap = capabilitytypes.NewCapability(6) }, false}, } @@ -581,7 +459,7 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanOpenConfirm( suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, - channelCap, proof, malleateHeight(proofHeight, heightDiff), + proof, malleateHeight(proofHeight, heightDiff), ) if tc.expPass { @@ -598,14 +476,12 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { func (suite *KeeperTestSuite) TestChanCloseInit() { var ( path *ibctesting.Path - channelCap *capabilitytypes.Capability expErrorMsgSubstring string ) testCases := []testCase{ {"success", func() { path.Setup() - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"channel doesn't exist", func() { // any non-nil values work for connections @@ -614,21 +490,15 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { path.EndpointA.ChannelID = ibctesting.FirstChannelID path.EndpointB.ChannelID = ibctesting.FirstChannelID - - // ensure channel capability check passes - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"channel state is CLOSED", func() { path.Setup() - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) // close channel path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) }, false}, {"connection not found", func() { path.Setup() - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) // set the channel's connection hops to wrong connection ID channel := path.EndpointA.GetChannel() @@ -645,21 +515,12 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { path.SetChannelOrdered() err = path.EndpointA.ChanOpenInit() suite.Require().NoError(err) - - // ensure channel capability check passes - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, - {"channel capability not found", func() { - path.Setup() - channelCap = capabilitytypes.NewCapability(3) }, false}, { msg: "unauthorized client", expPass: false, malleate: func() { path.Setup() - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) // remove client from allowed list params := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetParams(suite.chainA.GetContext()) @@ -680,7 +541,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { tc.malleate() err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.ChanCloseInit( - suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channelCap, + suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ) if tc.expPass { @@ -699,7 +560,6 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { func (suite *KeeperTestSuite) TestChanCloseConfirm() { var ( path *ibctesting.Path - channelCap *capabilitytypes.Capability heightDiff uint64 counterpartyUpgradeSequence uint64 ) @@ -707,13 +567,10 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { testCases := []testCase{ {"success", func() { path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) }, true}, {"success with upgrade info", func() { path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) err := path.EndpointA.SetChannelState(types.CLOSED) suite.Require().NoError(err) @@ -737,20 +594,14 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { // any non-nil values work for connections path.EndpointA.ChannelID = ibctesting.FirstChannelID path.EndpointB.ChannelID = ibctesting.FirstChannelID - - // ensure channel capability check passes - suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, ibctesting.FirstChannelID) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, ibctesting.FirstChannelID) }, false}, {"channel state is CLOSED", func() { path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) }, false}, {"connection not found", func() { path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) // set the channel's connection hops to wrong connection ID channel := path.EndpointB.GetChannel() @@ -767,14 +618,9 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { path.SetChannelOrdered() err = path.EndpointB.ChanOpenInit() suite.Require().NoError(err) - - // ensure channel capability check passes - suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"consensus state not found", func() { path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) @@ -783,30 +629,18 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { {"channel verification failed", func() { // channel not closed path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - }, false}, - {"channel capability not found", func() { - path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - - channelCap = capabilitytypes.NewCapability(3) }, false}, { "failure: invalid counterparty upgrade sequence", func() { path.Setup() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - // trigger upgradeInit on B which will bump the counterparty upgrade sequence. - path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion - err := path.EndpointB.ChanUpgradeInit() + // trigger upgradeInit on A which will bump the counterparty upgrade sequence. + path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion + err := path.EndpointA.ChanUpgradeInit() suite.Require().NoError(err) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - - channelCap = capabilitytypes.NewCapability(3) }, false, }, @@ -827,7 +661,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { ctx := suite.chainB.GetContext() err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanCloseConfirm( - ctx, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channelCap, + ctx, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, proof, malleateHeight(proofHeight, heightDiff), counterpartyUpgradeSequence, ) diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index aab49c00697..65410bcd11b 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -10,11 +10,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -105,7 +103,6 @@ func (k *Keeper) SendPacket( // sent on the corresponding channel end on the counterparty chain. func (k *Keeper) RecvPacket( ctx context.Context, - chanCap *capabilitytypes.Capability, packet types.Packet, proof []byte, proofHeight exported.Height, @@ -120,7 +117,7 @@ func (k *Keeper) RecvPacket( } // If counterpartyUpgrade is stored we need to ensure that the - // packet sequence is < counterparty next sequence send. If the + // packet sequence is counterparty next sequence send. If the // counterparty is implemented correctly, this may only occur // when we are in FLUSHCOMPLETE and the counterparty has already // completed the channel upgrade. @@ -132,15 +129,6 @@ func (k *Keeper) RecvPacket( } } - // Authenticate capability to ensure caller has authority to receive packet on this channel - capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return "", errorsmod.Wrapf( - types.ErrInvalidChannelCapability, - "channel capability failed authentication for capability name %s", capName, - ) - } - // packet must come from the channel's counterparty if packet.GetSourcePort() != channel.Counterparty.PortId { return "", errorsmod.Wrapf( @@ -360,7 +348,6 @@ func (k *Keeper) WriteAcknowledgement( // It will also increment NextSequenceAck in case of ORDERED channels. func (k *Keeper) AcknowledgePacket( ctx context.Context, - chanCap *capabilitytypes.Capability, packet types.Packet, acknowledgement []byte, proof []byte, @@ -378,15 +365,6 @@ func (k *Keeper) AcknowledgePacket( return "", errorsmod.Wrapf(types.ErrInvalidChannelState, "packets cannot be acknowledged on channel with state (%s)", channel.State) } - // Authenticate capability to ensure caller has authority to receive packet on this channel - capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return "", errorsmod.Wrapf( - types.ErrInvalidChannelCapability, - "channel capability failed authentication for capability name %s", capName, - ) - } - // packet must have been sent to the channel's counterparty if packet.GetDestPort() != channel.Counterparty.PortId { return "", errorsmod.Wrapf( diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index b5c2c480e75..8025eaca3b6 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -9,7 +9,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -193,7 +192,6 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{path.EndpointA.ConnectionID}, path.EndpointA.ChannelConfig.Version), ) - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, { "channel is in FLUSH_COMPLETE state", @@ -262,9 +260,8 @@ func (suite *KeeperTestSuite) TestSendPacket() { // verification tests need to simulate sending a packet from chainA to chainB. func (suite *KeeperTestSuite) TestRecvPacket() { var ( - path *ibctesting.Path - packet types.Packet - channelCap *capabilitytypes.Capability + path *ibctesting.Path + packet types.Packet ) testCases := []struct { @@ -281,7 +278,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, nil, }, @@ -293,7 +289,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, nil, }, @@ -307,7 +302,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, nil, }, @@ -321,7 +315,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, nil, }, @@ -337,7 +330,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // attempts to receive packet 2 without receiving packet 1 - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, nil, }, @@ -348,7 +340,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) @@ -365,7 +356,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) }, @@ -381,7 +371,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) @@ -399,7 +388,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointB.RecvPacket(packet) @@ -414,7 +402,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.Setup() sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointB.RecvPacket(packet) @@ -436,7 +423,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // attempts to receive packet 2 without receiving packet 1 - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrPacketSequenceOutOfOrder, }, @@ -446,7 +432,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // use wrong channel naming path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrChannelNotFound, }, @@ -457,23 +442,9 @@ func (suite *KeeperTestSuite) TestRecvPacket() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrInvalidChannelState, }, - { - "capability cannot authenticate ORDERED", - func() { - path.SetChannelOrdered() - path.Setup() - - sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) - suite.Require().NoError(err) - packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = capabilitytypes.NewCapability(3) - }, - types.ErrInvalidChannelCapability, - }, { "packet source port ≠ channel counterparty port", func() { @@ -481,7 +452,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // use wrong port for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrInvalidPacket, }, @@ -492,7 +462,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // use wrong port for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrInvalidPacket, }, @@ -508,8 +477,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{connIDB}, path.EndpointB.ChannelConfig.Version), ) packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, connectiontypes.ErrConnectionNotFound, }, @@ -529,8 +496,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointB.ConnectionID}, path.EndpointB.ChannelConfig.Version), ) packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, connectiontypes.ErrInvalidConnectionState, }, @@ -540,7 +505,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrTimeoutElapsed, }, @@ -550,7 +514,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, disabledTimeoutHeight, uint64(suite.chainB.GetContext().BlockTime().UnixNano())) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrTimeoutElapsed, }, @@ -573,9 +536,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // manually set packet commitment suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence(), types.CommitPacket(suite.chainA.App.AppCodec(), packet)) - suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) err := path.EndpointA.UpdateClient() suite.Require().NoError(err) @@ -592,7 +552,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) // set recv seq start to indicate packet was processed in previous upgrade suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetRecvStartSequence(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sequence+1) @@ -608,7 +567,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { suite.Require().NoError(err) suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketReceipt(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sequence) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, types.ErrNoOpMsg, }, @@ -618,7 +576,6 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // packet commitment not set resulting in invalid proof path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, commitmenttypes.ErrInvalidProof, }, @@ -636,7 +593,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { packetKey := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) proof, proofHeight := path.EndpointA.QueryProof(packetKey) - channelVersion, err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.RecvPacket(suite.chainB.GetContext(), channelCap, packet, proof, proofHeight) + channelVersion, err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.RecvPacket(suite.chainB.GetContext(), packet, proof, proofHeight) expPass := tc.expError == nil if expPass { @@ -786,8 +743,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path *ibctesting.Path packet types.Packet ack = ibcmock.MockAcknowledgement - - channelCap *capabilitytypes.Capability ) assertErr := func(errType *errors.Error) func(commitment []byte, channelVersion string, err error) { @@ -839,8 +794,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertSuccess(func() uint64 { return packet.GetSequence() + 1 }, "sequence not incremented in ordered channel"), }, @@ -858,8 +811,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertSuccess(func() uint64 { return uint64(1) }, "sequence incremented for UNORDERED channel"), }, @@ -878,8 +829,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) }, expResult: func(commitment []byte, channelVersion string, err error) { @@ -910,8 +859,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) counterpartyUpgrade := types.Upgrade{ @@ -964,8 +911,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) upgrade := types.Upgrade{ @@ -1013,8 +958,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - err = path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement()) suite.Require().NoError(err) }, @@ -1035,8 +978,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - err = path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement()) suite.Require().NoError(err) }, @@ -1068,7 +1009,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(types.ErrInvalidChannelState), }, @@ -1077,7 +1017,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { malleate: func() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE }) }, @@ -1088,25 +1027,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { suite.Require().Equal("", channelVersion) }, }, - { - name: "capability authentication failed ORDERED", - malleate: func() { - path.SetChannelOrdered() - path.Setup() - - // create packet commitment - sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) - suite.Require().NoError(err) - - // create packet receipt and acknowledgement - packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - err = path.EndpointB.RecvPacket(packet) - suite.Require().NoError(err) - - channelCap = capabilitytypes.NewCapability(3) - }, - expResult: assertErr(types.ErrInvalidChannelCapability), - }, { name: "packet destination port ≠ channel counterparty port", malleate: func() { @@ -1118,7 +1038,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // use wrong port for dest packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(types.ErrInvalidPacket), }, @@ -1133,7 +1052,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // use wrong channel for dest packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(types.ErrInvalidPacket), }, @@ -1154,9 +1072,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{"connection-1000"}, path.EndpointA.GetChannel().Version), ) - - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(connectiontypes.ErrConnectionNotFound), }, @@ -1181,8 +1096,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{path.EndpointA.ConnectionID}, path.EndpointA.GetChannel().Version), ) - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(connectiontypes.ErrInvalidConnectionState), }, @@ -1192,7 +1105,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // packet commitment never written path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertNoOp, // NOTE: ibc core does not distinguish between unsent and already relayed packets. }, @@ -1208,7 +1120,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(commitmenttypes.ErrInvalidProof), }, @@ -1227,8 +1138,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - packet.Data = []byte("invalid packet commitment") }, expResult: assertErr(types.ErrInvalidPacket), @@ -1252,8 +1161,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { ibcStore := suite.chainA.GetContext().KVStore(storeKey) ibcStore.Delete(host.NextSequenceAckKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(types.ErrSequenceAckNotFound), }, @@ -1274,7 +1181,6 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // set next sequence ack wrong suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetNextSequenceAck(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, 10) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, expResult: assertErr(types.ErrPacketSequenceOutOfOrder), }, @@ -1293,7 +1199,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { packetKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) proof, proofHeight := path.EndpointB.QueryProof(packetKey) - channelVersion, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.AcknowledgePacket(ctx, channelCap, packet, ack.Acknowledgement(), proof, proofHeight) + channelVersion, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.AcknowledgePacket(ctx, packet, ack.Acknowledgement(), proof, proofHeight) commitment := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(ctx, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence()) tc.expResult(commitment, channelVersion, err) diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 06f93974e98..98156a68147 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -7,11 +7,9 @@ import ( errorsmod "cosmossdk.io/errors" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -131,7 +129,6 @@ func (k *Keeper) TimeoutPacket( // CONTRACT: this function must be called in the IBC handler func (k *Keeper) TimeoutExecuted( ctx context.Context, - chanCap *capabilitytypes.Capability, packet types.Packet, ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) @@ -139,14 +136,6 @@ func (k *Keeper) TimeoutExecuted( return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) } - capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return errorsmod.Wrapf( - types.ErrChannelCapabilityNotFound, - "caller does not own capability for channel with capability name %s", capName, - ) - } - k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) // if an upgrade is in progress, handling packet flushing and update channel state appropriately @@ -192,7 +181,6 @@ func (k *Keeper) TimeoutExecuted( // never be received (even if the timeoutHeight has not yet been reached). func (k *Keeper) TimeoutOnClose( ctx context.Context, - chanCap *capabilitytypes.Capability, packet types.Packet, proof, closedProof []byte, @@ -205,14 +193,6 @@ func (k *Keeper) TimeoutOnClose( return "", errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) } - capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return "", errorsmod.Wrapf( - types.ErrInvalidChannelCapability, - "channel capability failed authentication with capability name %s", capName, - ) - } - if packet.GetDestPort() != channel.Counterparty.PortId { return "", errorsmod.Wrapf( types.ErrInvalidPacket, diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 26b55158907..163d626e763 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -10,7 +10,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -237,14 +236,13 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { } } -// TestTimeoutExecuted verifies that packet commitments are deleted on chainA after the -// channel capabilities are verified. In addition, the test verifies that the channel state +// TestTimeoutExecuted verifies that packet commitments are deleted. +// In addition, the test verifies that the channel state // after a timeout is updated accordingly. func (suite *KeeperTestSuite) TestTimeoutExecuted() { var ( - path *ibctesting.Path - packet types.Packet - chanCap *capabilitytypes.Capability + path *ibctesting.Path + packet types.Packet ) testCases := []struct { @@ -266,7 +264,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, func(packetCommitment []byte, err error) { suite.Require().NoError(err) @@ -294,30 +291,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { }, nil, }, - { - "incorrect capability ORDERED", - func() { - path.SetChannelOrdered() - path.Setup() - - timeoutHeight := clienttypes.GetSelfHeight(suite.chainB.GetContext()) - timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().UnixNano()) - - sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData) - suite.Require().NoError(err) - - packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = capabilitytypes.NewCapability(100) - }, - func(packetCommitment []byte, err error) { - suite.Require().Error(err) - suite.Require().ErrorIs(err, types.ErrChannelCapabilityNotFound) - - // packet sent, never deleted. - suite.Require().NotNil(packetCommitment) - }, - nil, - }, { "set to flush complete with no inflight packets", func() { @@ -326,8 +299,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().UnixNano()) packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) path.EndpointA.SetChannelCounterpartyUpgrade(types.Upgrade{ @@ -369,7 +340,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) }, @@ -393,7 +363,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) @@ -442,7 +411,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) @@ -484,7 +452,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) @@ -523,7 +490,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { tc.malleate() - err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutExecuted(ctx, chanCap, packet) + err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutExecuted(ctx, packet) pc := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) tc.expResult(pc, err) @@ -544,7 +511,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { var ( path *ibctesting.Path packet types.Packet - chanCap *capabilitytypes.Capability nextSeqRecv uint64 counterpartyUpgradeSequence uint64 ordered bool @@ -567,7 +533,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success: UNORDERED", func() { ordered = false @@ -583,7 +548,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"channel not found", func() { // use wrong channel naming @@ -594,13 +558,11 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { path.Setup() // use wrong port for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet dest channel ID ≠ channel counterparty channel ID", func() { path.Setup() // use wrong channel for dest packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"connection not found", func() { // pass channel check @@ -610,17 +572,12 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - - // create chancap - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet hasn't been sent ORDERED", func() { path.SetChannelOrdered() path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), uint64(suite.chainB.GetContext().BlockTime().UnixNano())) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet already received ORDERED", func() { path.SetChannelOrdered() @@ -639,7 +596,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"channel verification failed ORDERED", func() { ordered = true @@ -652,7 +608,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"next seq receive verification failed ORDERED", func() { // set ordered to false providing the wrong proof for ORDERED case @@ -670,7 +625,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), uint64(suite.chainB.GetContext().BlockTime().UnixNano())) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet ack verification failed", func() { // set ordered to true providing the wrong proof for UNORDERED case @@ -686,25 +640,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, - {"channel capability not found ORDERED", func() { - ordered = true - path.SetChannelOrdered() - path.Setup() - - timeoutHeight := clienttypes.GetSelfHeight(suite.chainB.GetContext()) - timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().UnixNano()) - - sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, ibctesting.MockPacketData) - suite.Require().NoError(err) - path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - // need to update chainA's client representing chainB to prove missing ack - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), uint64(suite.chainB.GetContext().BlockTime().UnixNano())) - chanCap = capabilitytypes.NewCapability(100) }, false}, { "failure: invalid counterparty upgrade sequence", @@ -729,7 +664,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false, }, @@ -761,7 +695,6 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { channelVersion, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutOnClose( suite.chainA.GetContext(), - chanCap, packet, proof, closedProof, diff --git a/modules/core/05-port/keeper/keeper.go b/modules/core/05-port/keeper/keeper.go index 2daad5743b7..b0c90403e49 100644 --- a/modules/core/05-port/keeper/keeper.go +++ b/modules/core/05-port/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "context" "fmt" + "strings" "cosmossdk.io/log" @@ -87,5 +88,17 @@ func (k *Keeper) LookupModuleByPort(ctx context.Context, portID string) (string, // Route returns a IBCModule for a given module, and a boolean indicating // whether or not the route is present. func (k *Keeper) Route(module string) (types.IBCModule, bool) { - return k.Router.GetRoute(module) + routes, ok := k.Router.Route(module) + + if ok { + return routes, true + } + + for _, prefix := range k.Router.Keys() { + if strings.Contains(module, prefix) { + return k.Router.Route(prefix) + } + } + + return nil, false } diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index a9f2f52ebcc..cc7915bb6b0 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -30,7 +29,6 @@ type IBCModule interface { connectionHops []string, portID string, channelID string, - channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) @@ -49,7 +47,6 @@ type IBCModule interface { connectionHops []string, portID, channelID string, - channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error) diff --git a/modules/core/05-port/types/router.go b/modules/core/05-port/types/router.go index b66999644f5..7b6b629f3ff 100644 --- a/modules/core/05-port/types/router.go +++ b/modules/core/05-port/types/router.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" + "golang.org/x/exp/maps" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -57,10 +59,15 @@ func (rtr *Router) HasRoute(module string) bool { return ok } -// GetRoute returns a IBCModule for a given module. -func (rtr *Router) GetRoute(module string) (IBCModule, bool) { +// Route returns a IBCModule for a given module. +func (rtr *Router) Route(module string) (IBCModule, bool) { if !rtr.HasRoute(module) { return nil, false } return rtr.routes[module], true } + +// Keys returns the keys of the routes map. +func (rtr *Router) Keys() []string { + return maps.Keys(rtr.routes) +} diff --git a/modules/core/ante/ante.go b/modules/core/ante/ante.go index 2d08ba0db16..243a25f7442 100644 --- a/modules/core/ante/ante.go +++ b/modules/core/ante/ante.go @@ -108,16 +108,10 @@ func (rrd RedundantRelayDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // recvPacketCheckTx runs a subset of ibc recv packet logic to be used specifically within the RedundantRelayDecorator AnteHandler. // It only performs core IBC receiving logic and skips any application logic. func (rrd RedundantRelayDecorator) recvPacketCheckTx(ctx sdk.Context, msg *channeltypes.MsgRecvPacket) (*channeltypes.MsgRecvPacketResponse, error) { - // grab channel capability - _, capability, err := rrd.k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) - if err != nil { - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // If the packet was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - _, err = rrd.k.ChannelKeeper.RecvPacket(cacheCtx, capability, msg.Packet, msg.ProofCommitment, msg.ProofHeight) + _, err := rrd.k.ChannelKeeper.RecvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) switch err { case nil: diff --git a/modules/core/ante/ante_test.go b/modules/core/ante/ante_test.go index daa4e44b214..1543e5803f4 100644 --- a/modules/core/ante/ante_test.go +++ b/modules/core/ante/ante_test.go @@ -11,7 +11,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" @@ -504,15 +503,6 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() { }, channeltypes.ErrRedundantTx, }, - { - "no success on recvPacket checkTx, no capability found", - func(suite *AnteTestSuite) []sdk.Msg { - msg := suite.createRecvPacketMessage(false) - msg.Packet.DestinationPort = "invalid-port" - return []sdk.Msg{msg} - }, - capabilitytypes.ErrCapabilityNotFound, - }, } for _, tc := range testCases { diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 5cb274b0133..9ec65058344 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -193,24 +193,16 @@ func (k *Keeper) ConnectionOpenConfirm(goCtx context.Context, msg *connectiontyp func (k *Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChannelOpenInit) (*channeltypes.MsgChannelOpenInitResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Lookup module by port capability - module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortId) - if err != nil { - ctx.Logger().Error("channel open init failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve application callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel open init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } // Perform 04-channel verification - channelID, capability, err := k.ChannelKeeper.ChanOpenInit( - ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, - portCap, msg.Channel.Counterparty, msg.Channel.Version, + channelID, err := k.ChannelKeeper.ChanOpenInit( + ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, msg.Channel.Counterparty, msg.Channel.Version, ) if err != nil { ctx.Logger().Error("channel open init failed", "error", errorsmod.Wrap(err, "channel handshake open init failed")) @@ -218,7 +210,7 @@ func (k *Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgCha } // Perform application logic callback - version, err := cbs.OnChanOpenInit(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, capability, msg.Channel.Counterparty, msg.Channel.Version) + version, err := cbs.OnChanOpenInit(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, msg.Channel.Counterparty, msg.Channel.Version) if err != nil { ctx.Logger().Error("channel open init failed", "port-id", msg.PortId, "channel-id", channelID, "error", errorsmod.Wrap(err, "channel open init callback failed")) return nil, errorsmod.Wrapf(err, "channel open init callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) @@ -241,31 +233,22 @@ func (k *Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgCha func (k *Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChannelOpenTry) (*channeltypes.MsgChannelOpenTryResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Lookup module by port capability - module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortId) - if err != nil { - ctx.Logger().Error("channel open try failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve application callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel open try failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open try failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } // Perform 04-channel verification - channelID, capability, err := k.ChannelKeeper.ChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, - portCap, msg.Channel.Counterparty, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, - ) + channelID, err := k.ChannelKeeper.ChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, msg.Channel.Counterparty, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight) if err != nil { ctx.Logger().Error("channel open try failed", "error", errorsmod.Wrap(err, "channel handshake open try failed")) return nil, errorsmod.Wrap(err, "channel handshake open try failed") } // Perform application logic callback - version, err := cbs.OnChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, capability, msg.Channel.Counterparty, msg.CounterpartyVersion) + version, err := cbs.OnChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, msg.Channel.Counterparty, msg.CounterpartyVersion) if err != nil { ctx.Logger().Error("channel open try failed", "port-id", msg.PortId, "channel-id", channelID, "error", errorsmod.Wrap(err, "channel open try callback failed")) return nil, errorsmod.Wrapf(err, "channel open try callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) @@ -288,23 +271,16 @@ func (k *Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChan func (k *Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChannelOpenAck) (*channeltypes.MsgChannelOpenAckResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel open ack failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve application callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel open ack failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open ack failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } // Perform 04-channel verification - if err = k.ChannelKeeper.ChanOpenAck( - ctx, msg.PortId, msg.ChannelId, capability, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, + if err := k.ChannelKeeper.ChanOpenAck( + ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, ); err != nil { ctx.Logger().Error("channel open ack failed", "error", err.Error()) return nil, errorsmod.Wrap(err, "channel handshake open ack failed") @@ -314,7 +290,7 @@ func (k *Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChan k.ChannelKeeper.WriteOpenAckChannel(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion, msg.CounterpartyChannelId) // Perform application logic callback - if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelId, msg.CounterpartyVersion); err != nil { + if err := cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelId, msg.CounterpartyVersion); err != nil { ctx.Logger().Error("channel open ack failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "channel open ack callback failed")) return nil, errorsmod.Wrapf(err, "channel open ack callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } @@ -330,22 +306,15 @@ func (k *Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChan func (k *Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgChannelOpenConfirm) (*channeltypes.MsgChannelOpenConfirmResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel open confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve application callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel open confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } // Perform 04-channel verification - if err = k.ChannelKeeper.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, capability, msg.ProofAck, msg.ProofHeight); err != nil { + if err := k.ChannelKeeper.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, msg.ProofAck, msg.ProofHeight); err != nil { ctx.Logger().Error("channel open confirm failed", "error", errorsmod.Wrap(err, "channel handshake open confirm failed")) return nil, errorsmod.Wrap(err, "channel handshake open confirm failed") } @@ -354,7 +323,7 @@ func (k *Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.Msg k.ChannelKeeper.WriteOpenConfirmChannel(ctx, msg.PortId, msg.ChannelId) // Perform application logic callback - if err = cbs.OnChanOpenConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { + if err := cbs.OnChanOpenConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel open confirm failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "channel open confirm callback failed")) return nil, errorsmod.Wrapf(err, "channel open confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } @@ -368,26 +337,19 @@ func (k *Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.Msg func (k *Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgChannelCloseInit) (*channeltypes.MsgChannelCloseInitResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel close init failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel close init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel close init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } - if err = cbs.OnChanCloseInit(ctx, msg.PortId, msg.ChannelId); err != nil { + if err := cbs.OnChanCloseInit(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel close init failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "channel close init callback failed")) return nil, errorsmod.Wrapf(err, "channel close init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } - err = k.ChannelKeeper.ChanCloseInit(ctx, msg.PortId, msg.ChannelId, capability) + err := k.ChannelKeeper.ChanCloseInit(ctx, msg.PortId, msg.ChannelId) if err != nil { ctx.Logger().Error("channel close init failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) return nil, errorsmod.Wrap(err, "channel handshake close init failed") @@ -402,26 +364,19 @@ func (k *Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgCh func (k *Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.MsgChannelCloseConfirm) (*channeltypes.MsgChannelCloseConfirmResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel close confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel close confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel close confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } - if err = cbs.OnChanCloseConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { + if err := cbs.OnChanCloseConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel close confirm failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "channel close confirm callback failed")) return nil, errorsmod.Wrapf(err, "channel close confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } - err = k.ChannelKeeper.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, capability, msg.ProofInit, msg.ProofHeight, msg.CounterpartyUpgradeSequence) + err := k.ChannelKeeper.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, msg.ProofInit, msg.ProofHeight, msg.CounterpartyUpgradeSequence) if err != nil { ctx.Logger().Error("channel close confirm failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) return nil, errorsmod.Wrap(err, "channel handshake close confirm failed") @@ -442,18 +397,11 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) - if err != nil { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.Packet.DestinationPort) if !ok { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.DestinationPort)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.DestinationPort) } // Perform TAO verification @@ -461,7 +409,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack // If the packet was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - channelVersion, err := k.ChannelKeeper.RecvPacket(cacheCtx, capability, msg.Packet, msg.ProofCommitment, msg.ProofHeight) + channelVersion, err := k.ChannelKeeper.RecvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) switch err { case nil: @@ -514,18 +462,11 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) - if err != nil { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort) if !ok { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort) } // Perform TAO verification @@ -548,7 +489,7 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* } // Delete packet commitment - if err = k.ChannelKeeper.TimeoutExecuted(ctx, capability, msg.Packet); err != nil { + if err = k.ChannelKeeper.TimeoutExecuted(ctx, msg.Packet); err != nil { return nil, err } @@ -576,18 +517,10 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) - if err != nil { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - // Retrieve callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort) if !ok { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort) } // Perform TAO verification @@ -595,7 +528,7 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime // If the timeout was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - channelVersion, err := k.ChannelKeeper.TimeoutOnClose(cacheCtx, capability, msg.Packet, msg.ProofUnreceived, msg.ProofClose, msg.ProofHeight, msg.NextSequenceRecv, msg.CounterpartyUpgradeSequence) + channelVersion, err := k.ChannelKeeper.TimeoutOnClose(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofClose, msg.ProofHeight, msg.NextSequenceRecv, msg.CounterpartyUpgradeSequence) switch err { case nil: @@ -610,7 +543,7 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime } // Delete packet commitment - if err = k.ChannelKeeper.TimeoutExecuted(ctx, capability, msg.Packet); err != nil { + if err = k.ChannelKeeper.TimeoutExecuted(ctx, msg.Packet); err != nil { return nil, err } @@ -641,18 +574,10 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - // Lookup module by channel capability - module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) - if err != nil { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - // Retrieve callbacks from router - cbs, ok := k.PortKeeper.Route(module) + cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort) if !ok { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort) } // Perform TAO verification @@ -660,7 +585,7 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck // If the acknowledgement was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - channelVersion, err := k.ChannelKeeper.AcknowledgePacket(cacheCtx, capability, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) + channelVersion, err := k.ChannelKeeper.AcknowledgePacket(cacheCtx, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) switch err { case nil: @@ -696,22 +621,16 @@ func (k *Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.Msg return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer) } - module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - app, ok := k.PortKeeper.Route(module) + app, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } cbs, ok := app.(porttypes.UpgradableModule) if !ok { - ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module) + ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId) } upgrade, err := k.ChannelKeeper.ChanUpgradeInit(ctx, msg.PortId, msg.ChannelId, msg.Fields) @@ -744,22 +663,16 @@ func (k *Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.Msg func (k *Keeper) ChannelUpgradeTry(goCtx context.Context, msg *channeltypes.MsgChannelUpgradeTry) (*channeltypes.MsgChannelUpgradeTryResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel upgrade try failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - app, ok := k.PortKeeper.Route(module) + app, ok := k.PortKeeper.Route(msg.PortId) if !ok { - ctx.Logger().Error("channel upgrade try failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel upgrade try failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) } cbs, ok := app.(porttypes.UpgradableModule) if !ok { - ctx.Logger().Error("channel upgrade try failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) - return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module) + ctx.Logger().Error("channel upgrade try failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId) } channel, upgrade, err := k.ChannelKeeper.ChanUpgradeTry(ctx, msg.PortId, msg.ChannelId, msg.ProposedUpgradeConnectionHops, msg.CounterpartyUpgradeFields, msg.CounterpartyUpgradeSequence, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) @@ -805,27 +718,21 @@ func (k *Keeper) ChannelUpgradeTry(goCtx context.Context, msg *channeltypes.MsgC func (k *Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgChannelUpgradeAck) (*channeltypes.MsgChannelUpgradeAckResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - app, ok := k.PortKeeper.Route(module) + app, ok := k.PortKeeper.Route(msg.PortId) if !ok { - err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + err := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", err) return nil, err } cbs, ok := app.(porttypes.UpgradableModule) if !ok { - err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module) + err := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId) ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", err) return nil, err } - err = k.ChannelKeeper.ChanUpgradeAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) + err := k.ChannelKeeper.ChanUpgradeAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) if err != nil { ctx.Logger().Error("channel upgrade ack failed", "error", errorsmod.Wrap(err, "channel upgrade ack failed")) if channeltypes.IsUpgradeError(err) { @@ -871,27 +778,21 @@ func (k *Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgC func (k *Keeper) ChannelUpgradeConfirm(goCtx context.Context, msg *channeltypes.MsgChannelUpgradeConfirm) (*channeltypes.MsgChannelUpgradeConfirmResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel upgrade confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - app, ok := k.PortKeeper.Route(module) + app, ok := k.PortKeeper.Route(msg.PortId) if !ok { - err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + err := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) ctx.Logger().Error("channel upgrade confirm failed", "port-id", msg.PortId, "error", err) return nil, err } cbs, ok := app.(porttypes.UpgradableModule) if !ok { - err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module) + err := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId) ctx.Logger().Error("channel upgrade confirm failed", "port-id", msg.PortId, "error", err) return nil, err } - err = k.ChannelKeeper.ChanUpgradeConfirm(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.CounterpartyUpgrade, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) + err := k.ChannelKeeper.ChanUpgradeConfirm(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.CounterpartyUpgrade, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) if err != nil { ctx.Logger().Error("channel upgrade confirm failed", "error", errorsmod.Wrap(err, "channel upgrade confirm failed")) if channeltypes.IsUpgradeError(err) { @@ -932,27 +833,21 @@ func (k *Keeper) ChannelUpgradeConfirm(goCtx context.Context, msg *channeltypes. func (k *Keeper) ChannelUpgradeOpen(goCtx context.Context, msg *channeltypes.MsgChannelUpgradeOpen) (*channeltypes.MsgChannelUpgradeOpenResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) - if err != nil { - ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - - app, ok := k.PortKeeper.Route(module) + app, ok := k.PortKeeper.Route(msg.PortId) if !ok { - err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + err := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.PortId) ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", err) return nil, err } cbs, ok := app.(porttypes.UpgradableModule) if !ok { - err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module) + err := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to portID: %s", msg.PortId) ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", err) return nil, err } - if err = k.ChannelKeeper.ChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.CounterpartyUpgradeSequence, msg.ProofChannel, msg.ProofHeight); err != nil { + if err := k.ChannelKeeper.ChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.CounterpartyUpgradeSequence, msg.ProofChannel, msg.ProofHeight); err != nil { ctx.Logger().Error("channel upgrade open failed", "error", errorsmod.Wrap(err, "channel upgrade open failed")) return nil, errorsmod.Wrap(err, "channel upgrade open failed") } diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 2c04b9d378d..137e7f58aef 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -12,7 +12,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -1096,20 +1095,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() { ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, - { - "module capability not found", - func() { - msg.PortId = "invalid-port" - msg.ChannelId = "invalid-channel" - }, - func(res *channeltypes.MsgChannelUpgradeTryResponse, events []abci.Event, err error) { - suite.Require().Error(err) - suite.Require().Nil(res) - - suite.Require().ErrorIs(err, capabilitytypes.ErrCapabilityNotFound) - suite.Require().Empty(events) - }, - }, { "unsynchronized upgrade sequence writes upgrade error receipt", func() { @@ -1312,20 +1297,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, - { - "module capability not found", - func() { - msg.PortId = ibctesting.InvalidID - msg.ChannelId = ibctesting.InvalidID - }, - func(res *channeltypes.MsgChannelUpgradeAckResponse, events []abci.Event, err error) { - suite.Require().Error(err) - suite.Require().Nil(res) - - suite.Require().ErrorIs(err, capabilitytypes.ErrCapabilityNotFound) - suite.Require().Empty(events) - }, - }, { "core handler returns error and no upgrade error receipt is written", func() { @@ -1683,20 +1654,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeConfirm() { ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, - { - "module capability not found", - func() { - msg.PortId = ibctesting.InvalidID - msg.ChannelId = ibctesting.InvalidID - }, - func(res *channeltypes.MsgChannelUpgradeConfirmResponse, events []abci.Event, err error) { - suite.Require().Error(err) - suite.Require().Nil(res) - - suite.Require().ErrorIs(err, capabilitytypes.ErrCapabilityNotFound) - suite.Require().Empty(events) - }, - }, { "core handler returns error and no upgrade error receipt is written", func() { @@ -1923,20 +1880,6 @@ func (suite *KeeperTestSuite) TestChannelUpgradeOpen() { ibctesting.AssertEvents(&suite.Suite, expEvents, events) }, }, - { - "module capability not found", - func() { - msg.PortId = ibctesting.InvalidID - msg.ChannelId = ibctesting.InvalidID - }, - func(res *channeltypes.MsgChannelUpgradeOpenResponse, events []abci.Event, err error) { - suite.Require().Error(err) - suite.Require().Nil(res) - - suite.Require().ErrorIs(err, capabilitytypes.ErrCapabilityNotFound) - suite.Require().Empty(events) - }, - }, { "core handler fails", func() { diff --git a/testing/mock/ibc_app.go b/testing/mock/ibc_app.go index 687b3ec2c85..f3dcb1fa533 100644 --- a/testing/mock/ibc_app.go +++ b/testing/mock/ibc_app.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -22,7 +21,6 @@ type IBCApp struct { connectionHops []string, portID string, channelID string, - channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) @@ -33,7 +31,6 @@ type IBCApp struct { connectionHops []string, portID, channelID string, - channelCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error) diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 81728670a68..8542dc43ffe 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -10,10 +10,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -48,21 +46,14 @@ func NewIBCModule(appModule *AppModule, app *IBCApp) IBCModule { // OnChanOpenInit implements the IBCModule interface. func (im IBCModule) OnChanOpenInit( ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, - channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, + channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error) { if strings.TrimSpace(version) == "" { version = Version } if im.IBCApp.OnChanOpenInit != nil { - return im.IBCApp.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version) - } - - if chanCap != nil { - // Claim channel capability passed back by IBC module - if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } + return im.IBCApp.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, counterparty, version) } return version, nil @@ -71,17 +62,10 @@ func (im IBCModule) OnChanOpenInit( // OnChanOpenTry implements the IBCModule interface. func (im IBCModule) OnChanOpenTry( ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, - channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, + channelID string, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error) { if im.IBCApp.OnChanOpenTry != nil { - return im.IBCApp.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) - } - - if chanCap != nil { - // Claim channel capability passed back by IBC module - if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } + return im.IBCApp.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, counterparty, counterpartyVersion) } return Version, nil diff --git a/testing/mock/middleware.go b/testing/mock/middleware.go index 70891d582bd..c0295d8fb8b 100644 --- a/testing/mock/middleware.go +++ b/testing/mock/middleware.go @@ -7,11 +7,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -39,21 +37,14 @@ func NewBlockUpgradeMiddleware(appModule *AppModule, app *IBCApp) BlockUpgradeMi // OnChanOpenInit implements the IBCModule interface. func (im BlockUpgradeMiddleware) OnChanOpenInit( ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, - channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, + channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error) { if strings.TrimSpace(version) == "" { version = Version } if im.IBCApp.OnChanOpenInit != nil { - return im.IBCApp.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version) - } - - if chanCap != nil { - // Claim channel capability passed back by IBC module - if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } + return im.IBCApp.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, counterparty, version) } return version, nil @@ -62,17 +53,10 @@ func (im BlockUpgradeMiddleware) OnChanOpenInit( // OnChanOpenTry implements the IBCModule interface. func (im BlockUpgradeMiddleware) OnChanOpenTry( ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, - channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, + channelID string, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error) { if im.IBCApp.OnChanOpenTry != nil { - return im.IBCApp.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) - } - - if chanCap != nil { - // Claim channel capability passed back by IBC module - if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", err - } + return im.IBCApp.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, counterparty, counterpartyVersion) } return Version, nil From a2cb6d65db1442b682fc4b1fc7d38efa83666bbb Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 3 Sep 2024 13:57:16 +0200 Subject: [PATCH 3/3] chore: remove exp pkg (#7237) * chore: remove exp pkg * sort keys --- e2e/go.mod | 2 +- e2e/testsuite/testsuite.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- modules/core/05-port/types/router.go | 12 +++++++++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/e2e/go.mod b/e2e/go.mod index 126f95a07eb..6dc29d102eb 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -24,7 +24,6 @@ require ( github.com/strangelove-ventures/interchaintest/v8 v8.2.1-0.20240419152858-c8b741617cd8 github.com/stretchr/testify v1.9.0 go.uber.org/zap v1.27.0 - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 golang.org/x/mod v0.20.0 google.golang.org/grpc v1.66.0 gopkg.in/yaml.v2 v2.4.0 @@ -237,6 +236,7 @@ require ( go.opentelemetry.io/otel/trace v1.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 4237afacbec..cb8ab6ed9c1 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path" + "slices" "strings" "sync" @@ -17,7 +18,6 @@ import ( test "github.com/strangelove-ventures/interchaintest/v8/testutil" testifysuite "github.com/stretchr/testify/suite" "go.uber.org/zap" - "golang.org/x/exp/slices" sdkmath "cosmossdk.io/math" diff --git a/go.mod b/go.mod index 89c4db16f3b..c717a630f6b 100644 --- a/go.mod +++ b/go.mod @@ -178,7 +178,7 @@ require ( go.opentelemetry.io/otel/trace v1.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect + golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/go.sum b/go.sum index 43cbd894041..2509eb4cd2a 100644 --- a/go.sum +++ b/go.sum @@ -1048,8 +1048,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8= +golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/modules/core/05-port/types/router.go b/modules/core/05-port/types/router.go index 7b6b629f3ff..5c7014526f4 100644 --- a/modules/core/05-port/types/router.go +++ b/modules/core/05-port/types/router.go @@ -3,8 +3,7 @@ package types import ( "errors" "fmt" - - "golang.org/x/exp/maps" + "sort" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -69,5 +68,12 @@ func (rtr *Router) Route(module string) (IBCModule, bool) { // Keys returns the keys of the routes map. func (rtr *Router) Keys() []string { - return maps.Keys(rtr.routes) + keys := make([]string, 0, len(rtr.routes)) + + for k := range rtr.routes { + keys = append(keys, k) + } + + sort.Strings(keys) + return keys }