Skip to content

Commit 6d95456

Browse files
refactor: RegisterInterchainAccount (#814) (#835)
## Description closes: #802 --- 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/<module>/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 fed6a86) Co-authored-by: Sean King <seantking@users.noreply.github.com>
1 parent 5d9e7db commit 6d95456

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

modules/apps/27-interchain-accounts/controller/keeper/account.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner s
2121
return err
2222
}
2323

24-
if k.portKeeper.IsBound(ctx, portID) {
25-
return sdkerrors.Wrap(icatypes.ErrPortAlreadyBound, portID)
24+
// if there is an active channel for this portID / connectionID return an error
25+
activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID)
26+
if found {
27+
return sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s on connection %s for owner %s", activeChannelID, portID, connectionID, owner)
2628
}
2729

28-
cap := k.BindPort(ctx, portID)
29-
if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
30-
return sdkerrors.Wrap(err, "unable to bind to newly generated portID")
30+
switch {
31+
case k.portKeeper.IsBound(ctx, portID) && !k.IsBound(ctx, portID):
32+
return sdkerrors.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID)
33+
case !k.portKeeper.IsBound(ctx, portID):
34+
cap := k.BindPort(ctx, portID)
35+
if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
36+
return sdkerrors.Wrapf(err, "unable to bind to newly generated portID: %s", portID)
37+
}
3138
}
3239

3340
connectionEnd, err := k.channelKeeper.GetConnection(ctx, connectionID)

modules/apps/27-interchain-accounts/controller/keeper/account_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keeper_test
33
import (
44
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
55
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
6+
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
67
ibctesting "github.com/cosmos/ibc-go/v3/testing"
78
)
89

@@ -22,9 +23,11 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
2223
"success", func() {}, true,
2324
},
2425
{
25-
"port is already bound",
26+
"port is already bound for owner but capability is claimed by another module",
2627
func() {
27-
suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
28+
cap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
29+
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), cap, host.PortPath(TestPortID))
30+
suite.Require().NoError(err)
2831
},
2932
false,
3033
},
@@ -56,7 +59,6 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
5659
false,
5760
},
5861
}
59-
6062
for _, tc := range testCases {
6163
tc := tc
6264

@@ -77,7 +79,6 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
7779
} else {
7880
suite.Require().Error(err)
7981
}
80-
8182
})
8283
}
8384
}

modules/apps/27-interchain-accounts/types/errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var (
1313
ErrInvalidRoute = sdkerrors.Register(ModuleName, 7, "invalid route")
1414
ErrInterchainAccountNotFound = sdkerrors.Register(ModuleName, 8, "interchain account not found")
1515
ErrInterchainAccountAlreadySet = sdkerrors.Register(ModuleName, 9, "interchain account is already set")
16-
ErrActiveChannelNotFound = sdkerrors.Register(ModuleName, 10, "no active channel for this owner")
17-
ErrActiveChannelAlreadySet = sdkerrors.Register(ModuleName, 11, "active channel already set for this owner")
16+
ErrActiveChannelAlreadySet = sdkerrors.Register(ModuleName, 10, "active channel already set for this owner")
17+
ErrActiveChannelNotFound = sdkerrors.Register(ModuleName, 11, "no active channel for this owner")
1818
ErrInvalidVersion = sdkerrors.Register(ModuleName, 12, "invalid interchain accounts version")
1919
ErrInvalidAccountAddress = sdkerrors.Register(ModuleName, 13, "invalid account address")
2020
ErrUnsupported = sdkerrors.Register(ModuleName, 14, "interchain account does not support this action")

0 commit comments

Comments
 (0)