From 73369b11af10b1c872f5932870bc6d9967d42099 Mon Sep 17 00:00:00 2001 From: Marko Date: Fri, 30 Aug 2024 12:02:44 +0200 Subject: [PATCH] chore: rewrite capability to not use sdk.Context (#7089) * migrate context part 1 * ++ * ++ * ++ * ++ * ++fafo * p2 * capability changes * fix capability * remove todos * linting * build * fix build * add missing replace * fix capability tests * chore(linter): fix linter madness * Apply suggestions from code review * Update modules/capability/keeper/keeper.go Co-authored-by: DimitrisJim * nit: has -> isInitialized --------- Co-authored-by: DimitrisJim Co-authored-by: Damian Nolan --- e2e/go.mod | 4 +- e2e/go.sum | 6 +- go.mod | 4 +- go.sum | 6 +- .../controller/keeper/account.go | 11 +- .../controller/keeper/genesis.go | 7 +- .../controller/keeper/keeper.go | 9 +- .../host/keeper/handshake.go | 3 +- .../host/keeper/keeper.go | 9 +- modules/apps/29-fee/keeper/escrow.go | 11 +- modules/apps/29-fee/keeper/events.go | 22 +- modules/apps/callbacks/go.mod | 6 +- modules/apps/callbacks/go.sum | 6 +- modules/apps/callbacks/testing/simapp/app.go | 2 +- modules/apps/transfer/keeper/keeper.go | 9 +- modules/capability/capability_test.go | 16 +- modules/capability/genesis_test.go | 13 +- modules/capability/go.mod | 8 +- modules/capability/go.sum | 40 +++- modules/capability/keeper/keeper.go | 201 +++++++++++------- modules/capability/keeper/keeper_test.go | 12 +- modules/core/03-connection/keeper/keeper.go | 3 +- modules/core/04-channel/keeper/keeper.go | 3 +- modules/core/04-channel/keeper/packet.go | 3 +- modules/core/05-port/keeper/keeper.go | 13 +- modules/core/exported/expected_keepers.go | 12 +- .../07-tendermint/light_client_module.go | 4 +- modules/light-clients/08-wasm/go.mod | 4 +- modules/light-clients/08-wasm/go.sum | 6 +- .../08-wasm/testing/simapp/app.go | 2 +- simapp/app.go | 2 +- simapp/go.mod | 2 +- simapp/go.sum | 4 +- testing/mock/ibc_module.go | 18 +- testing/mock/middleware.go | 15 +- testing/simapp/app.go | 2 +- 36 files changed, 284 insertions(+), 214 deletions(-) diff --git a/e2e/go.mod b/e2e/go.mod index f1c382f3793..126f95a07eb 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -15,7 +15,7 @@ require ( cosmossdk.io/math v1.3.0 cosmossdk.io/x/upgrade v0.1.4 github.com/cometbft/cometbft v0.38.11 - github.com/cosmos/cosmos-sdk v0.50.9 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef github.com/cosmos/gogoproto v1.7.0 github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-00010101000000-000000000000 github.com/cosmos/ibc-go/v9 v9.0.0 @@ -282,6 +282,8 @@ replace github.com/cosmos/ibc-go/v9 => ../ replace github.com/cosmos/ibc-go/modules/light-clients/08-wasm => ../modules/light-clients/08-wasm +replace github.com/cosmos/ibc-go/modules/capability => ../modules/capability //TODO: remove after capability is tagged + replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/e2e/go.sum b/e2e/go.sum index 9467ee524c9..ff1ff490ca6 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -377,8 +377,8 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.9 h1:gt2usjz0H0qW6KwAxWw7ZJ3XU8uDwmhN+hYG3nTLeSg= -github.com/cosmos/cosmos-sdk v0.50.9/go.mod h1:TMH6wpoYBcg7Cp5BEg8fneLr+8XloNQkf2MRNF9V6JE= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef h1:us0dw4egT2k00jnK4JgQ2Su6yJlBnwCfgWnKC7MIwqk= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef/go.mod h1:9l85MGxnejiuiY4gum/RzdRKfkmLZDJh5uOD3m1zxy0= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -389,8 +389,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM= github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI= -github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI= -github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/go.mod b/go.mod index dce0cf3457b..89c4db16f3b 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/cometbft/cometbft v0.38.11 github.com/cosmos/cosmos-db v1.0.2 github.com/cosmos/cosmos-proto v1.0.0-beta.5 - github.com/cosmos/cosmos-sdk v0.50.9 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef github.com/cosmos/gogoproto v1.7.0 github.com/cosmos/ibc-go/modules/capability v1.0.1 github.com/cosmos/ics23/go v0.11.0 @@ -198,3 +198,5 @@ require ( ) replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 + +replace github.com/cosmos/ibc-go/modules/capability => ./modules/capability //TODO: remove after capability is tagged diff --git a/go.sum b/go.sum index b8b3082961e..43cbd894041 100644 --- a/go.sum +++ b/go.sum @@ -343,8 +343,8 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.9 h1:gt2usjz0H0qW6KwAxWw7ZJ3XU8uDwmhN+hYG3nTLeSg= -github.com/cosmos/cosmos-sdk v0.50.9/go.mod h1:TMH6wpoYBcg7Cp5BEg8fneLr+8XloNQkf2MRNF9V6JE= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef h1:us0dw4egT2k00jnK4JgQ2Su6yJlBnwCfgWnKC7MIwqk= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef/go.mod h1:9l85MGxnejiuiY4gum/RzdRKfkmLZDJh5uOD3m1zxy0= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= @@ -354,8 +354,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM= github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI= -github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI= -github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 779826dbc94..e0cdd500fc8 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,7 +31,7 @@ import ( // Prior to v6.x.x of ibc-go, the controller module was only functional as middleware, with authentication performed // by the underlying application. For a full summary of the changes in v6.x.x, please see ADR009. // This API will be removed in later releases. -func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, version string, ordering channeltypes.Order) error { +func (k Keeper) RegisterInterchainAccount(ctx context.Context, connectionID, owner, version string, ordering channeltypes.Order) error { portID, err := icatypes.NewControllerPortID(owner) if err != nil { return err @@ -56,7 +58,7 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, // registerInterchainAccount registers an interchain account, returning the channel id of the MsgChannelOpenInitResponse // and an error if one occurred. -func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, version string, ordering channeltypes.Order) (string, error) { +func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, portID, version string, ordering channeltypes.Order) (string, error) { // if there is an active channel for this portID / connectionID return an error activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if found { @@ -74,9 +76,10 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, } } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 msg := channeltypes.NewMsgChannelOpenInit(portID, version, ordering, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) handler := k.msgRouter.Handler(msg) - res, err := handler(ctx, msg) + res, err := handler(sdkCtx, msg) if err != nil { return "", err } @@ -85,7 +88,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, k.Logger(ctx).Debug("emitting interchain account registration events", logging.SdkEventsToLogArguments(events)) // NOTE: The sdk msg handler creates a new EventManager, so events must be correctly propagated back to the current context - ctx.EventManager().EmitEvents(events) + sdkCtx.EventManager().EmitEvents(events) firstMsgResponse := res.MsgResponses[0] channelOpenInitResponse, ok := firstMsgResponse.GetCachedValue().(*channeltypes.MsgChannelOpenInitResponse) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index acf5f0d33aa..a904d9de271 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -1,16 +1,15 @@ package keeper import ( + "context" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - genesistypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/genesis/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ) // InitGenesis initializes the interchain accounts controller application state from a provided genesis state -func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) { +func InitGenesis(ctx context.Context, keeper Keeper, state genesistypes.ControllerGenesisState) { for _, portID := range state.Ports { keeper.setPort(ctx, portID) @@ -44,7 +43,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGe } // ExportGenesis returns the interchain accounts controller exported genesis -func ExportGenesis(ctx sdk.Context, keeper Keeper) genesistypes.ControllerGenesisState { +func ExportGenesis(ctx context.Context, keeper Keeper) genesistypes.ControllerGenesisState { return genesistypes.NewControllerGenesisState( keeper.GetAllActiveChannels(ctx), keeper.GetAllInterchainAccounts(ctx), diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 584fa109361..be9fa6b08ef 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -121,21 +121,18 @@ func (k Keeper) setPort(ctx context.Context, portID string) { // hasCapability checks if the interchain account controller module owns the port capability for the desired port 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)) + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function 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) + return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) } // ClaimCapability wraps the scopedKeeper's ClaimCapability function 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) + return k.scopedKeeper.ClaimCapability(ctx, cap, name) } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 4e8fcfb5f93..6ab2c7dd2e9 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -72,8 +72,7 @@ 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) - 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 { + if err = k.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", errorsmod.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 5ee78ac8aea..7a3169c0b1d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -126,21 +126,18 @@ func (k Keeper) setPort(ctx context.Context, portID string) { // hasCapability checks if the interchain account host module owns the port capability for the desired port 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)) + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function 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) + return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) } // ClaimCapability wraps the scopedKeeper's ClaimCapability function 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) + return k.scopedKeeper.ClaimCapability(ctx, cap, name) } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 40c1b29eb49..36571450fb0 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -14,7 +14,7 @@ import ( ) // escrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow -func (k Keeper) escrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, packetFee types.PacketFee) error { +func (k Keeper) escrowPacketFee(ctx context.Context, packetID channeltypes.PacketId, packetFee types.PacketFee) error { // check if the refund address is valid refundAddr, err := sdk.AccAddressFromBech32(packetFee.RefundAddress) if err != nil { @@ -86,7 +86,7 @@ func (k Keeper) DistributePacketFeesOnAcknowledgement(ctx context.Context, forwa // distributePacketFeeOnAcknowledgement pays the receive fee for a given packetID while refunding the timeout fee to the refund account associated with the Fee. // If there was no forward relayer or the associated forward relayer address is blocked, the receive fee is refunded. -func (k Keeper) distributePacketFeeOnAcknowledgement(ctx sdk.Context, refundAddr, forwardRelayer, reverseRelayer sdk.AccAddress, packetFee types.PacketFee) { +func (k Keeper) distributePacketFeeOnAcknowledgement(ctx context.Context, refundAddr, forwardRelayer, reverseRelayer sdk.AccAddress, packetFee types.PacketFee) { // distribute fee to valid forward relayer address otherwise refund the fee if !forwardRelayer.Empty() && !k.bankKeeper.BlockedAddr(forwardRelayer) { // distribute fee for forward relaying @@ -140,7 +140,7 @@ func (k Keeper) DistributePacketFeesOnTimeout(ctx context.Context, timeoutRelaye } // distributePacketFeeOnTimeout pays the timeout fee to the timeout relayer and refunds the acknowledgement & receive fee. -func (k Keeper) distributePacketFeeOnTimeout(ctx sdk.Context, refundAddr, timeoutRelayer sdk.AccAddress, packetFee types.PacketFee) { +func (k Keeper) distributePacketFeeOnTimeout(ctx context.Context, refundAddr, timeoutRelayer sdk.AccAddress, packetFee types.PacketFee) { // distribute fee for timeout relaying k.distributeFee(ctx, timeoutRelayer, refundAddr, packetFee.Fee.TimeoutFee) @@ -152,9 +152,10 @@ func (k Keeper) distributePacketFeeOnTimeout(ctx sdk.Context, refundAddr, timeou // distributeFee will attempt to distribute the escrowed fee to the receiver address. // If the distribution fails for any reason (such as the receiving address being blocked), // the state changes will be discarded. -func (k Keeper) distributeFee(ctx sdk.Context, receiver, refundAccAddress sdk.AccAddress, fee sdk.Coins) { +func (k Keeper) distributeFee(ctx context.Context, receiver, refundAccAddress sdk.AccAddress, fee sdk.Coins) { // cache context before trying to distribute fees - cacheCtx, writeFn := ctx.CacheContext() + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + cacheCtx, writeFn := sdkCtx.CacheContext() err := k.bankKeeper.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, receiver, fee) if err != nil { diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index d5883be5443..683339a55ff 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,7 +12,7 @@ import ( // emitIncentivizedPacketEvent emits an event containing information on the total amount of fees incentivizing // a specific packet. It should be emitted on every fee escrowed for the given packetID. -func emitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId, packetFees types.PacketFees) { +func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.PacketId, packetFees types.PacketFees) { var ( totalRecvFees sdk.Coins totalAckFees sdk.Coins @@ -26,8 +27,8 @@ func emitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId totalTimeoutFees = totalTimeoutFees.Add(fee.Fee.TimeoutFee...) } } - - ctx.EventManager().EmitEvents(sdk.Events{ + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeIncentivizedPacket, sdk.NewAttribute(channeltypes.AttributeKeyPortID, packetID.PortId), @@ -45,8 +46,9 @@ func emitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId } // emitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel -func emitRegisterPayeeEvent(ctx sdk.Context, relayer, payee, channelID string) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterPayee, sdk.NewAttribute(types.AttributeKeyRelayer, relayer), @@ -61,8 +63,9 @@ func emitRegisterPayeeEvent(ctx sdk.Context, relayer, payee, channelID string) { } // emitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel -func emitRegisterCounterpartyPayeeEvent(ctx sdk.Context, relayer, counterpartyPayee, channelID string) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpartyPayee, channelID string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterCounterpartyPayee, sdk.NewAttribute(types.AttributeKeyRelayer, relayer), @@ -77,8 +80,9 @@ func emitRegisterCounterpartyPayeeEvent(ctx sdk.Context, relayer, counterpartyPa } // emitDistributeFeeEvent emits an event containing a distribution fee and receiver address -func emitDistributeFeeEvent(ctx sdk.Context, receiver string, fee sdk.Coins) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitDistributeFeeEvent(ctx context.Context, receiver string, fee sdk.Coins) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeDistributeFee, sdk.NewAttribute(types.AttributeKeyReceiver, receiver), diff --git a/modules/apps/callbacks/go.mod b/modules/apps/callbacks/go.mod index 7a8dd2e7eaa..54d546237d5 100644 --- a/modules/apps/callbacks/go.mod +++ b/modules/apps/callbacks/go.mod @@ -2,12 +2,12 @@ module github.com/cosmos/ibc-go/modules/apps/callbacks go 1.22.2 -toolchain go1.22.3 - replace github.com/cosmos/ibc-go/v9 => ../../../ replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 +replace github.com/cosmos/ibc-go/modules/capability => ../../capability + require ( cosmossdk.io/api v0.7.5 cosmossdk.io/client/v2 v2.0.0-beta.3 @@ -24,7 +24,7 @@ require ( cosmossdk.io/x/upgrade v0.1.4 github.com/cometbft/cometbft v0.38.11 github.com/cosmos/cosmos-db v1.0.2 - github.com/cosmos/cosmos-sdk v0.50.9 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef github.com/cosmos/gogoproto v1.7.0 github.com/cosmos/ibc-go/modules/capability v1.0.1 github.com/cosmos/ibc-go/v9 v9.0.0 diff --git a/modules/apps/callbacks/go.sum b/modules/apps/callbacks/go.sum index 5b09218b468..dd48081714a 100644 --- a/modules/apps/callbacks/go.sum +++ b/modules/apps/callbacks/go.sum @@ -351,8 +351,8 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.9 h1:gt2usjz0H0qW6KwAxWw7ZJ3XU8uDwmhN+hYG3nTLeSg= -github.com/cosmos/cosmos-sdk v0.50.9/go.mod h1:TMH6wpoYBcg7Cp5BEg8fneLr+8XloNQkf2MRNF9V6JE= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef h1:us0dw4egT2k00jnK4JgQ2Su6yJlBnwCfgWnKC7MIwqk= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef/go.mod h1:9l85MGxnejiuiY4gum/RzdRKfkmLZDJh5uOD3m1zxy0= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= @@ -362,8 +362,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM= github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI= -github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI= -github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index aa361c81263..b2efd323b6d 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -329,7 +329,7 @@ func NewSimApp( bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey])) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 98f5a0b8d09..6e21c87637f 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -106,8 +106,7 @@ func (Keeper) Logger(ctx context.Context) log.Logger { // hasCapability checks if the transfer module owns the port capability for the desired port 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)) + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } @@ -322,15 +321,13 @@ func (k Keeper) IterateTokensInEscrow(ctx context.Context, storeprefix []byte, c // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function 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) + return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) } // ClaimCapability allows the transfer module that can claim a capability that IBC module // passes to it 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) + return k.scopedKeeper.ClaimCapability(ctx, cap, name) } // setForwardedPacket sets the forwarded packet in the store. diff --git a/modules/capability/capability_test.go b/modules/capability/capability_test.go index 72fae13e3e8..de855fc8ce7 100644 --- a/modules/capability/capability_test.go +++ b/modules/capability/capability_test.go @@ -12,9 +12,9 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -23,7 +23,11 @@ import ( "github.com/cosmos/ibc-go/modules/capability/types" ) -const mockMemStoreKey = "memory:mock" +const ( + mockMemStoreKey = "memory:mock" + bankModuleName = "bank" + stakingModuleName = "staking" +) type CapabilityTestSuite struct { testifysuite.Suite @@ -47,7 +51,7 @@ func (suite *CapabilityTestSuite) SetupTest() { suite.mockMemStoreKey = storetypes.NewMemoryStoreKey(mockMemStoreKey) suite.ctx = suite.NewTestContext() - suite.keeper = keeper.NewKeeper(suite.cdc, suite.storeKey, suite.memStoreKey) + suite.keeper = keeper.NewKeeper(suite.cdc, runtime.NewKVStoreService(suite.storeKey), runtime.NewMemStoreService(suite.memStoreKey)) } func (suite *CapabilityTestSuite) NewTestContext() sdk.Context { @@ -70,7 +74,7 @@ func (suite *CapabilityTestSuite) NewTestContext() sdk.Context { // BeginBlock is then called to populate the new in-memory store using the persisted state. func (suite *CapabilityTestSuite) TestInitializeMemStore() { // create a scoped keeper and instantiate a new capability to populate state - scopedKeeper := suite.keeper.ScopeToModule(banktypes.ModuleName) + scopedKeeper := suite.keeper.ScopeToModule(bankModuleName) cap1, err := scopedKeeper.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) @@ -78,11 +82,11 @@ func (suite *CapabilityTestSuite) TestInitializeMemStore() { // mock statesync by creating a new keeper and module that shares persisted state // but discards in-memory map by using a mock memstore key - newKeeper := keeper.NewKeeper(suite.cdc, suite.storeKey, suite.mockMemStoreKey) + newKeeper := keeper.NewKeeper(suite.cdc, runtime.NewKVStoreService(suite.storeKey), runtime.NewMemStoreService(suite.mockMemStoreKey)) newModule := capability.NewAppModule(suite.cdc, *newKeeper, true) // reassign the scoped keeper, this will inherit the mock memstore key used above - scopedKeeper = newKeeper.ScopeToModule(banktypes.ModuleName) + scopedKeeper = newKeeper.ScopeToModule(bankModuleName) // seal the new keeper and ensure the in-memory store is not initialized newKeeper.Seal() diff --git a/modules/capability/genesis_test.go b/modules/capability/genesis_test.go index 9f1aed78e1a..13cc887c466 100644 --- a/modules/capability/genesis_test.go +++ b/modules/capability/genesis_test.go @@ -1,8 +1,7 @@ package capability_test import ( - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/ibc-go/modules/capability" "github.com/cosmos/ibc-go/modules/capability/keeper" @@ -13,8 +12,8 @@ func (suite *CapabilityTestSuite) TestGenesis() { // InitGenesis must be called in order to set the initial index to 1. capability.InitGenesis(suite.ctx, *suite.keeper, *types.DefaultGenesis()) - sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName) - sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) + sk1 := suite.keeper.ScopeToModule(bankModuleName) + sk2 := suite.keeper.ScopeToModule(stakingModuleName) cap1, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) @@ -29,9 +28,9 @@ func (suite *CapabilityTestSuite) TestGenesis() { genState := capability.ExportGenesis(suite.ctx, *suite.keeper) - newKeeper := keeper.NewKeeper(suite.cdc, suite.storeKey, suite.memStoreKey) - newSk1 := newKeeper.ScopeToModule(banktypes.ModuleName) - newSk2 := newKeeper.ScopeToModule(stakingtypes.ModuleName) + newKeeper := keeper.NewKeeper(suite.cdc, runtime.NewKVStoreService(suite.storeKey), runtime.NewMemStoreService(suite.memStoreKey)) + newSk1 := newKeeper.ScopeToModule(bankModuleName) + newSk2 := newKeeper.ScopeToModule(stakingModuleName) deliverCtx := suite.NewTestContext() capability.InitGenesis(deliverCtx, *newKeeper, *genState) diff --git a/modules/capability/go.mod b/modules/capability/go.mod index 798716d7477..44e7f2868ad 100644 --- a/modules/capability/go.mod +++ b/modules/capability/go.mod @@ -14,8 +14,8 @@ require ( cosmossdk.io/store v1.1.0 github.com/cometbft/cometbft v0.38.11 github.com/cosmos/cosmos-db v1.0.2 - github.com/cosmos/cosmos-sdk v0.50.9 - github.com/cosmos/gogoproto v1.6.0 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef + github.com/cosmos/gogoproto v1.7.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/stretchr/testify v1.9.0 sigs.k8s.io/yaml v1.4.0 @@ -78,6 +78,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/google/orderedcode v0.0.1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect @@ -89,6 +90,7 @@ require ( github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/hdevalence/ed25519consensus v0.1.0 // indirect @@ -100,10 +102,12 @@ require ( github.com/klauspost/compress v1.17.7 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect + github.com/lib/pq v1.10.7 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/minio/highwayhash v1.0.2 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect diff --git a/modules/capability/go.sum b/modules/capability/go.sum index 82e93912bfa..cf393d4f2d3 100644 --- a/modules/capability/go.sum +++ b/modules/capability/go.sum @@ -25,6 +25,8 @@ github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMb github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/99designs/keyring v1.2.1 h1:tYLp1ULvO7i3fI5vE21ReQuj99QFSs7lGm0xWyJo87o= github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= @@ -32,12 +34,18 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3 github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= +github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I= +github.com/adlio/schema v1.3.3/go.mod h1:1EsRssiv9/Ce2CMzq5DoL7RiMshhuigQxrR4DMV9fHg= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -74,6 +82,7 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtyd github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY= github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= +github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= @@ -97,6 +106,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= +github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= @@ -115,6 +126,8 @@ github.com/cometbft/cometbft v0.38.11 h1:6bNDUB8/xq4uYonYwIfGc9OqK1ZH4NkdaMmR1LZ github.com/cometbft/cometbft v0.38.11/go.mod h1:jHPx9vQpWzPHEAiYI/7EDKaB1NXhK6o3SArrrY8ExKc= github.com/cometbft/cometbft-db v0.9.1 h1:MIhVX5ja5bXNHF8EYrThkG9F7r9kSfv8BX4LWaxWJ4M= github.com/cometbft/cometbft-db v0.9.1/go.mod h1:iliyWaoV0mRwBJoizElCwwRA9Tf7jZJOURcRZF9m60U= +github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= +github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -127,15 +140,15 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.9 h1:gt2usjz0H0qW6KwAxWw7ZJ3XU8uDwmhN+hYG3nTLeSg= -github.com/cosmos/cosmos-sdk v0.50.9/go.mod h1:TMH6wpoYBcg7Cp5BEg8fneLr+8XloNQkf2MRNF9V6JE= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef h1:us0dw4egT2k00jnK4JgQ2Su6yJlBnwCfgWnKC7MIwqk= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef/go.mod h1:9l85MGxnejiuiY4gum/RzdRKfkmLZDJh5uOD3m1zxy0= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI= github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= -github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE= -github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk= +github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro= +github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.1.2 h1:zL9FK7C4L/P4IF1Dm5fIwz0WXCnn7Bp1M2FxH0ayM7Y= github.com/cosmos/iavl v1.1.2/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= @@ -168,6 +181,10 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= @@ -523,6 +540,12 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q= github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034= +github.com/opencontainers/image-spec v1.1.0-rc2/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= +github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w= +github.com/opencontainers/runc v1.1.3/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= @@ -531,6 +554,8 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA= +github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= @@ -621,6 +646,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -745,6 +772,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -794,6 +823,7 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -875,6 +905,8 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index 5d856c5e64b..45e30d4ea15 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -1,16 +1,19 @@ package keeper import ( + "context" "errors" "fmt" "strings" + corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" "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" "github.com/cosmos/ibc-go/modules/capability/types" @@ -31,8 +34,8 @@ type ( // a single specific module. Keeper struct { cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey + storeService corestore.KVStoreService + memService corestore.MemoryStoreService capMap map[uint64]*types.Capability scopedModules map[string]struct{} sealed bool @@ -45,21 +48,21 @@ type ( // by name, in addition to creating new capabilities & authenticating capabilities // passed by other modules. ScopedKeeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey - capMap map[uint64]*types.Capability - module string + cdc codec.BinaryCodec + storeService corestore.KVStoreService + memService corestore.MemoryStoreService + capMap map[uint64]*types.Capability + module string } ) // NewKeeper constructs a new CapabilityKeeper instance and initializes maps // for capability map and scopedModules map. -func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeService corestore.KVStoreService, memService corestore.MemoryStoreService) *Keeper { return &Keeper{ cdc: cdc, - storeKey: storeKey, - memKey: memKey, + storeService: storeService, + memService: memService, capMap: make(map[uint64]*types.Capability), scopedModules: make(map[string]struct{}), sealed: false, @@ -90,11 +93,11 @@ func (k *Keeper) ScopeToModule(moduleName string) ScopedKeeper { k.scopedModules[moduleName] = struct{}{} return ScopedKeeper{ - cdc: k.cdc, - storeKey: k.storeKey, - memKey: k.memKey, - capMap: k.capMap, - module: moduleName, + cdc: k.cdc, + storeService: k.storeService, + memService: k.memService, + capMap: k.capMap, + module: moduleName, } } @@ -118,20 +121,15 @@ func (k *Keeper) IsSealed() bool { // InitMemStore must be called every time the app starts before the keeper is used (so // `BeginBlock` or `InitChain` - whichever is first). We need access to the store so we // can't initialize it in a constructor. -func (k *Keeper) InitMemStore(ctx sdk.Context) { - memStore := ctx.KVStore(k.memKey) - memStoreType := memStore.GetStoreType() - - if memStoreType != storetypes.StoreTypeMemory { - panic(fmt.Errorf("invalid memory store type; got %s, expected: %s", memStoreType, storetypes.StoreTypeMemory)) - } - +func (k *Keeper) InitMemStore(ctx context.Context) { // create context with no block gas meter to ensure we do not consume gas during local initialization logic. - noGasCtx := ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithGasMeter(storetypes.NewInfiniteGasMeter()) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + noGasCtx := sdkCtx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithGasMeter(storetypes.NewInfiniteGasMeter()) // check if memory store has not been initialized yet by checking if initialized flag is nil. if !k.IsInitialized(noGasCtx) { - prefixStore := prefix.NewStore(noGasCtx.KVStore(k.storeKey), types.KeyPrefixIndexCapability) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(noGasCtx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) iterator := storetypes.KVStorePrefixIterator(prefixStore, nil) // initialize the in-memory store for all persisted capabilities @@ -147,21 +145,27 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { } // set the initialized flag so we don't rerun initialization logic - memStore := noGasCtx.KVStore(k.memKey) - memStore.Set(types.KeyMemInitialized, []byte{1}) + memStore := k.memService.OpenMemoryStore(noGasCtx) + if err := memStore.Set(types.KeyMemInitialized, []byte{1}); err != nil { + panic(err) + } } } // IsInitialized returns true if the keeper is properly initialized, and false otherwise. -func (k *Keeper) IsInitialized(ctx sdk.Context) bool { - memStore := ctx.KVStore(k.memKey) - return memStore.Has(types.KeyMemInitialized) +func (k *Keeper) IsInitialized(ctx context.Context) bool { + memStore := k.memService.OpenMemoryStore(ctx) + isInitialized, err := memStore.Has(types.KeyMemInitialized) + if err != nil { + panic(err) + } + return isInitialized } // InitializeIndex sets the index to one (or greater) in InitChain according // to the GenesisState. It must only be called once. // It will panic if the provided index is 0, or if the index is already set. -func (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error { +func (k Keeper) InitializeIndex(ctx context.Context, index uint64) error { if index == 0 { panic(errors.New("SetIndex requires index > 0")) } @@ -171,20 +175,27 @@ func (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error { } // set the global index to the passed index - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyIndex, types.IndexToKey(index)) + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(types.KeyIndex, types.IndexToKey(index)); err != nil { + panic(err) + } return nil } // GetLatestIndex returns the latest index of the CapabilityKeeper -func (k Keeper) GetLatestIndex(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - return types.IndexFromKey(store.Get(types.KeyIndex)) +func (k Keeper) GetLatestIndex(ctx context.Context) uint64 { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.KeyIndex) + if err != nil { + panic(err) + } + return types.IndexFromKey(bz) } // SetOwners set the capability owners to the store -func (k Keeper) SetOwners(ctx sdk.Context, index uint64, owners types.CapabilityOwners) { - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixIndexCapability) +func (k Keeper) SetOwners(ctx context.Context, index uint64, owners types.CapabilityOwners) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) indexKey := types.IndexToKey(index) // set owners in persistent store @@ -192,8 +203,9 @@ func (k Keeper) SetOwners(ctx sdk.Context, index uint64, owners types.Capability } // GetOwners returns the capability owners with a given index. -func (k Keeper) GetOwners(ctx sdk.Context, index uint64) (types.CapabilityOwners, bool) { - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixIndexCapability) +func (k Keeper) GetOwners(ctx context.Context, index uint64) (types.CapabilityOwners, bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) indexKey := types.IndexToKey(index) // get owners for index from persistent store @@ -209,20 +221,24 @@ func (k Keeper) GetOwners(ctx sdk.Context, index uint64) (types.CapabilityOwners // InitializeCapability takes in an index and an owners array. It creates the capability in memory // and sets the fwd and reverse keys for each owner in the memstore. // It is used during initialization from genesis. -func (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types.CapabilityOwners) { - memStore := ctx.KVStore(k.memKey) +func (k Keeper) InitializeCapability(ctx context.Context, index uint64, owners types.CapabilityOwners) { + memStore := k.memService.OpenMemoryStore(ctx) capability := types.NewCapability(index) for _, owner := range owners.Owners { // Set the forward mapping between the module and capability tuple and the // capability name in the memKVStore - memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name)) + if err := memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name)); err != nil { + panic(err) + } // Set the reverse mapping between the module and capability name and the // index in the in-memory store. Since marshalling and unmarshalling into a store // will change memory address of capability, we simply store index as value here // and retrieve the in-memory pointer to the capability from our map - memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index)) + if err := memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index)); err != nil { + panic(err) + } // Set the mapping from index to in-memory capability in the go map k.capMap[index] = capability @@ -238,18 +254,22 @@ func (k Keeper) InitializeCapability(ctx sdk.Context, index uint64, owners types // // Note, namespacing is completely local, which is safe since records are prefixed // with the module name and no two ScopedKeeper can have the same module name. -func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capability, error) { +func (sk ScopedKeeper) NewCapability(ctx context.Context, name string) (*types.Capability, error) { if strings.TrimSpace(name) == "" { return nil, errorsmod.Wrap(types.ErrInvalidCapabilityName, "capability name cannot be empty") } - store := ctx.KVStore(sk.storeKey) + store := sk.storeService.OpenKVStore(ctx) if _, ok := sk.GetCapability(ctx, name); ok { - return nil, errorsmod.Wrapf(types.ErrCapabilityTaken, fmt.Sprintf("module: %s, name: %s", sk.module, name)) + return nil, errorsmod.Wrapf(types.ErrCapabilityTaken, "module: %s, name: %s", sk.module, name) } // create new capability with the current global index - index := types.IndexFromKey(store.Get(types.KeyIndex)) + bz, err := store.Get(types.KeyIndex) + if err != nil { + panic(err) + } + index := types.IndexFromKey(bz) capability := types.NewCapability(index) // update capability owner set @@ -258,19 +278,25 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capab } // increment global index - store.Set(types.KeyIndex, types.IndexToKey(index+1)) + if err := store.Set(types.KeyIndex, types.IndexToKey(index+1)); err != nil { + panic(err) + } - memStore := ctx.KVStore(sk.memKey) + memStore := sk.memService.OpenMemoryStore(ctx) // Set the forward mapping between the module and capability tuple and the // capability name in the memKVStore - memStore.Set(types.FwdCapabilityKey(sk.module, capability), []byte(name)) + if err := memStore.Set(types.FwdCapabilityKey(sk.module, capability), []byte(name)); err != nil { + panic(err) + } // Set the reverse mapping between the module and capability name and the // index in the in-memory store. Since marshalling and unmarshalling into a store // will change memory address of capability, we simply store index as value here // and retrieve the in-memory pointer to the capability from our map - memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(index)) + if err := memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(index)); err != nil { + panic(err) + } // Set the mapping from index to in-memory capability in the go map sk.capMap[index] = capability @@ -288,7 +314,7 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capab // // Note, the capability's forward mapping is indexed by a string which should // contain its unique memory reference. -func (sk ScopedKeeper) AuthenticateCapability(ctx sdk.Context, cap *types.Capability, name string) bool { +func (sk ScopedKeeper) AuthenticateCapability(ctx context.Context, cap *types.Capability, name string) bool { if strings.TrimSpace(name) == "" || cap == nil { return false } @@ -300,7 +326,7 @@ func (sk ScopedKeeper) AuthenticateCapability(ctx sdk.Context, cap *types.Capabi // to add the owner to the persistent set of capability owners for the capability // index. If the owner already exists, it will return an error. Otherwise, it will // also set a forward and reverse index for the capability and capability name. -func (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap *types.Capability, name string) error { +func (sk ScopedKeeper) ClaimCapability(ctx context.Context, cap *types.Capability, name string) error { if cap == nil { return errorsmod.Wrap(types.ErrNilCapability, "cannot claim nil capability") } @@ -312,17 +338,21 @@ func (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap *types.Capability, n return err } - memStore := ctx.KVStore(sk.memKey) + memStore := sk.memService.OpenMemoryStore(ctx) // Set the forward mapping between the module and capability tuple and the // capability name in the memKVStore - memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name)) + if err := memStore.Set(types.FwdCapabilityKey(sk.module, cap), []byte(name)); err != nil { + panic(err) + } // Set the reverse mapping between the module and capability name and the // index in the in-memory store. Since marshalling and unmarshalling into a store // will change memory address of capability, we simply store index as value here // and retrieve the in-memory pointer to the capability from our map - memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(cap.GetIndex())) + if err := memStore.Set(types.RevCapabilityKey(sk.module, name), sdk.Uint64ToBigEndian(cap.GetIndex())); err != nil { + panic(err) + } logger(ctx).Info("claimed capability", "module", sk.module, "name", name, "capability", cap.GetIndex()) @@ -332,7 +362,7 @@ func (sk ScopedKeeper) ClaimCapability(ctx sdk.Context, cap *types.Capability, n // ReleaseCapability allows a scoped module to release a capability which it had // previously claimed or created. After releasing the capability, if no more // owners exist, the capability will be globally removed. -func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) error { +func (sk ScopedKeeper) ReleaseCapability(ctx context.Context, cap *types.Capability) error { if cap == nil { return errorsmod.Wrap(types.ErrNilCapability, "cannot release nil capability") } @@ -341,21 +371,26 @@ func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) return errorsmod.Wrap(types.ErrCapabilityNotOwned, sk.module) } - memStore := ctx.KVStore(sk.memKey) + memStore := sk.memService.OpenMemoryStore(ctx) // Delete the forward mapping between the module and capability tuple and the // capability name in the memKVStore - memStore.Delete(types.FwdCapabilityKey(sk.module, cap)) + if err := memStore.Delete(types.FwdCapabilityKey(sk.module, cap)); err != nil { + panic(err) + } // Delete the reverse mapping between the module and capability name and the // index in the in-memory store. - memStore.Delete(types.RevCapabilityKey(sk.module, name)) + if err := memStore.Delete(types.RevCapabilityKey(sk.module, name)); err != nil { + panic(err) + } // remove owner capOwners := sk.getOwners(ctx, cap) capOwners.Remove(types.NewOwner(sk.module, name)) - prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability) + store := runtime.KVStoreAdapter(sk.storeService.OpenKVStore(ctx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) indexKey := types.IndexToKey(cap.GetIndex()) if len(capOwners.Owners) == 0 { @@ -374,14 +409,17 @@ func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) // GetCapability allows a module to fetch a capability which it previously claimed // by name. The module is not allowed to retrieve capabilities which it does not // own. -func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capability, bool) { +func (sk ScopedKeeper) GetCapability(ctx context.Context, name string) (*types.Capability, bool) { if strings.TrimSpace(name) == "" { return nil, false } - memStore := ctx.KVStore(sk.memKey) + memStore := sk.memService.OpenMemoryStore(ctx) key := types.RevCapabilityKey(sk.module, name) - indexBytes := memStore.Get(key) + indexBytes, err := memStore.Get(key) + if err != nil { + panic(err) + } index := sdk.BigEndianToUint64(indexBytes) if len(indexBytes) == 0 { @@ -405,18 +443,23 @@ func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capab // GetCapabilityName allows a module to retrieve the name under which it stored a given // capability given the capability -func (sk ScopedKeeper) GetCapabilityName(ctx sdk.Context, cap *types.Capability) string { +func (sk ScopedKeeper) GetCapabilityName(ctx context.Context, cap *types.Capability) string { if cap == nil { return "" } - memStore := ctx.KVStore(sk.memKey) + memStore := sk.memService.OpenMemoryStore(ctx) + + bz, err := memStore.Get(types.FwdCapabilityKey(sk.module, cap)) + if err != nil { + panic(err) + } - return string(memStore.Get(types.FwdCapabilityKey(sk.module, cap))) + return string(bz) } // GetOwners all the Owners that own the capability associated with the name this ScopedKeeper uses // to refer to the capability -func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.CapabilityOwners, bool) { +func (sk ScopedKeeper) GetOwners(ctx context.Context, name string) (*types.CapabilityOwners, bool) { if strings.TrimSpace(name) == "" { return nil, false } @@ -425,7 +468,8 @@ func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.Capabilit return nil, false } - prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability) + store := runtime.KVStoreAdapter(sk.storeService.OpenKVStore(ctx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) indexKey := types.IndexToKey(capability.GetIndex()) var capOwners types.CapabilityOwners @@ -444,7 +488,7 @@ func (sk ScopedKeeper) GetOwners(ctx sdk.Context, name string) (*types.Capabilit // as a string array and the capability itself. // The method returns an error if either the capability or the owners cannot be // retrieved from the memstore. -func (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *types.Capability, error) { +func (sk ScopedKeeper) LookupModules(ctx context.Context, name string) ([]string, *types.Capability, error) { if strings.TrimSpace(name) == "" { return nil, nil, errorsmod.Wrap(types.ErrInvalidCapabilityName, "cannot lookup modules with empty capability name") } @@ -466,8 +510,9 @@ func (sk ScopedKeeper) LookupModules(ctx sdk.Context, name string) ([]string, *t return mods, capability, nil } -func (sk ScopedKeeper) addOwner(ctx sdk.Context, cap *types.Capability, name string) error { - prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability) +func (sk ScopedKeeper) addOwner(ctx context.Context, cap *types.Capability, name string) error { + store := runtime.KVStoreAdapter(sk.storeService.OpenKVStore(ctx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) indexKey := types.IndexToKey(cap.GetIndex()) capOwners := sk.getOwners(ctx, cap) @@ -482,8 +527,9 @@ func (sk ScopedKeeper) addOwner(ctx sdk.Context, cap *types.Capability, name str return nil } -func (sk ScopedKeeper) getOwners(ctx sdk.Context, cap *types.Capability) *types.CapabilityOwners { - prefixStore := prefix.NewStore(ctx.KVStore(sk.storeKey), types.KeyPrefixIndexCapability) +func (sk ScopedKeeper) getOwners(ctx context.Context, cap *types.Capability) *types.CapabilityOwners { + store := runtime.KVStoreAdapter(sk.storeService.OpenKVStore(ctx)) + prefixStore := prefix.NewStore(store, types.KeyPrefixIndexCapability) indexKey := types.IndexToKey(cap.GetIndex()) bz := prefixStore.Get(indexKey) @@ -497,6 +543,7 @@ func (sk ScopedKeeper) getOwners(ctx sdk.Context, cap *types.Capability) *types. return &capOwners } -func logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +func logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } diff --git a/modules/capability/keeper/keeper_test.go b/modules/capability/keeper/keeper_test.go index c2cd70597dc..f5f1a896e41 100644 --- a/modules/capability/keeper/keeper_test.go +++ b/modules/capability/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -31,10 +32,15 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) - suite.ctx = testCtx.Ctx + memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + testCtx := testutil.DefaultContextWithKeys( + map[string]*storetypes.KVStoreKey{key.Name(): key}, + map[string]*storetypes.TransientStoreKey{}, + map[string]*storetypes.MemoryStoreKey{memKey.Name(): memKey}, + ) + suite.ctx = testCtx encCfg := moduletestutil.MakeTestEncodingConfig(capability.AppModule{}) - suite.keeper = keeper.NewKeeper(encCfg.Codec, key, key) + suite.keeper = keeper.NewKeeper(encCfg.Codec, runtime.NewKVStoreService(key), runtime.NewMemStoreService(memKey)) } func (suite *KeeperTestSuite) TestSeal() { diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 08d465f6716..72d9beb6d08 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -214,8 +214,7 @@ func (k *Keeper) CreateSentinelLocalhostConnection(ctx context.Context) { // addConnectionToClient is used to add a connection identifier to the set of // connections associated with a client. func (k *Keeper) addConnectionToClient(ctx context.Context, clientID, connectionID string) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - _, found := k.clientKeeper.GetClientState(sdkCtx, clientID) + _, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index ddf461e9a6d..17e41d72618 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -555,8 +555,7 @@ func (k *Keeper) GetChannelConnection(ctx context.Context, portID, channelID str // LookupModuleByChannel will return the IBCModule along with the capability associated with a given channel defined by its portID and channelID func (k *Keeper) LookupModuleByChannel(ctx context.Context, portID, channelID string) (string, *capabilitytypes.Capability, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - modules, capability, err := k.scopedKeeper.LookupModules(sdkCtx, host.ChannelCapabilityPath(portID, channelID)) + modules, capability, err := k.scopedKeeper.LookupModules(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { return "", nil, err } diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index f4a955aa34f..b7677740ef8 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -302,8 +302,6 @@ func (k *Keeper) WriteAcknowledgement( return errorsmod.Wrapf(types.ErrInvalidChannelState, "expected one of [%s, %s, %s], got %s", types.OPEN, types.FLUSHING, types.FLUSHCOMPLETE, channel.State) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - // REPLAY PROTECTION: The recvStartSequence will prevent historical proofs from allowing replay // attacks on packets processed in previous lifecycles of a channel. After a successful channel // upgrade all packets under the recvStartSequence will have been processed and thus should be @@ -346,6 +344,7 @@ func (k *Keeper) WriteAcknowledgement( "dst_channel", packet.GetDestChannel(), ) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 emitWriteAcknowledgementEvent(sdkCtx, packet.(types.Packet), channel, bz) return nil diff --git a/modules/core/05-port/keeper/keeper.go b/modules/core/05-port/keeper/keeper.go index ea0188099be..2daad5743b7 100644 --- a/modules/core/05-port/keeper/keeper.go +++ b/modules/core/05-port/keeper/keeper.go @@ -36,8 +36,7 @@ func (Keeper) Logger(ctx context.Context) log.Logger { // IsBound checks a given port ID is already bounded. func (k *Keeper) IsBound(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)) + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } @@ -54,9 +53,7 @@ func (k *Keeper) BindPort(ctx context.Context, portID string) *capabilitytypes.C panic(fmt.Errorf("port %s is already bound", portID)) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - - key, err := k.scopedKeeper.NewCapability(sdkCtx, host.PortPath(portID)) + key, err := k.scopedKeeper.NewCapability(ctx, host.PortPath(portID)) if err != nil { panic(err.Error()) } @@ -74,14 +71,12 @@ func (k *Keeper) Authenticate(ctx context.Context, key *capabilitytypes.Capabili panic(err.Error()) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - return k.scopedKeeper.AuthenticateCapability(sdkCtx, key, host.PortPath(portID)) + return k.scopedKeeper.AuthenticateCapability(ctx, key, host.PortPath(portID)) } // LookupModuleByPort will return the IBCModule along with the capability associated with a given portID func (k *Keeper) LookupModuleByPort(ctx context.Context, portID string) (string, *capabilitytypes.Capability, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - modules, capability, err := k.scopedKeeper.LookupModules(sdkCtx, host.PortPath(portID)) + modules, capability, err := k.scopedKeeper.LookupModules(ctx, host.PortPath(portID)) if err != nil { return "", nil, err } diff --git a/modules/core/exported/expected_keepers.go b/modules/core/exported/expected_keepers.go index f1496c7f2b2..22bd5ee841d 100644 --- a/modules/core/exported/expected_keepers.go +++ b/modules/core/exported/expected_keepers.go @@ -1,16 +1,16 @@ package exported import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ) // ScopedKeeper defines the expected x/capability scoped keeper interface type ScopedKeeper interface { - NewCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, error) - GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) - AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool - LookupModules(ctx sdk.Context, name string) ([]string, *capabilitytypes.Capability, error) - ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error + NewCapability(ctx context.Context, name string) (*capabilitytypes.Capability, error) + GetCapability(ctx context.Context, name string) (*capabilitytypes.Capability, bool) + AuthenticateCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) bool + LookupModules(ctx context.Context, name string) ([]string, *capabilitytypes.Capability, error) + ClaimCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) error } diff --git a/modules/light-clients/07-tendermint/light_client_module.go b/modules/light-clients/07-tendermint/light_client_module.go index 821ccbeecfa..2b45ba7d917 100644 --- a/modules/light-clients/07-tendermint/light_client_module.go +++ b/modules/light-clients/07-tendermint/light_client_module.go @@ -7,7 +7,6 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" @@ -64,8 +63,7 @@ func (l LightClientModule) VerifyClientMessage(ctx context.Context, clientID str return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - return clientState.VerifyClientMessage(sdkCtx, l.cdc, clientStore, clientMsg) + return clientState.VerifyClientMessage(ctx, l.cdc, clientStore, clientMsg) } // CheckForMisbehaviour obtains the client state associated with the client identifier and calls into the clientState.CheckForMisbehaviour method. diff --git a/modules/light-clients/08-wasm/go.mod b/modules/light-clients/08-wasm/go.mod index 03d2fe243bf..341d38fd13e 100644 --- a/modules/light-clients/08-wasm/go.mod +++ b/modules/light-clients/08-wasm/go.mod @@ -8,6 +8,8 @@ replace github.com/cosmos/ibc-go/v9 => ../../../ replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 +replace github.com/cosmos/ibc-go/modules/capability => ../../capability + require ( cosmossdk.io/api v0.7.5 cosmossdk.io/client/v2 v2.0.0-beta.3 @@ -26,7 +28,7 @@ require ( github.com/CosmWasm/wasmvm/v2 v2.1.2 github.com/cometbft/cometbft v0.38.11 github.com/cosmos/cosmos-db v1.0.2 - github.com/cosmos/cosmos-sdk v0.50.9 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef github.com/cosmos/gogoproto v1.7.0 github.com/cosmos/ibc-go/modules/capability v1.0.1 github.com/cosmos/ibc-go/v9 v9.0.0 diff --git a/modules/light-clients/08-wasm/go.sum b/modules/light-clients/08-wasm/go.sum index 989bfc8bf8a..c8fe00f6025 100644 --- a/modules/light-clients/08-wasm/go.sum +++ b/modules/light-clients/08-wasm/go.sum @@ -353,8 +353,8 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.9 h1:gt2usjz0H0qW6KwAxWw7ZJ3XU8uDwmhN+hYG3nTLeSg= -github.com/cosmos/cosmos-sdk v0.50.9/go.mod h1:TMH6wpoYBcg7Cp5BEg8fneLr+8XloNQkf2MRNF9V6JE= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef h1:us0dw4egT2k00jnK4JgQ2Su6yJlBnwCfgWnKC7MIwqk= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef/go.mod h1:9l85MGxnejiuiY4gum/RzdRKfkmLZDJh5uOD3m1zxy0= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= @@ -364,8 +364,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM= github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI= -github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI= -github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index d7b4f88fe69..f925bf18a9a 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -336,7 +336,7 @@ func NewSimApp( bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey])) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) diff --git a/simapp/app.go b/simapp/app.go index 816cb4a49be..02adfad461e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -327,7 +327,7 @@ func NewSimApp( bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey])) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) diff --git a/simapp/go.mod b/simapp/go.mod index 7121f82b8a5..65c762013dc 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/x/upgrade v0.1.4 github.com/cometbft/cometbft v0.38.11 github.com/cosmos/cosmos-db v1.0.2 - github.com/cosmos/cosmos-sdk v0.50.9 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef github.com/cosmos/gogoproto v1.7.0 github.com/cosmos/ibc-go/modules/capability v1.0.1 github.com/cosmos/ibc-go/v9 v9.0.0 diff --git a/simapp/go.sum b/simapp/go.sum index f29022ddb62..bcbc71daa46 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -351,8 +351,8 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.9 h1:gt2usjz0H0qW6KwAxWw7ZJ3XU8uDwmhN+hYG3nTLeSg= -github.com/cosmos/cosmos-sdk v0.50.9/go.mod h1:TMH6wpoYBcg7Cp5BEg8fneLr+8XloNQkf2MRNF9V6JE= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef h1:us0dw4egT2k00jnK4JgQ2Su6yJlBnwCfgWnKC7MIwqk= +github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef/go.mod h1:9l85MGxnejiuiY4gum/RzdRKfkmLZDJh5uOD3m1zxy0= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 732d193de35..81728670a68 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -60,8 +60,7 @@ func (im IBCModule) OnChanOpenInit( if chanCap != nil { // Claim channel capability passed back by IBC module - 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 { + if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -80,8 +79,7 @@ func (im IBCModule) OnChanOpenTry( if chanCap != nil { // Claim channel capability passed back by IBC module - 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 { + if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -133,13 +131,13 @@ func (im IBCModule) OnRecvPacket(ctx context.Context, channelVersion string, pac // set state by claiming capability to check if revert happens return capName := GetMockRecvCanaryCapabilityName(packet) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { + if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvent(NewMockRecvPacketEvent()) if bytes.Equal(MockPacketData, packet.GetData()) { @@ -158,13 +156,13 @@ func (im IBCModule) OnAcknowledgementPacket(ctx context.Context, channelVersion } capName := GetMockAckCanaryCapabilityName(packet) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { + if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvent(NewMockAckPacketEvent()) return nil @@ -177,13 +175,13 @@ func (im IBCModule) OnTimeoutPacket(ctx context.Context, channelVersion string, } capName := GetMockTimeoutCanaryCapabilityName(packet) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { + if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) } + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvent(NewMockTimeoutPacketEvent()) return nil diff --git a/testing/mock/middleware.go b/testing/mock/middleware.go index 7a62ffd0ff4..70891d582bd 100644 --- a/testing/mock/middleware.go +++ b/testing/mock/middleware.go @@ -51,8 +51,7 @@ func (im BlockUpgradeMiddleware) OnChanOpenInit( if chanCap != nil { // Claim channel capability passed back by IBC module - 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 { + if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -71,8 +70,7 @@ func (im BlockUpgradeMiddleware) OnChanOpenTry( if chanCap != nil { // Claim channel capability passed back by IBC module - 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 { + if err := im.IBCApp.ScopedKeeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return "", err } } @@ -124,8 +122,7 @@ func (im BlockUpgradeMiddleware) OnRecvPacket(ctx context.Context, channelVersio // set state by claiming capability to check if revert happens return capName := GetMockRecvCanaryCapabilityName(packet) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { + if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) @@ -147,8 +144,7 @@ func (im BlockUpgradeMiddleware) OnAcknowledgementPacket(ctx context.Context, ch } capName := GetMockAckCanaryCapabilityName(packet) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { + if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, capName); err != nil { // application callback called twice on same packet sequence // must never occur panic(err) @@ -164,8 +160,7 @@ func (im BlockUpgradeMiddleware) OnTimeoutPacket(ctx context.Context, channelVer } capName := GetMockTimeoutCanaryCapabilityName(packet) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if _, err := im.IBCApp.ScopedKeeper.NewCapability(sdkCtx, capName); err != nil { + if _, err := im.IBCApp.ScopedKeeper.NewCapability(ctx, 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 a6c0bd047d6..dd96cb9f53d 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -306,7 +306,7 @@ func NewSimApp( bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[capabilitytypes.StoreKey]), runtime.NewMemStoreService(memKeys[capabilitytypes.MemStoreKey])) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)