Skip to content

Commit b6921cd

Browse files
fix: ica handshake reopening channel - use GetAppVersion in favour of channel.Version (backport #2302) (#2357)
* fix: ica handshake reopening channel - use `GetAppVersion` in favour of `channel.Version` (#2302) * adding unwrapping of channel version to ica controller handshake reopening flow * adding changelog * adding ics4Wrapper to ics27 host submodule, handling unwrapping channel version in OnChanOpenTry handshake cb * updating changelog Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> (cherry picked from commit 9e6246f) # Conflicts: # CHANGELOG.md # modules/apps/27-interchain-accounts/host/keeper/keeper.go * fixing imports and interface type Co-authored-by: Damian Nolan <damiannolan@gmail.com>
1 parent e4ff2c6 commit b6921cd

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4949
* (core/ante) [\#1820](https://github.com/cosmos/ibc-go/pull/1418) `RedundancyDecorator` has been renamed to `RedundantRelayDecorator` to make the name for explicit.
5050
* (testing) [\#1418](https://github.com/cosmos/ibc-go/pull/1418) `MockIBCApp` has been renamed to `IBCApp` and `MockEmptyAcknowledgement` has been renamed to `EmptyAcknowledgement` to comply with go linting rules
5151
* (apps/27-interchain-accounts) [\#2058](https://github.com/cosmos/ibc-go/pull/2058) Added `MessageRouter` interface and replaced `*baseapp.MsgServiceRouter` with it. The controller and host keepers of apps/27-interchain-accounts have been updated to use it.
52+
* (apps/27-interchain-accounts)[\#2302](https://github.com/cosmos/ibc-go/pull/2302) Handle unwrapping of channel version in interchain accounts channel reopening handshake flow. The `host` submodule `Keeper` now requires an `ICS4Wrapper` similarly to the `controller` submodule.
5253
* (apps/27-interchain-accounts) [\#2035](https://github.com/cosmos/ibc-go/pull/2035) Interchain accounts host and controller Keepers now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper.
5354

5455
### State Machine Breaking

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ func (k Keeper) OnChanOpenInit(
7070
return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID)
7171
}
7272

73-
if !icatypes.IsPreviousMetadataEqual(channel.Version, metadata) {
73+
appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID)
74+
if !found {
75+
panic(fmt.Sprintf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID))
76+
}
77+
78+
if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) {
7479
return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version")
7580
}
7681
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/cosmos/cosmos-sdk/baseapp"
87
"github.com/cosmos/cosmos-sdk/codec"
98
storetypes "github.com/cosmos/cosmos-sdk/store/types"
109
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -37,7 +36,7 @@ type Keeper struct {
3736
func NewKeeper(
3837
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
3938
ics4Wrapper icatypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
40-
scopedKeeper icatypes.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter,
39+
scopedKeeper icatypes.ScopedKeeper, msgRouter icatypes.MessageRouter,
4140
) Keeper {
4241
// set KeyTable if it has not already been set
4342
if !paramSpace.HasKeyTable() {

modules/apps/27-interchain-accounts/host/ibc_module_test.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types"
1515
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
16+
feetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
1617
clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
1718
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
1819
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
@@ -77,7 +78,7 @@ func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) erro
7778

7879
channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(endpoint.Chain.GetContext())
7980

80-
if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, TestVersion); err != nil {
81+
if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, endpoint.ChannelConfig.Version); err != nil {
8182
return err
8283
}
8384

@@ -618,6 +619,18 @@ func (suite *InterchainAccountsTestSuite) fundICAWallet(ctx sdk.Context, portID
618619
// A new channel will be opened for the controller portID. The interchain account address should remain unchanged.
619620
func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose() {
620621
path := NewICAPath(suite.chainA, suite.chainB)
622+
623+
// use a fee enabled version to cover unwrapping channel version code paths
624+
feeMetadata := feetypes.Metadata{
625+
FeeVersion: feetypes.Version,
626+
AppVersion: TestVersion,
627+
}
628+
629+
feeICAVersion := string(feetypes.ModuleCdc.MustMarshalJSON(&feeMetadata))
630+
631+
path.EndpointA.ChannelConfig.Version = feeICAVersion
632+
path.EndpointB.ChannelConfig.Version = feeICAVersion
633+
621634
suite.coordinator.SetupConnections(path)
622635

623636
err := SetupICAPath(path, TestOwnerAddress)

modules/apps/27-interchain-accounts/host/keeper/handshake.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ func (k Keeper) OnChanOpenTry(
5959
return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID)
6060
}
6161

62-
if !icatypes.IsPreviousMetadataEqual(channel.Version, metadata) {
62+
appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID)
63+
if !found {
64+
panic(fmt.Sprintf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID))
65+
}
66+
67+
if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) {
6368
return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version")
6469
}
6570
}

modules/apps/27-interchain-accounts/host/keeper/keeper.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/cosmos/cosmos-sdk/baseapp"
87
"github.com/cosmos/cosmos-sdk/codec"
98
storetypes "github.com/cosmos/cosmos-sdk/store/types"
109
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -24,6 +23,7 @@ type Keeper struct {
2423
cdc codec.BinaryCodec
2524
paramSpace paramtypes.Subspace
2625

26+
ics4Wrapper icatypes.ICS4Wrapper
2727
channelKeeper icatypes.ChannelKeeper
2828
portKeeper icatypes.PortKeeper
2929
accountKeeper icatypes.AccountKeeper
@@ -36,8 +36,8 @@ type Keeper struct {
3636
// NewKeeper creates a new interchain accounts host Keeper instance
3737
func NewKeeper(
3838
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
39-
channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
40-
accountKeeper icatypes.AccountKeeper, scopedKeeper icatypes.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter,
39+
ics4Wrapper icatypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
40+
accountKeeper icatypes.AccountKeeper, scopedKeeper icatypes.ScopedKeeper, msgRouter icatypes.MessageRouter,
4141
) Keeper {
4242
// ensure ibc interchain accounts module account is set
4343
if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil {
@@ -53,6 +53,7 @@ func NewKeeper(
5353
storeKey: key,
5454
cdc: cdc,
5555
paramSpace: paramSpace,
56+
ics4Wrapper: ics4Wrapper,
5657
channelKeeper: channelKeeper,
5758
portKeeper: portKeeper,
5859
accountKeeper: accountKeeper,
@@ -90,6 +91,11 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
9091
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
9192
}
9293

94+
// GetAppVersion calls the ICS4Wrapper GetAppVersion function.
95+
func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
96+
return k.ics4Wrapper.GetAppVersion(ctx, portID, channelID)
97+
}
98+
9399
// GetActiveChannelID retrieves the active channelID from the store keyed by the provided connectionID and portID
94100
func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) {
95101
store := ctx.KVStore(k.storeKey)

testing/simapp/app.go

+1
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ func NewSimApp(
393393
// ICA Host keeper
394394
app.ICAHostKeeper = icahostkeeper.NewKeeper(
395395
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
396+
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
396397
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
397398
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
398399
)

0 commit comments

Comments
 (0)