From d9dcbe1fe709d0b6576009793d5b32d28635eb4f Mon Sep 17 00:00:00 2001 From: expertdicer Date: Wed, 8 Mar 2023 11:52:34 +0700 Subject: [PATCH 1/5] rename IsBound to HasCapability --- .../27-interchain-accounts/controller/keeper/account.go | 2 +- .../27-interchain-accounts/controller/keeper/genesis.go | 2 +- .../apps/27-interchain-accounts/controller/keeper/keeper.go | 4 ++-- .../27-interchain-accounts/controller/keeper/keeper_test.go | 6 +++--- modules/apps/27-interchain-accounts/host/keeper/genesis.go | 2 +- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 4 ++-- .../apps/27-interchain-accounts/host/keeper/keeper_test.go | 6 +++--- modules/apps/transfer/keeper/genesis.go | 2 +- modules/apps/transfer/keeper/keeper.go | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 5044e50b962..71c6947158d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -58,7 +58,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, } switch { - case k.portKeeper.IsBound(ctx, portID) && !k.IsBound(ctx, portID): + case k.portKeeper.IsBound(ctx, portID) && !k.HasCapability(ctx, portID): return "", errorsmod.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) case !k.portKeeper.IsBound(ctx, portID): cap := k.BindPort(ctx, portID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index ea5cbd822cd..a018d5d8c14 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -12,7 +12,7 @@ import ( // InitGenesis initializes the interchain accounts controller application state from a provided genesis state func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) { for _, portID := range state.Ports { - if !keeper.IsBound(ctx, portID) { + if !keeper.HasCapability(ctx, portID) { cap := keeper.BindPort(ctx, portID) if err := keeper.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 872186ebe7f..62b38be0612 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -98,8 +98,8 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } -// IsBound checks if the interchain account controller module is already bound to the desired port -func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { +// HasCapability checks if the interchain account controller module is already bound to the desired port +func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } 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 0583912165b..9f80aa507e0 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -106,7 +106,7 @@ func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } -func (suite *KeeperTestSuite) TestIsBound() { +func (suite *KeeperTestSuite) TestHasCapability() { suite.SetupTest() path := NewICAPath(suite.chainA, suite.chainB) @@ -115,8 +115,8 @@ func (suite *KeeperTestSuite) TestIsBound() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - isBound := suite.chainA.GetSimApp().ICAControllerKeeper.IsBound(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().True(isBound) + hasCapability := suite.chainA.GetSimApp().ICAControllerKeeper.HasCapability(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + suite.Require().True(hasCapability) } func (suite *KeeperTestSuite) TestGetAllPorts() { diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 6575bac1713..6a31978d589 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -12,7 +12,7 @@ import ( // InitGenesis initializes the interchain accounts host application state from a provided genesis state func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisState) { - if !keeper.IsBound(ctx, state.Port) { + if !keeper.HasCapability(ctx, state.Port) { cap := keeper.BindPort(ctx, state.Port) if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.Port)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 506d7be6832..7e659bbfa11 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -78,8 +78,8 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } -// IsBound checks if the interchain account host module is already bound to the desired port -func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { +// HasCapability checks if the interchain account host module is already bound to the desired port +func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } 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 c250e046d67..e6dad73e5b2 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -106,7 +106,7 @@ func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } -func (suite *KeeperTestSuite) TestIsBound() { +func (suite *KeeperTestSuite) TestHasCapability() { suite.SetupTest() path := NewICAPath(suite.chainA, suite.chainB) @@ -115,8 +115,8 @@ func (suite *KeeperTestSuite) TestIsBound() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - isBound := suite.chainB.GetSimApp().ICAHostKeeper.IsBound(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID) - suite.Require().True(isBound) + hasCapability := suite.chainB.GetSimApp().ICAHostKeeper.HasCapability(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID) + suite.Require().True(hasCapability) } func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { diff --git a/modules/apps/transfer/keeper/genesis.go b/modules/apps/transfer/keeper/genesis.go index ce0a45155e1..89ce4697624 100644 --- a/modules/apps/transfer/keeper/genesis.go +++ b/modules/apps/transfer/keeper/genesis.go @@ -18,7 +18,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { // Only try to bind to port if it is not already bound, since we may already own // port capability from capability InitGenesis - if !k.IsBound(ctx, state.PortId) { + if !k.HasCapability(ctx, state.PortId) { // transfer module binds to the transfer port on InitChain // and claims the returned capability err := k.BindPort(ctx, state.PortId) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 0c2546c6b3a..066898f544e 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -64,8 +64,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName+"-"+types.ModuleName) } -// IsBound checks if the transfer module is already bound to the desired port -func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { +// HasCapability checks if the transfer module is already bound to the desired port +func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } From 38c92964d18214d3d7665e2f3e114f12263bb1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= <67097720+expertdicer@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:57:25 +0700 Subject: [PATCH 2/5] Update modules/apps/27-interchain-accounts/controller/keeper/keeper.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/27-interchain-accounts/controller/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 62b38be0612..edb9a69299e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -98,7 +98,7 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } -// HasCapability checks if the interchain account controller module is already bound to the desired port +// 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)) return ok From 5a3855ae23857809a61cf6e4f48fd5f7fce3d8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= <67097720+expertdicer@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:57:33 +0700 Subject: [PATCH 3/5] Update modules/apps/27-interchain-accounts/host/keeper/keeper.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 7e659bbfa11..d89a7ecbee5 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -78,7 +78,7 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } -// HasCapability checks if the interchain account host module is already bound to the desired port +// 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)) return ok From 7aeb8b1514c938b01db047371b4fb2e4ed511f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= <67097720+expertdicer@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:57:38 +0700 Subject: [PATCH 4/5] Update modules/apps/transfer/keeper/keeper.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/transfer/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 066898f544e..49f828f021e 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -64,7 +64,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName+"-"+types.ModuleName) } -// HasCapability checks if the transfer module is already bound to the desired port +// 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)) return ok From ae04452d86851ba51afe2d3154bdcaf44a57e4b3 Mon Sep 17 00:00:00 2001 From: expertdicer Date: Mon, 13 Mar 2023 16:15:12 +0700 Subject: [PATCH 5/5] docs --- docs/ibc/apps.md | 2 +- docs/ibc/apps/bindports.md | 2 +- docs/ibc/apps/keeper.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ibc/apps.md b/docs/ibc/apps.md index be0457f4fe6..0d80d412337 100644 --- a/docs/ibc/apps.md +++ b/docs/ibc/apps.md @@ -191,7 +191,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState // Only try to bind to port if it is not already bound, since we may already own // port capability from capability InitGenesis - if !isBound(ctx, state.PortID) { + if !hasCapability(ctx, state.PortID) { // module binds to desired ports on InitChain // and claims returned capabilities cap1 := keeper.IBCPortKeeper.BindPort(ctx, port1) diff --git a/docs/ibc/apps/bindports.md b/docs/ibc/apps/bindports.md index bf35fc0df0d..07bdff224e1 100644 --- a/docs/ibc/apps/bindports.md +++ b/docs/ibc/apps/bindports.md @@ -79,7 +79,7 @@ Currently, ports must be bound on app initialization. In order to bind modules t // Only try to bind to port if it is not already bound, since we may already own // port capability from capability InitGenesis - if !k.IsBound(ctx, state.PortId) { + if !k.HasCapability(ctx, state.PortId) { // transfer module binds to the transfer port on InitChain // and claims the returned capability err := k.BindPort(ctx, state.PortId) diff --git a/docs/ibc/apps/keeper.md b/docs/ibc/apps/keeper.md index 809ac46d8d7..f108d0b9f32 100644 --- a/docs/ibc/apps/keeper.md +++ b/docs/ibc/apps/keeper.md @@ -48,8 +48,8 @@ func NewKeeper( } } -// IsBound checks if the IBC app module is already bound to the desired port -func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { +// HasCapability checks if the IBC app 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)) return ok }