diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 05dd4cb3177..84bb7e0b13c 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -58,7 +58,7 @@ func NewIBCMiddlewareWithAuth(app porttypes.IBCModule, k keeper.Keeper) IBCMiddl // version. They will be allowed to perform custom logic without changing // the parameters stored within a channel struct. func (im IBCMiddleware) OnChanOpenInit( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, @@ -94,7 +94,7 @@ func (im IBCMiddleware) OnChanOpenInit( // OnChanOpenTry implements the IBCMiddleware interface func (IBCMiddleware) OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -113,7 +113,7 @@ func (IBCMiddleware) OnChanOpenTry( // version. They will be allowed to perform custom logic without changing // the parameters stored within a channel struct. func (im IBCMiddleware) OnChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannelID string, @@ -142,7 +142,7 @@ func (im IBCMiddleware) OnChanOpenAck( // OnChanOpenConfirm implements the IBCMiddleware interface func (IBCMiddleware) OnChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -151,7 +151,7 @@ func (IBCMiddleware) OnChanOpenConfirm( // OnChanCloseInit implements the IBCMiddleware interface func (IBCMiddleware) OnChanCloseInit( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -161,7 +161,7 @@ func (IBCMiddleware) OnChanCloseInit( // OnChanCloseConfirm implements the IBCMiddleware interface func (im IBCMiddleware) OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -183,7 +183,7 @@ func (im IBCMiddleware) OnChanCloseConfirm( // OnRecvPacket implements the IBCMiddleware interface func (IBCMiddleware) OnRecvPacket( - ctx sdk.Context, + ctx context.Context, _ string, packet channeltypes.Packet, _ sdk.AccAddress, @@ -196,7 +196,7 @@ func (IBCMiddleware) OnRecvPacket( // OnAcknowledgementPacket implements the IBCMiddleware interface func (im IBCMiddleware) OnAcknowledgementPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, @@ -221,7 +221,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket( // OnTimeoutPacket implements the IBCMiddleware interface func (im IBCMiddleware) OnTimeoutPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -247,7 +247,7 @@ func (im IBCMiddleware) OnTimeoutPacket( } // OnChanUpgradeInit implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { +func (im IBCMiddleware) OnChanUpgradeInit(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { if !im.keeper.GetParams(ctx).ControllerEnabled { return "", types.ErrControllerSubModuleDisabled } @@ -275,12 +275,12 @@ func (im IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID str } // OnChanUpgradeTry implements the IBCModule interface -func (IBCMiddleware) OnChanUpgradeTry(_ sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (IBCMiddleware) OnChanUpgradeTry(_ context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel upgrade handshake must be initiated by controller chain") } // OnChanUpgradeAck implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { +func (im IBCMiddleware) OnChanUpgradeAck(ctx context.Context, portID, channelID, counterpartyVersion string) error { if !im.keeper.GetParams(ctx).ControllerEnabled { return types.ErrControllerSubModuleDisabled } @@ -307,7 +307,7 @@ func (im IBCMiddleware) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, cou } // OnChanUpgradeOpen implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { +func (im IBCMiddleware) OnChanUpgradeOpen(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { connectionID, err := im.keeper.GetConnectionID(ctx, portID, channelID) if err != nil { panic(err) 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 b169e10f284..11951cbe655 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go @@ -1,6 +1,7 @@ package controller_test import ( + "context" "fmt" "strconv" "testing" @@ -129,7 +130,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { }, { "ICA auth module does not claim channel capability", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string, + 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) { @@ -145,7 +146,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { "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 sdk.Context, order channeltypes.Order, connectionHops []string, + 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) { @@ -160,7 +161,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { }, { "ICA auth module callback fails", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string, + 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) { @@ -177,7 +178,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() { "middleware disabled", func() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenInit = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string, + 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) { @@ -333,7 +334,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() { { "ICA auth module callback fails", func() { suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenAck = func( - ctx sdk.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string, + ctx context.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string, ) error { return fmt.Errorf("mock ica auth fails") } @@ -349,7 +350,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenAck = func( - ctx sdk.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string, + ctx context.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string, ) error { return fmt.Errorf("error should be unreachable") } @@ -622,7 +623,7 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() { { "ICA auth module callback fails", func() { suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnAcknowledgementPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, ) error { return fmt.Errorf("mock ica auth fails") } @@ -638,7 +639,7 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnAcknowledgementPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, ) error { return fmt.Errorf("error should be unreachable") } @@ -719,7 +720,7 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { { "ICA auth module callback fails", func() { suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnTimeoutPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) error { return fmt.Errorf("mock ica auth fails") } @@ -735,7 +736,7 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnTimeoutPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) error { return fmt.Errorf("error should be unreachable") } @@ -826,7 +827,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() { }, { "ICA auth module callback fails", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { return "", ibcmock.MockApplicationCallbackError } }, ibcmock.MockApplicationCallbackError, @@ -834,7 +835,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() { { "middleware disabled", func() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeInit = func(ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { return "", ibcmock.MockApplicationCallbackError } }, nil, @@ -954,7 +955,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() { }, { "ICA auth module callback fails", func() { - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx context.Context, portID, channelID string, counterpartyVersion string) error { return ibcmock.MockApplicationCallbackError } }, ibcmock.MockApplicationCallbackError, @@ -962,7 +963,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() { { "middleware disabled", func() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx context.Context, portID, channelID string, counterpartyVersion string) error { return ibcmock.MockApplicationCallbackError } }, nil, @@ -1039,7 +1040,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeOpen() { { "middleware disabled", func() { suite.chainA.GetSimApp().ICAControllerKeeper.DeleteMiddlewareEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID string, counterpartyVersion string) error { + suite.chainA.GetSimApp().ICAAuthModule.IBCApp.OnChanUpgradeAck = func(ctx context.Context, portID, channelID string, counterpartyVersion string) error { return ibcmock.MockApplicationCallbackError } }, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account_test.go b/modules/apps/27-interchain-accounts/controller/keeper/account_test.go index 3366713daab..13196d7314b 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account_test.go @@ -45,6 +45,9 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { portID, err := icatypes.NewControllerPortID(TestOwnerAddress) suite.Require().NoError(err) + channelID := channeltypes.FormatChannelIdentifier(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextChannelSequence(suite.chainA.GetContext())) + path.EndpointA.ChannelID = channelID + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID) counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/events.go b/modules/apps/27-interchain-accounts/controller/keeper/events.go index 5743253b530..468a1028a5c 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/events.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/events.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,7 +13,8 @@ import ( // EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error // details if any. -func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { +func EmitAcknowledgementEvent(ctx context.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 attributes := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), sdk.NewAttribute(icatypes.AttributeKeyControllerChannelID, packet.GetDestChannel()), @@ -23,7 +25,7 @@ func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack e attributes = append(attributes, sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error())) } - ctx.EventManager().EmitEvent( + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( icatypes.EventTypePacket, attributes..., diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 609e6ae17b3..8e0ca30a1f3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -1,13 +1,12 @@ package keeper import ( + "context" "fmt" "strings" errorsmod "cosmossdk.io/errors" - 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" @@ -21,7 +20,7 @@ import ( // and the interchain accounts module must be able to claim the channel // capability. func (k Keeper) OnChanOpenInit( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, @@ -91,7 +90,7 @@ func (k Keeper) OnChanOpenInit( // OnChanOpenAck sets the active channel for the interchain account/owner pair // and stores the associated interchain account address in state keyed by it's corresponding port identifier func (k Keeper) OnChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyVersion string, @@ -133,7 +132,7 @@ func (k Keeper) OnChanOpenAck( // OnChanCloseConfirm removes the active channel stored in state func (Keeper) OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -154,7 +153,7 @@ func (Keeper) OnChanCloseConfirm( // - connectionHops (and subsequently host/controller connectionIDs) // - interchain account address // - ICS27 protocol version -func (k Keeper) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedversion string) (string, error) { +func (k Keeper) OnChanUpgradeInit(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedversion string) (string, error) { // verify connection hops has not changed connectionID, err := k.GetConnectionID(ctx, portID, channelID) if err != nil { @@ -217,7 +216,7 @@ func (k Keeper) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, pro // - host connectionID // - interchain account address // - ICS27 protocol version -func (k Keeper) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { +func (k Keeper) OnChanUpgradeAck(ctx context.Context, portID, channelID, counterpartyVersion string) error { if strings.TrimSpace(counterpartyVersion) == "" { return errorsmod.Wrap(channeltypes.ErrInvalidChannelVersion, "counterparty version cannot be empty") } 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 fe9b348f3c5..abc062b1649 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -294,11 +294,14 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { Version: string(versionBytes), } - chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) - suite.Require().NoError(err) + channelID := channeltypes.FormatChannelIdentifier(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextChannelSequence(suite.chainA.GetContext())) + path.EndpointA.ChannelID = channelID 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, ) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 46b040c4568..584fa109361 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -7,11 +7,13 @@ import ( "fmt" "strings" + corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -27,7 +29,7 @@ import ( // Keeper defines the IBC interchain accounts controller keeper type Keeper struct { - storeKey storetypes.StoreKey + storeService corestore.KVStoreService cdc codec.Codec legacySubspace icatypes.ParamSubspace ics4Wrapper porttypes.ICS4Wrapper @@ -45,7 +47,7 @@ type Keeper struct { // NewKeeper creates a new interchain accounts controller Keeper instance func NewKeeper( - cdc codec.Codec, key storetypes.StoreKey, legacySubspace icatypes.ParamSubspace, + cdc codec.Codec, storeService corestore.KVStoreService, legacySubspace icatypes.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string, ) Keeper { @@ -54,7 +56,7 @@ func NewKeeper( } return Keeper{ - storeKey: key, + storeService: storeService, cdc: cdc, legacySubspace: legacySubspace, ics4Wrapper: ics4Wrapper, @@ -79,12 +81,13 @@ func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper { } // Logger returns the application logger, scoped to the associated module -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName)) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName)) } // GetConnectionID returns the connection id for the given port and channelIDs. -func (k Keeper) GetConnectionID(ctx sdk.Context, portID, channelID string) (string, error) { +func (k Keeper) GetConnectionID(ctx context.Context, portID, channelID string) (string, error) { channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { return "", errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) @@ -93,10 +96,10 @@ func (k Keeper) GetConnectionID(ctx sdk.Context, portID, channelID string) (stri } // GetAllPorts returns all ports to which the interchain accounts controller module is bound. Used in ExportGenesis -func (k Keeper) GetAllPorts(ctx sdk.Context) []string { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetAllPorts(ctx context.Context) []string { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(icatypes.PortKeyPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var ports []string for ; iterator.Valid(); iterator.Next() { @@ -109,25 +112,30 @@ func (k Keeper) GetAllPorts(ctx sdk.Context) []string { } // setPort sets the provided portID in state -func (k Keeper) setPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyPort(portID), []byte{0x01}) +func (k Keeper) setPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyPort(portID), []byte{0x01}); err != nil { + panic(err) + } } // hasCapability checks if the interchain account controller module owns the port capability for the desired port -func (k Keeper) hasCapability(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) +func (k Keeper) hasCapability(ctx context.Context, portID string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + _, ok := k.scopedKeeper.GetCapability(sdkCtx, host.PortPath(portID)) return ok } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function -func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool { - return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) +func (k Keeper) AuthenticateCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return k.scopedKeeper.AuthenticateCapability(sdkCtx, cap, name) } // ClaimCapability wraps the scopedKeeper's ClaimCapability function -func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { - return k.scopedKeeper.ClaimCapability(ctx, cap, name) +func (k Keeper) ClaimCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return k.scopedKeeper.ClaimCapability(sdkCtx, cap, name) } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. @@ -136,19 +144,23 @@ func (k Keeper) GetAppVersion(ctx context.Context, portID, channelID string) (st } // GetActiveChannelID retrieves the active channelID from the store, keyed by the provided connectionID and portID -func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetActiveChannelID(ctx context.Context, connectionID, portID string) (string, bool) { + store := k.storeService.OpenKVStore(ctx) key := icatypes.KeyActiveChannel(portID, connectionID) - if !store.Has(key) { + bz, err := store.Get(key) + if err != nil { + panic(err) + } + if len(bz) == 0 { return "", false } - return string(store.Get(key)), true + return string(bz), true } // GetOpenActiveChannel retrieves the active channelID from the store, keyed by the provided connectionID and portID & checks if the channel in question is in state OPEN -func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID string) (string, bool) { +func (k Keeper) GetOpenActiveChannel(ctx context.Context, connectionID, portID string) (string, bool) { channelID, found := k.GetActiveChannelID(ctx, connectionID, portID) if !found { return "", false @@ -164,7 +176,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin } // IsActiveChannelClosed retrieves the active channel from the store and returns true if the channel state is CLOSED, otherwise false -func (k Keeper) IsActiveChannelClosed(ctx sdk.Context, connectionID, portID string) bool { +func (k Keeper) IsActiveChannelClosed(ctx context.Context, connectionID, portID string) bool { channelID, found := k.GetActiveChannelID(ctx, connectionID, portID) if !found { return false @@ -175,10 +187,10 @@ func (k Keeper) IsActiveChannelClosed(ctx sdk.Context, connectionID, portID stri } // GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated connection and port identifiers -func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChannel { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetAllActiveChannels(ctx context.Context) []genesistypes.ActiveChannel { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var activeChannels []genesistypes.ActiveChannel for ; iterator.Valid(); iterator.Next() { @@ -202,32 +214,38 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChann } // SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID -func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID)) +func (k Keeper) SetActiveChannelID(ctx context.Context, connectionID, portID, channelID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID)); err != nil { + panic(err) + } } // IsActiveChannel returns true if there exists an active channel for the provided connectionID and portID, otherwise false -func (k Keeper) IsActiveChannel(ctx sdk.Context, connectionID, portID string) bool { +func (k Keeper) IsActiveChannel(ctx context.Context, connectionID, portID string) bool { _, ok := k.GetActiveChannelID(ctx, connectionID, portID) return ok } // GetInterchainAccountAddress retrieves the InterchainAccount address from the store associated with the provided connectionID and portID -func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetInterchainAccountAddress(ctx context.Context, connectionID, portID string) (string, bool) { + store := k.storeService.OpenKVStore(ctx) key := icatypes.KeyOwnerAccount(portID, connectionID) - if !store.Has(key) { + bz, err := store.Get(key) + if err != nil { + panic(err) + } + if len(bz) == 0 { return "", false } - return string(store.Get(key)), true + return string(bz), true } // GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated connection and controller port identifiers -func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []genesistypes.RegisteredInterchainAccount { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetAllInterchainAccounts(ctx context.Context) []genesistypes.RegisteredInterchainAccount { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix)) var interchainAccounts []genesistypes.RegisteredInterchainAccount @@ -247,39 +265,55 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []genesistypes.Registe } // SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated connectionID and portID -func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portID, address string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) +func (k Keeper) SetInterchainAccountAddress(ctx context.Context, connectionID, portID, address string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)); err != nil { + panic(err) + } } // IsMiddlewareEnabled returns true if the underlying application callbacks are enabled for given port and connection identifier pair, otherwise false -func (k Keeper) IsMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) bool { - store := ctx.KVStore(k.storeKey) - return bytes.Equal(icatypes.MiddlewareEnabled, store.Get(icatypes.KeyIsMiddlewareEnabled(portID, connectionID))) +func (k Keeper) IsMiddlewareEnabled(ctx context.Context, portID, connectionID string) bool { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)) + if err != nil { + panic(err) + } + return bytes.Equal(icatypes.MiddlewareEnabled, bz) } // IsMiddlewareDisabled returns true if the underlying application callbacks are disabled for the given port and connection identifier pair, otherwise false -func (k Keeper) IsMiddlewareDisabled(ctx sdk.Context, portID, connectionID string) bool { - store := ctx.KVStore(k.storeKey) - return bytes.Equal(icatypes.MiddlewareDisabled, store.Get(icatypes.KeyIsMiddlewareEnabled(portID, connectionID))) +func (k Keeper) IsMiddlewareDisabled(ctx context.Context, portID, connectionID string) bool { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)) + if err != nil { + panic(err) + } + return bytes.Equal(icatypes.MiddlewareDisabled, bz) } // SetMiddlewareEnabled stores a flag to indicate that the underlying application callbacks should be enabled for the given port and connection identifier pair -func (k Keeper) SetMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), icatypes.MiddlewareEnabled) +func (k Keeper) SetMiddlewareEnabled(ctx context.Context, portID, connectionID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), icatypes.MiddlewareEnabled); err != nil { + panic(err) + } } // SetMiddlewareDisabled stores a flag to indicate that the underlying application callbacks should be disabled for the given port and connection identifier pair -func (k Keeper) SetMiddlewareDisabled(ctx sdk.Context, portID, connectionID string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), icatypes.MiddlewareDisabled) +func (k Keeper) SetMiddlewareDisabled(ctx context.Context, portID, connectionID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), icatypes.MiddlewareDisabled); err != nil { + panic(err) + } } // DeleteMiddlewareEnabled deletes the middleware enabled flag stored in state -func (k Keeper) DeleteMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) { - store := ctx.KVStore(k.storeKey) - store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)) +func (k Keeper) DeleteMiddlewareEnabled(ctx context.Context, portID, connectionID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)); err != nil { + panic(err) + } } // GetAuthority returns the ica/controller submodule's authority. @@ -288,7 +322,7 @@ func (k Keeper) GetAuthority() string { } // getAppMetadata retrieves the interchain accounts channel metadata from the store associated with the provided portID and channelID -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) { appVersion, found := k.GetAppVersion(ctx, portID, channelID) if !found { return icatypes.Metadata{}, errorsmod.Wrapf(ibcerrors.ErrNotFound, "app version not found for port %s and channel %s", portID, channelID) @@ -298,9 +332,12 @@ func (k Keeper) getAppMetadata(ctx sdk.Context, portID, channelID string) (icaty } // GetParams returns the current ica/controller submodule parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.ParamsKey)) +func (k Keeper) GetParams(ctx context.Context) types.Params { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte(types.ParamsKey)) + if err != nil { + panic(err) + } if bz == nil { // only panic on unset params and not on empty params panic(errors.New("ica/controller params are not set in store")) } @@ -311,8 +348,10 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the ica/controller submodule parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetParams(ctx context.Context, params types.Params) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(¶ms) - store.Set([]byte(types.ParamsKey), bz) + if err := store.Set([]byte(types.ParamsKey), bz); err != nil { + panic(err) + } } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go index 701e0b7fd6e..bffb0a87105 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -5,6 +5,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/runtime" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -117,7 +118,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"success", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -130,7 +131,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: empty authority", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go index f4d25b37ea7..f7751fa9476 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/runtime" + icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper" icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types" ) @@ -27,7 +29,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { func() { suite.chainA.GetSimApp().ICAControllerKeeper = icacontrollerkeeper.NewKeeper( suite.chainA.Codec, - suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)), nil, // assign a nil legacy param subspace suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index 7493bd0bde9..280328727b0 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -60,6 +62,6 @@ func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketDa // OnTimeoutPacket removes the active channel associated with the provided packet, the underlying channel end is closed // due to the semantics of ORDERED channels -func (Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet) error { +func (Keeper) OnTimeoutPacket(ctx context.Context, packet channeltypes.Packet) error { return nil } diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 752b4b9d5c7..0181a6a65b8 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -38,7 +38,7 @@ func NewIBCModule(k keeper.Keeper) IBCModule { // OnChanOpenInit implements the IBCModule interface func (IBCModule) OnChanOpenInit( - _ sdk.Context, + _ context.Context, _ channeltypes.Order, _ []string, _ string, @@ -52,7 +52,7 @@ func (IBCModule) OnChanOpenInit( // OnChanOpenTry implements the IBCModule interface func (im IBCModule) OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -70,7 +70,7 @@ func (im IBCModule) OnChanOpenTry( // OnChanOpenAck implements the IBCModule interface func (IBCModule) OnChanOpenAck( - _ sdk.Context, + _ context.Context, _, _ string, _ string, @@ -81,7 +81,7 @@ func (IBCModule) OnChanOpenAck( // OnChanOpenConfirm implements the IBCModule interface func (im IBCModule) OnChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -94,7 +94,7 @@ func (im IBCModule) OnChanOpenConfirm( // OnChanCloseInit implements the IBCModule interface func (IBCModule) OnChanCloseInit( - _ sdk.Context, + _ context.Context, _ string, _ string, ) error { @@ -104,7 +104,7 @@ func (IBCModule) OnChanCloseInit( // OnChanCloseConfirm implements the IBCModule interface func (im IBCModule) OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -113,7 +113,7 @@ func (im IBCModule) OnChanCloseConfirm( // OnRecvPacket implements the IBCModule interface func (im IBCModule) OnRecvPacket( - ctx sdk.Context, + ctx context.Context, _ string, packet channeltypes.Packet, _ sdk.AccAddress, @@ -142,7 +142,7 @@ func (im IBCModule) OnRecvPacket( // OnAcknowledgementPacket implements the IBCModule interface func (IBCModule) OnAcknowledgementPacket( - _ sdk.Context, + _ context.Context, _ string, _ channeltypes.Packet, _ []byte, @@ -153,7 +153,7 @@ func (IBCModule) OnAcknowledgementPacket( // OnTimeoutPacket implements the IBCModule interface func (IBCModule) OnTimeoutPacket( - _ sdk.Context, + _ context.Context, _ string, _ channeltypes.Packet, _ sdk.AccAddress, @@ -162,12 +162,12 @@ func (IBCModule) OnTimeoutPacket( } // OnChanUpgradeInit implements the IBCModule interface -func (IBCModule) OnChanUpgradeInit(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { +func (IBCModule) OnChanUpgradeInit(_ context.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel upgrade handshake must be initiated by controller chain") } // OnChanUpgradeTry implements the IBCModule interface -func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (im IBCModule) OnChanUpgradeTry(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { if !im.keeper.GetParams(ctx).HostEnabled { return "", types.ErrHostSubModuleDisabled } @@ -176,12 +176,12 @@ func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, } // OnChanUpgradeAck implements the IBCModule interface -func (IBCModule) OnChanUpgradeAck(_ sdk.Context, _, _, _ string) error { +func (IBCModule) OnChanUpgradeAck(_ context.Context, _, _, _ string) error { return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel upgrade handshake must be initiated by controller chain") } // OnChanUpgradeOpen implements the IBCModule interface -func (IBCModule) OnChanUpgradeOpen(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) { +func (IBCModule) OnChanUpgradeOpen(_ context.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) { } // UnmarshalPacketData attempts to unmarshal the provided packet data bytes 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 c29efb59816..ba88fbdd3fa 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -1,6 +1,7 @@ package host_test import ( + "context" "fmt" "strconv" "testing" @@ -160,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 sdk.Context, order channeltypes.Order, connectionHops []string, + suite.chainB.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenTry = func(ctx context.Context, order channeltypes.Order, connectionHops []string, portID, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { @@ -282,7 +283,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() { "success: ICA auth module callback returns error", func() { // mock module callback should not be called on host side suite.chainB.GetSimApp().ICAAuthModule.IBCApp.OnChanOpenConfirm = func( - ctx sdk.Context, portID, channelID string, + ctx context.Context, portID, channelID string, ) error { return fmt.Errorf("mock ica auth fails") } @@ -424,7 +425,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { { "success with ICA auth module callback failure", func() { suite.chainB.GetSimApp().ICAAuthModule.IBCApp.OnRecvPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement { return channeltypes.NewErrorAcknowledgement(fmt.Errorf("failed OnRecvPacket mock callback")) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/account.go b/modules/apps/27-interchain-accounts/host/keeper/account.go index 9e2cc425d5d..c6b239232bb 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/account.go +++ b/modules/apps/27-interchain-accounts/host/keeper/account.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,7 +14,7 @@ import ( // createInterchainAccount creates a new interchain account. An address is generated using the host connectionID, the controller portID, // and block dependent information. An error is returned if an account already exists for the generated account. // An interchain account type is set in the account keeper and the interchain account address mapping is updated. -func (k Keeper) createInterchainAccount(ctx sdk.Context, connectionID, controllerPortID string) (sdk.AccAddress, error) { +func (k Keeper) createInterchainAccount(ctx context.Context, connectionID, controllerPortID string) (sdk.AccAddress, error) { accAddress := icatypes.GenerateAddress(ctx, connectionID, controllerPortID) if acc := k.accountKeeper.GetAccount(ctx, accAddress); acc != nil { diff --git a/modules/apps/27-interchain-accounts/host/keeper/events.go b/modules/apps/27-interchain-accounts/host/keeper/events.go index 91af1e449c4..fb497ec2ca3 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/events.go +++ b/modules/apps/27-interchain-accounts/host/keeper/events.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +14,7 @@ import ( // EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error // details if any. -func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { +func EmitAcknowledgementEvent(ctx context.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { attributes := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()), @@ -23,8 +24,8 @@ func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack e if err != nil { attributes = append(attributes, sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error())) } - - ctx.EventManager().EmitEvent( + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( icatypes.EventTypePacket, attributes..., @@ -33,8 +34,9 @@ func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack e } // EmitHostDisabledEvent emits an event signalling that the host submodule is disabled. -func EmitHostDisabledEvent(ctx sdk.Context, packet channeltypes.Packet) { - ctx.EventManager().EmitEvent( +func EmitHostDisabledEvent(ctx context.Context, packet channeltypes.Packet) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( icatypes.EventTypePacket, sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 0de6b77a731..4e8fcfb5f93 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "strings" @@ -21,7 +22,7 @@ import ( // The version returned will include the registered interchain // account address. func (k Keeper) OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -71,7 +72,8 @@ func (k Keeper) OnChanOpenTry( // 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 { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if err = k.ClaimCapability(sdkCtx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", errorsmod.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) } @@ -105,7 +107,7 @@ func (k Keeper) OnChanOpenTry( // OnChanOpenConfirm completes the handshake process by setting the active channel in state on the host chain func (k Keeper) OnChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -125,7 +127,7 @@ func (k Keeper) OnChanOpenConfirm( // OnChanCloseConfirm removes the active channel stored in state func (Keeper) OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -146,7 +148,7 @@ func (Keeper) OnChanCloseConfirm( // - connectionHops (and subsequently host/controller connectionIDs) // - interchain account address // - ICS27 protocol version -func (k Keeper) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (k Keeper) OnChanUpgradeTry(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { if portID != icatypes.HostPortID { return "", errorsmod.Wrapf(porttypes.ErrInvalidPort, "expected %s, got %s", icatypes.HostPortID, portID) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 86fb5f7accf..5ee78ac8aea 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -13,11 +13,13 @@ import ( msgv1 "cosmossdk.io/api/cosmos/msg/v1" queryv1 "cosmossdk.io/api/cosmos/query/v1" + corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -33,7 +35,7 @@ import ( // Keeper defines the IBC interchain accounts host keeper type Keeper struct { - storeKey storetypes.StoreKey + storeService corestore.KVStoreService cdc codec.Codec legacySubspace icatypes.ParamSubspace @@ -57,7 +59,7 @@ type Keeper struct { // NewKeeper creates a new interchain accounts host Keeper instance func NewKeeper( - cdc codec.Codec, key storetypes.StoreKey, legacySubspace icatypes.ParamSubspace, + cdc codec.Codec, storeService corestore.KVStoreService, legacySubspace icatypes.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, queryRouter icatypes.QueryRouter, authority string, @@ -72,7 +74,7 @@ func NewKeeper( } return Keeper{ - storeKey: key, + storeService: storeService, cdc: cdc, legacySubspace: legacySubspace, ics4Wrapper: ics4Wrapper, @@ -100,12 +102,13 @@ func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper { } // Logger returns the application logger, scoped to the associated module -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName)) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after context.Context is removed from core IBC + return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName)) } // getConnectionID returns the connection id for the given port and channelIDs. -func (k Keeper) getConnectionID(ctx sdk.Context, portID, channelID string) (string, error) { +func (k Keeper) getConnectionID(ctx context.Context, portID, channelID string) (string, error) { channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { return "", errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) @@ -114,25 +117,30 @@ func (k Keeper) getConnectionID(ctx sdk.Context, portID, channelID string) (stri } // setPort sets the provided portID in state. -func (k Keeper) setPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyPort(portID), []byte{0x01}) +func (k Keeper) setPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyPort(portID), []byte{0x01}); err != nil { + panic(err) + } } // hasCapability checks if the interchain account host module owns the port capability for the desired port -func (k Keeper) hasCapability(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) +func (k Keeper) hasCapability(ctx context.Context, portID string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + _, ok := k.scopedKeeper.GetCapability(sdkCtx, host.PortPath(portID)) return ok } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function -func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool { - return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) +func (k Keeper) AuthenticateCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return k.scopedKeeper.AuthenticateCapability(sdkCtx, cap, name) } // ClaimCapability wraps the scopedKeeper's ClaimCapability function -func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { - return k.scopedKeeper.ClaimCapability(ctx, cap, name) +func (k Keeper) ClaimCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return k.scopedKeeper.ClaimCapability(sdkCtx, cap, name) } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. @@ -141,7 +149,7 @@ func (k Keeper) GetAppVersion(ctx context.Context, portID, channelID string) (st } // getAppMetadata retrieves the interchain accounts channel metadata from the store associated with the provided portID and channelID -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) { appVersion, found := k.GetAppVersion(ctx, portID, channelID) if !found { return icatypes.Metadata{}, errorsmod.Wrapf(ibcerrors.ErrNotFound, "app version not found for port %s and channel %s", portID, channelID) @@ -151,19 +159,23 @@ func (k Keeper) getAppMetadata(ctx sdk.Context, portID, channelID string) (icaty } // GetActiveChannelID retrieves the active channelID from the store keyed by the provided connectionID and portID -func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetActiveChannelID(ctx context.Context, connectionID, portID string) (string, bool) { + store := k.storeService.OpenKVStore(ctx) key := icatypes.KeyActiveChannel(portID, connectionID) - if !store.Has(key) { + bz, err := store.Get(key) + if err != nil { + panic(err) + } + if len(bz) == 0 { return "", false } - return string(store.Get(key)), true + return string(bz), true } // GetOpenActiveChannel retrieves the active channelID from the store, keyed by the provided connectionID and portID & checks if the channel in question is in state OPEN -func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID string) (string, bool) { +func (k Keeper) GetOpenActiveChannel(ctx context.Context, connectionID, portID string) (string, bool) { channelID, found := k.GetActiveChannelID(ctx, connectionID, portID) if !found { return "", false @@ -179,10 +191,10 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin } // GetAllActiveChannels returns a list of all active interchain accounts host channels and their associated connection and port identifiers -func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChannel { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetAllActiveChannels(ctx context.Context) []genesistypes.ActiveChannel { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var activeChannels []genesistypes.ActiveChannel for ; iterator.Valid(); iterator.Next() { @@ -201,32 +213,38 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChann } // SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID -func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID)) +func (k Keeper) SetActiveChannelID(ctx context.Context, connectionID, portID, channelID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID)); err != nil { + panic(err) + } } // IsActiveChannel returns true if there exists an active channel for the provided connectionID and portID, otherwise false -func (k Keeper) IsActiveChannel(ctx sdk.Context, connectionID, portID string) bool { +func (k Keeper) IsActiveChannel(ctx context.Context, connectionID, portID string) bool { _, ok := k.GetActiveChannelID(ctx, connectionID, portID) return ok } // GetInterchainAccountAddress retrieves the InterchainAccount address from the store associated with the provided connectionID and portID -func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetInterchainAccountAddress(ctx context.Context, connectionID, portID string) (string, bool) { + store := k.storeService.OpenKVStore(ctx) key := icatypes.KeyOwnerAccount(portID, connectionID) - if !store.Has(key) { + bz, err := store.Get(key) + if len(bz) == 0 { return "", false } + if err != nil { + panic(err) + } - return string(store.Get(key)), true + return string(bz), true } // GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated connection and controller port identifiers -func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []genesistypes.RegisteredInterchainAccount { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetAllInterchainAccounts(ctx context.Context) []genesistypes.RegisteredInterchainAccount { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix)) var interchainAccounts []genesistypes.RegisteredInterchainAccount @@ -246,9 +264,11 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []genesistypes.Registe } // SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated connectionID and portID -func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portID, address string) { - store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) +func (k Keeper) SetInterchainAccountAddress(ctx context.Context, connectionID, portID, address string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)); err != nil { + panic(err) + } } // GetAuthority returns the 27-interchain-accounts host submodule's authority. @@ -257,9 +277,12 @@ func (k Keeper) GetAuthority() string { } // GetParams returns the total set of the host submodule parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.ParamsKey)) +func (k Keeper) GetParams(ctx context.Context) types.Params { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte(types.ParamsKey)) + if err != nil { + panic(err) + } if bz == nil { // only panic on unset params and not on empty params panic(errors.New("ica/host params are not set in store")) } @@ -270,10 +293,12 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the total set of the host submodule parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetParams(ctx context.Context, params types.Params) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(¶ms) - store.Set([]byte(types.ParamsKey), bz) + if err := store.Set([]byte(types.ParamsKey), bz); err != nil { + panic(err) + } } // newModuleQuerySafeAllowList returns a list of all query paths labeled with module_query_safe in the proto files. diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index efd201712ae..4a4e000bfd5 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/runtime" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" genesistypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/genesis/types" @@ -141,7 +142,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"success", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -156,7 +157,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: interchain accounts module account does not exist", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -171,7 +172,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: empty mock staking keeper", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.SubModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go index a4007c3d7bc..b190c0a921b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/runtime" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -30,7 +31,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { func() { suite.chainA.GetSimApp().ICAHostKeeper = icahostkeeper.NewKeeper( suite.chainA.Codec, - suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)), nil, // assign a nil legacy param subspace suite.chainA.GetSimApp().IBCFeeKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index 91c03a75ee1..cc395a1197a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + "github.com/cosmos/gogoproto/proto" errorsmod "cosmossdk.io/errors" @@ -16,7 +18,7 @@ import ( // OnRecvPacket handles a given interchain accounts packet on a destination host chain. // If the transaction is successfully executed, the transaction response bytes will be returned. -func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byte, error) { +func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet) ([]byte, error) { var data icatypes.InterchainAccountPacketData err := data.UnmarshalJSON(packet.GetData()) if err != nil { @@ -50,7 +52,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byt // If authentication succeeds, it does basic validation of the messages before attempting to deliver each message // into state. The state changes will only be committed if all messages in the transaction succeed. Thus the // execution of the transaction is atomic, all state changes are reverted if a single message fails. -func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel string, msgs []sdk.Msg) ([]byte, error) { +func (k Keeper) executeTx(ctx context.Context, sourcePort, destPort, destChannel string, msgs []sdk.Msg) ([]byte, error) { channel, found := k.channelKeeper.GetChannel(ctx, destPort, destChannel) if !found { return nil, channeltypes.ErrChannelNotFound @@ -66,7 +68,8 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str // CacheContext returns a new context with the multi-store branched into a cached storage object // writeCache is called only if all msgs succeed, performing state transitions atomically - cacheCtx, writeCache := ctx.CacheContext() + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + cacheCtx, writeCache := sdkCtx.CacheContext() for i, msg := range msgs { if m, ok := msg.(sdk.HasValidateBasic); ok { if err := m.ValidateBasic(); err != nil { @@ -94,7 +97,7 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str // authenticateTx ensures the provided msgs contain the correct interchain account signer address retrieved // from state using the provided controller port identifier -func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, connectionID, portID string) error { +func (k Keeper) authenticateTx(ctx context.Context, msgs []sdk.Msg, connectionID, portID string) error { interchainAccountAddr, found := k.GetInterchainAccountAddress(ctx, connectionID, portID) if !found { return errorsmod.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index 60c05ad448c..d1542f52ace 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -1,6 +1,7 @@ package types import ( + "context" "encoding/json" "regexp" "strings" @@ -43,9 +44,10 @@ type interchainAccountPretty struct { // GenerateAddress returns an sdk.AccAddress derived using a host module account address, host connection ID, the controller portID, // the current block app hash, and the current block data hash. The sdk.AccAddress returned is a sub-address of the host module account. -func GenerateAddress(ctx sdk.Context, connectionID, portID string) sdk.AccAddress { +func GenerateAddress(ctx context.Context, connectionID, portID string) sdk.AccAddress { hostModuleAcc := sdkaddress.Module(ModuleName, []byte(hostAccountsKey)) - header := ctx.BlockHeader() + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + header := sdkCtx.BlockHeader() buf := []byte(connectionID + portID) buf = append(buf, header.AppHash...) diff --git a/modules/apps/27-interchain-accounts/types/metadata.go b/modules/apps/27-interchain-accounts/types/metadata.go index 13cc5c30fc2..7998e518d58 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.go +++ b/modules/apps/27-interchain-accounts/types/metadata.go @@ -1,12 +1,11 @@ package types import ( + "context" "slices" errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ) @@ -81,7 +80,7 @@ func IsPreviousMetadataEqual(previousVersion string, metadata Metadata) bool { // ValidateControllerMetadata performs validation of the provided ICS27 controller metadata parameters as well // as the connection params against the provided metadata -func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { +func ValidateControllerMetadata(ctx context.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { if !isSupportedEncoding(metadata.Encoding) { return errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) } @@ -113,7 +112,7 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co } // ValidateHostMetadata performs validation of the provided ICS27 host metadata parameters -func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { +func ValidateHostMetadata(ctx context.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { if !isSupportedEncoding(metadata.Encoding) { return errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) } diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 850caec1e92..234273b780c 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -42,7 +42,7 @@ func NewIBCMiddleware(app porttypes.IBCModule, k keeper.Keeper) IBCMiddleware { // OnChanOpenInit implements the IBCMiddleware interface func (im IBCMiddleware) OnChanOpenInit( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, @@ -96,7 +96,7 @@ func (im IBCMiddleware) OnChanOpenInit( // If the channel is not fee enabled the underlying application version will be returned // If the channel is fee enabled we merge the underlying application version with the ics29 version func (im IBCMiddleware) OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -136,7 +136,7 @@ func (im IBCMiddleware) OnChanOpenTry( // OnChanOpenAck implements the IBCMiddleware interface func (im IBCMiddleware) OnChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannelID string, @@ -165,7 +165,7 @@ func (im IBCMiddleware) OnChanOpenAck( // OnChanOpenConfirm implements the IBCMiddleware interface func (im IBCMiddleware) OnChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -175,7 +175,7 @@ func (im IBCMiddleware) OnChanOpenConfirm( // OnChanCloseInit implements the IBCMiddleware interface func (im IBCMiddleware) OnChanCloseInit( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -196,7 +196,7 @@ func (im IBCMiddleware) OnChanCloseInit( // OnChanCloseConfirm implements the IBCMiddleware interface func (im IBCMiddleware) OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -218,7 +218,7 @@ func (im IBCMiddleware) OnChanCloseConfirm( // OnRecvPacket implements the IBCMiddleware interface. // If fees are not enabled, this callback will default to the ibc-core packet callback func (im IBCMiddleware) OnRecvPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -245,7 +245,7 @@ func (im IBCMiddleware) OnRecvPacket( // OnAcknowledgementPacket implements the IBCMiddleware interface // If fees are not enabled, this callback will default to the ibc-core packet callback func (im IBCMiddleware) OnAcknowledgementPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, @@ -300,7 +300,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket( // OnTimeoutPacket implements the IBCMiddleware interface // If fees are not enabled, this callback will default to the ibc-core packet callback func (im IBCMiddleware) OnTimeoutPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -345,7 +345,7 @@ func (im IBCMiddleware) OnTimeoutPacket( // OnChanUpgradeInit implements the IBCModule interface func (im IBCMiddleware) OnChanUpgradeInit( - ctx sdk.Context, + ctx context.Context, portID string, channelID string, proposedOrder channeltypes.Order, @@ -383,7 +383,7 @@ func (im IBCMiddleware) OnChanUpgradeInit( } // OnChanUpgradeTry implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (im IBCMiddleware) OnChanUpgradeTry(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { return "", errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack") @@ -415,7 +415,7 @@ func (im IBCMiddleware) OnChanUpgradeTry(ctx sdk.Context, portID, channelID stri } // OnChanUpgradeAck implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { +func (im IBCMiddleware) OnChanUpgradeAck(ctx context.Context, portID, channelID, counterpartyVersion string) error { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { return errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack") @@ -437,7 +437,7 @@ func (im IBCMiddleware) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, cou } // OnChanUpgradeOpen implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { +func (im IBCMiddleware) OnChanUpgradeOpen(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { panic(errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack")) diff --git a/modules/apps/29-fee/ibc_middleware_test.go b/modules/apps/29-fee/ibc_middleware_test.go index d348c4de7e2..6fb19d3d1ac 100644 --- a/modules/apps/29-fee/ibc_middleware_test.go +++ b/modules/apps/29-fee/ibc_middleware_test.go @@ -1,6 +1,7 @@ package fee_test import ( + "context" "encoding/json" "errors" "fmt" @@ -86,7 +87,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() { suite.path.SetupConnections() // setup mock callback - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenInit = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string, + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenInit = func(ctx context.Context, order channeltypes.Order, connectionHops []string, portID, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { @@ -186,7 +187,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() { suite.Require().NoError(err) // setup mock callback - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenTry = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string, + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenTry = func(ctx context.Context, order channeltypes.Order, connectionHops []string, portID, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { @@ -286,7 +287,7 @@ func (suite *FeeTestSuite) TestOnChanOpenAck() { // setup mock callback suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenAck = func( - ctx sdk.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string, + ctx context.Context, portID, channelID string, counterpartyChannelID string, counterpartyVersion string, ) error { if counterpartyVersion != ibcmock.Version { return fmt.Errorf("incorrect mock version") @@ -353,7 +354,7 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() { { "application callback fails", func() { suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanCloseInit = func( - ctx sdk.Context, portID, channelID string, + ctx context.Context, portID, channelID string, ) error { return fmt.Errorf("application callback fails") } @@ -442,7 +443,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { { "application callback fails", func() { suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanCloseConfirm = func( - ctx sdk.Context, portID, channelID string, + ctx context.Context, portID, channelID string, ) error { return fmt.Errorf("application callback fails") } @@ -515,7 +516,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { func() { // setup mock callback suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnRecvPacket = func( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -802,7 +803,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { { "application callback fails", func() { - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnAcknowledgementPacket = func(_ sdk.Context, _ string, _ channeltypes.Packet, _ []byte, _ sdk.AccAddress) error { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnAcknowledgementPacket = func(_ context.Context, _ string, _ channeltypes.Packet, _ []byte, _ sdk.AccAddress) error { return fmt.Errorf("mock fee app callback fails") } }, @@ -1016,7 +1017,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { { "application callback fails", func() { - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnTimeoutPacket = func(_ sdk.Context, _ string, _ channeltypes.Packet, _ sdk.AccAddress) error { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnTimeoutPacket = func(_ context.Context, _ string, _ channeltypes.Packet, _ sdk.AccAddress) error { return fmt.Errorf("mock fee app callback fails") } }, @@ -1100,7 +1101,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeInit() { path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibctesting.InvalidID path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = ibctesting.InvalidID - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ context.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { // intentionally force the error here so we can assert that a passthrough occurs when fees should not be enabled for this channel return "", ibcmock.MockApplicationCallbackError } @@ -1119,7 +1120,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeInit() { { "underlying app callback returns error", func() { - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ context.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { return "", ibcmock.MockApplicationCallbackError } }, @@ -1207,7 +1208,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeTry() { suite.coordinator.CommitBlock(suite.chainA) // intentionally force the error here so we can assert that a passthrough occurs when fees should not be enabled for this channel - suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeTry = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { + suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeTry = func(_ context.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { return "", ibcmock.MockApplicationCallbackError } }, @@ -1229,7 +1230,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeTry() { { "underlying app callback returns error", func() { - suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeTry = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { + suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeTry = func(_ context.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { return "", ibcmock.MockApplicationCallbackError } }, @@ -1304,7 +1305,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeAck() { suite.coordinator.CommitBlock(suite.chainB) - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeAck = func(_ sdk.Context, _, _, _ string) error { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeAck = func(_ context.Context, _, _, _ string) error { return types.ErrInvalidVersion } }, @@ -1326,7 +1327,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeAck() { { "underlying app callback returns error", func() { - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeAck = func(_ sdk.Context, _, _, _ string) error { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeAck = func(_ context.Context, _, _, _ string) error { return ibcmock.MockApplicationCallbackError } }, @@ -1397,7 +1398,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeOpen() { "success: enable fees", func() { // Assert in callback that correct upgrade information is passed - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeOpen = func(_ sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeOpen = func(_ context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) { suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, portID) suite.Require().Equal(path.EndpointA.ChannelID, channelID) suite.Require().Equal(channeltypes.UNORDERED, order) @@ -1427,7 +1428,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeOpen() { path.Setup() // Assert in callback that correct version is passed - suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeOpen = func(_ sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) { + suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeOpen = func(_ context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) { suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, portID) suite.Require().Equal(path.EndpointA.ChannelID, channelID) suite.Require().Equal(channeltypes.UNORDERED, order) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 6fea91f84eb..40c1b29eb49 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -2,6 +2,7 @@ package keeper import ( "bytes" + "context" "fmt" errorsmod "cosmossdk.io/errors" @@ -46,10 +47,11 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, } // DistributePacketFeesOnAcknowledgement pays all the acknowledgement & receive fees for a given packetID while refunding the timeout fees to the refund account. -func (k Keeper) DistributePacketFeesOnAcknowledgement(ctx sdk.Context, forwardRelayer string, reverseRelayer sdk.AccAddress, packetFees []types.PacketFee, packetID channeltypes.PacketId) { +func (k Keeper) DistributePacketFeesOnAcknowledgement(ctx context.Context, forwardRelayer string, reverseRelayer sdk.AccAddress, packetFees []types.PacketFee, packetID channeltypes.PacketId) { // cache context before trying to distribute fees // if the escrow account has insufficient balance then we want to avoid partially distributing fees - cacheCtx, writeFn := ctx.CacheContext() + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + cacheCtx, writeFn := sdkCtx.CacheContext() // forward relayer address will be empty if conversion fails forwardAddr, _ := sdk.AccAddressFromBech32(forwardRelayer) @@ -103,10 +105,11 @@ func (k Keeper) distributePacketFeeOnAcknowledgement(ctx sdk.Context, refundAddr } // DistributePacketFeesOnTimeout pays all the timeout fees for a given packetID while refunding the acknowledgement & receive fees to the refund account. -func (k Keeper) DistributePacketFeesOnTimeout(ctx sdk.Context, timeoutRelayer sdk.AccAddress, packetFees []types.PacketFee, packetID channeltypes.PacketId) { +func (k Keeper) DistributePacketFeesOnTimeout(ctx context.Context, timeoutRelayer sdk.AccAddress, packetFees []types.PacketFee, packetID channeltypes.PacketId) { // cache context before trying to distribute fees // if the escrow account has insufficient balance then we want to avoid partially distributing fees - cacheCtx, writeFn := ctx.CacheContext() + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + cacheCtx, writeFn := sdkCtx.CacheContext() for _, packetFee := range packetFees { if !k.EscrowAccountHasBalance(cacheCtx, packetFee.Fee.Total()) { @@ -181,12 +184,13 @@ func (k Keeper) distributeFee(ctx sdk.Context, receiver, refundAccAddress sdk.Ac // If the escrow account runs out of balance then fee module will become locked as this implies the presence // of a severe bug. When the fee module is locked, no fee distributions will be performed. // Please see ADR 004 for more information. -func (k Keeper) RefundFeesOnChannelClosure(ctx sdk.Context, portID, channelID string) error { +func (k Keeper) RefundFeesOnChannelClosure(ctx context.Context, portID, channelID string) error { identifiedPacketFees := k.GetIdentifiedPacketFeesForChannel(ctx, portID, channelID) // cache context before trying to distribute fees // if the escrow account has insufficient balance then we want to avoid partially distributing fees - cacheCtx, writeFn := ctx.CacheContext() + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + cacheCtx, writeFn := sdkCtx.CacheContext() for _, identifiedPacketFee := range identifiedPacketFees { var unRefundedFees []types.PacketFee diff --git a/modules/apps/callbacks/ibc_middleware.go b/modules/apps/callbacks/ibc_middleware.go index b7a19237797..6f921750fe5 100644 --- a/modules/apps/callbacks/ibc_middleware.go +++ b/modules/apps/callbacks/ibc_middleware.go @@ -131,7 +131,7 @@ func (im IBCMiddleware) SendPacket( // If the contract callback runs out of gas and may be retried with a higher gas limit then the state changes are // reverted via a panic. func (im IBCMiddleware) OnAcknowledgementPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, @@ -143,8 +143,10 @@ func (im IBCMiddleware) OnAcknowledgementPacket( return err } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + callbackData, err := types.GetSourceCallbackData( - ctx, im.app, packet, im.maxCallbackGas, + sdkCtx, im.app, packet, im.maxCallbackGas, ) // OnAcknowledgementPacket is not blocked if the packet does not opt-in to callbacks if err != nil { @@ -158,9 +160,9 @@ func (im IBCMiddleware) OnAcknowledgementPacket( } // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions - err = im.processCallback(ctx, types.CallbackTypeAcknowledgementPacket, callbackData, callbackExecutor) + err = im.processCallback(sdkCtx, types.CallbackTypeAcknowledgementPacket, callbackData, callbackExecutor) types.EmitCallbackEvent( - ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), + sdkCtx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), types.CallbackTypeAcknowledgementPacket, callbackData, err, ) @@ -171,14 +173,16 @@ func (im IBCMiddleware) OnAcknowledgementPacket( // It defers to the underlying application and then calls the contract callback. // If the contract callback runs out of gas and may be retried with a higher gas limit then the state changes are // reverted via a panic. -func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error { +func (im IBCMiddleware) OnTimeoutPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error { err := im.app.OnTimeoutPacket(ctx, channelVersion, packet, relayer) if err != nil { return err } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + callbackData, err := types.GetSourceCallbackData( - ctx, im.app, packet, im.maxCallbackGas, + sdkCtx, im.app, packet, im.maxCallbackGas, ) // OnTimeoutPacket is not blocked if the packet does not opt-in to callbacks if err != nil { @@ -190,9 +194,9 @@ func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, channelVersion string, } // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions - err = im.processCallback(ctx, types.CallbackTypeTimeoutPacket, callbackData, callbackExecutor) + err = im.processCallback(sdkCtx, types.CallbackTypeTimeoutPacket, callbackData, callbackExecutor) types.EmitCallbackEvent( - ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), + sdkCtx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), types.CallbackTypeTimeoutPacket, callbackData, err, ) @@ -204,7 +208,7 @@ func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, channelVersion string, // It defers to the underlying application and then calls the contract callback. // If the contract callback runs out of gas and may be retried with a higher gas limit then the state changes are // reverted via a panic. -func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement { +func (im IBCMiddleware) OnRecvPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement { ack := im.app.OnRecvPacket(ctx, channelVersion, packet, relayer) // if ack is nil (asynchronous acknowledgements), then the callback will be handled in WriteAcknowledgement // if ack is not successful, all state changes are reverted. If a packet cannot be received, then there is @@ -213,8 +217,9 @@ func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion string, pac return ack } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 callbackData, err := types.GetDestCallbackData( - ctx, im.app, packet, im.maxCallbackGas, + sdkCtx, im.app, packet, im.maxCallbackGas, ) // OnRecvPacket is not blocked if the packet does not opt-in to callbacks if err != nil { @@ -226,9 +231,9 @@ func (im IBCMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion string, pac } // callback execution errors are not allowed to block the packet lifecycle, they are only used in event emissions - err = im.processCallback(ctx, types.CallbackTypeReceivePacket, callbackData, callbackExecutor) + err = im.processCallback(sdkCtx, types.CallbackTypeReceivePacket, callbackData, callbackExecutor) types.EmitCallbackEvent( - ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), + sdkCtx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), types.CallbackTypeReceivePacket, callbackData, err, ) @@ -330,7 +335,7 @@ func (IBCMiddleware) processCallback( // OnChanOpenInit defers to the underlying application func (im IBCMiddleware) OnChanOpenInit( - ctx sdk.Context, + ctx context.Context, channelOrdering channeltypes.Order, connectionHops []string, portID, @@ -344,7 +349,7 @@ func (im IBCMiddleware) OnChanOpenInit( // OnChanOpenTry defers to the underlying application func (im IBCMiddleware) OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, channelOrdering channeltypes.Order, connectionHops []string, portID, channelID string, @@ -357,7 +362,7 @@ func (im IBCMiddleware) OnChanOpenTry( // OnChanOpenAck defers to the underlying application func (im IBCMiddleware) OnChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID, counterpartyChannelID, @@ -367,22 +372,22 @@ func (im IBCMiddleware) OnChanOpenAck( } // OnChanOpenConfirm defers to the underlying application -func (im IBCMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { +func (im IBCMiddleware) OnChanOpenConfirm(ctx context.Context, portID, channelID string) error { return im.app.OnChanOpenConfirm(ctx, portID, channelID) } // OnChanCloseInit defers to the underlying application -func (im IBCMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { +func (im IBCMiddleware) OnChanCloseInit(ctx context.Context, portID, channelID string) error { return im.app.OnChanCloseInit(ctx, portID, channelID) } // OnChanCloseConfirm defers to the underlying application -func (im IBCMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { +func (im IBCMiddleware) OnChanCloseConfirm(ctx context.Context, portID, channelID string) error { return im.app.OnChanCloseConfirm(ctx, portID, channelID) } // OnChanUpgradeInit implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { +func (im IBCMiddleware) OnChanUpgradeInit(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { return "", errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack") @@ -392,7 +397,7 @@ func (im IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID str } // OnChanUpgradeTry implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (im IBCMiddleware) OnChanUpgradeTry(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { return "", errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack") @@ -402,7 +407,7 @@ func (im IBCMiddleware) OnChanUpgradeTry(ctx sdk.Context, portID, channelID stri } // OnChanUpgradeAck implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { +func (im IBCMiddleware) OnChanUpgradeAck(ctx context.Context, portID, channelID, counterpartyVersion string) error { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { return errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack") @@ -412,7 +417,7 @@ func (im IBCMiddleware) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, cou } // OnChanUpgradeOpen implements the IBCModule interface -func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { +func (im IBCMiddleware) OnChanUpgradeOpen(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { cbs, ok := im.app.(porttypes.UpgradableModule) if !ok { panic(errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack")) diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index 7aa3f1334a4..aa361c81263 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -438,7 +438,7 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, scopedICAControllerKeeper, app.MsgServiceRouter(), @@ -447,7 +447,7 @@ func NewSimApp( // ICA Host keeper app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icahosttypes.StoreKey]), app.GetSubspace(icahosttypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), @@ -464,7 +464,7 @@ func NewSimApp( // since fee middleware will wrap the IBCKeeper for underlying application. // NOTE: the Transfer Keeper's ICS4Wrapper can later be replaced. app.TransferKeeper = ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), + appCodec, runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index f40d2a9b326..ac2aaf890db 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -44,7 +44,7 @@ func NewIBCModule(k keeper.Keeper) IBCModule { // channel must be UNORDERED, use the correct port (by default 'transfer'), and use the current // supported version. Only 2^32 channels are allowed to be created. func ValidateTransferChannelParams( - ctx sdk.Context, + ctx context.Context, transferkeeper keeper.Keeper, order channeltypes.Order, portID string, @@ -74,7 +74,7 @@ func ValidateTransferChannelParams( // OnChanOpenInit implements the IBCModule interface func (im IBCModule) OnChanOpenInit( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, @@ -106,7 +106,7 @@ func (im IBCModule) OnChanOpenInit( // OnChanOpenTry implements the IBCModule interface. func (im IBCModule) OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -134,7 +134,7 @@ func (im IBCModule) OnChanOpenTry( // OnChanOpenAck implements the IBCModule interface func (IBCModule) OnChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, _ string, @@ -149,7 +149,7 @@ func (IBCModule) OnChanOpenAck( // OnChanOpenConfirm implements the IBCModule interface func (IBCModule) OnChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -158,7 +158,7 @@ func (IBCModule) OnChanOpenConfirm( // OnChanCloseInit implements the IBCModule interface func (IBCModule) OnChanCloseInit( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -168,7 +168,7 @@ func (IBCModule) OnChanCloseInit( // OnChanCloseConfirm implements the IBCModule interface func (IBCModule) OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error { @@ -180,7 +180,7 @@ func (IBCModule) OnChanCloseConfirm( // logic returns without error. // A nil acknowledgement may be returned when using the packet forwarding feature. This signals to core IBC that the acknowledgement will be written asynchronously. func (im IBCModule) OnRecvPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -224,7 +224,7 @@ func (im IBCModule) OnRecvPacket( // OnAcknowledgementPacket implements the IBCModule interface func (im IBCModule) OnAcknowledgementPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, @@ -251,7 +251,7 @@ func (im IBCModule) OnAcknowledgementPacket( // OnTimeoutPacket implements the IBCModule interface func (im IBCModule) OnTimeoutPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -271,7 +271,7 @@ func (im IBCModule) OnTimeoutPacket( } // OnChanUpgradeInit implements the IBCModule interface -func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { +func (im IBCModule) OnChanUpgradeInit(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { if err := ValidateTransferChannelParams(ctx, im.keeper, proposedOrder, portID, channelID); err != nil { return "", err } @@ -284,7 +284,7 @@ func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, } // OnChanUpgradeTry implements the IBCModule interface -func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (im IBCModule) OnChanUpgradeTry(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { if err := ValidateTransferChannelParams(ctx, im.keeper, proposedOrder, portID, channelID); err != nil { return "", err } @@ -298,7 +298,7 @@ func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, } // OnChanUpgradeAck implements the IBCModule interface -func (IBCModule) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { +func (IBCModule) OnChanUpgradeAck(ctx context.Context, portID, channelID, counterpartyVersion string) error { if !slices.Contains(types.SupportedVersions, counterpartyVersion) { return errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected one of %s, got %s", types.SupportedVersions, counterpartyVersion) } @@ -307,7 +307,7 @@ func (IBCModule) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpar } // OnChanUpgradeOpen implements the IBCModule interface -func (IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { +func (IBCModule) OnChanUpgradeOpen(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { } // UnmarshalPacketData attempts to unmarshal the provided packet data bytes diff --git a/modules/apps/transfer/internal/events/events.go b/modules/apps/transfer/internal/events/events.go index 64f26cc003a..b6e48282e3c 100644 --- a/modules/apps/transfer/internal/events/events.go +++ b/modules/apps/transfer/internal/events/events.go @@ -1,6 +1,7 @@ package events import ( + "context" "encoding/json" "strconv" @@ -11,11 +12,12 @@ import ( ) // EmitTransferEvent emits a ibc transfer event on successful transfers. -func EmitTransferEvent(ctx sdk.Context, sender, receiver string, tokens types.Tokens, memo string, forwardingHops []types.Hop) { +func EmitTransferEvent(ctx context.Context, sender, receiver string, tokens types.Tokens, memo string, forwardingHops []types.Hop) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 tokensStr := mustMarshalJSON(tokens) forwardingHopsStr := mustMarshalJSON(forwardingHops) - ctx.EventManager().EmitEvents(sdk.Events{ + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeTransfer, sdk.NewAttribute(types.AttributeKeySender, sender), @@ -32,7 +34,7 @@ func EmitTransferEvent(ctx sdk.Context, sender, receiver string, tokens types.To } // EmitOnRecvPacketEvent emits a fungible token packet event in the OnRecvPacket callback -func EmitOnRecvPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement, ackErr error) { +func EmitOnRecvPacketEvent(ctx context.Context, packetData types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement, ackErr error) { tokensStr := mustMarshalJSON(packetData.Tokens) forwardingHopStr := mustMarshalJSON(packetData.Forwarding.Hops) @@ -49,7 +51,9 @@ func EmitOnRecvPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacket eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyAckError, ackErr.Error())) } - ctx.EventManager().EmitEvents(sdk.Events{ + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypePacket, eventAttributes..., @@ -62,11 +66,11 @@ func EmitOnRecvPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacket } // EmitOnAcknowledgementPacketEvent emits a fungible token packet event in the OnAcknowledgementPacket callback -func EmitOnAcknowledgementPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement) { +func EmitOnAcknowledgementPacketEvent(ctx context.Context, packetData types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement) { tokensStr := mustMarshalJSON(packetData.Tokens) forwardingHopsStr := mustMarshalJSON(packetData.Forwarding.Hops) - - ctx.EventManager().EmitEvents(sdk.Events{ + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypePacket, sdk.NewAttribute(sdk.AttributeKeySender, packetData.Sender), @@ -84,14 +88,14 @@ func EmitOnAcknowledgementPacketEvent(ctx sdk.Context, packetData types.Fungible switch resp := ack.Response.(type) { case *channeltypes.Acknowledgement_Result: - ctx.EventManager().EmitEvent( + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypePacket, sdk.NewAttribute(types.AttributeKeyAckSuccess, string(resp.Result)), ), ) case *channeltypes.Acknowledgement_Error: - ctx.EventManager().EmitEvent( + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypePacket, sdk.NewAttribute(types.AttributeKeyAckError, resp.Error), @@ -101,11 +105,12 @@ func EmitOnAcknowledgementPacketEvent(ctx sdk.Context, packetData types.Fungible } // EmitOnTimeoutEvent emits a fungible token packet event in the OnTimeoutPacket callback -func EmitOnTimeoutEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDataV2) { +func EmitOnTimeoutEvent(ctx context.Context, packetData types.FungibleTokenPacketDataV2) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 tokensStr := mustMarshalJSON(packetData.Tokens) forwardingHopsStr := mustMarshalJSON(packetData.Forwarding.Hops) - ctx.EventManager().EmitEvents(sdk.Events{ + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeTimeout, sdk.NewAttribute(types.AttributeKeyReceiver, packetData.Sender), @@ -121,10 +126,11 @@ func EmitOnTimeoutEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDat } // EmitDenomEvent emits a denomination event in the OnRecv callback. -func EmitDenomEvent(ctx sdk.Context, token types.Token) { +func EmitDenomEvent(ctx context.Context, token types.Token) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 denomStr := mustMarshalJSON(token.Denom) - ctx.EventManager().EmitEvent( + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeDenom, sdk.NewAttribute(types.AttributeKeyDenomHash, token.Denom.Hash().String()), diff --git a/modules/apps/transfer/keeper/forwarding.go b/modules/apps/transfer/keeper/forwarding.go index d4c2fb57168..656fbb75c4a 100644 --- a/modules/apps/transfer/keeper/forwarding.go +++ b/modules/apps/transfer/keeper/forwarding.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +15,7 @@ import ( ) // forwardPacket forwards a fungible FungibleTokenPacketDataV2 to the next hop in the forwarding path. -func (k Keeper) forwardPacket(ctx sdk.Context, data types.FungibleTokenPacketDataV2, packet channeltypes.Packet, receivedCoins sdk.Coins) error { +func (k Keeper) forwardPacket(ctx context.Context, data types.FungibleTokenPacketDataV2, packet channeltypes.Packet, receivedCoins sdk.Coins) error { var nextForwardingPath *types.Forwarding if len(data.Forwarding.Hops) > 1 { // remove the first hop since we are going to send to the first hop now and we want to propagate the rest of the hops to the receiver @@ -45,8 +47,9 @@ func (k Keeper) forwardPacket(ctx sdk.Context, data types.FungibleTokenPacketDat } // acknowledgeForwardedPacket writes the async acknowledgement for forwardedPacket -func (k Keeper) acknowledgeForwardedPacket(ctx sdk.Context, forwardedPacket, packet channeltypes.Packet, ack channeltypes.Acknowledgement) error { - capability, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel)) +func (k Keeper) acknowledgeForwardedPacket(ctx context.Context, forwardedPacket, packet channeltypes.Packet, ack channeltypes.Acknowledgement) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + capability, ok := k.scopedKeeper.GetCapability(sdkCtx, host.ChannelCapabilityPath(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel)) if !ok { return errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } @@ -62,7 +65,7 @@ func (k Keeper) acknowledgeForwardedPacket(ctx sdk.Context, forwardedPacket, pac // revertForwardedPacket reverts the logic of receive packet that occurs in the middle chains during a packet forwarding. // If the packet fails to be forwarded all the way to the final destination, the state changes on this chain must be reverted // before sending back the error acknowledgement to ensure atomic packet forwarding. -func (k Keeper) revertForwardedPacket(ctx sdk.Context, forwardedPacket channeltypes.Packet, failedPacketData types.FungibleTokenPacketDataV2) error { +func (k Keeper) revertForwardedPacket(ctx context.Context, forwardedPacket channeltypes.Packet, failedPacketData types.FungibleTokenPacketDataV2) error { /* Recall that RecvPacket handles an incoming packet depending on the denom of the received funds: 1. If the funds are native, then the amount is sent to the receiver from the escrow. diff --git a/modules/apps/transfer/keeper/grpc_query.go b/modules/apps/transfer/keeper/grpc_query.go index 8b5115007a6..90f53542985 100644 --- a/modules/apps/transfer/keeper/grpc_query.go +++ b/modules/apps/transfer/keeper/grpc_query.go @@ -11,6 +11,7 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/store/prefix" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" @@ -25,7 +26,7 @@ var ( ) // Denom implements the Query/Denom gRPC method -func (k Keeper) Denom(c context.Context, req *types.QueryDenomRequest) (*types.QueryDenomResponse, error) { +func (k Keeper) Denom(ctx context.Context, req *types.QueryDenomRequest) (*types.QueryDenomResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -35,7 +36,6 @@ func (k Keeper) Denom(c context.Context, req *types.QueryDenomRequest) (*types.Q return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash: %s, error: %s", hash.String(), err)) } - ctx := sdk.UnwrapSDKContext(c) denom, found := k.GetDenom(ctx, hash) if !found { return nil, status.Error( @@ -50,15 +50,13 @@ func (k Keeper) Denom(c context.Context, req *types.QueryDenomRequest) (*types.Q } // Denoms implements the Query/Denoms gRPC method -func (k Keeper) Denoms(c context.Context, req *types.QueryDenomsRequest) (*types.QueryDenomsResponse, error) { +func (k Keeper) Denoms(ctx context.Context, req *types.QueryDenomsRequest) (*types.QueryDenomsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - ctx := sdk.UnwrapSDKContext(c) - var denoms types.Denoms - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomKey) + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.DenomKey) pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error { var denom types.Denom @@ -80,8 +78,7 @@ func (k Keeper) Denoms(c context.Context, req *types.QueryDenomsRequest) (*types } // Params implements the Query/Params gRPC method -func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - ctx := sdk.UnwrapSDKContext(c) +func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { params := k.GetParams(ctx) return &types.QueryParamsResponse{ @@ -90,7 +87,7 @@ func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q } // DenomHash implements the Query/DenomHash gRPC method -func (k Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) { +func (k Keeper) DenomHash(ctx context.Context, req *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -101,7 +98,6 @@ func (k Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) ( return nil, status.Error(codes.InvalidArgument, err.Error()) } - ctx := sdk.UnwrapSDKContext(c) denomHash := denom.Hash() found := k.HasDenom(ctx, denomHash) if !found { @@ -117,7 +113,7 @@ func (k Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) ( } // EscrowAddress implements the EscrowAddress gRPC method -func (k Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) { +func (k Keeper) EscrowAddress(ctx context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -128,7 +124,6 @@ func (k Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRe return nil, err } - ctx := sdk.UnwrapSDKContext(c) if !k.channelKeeper.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -142,13 +137,11 @@ func (k Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRe } // TotalEscrowForDenom implements the TotalEscrowForDenom gRPC method. -func (k Keeper) TotalEscrowForDenom(c context.Context, req *types.QueryTotalEscrowForDenomRequest) (*types.QueryTotalEscrowForDenomResponse, error) { +func (k Keeper) TotalEscrowForDenom(ctx context.Context, req *types.QueryTotalEscrowForDenomRequest) (*types.QueryTotalEscrowForDenomResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - ctx := sdk.UnwrapSDKContext(c) - if err := sdk.ValidateDenom(req.Denom); err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 0ce1399513d..98f5a0b8d09 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -1,16 +1,19 @@ package keeper import ( + "context" "errors" "fmt" "strings" + corestore "cosmossdk.io/core/store" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -26,7 +29,7 @@ import ( // Keeper defines the IBC fungible transfer keeper type Keeper struct { - storeKey storetypes.StoreKey + storeService corestore.KVStoreService cdc codec.BinaryCodec legacySubspace types.ParamSubspace @@ -45,7 +48,7 @@ type Keeper struct { // NewKeeper creates a new IBC transfer Keeper instance func NewKeeper( cdc codec.BinaryCodec, - key storetypes.StoreKey, + storeService corestore.KVStoreService, legacySubspace types.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, @@ -66,7 +69,7 @@ func NewKeeper( return Keeper{ cdc: cdc, - storeKey: key, + storeService: storeService, legacySubspace: legacySubspace, ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, @@ -96,39 +99,50 @@ func (k Keeper) GetAuthority() string { } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+exported.ModuleName+"-"+types.ModuleName) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"-"+types.ModuleName) } // hasCapability checks if the transfer module owns the port capability for the desired port -func (k Keeper) hasCapability(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) +func (k Keeper) hasCapability(ctx context.Context, portID string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + _, ok := k.scopedKeeper.GetCapability(sdkCtx, host.PortPath(portID)) return ok } // BindPort defines a wrapper function for the port Keeper's function in // order to expose it to module's InitGenesis function -func (k Keeper) BindPort(ctx sdk.Context, portID string) error { +func (k Keeper) BindPort(ctx context.Context, portID string) error { capability := k.portKeeper.BindPort(ctx, portID) return k.ClaimCapability(ctx, capability, host.PortPath(portID)) } // GetPort returns the portID for the transfer module. Used in ExportGenesis -func (k Keeper) GetPort(ctx sdk.Context) string { - store := ctx.KVStore(k.storeKey) - return string(store.Get(types.PortKey)) +func (k Keeper) GetPort(ctx context.Context) string { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PortKey) + if err != nil { + panic(err) + } + return string(bz) } // SetPort sets the portID for the transfer module. Used in InitGenesis -func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) - store.Set(types.PortKey, []byte(portID)) +func (k Keeper) SetPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(types.PortKey, []byte(portID)); err != nil { + panic(err) + } } // GetParams returns the current transfer module parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.ParamsKey)) +func (k Keeper) GetParams(ctx context.Context) types.Params { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte(types.ParamsKey)) + if err != nil { + panic(err) + } if bz == nil { // only panic on unset params and not on empty params panic(errors.New("transfer params are not set in store")) } @@ -139,15 +153,17 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the transfer module parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetParams(ctx context.Context, params types.Params) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(¶ms) - store.Set([]byte(types.ParamsKey), bz) + if err := store.Set([]byte(types.ParamsKey), bz); err != nil { + panic(err) + } } // GetDenom retrieves the denom from store given the hash of the denom. -func (k Keeper) GetDenom(ctx sdk.Context, denomHash cmtbytes.HexBytes) (types.Denom, bool) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomKey) +func (k Keeper) GetDenom(ctx context.Context, denomHash cmtbytes.HexBytes) (types.Denom, bool) { + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.DenomKey) bz := store.Get(denomHash) if len(bz) == 0 { return types.Denom{}, false @@ -160,21 +176,21 @@ func (k Keeper) GetDenom(ctx sdk.Context, denomHash cmtbytes.HexBytes) (types.De } // HasDenom checks if a the key with the given denomination hash exists on the store. -func (k Keeper) HasDenom(ctx sdk.Context, denomHash cmtbytes.HexBytes) bool { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomKey) +func (k Keeper) HasDenom(ctx context.Context, denomHash cmtbytes.HexBytes) bool { + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.DenomKey) return store.Has(denomHash) } // SetDenom sets a new {denom hash -> denom } pair to the store. // This allows for reverse lookup of the denom given the hash. -func (k Keeper) SetDenom(ctx sdk.Context, denom types.Denom) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomKey) +func (k Keeper) SetDenom(ctx context.Context, denom types.Denom) { + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.DenomKey) bz := k.cdc.MustMarshal(&denom) store.Set(denom.Hash(), bz) } // GetAllDenoms returns all the denominations. -func (k Keeper) GetAllDenoms(ctx sdk.Context) types.Denoms { +func (k Keeper) GetAllDenoms(ctx context.Context) types.Denoms { denoms := types.Denoms{} k.IterateDenoms(ctx, func(denom types.Denom) bool { denoms = append(denoms, denom) @@ -185,11 +201,11 @@ func (k Keeper) GetAllDenoms(ctx sdk.Context) types.Denoms { } // IterateDenoms iterates over the denominations in the store and performs a callback function. -func (k Keeper) IterateDenoms(ctx sdk.Context, cb func(denom types.Denom) bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) IterateDenoms(ctx context.Context, cb func(denom types.Denom) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, types.DenomKey) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) for ; iterator.Valid(); iterator.Next() { var denom types.Denom k.cdc.MustUnmarshal(iterator.Value(), &denom) @@ -201,7 +217,7 @@ func (k Keeper) IterateDenoms(ctx sdk.Context, cb func(denom types.Denom) bool) } // setDenomMetadata sets an IBC token's denomination metadata -func (k Keeper) setDenomMetadata(ctx sdk.Context, denom types.Denom) { +func (k Keeper) setDenomMetadata(ctx context.Context, denom types.Denom) { metadata := banktypes.Metadata{ Description: fmt.Sprintf("IBC token from %s", denom.Path()), DenomUnits: []*banktypes.DenomUnit{ @@ -227,9 +243,12 @@ func (k Keeper) setDenomMetadata(ctx sdk.Context, denom types.Denom) { // // NOTE: if there is no value stored in state for the provided denom then a new Coin is returned for the denom with an initial value of zero. // This accommodates callers to simply call `Add()` on the returned Coin as an empty Coin literal (e.g. sdk.Coin{}) will trigger a panic due to the absence of a denom. -func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.TotalEscrowForDenomKey(denom)) +func (k Keeper) GetTotalEscrowForDenom(ctx context.Context, denom string) sdk.Coin { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.TotalEscrowForDenomKey(denom)) + if err != nil { + panic(err) + } if len(bz) == 0 { return sdk.NewCoin(denom, sdkmath.ZeroInt()) } @@ -243,25 +262,29 @@ func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin { // SetTotalEscrowForDenom stores the total amount of source chain tokens that are in escrow. // Amount is stored in state if and only if it is not equal to zero. The function will panic // if the amount is negative. -func (k Keeper) SetTotalEscrowForDenom(ctx sdk.Context, coin sdk.Coin) { +func (k Keeper) SetTotalEscrowForDenom(ctx context.Context, coin sdk.Coin) { if coin.Amount.IsNegative() { panic(fmt.Errorf("amount cannot be negative: %s", coin.Amount)) } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) key := types.TotalEscrowForDenomKey(coin.Denom) if coin.Amount.IsZero() { - store.Delete(key) // delete the key since Cosmos SDK x/bank module will prune any non-zero balances + if err := store.Delete(key); err != nil { // delete the key since Cosmos SDK x/bank module will prune any non-zero balances + panic(err) + } return } bz := k.cdc.MustMarshal(&sdk.IntProto{Int: coin.Amount}) - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } // GetAllTotalEscrowed returns the escrow information for all the denominations. -func (k Keeper) GetAllTotalEscrowed(ctx sdk.Context) sdk.Coins { +func (k Keeper) GetAllTotalEscrowed(ctx context.Context) sdk.Coins { var escrows sdk.Coins k.IterateTokensInEscrow(ctx, []byte(types.KeyTotalEscrowPrefix), func(denomEscrow sdk.Coin) bool { escrows = escrows.Add(denomEscrow) @@ -274,11 +297,11 @@ func (k Keeper) GetAllTotalEscrowed(ctx sdk.Context) sdk.Coins { // IterateTokensInEscrow iterates over the denomination escrows in the store // and performs a callback function. Denominations for which an invalid value // (i.e. not integer) is stored, will be skipped. -func (k Keeper) IterateTokensInEscrow(ctx sdk.Context, storeprefix []byte, cb func(denomEscrow sdk.Coin) bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) IterateTokensInEscrow(ctx context.Context, storeprefix []byte, cb func(denomEscrow sdk.Coin) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, storeprefix) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) for ; iterator.Valid(); iterator.Next() { denom := strings.TrimPrefix(string(iterator.Key()), fmt.Sprintf("%s/", types.KeyTotalEscrowPrefix)) if strings.TrimSpace(denom) == "" { @@ -298,27 +321,34 @@ func (k Keeper) IterateTokensInEscrow(ctx sdk.Context, storeprefix []byte, cb fu } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function -func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool { - return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) +func (k Keeper) AuthenticateCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return k.scopedKeeper.AuthenticateCapability(sdkCtx, cap, name) } // ClaimCapability allows the transfer module that can claim a capability that IBC module // passes to it -func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { - return k.scopedKeeper.ClaimCapability(ctx, cap, name) +func (k Keeper) ClaimCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return k.scopedKeeper.ClaimCapability(sdkCtx, cap, name) } // setForwardedPacket sets the forwarded packet in the store. -func (k Keeper) setForwardedPacket(ctx sdk.Context, portID, channelID string, sequence uint64, packet channeltypes.Packet) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) setForwardedPacket(ctx context.Context, portID, channelID string, sequence uint64, packet channeltypes.Packet) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&packet) - store.Set(types.PacketForwardKey(portID, channelID, sequence), bz) + if err := store.Set(types.PacketForwardKey(portID, channelID, sequence), bz); err != nil { + panic(err) + } } // getForwardedPacket gets the forwarded packet from the store. -func (k Keeper) getForwardedPacket(ctx sdk.Context, portID, channelID string, sequence uint64) (channeltypes.Packet, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PacketForwardKey(portID, channelID, sequence)) +func (k Keeper) getForwardedPacket(ctx context.Context, portID, channelID string, sequence uint64) (channeltypes.Packet, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PacketForwardKey(portID, channelID, sequence)) + if err != nil { + panic(err) + } if bz == nil { return channeltypes.Packet{}, false } @@ -330,15 +360,17 @@ func (k Keeper) getForwardedPacket(ctx sdk.Context, portID, channelID string, se } // deleteForwardedPacket deletes the forwarded packet from the store. -func (k Keeper) deleteForwardedPacket(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) deleteForwardedPacket(ctx context.Context, portID, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) packetKey := types.PacketForwardKey(portID, channelID, sequence) - store.Delete(packetKey) + if err := store.Delete(packetKey); err != nil { + panic(err) + } } // getAllForwardedPackets gets all forward packets stored in state. -func (k Keeper) getAllForwardedPackets(ctx sdk.Context) []types.ForwardedPacket { +func (k Keeper) getAllForwardedPackets(ctx context.Context) []types.ForwardedPacket { var packets []types.ForwardedPacket k.iterateForwardedPackets(ctx, func(packet types.ForwardedPacket) bool { packets = append(packets, packet) @@ -349,11 +381,11 @@ func (k Keeper) getAllForwardedPackets(ctx sdk.Context) []types.ForwardedPacket } // iterateForwardedPackets iterates over the forward packets in the store and performs a callback function. -func (k Keeper) iterateForwardedPackets(ctx sdk.Context, cb func(packet types.ForwardedPacket) bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) iterateForwardedPackets(ctx context.Context, cb func(packet types.ForwardedPacket) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, types.ForwardedPacketKey) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) for ; iterator.Valid(); iterator.Next() { var forwardPacket types.ForwardedPacket k.cdc.MustUnmarshal(iterator.Value(), &forwardPacket.Packet) diff --git a/modules/apps/transfer/keeper/keeper_test.go b/modules/apps/transfer/keeper/keeper_test.go index 683bf8175ab..dc9566bd39f 100644 --- a/modules/apps/transfer/keeper/keeper_test.go +++ b/modules/apps/transfer/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -57,7 +58,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"success", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.ModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -71,7 +72,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: transfer module account does not exist", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.ModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, @@ -85,7 +86,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { {"failure: empty authority", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(types.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)), suite.chainA.GetSimApp().GetSubspace(types.ModuleName), suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper, diff --git a/modules/apps/transfer/keeper/migrations.go b/modules/apps/transfer/keeper/migrations.go index bcfb43344f0..ab1e526d4a2 100644 --- a/modules/apps/transfer/keeper/migrations.go +++ b/modules/apps/transfer/keeper/migrations.go @@ -1,12 +1,14 @@ package keeper import ( + "context" "fmt" "strings" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -113,26 +115,26 @@ func (m Migrator) MigrateDenomTraceToDenom(ctx sdk.Context) error { } // setDenomTrace sets a new {trace hash -> denom trace} pair to the store. -func (k Keeper) setDenomTrace(ctx sdk.Context, denomTrace internaltypes.DenomTrace) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomTraceKey) +func (k Keeper) setDenomTrace(ctx context.Context, denomTrace internaltypes.DenomTrace) { + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.DenomTraceKey) bz := k.cdc.MustMarshal(&denomTrace) store.Set(denomTrace.Hash(), bz) } // deleteDenomTrace deletes the denom trace -func (k Keeper) deleteDenomTrace(ctx sdk.Context, denomTrace internaltypes.DenomTrace) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomTraceKey) +func (k Keeper) deleteDenomTrace(ctx context.Context, denomTrace internaltypes.DenomTrace) { + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.DenomTraceKey) store.Delete(denomTrace.Hash()) } // iterateDenomTraces iterates over the denomination traces in the store // and performs a callback function. -func (k Keeper) iterateDenomTraces(ctx sdk.Context, cb func(denomTrace internaltypes.DenomTrace) bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) iterateDenomTraces(ctx context.Context, cb func(denomTrace internaltypes.DenomTrace) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, types.DenomTraceKey) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) for ; iterator.Valid(); iterator.Next() { var denomTrace internaltypes.DenomTrace k.cdc.MustUnmarshal(iterator.Value(), &denomTrace) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 122e4501fae..c69e840de7f 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "strings" @@ -167,7 +168,7 @@ func (k Keeper) sendTransfer( // // In the case of packet forwarding, the packet is sent on the next hop as specified // in the packet's ForwardingPacketData. -func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { +func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { // validate packet data upon receiving if err := data.ValidateBasic(); err != nil { return errorsmod.Wrapf(err, "error validating ICS-20 transfer packet data") @@ -277,7 +278,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // If forwarding is used and the acknowledgement was a success, a successful acknowledgement is written // for the forwarded packet. Otherwise, if the acknowledgement failed, after refunding the sender, the // tokens of the forwarded packet that were received are in turn either refunded or burned. -func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement) error { +func (k Keeper) OnAcknowledgementPacket(ctx context.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement) error { forwardedPacket, isForwarded := k.getForwardedPacket(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) switch ack.Response.(type) { @@ -321,7 +322,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac // If forwarding is used and the chain acted as a middle hop on a multihop transfer, after refunding // the tokens to the sender, the tokens of the forwarded packet that were received are in turn // either refunded or burned. -func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { +func (k Keeper) OnTimeoutPacket(ctx context.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { if err := k.refundPacketTokens(ctx, packet, data); err != nil { return err } @@ -343,7 +344,7 @@ func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, dat // if the sending chain was the source chain. Otherwise, the sent tokens // were burnt in the original send so new tokens are minted and sent to // the sending address. -func (k Keeper) refundPacketTokens(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { +func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Packet, data types.FungibleTokenPacketDataV2) error { // NOTE: packet data type already checked in handler.go sender, err := sdk.AccAddressFromBech32(data.Sender) @@ -389,7 +390,7 @@ func (k Keeper) refundPacketTokens(ctx sdk.Context, packet channeltypes.Packet, // escrowCoin will send the given coin from the provided sender to the escrow address. It will also // update the total escrowed amount by adding the escrowed coin's amount to the current total escrow. -func (k Keeper) escrowCoin(ctx sdk.Context, sender, escrowAddress sdk.AccAddress, coin sdk.Coin) error { +func (k Keeper) escrowCoin(ctx context.Context, sender, escrowAddress sdk.AccAddress, coin sdk.Coin) error { if err := k.bankKeeper.SendCoins(ctx, sender, escrowAddress, sdk.NewCoins(coin)); err != nil { // failure is expected for insufficient balances return err @@ -405,7 +406,7 @@ func (k Keeper) escrowCoin(ctx sdk.Context, sender, escrowAddress sdk.AccAddress // unescrowCoin will send the given coin from the escrow address to the provided receiver. It will also // update the total escrow by deducting the unescrowed coin's amount from the current total escrow. -func (k Keeper) unescrowCoin(ctx sdk.Context, escrowAddress, receiver sdk.AccAddress, coin sdk.Coin) error { +func (k Keeper) unescrowCoin(ctx context.Context, escrowAddress, receiver sdk.AccAddress, coin sdk.Coin) error { if err := k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(coin)); err != nil { // NOTE: this error is only expected to occur given an unexpected bug or a malicious // counterparty module. The bug may occur in bank or any part of the code that allows diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index f20d83e64aa..e7eea289614 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -25,7 +25,7 @@ type IBCModule interface { // If there is no default version string for the application, // it should return an error if provided version is empty string. OnChanOpenInit( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, @@ -44,7 +44,7 @@ type IBCModule interface { // must select the final version string and return it to core IBC. // OnChanOpenTry may also perform custom initialization logic OnChanOpenTry( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -57,7 +57,7 @@ type IBCModule interface { // OnChanOpenAck will error if the counterparty selected version string // is invalid to abort the handshake. It may also perform custom ACK logic. OnChanOpenAck( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannelID string, @@ -66,19 +66,19 @@ type IBCModule interface { // OnChanOpenConfirm will perform custom CONFIRM logic and may error to abort the handshake. OnChanOpenConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error OnChanCloseInit( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error OnChanCloseConfirm( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error @@ -89,14 +89,14 @@ type IBCModule interface { // otherwise the application state changes are discarded. In either case the packet is received // and the acknowledgement is written (in synchronous cases). OnRecvPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement OnAcknowledgementPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, @@ -104,7 +104,7 @@ type IBCModule interface { ) error OnTimeoutPacket( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, @@ -120,7 +120,7 @@ type UpgradableModule interface { // NOTE: in the case of crossing hellos, this callback may be executed on both chains. // NOTE: Any IBC application state changes made in this callback handler are not committed. OnChanUpgradeInit( - ctx sdk.Context, + ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, @@ -132,7 +132,7 @@ type UpgradableModule interface { // and connection hops. // NOTE: Any IBC application state changes made in this callback handler are not committed. OnChanUpgradeTry( - ctx sdk.Context, + ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, @@ -143,7 +143,7 @@ type UpgradableModule interface { // channel upgrade handshake. It must validate the version proposed by the counterparty. // NOTE: Any IBC application state changes made in this callback handler are not committed. OnChanUpgradeAck( - ctx sdk.Context, + ctx context.Context, portID, channelID, counterpartyVersion string, @@ -153,7 +153,7 @@ type UpgradableModule interface { // has returned to the OPEN state. Any logic associated with changing of the channel fields should be performed // in this callback. OnChanUpgradeOpen( - ctx sdk.Context, + ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, diff --git a/modules/core/ante/ante_test.go b/modules/core/ante/ante_test.go index 1757d3d3534..daa4e44b214 100644 --- a/modules/core/ante/ante_test.go +++ b/modules/core/ante/ante_test.go @@ -1,6 +1,7 @@ package ante_test import ( + "context" "fmt" "testing" @@ -351,7 +352,7 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() { "success on app callback error, app callbacks are skipped for performance", func(suite *AnteTestSuite) []sdk.Msg { suite.chainB.GetSimApp().IBCMockModule.IBCApp.OnRecvPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement { panic(fmt.Errorf("failed OnRecvPacket mock callback")) } @@ -587,7 +588,7 @@ func (suite *AnteTestSuite) TestAnteDecoratorReCheckTx() { "success on app callback error, app callbacks are skipped for performance", func(suite *AnteTestSuite) []sdk.Msg { suite.chainB.GetSimApp().IBCMockModule.IBCApp.OnRecvPacket = func( - ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement { panic(fmt.Errorf("failed OnRecvPacket mock callback")) } diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 68d354786d7..2c04b9d378d 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "errors" "fmt" @@ -1004,12 +1005,13 @@ func (suite *KeeperTestSuite) TestChannelUpgradeInit() { path.EndpointA.Chain.GetSimApp().IBCKeeper.GetAuthority(), ) - suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeInit = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { + suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeInit = func(ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { storeKey := suite.chainA.GetSimApp().GetKey(exported.ModuleName) - store := ctx.KVStore(storeKey) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + store := sdkCtx.KVStore(storeKey) store.Set(ibcmock.TestKey, ibcmock.TestValue) - ctx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) + sdkCtx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) return ibcmock.UpgradeVersion, nil } }, @@ -1165,12 +1167,13 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() { { "ibc application does not commit state changes in callback", func() { - suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeTry = func(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, counterpartyVersion string) (string, error) { + suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeTry = func(ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, counterpartyVersion string) (string, error) { storeKey := suite.chainA.GetSimApp().GetKey(exported.ModuleName) - store := ctx.KVStore(storeKey) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + store := sdkCtx.KVStore(storeKey) store.Set(ibcmock.TestKey, ibcmock.TestValue) - ctx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) + sdkCtx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) return ibcmock.UpgradeVersion, nil } }, @@ -1384,10 +1387,11 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { "application callback returns error and error receipt is written", func() { suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeAck = func( - ctx sdk.Context, portID, channelID, counterpartyVersion string, + ctx context.Context, portID, channelID, counterpartyVersion string, ) error { // set arbitrary value in store to mock application state changes - store := ctx.KVStore(suite.chainA.GetSimApp().GetKey(exported.ModuleName)) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + store := sdkCtx.KVStore(suite.chainA.GetSimApp().GetKey(exported.ModuleName)) store.Set([]byte("foo"), []byte("bar")) return fmt.Errorf("mock app callback failed") } @@ -1447,7 +1451,7 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { { "application callback returns an upgrade error", func() { - suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { + suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeAck = func(ctx context.Context, portID, channelID, counterpartyVersion string) error { return channeltypes.NewUpgradeError(10000000, ibcmock.MockApplicationCallbackError) } }, @@ -1459,12 +1463,13 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { { "ibc application does not commit state changes in callback", func() { - suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeAck = func(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { + suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeAck = func(ctx context.Context, portID, channelID, counterpartyVersion string) error { storeKey := suite.chainA.GetSimApp().GetKey(exported.ModuleName) - store := ctx.KVStore(storeKey) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + store := sdkCtx.KVStore(storeKey) store.Set(ibcmock.TestKey, ibcmock.TestValue) - ctx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) + sdkCtx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) return nil } }, diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index f4538807337..d7b4f88fe69 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -483,7 +483,7 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, scopedICAControllerKeeper, app.MsgServiceRouter(), @@ -492,7 +492,7 @@ func NewSimApp( // ICA Host keeper app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icahosttypes.StoreKey]), app.GetSubspace(icahosttypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), @@ -507,7 +507,7 @@ func NewSimApp( // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper // since fee middleware will wrap the IBCKeeper for underlying application. app.TransferKeeper = ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), + appCodec, runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, diff --git a/simapp/app.go b/simapp/app.go index 9d8e4fd7d63..816cb4a49be 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -433,7 +433,7 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, scopedICAControllerKeeper, app.MsgServiceRouter(), @@ -442,7 +442,7 @@ func NewSimApp( // ICA Host keeper app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icahosttypes.StoreKey]), app.GetSubspace(icahosttypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), app.GRPCQueryRouter(), @@ -457,7 +457,7 @@ func NewSimApp( // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper // since fee middleware will wrap the IBCKeeper for underlying application. app.TransferKeeper = ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), + appCodec, runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, diff --git a/testing/mock/ibc_app.go b/testing/mock/ibc_app.go index 798bd35749a..687b3ec2c85 100644 --- a/testing/mock/ibc_app.go +++ b/testing/mock/ibc_app.go @@ -1,6 +1,8 @@ package mock import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" @@ -15,7 +17,7 @@ type IBCApp struct { ScopedKeeper capabilitykeeper.ScopedKeeper OnChanOpenInit func( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, @@ -26,7 +28,7 @@ type IBCApp struct { ) (string, error) OnChanOpenTry func( - ctx sdk.Context, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID, @@ -37,7 +39,7 @@ type IBCApp struct { ) (version string, err error) OnChanOpenAck func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, counterpartyChannelID string, @@ -45,19 +47,19 @@ type IBCApp struct { ) error OnChanOpenConfirm func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error OnChanCloseInit func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error OnChanCloseConfirm func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) error @@ -68,14 +70,14 @@ type IBCApp struct { // otherwise the application state changes are discarded. In either case the packet is received // and the acknowledgement is written (in synchronous cases). OnRecvPacket func( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement OnAcknowledgementPacket func( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, @@ -83,14 +85,14 @@ type IBCApp struct { ) error OnTimeoutPacket func( - ctx sdk.Context, + ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) error OnChanUpgradeInit func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, @@ -98,7 +100,7 @@ type IBCApp struct { ) (string, error) OnChanUpgradeTry func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, @@ -106,14 +108,14 @@ type IBCApp struct { ) (string, error) OnChanUpgradeAck func( - ctx sdk.Context, + ctx context.Context, portID, channelID, counterpartyVersion string, ) error OnChanUpgradeOpen func( - ctx sdk.Context, + ctx context.Context, portID, channelID string, order channeltypes.Order, diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index d96abb5bf1c..732d193de35 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -47,7 +47,7 @@ func NewIBCModule(appModule *AppModule, app *IBCApp) IBCModule { // OnChanOpenInit implements the IBCModule interface. func (im IBCModule) OnChanOpenInit( - ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { if strings.TrimSpace(version) == "" { @@ -60,7 +60,8 @@ func (im IBCModule) OnChanOpenInit( 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 { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if err := im.IBCApp.ScopedKeeper.ClaimCapability(sdkCtx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -70,7 +71,7 @@ func (im IBCModule) OnChanOpenInit( // OnChanOpenTry implements the IBCModule interface. func (im IBCModule) OnChanOpenTry( - ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error) { if im.IBCApp.OnChanOpenTry != nil { @@ -79,7 +80,8 @@ func (im IBCModule) OnChanOpenTry( 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 { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if err := im.IBCApp.ScopedKeeper.ClaimCapability(sdkCtx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -88,7 +90,7 @@ func (im IBCModule) OnChanOpenTry( } // OnChanOpenAck implements the IBCModule interface. -func (im IBCModule) OnChanOpenAck(ctx sdk.Context, portID string, channelID string, counterpartyChannelID string, counterpartyVersion string) error { +func (im IBCModule) OnChanOpenAck(ctx context.Context, portID string, channelID string, counterpartyChannelID string, counterpartyVersion string) error { if im.IBCApp.OnChanOpenAck != nil { return im.IBCApp.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) } @@ -97,7 +99,7 @@ func (im IBCModule) OnChanOpenAck(ctx sdk.Context, portID string, channelID stri } // OnChanOpenConfirm implements the IBCModule interface. -func (im IBCModule) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { +func (im IBCModule) OnChanOpenConfirm(ctx context.Context, portID, channelID string) error { if im.IBCApp.OnChanOpenConfirm != nil { return im.IBCApp.OnChanOpenConfirm(ctx, portID, channelID) } @@ -106,7 +108,7 @@ func (im IBCModule) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) } // OnChanCloseInit implements the IBCModule interface. -func (im IBCModule) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { +func (im IBCModule) OnChanCloseInit(ctx context.Context, portID, channelID string) error { if im.IBCApp.OnChanCloseInit != nil { return im.IBCApp.OnChanCloseInit(ctx, portID, channelID) } @@ -115,7 +117,7 @@ func (im IBCModule) OnChanCloseInit(ctx sdk.Context, portID, channelID string) e } // OnChanCloseConfirm implements the IBCModule interface. -func (im IBCModule) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { +func (im IBCModule) OnChanCloseConfirm(ctx context.Context, portID, channelID string) error { if im.IBCApp.OnChanCloseConfirm != nil { return im.IBCApp.OnChanCloseConfirm(ctx, portID, channelID) } @@ -124,20 +126,21 @@ func (im IBCModule) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string } // OnRecvPacket implements the IBCModule interface. -func (im IBCModule) OnRecvPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement { +func (im IBCModule) OnRecvPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement { if im.IBCApp.OnRecvPacket != nil { return im.IBCApp.OnRecvPacket(ctx, channelVersion, packet, relayer) } // set state by claiming capability to check if revert happens return capName := GetMockRecvCanaryCapabilityName(packet) - if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) } - ctx.EventManager().EmitEvent(NewMockRecvPacketEvent()) + sdkCtx.EventManager().EmitEvent(NewMockRecvPacketEvent()) if bytes.Equal(MockPacketData, packet.GetData()) { return MockAcknowledgement @@ -149,43 +152,45 @@ func (im IBCModule) OnRecvPacket(ctx sdk.Context, channelVersion string, packet } // OnAcknowledgementPacket implements the IBCModule interface. -func (im IBCModule) OnAcknowledgementPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { +func (im IBCModule) OnAcknowledgementPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { if im.IBCApp.OnAcknowledgementPacket != nil { return im.IBCApp.OnAcknowledgementPacket(ctx, channelVersion, packet, acknowledgement, relayer) } capName := GetMockAckCanaryCapabilityName(packet) - if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) } - ctx.EventManager().EmitEvent(NewMockAckPacketEvent()) + sdkCtx.EventManager().EmitEvent(NewMockAckPacketEvent()) return nil } // OnTimeoutPacket implements the IBCModule interface. -func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error { +func (im IBCModule) OnTimeoutPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error { if im.IBCApp.OnTimeoutPacket != nil { return im.IBCApp.OnTimeoutPacket(ctx, channelVersion, packet, relayer) } capName := GetMockTimeoutCanaryCapabilityName(packet) - if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) } - ctx.EventManager().EmitEvent(NewMockTimeoutPacketEvent()) + sdkCtx.EventManager().EmitEvent(NewMockTimeoutPacketEvent()) return nil } // OnChanUpgradeInit implements the IBCModule interface -func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { +func (im IBCModule) OnChanUpgradeInit(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { if im.IBCApp.OnChanUpgradeInit != nil { return im.IBCApp.OnChanUpgradeInit(ctx, portID, channelID, proposedOrder, proposedConnectionHops, proposedVersion) } @@ -194,7 +199,7 @@ func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, } // OnChanUpgradeTry implements the IBCModule interface -func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { +func (im IBCModule) OnChanUpgradeTry(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, counterpartyVersion string) (string, error) { if im.IBCApp.OnChanUpgradeTry != nil { return im.IBCApp.OnChanUpgradeTry(ctx, portID, channelID, proposedOrder, proposedConnectionHops, counterpartyVersion) } @@ -203,7 +208,7 @@ func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, } // OnChanUpgradeAck implements the IBCModule interface -func (im IBCModule) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { +func (im IBCModule) OnChanUpgradeAck(ctx context.Context, portID, channelID, counterpartyVersion string) error { if im.IBCApp.OnChanUpgradeAck != nil { return im.IBCApp.OnChanUpgradeAck(ctx, portID, channelID, counterpartyVersion) } @@ -212,7 +217,7 @@ func (im IBCModule) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counter } // OnChanUpgradeOpen implements the IBCModule interface -func (im IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { +func (im IBCModule) OnChanUpgradeOpen(ctx context.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) { if im.IBCApp.OnChanUpgradeOpen != nil { im.IBCApp.OnChanUpgradeOpen(ctx, portID, channelID, proposedOrder, proposedConnectionHops, proposedVersion) } diff --git a/testing/mock/middleware.go b/testing/mock/middleware.go index c0949fa5f67..659438d239d 100644 --- a/testing/mock/middleware.go +++ b/testing/mock/middleware.go @@ -38,7 +38,7 @@ func NewBlockUpgradeMiddleware(appModule *AppModule, app *IBCApp) BlockUpgradeMi // OnChanOpenInit implements the IBCModule interface. func (im BlockUpgradeMiddleware) OnChanOpenInit( - ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, version string, ) (string, error) { if strings.TrimSpace(version) == "" { @@ -51,7 +51,8 @@ func (im BlockUpgradeMiddleware) OnChanOpenInit( 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 { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if err := im.IBCApp.ScopedKeeper.ClaimCapability(sdkCtx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -61,7 +62,7 @@ func (im BlockUpgradeMiddleware) OnChanOpenInit( // OnChanOpenTry implements the IBCModule interface. func (im BlockUpgradeMiddleware) OnChanOpenTry( - ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, + ctx context.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, chanCap *capabilitytypes.Capability, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error) { if im.IBCApp.OnChanOpenTry != nil { @@ -70,7 +71,8 @@ func (im BlockUpgradeMiddleware) OnChanOpenTry( 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 { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if err := im.IBCApp.ScopedKeeper.ClaimCapability(sdkCtx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -79,7 +81,7 @@ func (im BlockUpgradeMiddleware) OnChanOpenTry( } // OnChanOpenAck implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnChanOpenAck(ctx sdk.Context, portID string, channelID string, counterpartyChannelID string, counterpartyVersion string) error { +func (im BlockUpgradeMiddleware) OnChanOpenAck(ctx context.Context, portID string, channelID string, counterpartyChannelID string, counterpartyVersion string) error { if im.IBCApp.OnChanOpenAck != nil { return im.IBCApp.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) } @@ -88,7 +90,7 @@ func (im BlockUpgradeMiddleware) OnChanOpenAck(ctx sdk.Context, portID string, c } // OnChanOpenConfirm implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { +func (im BlockUpgradeMiddleware) OnChanOpenConfirm(ctx context.Context, portID, channelID string) error { if im.IBCApp.OnChanOpenConfirm != nil { return im.IBCApp.OnChanOpenConfirm(ctx, portID, channelID) } @@ -97,7 +99,7 @@ func (im BlockUpgradeMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, chan } // OnChanCloseInit implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { +func (im BlockUpgradeMiddleware) OnChanCloseInit(ctx context.Context, portID, channelID string) error { if im.IBCApp.OnChanCloseInit != nil { return im.IBCApp.OnChanCloseInit(ctx, portID, channelID) } @@ -106,7 +108,7 @@ func (im BlockUpgradeMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channe } // OnChanCloseConfirm implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { +func (im BlockUpgradeMiddleware) OnChanCloseConfirm(ctx context.Context, portID, channelID string) error { if im.IBCApp.OnChanCloseConfirm != nil { return im.IBCApp.OnChanCloseConfirm(ctx, portID, channelID) } @@ -115,14 +117,15 @@ func (im BlockUpgradeMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, cha } // OnRecvPacket implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement { +func (im BlockUpgradeMiddleware) OnRecvPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement { if im.IBCApp.OnRecvPacket != nil { return im.IBCApp.OnRecvPacket(ctx, channelVersion, packet, relayer) } // set state by claiming capability to check if revert happens return capName := GetMockRecvCanaryCapabilityName(packet) - if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) @@ -138,13 +141,14 @@ func (im BlockUpgradeMiddleware) OnRecvPacket(ctx sdk.Context, channelVersion st } // OnAcknowledgementPacket implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnAcknowledgementPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { +func (im BlockUpgradeMiddleware) OnAcknowledgementPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { if im.IBCApp.OnAcknowledgementPacket != nil { return im.IBCApp.OnAcknowledgementPacket(ctx, channelVersion, packet, acknowledgement, relayer) } capName := GetMockAckCanaryCapabilityName(packet) - if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) @@ -154,13 +158,14 @@ func (im BlockUpgradeMiddleware) OnAcknowledgementPacket(ctx sdk.Context, channe } // OnTimeoutPacket implements the IBCModule interface. -func (im BlockUpgradeMiddleware) OnTimeoutPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error { +func (im BlockUpgradeMiddleware) OnTimeoutPacket(ctx context.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress) error { if im.IBCApp.OnTimeoutPacket != nil { return im.IBCApp.OnTimeoutPacket(ctx, channelVersion, packet, relayer) } capName := GetMockTimeoutCanaryCapabilityName(packet) - if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index ad986106660..a6c0bd047d6 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -396,7 +396,7 @@ func NewSimApp( // ICA Controller keeper app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( - appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]), app.GetSubspace(icacontrollertypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, scopedICAControllerKeeper, app.MsgServiceRouter(), @@ -405,7 +405,7 @@ func NewSimApp( // ICA Host keeper app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + appCodec, runtime.NewKVStoreService(keys[icahosttypes.StoreKey]), app.GetSubspace(icahosttypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), app.GRPCQueryRouter(), @@ -420,7 +420,7 @@ func NewSimApp( // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper // since fee middleware will wrap the IBCKeeper for underlying application. app.TransferKeeper = ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), + appCodec, runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]), app.GetSubspace(ibctransfertypes.ModuleName), app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,