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

refactor: no longer removing active channel mapping on close channel #730

Merged
merged 10 commits into from
Jan 14, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
err = cbs.OnChanCloseConfirm(
suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

activeChannelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().False(found)
suite.Require().Empty(activeChannelID)
} else {
suite.Require().Error(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
)

Expand Down Expand Up @@ -35,12 +36,22 @@ func (suite *KeeperTestSuite) TestInitInterchainAccount() {
false,
},
{
"MsgChanOpenInit fails - channel is already active",
"MsgChanOpenInit fails - channel is already active & in state OPEN",
func() {
portID, err := icatypes.NewControllerPortID(TestOwnerAddress)
suite.Require().NoError(err)

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
channel := channeltypes.Channel{
State: channeltypes.OPEN,
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: string("version"),
}
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel)
},
false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (k Keeper) OnChanOpenInit(
return sdkerrors.Wrapf(icatypes.ErrInvalidVersion, "expected %s, got %s", icatypes.Version, metadata.Version)
}

activeChannelID, found := k.GetActiveChannelID(ctx, portID)
activeChannelID, found := k.HasActiveChannel(ctx, portID)
if found {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "existing active channel %s for portID %s", activeChannelID, portID)
}
Expand Down Expand Up @@ -105,8 +105,6 @@ func (k Keeper) OnChanCloseConfirm(
channelID string,
) error {

k.DeleteActiveChannelID(ctx, portID)

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
"channel is already active",
func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
channel := channeltypes.Channel{
State: channeltypes.OPEN,
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: string("version"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the TestVersion variable here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

}
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel)
},
false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
)

Expand Down Expand Up @@ -101,7 +102,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}

// GetActiveChannelID retrieves the active channelID from the store keyed by the provided portID
// GetActiveChannelID retrieves the active channelID from the store key by the provided portID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this comment should stay the same, but probably add a comma so it reads correctly.

Suggested change
// GetActiveChannelID retrieves the active channelID from the store key by the provided portID
// GetActiveChannelID retrieves the active channelID from the store, keyed by the provided portID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I've updated in in two places.

func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := icatypes.KeyActiveChannel(portID)
Expand All @@ -113,6 +114,21 @@ func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool
return string(store.Get(key)), true
}

// HasActiveChannel retrieves the active channelID from the store key by the provided portID & checks if the channel in question is in state OPEN
func (k Keeper) HasActiveChannel(ctx sdk.Context, portID string) (string, bool) {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
store := ctx.KVStore(k.storeKey)
key := icatypes.KeyActiveChannel(portID)

channelID := string(store.Get(key))
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

just a suggestion

if channel.State == channeltypes.OPEN && found {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
return channelID, true
}

return "", false
}

// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated port identifiers
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
store := ctx.KVStore(k.storeKey)
Expand Down
4 changes: 0 additions & 4 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() {
err = cbs.OnChanCloseConfirm(
suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

activeChannelID, found := suite.chainB.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().False(found)
suite.Require().Empty(activeChannelID)
} else {
suite.Require().Error(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func (k Keeper) OnChanCloseConfirm(
channelID string,
) error {

k.DeleteActiveChannelID(ctx, portID)

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,8 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() {
err = suite.chainB.GetSimApp().ICAHostKeeper.OnChanCloseConfirm(suite.chainB.GetContext(),
path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

activeChannelID, found := suite.chainB.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().False(found)
suite.Require().Empty(activeChannelID)
} else {
suite.Require().Error(err)
}
Expand Down