diff --git a/modules/core/04-channel/v2/keeper/export_test.go b/modules/core/04-channel/v2/keeper/export_test.go index 6da7c89c873..002bc6d8d41 100644 --- a/modules/core/04-channel/v2/keeper/export_test.go +++ b/modules/core/04-channel/v2/keeper/export_test.go @@ -7,10 +7,17 @@ package keeper import ( "context" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) +// ChannelStore is a wrapper around channelStore to allow its usage during testing. +func (k Keeper) ChannelStore(ctx context.Context) storetypes.KVStore { + return k.channelStore(ctx) +} + func (k *Keeper) SendPacketTest( ctx context.Context, sourceChannel string, diff --git a/modules/core/04-channel/v2/keeper/keeper.go b/modules/core/04-channel/v2/keeper/keeper.go index febc06a1f24..ebf512063b2 100644 --- a/modules/core/04-channel/v2/keeper/keeper.go +++ b/modules/core/04-channel/v2/keeper/keeper.go @@ -18,7 +18,6 @@ import ( channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" "github.com/cosmos/ibc-go/v9/modules/core/api" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -55,21 +54,28 @@ func (Keeper) Logger(ctx context.Context) log.Logger { return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) } -func (k Keeper) ChannelStore(ctx context.Context, channelID string) storetypes.KVStore { - channelPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyChannelPrefix, channelID)) +// channelStore returns the KV store under which channels are stored. +func (k Keeper) channelStore(ctx context.Context) storetypes.KVStore { + channelPrefix := []byte(fmt.Sprintf("%s/", types.ChannelPrefix)) return prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), channelPrefix) } +// creatorStore returns the KV store under which creators are stored. +func (k Keeper) creatorStore(ctx context.Context) storetypes.KVStore { + creatorPrefix := []byte(fmt.Sprintf("%s/", types.CreatorPrefix)) + return prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), creatorPrefix) +} + // SetChannel sets the Channel for a given channel identifier. func (k *Keeper) SetChannel(ctx context.Context, channelID string, channel types.Channel) { bz := k.cdc.MustMarshal(&channel) - k.ChannelStore(ctx, channelID).Set([]byte(types.ChannelKey), bz) + k.channelStore(ctx).Set([]byte(channelID), bz) } // GetChannel gets the Channel for a given channel identifier. func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.Channel, bool) { - store := k.ChannelStore(ctx, channelID) - bz := store.Get([]byte(types.ChannelKey)) + store := k.channelStore(ctx) + bz := store.Get([]byte(channelID)) if len(bz) == 0 { return types.Channel{}, false } @@ -81,13 +87,13 @@ func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.Channe // HasChannel returns true if a Channel exists for a given channel identifier, otherwise false. func (k *Keeper) HasChannel(ctx context.Context, channelID string) bool { - store := k.ChannelStore(ctx, channelID) - return store.Has([]byte(types.ChannelKey)) + store := k.channelStore(ctx) + return store.Has([]byte(channelID)) } // GetCreator returns the creator of the channel. func (k *Keeper) GetCreator(ctx context.Context, channelID string) (string, bool) { - bz := k.ChannelStore(ctx, channelID).Get([]byte(types.CreatorKey)) + bz := k.creatorStore(ctx).Get([]byte(channelID)) if len(bz) == 0 { return "", false } @@ -97,12 +103,12 @@ func (k *Keeper) GetCreator(ctx context.Context, channelID string) (string, bool // SetCreator sets the creator of the channel. func (k *Keeper) SetCreator(ctx context.Context, channelID, creator string) { - k.ChannelStore(ctx, channelID).Set([]byte(types.CreatorKey), []byte(creator)) + k.creatorStore(ctx).Set([]byte(channelID), []byte(creator)) } // DeleteCreator deletes the creator associated with the channel. func (k *Keeper) DeleteCreator(ctx context.Context, channelID string) { - k.ChannelStore(ctx, channelID).Delete([]byte(types.CreatorKey)) + k.creatorStore(ctx).Delete([]byte(channelID)) } // GetPacketReceipt returns the packet receipt from the packet receipt path based on the channelID and sequence. diff --git a/modules/core/04-channel/v2/keeper/msg_server_test.go b/modules/core/04-channel/v2/keeper/msg_server_test.go index 34dff03cba7..58dc3126dbd 100644 --- a/modules/core/04-channel/v2/keeper/msg_server_test.go +++ b/modules/core/04-channel/v2/keeper/msg_server_test.go @@ -53,7 +53,7 @@ func (suite *KeeperTestSuite) TestRegisterCounterparty() { "failure: channel must already exist", func() { suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID) - suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(types.ChannelKey)) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext()).Delete([]byte(path.EndpointA.ChannelID)) }, types.ErrChannelNotFound, }, diff --git a/modules/core/04-channel/v2/types/keys.go b/modules/core/04-channel/v2/types/keys.go index f751a92b3f1..9b636340e38 100644 --- a/modules/core/04-channel/v2/types/keys.go +++ b/modules/core/04-channel/v2/types/keys.go @@ -4,13 +4,13 @@ const ( // SubModuleName defines the channelv2 module name. SubModuleName = "channelv2" - // ChannelKey is the key used to store channels in the channel store. - // the channel key is imported from types instead of host because - // the channel key is not a part of the ics-24 host specification - ChannelKey = "channel" + // ChannelPrefix is the prefix under which all v2 channels are stored. + // It is imported from types since it is not part of the ics-24 host + // specification. + ChannelPrefix = "channels" - // CreatorKey is the key used to store the channel creator in the channel store - // the creator key is imported from types instead of host because - // the creator key is not a part of the ics-24 host specification - CreatorKey = "creator" + // CreatorPrefix is the prefix under which all v2 channel creators are stored. + // It is imported from types since it is not part of the ics-24 host + // specification. + CreatorPrefix = "creators" )