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) }