From 3e0cd101f7d61b99a70758daeea079bf43c6729b Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Tue, 6 Aug 2024 13:02:17 +0200 Subject: [PATCH 01/19] migrate context part 1 --- modules/core/02-client/keeper/keeper.go | 49 ++++++++++--------- modules/core/exported/client.go | 28 +++++------ modules/core/keeper/keeper.go | 11 ++--- .../09-localhost/light_client_module.go | 32 +++++++----- testing/simapp/app.go | 2 +- 5 files changed, 67 insertions(+), 55 deletions(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 4f551220a7e..49b89737f8a 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -1,10 +1,12 @@ package keeper import ( + "context" "errors" "fmt" "strings" + corestoretypes "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" "cosmossdk.io/store/prefix" @@ -24,7 +26,7 @@ import ( // Keeper represents a type that grants read and write permissions to any client // state information type Keeper struct { - storeKey storetypes.StoreKey + storeService corestoretypes.KVStoreService cdc codec.BinaryCodec router *types.Router legacySubspace types.ParamSubspace @@ -32,13 +34,13 @@ type Keeper struct { } // NewKeeper creates a new NewKeeper instance -func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, uk types.UpgradeKeeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeService corestoretypes.KVStoreService, legacySubspace types.ParamSubspace, uk types.UpgradeKeeper) *Keeper { router := types.NewRouter() localhostModule := localhost.NewLightClientModule(cdc, key) router.AddRoute(exported.Localhost, localhostModule) return &Keeper{ - storeKey: key, + storeService: storeService, cdc: cdc, router: router, legacySubspace: legacySubspace, @@ -136,9 +138,12 @@ func (k *Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, heigh } // GetNextClientSequence gets the next client sequence from the store. -func (k *Keeper) GetNextClientSequence(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.KeyNextClientSequence)) +func (k *Keeper) GetNextClientSequence(ctx context.Context) uint64 { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte(types.KeyNextClientSequence)) + if err != nil { + panic(err) + } if len(bz) == 0 { panic(errors.New("next client sequence is nil")) } @@ -147,8 +152,8 @@ func (k *Keeper) GetNextClientSequence(ctx sdk.Context) uint64 { } // SetNextClientSequence sets the next client sequence to the store. -func (k *Keeper) SetNextClientSequence(ctx sdk.Context, sequence uint64) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetNextClientSequence(ctx context.Context, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set([]byte(types.KeyNextClientSequence), bz) } @@ -156,8 +161,8 @@ func (k *Keeper) SetNextClientSequence(ctx sdk.Context, sequence uint64) { // IterateConsensusStates provides an iterator over all stored consensus states. // objects. For each State object, cb will be called. If the cb returns true, // the iterator will close and stop. -func (k *Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string, cs types.ConsensusStateWithHeight) bool) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) IterateConsensusStates(ctx context.Context, cb func(clientID string, cs types.ConsensusStateWithHeight) bool) { + store := k.storeService.OpenKVStore(ctx) iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -181,11 +186,11 @@ func (k *Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string // iterateMetadata provides an iterator over all stored metadata keys in the client store. // For each metadata object, it will perform a callback. -func (k *Keeper) iterateMetadata(ctx sdk.Context, cb func(clientID string, key, value []byte) bool) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) iterateMetadata(ctx context.Context, cb func(clientID string, key, value []byte) bool) { + store := k.storeService.OpenKVStore(ctx) iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix) - 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() { split := strings.Split(string(iterator.Key()), "/") if len(split) == 3 && split[2] == string(host.KeyClientState) { @@ -347,11 +352,11 @@ func (k *Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz // IterateClientStates provides an iterator over all stored ibc ClientState // objects using the provided store prefix. For each ClientState object, cb will be called. If the cb returns true, // the iterator will close and stop. -func (k *Keeper) IterateClientStates(ctx sdk.Context, storePrefix []byte, cb func(clientID string, cs exported.ClientState) bool) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) IterateClientStates(ctx context.Context, storePrefix []byte, cb func(clientID string, cs exported.ClientState) bool) { + store := k.storeService.OpenKVStore(ctx) iterator := storetypes.KVStorePrefixIterator(store, host.PrefixedClientStoreKey(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() { path := string(iterator.Key()) if !strings.Contains(path, host.KeyClientState) { @@ -424,10 +429,10 @@ func (k *Keeper) GetClientTimestampAtHeight(ctx sdk.Context, clientID string, he } // GetParams returns the total set of ibc-client parameters. -func (k *Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.ParamsKey)) - if bz == nil { // only panic on unset params and not on empty params +func (k *Keeper) GetParams(ctx context.Context) types.Params { + store := k.storeService.OpenKVStore(ctx) + bz, _ := store.Get([]byte(types.ParamsKey)) // TODO: handle error + if bz == nil { // only panic on unset params and not on empty params panic(errors.New("client params are not set in store")) } @@ -437,8 +442,8 @@ func (k *Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the total set of ibc-client 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) } diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 98f18b83a04..5a0e2084af6 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -1,9 +1,9 @@ package exported import ( - "github.com/cosmos/gogoproto/proto" + "context" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/gogoproto/proto" ) // Status represents the status of a client @@ -44,29 +44,29 @@ type LightClientModule interface { // Initialize is called upon client creation, it allows the client to perform validation on the client state and initial consensus state. // The light client module is responsible for setting any client-specific data in the store. This includes the client state, // initial consensus state and any associated metadata. - Initialize(ctx sdk.Context, clientID string, clientState, consensusState []byte) error + Initialize(ctx context.Context, clientID string, clientState, consensusState []byte) error // VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update. // It must handle each type of ClientMessage appropriately. Calls to CheckForMisbehaviour, UpdateState, and UpdateStateOnMisbehaviour // will assume that the content of the ClientMessage has been verified and can be trusted. An error should be returned // if the ClientMessage fails to verify. - VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg ClientMessage) error + VerifyClientMessage(ctx context.Context, clientID string, clientMsg ClientMessage) error // Checks for evidence of a misbehaviour in Header or Misbehaviour type. It assumes the ClientMessage // has already been verified. - CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg ClientMessage) bool + CheckForMisbehaviour(ctx context.Context, clientID string, clientMsg ClientMessage) bool // UpdateStateOnMisbehaviour should perform appropriate state changes on a client state given that misbehaviour has been detected and verified - UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg ClientMessage) + UpdateStateOnMisbehaviour(ctx context.Context, clientID string, clientMsg ClientMessage) // UpdateState updates and stores as necessary any associated information for an IBC client, such as the ClientState and corresponding ConsensusState. // Upon successful update, a list of consensus heights is returned. It assumes the ClientMessage has already been verified. - UpdateState(ctx sdk.Context, clientID string, clientMsg ClientMessage) []Height + UpdateState(ctx context.Context, clientID string, clientMsg ClientMessage) []Height // VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). VerifyMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height Height, delayTimePeriod uint64, @@ -79,7 +79,7 @@ type LightClientModule interface { // VerifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height. // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). VerifyNonMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height Height, delayTimePeriod uint64, @@ -89,21 +89,21 @@ type LightClientModule interface { ) error // Status must return the status of the client. Only Active clients are allowed to process packets. - Status(ctx sdk.Context, clientID string) Status + Status(ctx context.Context, clientID string) Status // LatestHeight returns the latest height of the client. If no client is present for the provided client identifier a zero value height may be returned. - LatestHeight(ctx sdk.Context, clientID string) Height + LatestHeight(ctx context.Context, clientID string) Height // TimestampAtHeight must return the timestamp for the consensus state associated with the provided height. TimestampAtHeight( - ctx sdk.Context, + ctx context.Context, clientID string, height Height, ) (uint64, error) // RecoverClient must verify that the provided substitute may be used to update the subject client. // The light client module must set the updated client and consensus states within the clientStore for the subject client. - RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error + RecoverClient(ctx context.Context, clientID, substituteClientID string) error // Upgrade functions // NOTE: proof heights are not included as upgrade to a new revision is expected to pass only on the last @@ -113,7 +113,7 @@ type LightClientModule interface { // may be cancelled or modified before the last planned height. // If the upgrade is verified, the upgraded client and consensus states must be set in the client store. VerifyUpgradeAndUpdateState( - ctx sdk.Context, + ctx context.Context, clientID string, newClient []byte, newConsState []byte, diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index fed78a94888..902fb772a81 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -5,8 +5,7 @@ import ( "reflect" "strings" - storetypes "cosmossdk.io/store/types" - + corestoretypes "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/codec" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" @@ -33,7 +32,7 @@ type Keeper struct { // NewKeeper creates a new ibc Keeper func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace, + cdc codec.BinaryCodec, storeService corestoretypes.KVStoreService, paramSpace types.ParamSubspace, upgradeKeeper clienttypes.UpgradeKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, authority string, ) *Keeper { @@ -50,10 +49,10 @@ func NewKeeper( panic(errors.New("authority must be non-empty")) } - clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, upgradeKeeper) - connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper) + clientKeeper := clientkeeper.NewKeeper(cdc, storeService, paramSpace, upgradeKeeper) + connectionKeeper := connectionkeeper.NewKeeper(cdc, storeService, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper(scopedKeeper) - channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper) + channelKeeper := channelkeeper.NewKeeper(cdc, storeService, clientKeeper, connectionKeeper, portKeeper, scopedKeeper) return &Keeper{ cdc: cdc, diff --git a/modules/light-clients/09-localhost/light_client_module.go b/modules/light-clients/09-localhost/light_client_module.go index 3095503d985..687e3108bd6 100644 --- a/modules/light-clients/09-localhost/light_client_module.go +++ b/modules/light-clients/09-localhost/light_client_module.go @@ -2,9 +2,10 @@ package localhost import ( "bytes" + "context" + corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,15 +33,15 @@ var _ exported.LightClientModule = (*LightClientModule)(nil) // LightClientModule implements the core IBC api.LightClientModule interface. type LightClientModule struct { - cdc codec.BinaryCodec - key storetypes.StoreKey + cdc codec.BinaryCodec + kvstoreService corestore.KVStoreService } // NewLightClientModule creates and returns a new 09-localhost LightClientModule. -func NewLightClientModule(cdc codec.BinaryCodec, key storetypes.StoreKey) *LightClientModule { +func NewLightClientModule(cdc codec.BinaryCodec, key corestore.KVStoreService) *LightClientModule { return &LightClientModule{ - cdc: cdc, - key: key, + cdc: cdc, + kvstoreService: key, } } @@ -73,7 +74,7 @@ func (LightClientModule) UpdateState(ctx sdk.Context, _ string, _ exported.Clien // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). // The caller must provide the full IBC store. func (l LightClientModule) VerifyMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, @@ -82,7 +83,7 @@ func (l LightClientModule) VerifyMembership( path exported.Path, value []byte, ) error { - ibcStore := ctx.KVStore(l.key) + ibcStore := l.kvstoreService.OpenKVStore(ctx) // ensure the proof provided is the expected sentinel localhost client proof if !bytes.Equal(proof, SentinelProof) { @@ -99,7 +100,10 @@ func (l LightClientModule) VerifyMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - bz := ibcStore.Get(merklePath.KeyPath[1]) + bz, err := ibcStore.Get(merklePath.KeyPath[1]) + if err != nil { + return errorsmod.Wrapf(err, "error getting value for path %s", path) + } if bz == nil { return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) } @@ -115,7 +119,7 @@ func (l LightClientModule) VerifyMembership( // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). // The caller must provide the full IBC store. func (l LightClientModule) VerifyNonMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, @@ -123,7 +127,7 @@ func (l LightClientModule) VerifyNonMembership( proof []byte, path exported.Path, ) error { - ibcStore := ctx.KVStore(l.key) + ibcStore := l.kvstoreService.OpenKVStore(ctx) // ensure the proof provided is the expected sentinel localhost client proof if !bytes.Equal(proof, SentinelProof) { @@ -140,7 +144,11 @@ func (l LightClientModule) VerifyNonMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - if ibcStore.Has(merklePath.KeyPath[1]) { + has, err := ibcStore.Has(merklePath.KeyPath[1]) + if err != nil { + return errorsmod.Wrapf(err, "error checking for value for path %s", path) + } + if has { return errorsmod.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 6ebf791d319..782aaab3649 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -367,7 +367,7 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) govConfig := govtypes.DefaultConfig() From f3c9418f12498a9d07d201edd5d9a6e47bcdde5b Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Tue, 6 Aug 2024 13:11:10 +0200 Subject: [PATCH 02/19] ++ --- .../core/03-connection/keeper/grpc_query.go | 2 +- modules/core/03-connection/keeper/keeper.go | 97 +++++++++++-------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 960c1ea025c..256ffe30a9d 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -66,7 +66,7 @@ func (q *queryServer) Connections(c context.Context, req *types.QueryConnections ctx := sdk.UnwrapSDKContext(c) var connections []*types.IdentifiedConnection - store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyConnectionPrefix)) + store := prefix.NewStore(ctx.KVStore(q.storeService), []byte(host.KeyConnectionPrefix)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var result types.ConnectionEnd diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 2ce0c82aa69..8dc7b5c3826 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -1,8 +1,10 @@ package keeper import ( + "context" "errors" + corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -22,16 +24,16 @@ type Keeper struct { // implements gRPC QueryServer interface types.QueryServer - storeKey storetypes.StoreKey + storeService corestore.KVStoreService legacySubspace types.ParamSubspace cdc codec.BinaryCodec clientKeeper types.ClientKeeper } // NewKeeper creates a new IBC connection Keeper instance -func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, ck types.ClientKeeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeService corestore.KVStoreService, legacySubspace types.ParamSubspace, ck types.ClientKeeper) *Keeper { return &Keeper{ - storeKey: key, + storeService: storeService, cdc: cdc, legacySubspace: legacySubspace, clientKeeper: ck, @@ -39,14 +41,15 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace ty } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when sdk.Context is removed + return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } // GetCommitmentPrefix returns the IBC connection store prefix as a commitment // Prefix func (k *Keeper) GetCommitmentPrefix() exported.Prefix { - return commitmenttypes.NewMerklePrefix([]byte(k.storeKey.Name())) + return commitmenttypes.NewMerklePrefix([]byte(k.storeService.Name())) } // GenerateConnectionIdentifier returns the next connection identifier. @@ -60,9 +63,12 @@ func (k *Keeper) GenerateConnectionIdentifier(ctx sdk.Context) string { } // GetConnection returns a connection with a particular identifier -func (k *Keeper) GetConnection(ctx sdk.Context, connectionID string) (types.ConnectionEnd, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(host.ConnectionKey(connectionID)) +func (k *Keeper) GetConnection(ctx context.Context, connectionID string) (types.ConnectionEnd, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.ConnectionKey(connectionID)) + if err != nil { + return types.ConnectionEnd{}, false + } if len(bz) == 0 { return types.ConnectionEnd{}, false } @@ -75,23 +81,30 @@ func (k *Keeper) GetConnection(ctx sdk.Context, connectionID string) (types.Conn // HasConnection returns a true if the connection with the given identifier // exists in the store. -func (k *Keeper) HasConnection(ctx sdk.Context, connectionID string) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(host.ConnectionKey(connectionID)) +func (k *Keeper) HasConnection(ctx context.Context, connectionID string) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.ConnectionKey(connectionID)) + if err != nil { + return false + } + return has } // SetConnection sets a connection to the store -func (k *Keeper) SetConnection(ctx sdk.Context, connectionID string, connection types.ConnectionEnd) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetConnection(ctx context.Context, connectionID string, connection types.ConnectionEnd) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&connection) store.Set(host.ConnectionKey(connectionID), bz) } // GetClientConnectionPaths returns all the connection paths stored under a // particular client -func (k *Keeper) GetClientConnectionPaths(ctx sdk.Context, clientID string) ([]string, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(host.ClientConnectionsKey(clientID)) +func (k *Keeper) GetClientConnectionPaths(ctx context.Context, clientID string) ([]string, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.ClientConnectionsKey(clientID)) + if err != nil { + return nil, false + } if len(bz) == 0 { return nil, false } @@ -102,17 +115,20 @@ func (k *Keeper) GetClientConnectionPaths(ctx sdk.Context, clientID string) ([]s } // SetClientConnectionPaths sets the connections paths for client -func (k *Keeper) SetClientConnectionPaths(ctx sdk.Context, clientID string, paths []string) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetClientConnectionPaths(ctx context.Context, clientID string, paths []string) { + store := k.storeService.OpenKVStore(ctx) clientPaths := types.ClientPaths{Paths: paths} bz := k.cdc.MustMarshal(&clientPaths) store.Set(host.ClientConnectionsKey(clientID), bz) } // GetNextConnectionSequence gets the next connection sequence from the store. -func (k *Keeper) GetNextConnectionSequence(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.KeyNextConnectionSequence)) +func (k *Keeper) GetNextConnectionSequence(ctx context.Context) uint64 { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte(types.KeyNextConnectionSequence)) + if err != nil { + panic(errors.New("next connection sequence is nil")) + } if len(bz) == 0 { panic(errors.New("next connection sequence is nil")) } @@ -121,8 +137,8 @@ func (k *Keeper) GetNextConnectionSequence(ctx sdk.Context) uint64 { } // SetNextConnectionSequence sets the next connection sequence to the store. -func (k *Keeper) SetNextConnectionSequence(ctx sdk.Context, sequence uint64) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetNextConnectionSequence(ctx context.Context, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set([]byte(types.KeyNextConnectionSequence), bz) } @@ -130,9 +146,10 @@ func (k *Keeper) SetNextConnectionSequence(ctx sdk.Context, sequence uint64) { // GetAllClientConnectionPaths returns all stored clients connection id paths. It // will ignore the clients that haven't initialized a connection handshake since // no paths are stored. -func (k *Keeper) GetAllClientConnectionPaths(ctx sdk.Context) []types.ConnectionPaths { +func (k *Keeper) GetAllClientConnectionPaths(ctx context.Context) []types.ConnectionPaths { var allConnectionPaths []types.ConnectionPaths - k.clientKeeper.IterateClientStates(ctx, nil, func(clientID string, cs exported.ClientState) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when sdk.Context is removed + k.clientKeeper.IterateClientStates(sdkCtx, nil, func(clientID string, cs exported.ClientState) bool { paths, found := k.GetClientConnectionPaths(ctx, clientID) if !found { // continue when connection handshake is not initialized @@ -149,11 +166,11 @@ func (k *Keeper) GetAllClientConnectionPaths(ctx sdk.Context) []types.Connection // IterateConnections provides an iterator over all ConnectionEnd objects. // For each ConnectionEnd, cb will be called. If the cb returns true, the // iterator will close and stop. -func (k *Keeper) IterateConnections(ctx sdk.Context, cb func(types.IdentifiedConnection) bool) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) IterateConnections(ctx context.Context, cb func(types.IdentifiedConnection) bool) { + store := k.storeService.OpenKVStore(ctx) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyConnectionPrefix)) - 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 connection types.ConnectionEnd k.cdc.MustUnmarshal(iterator.Value(), &connection) @@ -167,7 +184,7 @@ func (k *Keeper) IterateConnections(ctx sdk.Context, cb func(types.IdentifiedCon } // GetAllConnections returns all stored ConnectionEnd objects. -func (k *Keeper) GetAllConnections(ctx sdk.Context) (connections []types.IdentifiedConnection) { +func (k *Keeper) GetAllConnections(ctx context.Context) (connections []types.IdentifiedConnection) { k.IterateConnections(ctx, func(connection types.IdentifiedConnection) bool { connections = append(connections, connection) return false @@ -176,7 +193,7 @@ func (k *Keeper) GetAllConnections(ctx sdk.Context) (connections []types.Identif } // CreateSentinelLocalhostConnection creates and sets the sentinel localhost connection end in the IBC store. -func (k *Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { +func (k *Keeper) CreateSentinelLocalhostConnection(ctx context.Context) { counterparty := types.NewCounterparty(exported.LocalhostClientID, exported.LocalhostConnectionID, commitmenttypes.NewMerklePrefix(k.GetCommitmentPrefix().Bytes())) connectionEnd := types.NewConnectionEnd(types.OPEN, exported.LocalhostClientID, counterparty, types.GetCompatibleVersions(), 0) @@ -185,8 +202,9 @@ func (k *Keeper) CreateSentinelLocalhostConnection(ctx sdk.Context) { // addConnectionToClient is used to add a connection identifier to the set of // connections associated with a client. -func (k *Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID string) error { - _, found := k.clientKeeper.GetClientState(ctx, clientID) +func (k *Keeper) addConnectionToClient(ctx context.Context, clientID, connectionID string) error { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when sdk.Context is removed + _, found := k.clientKeeper.GetClientState(sdkCtx, clientID) if !found { return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } @@ -202,9 +220,12 @@ func (k *Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID s } // GetParams returns the total set of ibc-connection 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(errors.New("connection params are not set in store")) + } if bz == nil { // only panic on unset params and not on empty params panic(errors.New("connection params are not set in store")) } @@ -215,8 +236,8 @@ func (k *Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the total set of ibc-connection 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) } From 29d32cd412c8cad0a883d9051de5a258e6a41b74 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Tue, 6 Aug 2024 13:16:06 +0200 Subject: [PATCH 03/19] ++ --- modules/core/02-client/keeper/keeper.go | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 49b89737f8a..0c40c15d28b 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -54,8 +54,9 @@ func (k *Keeper) Codec() codec.BinaryCodec { } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after sdk.Context is removed from core IBC + return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } // AddRoute adds a new route to the underlying router. @@ -69,7 +70,7 @@ func (k *Keeper) GetStoreProvider() types.StoreProvider { } // Route returns the light client module for the given client identifier. -func (k *Keeper) Route(ctx sdk.Context, clientID string) (exported.LightClientModule, error) { +func (k *Keeper) Route(ctx context.Context, clientID string) (exported.LightClientModule, error) { clientType, _, err := types.ParseClientIdentifier(clientID) if err != nil { return nil, errorsmod.Wrapf(err, "unable to parse client identifier %s", clientID) @@ -91,7 +92,7 @@ func (k *Keeper) Route(ctx sdk.Context, clientID string) (exported.LightClientMo } // GenerateClientIdentifier returns the next client identifier. -func (k *Keeper) GenerateClientIdentifier(ctx sdk.Context, clientType string) string { +func (k *Keeper) GenerateClientIdentifier(ctx context.Context, clientType string) string { nextClientSeq := k.GetNextClientSequence(ctx) clientID := types.FormatClientIdentifier(clientType, nextClientSeq) @@ -101,7 +102,7 @@ func (k *Keeper) GenerateClientIdentifier(ctx sdk.Context, clientType string) st } // GetClientState gets a particular client from the store -func (k *Keeper) GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) { +func (k *Keeper) GetClientState(ctx context.Context, clientID string) (exported.ClientState, bool) { store := k.ClientStore(ctx, clientID) bz := store.Get(host.ClientStateKey()) if len(bz) == 0 { @@ -113,13 +114,13 @@ func (k *Keeper) GetClientState(ctx sdk.Context, clientID string) (exported.Clie } // SetClientState sets a particular Client to the store -func (k *Keeper) SetClientState(ctx sdk.Context, clientID string, clientState exported.ClientState) { +func (k *Keeper) SetClientState(ctx context.Context, clientID string, clientState exported.ClientState) { store := k.ClientStore(ctx, clientID) store.Set(host.ClientStateKey(), types.MustMarshalClientState(k.cdc, clientState)) } // GetClientConsensusState gets the stored consensus state from a client at a given height. -func (k *Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) { +func (k *Keeper) GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) { store := k.ClientStore(ctx, clientID) bz := store.Get(host.ConsensusStateKey(height)) if len(bz) == 0 { @@ -132,7 +133,7 @@ func (k *Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, heigh // SetClientConsensusState sets a ConsensusState to a particular client at the given // height -func (k *Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height, consensusState exported.ConsensusState) { +func (k *Keeper) SetClientConsensusState(ctx context.Context, clientID string, height exported.Height, consensusState exported.ConsensusState) { store := k.ClientStore(ctx, clientID) store.Set(host.ConsensusStateKey(height), types.MustMarshalConsensusState(k.cdc, consensusState)) } @@ -165,7 +166,7 @@ func (k *Keeper) IterateConsensusStates(ctx context.Context, cb func(clientID st store := k.storeService.OpenKVStore(ctx) iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix) - 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() { keySplit := strings.Split(string(iterator.Key()), "/") // consensus key is in the format "clients//consensusStates/" @@ -386,14 +387,15 @@ func (k *Keeper) GetAllClients(ctx sdk.Context) []exported.ClientState { // ClientStore returns isolated prefix store for each client so they can read/write in separate // namespace without being able to read/write other client's data -func (k *Keeper) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore { +func (k *Keeper) ClientStore(ctx context.Context, clientID string) storetypes.KVStore { clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) - return prefix.NewStore(ctx.KVStore(k.storeKey), clientPrefix) + store := k.storeService.OpenKVStore(ctx) + return prefix.NewStore(store, clientPrefix) } // GetClientStatus returns the status for a client state given a client identifier. If the client type is not in the allowed // clients param field, Unauthorized is returned, otherwise the client state status is returned. -func (k *Keeper) GetClientStatus(ctx sdk.Context, clientID string) exported.Status { +func (k *Keeper) GetClientStatus(ctx context.Context, clientID string) exported.Status { clientModule, err := k.Route(ctx, clientID) if err != nil { return exported.Unauthorized @@ -404,7 +406,7 @@ func (k *Keeper) GetClientStatus(ctx sdk.Context, clientID string) exported.Stat // GetClientLatestHeight returns the latest height of a client state for a given client identifier. If the client type is not in the allowed // clients param field, a zero value height is returned, otherwise the client state latest height is returned. -func (k *Keeper) GetClientLatestHeight(ctx sdk.Context, clientID string) types.Height { +func (k *Keeper) GetClientLatestHeight(ctx context.Context, clientID string) types.Height { clientModule, err := k.Route(ctx, clientID) if err != nil { return types.ZeroHeight() @@ -419,7 +421,7 @@ func (k *Keeper) GetClientLatestHeight(ctx sdk.Context, clientID string) types.H } // GetClientTimestampAtHeight returns the timestamp in nanoseconds of the consensus state at the given height. -func (k *Keeper) GetClientTimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { +func (k *Keeper) GetClientTimestampAtHeight(ctx context.Context, clientID string, height exported.Height) (uint64, error) { clientModule, err := k.Route(ctx, clientID) if err != nil { return 0, err From 1636f4868beebf649b708f8c26ce6d4cad96372c Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Tue, 6 Aug 2024 22:19:58 +0200 Subject: [PATCH 04/19] ++ --- modules/core/02-client/keeper/grpc_query.go | 7 +- modules/core/02-client/keeper/keeper.go | 44 ++--- modules/core/02-client/keeper/migrations.go | 4 +- .../migrations/v7/expected_keepers.go | 10 +- modules/core/02-client/migrations/v7/store.go | 6 +- modules/core/02-client/types/height.go | 8 +- modules/core/02-client/types/store.go | 19 +- .../core/03-connection/keeper/grpc_query.go | 4 +- modules/core/03-connection/keeper/keeper.go | 8 +- .../migrations/v7/expected_keepers.go | 6 +- .../03-connection/types/expected_keepers.go | 14 +- modules/core/04-channel/keeper/grpc_query.go | 8 +- modules/core/04-channel/keeper/keeper.go | 165 ++++++++++-------- .../core/04-channel/types/expected_keepers.go | 12 +- .../07-tendermint/light_client_module.go | 26 +-- .../09-localhost/light_client_module.go | 23 +-- 16 files changed, 202 insertions(+), 162 deletions(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index b8d742ba838..e0dafbd3294 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -14,6 +14,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" @@ -77,7 +78,7 @@ func (q *queryServer) ClientStates(c context.Context, req *types.QueryClientStat ctx := sdk.UnwrapSDKContext(c) var clientStates types.IdentifiedClientStates - store := prefix.NewStore(ctx.KVStore(q.storeKey), host.KeyClientStorePrefix) + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), host.KeyClientStorePrefix) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under client state key @@ -172,7 +173,7 @@ func (q *queryServer) ConsensusStates(c context.Context, req *types.QueryConsens ctx := sdk.UnwrapSDKContext(c) var consensusStates []types.ConsensusStateWithHeight - store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under consensus state key @@ -216,7 +217,7 @@ func (q *queryServer) ConsensusStateHeights(c context.Context, req *types.QueryC ctx := sdk.UnwrapSDKContext(c) var consensusStateHeights []types.Height - store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix)))) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) { // filter any metadata stored under consensus state key diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 0c40c15d28b..6b3a618a021 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -14,6 +14,7 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/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/v9/modules/core/02-client/types" @@ -36,7 +37,7 @@ type Keeper struct { // NewKeeper creates a new NewKeeper instance func NewKeeper(cdc codec.BinaryCodec, storeService corestoretypes.KVStoreService, legacySubspace types.ParamSubspace, uk types.UpgradeKeeper) *Keeper { router := types.NewRouter() - localhostModule := localhost.NewLightClientModule(cdc, key) + localhostModule := localhost.NewLightClientModule(cdc, storeService) router.AddRoute(exported.Localhost, localhostModule) return &Keeper{ @@ -66,7 +67,7 @@ func (k *Keeper) AddRoute(clientType string, module exported.LightClientModule) // GetStoreProvider returns the light client store provider. func (k *Keeper) GetStoreProvider() types.StoreProvider { - return types.NewStoreProvider(k.storeKey) + return types.NewStoreProvider(k.storeService) } // Route returns the light client module for the given client identifier. @@ -163,7 +164,7 @@ func (k *Keeper) SetNextClientSequence(ctx context.Context, sequence uint64) { // objects. For each State object, cb will be called. If the cb returns true, // the iterator will close and stop. func (k *Keeper) IterateConsensusStates(ctx context.Context, cb func(clientID string, cs types.ConsensusStateWithHeight) bool) { - store := k.storeService.OpenKVStore(ctx) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix) defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) @@ -188,7 +189,7 @@ func (k *Keeper) IterateConsensusStates(ctx context.Context, cb func(clientID st // iterateMetadata provides an iterator over all stored metadata keys in the client store. // For each metadata object, it will perform a callback. func (k *Keeper) iterateMetadata(ctx context.Context, cb func(clientID string, key, value []byte) bool) { - store := k.storeService.OpenKVStore(ctx) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, host.KeyClientStorePrefix) defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) @@ -222,7 +223,7 @@ func (k *Keeper) iterateMetadata(ctx context.Context, cb func(clientID string, k } // GetAllGenesisClients returns all the clients in state with their client ids returned as IdentifiedClientState -func (k *Keeper) GetAllGenesisClients(ctx sdk.Context) types.IdentifiedClientStates { +func (k *Keeper) GetAllGenesisClients(ctx context.Context) types.IdentifiedClientStates { var genClients types.IdentifiedClientStates k.IterateClientStates(ctx, nil, func(clientID string, cs exported.ClientState) bool { genClients = append(genClients, types.NewIdentifiedClientState(clientID, cs)) @@ -235,7 +236,7 @@ func (k *Keeper) GetAllGenesisClients(ctx sdk.Context) types.IdentifiedClientSta // GetAllClientMetadata will take a list of IdentifiedClientState and return a list // of IdentifiedGenesisMetadata necessary for exporting and importing client metadata // into the client store. -func (k *Keeper) GetAllClientMetadata(ctx sdk.Context, genClients []types.IdentifiedClientState) ([]types.IdentifiedGenesisMetadata, error) { +func (k *Keeper) GetAllClientMetadata(ctx context.Context, genClients []types.IdentifiedClientState) ([]types.IdentifiedGenesisMetadata, error) { metadataMap := make(map[string][]types.GenesisMetadata) k.iterateMetadata(ctx, func(clientID string, key, value []byte) bool { metadataMap[clientID] = append(metadataMap[clientID], types.NewGenesisMetadata(key, value)) @@ -257,7 +258,7 @@ func (k *Keeper) GetAllClientMetadata(ctx sdk.Context, genClients []types.Identi } // SetAllClientMetadata takes a list of IdentifiedGenesisMetadata and stores all of the metadata in the client store at the appropriate paths. -func (k *Keeper) SetAllClientMetadata(ctx sdk.Context, genMetadata []types.IdentifiedGenesisMetadata) { +func (k *Keeper) SetAllClientMetadata(ctx context.Context, genMetadata []types.IdentifiedGenesisMetadata) { for _, igm := range genMetadata { // create client store store := k.ClientStore(ctx, igm.ClientId) @@ -269,7 +270,7 @@ func (k *Keeper) SetAllClientMetadata(ctx sdk.Context, genMetadata []types.Ident } // GetAllConsensusStates returns all stored client consensus states. -func (k *Keeper) GetAllConsensusStates(ctx sdk.Context) types.ClientsConsensusStates { +func (k *Keeper) GetAllConsensusStates(ctx context.Context) types.ClientsConsensusStates { clientConsStates := make(types.ClientsConsensusStates, 0) mapClientIDToConsStateIdx := make(map[string]int) @@ -295,13 +296,13 @@ func (k *Keeper) GetAllConsensusStates(ctx sdk.Context) types.ClientsConsensusSt // HasClientConsensusState returns if keeper has a ConsensusState for a particular // client at the given height -func (k *Keeper) HasClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) bool { +func (k *Keeper) HasClientConsensusState(ctx context.Context, clientID string, height exported.Height) bool { store := k.ClientStore(ctx, clientID) return store.Has(host.ConsensusStateKey(height)) } // GetLatestClientConsensusState gets the latest ConsensusState stored for a given client -func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) (exported.ConsensusState, bool) { +func (k *Keeper) GetLatestClientConsensusState(ctx context.Context, clientID string) (exported.ConsensusState, bool) { clientModule, err := k.Route(ctx, clientID) if err != nil { return nil, false @@ -311,7 +312,7 @@ func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) } // VerifyMembership retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height. -func (k *Keeper) VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error { +func (k *Keeper) VerifyMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error { clientModule, err := k.Route(ctx, clientID) if err != nil { return err @@ -321,7 +322,7 @@ func (k *Keeper) VerifyMembership(ctx sdk.Context, clientID string, height expor } // VerifyNonMembership retrieves the light client module for the clientID and verifies the absence of a given key at a specified height. -func (k *Keeper) VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error { +func (k *Keeper) VerifyNonMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error { clientModule, err := k.Route(ctx, clientID) if err != nil { return err @@ -331,22 +332,22 @@ func (k *Keeper) VerifyNonMembership(ctx sdk.Context, clientID string, height ex } // GetUpgradePlan executes the upgrade keeper GetUpgradePlan function. -func (k *Keeper) GetUpgradePlan(ctx sdk.Context) (upgradetypes.Plan, error) { +func (k *Keeper) GetUpgradePlan(ctx context.Context) (upgradetypes.Plan, error) { return k.upgradeKeeper.GetUpgradePlan(ctx) } // GetUpgradedClient executes the upgrade keeper GetUpgradeClient function. -func (k *Keeper) GetUpgradedClient(ctx sdk.Context, planHeight int64) ([]byte, error) { +func (k *Keeper) GetUpgradedClient(ctx context.Context, planHeight int64) ([]byte, error) { return k.upgradeKeeper.GetUpgradedClient(ctx, planHeight) } // GetUpgradedConsensusState returns the upgraded consensus state -func (k *Keeper) GetUpgradedConsensusState(ctx sdk.Context, planHeight int64) ([]byte, error) { +func (k *Keeper) GetUpgradedConsensusState(ctx context.Context, planHeight int64) ([]byte, error) { return k.upgradeKeeper.GetUpgradedConsensusState(ctx, planHeight) } // SetUpgradedConsensusState executes the upgrade keeper SetUpgradedConsensusState function. -func (k *Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error { +func (k *Keeper) SetUpgradedConsensusState(ctx context.Context, planHeight int64, bz []byte) error { return k.upgradeKeeper.SetUpgradedConsensusState(ctx, planHeight, bz) } @@ -354,7 +355,7 @@ func (k *Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz // objects using the provided store prefix. For each ClientState object, cb will be called. If the cb returns true, // the iterator will close and stop. func (k *Keeper) IterateClientStates(ctx context.Context, storePrefix []byte, cb func(clientID string, cs exported.ClientState) bool) { - store := k.storeService.OpenKVStore(ctx) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, host.PrefixedClientStoreKey(storePrefix)) defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) @@ -375,7 +376,7 @@ func (k *Keeper) IterateClientStates(ctx context.Context, storePrefix []byte, cb } // GetAllClients returns all stored light client State objects. -func (k *Keeper) GetAllClients(ctx sdk.Context) []exported.ClientState { +func (k *Keeper) GetAllClients(ctx context.Context) []exported.ClientState { var states []exported.ClientState k.IterateClientStates(ctx, nil, func(_ string, state exported.ClientState) bool { states = append(states, state) @@ -389,7 +390,7 @@ func (k *Keeper) GetAllClients(ctx sdk.Context) []exported.ClientState { // namespace without being able to read/write other client's data func (k *Keeper) ClientStore(ctx context.Context, clientID string) storetypes.KVStore { clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) - store := k.storeService.OpenKVStore(ctx) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) return prefix.NewStore(store, clientPrefix) } @@ -451,7 +452,7 @@ func (k *Keeper) SetParams(ctx context.Context, params types.Params) { } // ScheduleIBCSoftwareUpgrade schedules an upgrade for the IBC client. -func (k *Keeper) ScheduleIBCSoftwareUpgrade(ctx sdk.Context, plan upgradetypes.Plan, upgradedClientState exported.ClientState) error { +func (k *Keeper) ScheduleIBCSoftwareUpgrade(ctx context.Context, plan upgradetypes.Plan, upgradedClientState exported.ClientState) error { // zero out any custom fields before setting cs, ok := upgradedClientState.(*ibctm.ClientState) if !ok { @@ -475,7 +476,8 @@ func (k *Keeper) ScheduleIBCSoftwareUpgrade(ctx sdk.Context, plan upgradetypes.P } // emitting an event for scheduling an upgrade plan - emitScheduleIBCSoftwareUpgradeEvent(ctx, plan.Name, plan.Height) + sdkContext := sdk.UnwrapSDKContext(ctx) // TODO: remove after sdk.Context is removed from core IBC + emitScheduleIBCSoftwareUpgradeEvent(sdkContext, plan.Name, plan.Height) return nil } diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index ba45e543622..637b03b6c1b 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" + v7 "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -26,7 +26,7 @@ func NewMigrator(keeper *Keeper) Migrator { // - removes the localhost client // - asserts that existing tendermint clients are properly registered on the chain codec func (m Migrator) Migrate2to3(ctx sdk.Context) error { - return v7.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc, m.keeper) + return v7.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc, m.keeper) } // MigrateParams migrates from consensus version 4 to 5. diff --git a/modules/core/02-client/migrations/v7/expected_keepers.go b/modules/core/02-client/migrations/v7/expected_keepers.go index d25f9f880f6..feb486b73f2 100644 --- a/modules/core/02-client/migrations/v7/expected_keepers.go +++ b/modules/core/02-client/migrations/v7/expected_keepers.go @@ -1,16 +1,16 @@ package v7 import ( - storetypes "cosmossdk.io/store/types" + "context" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "cosmossdk.io/store/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) // ClientKeeper expected IBC client keeper type ClientKeeper interface { - GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) - SetClientState(ctx sdk.Context, clientID string, clientState exported.ClientState) - ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore + GetClientState(ctx context.Context, clientID string) (exported.ClientState, bool) + SetClientState(ctx context.Context, clientID string, clientState exported.ClientState) + ClientStore(ctx context.Context, clientID string) storetypes.KVStore } diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go index a75de44cbed..0885b343f2f 100644 --- a/modules/core/02-client/migrations/v7/store.go +++ b/modules/core/02-client/migrations/v7/store.go @@ -6,8 +6,10 @@ import ( errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" + corestore "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -29,8 +31,8 @@ const Localhost string = "09-localhost" // - Pruning all solo machine consensus states // - Removing the localhost client // - Asserting existing tendermint clients are properly registered on the chain codec -func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, clientKeeper ClientKeeper) error { - store := ctx.KVStore(storeKey) +func MigrateStore(ctx sdk.Context, storeService corestore.KVStoreService, cdc codec.BinaryCodec, clientKeeper ClientKeeper) error { + store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx)) if err := handleSolomachineMigration(ctx, store, cdc, clientKeeper); err != nil { return err diff --git a/modules/core/02-client/types/height.go b/modules/core/02-client/types/height.go index a326142a685..0d21426a17f 100644 --- a/modules/core/02-client/types/height.go +++ b/modules/core/02-client/types/height.go @@ -1,6 +1,7 @@ package types import ( + "context" "fmt" "math/big" "regexp" @@ -185,7 +186,8 @@ func ParseChainID(chainID string) uint64 { // GetSelfHeight is a utility function that returns self height given context // Revision number is retrieved from ctx.ChainID() -func GetSelfHeight(ctx sdk.Context) Height { - revision := ParseChainID(ctx.ChainID()) - return NewHeight(revision, uint64(ctx.BlockHeight())) +func GetSelfHeight(ctx context.Context) Height { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after sdk.Context is removed from core IBC + revision := ParseChainID(sdkCtx.ChainID()) + return NewHeight(revision, uint64(sdkCtx.BlockHeight())) } diff --git a/modules/core/02-client/types/store.go b/modules/core/02-client/types/store.go index 446e6933d8a..721e496be20 100644 --- a/modules/core/02-client/types/store.go +++ b/modules/core/02-client/types/store.go @@ -1,35 +1,36 @@ package types import ( + "context" "fmt" + corestore "cosmossdk.io/core/store" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - + "github.com/cosmos/cosmos-sdk/runtime" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ) // StoreProvider encapsulates the IBC core store key and offers convenience methods for LightClientModules. type StoreProvider struct { - storeKey storetypes.StoreKey + storeService corestore.KVStoreService } // NewStoreProvider creates and returns a new client StoreProvider. -func NewStoreProvider(storeKey storetypes.StoreKey) StoreProvider { +func NewStoreProvider(storeKey corestore.KVStoreService) StoreProvider { return StoreProvider{ - storeKey: storeKey, + storeService: storeKey, } } // ClientStore returns isolated prefix store for each client so they can read/write in separate namespaces. -func (s StoreProvider) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore { +func (s StoreProvider) ClientStore(ctx context.Context, clientID string) storetypes.KVStore { clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) - return prefix.NewStore(ctx.KVStore(s.storeKey), clientPrefix) + return prefix.NewStore(runtime.KVStoreAdapter(s.storeService.OpenKVStore(ctx)), clientPrefix) } // ClientModuleStore returns the module store for a provided client type. -func (s StoreProvider) ClientModuleStore(ctx sdk.Context, clientType string) storetypes.KVStore { - return prefix.NewStore(ctx.KVStore(s.storeKey), host.PrefixedClientStoreKey([]byte(clientType))) +func (s StoreProvider) ClientModuleStore(ctx context.Context, clientType string) storetypes.KVStore { + return prefix.NewStore(runtime.KVStoreAdapter(s.storeService.OpenKVStore(ctx)), host.PrefixedClientStoreKey([]byte(clientType))) } diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 256ffe30a9d..859b6125332 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -9,6 +9,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" @@ -66,7 +67,8 @@ func (q *queryServer) Connections(c context.Context, req *types.QueryConnections ctx := sdk.UnwrapSDKContext(c) var connections []*types.IdentifiedConnection - store := prefix.NewStore(ctx.KVStore(q.storeService), []byte(host.KeyConnectionPrefix)) + + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), []byte(host.KeyConnectionPrefix)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var result types.ConnectionEnd diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 8dc7b5c3826..937f6bea4cd 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -10,6 +10,7 @@ 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" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -49,11 +50,11 @@ func (Keeper) Logger(ctx context.Context) log.Logger { // GetCommitmentPrefix returns the IBC connection store prefix as a commitment // Prefix func (k *Keeper) GetCommitmentPrefix() exported.Prefix { - return commitmenttypes.NewMerklePrefix([]byte(k.storeService.Name())) + return commitmenttypes.NewMerklePrefix([]byte("ibc")) // TODO: import store key directly } // GenerateConnectionIdentifier returns the next connection identifier. -func (k *Keeper) GenerateConnectionIdentifier(ctx sdk.Context) string { +func (k *Keeper) GenerateConnectionIdentifier(ctx context.Context) string { nextConnSeq := k.GetNextConnectionSequence(ctx) connectionID := types.FormatConnectionIdentifier(nextConnSeq) @@ -167,7 +168,8 @@ func (k *Keeper) GetAllClientConnectionPaths(ctx context.Context) []types.Connec // For each ConnectionEnd, cb will be called. If the cb returns true, the // iterator will close and stop. func (k *Keeper) IterateConnections(ctx context.Context, cb func(types.IdentifiedConnection) bool) { - store := k.storeService.OpenKVStore(ctx) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyConnectionPrefix)) defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) diff --git a/modules/core/03-connection/migrations/v7/expected_keepers.go b/modules/core/03-connection/migrations/v7/expected_keepers.go index 8427e2cc2bf..c36d1fbae93 100644 --- a/modules/core/03-connection/migrations/v7/expected_keepers.go +++ b/modules/core/03-connection/migrations/v7/expected_keepers.go @@ -1,10 +1,8 @@ package v7 -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) +import "context" // ConnectionKeeper expected IBC connection keeper type ConnectionKeeper interface { - CreateSentinelLocalhostConnection(ctx sdk.Context) + CreateSentinelLocalhostConnection(ctx context.Context) } diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index ff13cf0d742..b2c28f8fe10 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -1,6 +1,8 @@ package types import ( + context "context" + sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -9,12 +11,12 @@ import ( // ClientKeeper expected account IBC client keeper type ClientKeeper interface { - GetClientStatus(ctx sdk.Context, clientID string) exported.Status - GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) - GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) - VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error - VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error - IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) + GetClientStatus(ctx context.Context, clientID string) exported.Status + GetClientState(ctx context.Context, clientID string) (exported.ClientState, bool) + GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) + VerifyMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error + VerifyNonMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error + IterateClientStates(ctx context.Context, prefix []byte, cb func(string, exported.ClientState) bool) } // ParamSubspace defines the expected Subspace interface for module parameters. diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 3d03f8f9088..e02fcdf318a 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -68,7 +68,7 @@ func (q *queryServer) Channels(c context.Context, req *types.QueryChannelsReques ctx := sdk.UnwrapSDKContext(c) var channels []*types.IdentifiedChannel - store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyChannelEndPrefix)) + store := prefix.NewStore(ctx.KVStore(q.storeService), []byte(host.KeyChannelEndPrefix)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var result types.Channel @@ -110,7 +110,7 @@ func (q *queryServer) ConnectionChannels(c context.Context, req *types.QueryConn ctx := sdk.UnwrapSDKContext(c) var channels []*types.IdentifiedChannel - store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyChannelEndPrefix)) + store := prefix.NewStore(ctx.KVStore(q.storeService), []byte(host.KeyChannelEndPrefix)) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under channel key @@ -266,7 +266,7 @@ func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacke ) } var commitments []*types.PacketState - store := prefix.NewStore(ctx.KVStore(q.storeKey), host.PacketCommitmentPrefixKey(req.PortId, req.ChannelId)) + store := prefix.NewStore(ctx.KVStore(q.storeService), host.PacketCommitmentPrefixKey(req.PortId, req.ChannelId)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { keySplit := strings.Split(string(key), "/") @@ -370,7 +370,7 @@ func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.Query ) } var acks []*types.PacketState - store := prefix.NewStore(ctx.KVStore(q.storeKey), host.PacketAcknowledgementPrefixKey(req.PortId, req.ChannelId)) + store := prefix.NewStore(ctx.KVStore(q.storeService), host.PacketAcknowledgementPrefixKey(req.PortId, req.ChannelId)) // if a list of packet sequences is provided then query for each specific ack and return a list <= len(req.PacketCommitmentSequences) // otherwise, maintain previous behaviour and perform paginated query diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 33f9e6d2856..8ab5cd03d5a 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -1,12 +1,14 @@ package keeper import ( + "context" "errors" "strconv" "strings" db "github.com/cosmos/cosmos-db" + corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -30,7 +32,7 @@ type Keeper struct { // implements gRPC QueryServer interface types.QueryServer - storeKey storetypes.StoreKey + storeService corestore.KVStoreService cdc codec.BinaryCodec clientKeeper types.ClientKeeper connectionKeeper types.ConnectionKeeper @@ -40,12 +42,15 @@ type Keeper struct { // NewKeeper creates a new IBC channel Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, - clientKeeper types.ClientKeeper, connectionKeeper types.ConnectionKeeper, - portKeeper types.PortKeeper, scopedKeeper exported.ScopedKeeper, + cdc codec.BinaryCodec, + storeService corestore.KVStoreService, + clientKeeper types.ClientKeeper, + connectionKeeper types.ConnectionKeeper, + portKeeper types.PortKeeper, + scopedKeeper exported.ScopedKeeper, ) *Keeper { return &Keeper{ - storeKey: key, + storeService: storeService, cdc: cdc, clientKeeper: clientKeeper, connectionKeeper: connectionKeeper, @@ -70,15 +75,22 @@ func (k *Keeper) GenerateChannelIdentifier(ctx sdk.Context) string { } // HasChannel true if the channel with the given identifiers exists in state. -func (k *Keeper) HasChannel(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(host.ChannelKey(portID, channelID)) +func (k *Keeper) HasChannel(ctx context.Context, portID, channelID string) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.ChannelKey(portID, channelID)) + if err != nil { + panic(err) + } + return has } // GetChannel returns a channel with a particular identifier binded to a specific port -func (k *Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (types.Channel, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(host.ChannelKey(portID, channelID)) +func (k *Keeper) GetChannel(ctx context.Context, portID, channelID string) (types.Channel, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.ChannelKey(portID, channelID)) + if err != nil { + panic(err) + } if len(bz) == 0 { return types.Channel{}, false } @@ -89,8 +101,8 @@ func (k *Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (types.Ch } // SetChannel sets a channel to the store -func (k *Keeper) SetChannel(ctx sdk.Context, portID, channelID string, channel types.Channel) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetChannel(ctx context.Context, portID, channelID string, channel types.Channel) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&channel) store.Set(host.ChannelKey(portID, channelID), bz) } @@ -106,9 +118,12 @@ func (k *Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (strin } // GetNextChannelSequence gets the next channel sequence from the store. -func (k *Keeper) GetNextChannelSequence(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(types.KeyNextChannelSequence)) +func (k *Keeper) GetNextChannelSequence(ctx context.Context) uint64 { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte(types.KeyNextChannelSequence)) + if err != nil { + panic(err) + } if len(bz) == 0 { panic(errors.New("next channel sequence is nil")) } @@ -117,16 +132,19 @@ func (k *Keeper) GetNextChannelSequence(ctx sdk.Context) uint64 { } // SetNextChannelSequence sets the next channel sequence to the store. -func (k *Keeper) SetNextChannelSequence(ctx sdk.Context, sequence uint64) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetNextChannelSequence(ctx context.Context, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set([]byte(types.KeyNextChannelSequence), bz) } // GetNextSequenceSend gets a channel's next send sequence from the store -func (k *Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(host.NextSequenceSendKey(portID, channelID)) +func (k *Keeper) GetNextSequenceSend(ctx context.Context, portID, channelID string) (uint64, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.NextSequenceSendKey(portID, channelID)) + if err != nil { + panic(err) + } if len(bz) == 0 { return 0, false } @@ -135,16 +153,19 @@ func (k *Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) } // SetNextSequenceSend sets a channel's next send sequence to the store -func (k *Keeper) SetNextSequenceSend(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetNextSequenceSend(ctx context.Context, portID, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.NextSequenceSendKey(portID, channelID), bz) } // GetNextSequenceRecv gets a channel's next receive sequence from the store -func (k *Keeper) GetNextSequenceRecv(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(host.NextSequenceRecvKey(portID, channelID)) +func (k *Keeper) GetNextSequenceRecv(ctx context.Context, portID, channelID string) (uint64, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.NextSequenceRecvKey(portID, channelID)) + if err != nil { + panic(err) + } if len(bz) == 0 { return 0, false } @@ -153,15 +174,15 @@ func (k *Keeper) GetNextSequenceRecv(ctx sdk.Context, portID, channelID string) } // SetNextSequenceRecv sets a channel's next receive sequence to the store -func (k *Keeper) SetNextSequenceRecv(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) +func (k *Keeper) SetNextSequenceRecv(ctx context.Context, portID, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.NextSequenceRecvKey(portID, channelID), bz) } // GetNextSequenceAck gets a channel's next ack sequence from the store func (k *Keeper) GetNextSequenceAck(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.NextSequenceAckKey(portID, channelID)) if len(bz) == 0 { return 0, false @@ -172,14 +193,14 @@ func (k *Keeper) GetNextSequenceAck(ctx sdk.Context, portID, channelID string) ( // SetNextSequenceAck sets a channel's next ack sequence to the store func (k *Keeper) SetNextSequenceAck(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.NextSequenceAckKey(portID, channelID), bz) } // GetPacketReceipt gets a packet receipt from the store func (k *Keeper) GetPacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) (string, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.PacketReceiptKey(portID, channelID, sequence)) if len(bz) == 0 { return "", false @@ -190,49 +211,51 @@ func (k *Keeper) GetPacketReceipt(ctx sdk.Context, portID, channelID string, seq // SetPacketReceipt sets an empty packet receipt to the store func (k *Keeper) SetPacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(host.PacketReceiptKey(portID, channelID, sequence), []byte{byte(1)}) } // deletePacketReceipt deletes a packet receipt from the store func (k *Keeper) deletePacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(host.PacketReceiptKey(portID, channelID, sequence)) } // GetPacketCommitment gets the packet commitment hash from the store func (k *Keeper) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.PacketCommitmentKey(portID, channelID, sequence)) return bz } // HasPacketCommitment returns true if the packet commitment exists func (k *Keeper) HasPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) bool { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) return store.Has(host.PacketCommitmentKey(portID, channelID, sequence)) } // SetPacketCommitment sets the packet commitment hash to the store func (k *Keeper) SetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64, commitmentHash []byte) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(host.PacketCommitmentKey(portID, channelID, sequence), commitmentHash) } func (k *Keeper) deletePacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) - store.Delete(host.PacketCommitmentKey(portID, channelID, sequence)) + store := k.storeService.OpenKVStore(ctx) + if err := store.Delete(host.PacketCommitmentKey(portID, channelID, sequence)); err != nil { + panic(err) + } } // SetPacketAcknowledgement sets the packet ack hash to the store func (k *Keeper) SetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64, ackHash []byte) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(host.PacketAcknowledgementKey(portID, channelID, sequence), ackHash) } // GetPacketAcknowledgement gets the packet ack hash from the store func (k *Keeper) GetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) ([]byte, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.PacketAcknowledgementKey(portID, channelID, sequence)) if len(bz) == 0 { return nil, false @@ -242,14 +265,16 @@ func (k *Keeper) GetPacketAcknowledgement(ctx sdk.Context, portID, channelID str // HasPacketAcknowledgement check if the packet ack hash is already on the store func (k *Keeper) HasPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) bool { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) return store.Has(host.PacketAcknowledgementKey(portID, channelID, sequence)) } // deletePacketAcknowledgement deletes the packet ack hash from the store func (k *Keeper) deletePacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) - store.Delete(host.PacketAcknowledgementKey(portID, channelID, sequence)) + store := k.storeService.OpenKVStore(ctx) + if err := store.Delete(host.PacketAcknowledgementKey(portID, channelID, sequence)); err != nil { + panic(err) + } } // IteratePacketSequence provides an iterator over all send, receive or ack sequences. @@ -274,7 +299,7 @@ func (Keeper) IteratePacketSequence(ctx sdk.Context, iterator db.Iterator, cb fu // GetAllPacketSendSeqs returns all stored next send sequences. func (k *Keeper) GetAllPacketSendSeqs(ctx sdk.Context) (seqs []types.PacketSequence) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyNextSeqSendPrefix)) k.IteratePacketSequence(ctx, iterator, func(portID, channelID string, nextSendSeq uint64) bool { ps := types.NewPacketSequence(portID, channelID, nextSendSeq) @@ -286,7 +311,7 @@ func (k *Keeper) GetAllPacketSendSeqs(ctx sdk.Context) (seqs []types.PacketSeque // GetAllPacketRecvSeqs returns all stored next recv sequences. func (k *Keeper) GetAllPacketRecvSeqs(ctx sdk.Context) (seqs []types.PacketSequence) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyNextSeqRecvPrefix)) k.IteratePacketSequence(ctx, iterator, func(portID, channelID string, nextRecvSeq uint64) bool { ps := types.NewPacketSequence(portID, channelID, nextRecvSeq) @@ -298,7 +323,7 @@ func (k *Keeper) GetAllPacketRecvSeqs(ctx sdk.Context) (seqs []types.PacketSeque // GetAllPacketAckSeqs returns all stored next acknowledgements sequences. func (k *Keeper) GetAllPacketAckSeqs(ctx sdk.Context) (seqs []types.PacketSequence) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyNextSeqAckPrefix)) k.IteratePacketSequence(ctx, iterator, func(portID, channelID string, nextAckSeq uint64) bool { ps := types.NewPacketSequence(portID, channelID, nextAckSeq) @@ -312,7 +337,7 @@ func (k *Keeper) GetAllPacketAckSeqs(ctx sdk.Context) (seqs []types.PacketSequen // packet commitment, cb will be called. If the cb returns true, the iterator will close // and stop. func (k *Keeper) IteratePacketCommitment(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyPacketCommitmentPrefix)) k.iterateHashes(ctx, iterator, cb) } @@ -331,7 +356,7 @@ func (k *Keeper) GetAllPacketCommitments(ctx sdk.Context) (commitments []types.P // at a specified channel. For each packet commitment, cb will be called. If the cb returns // true, the iterator will close and stop. func (k *Keeper) IteratePacketCommitmentAtChannel(ctx sdk.Context, portID, channelID string, cb func(_, _ string, sequence uint64, hash []byte) bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, host.PacketCommitmentPrefixKey(portID, channelID)) k.iterateHashes(ctx, iterator, cb) } @@ -351,7 +376,7 @@ func (k *Keeper) GetAllPacketCommitmentsAtChannel(ctx sdk.Context, portID, chann // receipt, cb will be called. If the cb returns true, the iterator will close // and stop. func (k *Keeper) IteratePacketReceipt(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, receipt []byte) bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyPacketReceiptPrefix)) k.iterateHashes(ctx, iterator, cb) } @@ -370,7 +395,7 @@ func (k *Keeper) GetAllPacketReceipts(ctx sdk.Context) (receipts []types.PacketS // acknowledgement, cb will be called. If the cb returns true, the iterator will close // and stop. func (k *Keeper) IteratePacketAcknowledgement(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyPacketAckPrefix)) k.iterateHashes(ctx, iterator, cb) } @@ -389,7 +414,7 @@ func (k *Keeper) GetAllPacketAcks(ctx sdk.Context) (acks []types.PacketState) { // Channel, cb will be called. If the cb returns true, the iterator will close // and stop. func (k *Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChannel) bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyChannelEndPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -411,7 +436,7 @@ func (k *Keeper) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string if strings.TrimSpace(portPrefix) == "" { return k.GetAllChannels(ctx) } - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) iterator := storetypes.KVStorePrefixIterator(store, types.FilteredPortPrefix(portPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -495,7 +520,7 @@ func (k *Keeper) LookupModuleByChannel(ctx sdk.Context, portID, channelID string // GetUpgradeErrorReceipt returns the upgrade error receipt for the provided port and channel identifiers. func (k *Keeper) GetUpgradeErrorReceipt(ctx sdk.Context, portID, channelID string) (types.ErrorReceipt, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.ChannelUpgradeErrorKey(portID, channelID)) if bz == nil { return types.ErrorReceipt{}, false @@ -509,20 +534,20 @@ func (k *Keeper) GetUpgradeErrorReceipt(ctx sdk.Context, portID, channelID strin // setUpgradeErrorReceipt sets the provided error receipt in store using the port and channel identifiers. func (k *Keeper) setUpgradeErrorReceipt(ctx sdk.Context, portID, channelID string, errorReceipt types.ErrorReceipt) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := k.cdc.MustMarshal(&errorReceipt) store.Set(host.ChannelUpgradeErrorKey(portID, channelID), bz) } // hasUpgrade returns true if a proposed upgrade exists in store func (k *Keeper) hasUpgrade(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) return store.Has(host.ChannelUpgradeKey(portID, channelID)) } // GetUpgrade returns the proposed upgrade for the provided port and channel identifiers. func (k *Keeper) GetUpgrade(ctx sdk.Context, portID, channelID string) (types.Upgrade, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.ChannelUpgradeKey(portID, channelID)) if bz == nil { return types.Upgrade{}, false @@ -536,26 +561,26 @@ func (k *Keeper) GetUpgrade(ctx sdk.Context, portID, channelID string) (types.Up // SetUpgrade sets the proposed upgrade using the provided port and channel identifiers. func (k *Keeper) SetUpgrade(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := k.cdc.MustMarshal(&upgrade) store.Set(host.ChannelUpgradeKey(portID, channelID), bz) } // deleteUpgrade deletes the upgrade for the provided port and channel identifiers. func (k *Keeper) deleteUpgrade(ctx sdk.Context, portID, channelID string) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) store.Delete(host.ChannelUpgradeKey(portID, channelID)) } // hasCounterpartyUpgrade returns true if a counterparty upgrade exists in store func (k *Keeper) hasCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) return store.Has(host.ChannelCounterpartyUpgradeKey(portID, channelID)) } // GetCounterpartyUpgrade gets the counterparty upgrade from the store. func (k *Keeper) GetCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) (types.Upgrade, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.ChannelCounterpartyUpgradeKey(portID, channelID)) if bz == nil { return types.Upgrade{}, false @@ -569,14 +594,14 @@ func (k *Keeper) GetCounterpartyUpgrade(ctx sdk.Context, portID, channelID strin // SetCounterpartyUpgrade sets the counterparty upgrade in the store. func (k *Keeper) SetCounterpartyUpgrade(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := k.cdc.MustMarshal(&upgrade) store.Set(host.ChannelCounterpartyUpgradeKey(portID, channelID), bz) } // deleteCounterpartyUpgrade deletes the counterparty upgrade in the store. func (k *Keeper) deleteCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) store.Delete(host.ChannelCounterpartyUpgradeKey(portID, channelID)) } @@ -588,14 +613,14 @@ func (k *Keeper) deleteUpgradeInfo(ctx sdk.Context, portID, channelID string) { // SetParams sets the channel parameters. func (k *Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := k.cdc.MustMarshal(¶ms) store.Set([]byte(types.ParamsKey), bz) } // GetParams returns the total set of the channel parameters. func (k *Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { // only panic on unset params and not on empty params panic(errors.New("channel params are not set in store")) @@ -629,7 +654,7 @@ func (Keeper) iterateHashes(ctx sdk.Context, iterator db.Iterator, cb func(portI // HasInflightPackets returns true if there are packet commitments stored at the specified // port and channel, and false otherwise. func (k *Keeper) HasInflightPackets(ctx sdk.Context, portID, channelID string) bool { - iterator := storetypes.KVStorePrefixIterator(ctx.KVStore(k.storeKey), host.PacketCommitmentPrefixKey(portID, channelID)) + iterator := storetypes.KVStorePrefixIterator(ctx.KVStore(k.storeService), host.PacketCommitmentPrefixKey(portID, channelID)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) return iterator.Valid() @@ -637,7 +662,7 @@ func (k *Keeper) HasInflightPackets(ctx sdk.Context, portID, channelID string) b // setRecvStartSequence sets the channel's recv start sequence to the store. func (k *Keeper) setRecvStartSequence(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.RecvStartSequenceKey(portID, channelID), bz) } @@ -647,7 +672,7 @@ func (k *Keeper) setRecvStartSequence(ctx sdk.Context, portID, channelID string, // upon a successful channel upgrade. It will be used for replay protection of // historical packets and as the upper bound for pruning stale packet receives. func (k *Keeper) GetRecvStartSequence(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.RecvStartSequenceKey(portID, channelID)) if len(bz) == 0 { return 0, false @@ -658,14 +683,14 @@ func (k *Keeper) GetRecvStartSequence(ctx sdk.Context, portID, channelID string) // SetPruningSequenceStart sets a channel's pruning sequence start to the store. func (k *Keeper) SetPruningSequenceStart(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.PruningSequenceStartKey(portID, channelID), bz) } // GetPruningSequenceStart gets a channel's pruning sequence start from the store. func (k *Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := store.Get(host.PruningSequenceStartKey(portID, channelID)) if len(bz) == 0 { return 0, false @@ -676,7 +701,7 @@ func (k *Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID stri // HasPruningSequenceStart returns true if the pruning sequence start is set for the specified channel. func (k *Keeper) HasPruningSequenceStart(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) return store.Has(host.PruningSequenceStartKey(portID, channelID)) } diff --git a/modules/core/04-channel/types/expected_keepers.go b/modules/core/04-channel/types/expected_keepers.go index 47ff95e4685..b1b39d977da 100644 --- a/modules/core/04-channel/types/expected_keepers.go +++ b/modules/core/04-channel/types/expected_keepers.go @@ -1,6 +1,8 @@ package types import ( + context "context" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -11,11 +13,11 @@ import ( // ClientKeeper expected account IBC client keeper type ClientKeeper interface { - GetClientStatus(ctx sdk.Context, clientID string) exported.Status - GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) - GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) - GetClientLatestHeight(ctx sdk.Context, clientID string) clienttypes.Height - GetClientTimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) + GetClientStatus(ctx context.Context, clientID string) exported.Status + GetClientState(ctx context.Context, clientID string) (exported.ClientState, bool) + GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) + GetClientLatestHeight(ctx context.Context, clientID string) clienttypes.Height + GetClientTimestampAtHeight(ctx context.Context, clientID string, height exported.Height) (uint64, error) } // ConnectionKeeper expected account IBC connection keeper diff --git a/modules/light-clients/07-tendermint/light_client_module.go b/modules/light-clients/07-tendermint/light_client_module.go index e0acee6d75e..2b45ba7d917 100644 --- a/modules/light-clients/07-tendermint/light_client_module.go +++ b/modules/light-clients/07-tendermint/light_client_module.go @@ -1,12 +1,12 @@ package tendermint import ( + "context" "fmt" 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" @@ -31,7 +31,7 @@ func NewLightClientModule(cdc codec.BinaryCodec, storeProvider clienttypes.Store // Initialize unmarshals the provided client and consensus states and performs basic validation. It calls into the // clientState.initialize method. -func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error { +func (l LightClientModule) Initialize(ctx context.Context, clientID string, clientStateBz, consensusStateBz []byte) error { var clientState ClientState if err := l.cdc.Unmarshal(clientStateBz, &clientState); err != nil { return fmt.Errorf("failed to unmarshal client state bytes into client state: %w", err) @@ -56,7 +56,7 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt } // VerifyClientMessage obtains the client state associated with the client identifier and calls into the clientState.VerifyClientMessage method. -func (l LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { +func (l LightClientModule) VerifyClientMessage(ctx context.Context, clientID string, clientMsg exported.ClientMessage) error { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -67,7 +67,7 @@ func (l LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, } // CheckForMisbehaviour obtains the client state associated with the client identifier and calls into the clientState.CheckForMisbehaviour method. -func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { +func (l LightClientModule) CheckForMisbehaviour(ctx context.Context, clientID string, clientMsg exported.ClientMessage) bool { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -78,7 +78,7 @@ func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string } // UpdateStateOnMisbehaviour obtains the client state associated with the client identifier and calls into the clientState.UpdateStateOnMisbehaviour method. -func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { +func (l LightClientModule) UpdateStateOnMisbehaviour(ctx context.Context, clientID string, clientMsg exported.ClientMessage) { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -89,7 +89,7 @@ func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID s } // UpdateState obtains the client state associated with the client identifier and calls into the clientState.UpdateState method. -func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { +func (l LightClientModule) UpdateState(ctx context.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -101,7 +101,7 @@ func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientM // VerifyMembership obtains the client state associated with the client identifier and calls into the clientState.verifyMembership method. func (l LightClientModule) VerifyMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, @@ -121,7 +121,7 @@ func (l LightClientModule) VerifyMembership( // VerifyNonMembership obtains the client state associated with the client identifier and calls into the clientState.verifyNonMembership method. func (l LightClientModule) VerifyNonMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, @@ -139,7 +139,7 @@ func (l LightClientModule) VerifyNonMembership( } // Status obtains the client state associated with the client identifier and calls into the clientState.status method. -func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { +func (l LightClientModule) Status(ctx context.Context, clientID string) exported.Status { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -151,7 +151,7 @@ func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Sta // LatestHeight returns the latest height for the client state for the given client identifier. // If no client is present for the provided client identifier a zero value height is returned. -func (l LightClientModule) LatestHeight(ctx sdk.Context, clientID string) exported.Height { +func (l LightClientModule) LatestHeight(ctx context.Context, clientID string) exported.Height { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -163,7 +163,7 @@ func (l LightClientModule) LatestHeight(ctx sdk.Context, clientID string) export // TimestampAtHeight obtains the client state associated with the client identifier and calls into the clientState.getTimestampAtHeight method. func (l LightClientModule) TimestampAtHeight( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, ) (uint64, error) { @@ -178,7 +178,7 @@ func (l LightClientModule) TimestampAtHeight( // RecoverClient asserts that the substitute client is a tendermint client. It obtains the client state associated with the // subject client and calls into the subjectClientState.CheckSubstituteAndUpdateState method. -func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { +func (l LightClientModule) RecoverClient(ctx context.Context, clientID, substituteClientID string) error { substituteClientType, _, err := clienttypes.ParseClientIdentifier(substituteClientID) if err != nil { return err @@ -207,7 +207,7 @@ func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteCl // The new client and consensus states will be unmarshaled and an error is returned if the new client state is not at a height greater // than the existing client. func (l LightClientModule) VerifyUpgradeAndUpdateState( - ctx sdk.Context, + ctx context.Context, clientID string, newClient []byte, newConsState []byte, diff --git a/modules/light-clients/09-localhost/light_client_module.go b/modules/light-clients/09-localhost/light_client_module.go index 687e3108bd6..14a80c5b97e 100644 --- a/modules/light-clients/09-localhost/light_client_module.go +++ b/modules/light-clients/09-localhost/light_client_module.go @@ -46,27 +46,27 @@ func NewLightClientModule(cdc codec.BinaryCodec, key corestore.KVStoreService) * } // Initialize returns an error because it is stateless. -func (LightClientModule) Initialize(_ sdk.Context, _ string, _, _ []byte) error { +func (LightClientModule) Initialize(_ context.Context, _ string, _, _ []byte) error { return errorsmod.Wrap(clienttypes.ErrClientExists, "localhost is stateless and cannot be initialized") } // VerifyClientMessage is unsupported by the 09-localhost client type and returns an error. -func (LightClientModule) VerifyClientMessage(_ sdk.Context, _ string, _ exported.ClientMessage) error { +func (LightClientModule) VerifyClientMessage(_ context.Context, _ string, _ exported.ClientMessage) error { return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "client message verification is unsupported by the localhost client") } // CheckForMisbehaviour is unsupported by the 09-localhost client type and performs a no-op, returning false. -func (LightClientModule) CheckForMisbehaviour(_ sdk.Context, _ string, _ exported.ClientMessage) bool { +func (LightClientModule) CheckForMisbehaviour(_ context.Context, _ string, _ exported.ClientMessage) bool { return false } // UpdateStateOnMisbehaviour is unsupported by the 09-localhost client type and performs a no-op. -func (LightClientModule) UpdateStateOnMisbehaviour(_ sdk.Context, _ string, _ exported.ClientMessage) { +func (LightClientModule) UpdateStateOnMisbehaviour(_ context.Context, _ string, _ exported.ClientMessage) { // no-op } // UpdateState performs a no-op and returns the context height in the updated heights return value. -func (LightClientModule) UpdateState(ctx sdk.Context, _ string, _ exported.ClientMessage) []exported.Height { +func (LightClientModule) UpdateState(ctx context.Context, _ string, _ exported.ClientMessage) []exported.Height { return []exported.Height{clienttypes.GetSelfHeight(ctx)} } @@ -156,27 +156,28 @@ func (l LightClientModule) VerifyNonMembership( } // Status always returns Active. The 09-localhost status cannot be changed. -func (LightClientModule) Status(_ sdk.Context, _ string) exported.Status { +func (LightClientModule) Status(_ context.Context, _ string) exported.Status { return exported.Active } // LatestHeight returns the context height. -func (LightClientModule) LatestHeight(ctx sdk.Context, _ string) exported.Height { +func (LightClientModule) LatestHeight(ctx context.Context, _ string) exported.Height { return clienttypes.GetSelfHeight(ctx) } // TimestampAtHeight returns the current block time retrieved from the application context. The localhost client does not store consensus states and thus // cannot provide a timestamp for the provided height. -func (LightClientModule) TimestampAtHeight(ctx sdk.Context, _ string, _ exported.Height) (uint64, error) { - return uint64(ctx.BlockTime().UnixNano()), nil +func (LightClientModule) TimestampAtHeight(ctx context.Context, _ string, _ exported.Height) (uint64, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after sdk.Context is removed from core IBC + return uint64(sdkCtx.BlockTime().UnixNano()), nil } // RecoverClient returns an error. The localhost cannot be modified by proposals. -func (LightClientModule) RecoverClient(_ sdk.Context, _, _ string) error { +func (LightClientModule) RecoverClient(_ context.Context, _, _ string) error { return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "cannot update localhost client with a proposal") } // VerifyUpgradeAndUpdateState returns an error since localhost cannot be upgraded. -func (LightClientModule) VerifyUpgradeAndUpdateState(_ sdk.Context, _ string, _, _, _, _ []byte) error { +func (LightClientModule) VerifyUpgradeAndUpdateState(_ context.Context, _ string, _, _, _, _ []byte) error { return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade localhost client") } From a92ec4ba7273f2928bb3311a3f261e0c47650efe Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 7 Aug 2024 10:47:01 +0200 Subject: [PATCH 05/19] ++ --- .../controller/ibc_middleware.go | 3 +- modules/apps/29-fee/keeper/grpc_query.go | 6 +- modules/apps/29-fee/keeper/keeper.go | 72 +++-- modules/apps/29-fee/keeper/migrations.go | 2 +- modules/apps/29-fee/keeper/relay.go | 9 +- modules/apps/29-fee/types/expected_keepers.go | 10 +- modules/core/04-channel/keeper/grpc_query.go | 74 ++--- modules/core/04-channel/keeper/keeper.go | 277 +++++++++++------- modules/core/04-channel/keeper/packet.go | 15 +- .../core/04-channel/types/expected_keepers.go | 20 +- modules/core/05-port/keeper/keeper.go | 27 +- modules/core/05-port/types/module.go | 8 +- modules/core/exported/expected_keepers.go | 1 - .../06-solomachine/light_client_module.go | 26 +- .../06-solomachine/misbehaviour_handle.go | 5 +- .../06-solomachine/proposal_handle.go | 4 +- .../light-clients/06-solomachine/update.go | 7 +- .../07-tendermint/client_state.go | 17 +- .../07-tendermint/light_client_module.go | 4 +- .../07-tendermint/misbehaviour_handle.go | 10 +- .../07-tendermint/proposal_handle.go | 4 +- modules/light-clients/07-tendermint/store.go | 6 +- modules/light-clients/07-tendermint/update.go | 20 +- .../light-clients/07-tendermint/upgrade.go | 4 +- simapp/app.go | 2 +- 25 files changed, 348 insertions(+), 285 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index db7db8bc4e8..439b6641196 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -1,6 +1,7 @@ package controller import ( + "context" "errors" errorsmod "cosmossdk.io/errors" @@ -324,7 +325,7 @@ func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID str // SendPacket implements the ICS4 Wrapper interface func (IBCMiddleware) SendPacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index 508c6f6fc89..0e0948c4639 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -28,7 +28,7 @@ func (k Keeper) IncentivizedPackets(goCtx context.Context, req *types.QueryIncen ctx := sdk.UnwrapSDKContext(goCtx).WithBlockHeight(int64(req.QueryHeight)) var identifiedPackets []types.IdentifiedPacketFees - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeesInEscrowPrefix)) + store := prefix.NewStore(ctx.KVStore(k.storeService), []byte(types.FeesInEscrowPrefix)) pagination, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { packetID, err := types.ParseKeyFeesInEscrow(types.FeesInEscrowPrefix + string(key)) if err != nil { @@ -90,7 +90,7 @@ func (k Keeper) IncentivizedPacketsForChannel(goCtx context.Context, req *types. var packets []*types.IdentifiedPacketFees keyPrefix := types.KeyFeesInEscrowChannelPrefix(req.PortId, req.ChannelId) - store := prefix.NewStore(ctx.KVStore(k.storeKey), keyPrefix) + store := prefix.NewStore(ctx.KVStore(k.storeService), keyPrefix) pagination, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { packetID, err := types.ParseKeyFeesInEscrow(string(keyPrefix) + string(key)) if err != nil { @@ -237,7 +237,7 @@ func (k Keeper) FeeEnabledChannels(goCtx context.Context, req *types.QueryFeeEna ctx := sdk.UnwrapSDKContext(goCtx).WithBlockHeight(int64(req.QueryHeight)) var feeEnabledChannels []types.FeeEnabledChannel - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeeEnabledKeyPrefix)) + store := prefix.NewStore(ctx.KVStore(k.storeService), []byte(types.FeeEnabledKeyPrefix)) pagination, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { portID, channelID, err := types.ParseKeyFeeEnabled(types.FeeEnabledKeyPrefix + string(key)) if err != nil { diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 74228c9477b..59c44f08e3c 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -1,10 +1,14 @@ package keeper import ( + "context" + + corestore "cosmossdk.io/core/store" "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" @@ -23,8 +27,8 @@ var ( // Keeper defines the IBC fungible transfer keeper type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec + storeService corestore.KVStoreService + cdc codec.BinaryCodec authKeeper types.AccountKeeper ics4Wrapper porttypes.ICS4Wrapper @@ -35,13 +39,13 @@ type Keeper struct { // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, + cdc codec.BinaryCodec, key corestore.KVStoreService, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ) Keeper { return Keeper{ cdc: cdc, - storeKey: key, + storeService: key, ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -113,40 +117,48 @@ func (k Keeper) EscrowAccountHasBalance(ctx sdk.Context, coins sdk.Coins) bool { // identified by channel and port identifiers. // Please see ADR 004 for more information. func (k Keeper) lockFeeModule(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyLocked(), []byte{1}) } // IsLocked indicates if the fee module is locked // Please see ADR 004 for more information. func (k Keeper) IsLocked(ctx sdk.Context) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(types.KeyLocked()) + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(types.KeyLocked()) + if err != nil { + panic(err) + } + return has } // SetFeeEnabled sets a flag to determine if fee handling logic should run for the given channel // identified by channel and port identifiers. func (k Keeper) SetFeeEnabled(ctx sdk.Context, portID, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyFeeEnabled(portID, channelID), []byte{1}) } // DeleteFeeEnabled deletes the fee enabled flag for a given portID and channelID func (k Keeper) DeleteFeeEnabled(ctx sdk.Context, portID, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.KeyFeeEnabled(portID, channelID)) } // IsFeeEnabled returns whether fee handling logic should be run for the given port. It will check the // fee enabled flag for the given port and channel identifiers -func (k Keeper) IsFeeEnabled(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(types.KeyFeeEnabled(portID, channelID)) +func (k Keeper) IsFeeEnabled(ctx context.Context, portID, channelID string) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(types.KeyFeeEnabled(portID, channelID)) + if err != nil { + panic(err) + } + return has } // GetAllFeeEnabledChannels returns a list of all ics29 enabled channels containing portID & channelID that are stored in state func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []types.FeeEnabledChannel { - store := ctx.KVStore(k.storeKey) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeeEnabledKeyPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -169,7 +181,7 @@ func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []types.FeeEnabledChan // GetPayeeAddress retrieves the fee payee address stored in state given the provided channel identifier and relayer address func (k Keeper) GetPayeeAddress(ctx sdk.Context, relayerAddr, channelID string) (string, bool) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) key := types.KeyPayee(relayerAddr, channelID) if !store.Has(key) { @@ -181,13 +193,13 @@ func (k Keeper) GetPayeeAddress(ctx sdk.Context, relayerAddr, channelID string) // SetPayeeAddress stores the fee payee address in state keyed by the provided channel identifier and relayer address func (k Keeper) SetPayeeAddress(ctx sdk.Context, relayerAddr, payeeAddr, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyPayee(relayerAddr, channelID), []byte(payeeAddr)) } // GetAllPayees returns all registered payees addresses func (k Keeper) GetAllPayees(ctx sdk.Context) []types.RegisteredPayee { - store := ctx.KVStore(k.storeKey) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.PayeeKeyPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -213,13 +225,13 @@ func (k Keeper) GetAllPayees(ctx sdk.Context) []types.RegisteredPayee { // SetCounterpartyPayeeAddress maps the destination chain counterparty payee address to the source relayer address // The receiving chain must store the mapping from: address -> counterpartyPayeeAddress for the given channel func (k Keeper) SetCounterpartyPayeeAddress(ctx sdk.Context, address, counterpartyAddress, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyCounterpartyPayee(address, channelID), []byte(counterpartyAddress)) } // GetCounterpartyPayeeAddress gets the counterparty payee address given a destination relayer address func (k Keeper) GetCounterpartyPayeeAddress(ctx sdk.Context, address, channelID string) (string, bool) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) key := types.KeyCounterpartyPayee(address, channelID) if !store.Has(key) { @@ -232,7 +244,7 @@ func (k Keeper) GetCounterpartyPayeeAddress(ctx sdk.Context, address, channelID // GetAllCounterpartyPayees returns all registered counterparty payee addresses func (k Keeper) GetAllCounterpartyPayees(ctx sdk.Context) []types.RegisteredCounterpartyPayee { - store := ctx.KVStore(k.storeKey) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.CounterpartyPayeeKeyPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -257,13 +269,13 @@ func (k Keeper) GetAllCounterpartyPayees(ctx sdk.Context) []types.RegisteredCoun // SetRelayerAddressForAsyncAck sets the forward relayer address during OnRecvPacket in case of async acknowledgement func (k Keeper) SetRelayerAddressForAsyncAck(ctx sdk.Context, packetID channeltypes.PacketId, address string) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) store.Set(types.KeyRelayerAddressForAsyncAck(packetID), []byte(address)) } // GetRelayerAddressForAsyncAck gets forward relayer address for a particular packet -func (k Keeper) GetRelayerAddressForAsyncAck(ctx sdk.Context, packetID channeltypes.PacketId) (string, bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetRelayerAddressForAsyncAck(ctx context.Context, packetID channeltypes.PacketId) (string, bool) { + store := ctx.KVStore(k.storeService) key := types.KeyRelayerAddressForAsyncAck(packetID) if !store.Has(key) { return "", false @@ -275,7 +287,7 @@ func (k Keeper) GetRelayerAddressForAsyncAck(ctx sdk.Context, packetID channelty // GetAllForwardRelayerAddresses returns all forward relayer addresses stored for async acknowledgements func (k Keeper) GetAllForwardRelayerAddresses(ctx sdk.Context) []types.ForwardRelayerAddress { - store := ctx.KVStore(k.storeKey) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.ForwardRelayerPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -299,14 +311,14 @@ func (k Keeper) GetAllForwardRelayerAddresses(ctx sdk.Context) []types.ForwardRe // DeleteForwardRelayerAddress deletes the forwardRelayerAddr associated with the packetID func (k Keeper) DeleteForwardRelayerAddress(ctx sdk.Context, packetID channeltypes.PacketId) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) key := types.KeyRelayerAddressForAsyncAck(packetID) store.Delete(key) } // GetFeesInEscrow returns all escrowed packet fees for a given packetID func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) (types.PacketFees, bool) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) key := types.KeyFeesInEscrow(packetID) bz := store.Get(key) if len(bz) == 0 { @@ -318,7 +330,7 @@ func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) // HasFeesInEscrow returns true if packet fees exist for the provided packetID func (k Keeper) HasFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) bool { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) key := types.KeyFeesInEscrow(packetID) return store.Has(key) @@ -326,14 +338,14 @@ func (k Keeper) HasFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) // SetFeesInEscrow sets the given packet fees in escrow keyed by the packetID func (k Keeper) SetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId, fees types.PacketFees) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) bz := k.MustMarshalFees(fees) store.Set(types.KeyFeesInEscrow(packetID), bz) } // DeleteFeesInEscrow deletes the fee associated with the given packetID func (k Keeper) DeleteFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) { - store := ctx.KVStore(k.storeKey) + store := ctx.KVStore(k.storeService) key := types.KeyFeesInEscrow(packetID) store.Delete(key) } @@ -342,7 +354,7 @@ func (k Keeper) DeleteFeesInEscrow(ctx sdk.Context, packetID channeltypes.Packet func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx sdk.Context, portID, channelID string) []types.IdentifiedPacketFees { var identifiedPacketFees []types.IdentifiedPacketFees - store := ctx.KVStore(k.storeKey) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, types.KeyFeesInEscrowChannelPrefix(portID, channelID)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) @@ -363,7 +375,7 @@ func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx sdk.Context, portID, chann // GetAllIdentifiedPacketFees returns a list of all IdentifiedPacketFees that are stored in state func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []types.IdentifiedPacketFees { - store := ctx.KVStore(k.storeKey) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeesInEscrowPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) diff --git a/modules/apps/29-fee/keeper/migrations.go b/modules/apps/29-fee/keeper/migrations.go index c4c093de5de..f06b7e5b97e 100644 --- a/modules/apps/29-fee/keeper/migrations.go +++ b/modules/apps/29-fee/keeper/migrations.go @@ -23,7 +23,7 @@ func NewMigrator(keeper Keeper) Migrator { // Migrate1to2 migrates ibc-fee module from ConsensusVersion 1 to 2 // by refunding leftover fees to the refund address. func (m Migrator) Migrate1to2(ctx sdk.Context) error { - store := ctx.KVStore(m.keeper.storeKey) + store := ctx.KVStore(m.keeper.storeService) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeesInEscrowPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index a93ea0c88ce..b1a2a1306b6 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -1,12 +1,11 @@ package keeper import ( + "context" "fmt" errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -16,7 +15,7 @@ import ( // SendPacket wraps the ICS4Wrapper SendPacket function func (k Keeper) SendPacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, @@ -29,7 +28,7 @@ func (k Keeper) SendPacket( // WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function // ICS29 WriteAcknowledgement is used for asynchronous acknowledgements -func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error { +func (k Keeper) WriteAcknowledgement(ctx context.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error { if !k.IsFeeEnabled(ctx, packet.GetDestPort(), packet.GetDestChannel()) { // ics4Wrapper may be core IBC or higher-level middleware return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, acknowledgement) @@ -56,7 +55,7 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C } // GetAppVersion returns the underlying application version. -func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (k Keeper) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { version, found := k.ics4Wrapper.GetAppVersion(ctx, portID, channelID) if !found { return "", false diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index acd20d9e7ec..f83198484b4 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -17,15 +17,15 @@ type AccountKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) - GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte - GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) - HasChannel(ctx sdk.Context, portID, channelID string) bool + GetChannel(ctx context.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetPacketCommitment(ctx context.Context, portID, channelID string, sequence uint64) []byte + GetNextSequenceSend(ctx context.Context, portID, channelID string) (uint64, bool) + HasChannel(ctx context.Context, portID, channelID string) bool } // PortKeeper defines the expected IBC port keeper type PortKeeper interface { - BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability + BindPort(ctx context.Context, portID string) *capabilitytypes.Capability } // BankKeeper defines the expected bank keeper diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index e02fcdf318a..648a8028534 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -11,7 +11,7 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/ibc-go/v9/internal/validate" @@ -37,7 +37,7 @@ func NewQueryServer(k *Keeper) types.QueryServer { } // Channel implements the Query/Channel gRPC method -func (q *queryServer) Channel(c context.Context, req *types.QueryChannelRequest) (*types.QueryChannelResponse, error) { +func (q *queryServer) Channel(ctx context.Context, req *types.QueryChannelRequest) (*types.QueryChannelResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -46,7 +46,6 @@ func (q *queryServer) Channel(c context.Context, req *types.QueryChannelRequest) return nil, err } - ctx := sdk.UnwrapSDKContext(c) channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -60,15 +59,13 @@ func (q *queryServer) Channel(c context.Context, req *types.QueryChannelRequest) } // Channels implements the Query/Channels gRPC method -func (q *queryServer) Channels(c context.Context, req *types.QueryChannelsRequest) (*types.QueryChannelsResponse, error) { +func (q *queryServer) Channels(ctx context.Context, req *types.QueryChannelsRequest) (*types.QueryChannelsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - ctx := sdk.UnwrapSDKContext(c) - var channels []*types.IdentifiedChannel - store := prefix.NewStore(ctx.KVStore(q.storeService), []byte(host.KeyChannelEndPrefix)) + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), []byte(host.KeyChannelEndPrefix)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var result types.Channel @@ -98,7 +95,7 @@ func (q *queryServer) Channels(c context.Context, req *types.QueryChannelsReques } // ConnectionChannels implements the Query/ConnectionChannels gRPC method -func (q *queryServer) ConnectionChannels(c context.Context, req *types.QueryConnectionChannelsRequest) (*types.QueryConnectionChannelsResponse, error) { +func (q *queryServer) ConnectionChannels(ctx context.Context, req *types.QueryConnectionChannelsRequest) (*types.QueryConnectionChannelsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -107,10 +104,9 @@ func (q *queryServer) ConnectionChannels(c context.Context, req *types.QueryConn return nil, status.Error(codes.InvalidArgument, err.Error()) } - ctx := sdk.UnwrapSDKContext(c) - var channels []*types.IdentifiedChannel - store := prefix.NewStore(ctx.KVStore(q.storeService), []byte(host.KeyChannelEndPrefix)) + + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), []byte(host.KeyChannelEndPrefix)) pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) { // filter any metadata stored under channel key @@ -147,7 +143,7 @@ func (q *queryServer) ConnectionChannels(c context.Context, req *types.QueryConn } // ChannelClientState implements the Query/ChannelClientState gRPC method -func (q *queryServer) ChannelClientState(c context.Context, req *types.QueryChannelClientStateRequest) (*types.QueryChannelClientStateResponse, error) { +func (q *queryServer) ChannelClientState(ctx context.Context, req *types.QueryChannelClientStateRequest) (*types.QueryChannelClientStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -156,8 +152,6 @@ func (q *queryServer) ChannelClientState(c context.Context, req *types.QueryChan return nil, err } - ctx := sdk.UnwrapSDKContext(c) - clientID, clientState, err := q.GetChannelClientState(ctx, req.PortId, req.ChannelId) if err != nil { return nil, status.Error(codes.NotFound, err.Error()) @@ -170,7 +164,7 @@ func (q *queryServer) ChannelClientState(c context.Context, req *types.QueryChan } // ChannelConsensusState implements the Query/ChannelConsensusState gRPC method -func (q *queryServer) ChannelConsensusState(c context.Context, req *types.QueryChannelConsensusStateRequest) (*types.QueryChannelConsensusStateResponse, error) { +func (q *queryServer) ChannelConsensusState(ctx context.Context, req *types.QueryChannelConsensusStateRequest) (*types.QueryChannelConsensusStateResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -179,8 +173,6 @@ func (q *queryServer) ChannelConsensusState(c context.Context, req *types.QueryC return nil, err } - ctx := sdk.UnwrapSDKContext(c) - channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -216,7 +208,7 @@ func (q *queryServer) ChannelConsensusState(c context.Context, req *types.QueryC } // PacketCommitment implements the Query/PacketCommitment gRPC method -func (q *queryServer) PacketCommitment(c context.Context, req *types.QueryPacketCommitmentRequest) (*types.QueryPacketCommitmentResponse, error) { +func (q *queryServer) PacketCommitment(ctx context.Context, req *types.QueryPacketCommitmentRequest) (*types.QueryPacketCommitmentResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -229,8 +221,6 @@ func (q *queryServer) PacketCommitment(c context.Context, req *types.QueryPacket return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") } - ctx := sdk.UnwrapSDKContext(c) - if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -248,7 +238,7 @@ func (q *queryServer) PacketCommitment(c context.Context, req *types.QueryPacket } // PacketCommitments implements the Query/PacketCommitments gRPC method -func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacketCommitmentsRequest) (*types.QueryPacketCommitmentsResponse, error) { +func (q *queryServer) PacketCommitments(ctx context.Context, req *types.QueryPacketCommitmentsRequest) (*types.QueryPacketCommitmentsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -257,8 +247,6 @@ func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacke return nil, err } - ctx := sdk.UnwrapSDKContext(c) - if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -266,7 +254,7 @@ func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacke ) } var commitments []*types.PacketState - store := prefix.NewStore(ctx.KVStore(q.storeService), host.PacketCommitmentPrefixKey(req.PortId, req.ChannelId)) + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), host.PacketCommitmentPrefixKey(req.PortId, req.ChannelId)) pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { keySplit := strings.Split(string(key), "/") @@ -293,7 +281,7 @@ func (q *queryServer) PacketCommitments(c context.Context, req *types.QueryPacke } // PacketReceipt implements the Query/PacketReceipt gRPC method -func (q *queryServer) PacketReceipt(c context.Context, req *types.QueryPacketReceiptRequest) (*types.QueryPacketReceiptResponse, error) { +func (q *queryServer) PacketReceipt(ctx context.Context, req *types.QueryPacketReceiptRequest) (*types.QueryPacketReceiptResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -306,8 +294,6 @@ func (q *queryServer) PacketReceipt(c context.Context, req *types.QueryPacketRec return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") } - ctx := sdk.UnwrapSDKContext(c) - if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -321,7 +307,7 @@ func (q *queryServer) PacketReceipt(c context.Context, req *types.QueryPacketRec } // PacketAcknowledgement implements the Query/PacketAcknowledgement gRPC method -func (q *queryServer) PacketAcknowledgement(c context.Context, req *types.QueryPacketAcknowledgementRequest) (*types.QueryPacketAcknowledgementResponse, error) { +func (q *queryServer) PacketAcknowledgement(ctx context.Context, req *types.QueryPacketAcknowledgementRequest) (*types.QueryPacketAcknowledgementResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -334,8 +320,6 @@ func (q *queryServer) PacketAcknowledgement(c context.Context, req *types.QueryP return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") } - ctx := sdk.UnwrapSDKContext(c) - if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -352,7 +336,7 @@ func (q *queryServer) PacketAcknowledgement(c context.Context, req *types.QueryP } // PacketAcknowledgements implements the Query/PacketAcknowledgements gRPC method -func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.QueryPacketAcknowledgementsRequest) (*types.QueryPacketAcknowledgementsResponse, error) { +func (q *queryServer) PacketAcknowledgements(ctx context.Context, req *types.QueryPacketAcknowledgementsRequest) (*types.QueryPacketAcknowledgementsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -361,8 +345,6 @@ func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.Query return nil, err } - ctx := sdk.UnwrapSDKContext(c) - if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -370,7 +352,7 @@ func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.Query ) } var acks []*types.PacketState - store := prefix.NewStore(ctx.KVStore(q.storeService), host.PacketAcknowledgementPrefixKey(req.PortId, req.ChannelId)) + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), host.PacketAcknowledgementPrefixKey(req.PortId, req.ChannelId)) // if a list of packet sequences is provided then query for each specific ack and return a list <= len(req.PacketCommitmentSequences) // otherwise, maintain previous behaviour and perform paginated query @@ -434,7 +416,7 @@ func (q *queryServer) PacketAcknowledgements(c context.Context, req *types.Query // commitments is correct and will not function properly if the list // is not up to date. Ideally the query height should equal the latest height // on the counterparty's client which represents this chain. -func (q *queryServer) UnreceivedPackets(c context.Context, req *types.QueryUnreceivedPacketsRequest) (*types.QueryUnreceivedPacketsResponse, error) { +func (q *queryServer) UnreceivedPackets(ctx context.Context, req *types.QueryUnreceivedPacketsRequest) (*types.QueryUnreceivedPacketsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -443,8 +425,6 @@ func (q *queryServer) UnreceivedPackets(c context.Context, req *types.QueryUnrec return nil, err } - ctx := sdk.UnwrapSDKContext(c) - channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -520,7 +500,7 @@ func (q *queryServer) UnreceivedPackets(c context.Context, req *types.QueryUnrec // acknowledgements is correct and will not function properly if the list // is not up to date. Ideally the query height should equal the latest height // on the counterparty's client which represents this chain. -func (q *queryServer) UnreceivedAcks(c context.Context, req *types.QueryUnreceivedAcksRequest) (*types.QueryUnreceivedAcksResponse, error) { +func (q *queryServer) UnreceivedAcks(ctx context.Context, req *types.QueryUnreceivedAcksRequest) (*types.QueryUnreceivedAcksResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -529,8 +509,6 @@ func (q *queryServer) UnreceivedAcks(c context.Context, req *types.QueryUnreceiv return nil, err } - ctx := sdk.UnwrapSDKContext(c) - if !q.HasChannel(ctx, req.PortId, req.ChannelId) { return nil, status.Error( codes.NotFound, @@ -560,7 +538,7 @@ func (q *queryServer) UnreceivedAcks(c context.Context, req *types.QueryUnreceiv } // NextSequenceReceive implements the Query/NextSequenceReceive gRPC method -func (q *queryServer) NextSequenceReceive(c context.Context, req *types.QueryNextSequenceReceiveRequest) (*types.QueryNextSequenceReceiveResponse, error) { +func (q *queryServer) NextSequenceReceive(ctx context.Context, req *types.QueryNextSequenceReceiveRequest) (*types.QueryNextSequenceReceiveResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -569,7 +547,6 @@ func (q *queryServer) NextSequenceReceive(c context.Context, req *types.QueryNex return nil, err } - ctx := sdk.UnwrapSDKContext(c) channel, found := q.GetChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -595,7 +572,7 @@ func (q *queryServer) NextSequenceReceive(c context.Context, req *types.QueryNex } // NextSequenceSend implements the Query/NextSequenceSend gRPC method -func (q *queryServer) NextSequenceSend(c context.Context, req *types.QueryNextSequenceSendRequest) (*types.QueryNextSequenceSendResponse, error) { +func (q *queryServer) NextSequenceSend(ctx context.Context, req *types.QueryNextSequenceSendRequest) (*types.QueryNextSequenceSendResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -604,8 +581,6 @@ func (q *queryServer) NextSequenceSend(c context.Context, req *types.QueryNextSe return nil, err } - ctx := sdk.UnwrapSDKContext(c) - sequence, found := q.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -618,7 +593,7 @@ func (q *queryServer) NextSequenceSend(c context.Context, req *types.QueryNextSe } // UpgradeErrorReceipt implements the Query/UpgradeErrorReceipt gRPC method -func (q *queryServer) UpgradeError(c context.Context, req *types.QueryUpgradeErrorRequest) (*types.QueryUpgradeErrorResponse, error) { +func (q *queryServer) UpgradeError(ctx context.Context, req *types.QueryUpgradeErrorRequest) (*types.QueryUpgradeErrorResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -627,7 +602,6 @@ func (q *queryServer) UpgradeError(c context.Context, req *types.QueryUpgradeErr return nil, err } - ctx := sdk.UnwrapSDKContext(c) found := q.HasChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -649,7 +623,7 @@ func (q *queryServer) UpgradeError(c context.Context, req *types.QueryUpgradeErr } // Upgrade implements the Query/UpgradeSequence gRPC method -func (q *queryServer) Upgrade(c context.Context, req *types.QueryUpgradeRequest) (*types.QueryUpgradeResponse, error) { +func (q *queryServer) Upgrade(ctx context.Context, req *types.QueryUpgradeRequest) (*types.QueryUpgradeResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } @@ -658,7 +632,6 @@ func (q *queryServer) Upgrade(c context.Context, req *types.QueryUpgradeRequest) return nil, err } - ctx := sdk.UnwrapSDKContext(c) found := q.HasChannel(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( @@ -680,8 +653,7 @@ func (q *queryServer) Upgrade(c context.Context, req *types.QueryUpgradeRequest) } // ChannelParams implements the Query/ChannelParams gRPC method. -func (q *queryServer) ChannelParams(c context.Context, req *types.QueryChannelParamsRequest) (*types.QueryChannelParamsResponse, error) { - ctx := sdk.UnwrapSDKContext(c) +func (q *queryServer) ChannelParams(ctx context.Context, req *types.QueryChannelParamsRequest) (*types.QueryChannelParamsResponse, error) { params := q.GetParams(ctx) return &types.QueryChannelParamsResponse{ diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 8ab5cd03d5a..dee7ca7258e 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -14,6 +14,7 @@ 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" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -60,12 +61,13 @@ func NewKeeper( } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } // GenerateChannelIdentifier returns the next channel identifier. -func (k *Keeper) GenerateChannelIdentifier(ctx sdk.Context) string { +func (k *Keeper) GenerateChannelIdentifier(ctx context.Context) string { nextChannelSeq := k.GetNextChannelSequence(ctx) channelID := types.FormatChannelIdentifier(nextChannelSeq) @@ -108,7 +110,7 @@ func (k *Keeper) SetChannel(ctx context.Context, portID, channelID string, chann } // GetAppVersion gets the version for the specified channel. -func (k *Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (k *Keeper) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { return "", false @@ -181,9 +183,12 @@ func (k *Keeper) SetNextSequenceRecv(ctx context.Context, portID, channelID stri } // GetNextSequenceAck gets a channel's next ack sequence from the store -func (k *Keeper) GetNextSequenceAck(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.NextSequenceAckKey(portID, channelID)) +func (k *Keeper) GetNextSequenceAck(ctx context.Context, portID, channelID string) (uint64, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.NextSequenceAckKey(portID, channelID)) + if err != nil { + return 0, false + } if len(bz) == 0 { return 0, false } @@ -192,16 +197,19 @@ func (k *Keeper) GetNextSequenceAck(ctx sdk.Context, portID, channelID string) ( } // SetNextSequenceAck sets a channel's next ack sequence to the store -func (k *Keeper) SetNextSequenceAck(ctx sdk.Context, portID, channelID string, sequence uint64) { +func (k *Keeper) SetNextSequenceAck(ctx context.Context, portID, channelID string, sequence uint64) { store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.NextSequenceAckKey(portID, channelID), bz) } // GetPacketReceipt gets a packet receipt from the store -func (k *Keeper) GetPacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) (string, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.PacketReceiptKey(portID, channelID, sequence)) +func (k *Keeper) GetPacketReceipt(ctx context.Context, portID, channelID string, sequence uint64) (string, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.PacketReceiptKey(portID, channelID, sequence)) + if err != nil { + return "", false + } if len(bz) == 0 { return "", false } @@ -210,37 +218,44 @@ func (k *Keeper) GetPacketReceipt(ctx sdk.Context, portID, channelID string, seq } // SetPacketReceipt sets an empty packet receipt to the store -func (k *Keeper) SetPacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) { +func (k *Keeper) SetPacketReceipt(ctx context.Context, portID, channelID string, sequence uint64) { store := k.storeService.OpenKVStore(ctx) store.Set(host.PacketReceiptKey(portID, channelID, sequence), []byte{byte(1)}) } // deletePacketReceipt deletes a packet receipt from the store -func (k *Keeper) deletePacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) { +func (k *Keeper) deletePacketReceipt(ctx context.Context, portID, channelID string, sequence uint64) { store := k.storeService.OpenKVStore(ctx) store.Delete(host.PacketReceiptKey(portID, channelID, sequence)) } // GetPacketCommitment gets the packet commitment hash from the store -func (k *Keeper) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.PacketCommitmentKey(portID, channelID, sequence)) +func (k *Keeper) GetPacketCommitment(ctx context.Context, portID, channelID string, sequence uint64) []byte { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.PacketCommitmentKey(portID, channelID, sequence)) + if err != nil { + return nil + } return bz } // HasPacketCommitment returns true if the packet commitment exists -func (k *Keeper) HasPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) bool { - store := ctx.KVStore(k.storeService) - return store.Has(host.PacketCommitmentKey(portID, channelID, sequence)) +func (k *Keeper) HasPacketCommitment(ctx context.Context, portID, channelID string, sequence uint64) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.PacketCommitmentKey(portID, channelID, sequence)) + if err != nil { + panic(err) + } + return has } // SetPacketCommitment sets the packet commitment hash to the store -func (k *Keeper) SetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64, commitmentHash []byte) { +func (k *Keeper) SetPacketCommitment(ctx context.Context, portID, channelID string, sequence uint64, commitmentHash []byte) { store := k.storeService.OpenKVStore(ctx) store.Set(host.PacketCommitmentKey(portID, channelID, sequence), commitmentHash) } -func (k *Keeper) deletePacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) { +func (k *Keeper) deletePacketCommitment(ctx context.Context, portID, channelID string, sequence uint64) { store := k.storeService.OpenKVStore(ctx) if err := store.Delete(host.PacketCommitmentKey(portID, channelID, sequence)); err != nil { panic(err) @@ -248,15 +263,18 @@ func (k *Keeper) deletePacketCommitment(ctx sdk.Context, portID, channelID strin } // SetPacketAcknowledgement sets the packet ack hash to the store -func (k *Keeper) SetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64, ackHash []byte) { +func (k *Keeper) SetPacketAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64, ackHash []byte) { store := k.storeService.OpenKVStore(ctx) store.Set(host.PacketAcknowledgementKey(portID, channelID, sequence), ackHash) } // GetPacketAcknowledgement gets the packet ack hash from the store -func (k *Keeper) GetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) ([]byte, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.PacketAcknowledgementKey(portID, channelID, sequence)) +func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64) ([]byte, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.PacketAcknowledgementKey(portID, channelID, sequence)) + if err != nil { + return nil, false + } if len(bz) == 0 { return nil, false } @@ -264,13 +282,17 @@ func (k *Keeper) GetPacketAcknowledgement(ctx sdk.Context, portID, channelID str } // HasPacketAcknowledgement check if the packet ack hash is already on the store -func (k *Keeper) HasPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) bool { - store := ctx.KVStore(k.storeService) - return store.Has(host.PacketAcknowledgementKey(portID, channelID, sequence)) +func (k *Keeper) HasPacketAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.PacketAcknowledgementKey(portID, channelID, sequence)) + if err != nil { + panic(err) + } + return has } // deletePacketAcknowledgement deletes the packet ack hash from the store -func (k *Keeper) deletePacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) { +func (k *Keeper) deletePacketAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64) { store := k.storeService.OpenKVStore(ctx) if err := store.Delete(host.PacketAcknowledgementKey(portID, channelID, sequence)); err != nil { panic(err) @@ -280,8 +302,8 @@ func (k *Keeper) deletePacketAcknowledgement(ctx sdk.Context, portID, channelID // IteratePacketSequence provides an iterator over all send, receive or ack sequences. // For each sequence, cb will be called. If the cb returns true, the iterator // will close and stop. -func (Keeper) IteratePacketSequence(ctx sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64) bool) { - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) +func (k *Keeper) IteratePacketSequence(ctx context.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64) bool) { + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) for ; iterator.Valid(); iterator.Next() { portID, channelID, err := host.ParseChannelPath(string(iterator.Key())) if err != nil { @@ -298,8 +320,8 @@ func (Keeper) IteratePacketSequence(ctx sdk.Context, iterator db.Iterator, cb fu } // GetAllPacketSendSeqs returns all stored next send sequences. -func (k *Keeper) GetAllPacketSendSeqs(ctx sdk.Context) (seqs []types.PacketSequence) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) GetAllPacketSendSeqs(ctx context.Context) (seqs []types.PacketSequence) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyNextSeqSendPrefix)) k.IteratePacketSequence(ctx, iterator, func(portID, channelID string, nextSendSeq uint64) bool { ps := types.NewPacketSequence(portID, channelID, nextSendSeq) @@ -310,8 +332,8 @@ func (k *Keeper) GetAllPacketSendSeqs(ctx sdk.Context) (seqs []types.PacketSeque } // GetAllPacketRecvSeqs returns all stored next recv sequences. -func (k *Keeper) GetAllPacketRecvSeqs(ctx sdk.Context) (seqs []types.PacketSequence) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) GetAllPacketRecvSeqs(ctx context.Context) (seqs []types.PacketSequence) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyNextSeqRecvPrefix)) k.IteratePacketSequence(ctx, iterator, func(portID, channelID string, nextRecvSeq uint64) bool { ps := types.NewPacketSequence(portID, channelID, nextRecvSeq) @@ -322,8 +344,8 @@ func (k *Keeper) GetAllPacketRecvSeqs(ctx sdk.Context) (seqs []types.PacketSeque } // GetAllPacketAckSeqs returns all stored next acknowledgements sequences. -func (k *Keeper) GetAllPacketAckSeqs(ctx sdk.Context) (seqs []types.PacketSequence) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) GetAllPacketAckSeqs(ctx context.Context) (seqs []types.PacketSequence) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyNextSeqAckPrefix)) k.IteratePacketSequence(ctx, iterator, func(portID, channelID string, nextAckSeq uint64) bool { ps := types.NewPacketSequence(portID, channelID, nextAckSeq) @@ -336,14 +358,14 @@ func (k *Keeper) GetAllPacketAckSeqs(ctx sdk.Context) (seqs []types.PacketSequen // IteratePacketCommitment provides an iterator over all PacketCommitment objects. For each // packet commitment, cb will be called. If the cb returns true, the iterator will close // and stop. -func (k *Keeper) IteratePacketCommitment(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) IteratePacketCommitment(ctx context.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyPacketCommitmentPrefix)) k.iterateHashes(ctx, iterator, cb) } // GetAllPacketCommitments returns all stored PacketCommitments objects. -func (k *Keeper) GetAllPacketCommitments(ctx sdk.Context) (commitments []types.PacketState) { +func (k *Keeper) GetAllPacketCommitments(ctx context.Context) (commitments []types.PacketState) { k.IteratePacketCommitment(ctx, func(portID, channelID string, sequence uint64, hash []byte) bool { pc := types.NewPacketState(portID, channelID, sequence, hash) commitments = append(commitments, pc) @@ -355,15 +377,15 @@ func (k *Keeper) GetAllPacketCommitments(ctx sdk.Context) (commitments []types.P // IteratePacketCommitmentAtChannel provides an iterator over all PacketCommmitment objects // at a specified channel. For each packet commitment, cb will be called. If the cb returns // true, the iterator will close and stop. -func (k *Keeper) IteratePacketCommitmentAtChannel(ctx sdk.Context, portID, channelID string, cb func(_, _ string, sequence uint64, hash []byte) bool) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) IteratePacketCommitmentAtChannel(ctx context.Context, portID, channelID string, cb func(_, _ string, sequence uint64, hash []byte) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, host.PacketCommitmentPrefixKey(portID, channelID)) k.iterateHashes(ctx, iterator, cb) } // GetAllPacketCommitmentsAtChannel returns all stored PacketCommitments objects for a specified // port ID and channel ID. -func (k *Keeper) GetAllPacketCommitmentsAtChannel(ctx sdk.Context, portID, channelID string) (commitments []types.PacketState) { +func (k *Keeper) GetAllPacketCommitmentsAtChannel(ctx context.Context, portID, channelID string) (commitments []types.PacketState) { k.IteratePacketCommitmentAtChannel(ctx, portID, channelID, func(_, _ string, sequence uint64, hash []byte) bool { pc := types.NewPacketState(portID, channelID, sequence, hash) commitments = append(commitments, pc) @@ -375,14 +397,14 @@ func (k *Keeper) GetAllPacketCommitmentsAtChannel(ctx sdk.Context, portID, chann // IteratePacketReceipt provides an iterator over all PacketReceipt objects. For each // receipt, cb will be called. If the cb returns true, the iterator will close // and stop. -func (k *Keeper) IteratePacketReceipt(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, receipt []byte) bool) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) IteratePacketReceipt(ctx context.Context, cb func(portID, channelID string, sequence uint64, receipt []byte) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyPacketReceiptPrefix)) k.iterateHashes(ctx, iterator, cb) } // GetAllPacketReceipts returns all stored PacketReceipt objects. -func (k *Keeper) GetAllPacketReceipts(ctx sdk.Context) (receipts []types.PacketState) { +func (k *Keeper) GetAllPacketReceipts(ctx context.Context) (receipts []types.PacketState) { k.IteratePacketReceipt(ctx, func(portID, channelID string, sequence uint64, receipt []byte) bool { packetReceipt := types.NewPacketState(portID, channelID, sequence, receipt) receipts = append(receipts, packetReceipt) @@ -394,14 +416,14 @@ func (k *Keeper) GetAllPacketReceipts(ctx sdk.Context) (receipts []types.PacketS // IteratePacketAcknowledgement provides an iterator over all PacketAcknowledgement objects. For each // acknowledgement, cb will be called. If the cb returns true, the iterator will close // and stop. -func (k *Keeper) IteratePacketAcknowledgement(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) IteratePacketAcknowledgement(ctx context.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyPacketAckPrefix)) k.iterateHashes(ctx, iterator, cb) } // GetAllPacketAcks returns all stored PacketAcknowledgements objects. -func (k *Keeper) GetAllPacketAcks(ctx sdk.Context) (acks []types.PacketState) { +func (k *Keeper) GetAllPacketAcks(ctx context.Context) (acks []types.PacketState) { k.IteratePacketAcknowledgement(ctx, func(portID, channelID string, sequence uint64, ack []byte) bool { packetAck := types.NewPacketState(portID, channelID, sequence, ack) acks = append(acks, packetAck) @@ -413,11 +435,11 @@ func (k *Keeper) GetAllPacketAcks(ctx sdk.Context) (acks []types.PacketState) { // IterateChannels provides an iterator over all Channel objects. For each // Channel, cb will be called. If the cb returns true, the iterator will close // and stop. -func (k *Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChannel) bool) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) IterateChannels(ctx context.Context, cb func(types.IdentifiedChannel) bool) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(host.KeyChannelEndPrefix)) - 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 channel types.Channel k.cdc.MustUnmarshal(iterator.Value(), &channel) @@ -432,13 +454,13 @@ func (k *Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChanne // GetAllChannelsWithPortPrefix returns all channels with the specified port prefix. If an empty prefix is provided // all channels will be returned. -func (k *Keeper) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []types.IdentifiedChannel { +func (k *Keeper) GetAllChannelsWithPortPrefix(ctx context.Context, portPrefix string) []types.IdentifiedChannel { if strings.TrimSpace(portPrefix) == "" { return k.GetAllChannels(ctx) } - store := ctx.KVStore(k.storeService) + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, types.FilteredPortPrefix(portPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var filteredChannels []types.IdentifiedChannel for ; iterator.Valid(); iterator.Next() { @@ -453,7 +475,7 @@ func (k *Keeper) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string } // GetAllChannels returns all stored Channel objects. -func (k *Keeper) GetAllChannels(ctx sdk.Context) (channels []types.IdentifiedChannel) { +func (k *Keeper) GetAllChannels(ctx context.Context) (channels []types.IdentifiedChannel) { k.IterateChannels(ctx, func(channel types.IdentifiedChannel) bool { channels = append(channels, channel) return false @@ -462,7 +484,7 @@ func (k *Keeper) GetAllChannels(ctx sdk.Context) (channels []types.IdentifiedCha } // GetChannelClientState returns the associated client state with its ID, from a port and channel identifier. -func (k *Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) (string, exported.ClientState, error) { +func (k *Keeper) GetChannelClientState(ctx context.Context, portID, channelID string) (string, exported.ClientState, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { return "", nil, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) @@ -482,7 +504,7 @@ func (k *Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string } // GetConnection wraps the connection keeper's GetConnection function. -func (k *Keeper) GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, error) { +func (k *Keeper) GetConnection(ctx context.Context, connectionID string) (connectiontypes.ConnectionEnd, error) { connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { return connectiontypes.ConnectionEnd{}, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) @@ -492,7 +514,7 @@ func (k *Keeper) GetConnection(ctx sdk.Context, connectionID string) (connection } // GetChannelConnection returns the connection ID and state associated with the given port and channel identifier. -func (k *Keeper) GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, connectiontypes.ConnectionEnd, error) { +func (k *Keeper) GetChannelConnection(ctx context.Context, portID, channelID string) (string, connectiontypes.ConnectionEnd, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { return "", connectiontypes.ConnectionEnd{}, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) @@ -509,8 +531,9 @@ func (k *Keeper) GetChannelConnection(ctx sdk.Context, portID, channelID string) } // 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 sdk.Context, portID, channelID string) (string, *capabilitytypes.Capability, error) { - modules, capability, err := k.scopedKeeper.LookupModules(ctx, host.ChannelCapabilityPath(portID, channelID)) +func (k *Keeper) LookupModuleByChannel(ctx context.Context, portID, channelID string) (string, *capabilitytypes.Capability, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + modules, capability, err := k.scopedKeeper.LookupModules(sdkCtx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { return "", nil, err } @@ -519,9 +542,12 @@ func (k *Keeper) LookupModuleByChannel(ctx sdk.Context, portID, channelID string } // GetUpgradeErrorReceipt returns the upgrade error receipt for the provided port and channel identifiers. -func (k *Keeper) GetUpgradeErrorReceipt(ctx sdk.Context, portID, channelID string) (types.ErrorReceipt, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.ChannelUpgradeErrorKey(portID, channelID)) +func (k *Keeper) GetUpgradeErrorReceipt(ctx context.Context, portID, channelID string) (types.ErrorReceipt, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.ChannelUpgradeErrorKey(portID, channelID)) + if err != nil { + return types.ErrorReceipt{}, false + } if bz == nil { return types.ErrorReceipt{}, false } @@ -533,22 +559,29 @@ func (k *Keeper) GetUpgradeErrorReceipt(ctx sdk.Context, portID, channelID strin } // setUpgradeErrorReceipt sets the provided error receipt in store using the port and channel identifiers. -func (k *Keeper) setUpgradeErrorReceipt(ctx sdk.Context, portID, channelID string, errorReceipt types.ErrorReceipt) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) setUpgradeErrorReceipt(ctx context.Context, portID, channelID string, errorReceipt types.ErrorReceipt) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&errorReceipt) store.Set(host.ChannelUpgradeErrorKey(portID, channelID), bz) } // hasUpgrade returns true if a proposed upgrade exists in store -func (k *Keeper) hasUpgrade(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeService) - return store.Has(host.ChannelUpgradeKey(portID, channelID)) +func (k *Keeper) hasUpgrade(ctx context.Context, portID, channelID string) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.ChannelUpgradeKey(portID, channelID)) + if err != nil { + panic(err) + } + return has } // GetUpgrade returns the proposed upgrade for the provided port and channel identifiers. -func (k *Keeper) GetUpgrade(ctx sdk.Context, portID, channelID string) (types.Upgrade, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.ChannelUpgradeKey(portID, channelID)) +func (k *Keeper) GetUpgrade(ctx context.Context, portID, channelID string) (types.Upgrade, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.ChannelUpgradeKey(portID, channelID)) + if err != nil { + return types.Upgrade{}, false + } if bz == nil { return types.Upgrade{}, false } @@ -560,28 +593,35 @@ func (k *Keeper) GetUpgrade(ctx sdk.Context, portID, channelID string) (types.Up } // SetUpgrade sets the proposed upgrade using the provided port and channel identifiers. -func (k *Keeper) SetUpgrade(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) SetUpgrade(ctx context.Context, portID, channelID string, upgrade types.Upgrade) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&upgrade) store.Set(host.ChannelUpgradeKey(portID, channelID), bz) } // deleteUpgrade deletes the upgrade for the provided port and channel identifiers. -func (k *Keeper) deleteUpgrade(ctx sdk.Context, portID, channelID string) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) deleteUpgrade(ctx context.Context, portID, channelID string) { + store := k.storeService.OpenKVStore(ctx) store.Delete(host.ChannelUpgradeKey(portID, channelID)) } // hasCounterpartyUpgrade returns true if a counterparty upgrade exists in store -func (k *Keeper) hasCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeService) - return store.Has(host.ChannelCounterpartyUpgradeKey(portID, channelID)) +func (k *Keeper) hasCounterpartyUpgrade(ctx context.Context, portID, channelID string) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.ChannelCounterpartyUpgradeKey(portID, channelID)) + if err != nil { + panic(err) + } + return has } // GetCounterpartyUpgrade gets the counterparty upgrade from the store. -func (k *Keeper) GetCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) (types.Upgrade, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.ChannelCounterpartyUpgradeKey(portID, channelID)) +func (k *Keeper) GetCounterpartyUpgrade(ctx context.Context, portID, channelID string) (types.Upgrade, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.ChannelCounterpartyUpgradeKey(portID, channelID)) + if err != nil { + return types.Upgrade{}, false + } if bz == nil { return types.Upgrade{}, false } @@ -593,35 +633,38 @@ func (k *Keeper) GetCounterpartyUpgrade(ctx sdk.Context, portID, channelID strin } // SetCounterpartyUpgrade sets the counterparty upgrade in the store. -func (k *Keeper) SetCounterpartyUpgrade(ctx sdk.Context, portID, channelID string, upgrade types.Upgrade) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) SetCounterpartyUpgrade(ctx context.Context, portID, channelID string, upgrade types.Upgrade) { + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&upgrade) store.Set(host.ChannelCounterpartyUpgradeKey(portID, channelID), bz) } // deleteCounterpartyUpgrade deletes the counterparty upgrade in the store. -func (k *Keeper) deleteCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) deleteCounterpartyUpgrade(ctx context.Context, portID, channelID string) { + store := k.storeService.OpenKVStore(ctx) store.Delete(host.ChannelCounterpartyUpgradeKey(portID, channelID)) } // deleteUpgradeInfo deletes all auxiliary upgrade information. -func (k *Keeper) deleteUpgradeInfo(ctx sdk.Context, portID, channelID string) { +func (k *Keeper) deleteUpgradeInfo(ctx context.Context, portID, channelID string) { k.deleteUpgrade(ctx, portID, channelID) k.deleteCounterpartyUpgrade(ctx, portID, channelID) } // SetParams sets the channel parameters. -func (k *Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := ctx.KVStore(k.storeService) +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) } // GetParams returns the total set of the channel parameters. -func (k *Keeper) GetParams(ctx sdk.Context) types.Params { - store := ctx.KVStore(k.storeService) - 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("channel params are not set in store")) } @@ -632,8 +675,8 @@ func (k *Keeper) GetParams(ctx sdk.Context) types.Params { } // common functionality for IteratePacketCommitment and IteratePacketAcknowledgement -func (Keeper) iterateHashes(ctx sdk.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) +func (k *Keeper) iterateHashes(ctx context.Context, iterator db.Iterator, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) for ; iterator.Valid(); iterator.Next() { keySplit := strings.Split(string(iterator.Key()), "/") @@ -653,16 +696,17 @@ func (Keeper) iterateHashes(ctx sdk.Context, iterator db.Iterator, cb func(portI // HasInflightPackets returns true if there are packet commitments stored at the specified // port and channel, and false otherwise. -func (k *Keeper) HasInflightPackets(ctx sdk.Context, portID, channelID string) bool { - iterator := storetypes.KVStorePrefixIterator(ctx.KVStore(k.storeService), host.PacketCommitmentPrefixKey(portID, channelID)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) +func (k *Keeper) HasInflightPackets(ctx context.Context, portID, channelID string) bool { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iterator := storetypes.KVStorePrefixIterator(store, host.PacketCommitmentPrefixKey(portID, channelID)) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) return iterator.Valid() } // setRecvStartSequence sets the channel's recv start sequence to the store. -func (k *Keeper) setRecvStartSequence(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) setRecvStartSequence(ctx context.Context, portID, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.RecvStartSequenceKey(portID, channelID), bz) } @@ -671,9 +715,12 @@ func (k *Keeper) setRecvStartSequence(ctx sdk.Context, portID, channelID string, // The recv start sequence will be set to the counterparty's next sequence send // upon a successful channel upgrade. It will be used for replay protection of // historical packets and as the upper bound for pruning stale packet receives. -func (k *Keeper) GetRecvStartSequence(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.RecvStartSequenceKey(portID, channelID)) +func (k *Keeper) GetRecvStartSequence(ctx context.Context, portID, channelID string) (uint64, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.RecvStartSequenceKey(portID, channelID)) + if err != nil { + return 0, false + } if len(bz) == 0 { return 0, false } @@ -682,16 +729,19 @@ func (k *Keeper) GetRecvStartSequence(ctx sdk.Context, portID, channelID string) } // SetPruningSequenceStart sets a channel's pruning sequence start to the store. -func (k *Keeper) SetPruningSequenceStart(ctx sdk.Context, portID, channelID string, sequence uint64) { - store := ctx.KVStore(k.storeService) +func (k *Keeper) SetPruningSequenceStart(ctx context.Context, portID, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(sequence) store.Set(host.PruningSequenceStartKey(portID, channelID), bz) } // GetPruningSequenceStart gets a channel's pruning sequence start from the store. -func (k *Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID string) (uint64, bool) { - store := ctx.KVStore(k.storeService) - bz := store.Get(host.PruningSequenceStartKey(portID, channelID)) +func (k *Keeper) GetPruningSequenceStart(ctx context.Context, portID, channelID string) (uint64, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(host.PruningSequenceStartKey(portID, channelID)) + if err != nil { + return 0, false + } if len(bz) == 0 { return 0, false } @@ -700,9 +750,14 @@ func (k *Keeper) GetPruningSequenceStart(ctx sdk.Context, portID, channelID stri } // HasPruningSequenceStart returns true if the pruning sequence start is set for the specified channel. -func (k *Keeper) HasPruningSequenceStart(ctx sdk.Context, portID, channelID string) bool { - store := ctx.KVStore(k.storeService) - return store.Has(host.PruningSequenceStartKey(portID, channelID)) +func (k *Keeper) HasPruningSequenceStart(ctx context.Context, portID, channelID string) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(host.PruningSequenceStartKey(portID, channelID)) + if err != nil { + panic(err) + } + return has + } // PruneAcknowledgements prunes packet acknowledgements and receipts that have a sequence number less than pruning sequence end. @@ -710,7 +765,7 @@ func (k *Keeper) HasPruningSequenceStart(ctx sdk.Context, portID, channelID stri // // Pruning sequence start keeps track of the packet ack/receipt that can be pruned next. When it reaches pruningSequenceEnd, // pruning is complete. -func (k *Keeper) PruneAcknowledgements(ctx sdk.Context, portID, channelID string, limit uint64) (uint64, uint64, error) { +func (k *Keeper) PruneAcknowledgements(ctx context.Context, portID, channelID string, limit uint64) (uint64, uint64, error) { pruningSequenceStart, found := k.GetPruningSequenceStart(ctx, portID, channelID) if !found { return 0, 0, errorsmod.Wrapf(types.ErrPruningSequenceStartNotFound, "port ID (%s) channel ID (%s)", portID, channelID) diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index c73ff4ce073..6a1eca8b771 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -2,6 +2,7 @@ package keeper import ( "bytes" + "context" "slices" "strconv" @@ -21,7 +22,7 @@ import ( // The packet sequence generated for the packet to be sent is returned. An error // is returned if one occurs. func (k *Keeper) SendPacket( - ctx sdk.Context, + ctx context.Context, channelCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, @@ -38,7 +39,8 @@ func (k *Keeper) SendPacket( return 0, errorsmod.Wrapf(types.ErrInvalidChannelState, "channel is not OPEN (got %s)", channel.State) } - if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + if !k.scopedKeeper.AuthenticateCapability(sdkCtx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) { return 0, errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } @@ -89,7 +91,7 @@ func (k *Keeper) SendPacket( k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1) k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) - emitSendPacketEvent(ctx, packet, channel, timeoutHeight) + emitSendPacketEvent(sdkCtx, packet, channel, timeoutHeight) k.Logger(ctx).Info( "packet sent", @@ -291,7 +293,7 @@ func (k *Keeper) applyReplayProtection(ctx sdk.Context, packet types.Packet, cha // 2) Assumes that packet receipt has been written (unordered), or nextSeqRecv was incremented (ordered) // previously by RecvPacket. func (k *Keeper) WriteAcknowledgement( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet exported.PacketI, acknowledgement exported.Acknowledgement, @@ -307,7 +309,8 @@ func (k *Keeper) WriteAcknowledgement( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + if !k.scopedKeeper.AuthenticateCapability(sdkCtx, chanCap, capName) { return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, @@ -356,7 +359,7 @@ func (k *Keeper) WriteAcknowledgement( "dst_channel", packet.GetDestChannel(), ) - emitWriteAcknowledgementEvent(ctx, packet.(types.Packet), channel, bz) + emitWriteAcknowledgementEvent(sdkCtx, packet.(types.Packet), channel, bz) return nil } diff --git a/modules/core/04-channel/types/expected_keepers.go b/modules/core/04-channel/types/expected_keepers.go index b1b39d977da..2c59a519c51 100644 --- a/modules/core/04-channel/types/expected_keepers.go +++ b/modules/core/04-channel/types/expected_keepers.go @@ -3,8 +3,6 @@ package types import ( context "context" - sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" @@ -22,9 +20,9 @@ type ClientKeeper interface { // ConnectionKeeper expected account IBC connection keeper type ConnectionKeeper interface { - GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, bool) + GetConnection(ctx context.Context, connectionID string) (connectiontypes.ConnectionEnd, bool) VerifyChannelState( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -33,7 +31,7 @@ type ConnectionKeeper interface { channel Channel, ) error VerifyPacketCommitment( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -43,7 +41,7 @@ type ConnectionKeeper interface { commitmentBytes []byte, ) error VerifyPacketAcknowledgement( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -53,7 +51,7 @@ type ConnectionKeeper interface { acknowledgement []byte, ) error VerifyPacketReceiptAbsence( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -62,7 +60,7 @@ type ConnectionKeeper interface { sequence uint64, ) error VerifyNextSequenceRecv( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -71,7 +69,7 @@ type ConnectionKeeper interface { nextSequenceRecv uint64, ) error VerifyChannelUpgrade( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -80,7 +78,7 @@ type ConnectionKeeper interface { upgrade Upgrade, ) error VerifyChannelUpgradeError( - ctx sdk.Context, + ctx context.Context, connection connectiontypes.ConnectionEnd, height exported.Height, proof []byte, @@ -92,5 +90,5 @@ type ConnectionKeeper interface { // PortKeeper expected account IBC port keeper type PortKeeper interface { - Authenticate(ctx sdk.Context, key *capabilitytypes.Capability, portID string) bool + Authenticate(ctx context.Context, key *capabilitytypes.Capability, portID string) bool } diff --git a/modules/core/05-port/keeper/keeper.go b/modules/core/05-port/keeper/keeper.go index c6310ed3d4c..47bafef3779 100644 --- a/modules/core/05-port/keeper/keeper.go +++ b/modules/core/05-port/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "cosmossdk.io/log" @@ -28,13 +29,15 @@ func NewKeeper(sck exported.ScopedKeeper) *Keeper { } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } // IsBound checks a given port ID is already bounded. -func (k *Keeper) IsBound(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) +func (k *Keeper) IsBound(ctx context.Context, portID string) bool { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + _, ok := k.scopedKeeper.GetCapability(sdkCtx, host.PortPath(portID)) return ok } @@ -42,7 +45,7 @@ func (k *Keeper) IsBound(ctx sdk.Context, portID string) bool { // Ports must be bound statically when the chain starts in `app.go`. // The capability must then be passed to a module which will need to pass // it as an extra parameter when calling functions on the IBC module. -func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { +func (k *Keeper) BindPort(ctx context.Context, portID string) *capabilitytypes.Capability { if err := host.PortIdentifierValidator(portID); err != nil { panic(err.Error()) } @@ -51,7 +54,9 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capab panic(fmt.Errorf("port %s is already bound", portID)) } - key, err := k.scopedKeeper.NewCapability(ctx, host.PortPath(portID)) + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + + key, err := k.scopedKeeper.NewCapability(sdkCtx, host.PortPath(portID)) if err != nil { panic(err.Error()) } @@ -64,17 +69,19 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capab // by checking if the memory address of the capability was previously // generated and bound to the port (provided as a parameter) which the capability // is being authenticated against. -func (k *Keeper) Authenticate(ctx sdk.Context, key *capabilitytypes.Capability, portID string) bool { +func (k *Keeper) Authenticate(ctx context.Context, key *capabilitytypes.Capability, portID string) bool { if err := host.PortIdentifierValidator(portID); err != nil { panic(err.Error()) } - return k.scopedKeeper.AuthenticateCapability(ctx, key, host.PortPath(portID)) + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + return k.scopedKeeper.AuthenticateCapability(sdkCtx, key, host.PortPath(portID)) } // LookupModuleByPort will return the IBCModule along with the capability associated with a given portID -func (k *Keeper) LookupModuleByPort(ctx sdk.Context, portID string) (string, *capabilitytypes.Capability, error) { - modules, capability, err := k.scopedKeeper.LookupModules(ctx, host.PortPath(portID)) +func (k *Keeper) LookupModuleByPort(ctx context.Context, portID string) (string, *capabilitytypes.Capability, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + modules, capability, err := k.scopedKeeper.LookupModules(sdkCtx, host.PortPath(portID)) if err != nil { return "", nil, err } diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index d1afbf5820e..95be6e32dbb 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -1,6 +1,8 @@ package types import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -163,7 +165,7 @@ type UpgradableModule interface { // ICS4Wrapper implements the ICS4 interfaces that IBC applications use to send packets and acknowledgements. type ICS4Wrapper interface { SendPacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, @@ -173,14 +175,14 @@ type ICS4Wrapper interface { ) (sequence uint64, err error) WriteAcknowledgement( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet exported.PacketI, ack exported.Acknowledgement, ) error GetAppVersion( - ctx sdk.Context, + ctx context.Context, portID, channelID string, ) (string, bool) diff --git a/modules/core/exported/expected_keepers.go b/modules/core/exported/expected_keepers.go index f1496c7f2b2..afd4bce4e56 100644 --- a/modules/core/exported/expected_keepers.go +++ b/modules/core/exported/expected_keepers.go @@ -2,7 +2,6 @@ package exported import ( sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ) diff --git a/modules/light-clients/06-solomachine/light_client_module.go b/modules/light-clients/06-solomachine/light_client_module.go index 8c4885c776a..2ac9d66cf22 100644 --- a/modules/light-clients/06-solomachine/light_client_module.go +++ b/modules/light-clients/06-solomachine/light_client_module.go @@ -1,12 +1,12 @@ package solomachine import ( + "context" "reflect" errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -30,7 +30,7 @@ func NewLightClientModule(cdc codec.BinaryCodec, storeProvider clienttypes.Store // Initialize unmarshals the provided client and consensus states and performs basic validation. It calls into the // clientState.Initialize method. -func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error { +func (l LightClientModule) Initialize(ctx context.Context, clientID string, clientStateBz, consensusStateBz []byte) error { var clientState ClientState if err := l.cdc.Unmarshal(clientStateBz, &clientState); err != nil { return err @@ -62,7 +62,7 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt } // VerifyClientMessage obtains the client state associated with the client identifier and calls into the clientState.VerifyClientMessage method. -func (l LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { +func (l LightClientModule) VerifyClientMessage(ctx context.Context, clientID string, clientMsg exported.ClientMessage) error { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -73,7 +73,7 @@ func (l LightClientModule) VerifyClientMessage(ctx sdk.Context, clientID string, } // CheckForMisbehaviour obtains the client state associated with the client identifier and calls into the clientState.CheckForMisbehaviour method. -func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) bool { +func (l LightClientModule) CheckForMisbehaviour(ctx context.Context, clientID string, clientMsg exported.ClientMessage) bool { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -86,7 +86,7 @@ func (l LightClientModule) CheckForMisbehaviour(ctx sdk.Context, clientID string // UpdateStateOnMisbehaviour updates state upon misbehaviour, freezing the ClientState. // This method should only be called when misbehaviour is detected as it does not perform // any misbehaviour checks. -func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) { +func (l LightClientModule) UpdateStateOnMisbehaviour(ctx context.Context, clientID string, clientMsg exported.ClientMessage) { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -98,7 +98,7 @@ func (l LightClientModule) UpdateStateOnMisbehaviour(ctx sdk.Context, clientID s } // UpdateState obtains the client state associated with the client identifier and calls into the clientState.UpdateState method. -func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { +func (l LightClientModule) UpdateState(ctx context.Context, clientID string, clientMsg exported.ClientMessage) []exported.Height { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -110,7 +110,7 @@ func (l LightClientModule) UpdateState(ctx sdk.Context, clientID string, clientM // VerifyMembership obtains the client state associated with the client identifier and calls into the clientState.verifyMembership method. func (l LightClientModule) VerifyMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, @@ -130,7 +130,7 @@ func (l LightClientModule) VerifyMembership( // VerifyNonMembership obtains the client state associated with the client identifier and calls into the clientState.verifyNonMembership method. func (l LightClientModule) VerifyNonMembership( - ctx sdk.Context, + ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, @@ -152,7 +152,7 @@ func (l LightClientModule) VerifyNonMembership( // - Active: if `IsFrozen` is false. // - Frozen: if `IsFrozen` is true. // - Unknown: if the client state associated with the provided client identifier is not found. -func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Status { +func (l LightClientModule) Status(ctx context.Context, clientID string) exported.Status { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -169,7 +169,7 @@ func (l LightClientModule) Status(ctx sdk.Context, clientID string) exported.Sta // LatestHeight returns the latest height for the client state for the given client identifier. // If no client is present for the provided client identifier a zero value height is returned. // NOTE: RevisionNumber is always 0 for solomachine client heights. -func (l LightClientModule) LatestHeight(ctx sdk.Context, clientID string) exported.Height { +func (l LightClientModule) LatestHeight(ctx context.Context, clientID string) exported.Height { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) @@ -181,7 +181,7 @@ func (l LightClientModule) LatestHeight(ctx sdk.Context, clientID string) export } // TimestampAtHeight obtains the client state associated with the client identifier and returns the timestamp in nanoseconds of the consensus state at the given height. -func (l LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, height exported.Height) (uint64, error) { +func (l LightClientModule) TimestampAtHeight(ctx context.Context, clientID string, height exported.Height) (uint64, error) { clientStore := l.storeProvider.ClientStore(ctx, clientID) clientState, found := getClientState(clientStore, l.cdc) if !found { @@ -193,7 +193,7 @@ func (l LightClientModule) TimestampAtHeight(ctx sdk.Context, clientID string, h // RecoverClient asserts that the substitute client is a solo machine client. It obtains the client state associated with the // subject client and calls into the subjectClientState.CheckSubstituteAndUpdateState method. -func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteClientID string) error { +func (l LightClientModule) RecoverClient(ctx context.Context, clientID, substituteClientID string) error { substituteClientType, _, err := clienttypes.ParseClientIdentifier(substituteClientID) if err != nil { return err @@ -219,6 +219,6 @@ func (l LightClientModule) RecoverClient(ctx sdk.Context, clientID, substituteCl } // VerifyUpgradeAndUpdateState returns an error since solomachine client does not support upgrades -func (LightClientModule) VerifyUpgradeAndUpdateState(ctx sdk.Context, clientID string, newClient, newConsState, upgradeClientProof, upgradeConsensusStateProof []byte) error { +func (LightClientModule) VerifyUpgradeAndUpdateState(ctx context.Context, clientID string, newClient, newConsState, upgradeClientProof, upgradeConsensusStateProof []byte) error { return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade solomachine client") } diff --git a/modules/light-clients/06-solomachine/misbehaviour_handle.go b/modules/light-clients/06-solomachine/misbehaviour_handle.go index 0b38a4cbc88..3987a4823b0 100644 --- a/modules/light-clients/06-solomachine/misbehaviour_handle.go +++ b/modules/light-clients/06-solomachine/misbehaviour_handle.go @@ -1,18 +1,19 @@ package solomachine import ( + "context" + errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) // CheckForMisbehaviour returns true for type Misbehaviour (passed VerifyClientMessage check), otherwise returns false -func (ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, clientMsg exported.ClientMessage) bool { +func (ClientState) CheckForMisbehaviour(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, clientMsg exported.ClientMessage) bool { if _, ok := clientMsg.(*Misbehaviour); ok { return true } diff --git a/modules/light-clients/06-solomachine/proposal_handle.go b/modules/light-clients/06-solomachine/proposal_handle.go index aae18d037c1..a1a89a84279 100644 --- a/modules/light-clients/06-solomachine/proposal_handle.go +++ b/modules/light-clients/06-solomachine/proposal_handle.go @@ -1,13 +1,13 @@ package solomachine import ( + "context" "reflect" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -21,7 +21,7 @@ import ( // the substitute is not a solo machine, or the current public key equals // the new public key. func (cs ClientState) CheckSubstituteAndUpdateState( - ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, + ctx context.Context, cdc codec.BinaryCodec, subjectClientStore, _ storetypes.KVStore, substituteClient exported.ClientState, ) error { substituteClientState, ok := substituteClient.(*ClientState) diff --git a/modules/light-clients/06-solomachine/update.go b/modules/light-clients/06-solomachine/update.go index ddc53dbb2d2..b3c1463028d 100644 --- a/modules/light-clients/06-solomachine/update.go +++ b/modules/light-clients/06-solomachine/update.go @@ -1,11 +1,12 @@ package solomachine import ( + "context" + errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -14,7 +15,7 @@ import ( // VerifyClientMessage introspects the provided ClientMessage and checks its validity // A Solomachine Header is considered valid if the currently registered public key has signed over the new public key with the correct sequence // A Solomachine Misbehaviour is considered valid if duplicate signatures of the current public key are found on two different messages at a given sequence -func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) error { +func (cs ClientState) VerifyClientMessage(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) error { switch msg := clientMsg.(type) { case *Header: return cs.verifyHeader(cdc, msg) @@ -78,7 +79,7 @@ func (cs ClientState) verifyHeader(cdc codec.BinaryCodec, header *Header) error // UpdateState updates the consensus state to the new public key and an incremented sequence. // A list containing the updated consensus height is returned. // If the provided clientMsg is not of type Header, the handler will no-op and return an empty slice. -func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height { +func (cs ClientState) UpdateState(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height { smHeader, ok := clientMsg.(*Header) if !ok { // clientMsg is invalid Misbehaviour, no update necessary diff --git a/modules/light-clients/07-tendermint/client_state.go b/modules/light-clients/07-tendermint/client_state.go index 2e5becea74f..e60a07de19c 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -1,6 +1,7 @@ package tendermint import ( + "context" "strings" "time" @@ -77,7 +78,7 @@ func (ClientState) getTimestampAtHeight( // A frozen client will become expired, so the Frozen status // has higher precedence. func (cs ClientState) status( - ctx sdk.Context, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, ) exported.Status { @@ -93,7 +94,8 @@ func (cs ClientState) status( return exported.Expired } - if cs.IsExpired(consState.Timestamp, ctx.BlockTime()) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + if cs.IsExpired(consState.Timestamp, sdkCtx.BlockTime()) { return exported.Expired } @@ -186,7 +188,7 @@ func (cs ClientState) ZeroCustomFields() *ClientState { // initialize checks that the initial consensus state is an 07-tendermint consensus state and // sets the client state, consensus state and associated metadata in the provided client store. -func (cs ClientState) initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, consState exported.ConsensusState) error { +func (cs ClientState) initialize(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, consState exported.ConsensusState) error { consensusState, ok := consState.(*ConsensusState) if !ok { return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", @@ -204,7 +206,7 @@ func (cs ClientState) initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientS // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). // If a zero proof height is passed in, it will fail to retrieve the associated consensus state. func (cs ClientState) verifyMembership( - ctx sdk.Context, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, height exported.Height, @@ -247,7 +249,7 @@ func (cs ClientState) verifyMembership( // The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). // If a zero proof height is passed in, it will fail to retrieve the associated consensus state. func (cs ClientState) verifyNonMembership( - ctx sdk.Context, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, height exported.Height, @@ -287,7 +289,7 @@ func (cs ClientState) verifyNonMembership( // verifyDelayPeriodPassed will ensure that at least delayTimePeriod amount of time and delayBlockPeriod number of blocks have passed // since consensus state was submitted before allowing verification to continue. -func verifyDelayPeriodPassed(ctx sdk.Context, store storetypes.KVStore, proofHeight exported.Height, delayTimePeriod, delayBlockPeriod uint64) error { +func verifyDelayPeriodPassed(ctx context.Context, store storetypes.KVStore, proofHeight exported.Height, delayTimePeriod, delayBlockPeriod uint64) error { if delayTimePeriod != 0 { // check that executing chain's timestamp has passed consensusState's processed time + delay time period processedTime, ok := GetProcessedTime(store, proofHeight) @@ -295,7 +297,8 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store storetypes.KVStore, proofHei return errorsmod.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) } - currentTimestamp := uint64(ctx.BlockTime().UnixNano()) + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + currentTimestamp := uint64(sdkCtx.BlockTime().UnixNano()) validTime := processedTime + delayTimePeriod // NOTE: delay time period is inclusive, so if currentTimestamp is validTime, then we return no error diff --git a/modules/light-clients/07-tendermint/light_client_module.go b/modules/light-clients/07-tendermint/light_client_module.go index 2b45ba7d917..98f8552c8df 100644 --- a/modules/light-clients/07-tendermint/light_client_module.go +++ b/modules/light-clients/07-tendermint/light_client_module.go @@ -7,6 +7,7 @@ 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" @@ -63,7 +64,8 @@ func (l LightClientModule) VerifyClientMessage(ctx context.Context, clientID str return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } - return clientState.VerifyClientMessage(ctx, l.cdc, clientStore, clientMsg) + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + return clientState.VerifyClientMessage(sdkCtx, 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/07-tendermint/misbehaviour_handle.go b/modules/light-clients/07-tendermint/misbehaviour_handle.go index 11f5762b47e..c9fad90dbaa 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_handle.go +++ b/modules/light-clients/07-tendermint/misbehaviour_handle.go @@ -2,6 +2,7 @@ package tendermint import ( "bytes" + "context" "reflect" "time" @@ -19,7 +20,7 @@ import ( // CheckForMisbehaviour detects duplicate height misbehaviour and BFT time violation misbehaviour // in a submitted Header message and verifies the correctness of a submitted Misbehaviour ClientMessage -func (ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, msg exported.ClientMessage) bool { +func (ClientState) CheckForMisbehaviour(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, msg exported.ClientMessage) bool { switch msg := msg.(type) { case *Header: tmHeader := msg @@ -90,7 +91,7 @@ func (ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, // Similarly, consensusState2 is the trusted consensus state that corresponds // to misbehaviour.Header2 // Misbehaviour sets frozen height to {0, 1} since it is only used as a boolean value (zero or non-zero). -func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, misbehaviour *Misbehaviour) error { +func (cs *ClientState) verifyMisbehaviour(ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, misbehaviour *Misbehaviour) error { // Regardless of the type of misbehaviour, ensure that both headers are valid and would have been accepted by light-client // Retrieve trusted consensus states for each Header in misbehaviour @@ -109,13 +110,14 @@ func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore storetype // NOTE: header height and commitment root assertions are checked in // misbehaviour.ValidateBasic by the client keeper and msg.ValidateBasic // by the base application. + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC if err := checkMisbehaviourHeader( - cs, tmConsensusState1, misbehaviour.Header1, ctx.BlockTime(), + cs, tmConsensusState1, misbehaviour.Header1, sdkCtx.BlockTime(), ); err != nil { return errorsmod.Wrap(err, "verifying Header1 in Misbehaviour failed") } if err := checkMisbehaviourHeader( - cs, tmConsensusState2, misbehaviour.Header2, ctx.BlockTime(), + cs, tmConsensusState2, misbehaviour.Header2, sdkCtx.BlockTime(), ); err != nil { return errorsmod.Wrap(err, "verifying Header2 in Misbehaviour failed") } diff --git a/modules/light-clients/07-tendermint/proposal_handle.go b/modules/light-clients/07-tendermint/proposal_handle.go index 60f8ea4ac8b..ae83014cfec 100644 --- a/modules/light-clients/07-tendermint/proposal_handle.go +++ b/modules/light-clients/07-tendermint/proposal_handle.go @@ -1,6 +1,7 @@ package tendermint import ( + "context" "reflect" "time" @@ -8,7 +9,6 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -27,7 +27,7 @@ import ( // In case 1) before updating the client, the client will be unfrozen by resetting // the FrozenHeight to the zero Height. func (cs ClientState) CheckSubstituteAndUpdateState( - ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, + ctx context.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore storetypes.KVStore, substituteClient exported.ClientState, ) error { substituteClientState, ok := substituteClient.(*ClientState) diff --git a/modules/light-clients/07-tendermint/store.go b/modules/light-clients/07-tendermint/store.go index 823ad4c55d8..8366429785a 100644 --- a/modules/light-clients/07-tendermint/store.go +++ b/modules/light-clients/07-tendermint/store.go @@ -2,6 +2,7 @@ package tendermint import ( "bytes" + "context" "encoding/binary" "fmt" @@ -322,8 +323,9 @@ func bigEndianHeightBytes(height exported.Height) []byte { // as this is internal tendermint light client logic. // client state and consensus state will be set by client keeper // set iteration key to provide ability for efficient ordered iteration of consensus states. -func setConsensusMetadata(ctx sdk.Context, clientStore storetypes.KVStore, height exported.Height) { - setConsensusMetadataWithValues(clientStore, height, clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano())) +func setConsensusMetadata(ctx context.Context, clientStore storetypes.KVStore, height exported.Height) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + setConsensusMetadataWithValues(clientStore, height, clienttypes.GetSelfHeight(ctx), uint64(sdkCtx.BlockTime().UnixNano())) } // setConsensusMetadataWithValues sets the consensus metadata with the provided values diff --git a/modules/light-clients/07-tendermint/update.go b/modules/light-clients/07-tendermint/update.go index aa9d03cead6..fcb79909aef 100644 --- a/modules/light-clients/07-tendermint/update.go +++ b/modules/light-clients/07-tendermint/update.go @@ -2,6 +2,7 @@ package tendermint import ( "bytes" + "context" "fmt" errorsmod "cosmossdk.io/errors" @@ -21,7 +22,7 @@ import ( // VerifyClientMessage checks if the clientMessage is of type Header or Misbehaviour and verifies the message func (cs *ClientState) VerifyClientMessage( - ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, + ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage, ) error { switch msg := clientMsg.(type) { @@ -43,10 +44,11 @@ func (cs *ClientState) VerifyClientMessage( // - header timestamp is past the trusting period in relation to the consensus state // - header timestamp is less than or equal to the consensus state timestamp func (cs *ClientState) verifyHeader( - ctx sdk.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, + ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec, header *Header, ) error { - currentTimestamp := ctx.BlockTime() + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + currentTimestamp := sdkCtx.BlockTime() // Retrieve trusted consensus states for each Header in misbehaviour consState, found := GetConsensusState(clientStore, cdc, header.TrustedHeight) @@ -132,7 +134,7 @@ func (cs *ClientState) verifyHeader( // number must be the same. To update to a new revision, use a separate upgrade path // UpdateState will prune the oldest consensus state if it is expired. // If the provided clientMsg is not of type of Header then the handler will noop and empty slice is returned. -func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height { +func (cs ClientState) UpdateState(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, clientMsg exported.ClientMessage) []exported.Height { header, ok := clientMsg.(*Header) if !ok { // clientMsg is invalid Misbehaviour, no update necessary @@ -141,7 +143,8 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client // performance: do not prune in checkTx // simulation must prune for accurate gas estimation - if (!ctx.IsCheckTx() && !ctx.IsReCheckTx()) || ctx.ExecMode() == sdk.ExecModeSimulate { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + if (!sdkCtx.IsCheckTx() && !sdkCtx.IsReCheckTx()) || sdkCtx.ExecMode() == sdk.ExecModeSimulate { cs.pruneOldestConsensusState(ctx, cdc, clientStore) } @@ -176,7 +179,7 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client // pruneOldestConsensusState will retrieve the earliest consensus state for this clientID and check if it is expired. If it is, // that consensus state will be pruned from store along with all associated metadata. This will prevent the client store from // becoming bloated with expired consensus states that can no longer be used for updates and packet verification. -func (cs ClientState) pruneOldestConsensusState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore) { +func (cs ClientState) pruneOldestConsensusState(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore) { // Check the earliest consensus state to see if it is expired, if so then set the prune height // so that we can delete consensus state and all associated metadata. var ( @@ -190,7 +193,8 @@ func (cs ClientState) pruneOldestConsensusState(ctx sdk.Context, cdc codec.Binar panic(errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "failed to retrieve consensus state at height: %s", height)) } - if cs.IsExpired(consState.Timestamp, ctx.BlockTime()) { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + if cs.IsExpired(consState.Timestamp, sdkCtx.BlockTime()) { pruneHeight = height } @@ -208,7 +212,7 @@ func (cs ClientState) pruneOldestConsensusState(ctx sdk.Context, cdc codec.Binar // UpdateStateOnMisbehaviour updates state upon misbehaviour, freezing the ClientState. This method should only be called when misbehaviour is detected // as it does not perform any misbehaviour checks. -func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, _ exported.ClientMessage) { +func (cs ClientState) UpdateStateOnMisbehaviour(ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, _ exported.ClientMessage) { cs.FrozenHeight = FrozenHeight clientStore.Set(host.ClientStateKey(), clienttypes.MustMarshalClientState(cdc, &cs)) diff --git a/modules/light-clients/07-tendermint/upgrade.go b/modules/light-clients/07-tendermint/upgrade.go index 398b6652a75..9148b4f7c77 100644 --- a/modules/light-clients/07-tendermint/upgrade.go +++ b/modules/light-clients/07-tendermint/upgrade.go @@ -1,6 +1,7 @@ package tendermint import ( + "context" "fmt" errorsmod "cosmossdk.io/errors" @@ -8,7 +9,6 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" "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" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" @@ -28,7 +28,7 @@ import ( // - any Tendermint chain specified parameter in upgraded client such as ChainID, UnbondingPeriod, // and ProofSpecs do not match parameters set by committed client func (cs ClientState) VerifyUpgradeAndUpdateState( - ctx sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, + ctx context.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, upgradedClient exported.ClientState, upgradedConsState exported.ConsensusState, upgradeClientProof, upgradeConsStateProof []byte, ) error { diff --git a/simapp/app.go b/simapp/app.go index c40fc75e681..cbb581e51fd 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -404,7 +404,7 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) govConfig := govtypes.DefaultConfig() From 0be258a1c0c45db025c07b097fe711ecb365d2de Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 7 Aug 2024 14:34:40 +0200 Subject: [PATCH 06/19] ++fafo --- .../controller/ibc_middleware.go | 6 +- .../controller/keeper/keeper.go | 3 +- .../27-interchain-accounts/host/ibc_module.go | 3 +- .../host/keeper/keeper.go | 3 +- .../types/expected_keepers.go | 12 +- modules/apps/29-fee/ibc_middleware.go | 9 +- modules/apps/29-fee/keeper/grpc_query.go | 16 +-- modules/apps/29-fee/keeper/keeper.go | 136 +++++++++++------- modules/apps/29-fee/keeper/migrations.go | 3 +- modules/apps/transfer/ibc_module.go | 3 +- .../apps/transfer/types/expected_keepers.go | 10 +- .../02-client/migrations/v7/genesis_test.go | 5 +- .../02-client/migrations/v7/store_test.go | 7 +- modules/core/02-client/types/router_test.go | 5 +- modules/core/03-connection/keeper/verify.go | 19 +-- modules/core/05-port/types/module.go | 2 +- modules/core/keeper/keeper_test.go | 5 +- modules/core/migrations/v7/genesis_test.go | 5 +- .../migrations/expected_keepers.go | 12 +- simapp/app.go | 2 +- testing/mock/ibc_module.go | 3 +- testing/mock/middleware.go | 7 +- testing/mock/mock.go | 5 +- testing/simapp/app.go | 2 +- 24 files changed, 164 insertions(+), 119 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 439b6641196..05dd4cb3177 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -338,7 +338,7 @@ func (IBCMiddleware) SendPacket( // WriteAcknowledgement implements the ICS4 Wrapper interface func (IBCMiddleware) WriteAcknowledgement( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, ack ibcexported.Acknowledgement, @@ -347,14 +347,14 @@ func (IBCMiddleware) WriteAcknowledgement( } // GetAppVersion returns the interchain accounts metadata. -func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (im IBCMiddleware) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { return im.keeper.GetAppVersion(ctx, portID, channelID) } // UnmarshalPacketData attempts to unmarshal the provided packet data bytes // into an InterchainAccountPacketData. This function implements the optional // PacketDataUnmarshaler interface required for ADR 008 support. -func (im IBCMiddleware) UnmarshalPacketData(ctx sdk.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { +func (im IBCMiddleware) UnmarshalPacketData(ctx context.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { var data icatypes.InterchainAccountPacketData err := data.UnmarshalJSON(bz) if err != nil { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 09d751b00bb..46b040c4568 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "bytes" + "context" "errors" "fmt" "strings" @@ -130,7 +131,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. -func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (k Keeper) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { return k.ics4Wrapper.GetAppVersion(ctx, portID, channelID) } diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 65af63a3a30..752b4b9d5c7 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -1,6 +1,7 @@ package host import ( + "context" "fmt" errorsmod "cosmossdk.io/errors" @@ -186,7 +187,7 @@ func (IBCModule) OnChanUpgradeOpen(_ sdk.Context, _, _ string, _ channeltypes.Or // UnmarshalPacketData attempts to unmarshal the provided packet data bytes // into an InterchainAccountPacketData. This function implements the optional // PacketDataUnmarshaler interface required for ADR 008 support. -func (im IBCModule) UnmarshalPacketData(ctx sdk.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { +func (im IBCModule) UnmarshalPacketData(ctx context.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { var data icatypes.InterchainAccountPacketData err := data.UnmarshalJSON(bz) if err != nil { diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 50e7414939b..86fb5f7accf 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "errors" "fmt" "strings" @@ -135,7 +136,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. -func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (k Keeper) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { return k.ics4Wrapper.GetAppVersion(ctx, portID, channelID) } diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index 2a93fafaa92..3c65541acd3 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -22,16 +22,16 @@ type AccountKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) - GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) - GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, error) - GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel + GetChannel(ctx context.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx context.Context, portID, channelID string) (uint64, bool) + GetConnection(ctx context.Context, connectionID string) (connectiontypes.ConnectionEnd, error) + GetAllChannelsWithPortPrefix(ctx context.Context, portPrefix string) []channeltypes.IdentifiedChannel } // PortKeeper defines the expected IBC port keeper type PortKeeper interface { - BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability - IsBound(ctx sdk.Context, portID string) bool + BindPort(ctx context.Context, portID string) *capabilitytypes.Capability + IsBound(ctx context.Context, portID string) bool } // ParamSubspace defines the expected Subspace interface for module parameters. diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index dce52a87cdc..850caec1e92 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -1,6 +1,7 @@ package fee import ( + "context" "encoding/json" "strings" @@ -457,7 +458,7 @@ func (im IBCMiddleware) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID str // SendPacket implements the ICS4 Wrapper interface func (im IBCMiddleware) SendPacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, @@ -470,7 +471,7 @@ func (im IBCMiddleware) SendPacket( // WriteAcknowledgement implements the ICS4 Wrapper interface func (im IBCMiddleware) WriteAcknowledgement( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet exported.PacketI, ack exported.Acknowledgement, @@ -479,14 +480,14 @@ func (im IBCMiddleware) WriteAcknowledgement( } // GetAppVersion returns the application version of the underlying application -func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (im IBCMiddleware) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { return im.keeper.GetAppVersion(ctx, portID, channelID) } // UnmarshalPacketData attempts to use the underlying app to unmarshal the packet data. // If the underlying app does not support the PacketDataUnmarshaler interface, an error is returned. // This function implements the optional PacketDataUnmarshaler interface required for ADR 008 support. -func (im IBCMiddleware) UnmarshalPacketData(ctx sdk.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { +func (im IBCMiddleware) UnmarshalPacketData(ctx context.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { unmarshaler, ok := im.app.(porttypes.PacketDataUnmarshaler) if !ok { return nil, "", errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement %T", (*porttypes.PacketDataUnmarshaler)(nil)) diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index 0e0948c4639..cd6a0e05f33 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -9,6 +9,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" @@ -20,15 +21,14 @@ import ( var _ types.QueryServer = (*Keeper)(nil) // IncentivizedPackets implements the Query/IncentivizedPackets gRPC method -func (k Keeper) IncentivizedPackets(goCtx context.Context, req *types.QueryIncentivizedPacketsRequest) (*types.QueryIncentivizedPacketsResponse, error) { +func (k Keeper) IncentivizedPackets(ctx context.Context, req *types.QueryIncentivizedPacketsRequest) (*types.QueryIncentivizedPacketsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - ctx := sdk.UnwrapSDKContext(goCtx).WithBlockHeight(int64(req.QueryHeight)) - var identifiedPackets []types.IdentifiedPacketFees - store := prefix.NewStore(ctx.KVStore(k.storeService), []byte(types.FeesInEscrowPrefix)) + + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), []byte(types.FeesInEscrowPrefix)) pagination, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { packetID, err := types.ParseKeyFeesInEscrow(types.FeesInEscrowPrefix + string(key)) if err != nil { @@ -90,7 +90,7 @@ func (k Keeper) IncentivizedPacketsForChannel(goCtx context.Context, req *types. var packets []*types.IdentifiedPacketFees keyPrefix := types.KeyFeesInEscrowChannelPrefix(req.PortId, req.ChannelId) - store := prefix.NewStore(ctx.KVStore(k.storeService), keyPrefix) + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), keyPrefix) pagination, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { packetID, err := types.ParseKeyFeesInEscrow(string(keyPrefix) + string(key)) if err != nil { @@ -229,15 +229,13 @@ func (k Keeper) CounterpartyPayee(goCtx context.Context, req *types.QueryCounter } // FeeEnabledChannels implements the Query/FeeEnabledChannels gRPC method and returns a list of fee enabled channels -func (k Keeper) FeeEnabledChannels(goCtx context.Context, req *types.QueryFeeEnabledChannelsRequest) (*types.QueryFeeEnabledChannelsResponse, error) { +func (k Keeper) FeeEnabledChannels(ctx context.Context, req *types.QueryFeeEnabledChannelsRequest) (*types.QueryFeeEnabledChannelsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - ctx := sdk.UnwrapSDKContext(goCtx).WithBlockHeight(int64(req.QueryHeight)) - var feeEnabledChannels []types.FeeEnabledChannel - store := prefix.NewStore(ctx.KVStore(k.storeService), []byte(types.FeeEnabledKeyPrefix)) + store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), []byte(types.FeeEnabledKeyPrefix)) pagination, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { portID, channelID, err := types.ParseKeyFeeEnabled(types.FeeEnabledKeyPrefix + string(key)) if err != nil { diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 59c44f08e3c..d4136d675bd 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -67,33 +67,34 @@ func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper { } // Logger returns a module-specific logger. -func (Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+ibcexported.ModuleName+"-"+types.ModuleName) +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + return sdkCtx.Logger().With("module", "x/"+ibcexported.ModuleName+"-"+types.ModuleName) } // 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) *capabilitytypes.Capability { +func (k Keeper) BindPort(ctx context.Context, portID string) *capabilitytypes.Capability { return k.portKeeper.BindPort(ctx, portID) } // GetChannel wraps IBC ChannelKeeper's GetChannel function -func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool) { +func (k Keeper) GetChannel(ctx context.Context, portID, channelID string) (channeltypes.Channel, bool) { return k.channelKeeper.GetChannel(ctx, portID, channelID) } // HasChannel returns true if the channel with the given identifiers exists in state. -func (k Keeper) HasChannel(ctx sdk.Context, portID, channelID string) bool { +func (k Keeper) HasChannel(ctx context.Context, portID, channelID string) bool { return k.channelKeeper.HasChannel(ctx, portID, channelID) } // GetPacketCommitment wraps IBC ChannelKeeper's GetPacketCommitment function -func (k Keeper) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte { +func (k Keeper) GetPacketCommitment(ctx context.Context, portID, channelID string, sequence uint64) []byte { return k.channelKeeper.GetPacketCommitment(ctx, portID, channelID, sequence) } // GetNextSequenceSend wraps IBC ChannelKeeper's GetNextSequenceSend function -func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { +func (k Keeper) GetNextSequenceSend(ctx context.Context, portID, channelID string) (uint64, bool) { return k.channelKeeper.GetNextSequenceSend(ctx, portID, channelID) } @@ -103,7 +104,7 @@ func (k Keeper) GetFeeModuleAddress() sdk.AccAddress { } // EscrowAccountHasBalance verifies if the escrow account has the provided fee. -func (k Keeper) EscrowAccountHasBalance(ctx sdk.Context, coins sdk.Coins) bool { +func (k Keeper) EscrowAccountHasBalance(ctx context.Context, coins sdk.Coins) bool { for _, coin := range coins { if !k.bankKeeper.HasBalance(ctx, k.GetFeeModuleAddress(), coin) { return false @@ -116,14 +117,14 @@ func (k Keeper) EscrowAccountHasBalance(ctx sdk.Context, coins sdk.Coins) bool { // lockFeeModule sets a flag to determine if fee handling logic should run for the given channel // identified by channel and port identifiers. // Please see ADR 004 for more information. -func (k Keeper) lockFeeModule(ctx sdk.Context) { +func (k Keeper) lockFeeModule(ctx context.Context) { store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyLocked(), []byte{1}) } // IsLocked indicates if the fee module is locked // Please see ADR 004 for more information. -func (k Keeper) IsLocked(ctx sdk.Context) bool { +func (k Keeper) IsLocked(ctx context.Context) bool { store := k.storeService.OpenKVStore(ctx) has, err := store.Has(types.KeyLocked()) if err != nil { @@ -134,13 +135,13 @@ func (k Keeper) IsLocked(ctx sdk.Context) bool { // SetFeeEnabled sets a flag to determine if fee handling logic should run for the given channel // identified by channel and port identifiers. -func (k Keeper) SetFeeEnabled(ctx sdk.Context, portID, channelID string) { +func (k Keeper) SetFeeEnabled(ctx context.Context, portID, channelID string) { store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyFeeEnabled(portID, channelID), []byte{1}) } // DeleteFeeEnabled deletes the fee enabled flag for a given portID and channelID -func (k Keeper) DeleteFeeEnabled(ctx sdk.Context, portID, channelID string) { +func (k Keeper) DeleteFeeEnabled(ctx context.Context, portID, channelID string) { store := k.storeService.OpenKVStore(ctx) store.Delete(types.KeyFeeEnabled(portID, channelID)) } @@ -157,10 +158,10 @@ func (k Keeper) IsFeeEnabled(ctx context.Context, portID, channelID string) bool } // GetAllFeeEnabledChannels returns a list of all ics29 enabled channels containing portID & channelID that are stored in state -func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []types.FeeEnabledChannel { +func (k Keeper) GetAllFeeEnabledChannels(ctx context.Context) []types.FeeEnabledChannel { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeeEnabledKeyPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var enabledChArr []types.FeeEnabledChannel for ; iterator.Valid(); iterator.Next() { @@ -180,28 +181,37 @@ func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []types.FeeEnabledChan } // GetPayeeAddress retrieves the fee payee address stored in state given the provided channel identifier and relayer address -func (k Keeper) GetPayeeAddress(ctx sdk.Context, relayerAddr, channelID string) (string, bool) { +func (k Keeper) GetPayeeAddress(ctx context.Context, relayerAddr, channelID string) (string, bool) { store := k.storeService.OpenKVStore(ctx) key := types.KeyPayee(relayerAddr, channelID) - if !store.Has(key) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { return "", false } - return string(store.Get(key)), true + bz, err := store.Get(key) + if err != nil { + panic(err) + } + + return string(bz), true } // SetPayeeAddress stores the fee payee address in state keyed by the provided channel identifier and relayer address -func (k Keeper) SetPayeeAddress(ctx sdk.Context, relayerAddr, payeeAddr, channelID string) { +func (k Keeper) SetPayeeAddress(ctx context.Context, relayerAddr, payeeAddr, channelID string) { store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyPayee(relayerAddr, channelID), []byte(payeeAddr)) } // GetAllPayees returns all registered payees addresses -func (k Keeper) GetAllPayees(ctx sdk.Context) []types.RegisteredPayee { +func (k Keeper) GetAllPayees(ctx context.Context) []types.RegisteredPayee { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.PayeeKeyPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var registeredPayees []types.RegisteredPayee for ; iterator.Valid(); iterator.Next() { @@ -224,29 +234,36 @@ func (k Keeper) GetAllPayees(ctx sdk.Context) []types.RegisteredPayee { // SetCounterpartyPayeeAddress maps the destination chain counterparty payee address to the source relayer address // The receiving chain must store the mapping from: address -> counterpartyPayeeAddress for the given channel -func (k Keeper) SetCounterpartyPayeeAddress(ctx sdk.Context, address, counterpartyAddress, channelID string) { +func (k Keeper) SetCounterpartyPayeeAddress(ctx context.Context, address, counterpartyAddress, channelID string) { store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyCounterpartyPayee(address, channelID), []byte(counterpartyAddress)) } // GetCounterpartyPayeeAddress gets the counterparty payee address given a destination relayer address -func (k Keeper) GetCounterpartyPayeeAddress(ctx sdk.Context, address, channelID string) (string, bool) { +func (k Keeper) GetCounterpartyPayeeAddress(ctx context.Context, address, channelID string) (string, bool) { store := k.storeService.OpenKVStore(ctx) key := types.KeyCounterpartyPayee(address, channelID) - if !store.Has(key) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { return "", false } - addr := string(store.Get(key)) - return addr, true + addr, err := store.Get(key) + if err != nil { + panic(err) + } + return string(addr), true // TODO: why this cast? } // GetAllCounterpartyPayees returns all registered counterparty payee addresses -func (k Keeper) GetAllCounterpartyPayees(ctx sdk.Context) []types.RegisteredCounterpartyPayee { +func (k Keeper) GetAllCounterpartyPayees(ctx context.Context) []types.RegisteredCounterpartyPayee { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.CounterpartyPayeeKeyPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var registeredCounterpartyPayees []types.RegisteredCounterpartyPayee for ; iterator.Valid(); iterator.Next() { @@ -268,28 +285,37 @@ func (k Keeper) GetAllCounterpartyPayees(ctx sdk.Context) []types.RegisteredCoun } // SetRelayerAddressForAsyncAck sets the forward relayer address during OnRecvPacket in case of async acknowledgement -func (k Keeper) SetRelayerAddressForAsyncAck(ctx sdk.Context, packetID channeltypes.PacketId, address string) { - store := ctx.KVStore(k.storeService) +func (k Keeper) SetRelayerAddressForAsyncAck(ctx context.Context, packetID channeltypes.PacketId, address string) { + store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyRelayerAddressForAsyncAck(packetID), []byte(address)) } // GetRelayerAddressForAsyncAck gets forward relayer address for a particular packet func (k Keeper) GetRelayerAddressForAsyncAck(ctx context.Context, packetID channeltypes.PacketId) (string, bool) { - store := ctx.KVStore(k.storeService) + store := k.storeService.OpenKVStore(ctx) key := types.KeyRelayerAddressForAsyncAck(packetID) - if !store.Has(key) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { + return "", false } - addr := string(store.Get(key)) - return addr, true + addr, err := store.Get(key) + if err != nil { + panic(err) + } + + return string(addr), true } // GetAllForwardRelayerAddresses returns all forward relayer addresses stored for async acknowledgements -func (k Keeper) GetAllForwardRelayerAddresses(ctx sdk.Context) []types.ForwardRelayerAddress { +func (k Keeper) GetAllForwardRelayerAddresses(ctx context.Context) []types.ForwardRelayerAddress { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.ForwardRelayerPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var forwardRelayerAddr []types.ForwardRelayerAddress for ; iterator.Valid(); iterator.Next() { @@ -310,17 +336,20 @@ func (k Keeper) GetAllForwardRelayerAddresses(ctx sdk.Context) []types.ForwardRe } // DeleteForwardRelayerAddress deletes the forwardRelayerAddr associated with the packetID -func (k Keeper) DeleteForwardRelayerAddress(ctx sdk.Context, packetID channeltypes.PacketId) { - store := ctx.KVStore(k.storeService) +func (k Keeper) DeleteForwardRelayerAddress(ctx context.Context, packetID channeltypes.PacketId) { + store := k.storeService.OpenKVStore(ctx) key := types.KeyRelayerAddressForAsyncAck(packetID) store.Delete(key) } // GetFeesInEscrow returns all escrowed packet fees for a given packetID -func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) (types.PacketFees, bool) { - store := ctx.KVStore(k.storeService) +func (k Keeper) GetFeesInEscrow(ctx context.Context, packetID channeltypes.PacketId) (types.PacketFees, bool) { + store := k.storeService.OpenKVStore(ctx) key := types.KeyFeesInEscrow(packetID) - bz := store.Get(key) + bz, err := store.Get(key) + if err != nil { + panic(err) + } if len(bz) == 0 { return types.PacketFees{}, false } @@ -329,35 +358,38 @@ func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) } // HasFeesInEscrow returns true if packet fees exist for the provided packetID -func (k Keeper) HasFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) bool { - store := ctx.KVStore(k.storeService) +func (k Keeper) HasFeesInEscrow(ctx context.Context, packetID channeltypes.PacketId) bool { + store := k.storeService.OpenKVStore(ctx) key := types.KeyFeesInEscrow(packetID) - - return store.Has(key) + has, err := store.Has(key) + if err != nil { + panic(err) + } + return has } // SetFeesInEscrow sets the given packet fees in escrow keyed by the packetID -func (k Keeper) SetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId, fees types.PacketFees) { - store := ctx.KVStore(k.storeService) +func (k Keeper) SetFeesInEscrow(ctx context.Context, packetID channeltypes.PacketId, fees types.PacketFees) { + store := k.storeService.OpenKVStore(ctx) bz := k.MustMarshalFees(fees) store.Set(types.KeyFeesInEscrow(packetID), bz) } // DeleteFeesInEscrow deletes the fee associated with the given packetID -func (k Keeper) DeleteFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) { - store := ctx.KVStore(k.storeService) +func (k Keeper) DeleteFeesInEscrow(ctx context.Context, packetID channeltypes.PacketId) { + store := k.storeService.OpenKVStore(ctx) key := types.KeyFeesInEscrow(packetID) store.Delete(key) } // GetIdentifiedPacketFeesForChannel returns all the currently escrowed fees on a given channel. -func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx sdk.Context, portID, channelID string) []types.IdentifiedPacketFees { +func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx context.Context, portID, channelID string) []types.IdentifiedPacketFees { var identifiedPacketFees []types.IdentifiedPacketFees store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, types.KeyFeesInEscrowChannelPrefix(portID, channelID)) - 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() { packetID, err := types.ParseKeyFeesInEscrow(string(iterator.Key())) if err != nil { @@ -374,10 +406,10 @@ func (k Keeper) GetIdentifiedPacketFeesForChannel(ctx sdk.Context, portID, chann } // GetAllIdentifiedPacketFees returns a list of all IdentifiedPacketFees that are stored in state -func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []types.IdentifiedPacketFees { +func (k Keeper) GetAllIdentifiedPacketFees(ctx context.Context) []types.IdentifiedPacketFees { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeesInEscrowPrefix)) - defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + defer sdk.LogDeferred(k.Logger(ctx), func() error { return iterator.Close() }) var identifiedFees []types.IdentifiedPacketFees for ; iterator.Valid(); iterator.Next() { diff --git a/modules/apps/29-fee/keeper/migrations.go b/modules/apps/29-fee/keeper/migrations.go index f06b7e5b97e..25408c95954 100644 --- a/modules/apps/29-fee/keeper/migrations.go +++ b/modules/apps/29-fee/keeper/migrations.go @@ -3,6 +3,7 @@ package keeper import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types" @@ -23,7 +24,7 @@ func NewMigrator(keeper Keeper) Migrator { // Migrate1to2 migrates ibc-fee module from ConsensusVersion 1 to 2 // by refunding leftover fees to the refund address. func (m Migrator) Migrate1to2(ctx sdk.Context) error { - store := ctx.KVStore(m.keeper.storeService) + store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx)) iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeesInEscrowPrefix)) defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index 39220cc75eb..f40d2a9b326 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -1,6 +1,7 @@ package transfer import ( + "context" "fmt" "math" "slices" @@ -312,7 +313,7 @@ func (IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, pr // UnmarshalPacketData attempts to unmarshal the provided packet data bytes // into a FungibleTokenPacketData. This function implements the optional // PacketDataUnmarshaler interface required for ADR 008 support. -func (im IBCModule) UnmarshalPacketData(ctx sdk.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { +func (im IBCModule) UnmarshalPacketData(ctx context.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { ics20Version, found := im.keeper.GetICS4Wrapper().GetAppVersion(ctx, portID, channelID) if !found { return types.FungibleTokenPacketDataV2{}, "", errorsmod.Wrapf(ibcerrors.ErrNotFound, "app version not found for port %s and channel %s", portID, channelID) diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index 5125eb43315..ee12699cd9a 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -36,10 +36,10 @@ type BankKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) - GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) - GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel - HasChannel(ctx sdk.Context, portID, channelID string) bool + GetChannel(ctx context.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx context.Context, portID, channelID string) (uint64, bool) + GetAllChannelsWithPortPrefix(ctx context.Context, portPrefix string) []channeltypes.IdentifiedChannel + HasChannel(ctx context.Context, portID, channelID string) bool } // ClientKeeper defines the expected IBC client keeper @@ -54,7 +54,7 @@ type ConnectionKeeper interface { // PortKeeper defines the expected IBC port keeper type PortKeeper interface { - BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability + BindPort(ctx context.Context, portID string) *capabilitytypes.Capability } // ParamSubspace defines the expected Subspace interface for module parameters. diff --git a/modules/core/02-client/migrations/v7/genesis_test.go b/modules/core/02-client/migrations/v7/genesis_test.go index f97f5aa4ed7..52116463fcb 100644 --- a/modules/core/02-client/migrations/v7/genesis_test.go +++ b/modules/core/02-client/migrations/v7/genesis_test.go @@ -5,9 +5,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" ibcclient "github.com/cosmos/ibc-go/v9/modules/core/02-client" - "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" + v7 "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -107,7 +108,7 @@ func (suite *MigrationsV7TestSuite) TestMigrateGenesisSolomachine() { // migrate store get expected genesis // store migration and genesis migration should produce identical results // NOTE: tendermint clients are not pruned in genesis so the test should not have expired tendermint clients - err := v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + err := v7.MigrateStore(suite.chainA.GetContext(), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey)), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) suite.Require().NoError(err) expectedClientGenState := ibcclient.ExportGenesis(suite.chainA.GetContext(), suite.chainA.App.GetIBCKeeper().ClientKeeper) diff --git a/modules/core/02-client/migrations/v7/store_test.go b/modules/core/02-client/migrations/v7/store_test.go index 620da77107c..48232457381 100644 --- a/modules/core/02-client/migrations/v7/store_test.go +++ b/modules/core/02-client/migrations/v7/store_test.go @@ -7,8 +7,9 @@ import ( testifysuite "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" + v7 "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -61,7 +62,7 @@ func (suite *MigrationsV7TestSuite) TestMigrateStore() { suite.createSolomachineClients(solomachines) suite.createLocalhostClients() - err := v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + err := v7.MigrateStore(suite.chainA.GetContext(), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey)), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) suite.Require().NoError(err) suite.assertSolomachineClients(solomachines) @@ -77,7 +78,7 @@ func (suite *MigrationsV7TestSuite) TestMigrateStoreNoTendermintClients() { suite.createSolomachineClients(solomachines) suite.createLocalhostClients() - err := v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + err := v7.MigrateStore(suite.chainA.GetContext(), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey)), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) suite.Require().NoError(err) suite.assertSolomachineClients(solomachines) diff --git a/modules/core/02-client/types/router_test.go b/modules/core/02-client/types/router_test.go index 7b18319601c..fd3100660ed 100644 --- a/modules/core/02-client/types/router_test.go +++ b/modules/core/02-client/types/router_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" @@ -53,7 +54,7 @@ func (suite *TypesTestSuite) TestAddRoute() { suite.SetupTest() cdc := suite.chainA.App.AppCodec() - storeProvider := types.NewStoreProvider(suite.chainA.GetSimApp().GetKey(exported.StoreKey)) + storeProvider := types.NewStoreProvider(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(exported.StoreKey))) tmLightClientModule := ibctm.NewLightClientModule(cdc, storeProvider) router = types.NewRouter() @@ -110,7 +111,7 @@ func (suite *TypesTestSuite) TestHasGetRoute() { suite.SetupTest() cdc := suite.chainA.App.AppCodec() - storeProvider := types.NewStoreProvider(suite.chainA.GetSimApp().GetKey(exported.StoreKey)) + storeProvider := types.NewStoreProvider(runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(exported.StoreKey))) tmLightClientModule := ibctm.NewLightClientModule(cdc, storeProvider) router := types.NewRouter() router.AddRoute(exported.Tendermint, &tmLightClientModule) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index a46f4cf0a99..5dd4969edd2 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "math" errorsmod "cosmossdk.io/errors" @@ -18,7 +19,7 @@ import ( // VerifyConnectionState verifies a proof of the connection state of the // specified connection end stored on the target machine. func (k *Keeper) VerifyConnectionState( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -55,7 +56,7 @@ func (k *Keeper) VerifyConnectionState( // VerifyChannelState verifies a proof of the channel state of the specified // channel end, under the specified port, stored on the target machine. func (k *Keeper) VerifyChannelState( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -93,7 +94,7 @@ func (k *Keeper) VerifyChannelState( // VerifyPacketCommitment verifies a proof of an outgoing packet commitment at // the specified port, specified channel, and specified sequence. func (k *Keeper) VerifyPacketCommitment( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -129,7 +130,7 @@ func (k *Keeper) VerifyPacketCommitment( // VerifyPacketAcknowledgement verifies a proof of an incoming packet // acknowledgement at the specified port, specified channel, and specified sequence. func (k *Keeper) VerifyPacketAcknowledgement( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -167,7 +168,7 @@ func (k *Keeper) VerifyPacketAcknowledgement( // incoming packet receipt at the specified port, specified channel, and // specified sequence. func (k *Keeper) VerifyPacketReceiptAbsence( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -202,7 +203,7 @@ func (k *Keeper) VerifyPacketReceiptAbsence( // VerifyNextSequenceRecv verifies a proof of the next sequence number to be // received of the specified channel at the specified port. func (k *Keeper) VerifyNextSequenceRecv( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -238,7 +239,7 @@ func (k *Keeper) VerifyNextSequenceRecv( // VerifyChannelUpgradeError verifies a proof of the provided upgrade error receipt. func (k *Keeper) VerifyChannelUpgradeError( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, height exported.Height, proof []byte, @@ -275,7 +276,7 @@ func (k *Keeper) VerifyChannelUpgradeError( // VerifyChannelUpgrade verifies the proof that a particular proposed upgrade has been stored in the upgrade path. func (k *Keeper) VerifyChannelUpgrade( - ctx sdk.Context, + ctx context.Context, connection types.ConnectionEnd, proofHeight exported.Height, upgradeProof []byte, @@ -312,7 +313,7 @@ func (k *Keeper) VerifyChannelUpgrade( // getBlockDelay calculates the block delay period from the time delay of the connection // and the maximum expected time per block. -func (k *Keeper) getBlockDelay(ctx sdk.Context, connection types.ConnectionEnd) uint64 { +func (k *Keeper) getBlockDelay(ctx context.Context, connection types.ConnectionEnd) uint64 { // expectedTimePerBlock should never be zero, however if it is then return a 0 block delay for safety // as the expectedTimePerBlock parameter was not set. expectedTimePerBlock := k.GetParams(ctx).MaxExpectedTimePerBlock diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index 95be6e32dbb..f20d83e64aa 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -201,5 +201,5 @@ type PacketDataUnmarshaler interface { // UnmarshalPacketData unmarshals the packet data into a concrete type // ctx, portID, channelID are provided as arguments, so that (if needed) // the packet data can be unmarshaled based on the channel version. - UnmarshalPacketData(ctx sdk.Context, portID string, channelID string, bz []byte) (interface{}, string, error) + UnmarshalPacketData(ctx context.Context, portID string, channelID string, bz []byte) (interface{}, string, error) } diff --git a/modules/core/keeper/keeper_test.go b/modules/core/keeper/keeper_test.go index ff7fb8b8f11..4763c822a5b 100644 --- a/modules/core/keeper/keeper_test.go +++ b/modules/core/keeper/keeper_test.go @@ -7,6 +7,7 @@ import ( upgradekeeper "cosmossdk.io/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/runtime" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -72,7 +73,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { newIBCKeeperFn = func() { ibckeeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey)), suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), upgradeKeeper, scopedKeeper, @@ -91,7 +92,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { newIBCKeeperFn = func() { ibckeeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), - suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), + runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey)), suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName), upgradeKeeper, scopedKeeper, diff --git a/modules/core/migrations/v7/genesis_test.go b/modules/core/migrations/v7/genesis_test.go index 5bd598d1fee..8a5e274a863 100644 --- a/modules/core/migrations/v7/genesis_test.go +++ b/modules/core/migrations/v7/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ibcclient "github.com/cosmos/ibc-go/v9/modules/core/02-client" @@ -14,7 +15,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/migrations/v7" + v7 "github.com/cosmos/ibc-go/v9/modules/core/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -134,7 +135,7 @@ func (suite *MigrationsV7TestSuite) TestMigrateGenesisSolomachine() { // migrate store get expected genesis // store migration and genesis migration should produce identical results // NOTE: tendermint clients are not pruned in genesis so the test should not have expired tendermint clients - err := clientv7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + err := clientv7.MigrateStore(suite.chainA.GetContext(), runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey)), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) suite.Require().NoError(err) expectedClientGenState := ibcclient.ExportGenesis(suite.chainA.GetContext(), suite.chainA.App.GetIBCKeeper().ClientKeeper) diff --git a/modules/light-clients/07-tendermint/migrations/expected_keepers.go b/modules/light-clients/07-tendermint/migrations/expected_keepers.go index b6b681d6402..48ff97e416d 100644 --- a/modules/light-clients/07-tendermint/migrations/expected_keepers.go +++ b/modules/light-clients/07-tendermint/migrations/expected_keepers.go @@ -1,18 +1,18 @@ package migrations import ( + "context" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v9/modules/core/exported" ) // ClientKeeper expected account IBC client keeper type ClientKeeper interface { - GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) - IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) - ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore - Logger(ctx sdk.Context) log.Logger + GetClientState(ctx context.Context, clientID string) (exported.ClientState, bool) + IterateClientStates(ctx context.Context, prefix []byte, cb func(string, exported.ClientState) bool) + ClientStore(ctx context.Context, clientID string) storetypes.KVStore + Logger(ctx context.Context) log.Logger } diff --git a/simapp/app.go b/simapp/app.go index cbb581e51fd..9d8e4fd7d63 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -425,7 +425,7 @@ func NewSimApp( // IBC Fee Module keeper app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( - appCodec, keys[ibcfeetypes.StoreKey], + appCodec, runtime.NewKVStoreService(keys[ibcfeetypes.StoreKey]), app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 03c21ffce4a..d96abb5bf1c 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -2,6 +2,7 @@ package mock import ( "bytes" + "context" "fmt" "reflect" "strconv" @@ -219,7 +220,7 @@ func (im IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string, // UnmarshalPacketData returns the MockPacketData. This function implements the optional // PacketDataUnmarshaler interface required for ADR 008 support. -func (IBCModule) UnmarshalPacketData(ctx sdk.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { +func (IBCModule) UnmarshalPacketData(ctx context.Context, portID string, channelID string, bz []byte) (interface{}, string, error) { if reflect.DeepEqual(bz, MockPacketData) { return MockPacketData, Version, nil } diff --git a/testing/mock/middleware.go b/testing/mock/middleware.go index 6d6a33a1a1f..c0949fa5f67 100644 --- a/testing/mock/middleware.go +++ b/testing/mock/middleware.go @@ -2,6 +2,7 @@ package mock import ( "bytes" + "context" "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -170,7 +171,7 @@ func (im BlockUpgradeMiddleware) OnTimeoutPacket(ctx sdk.Context, channelVersion // SendPacket implements the ICS4 Wrapper interface func (BlockUpgradeMiddleware) SendPacket( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, sourcePort string, sourceChannel string, @@ -183,7 +184,7 @@ func (BlockUpgradeMiddleware) SendPacket( // WriteAcknowledgement implements the ICS4 Wrapper interface func (BlockUpgradeMiddleware) WriteAcknowledgement( - ctx sdk.Context, + ctx context.Context, chanCap *capabilitytypes.Capability, packet exported.PacketI, ack exported.Acknowledgement, @@ -192,6 +193,6 @@ func (BlockUpgradeMiddleware) WriteAcknowledgement( } // GetAppVersion returns the application version of the underlying application -func (BlockUpgradeMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { +func (BlockUpgradeMiddleware) GetAppVersion(ctx context.Context, portID, channelID string) (string, bool) { return Version, true } diff --git a/testing/mock/mock.go b/testing/mock/mock.go index 150900664b2..17055eda29e 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -1,6 +1,7 @@ package mock import ( + "context" "encoding/json" "errors" "fmt" @@ -67,8 +68,8 @@ var ( // Expected Interface // PortKeeper defines the expected IBC port keeper type PortKeeper interface { - BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability - IsBound(ctx sdk.Context, portID string) bool + BindPort(ctx context.Context, portID string) *capabilitytypes.Capability + IsBound(ctx context.Context, portID string) bool } // AppModuleBasic is the mock AppModuleBasic. diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 782aaab3649..ad986106660 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -388,7 +388,7 @@ func NewSimApp( // IBC Fee Module keeper app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( - appCodec, keys[ibcfeetypes.StoreKey], + appCodec, runtime.NewKVStoreService(keys[ibcfeetypes.StoreKey]), app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, From 88720c297ed7d9bf7b01a31a46f290d0eafff7b4 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 7 Aug 2024 15:52:12 +0200 Subject: [PATCH 07/19] p2 --- .../controller/ibc_middleware.go | 26 ++-- .../controller/ibc_middleware_test.go | 31 ++-- .../controller/keeper/events.go | 6 +- .../controller/keeper/handshake.go | 13 +- .../controller/keeper/keeper.go | 145 +++++++++++------- .../controller/keeper/keeper_test.go | 5 +- .../controller/keeper/migrations_test.go | 3 +- .../controller/keeper/relay.go | 4 +- .../27-interchain-accounts/host/ibc_module.go | 26 ++-- .../host/ibc_module_test.go | 7 +- .../host/keeper/account.go | 4 +- .../host/keeper/events.go | 13 +- .../host/keeper/handshake.go | 12 +- .../host/keeper/keeper.go | 105 ++++++++----- .../host/keeper/keeper_test.go | 7 +- .../host/keeper/migrations_test.go | 3 +- .../host/keeper/relay.go | 11 +- .../27-interchain-accounts/types/account.go | 6 +- .../27-interchain-accounts/types/metadata.go | 7 +- modules/apps/29-fee/ibc_middleware.go | 26 ++-- modules/apps/29-fee/ibc_middleware_test.go | 33 ++-- modules/apps/29-fee/keeper/escrow.go | 16 +- modules/apps/transfer/ibc_module.go | 28 ++-- .../apps/transfer/internal/events/events.go | 32 ++-- modules/apps/transfer/keeper/forwarding.go | 11 +- modules/apps/transfer/keeper/grpc_query.go | 23 +-- modules/apps/transfer/keeper/keeper.go | 127 ++++++++------- modules/apps/transfer/keeper/keeper_test.go | 7 +- modules/apps/transfer/keeper/migrations.go | 16 +- modules/apps/transfer/keeper/relay.go | 13 +- modules/core/05-port/types/module.go | 26 ++-- modules/core/ante/ante_test.go | 5 +- modules/core/keeper/msg_server_test.go | 29 ++-- testing/mock/ibc_app.go | 28 ++-- testing/mock/ibc_module.go | 47 +++--- testing/mock/middleware.go | 33 ++-- testing/simapp/app.go | 6 +- 37 files changed, 536 insertions(+), 404 deletions(-) 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 d76b26c064b..4671b48211d 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/events.go b/modules/apps/27-interchain-accounts/controller/keeper/events.go index 5743253b530..f4ca8b758a2 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: remove after sdk.Context is removed from core IBC 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/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 46b040c4568..fc1840a01fe 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: remove after sdk.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) @@ -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,28 @@ 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) +func (k Keeper) setPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyPort(portID), []byte{0x01}) } // 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: remove after sdk.Context is removed from core IBC + _, 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + return k.scopedKeeper.ClaimCapability(sdkCtx, cap, name) } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. @@ -136,19 +142,28 @@ 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) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { + return "", false } + bz, err := store.Get(key) + if err != nil { + panic(err) + } - return string(store.Get(key)), true + return string(bz), true // todo: why the cast? } // 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 +179,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 +190,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 +217,41 @@ 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) +func (k Keeper) SetActiveChannelID(ctx context.Context, connectionID, portID, channelID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID)) } // 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) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { return "", false } - return string(store.Get(key)), true + bz, err := store.Get(key) + if err != nil { + panic(err) + } + + return string(bz), true // todo: why the cast? } // 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,38 +271,46 @@ 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) +func (k Keeper) SetInterchainAccountAddress(ctx context.Context, connectionID, portID, address string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) } // 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) +func (k Keeper) SetMiddlewareEnabled(ctx context.Context, portID, connectionID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), icatypes.MiddlewareEnabled) } // 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) +func (k Keeper) SetMiddlewareDisabled(ctx context.Context, portID, connectionID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), icatypes.MiddlewareDisabled) } // DeleteMiddlewareEnabled deletes the middleware enabled flag stored in state -func (k Keeper) DeleteMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) DeleteMiddlewareEnabled(ctx context.Context, portID, connectionID string) { + store := k.storeService.OpenKVStore(ctx) store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)) } @@ -288,7 +320,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 +330,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 +346,8 @@ 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) } 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 a9638043c66..966d2ea9ecf 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 45562f1788e..f1b278950c2 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,7 @@ 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" icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types" @@ -99,7 +100,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 07699ee0da0..58c55c407de 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" @@ -165,7 +166,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) { @@ -287,7 +288,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..f1563be7d4f 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,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) { + attributes := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()), @@ -23,8 +25,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: remove after sdk.Context is removed from core IBC + sdkCtx.EventManager().EmitEvent( sdk.NewEvent( icatypes.EventTypePacket, attributes..., @@ -33,8 +35,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: remove after sdk.Context is removed from core IBC + 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..5beec992a3d 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: remove after sdk.Context is removed from core IBC + 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..cc2961cd1d5 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,28 @@ 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) +func (k Keeper) setPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyPort(portID), []byte{0x01}) } // 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: remove after sdk.Context is removed from core IBC + _, 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + return k.scopedKeeper.ClaimCapability(sdkCtx, cap, name) } // GetAppVersion calls the ICS4Wrapper GetAppVersion function. @@ -141,7 +147,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 +157,28 @@ 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) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { return "", false } - return string(store.Get(key)), true + bz, err := store.Get(key) + if err != nil { + panic(err) + } + + 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 +194,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 +216,41 @@ 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) +func (k Keeper) SetActiveChannelID(ctx context.Context, connectionID, portID, channelID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID)) } // 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) { + has, err := store.Has(key) + if err != nil { + panic(err) + } + if !has { return "", false } - return string(store.Get(key)), true + bz, err := store.Get(key) + if err != nil { + panic(err) + } + + 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,8 +270,8 @@ 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) +func (k Keeper) SetInterchainAccountAddress(ctx context.Context, connectionID, portID, address string) { + store := k.storeService.OpenKVStore(ctx) store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) } @@ -257,9 +281,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,8 +297,8 @@ 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) } 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 8986311c392..23828769cba 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..775424edf16 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: remove after sdk.Context is removed from core IBC + 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..55354e9cd24 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: remove after sdk.Context is removed from core IBC + 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 4e2a9c27280..9ec4c7c415e 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" "fmt" @@ -84,7 +85,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) { @@ -184,7 +185,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) { @@ -284,7 +285,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") @@ -333,7 +334,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") } @@ -422,7 +423,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") } @@ -513,7 +514,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, @@ -800,7 +801,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") } }, @@ -1014,7 +1015,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") } }, @@ -1098,7 +1099,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 } @@ -1117,7 +1118,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 } }, @@ -1205,7 +1206,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 } }, @@ -1227,7 +1228,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 } }, @@ -1302,7 +1303,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 } }, @@ -1324,7 +1325,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 } }, @@ -1395,7 +1396,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) @@ -1425,7 +1426,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..12cef74341f 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + cacheCtx, writeFn := sdkCtx.CacheContext() for _, identifiedPacketFee := range identifiedPacketFees { var unRefundedFees []types.PacketFee 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 ed015f68604..8a6e103b6f5 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: remove after sdk.Context is removed from core IBC 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: remove after sdk.Context is removed from core IBC + + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC 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: remove after sdk.Context is removed from core IBC 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..744c59ac701 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: remove after sdk.Context is removed from core IBC + 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..ea6f9aea714 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,49 @@ 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + _, 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) +func (k Keeper) SetPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(types.PortKey, []byte(portID)) } // 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 +152,15 @@ 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) } // 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 +173,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 +198,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 +214,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 +240,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,12 +259,12 @@ 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() { @@ -261,7 +277,7 @@ func (k Keeper) SetTotalEscrowForDenom(ctx sdk.Context, coin sdk.Coin) { } // 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 +290,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 +314,32 @@ 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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) } // 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 +351,15 @@ 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) } // 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 +370,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..ec2195eff0c 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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/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..e714a138551 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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..2ed1b8d17fb 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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: remove after sdk.Context is removed from core IBC + 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, From 776ad27732abfed72fb7e569f33d520d8f36dc6b Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Thu, 8 Aug 2024 10:04:32 +0200 Subject: [PATCH 08/19] capability changes --- .../controller/keeper/account.go | 11 +- .../controller/keeper/events.go | 2 +- .../controller/keeper/genesis.go | 7 +- .../controller/keeper/keeper.go | 8 +- modules/apps/29-fee/keeper/escrow.go | 17 +- modules/apps/29-fee/keeper/events.go | 22 ++- modules/apps/29-fee/keeper/keeper.go | 2 +- modules/capability/capability_test.go | 16 +- modules/capability/genesis_test.go | 13 +- modules/capability/go.mod | 34 ++-- modules/capability/go.sum | 92 +++++++---- modules/capability/keeper/keeper.go | 155 ++++++++++-------- modules/capability/keeper/keeper_test.go | 4 +- 13 files changed, 228 insertions(+), 155 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 779826dbc94..9ed66f6b3b1 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: remove when Upgrading to 52 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/events.go b/modules/apps/27-interchain-accounts/controller/keeper/events.go index f4ca8b758a2..c0fe4518b90 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/events.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/events.go @@ -14,7 +14,7 @@ import ( // EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error // details if any. func EmitAcknowledgementEvent(ctx context.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 attributes := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), sdk.NewAttribute(icatypes.AttributeKeyControllerChannelID, packet.GetDestChannel()), 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 fc1840a01fe..84535602dbd 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -82,7 +82,7 @@ func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper { // Logger returns the application logger, scoped to the associated module func (Keeper) Logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s-%s", exported.ModuleName, icatypes.ModuleName)) } @@ -119,20 +119,20 @@ 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: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 _, ok := k.scopedKeeper.GetCapability(sdkCtx, 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: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 return k.scopedKeeper.AuthenticateCapability(sdkCtx, 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: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 return k.scopedKeeper.ClaimCapability(sdkCtx, cap, name) } diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 12cef74341f..91e01eea090 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 { @@ -50,7 +50,7 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, 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 - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 cacheCtx, writeFn := sdkCtx.CacheContext() // forward relayer address will be empty if conversion fails @@ -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 @@ -108,7 +108,7 @@ func (k Keeper) distributePacketFeeOnAcknowledgement(ctx sdk.Context, refundAddr 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 - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 cacheCtx, writeFn := sdkCtx.CacheContext() for _, packetFee := range packetFees { @@ -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: remove when Upgrading to 52 + cacheCtx, writeFn := sdkCtx.CacheContext() err := k.bankKeeper.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, receiver, fee) if err != nil { @@ -189,7 +190,7 @@ func (k Keeper) RefundFeesOnChannelClosure(ctx context.Context, portID, channelI // cache context before trying to distribute fees // if the escrow account has insufficient balance then we want to avoid partially distributing fees - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 cacheCtx, writeFn := sdkCtx.CacheContext() for _, identifiedPacketFee := range identifiedPacketFees { diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index d5883be5443..92ea87f757c 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: remove when Upgrading to 52 + 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: remove when Upgrading to 52 + 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: remove when Upgrading to 52 + 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: remove when Upgrading to 52 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeDistributeFee, sdk.NewAttribute(types.AttributeKeyReceiver, receiver), diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index d4136d675bd..3fcdc7edf7f 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -68,7 +68,7 @@ func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper { // Logger returns a module-specific logger. func (Keeper) Logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after sdk.Context is removed from core IBC + sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 return sdkCtx.Logger().With("module", "x/"+ibcexported.ModuleName+"-"+types.ModuleName) } 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 5c1c70f933d..8fb9313c185 100644 --- a/modules/capability/go.mod +++ b/modules/capability/go.mod @@ -7,14 +7,14 @@ toolchain go1.22.0 replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 require ( - cosmossdk.io/core v0.11.0 + cosmossdk.io/core v0.11.1 cosmossdk.io/errors v1.0.1 - cosmossdk.io/log v1.3.1 + cosmossdk.io/log v1.4.0 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.0 github.com/cometbft/cometbft v0.38.10 github.com/cosmos/cosmos-db v1.0.2 - github.com/cosmos/cosmos-sdk v0.50.7 + github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef github.com/cosmos/gogoproto v1.5.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/stretchr/testify v1.9.0 @@ -24,8 +24,8 @@ require ( require ( cosmossdk.io/api v0.7.5 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/depinject v1.0.0-alpha.4 // indirect - cosmossdk.io/x/tx v0.13.3 // indirect + cosmossdk.io/depinject v1.0.0 // indirect + cosmossdk.io/x/tx v0.13.4 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -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 @@ -121,7 +125,7 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/cors v1.8.3 // indirect - github.com/rs/zerolog v1.32.0 // indirect + github.com/rs/zerolog v1.33.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect @@ -140,18 +144,18 @@ require ( github.com/zondax/ledger-go v0.14.3 // indirect go.etcd.io/bbolt v1.3.8 // indirect go.uber.org/multierr v1.10.0 // indirect - golang.org/x/crypto v0.22.0 // indirect + golang.org/x/crypto v0.25.0 // indirect golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect - golang.org/x/net v0.24.0 // indirect + golang.org/x/net v0.27.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/term v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/term v0.22.0 // indirect + golang.org/x/text v0.16.0 // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect - google.golang.org/grpc v1.63.2 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect + google.golang.org/grpc v1.64.1 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.5.1 // indirect diff --git a/modules/capability/go.sum b/modules/capability/go.sum index eae67a799f3..945459b3122 100644 --- a/modules/capability/go.sum +++ b/modules/capability/go.sum @@ -4,20 +4,20 @@ cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ= cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= -cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w= -cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= -cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= +cosmossdk.io/core v0.11.1 h1:h9WfBey7NAiFfIcUhDVNS503I2P2HdZLebJlUIs8LPA= +cosmossdk.io/core v0.11.1/go.mod h1:OJzxcdC+RPrgGF8NJZR2uoQr56tc7gfBKhiKeDO7hH0= +cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050= +cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= -cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= -cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= +cosmossdk.io/log v1.4.0 h1:Ttt9d6fQ0GlktwhcysOeNiIjixW7l0rYBocmoXOb11k= +cosmossdk.io/log v1.4.0/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk= cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng= -cosmossdk.io/x/tx v0.13.3 h1:Ha4mNaHmxBc6RMun9aKuqul8yHiL78EKJQ8g23Zf73g= -cosmossdk.io/x/tx v0.13.3/go.mod h1:I8xaHv0rhUdIvIdptKIqzYy27+n2+zBVaxO6fscFhys= +cosmossdk.io/x/tx v0.13.4 h1:Eg0PbJgeO0gM8p5wx6xa0fKR7hIV6+8lC56UrsvSo0Y= +cosmossdk.io/x/tx v0.13.4/go.mod h1:BkFqrnGGgW50Y6cwTy+JvgAhiffbGEKW6KF9ufcDpvk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -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.10 h1:2ePuglchT+j0Iao+cfmt/nw5U7K2lnGDzXSUPGV github.com/cometbft/cometbft v0.38.10/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,8 +140,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.7 h1:LsBGKxifENR/DN4E1RZaitsyL93HU44x0p8EnMHp4V4= -github.com/cosmos/cosmos-sdk v0.50.7/go.mod h1:84xDDJEHttRT7NDGwBaUOLVOMN0JNE9x7NbsYIxXs1s= +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= @@ -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= @@ -602,8 +627,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= -github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -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= @@ -725,8 +752,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= @@ -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= @@ -771,8 +800,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -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= @@ -839,20 +869,20 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -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= @@ -896,10 +928,10 @@ google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20220314164441-57ef72a4c106/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= -google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= -google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -917,8 +949,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -933,8 +965,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index 5d856c5e64b..e779b071f83 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: remove after 52 upgrade + 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,25 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { } // set the initialized flag so we don't rerun initialization logic - memStore := noGasCtx.KVStore(k.memKey) + memStore := k.memService.OpenMemoryStore(noGasCtx) memStore.Set(types.KeyMemInitialized, []byte{1}) } } // 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) + has, err := memStore.Has(types.KeyMemInitialized) + if err != nil { + panic(err) + } + return has } // 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 +173,25 @@ func (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error { } // set the global index to the passed index - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.KeyIndex, types.IndexToKey(index)) 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 +199,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,8 +217,8 @@ 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 { @@ -238,18 +246,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)) } // 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 @@ -260,7 +272,7 @@ func (sk ScopedKeeper) NewCapability(ctx sdk.Context, name string) (*types.Capab // increment global index store.Set(types.KeyIndex, types.IndexToKey(index+1)) - 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 @@ -288,7 +300,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 +312,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,7 +324,7 @@ 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 @@ -332,7 +344,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,7 +353,7 @@ 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 @@ -355,7 +367,8 @@ func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) 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 +387,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 +421,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) // TODO: why the cast? } // 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 +446,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 +466,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 +488,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 +505,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 +521,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: remove after 52 upgrade + 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..0b097c1c42b 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,11 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) + memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx 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() { From 0f519b41f18418d706ea6701b6646fa6bc5158f1 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 28 Aug 2024 11:19:56 +0200 Subject: [PATCH 09/19] fix capability --- .../27-interchain-accounts/controller/keeper/keeper.go | 4 ---- modules/capability/go.mod | 4 ++-- modules/capability/go.sum | 8 ++++---- modules/core/02-client/migrations/v7/store.go | 1 - 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 5a8fc8f9f8a..584fa109361 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -155,10 +155,6 @@ func (k Keeper) GetActiveChannelID(ctx context.Context, connectionID, portID str if len(bz) == 0 { return "", false } - bz, err := store.Get(key) - if err != nil { - panic(err) - } return string(bz), true } diff --git a/modules/capability/go.mod b/modules/capability/go.mod index 7be20b322e9..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 diff --git a/modules/capability/go.sum b/modules/capability/go.sum index f257f6f096f..cf393d4f2d3 100644 --- a/modules/capability/go.sum +++ b/modules/capability/go.sum @@ -140,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= diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go index 210318dda19..2bfff6099de 100644 --- a/modules/core/02-client/migrations/v7/store.go +++ b/modules/core/02-client/migrations/v7/store.go @@ -7,7 +7,6 @@ import ( errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" - corestore "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" From 70fd024072ebf93f7ccca770d2377fc7dec8c530 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 28 Aug 2024 11:32:39 +0200 Subject: [PATCH 10/19] remove todos --- go.mod | 6 ++++-- go.sum | 10 ++++------ .../controller/keeper/keeper.go | 9 +++------ .../host/keeper/handshake.go | 3 +-- .../host/keeper/keeper.go | 9 +++------ modules/apps/callbacks/go.mod | 6 ++++-- modules/apps/callbacks/go.sum | 10 ++++------ modules/apps/transfer/keeper/forwarding.go | 3 +-- modules/apps/transfer/keeper/keeper.go | 9 +++------ modules/core/03-connection/keeper/keeper.go | 3 +-- modules/core/04-channel/keeper/keeper.go | 3 +-- modules/core/04-channel/keeper/packet.go | 4 ++-- modules/core/05-port/keeper/keeper.go | 13 ++++--------- modules/core/exported/expected_keepers.go | 13 +++++++------ .../07-tendermint/light_client_module.go | 4 +--- modules/light-clients/08-wasm/go.mod | 4 +++- modules/light-clients/08-wasm/go.sum | 6 ++---- testing/mock/ibc_module.go | 18 ++++++++---------- testing/mock/middleware.go | 15 +++++---------- testing/simapp/app.go | 2 +- 20 files changed, 62 insertions(+), 88 deletions(-) diff --git a/go.mod b/go.mod index 629fdd2616c..6acdbeafbac 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.10.0 @@ -182,7 +182,7 @@ require ( golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/sys v0.24.0 // indirect golang.org/x/term v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect @@ -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 diff --git a/go.sum b/go.sum index 24afccc55ea..29a7f6771c4 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.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= @@ -1276,8 +1274,8 @@ golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 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/callbacks/go.mod b/modules/apps/callbacks/go.mod index 94c37bf511d..e089415e23e 100644 --- a/modules/apps/callbacks/go.mod +++ b/modules/apps/callbacks/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 @@ -24,7 +26,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 @@ -189,7 +191,7 @@ require ( golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.23.0 // indirect + golang.org/x/sys v0.24.0 // indirect golang.org/x/term v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect diff --git a/modules/apps/callbacks/go.sum b/modules/apps/callbacks/go.sum index b14e3de9111..4ca4cdf50f7 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.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= @@ -1288,8 +1286,8 @@ golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/modules/apps/transfer/keeper/forwarding.go b/modules/apps/transfer/keeper/forwarding.go index 656fbb75c4a..dac9aae3d77 100644 --- a/modules/apps/transfer/keeper/forwarding.go +++ b/modules/apps/transfer/keeper/forwarding.go @@ -48,8 +48,7 @@ func (k Keeper) forwardPacket(ctx context.Context, data types.FungibleTokenPacke // acknowledgeForwardedPacket writes the async acknowledgement for forwardedPacket 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)) + capability, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel)) if !ok { return errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } 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/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 64320cfc005..3c444200249 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -309,8 +309,7 @@ func (k *Keeper) WriteAcknowledgement( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if !k.scopedKeeper.AuthenticateCapability(sdkCtx, chanCap, capName) { + if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, @@ -359,6 +358,7 @@ func (k *Keeper) WriteAcknowledgement( "dst_channel", packet.GetDestChannel(), ) + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 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 afd4bce4e56..22bd5ee841d 100644 --- a/modules/core/exported/expected_keepers.go +++ b/modules/core/exported/expected_keepers.go @@ -1,15 +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 828ab27d0ed..9b5a54561e8 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 677c3713dcb..e600d1f5d22 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.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 732d193de35..281c7de780c 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/5917 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/5917 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/5917 sdkCtx.EventManager().EmitEvent(NewMockTimeoutPacketEvent()) return nil diff --git a/testing/mock/middleware.go b/testing/mock/middleware.go index 659438d239d..7c761cf5dea 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..be93c95ce9e 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]), memKeys[capabilitytypes.MemStoreKey]) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) From 9d4ece48cceee44be4d2f8598a4fac40a0a2029c Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 28 Aug 2024 15:03:08 +0200 Subject: [PATCH 11/19] linting --- .../controller/keeper/account.go | 2 +- modules/apps/29-fee/keeper/escrow.go | 2 +- modules/apps/29-fee/keeper/events.go | 8 +-- modules/apps/callbacks/testing/simapp/app.go | 2 +- modules/capability/keeper/keeper.go | 50 +++++++++++++------ .../08-wasm/testing/simapp/app.go | 2 +- testing/simapp/app.go | 2 +- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 9ed66f6b3b1..bf0135d63d6 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -76,7 +76,7 @@ func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, por } } - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 msg := channeltypes.NewMsgChannelOpenInit(portID, version, ordering, []string{connectionID}, icatypes.HostPortID, authtypes.NewModuleAddress(icatypes.ModuleName).String()) handler := k.msgRouter.Handler(msg) res, err := handler(sdkCtx, msg) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index a982e85960a..d91eeb0f756 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -154,7 +154,7 @@ func (k Keeper) distributePacketFeeOnTimeout(ctx context.Context, refundAddr, ti // the state changes will be discarded. func (k Keeper) distributeFee(ctx context.Context, receiver, refundAccAddress sdk.AccAddress, fee sdk.Coins) { // cache context before trying to distribute fees - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 cacheCtx, writeFn := sdkCtx.CacheContext() err := k.bankKeeper.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, receiver, fee) diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index 92ea87f757c..7a93f8bb00c 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -27,7 +27,7 @@ func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.Pack totalTimeoutFees = totalTimeoutFees.Add(fee.Fee.TimeoutFee...) } } - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeIncentivizedPacket, @@ -47,7 +47,7 @@ func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.Pack // emitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterPayee, @@ -64,7 +64,7 @@ func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID strin // emitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpartyPayee, channelID string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterCounterpartyPayee, @@ -81,7 +81,7 @@ func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpar // emitDistributeFeeEvent emits an event containing a distribution fee and receiver address func emitDistributeFeeEvent(ctx context.Context, receiver string, fee sdk.Coins) { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeDistributeFee, 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/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index e779b071f83..90fca39b99b 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -123,7 +123,7 @@ func (k *Keeper) IsSealed() bool { // can't initialize it in a constructor. 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. - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after 52 upgrade + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after 52 upgrade noGasCtx := sdkCtx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithGasMeter(storetypes.NewInfiniteGasMeter()) // check if memory store has not been initialized yet by checking if initialized flag is nil. @@ -146,7 +146,9 @@ func (k *Keeper) InitMemStore(ctx context.Context) { // set the initialized flag so we don't rerun initialization logic memStore := k.memService.OpenMemoryStore(noGasCtx) - memStore.Set(types.KeyMemInitialized, []byte{1}) + if err := memStore.Set(types.KeyMemInitialized, []byte{1}); err != nil { + panic(err) + } } } @@ -174,7 +176,9 @@ func (k Keeper) InitializeIndex(ctx context.Context, index uint64) error { // set the global index to the passed index store := k.storeService.OpenKVStore(ctx) - store.Set(types.KeyIndex, types.IndexToKey(index)) + if err := store.Set(types.KeyIndex, types.IndexToKey(index)); err != nil { + panic(err) + } return nil } @@ -224,13 +228,17 @@ func (k Keeper) InitializeCapability(ctx context.Context, index uint64, owners t 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 @@ -253,7 +261,7 @@ func (sk ScopedKeeper) NewCapability(ctx context.Context, name string) (*types.C 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 @@ -270,19 +278,25 @@ func (sk ScopedKeeper) NewCapability(ctx context.Context, name string) (*types.C } // 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 := 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 @@ -328,13 +342,17 @@ func (sk ScopedKeeper) ClaimCapability(ctx context.Context, cap *types.Capabilit // 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()) @@ -357,11 +375,15 @@ func (sk ScopedKeeper) ReleaseCapability(ctx context.Context, cap *types.Capabil // 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) @@ -522,6 +544,6 @@ func (sk ScopedKeeper) getOwners(ctx context.Context, cap *types.Capability) *ty } func logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) //TODO: remove after 52 upgrade + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after 52 upgrade return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } 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/testing/simapp/app.go b/testing/simapp/app.go index be93c95ce9e..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, runtime.NewKVStoreService(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) From 12883239d23a842d667ea81a7b261767102790f0 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 28 Aug 2024 15:15:13 +0200 Subject: [PATCH 12/19] build --- e2e/go.mod | 2 +- e2e/go.sum | 4 ++-- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/go.mod b/e2e/go.mod index 50f7d32d120..7fb34e5aeec 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 diff --git a/e2e/go.sum b/e2e/go.sum index 27883a64447..a5ae7090a11 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= diff --git a/simapp/go.mod b/simapp/go.mod index 0e580f421c6..7b8c0af48a1 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 6283843c20b..180e9aa202d 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= From 360e5d5be00a8bb83c9fc40e459e276b70f95645 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Thu, 29 Aug 2024 11:00:14 +0200 Subject: [PATCH 13/19] fix build --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From f72aa4ca761501b2dc71d3df2b7ba1297ef53100 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Thu, 29 Aug 2024 11:06:47 +0200 Subject: [PATCH 14/19] add missing replace --- e2e/go.mod | 2 ++ e2e/go.sum | 2 -- go.mod | 2 +- modules/apps/callbacks/go.mod | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/e2e/go.mod b/e2e/go.mod index 7fb34e5aeec..9b05edf34a7 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -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 a5ae7090a11..a35fe8f54d8 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -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.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/go.mod b/go.mod index 6acdbeafbac..1a6704677ca 100644 --- a/go.mod +++ b/go.mod @@ -199,4 +199,4 @@ 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 +replace github.com/cosmos/ibc-go/modules/capability => ./modules/capability //TODO: remove after capability is tagged diff --git a/modules/apps/callbacks/go.mod b/modules/apps/callbacks/go.mod index e089415e23e..78019c84599 100644 --- a/modules/apps/callbacks/go.mod +++ b/modules/apps/callbacks/go.mod @@ -2,8 +2,6 @@ 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 From 5be578188c5540047afa634c10816e53a46d78fd Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Thu, 29 Aug 2024 11:26:49 +0200 Subject: [PATCH 15/19] fix capability tests --- modules/capability/keeper/keeper_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/capability/keeper/keeper_test.go b/modules/capability/keeper/keeper_test.go index 0b097c1c42b..f5f1a896e41 100644 --- a/modules/capability/keeper/keeper_test.go +++ b/modules/capability/keeper/keeper_test.go @@ -33,8 +33,12 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) memKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) - testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) - suite.ctx = testCtx.Ctx + 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, runtime.NewKVStoreService(key), runtime.NewMemStoreService(memKey)) } From 1c82a812f6f560134e6556b20c62b94cd525a01c Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Thu, 29 Aug 2024 14:42:37 +0300 Subject: [PATCH 16/19] chore(linter): fix linter madness --- modules/core/02-client/keeper/migrations.go | 2 +- modules/core/02-client/migrations/v7/genesis_test.go | 2 +- modules/core/02-client/migrations/v7/store_test.go | 2 +- modules/core/migrations/v7/genesis_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index 637b03b6c1b..d39a756ed93 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - v7 "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" diff --git a/modules/core/02-client/migrations/v7/genesis_test.go b/modules/core/02-client/migrations/v7/genesis_test.go index 52116463fcb..2478f2a00f4 100644 --- a/modules/core/02-client/migrations/v7/genesis_test.go +++ b/modules/core/02-client/migrations/v7/genesis_test.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" ibcclient "github.com/cosmos/ibc-go/v9/modules/core/02-client" - v7 "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" diff --git a/modules/core/02-client/migrations/v7/store_test.go b/modules/core/02-client/migrations/v7/store_test.go index 48232457381..f9e104e823f 100644 --- a/modules/core/02-client/migrations/v7/store_test.go +++ b/modules/core/02-client/migrations/v7/store_test.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" - v7 "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" + "github.com/cosmos/ibc-go/v9/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" diff --git a/modules/core/migrations/v7/genesis_test.go b/modules/core/migrations/v7/genesis_test.go index 8a5e274a863..57ceb04973f 100644 --- a/modules/core/migrations/v7/genesis_test.go +++ b/modules/core/migrations/v7/genesis_test.go @@ -15,7 +15,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" - v7 "github.com/cosmos/ibc-go/v9/modules/core/migrations/v7" + "github.com/cosmos/ibc-go/v9/modules/core/migrations/v7" "github.com/cosmos/ibc-go/v9/modules/core/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) From d45cea5cb77a5c1f99bef8a97fb77aa1143470c1 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Thu, 29 Aug 2024 15:04:15 +0300 Subject: [PATCH 17/19] Apply suggestions from code review --- .../27-interchain-accounts/controller/keeper/account.go | 2 +- modules/apps/29-fee/keeper/escrow.go | 2 +- modules/apps/29-fee/keeper/events.go | 8 ++++---- modules/capability/keeper/keeper.go | 4 ++-- modules/core/04-channel/keeper/packet.go | 2 +- testing/mock/ibc_module.go | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index bf0135d63d6..e0cdd500fc8 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -76,7 +76,7 @@ func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, por } } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 + 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(sdkCtx, msg) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index d91eeb0f756..36571450fb0 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -154,7 +154,7 @@ func (k Keeper) distributePacketFeeOnTimeout(ctx context.Context, refundAddr, ti // the state changes will be discarded. func (k Keeper) distributeFee(ctx context.Context, receiver, refundAccAddress sdk.AccAddress, fee sdk.Coins) { // cache context before trying to distribute fees - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 + 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) diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index 7a93f8bb00c..683339a55ff 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -27,7 +27,7 @@ func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.Pack totalTimeoutFees = totalTimeoutFees.Add(fee.Fee.TimeoutFee...) } } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeIncentivizedPacket, @@ -47,7 +47,7 @@ func emitIncentivizedPacketEvent(ctx context.Context, packetID channeltypes.Pack // emitRegisterPayeeEvent emits an event containing information of a registered payee for a relayer on a particular channel func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterPayee, @@ -64,7 +64,7 @@ func emitRegisterPayeeEvent(ctx context.Context, relayer, payee, channelID strin // emitRegisterCounterpartyPayeeEvent emits an event containing information of a registered counterparty payee for a relayer on a particular channel func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpartyPayee, channelID string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRegisterCounterpartyPayee, @@ -81,7 +81,7 @@ func emitRegisterCounterpartyPayeeEvent(ctx context.Context, relayer, counterpar // emitDistributeFeeEvent emits an event containing a distribution fee and receiver address func emitDistributeFeeEvent(ctx context.Context, receiver string, fee sdk.Coins) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeDistributeFee, diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index 90fca39b99b..5a478ef3e7d 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -123,7 +123,7 @@ func (k *Keeper) IsSealed() bool { // can't initialize it in a constructor. 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. - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after 52 upgrade + 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. @@ -544,6 +544,6 @@ func (sk ScopedKeeper) getOwners(ctx context.Context, cap *types.Capability) *ty } func logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove after 52 upgrade + 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/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 1332cd71d5a..f79c1b83753 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -354,7 +354,7 @@ func (k *Keeper) WriteAcknowledgement( "dst_channel", packet.GetDestChannel(), ) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + 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/testing/mock/ibc_module.go b/testing/mock/ibc_module.go index 281c7de780c..81728670a68 100644 --- a/testing/mock/ibc_module.go +++ b/testing/mock/ibc_module.go @@ -137,7 +137,7 @@ func (im IBCModule) OnRecvPacket(ctx context.Context, channelVersion string, pac panic(err) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvent(NewMockRecvPacketEvent()) if bytes.Equal(MockPacketData, packet.GetData()) { @@ -162,7 +162,7 @@ func (im IBCModule) OnAcknowledgementPacket(ctx context.Context, channelVersion panic(err) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvent(NewMockAckPacketEvent()) return nil @@ -181,7 +181,7 @@ func (im IBCModule) OnTimeoutPacket(ctx context.Context, channelVersion string, panic(err) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 sdkCtx.EventManager().EmitEvent(NewMockTimeoutPacketEvent()) return nil From 199df3915fd8721a47c48134c10b92bece594fa3 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 29 Aug 2024 15:26:03 +0200 Subject: [PATCH 18/19] Update modules/capability/keeper/keeper.go Co-authored-by: DimitrisJim --- modules/capability/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index 5a478ef3e7d..e8dc781830a 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -454,7 +454,7 @@ func (sk ScopedKeeper) GetCapabilityName(ctx context.Context, cap *types.Capabil panic(err) } - return string(bz) // TODO: why the cast? + return string(bz) } // GetOwners all the Owners that own the capability associated with the name this ScopedKeeper uses From de65c01b62254ca160c9d69793099d875d31b6f1 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 30 Aug 2024 11:55:04 +0200 Subject: [PATCH 19/19] nit: has -> isInitialized --- modules/capability/keeper/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index e8dc781830a..45e30d4ea15 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -155,11 +155,11 @@ func (k *Keeper) InitMemStore(ctx context.Context) { // IsInitialized returns true if the keeper is properly initialized, and false otherwise. func (k *Keeper) IsInitialized(ctx context.Context) bool { memStore := k.memService.OpenMemoryStore(ctx) - has, err := memStore.Has(types.KeyMemInitialized) + isInitialized, err := memStore.Has(types.KeyMemInitialized) if err != nil { panic(err) } - return has + return isInitialized } // InitializeIndex sets the index to one (or greater) in InitChain according