From 5d9e7db69913513f25ed88ecf3d44f17e767a2e9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 2 Feb 2022 16:11:58 +0100 Subject: [PATCH] refactor: active channel key format (#823) (#832) ## Description Updating the store key format for active channels based on @AdityaSripal comment. closes: [Adityas comment](https://github.com/cosmos/ibc-go/pull/814#pullrequestreview-870330601) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x//spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes (cherry picked from commit 4c28c1ca7503a9c0603202560097fadce70d4cf2) Co-authored-by: Sean King --- .../27-interchain-accounts/controller/keeper/keeper.go | 8 ++++---- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 8 ++++---- modules/apps/27-interchain-accounts/types/keys.go | 4 ++-- modules/apps/27-interchain-accounts/types/keys_test.go | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index fc643cea30d..7216ccb7fa8 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -105,7 +105,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability // 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) - key := icatypes.KeyActiveChannel(connectionID, portID) + key := icatypes.KeyActiveChannel(portID, connectionID) if !store.Has(key) { return "", false @@ -141,8 +141,8 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { keySplit := strings.Split(string(iterator.Key()), "/") ch := icatypes.ActiveChannel{ - ConnectionId: keySplit[1], - PortId: keySplit[2], + ConnectionId: keySplit[2], + PortId: keySplit[1], ChannelId: string(iterator.Value()), } @@ -155,7 +155,7 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { // SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) { store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyActiveChannel(connectionID, portID), []byte(channelID)) + 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 diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 598c68789fc..181153a0fb5 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -94,7 +94,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability // 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) - key := icatypes.KeyActiveChannel(connectionID, portID) + key := icatypes.KeyActiveChannel(portID, connectionID) if !store.Has(key) { return "", false @@ -130,8 +130,8 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { keySplit := strings.Split(string(iterator.Key()), "/") ch := icatypes.ActiveChannel{ - ConnectionId: keySplit[1], - PortId: keySplit[2], + ConnectionId: keySplit[2], + PortId: keySplit[1], ChannelId: string(iterator.Value()), } @@ -144,7 +144,7 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { // SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) { store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyActiveChannel(connectionID, portID), []byte(channelID)) + 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 diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index 581aea8ae37..c2bde682551 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -39,8 +39,8 @@ var ( ) // KeyActiveChannel creates and returns a new key used for active channels store operations -func KeyActiveChannel(connectionID, portID string) []byte { - return []byte(fmt.Sprintf("%s/%s/%s", ActiveChannelKeyPrefix, connectionID, portID)) +func KeyActiveChannel(portID, connectionID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", ActiveChannelKeyPrefix, portID, connectionID)) } // KeyOwnerAccount creates and returns a new key used for interchain account store operations diff --git a/modules/apps/27-interchain-accounts/types/keys_test.go b/modules/apps/27-interchain-accounts/types/keys_test.go index 4fe7b5a813f..02da485bf32 100644 --- a/modules/apps/27-interchain-accounts/types/keys_test.go +++ b/modules/apps/27-interchain-accounts/types/keys_test.go @@ -5,8 +5,8 @@ import ( ) func (suite *TypesTestSuite) TestKeyActiveChannel() { - key := types.KeyActiveChannel("connection-id", "port-id") - suite.Require().Equal("activeChannel/connection-id/port-id", string(key)) + key := types.KeyActiveChannel("port-id", "connection-id") + suite.Require().Equal("activeChannel/port-id/connection-id", string(key)) } func (suite *TypesTestSuite) TestKeyOwnerAccount() {