Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HasCapability private #3303

Merged
merged 10 commits into from
Apr 14, 2023
Merged
2 changes: 1 addition & 1 deletion docs/ibc/apps/bindports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.HasCapability(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)
Expand Down
4 changes: 2 additions & 2 deletions docs/ibc/apps/keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewKeeper(
}
}

// 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 {
// 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID,
}

switch {
case k.portKeeper.IsBound(ctx, portID) && !k.HasCapability(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):
capability := k.BindPort(ctx, portID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ 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.HasCapability(ctx, portID) {
capability := keeper.BindPort(ctx, portID)
if err := keeper.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil {
if !keeper.hasCapability(ctx, portID) {
cap := keeper.BindPort(ctx, portID)
expertdicer marked this conversation as resolved.
Show resolved Hide resolved
if err := keeper.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ 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 owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
// 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (suite *KeeperTestSuite) TestHasCapability() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

hasCapability := suite.chainA.GetSimApp().ICAControllerKeeper.HasCapability(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID)
suite.Require().True(hasCapability)
}

func (suite *KeeperTestSuite) TestGetAllPorts() {
suite.SetupTest()

Expand Down
10 changes: 10 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/export_test.go
expertdicer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// SetParams sets the total set of params.
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
return k.hasCapability(ctx, portID)
}
6 changes: 3 additions & 3 deletions modules/apps/27-interchain-accounts/host/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ 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.HasCapability(ctx, state.Port) {
capability := keeper.BindPort(ctx, state.Port)
if err := keeper.ClaimCapability(ctx, capability, host.PortPath(state.Port)); err != nil {
if !keeper.hasCapability(ctx, state.Port) {
cap := keeper.BindPort(ctx, state.Port)
expertdicer marked this conversation as resolved.
Show resolved Hide resolved
if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.Port)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ 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 owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
// 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
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.HasCapability(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)
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ 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 owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
// 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
}
Expand Down