diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 74069f4ba83..667b8b9a4ee 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -311,11 +311,12 @@ An InterchainAccount is defined as a BaseAccount & the address of the account ow ### ActiveChannel -ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel +ActiveChannel contains a connection ID, port ID and associated active channel ID | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | +| `connection_id` | [string](#string) | | | | `port_id` | [string](#string) | | | | `channel_id` | [string](#string) | | | diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account_test.go b/modules/apps/27-interchain-accounts/controller/keeper/account_test.go index cfbc9d2312a..8086726bdc2 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account_test.go @@ -41,7 +41,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { portID, err := icatypes.NewControllerPortID(TestOwnerAddress) suite.Require().NoError(err) - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID) + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID) counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) channel := channeltypes.Channel{ diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index af7265495f1..eab7687236e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -21,7 +21,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesi } for _, ch := range state.ActiveChannels { - keeper.SetActiveChannelID(ctx, ch.PortId, ch.ChannelId) + keeper.SetActiveChannelID(ctx, ch.ConnectionId, ch.PortId, ch.ChannelId) } for _, acc := range state.InterchainAccounts { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go index 341db272548..7a41608d38f 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis_test.go @@ -13,8 +13,9 @@ func (suite *KeeperTestSuite) TestInitGenesis() { genesisState := icatypes.ControllerGenesisState{ ActiveChannels: []icatypes.ActiveChannel{ { - PortId: TestPortID, - ChannelId: ibctesting.FirstChannelID, + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + ChannelId: ibctesting.FirstChannelID, }, }, InterchainAccounts: []icatypes.RegisteredInterchainAccount{ @@ -29,7 +30,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper, genesisState) - channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), TestPortID) + channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) suite.Require().True(found) suite.Require().Equal(ibctesting.FirstChannelID, channelID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index b2bf1a31357..533bb8d89da 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -50,7 +50,7 @@ func (k Keeper) OnChanOpenInit( return err } - activeChannelID, found := k.GetOpenActiveChannel(ctx, portID) + activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionHops[0], portID) if found { return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "existing active channel %s for portID %s", activeChannelID, portID) } @@ -92,7 +92,7 @@ func (k Keeper) OnChanOpenAck( return sdkerrors.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be empty") } - k.SetActiveChannelID(ctx, portID, channelID) + k.SetActiveChannelID(ctx, metadata.ControllerConnectionId, portID, channelID) k.SetInterchainAccountAddress(ctx, metadata.ControllerConnectionId, portID, metadata.Address) return nil diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index c32547b7e81..3a810a8790a 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -110,7 +110,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { { "channel is already active", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) channel := channeltypes.Channel{ @@ -279,7 +279,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() { if tc.expPass { suite.Require().NoError(err) - activeChannelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + activeChannelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) suite.Require().Equal(path.EndpointA.ChannelID, activeChannelID) @@ -326,7 +326,7 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { err = suite.chainB.GetSimApp().ICAControllerKeeper.OnChanCloseConfirm(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - activeChannelID, found := suite.chainB.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID) + activeChannelID, found := suite.chainB.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointB.ChannelConfig.PortID) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 20e77717382..fc643cea30d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -102,10 +102,10 @@ 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 -func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool) { +// GetActiveChannelID retrieves the active channelID from the store, keyed by the provided connectionID and portID +func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := icatypes.KeyActiveChannel(portID) + key := icatypes.KeyActiveChannel(connectionID, portID) if !store.Has(key) { return "", false @@ -114,9 +114,9 @@ func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool return string(store.Get(key)), true } -// GetOpenActiveChannel retrieves the active channelID from the store, keyed by the provided portID & checks if the channel in question is in state OPEN -func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, portID string) (string, bool) { - channelID, found := k.GetActiveChannelID(ctx, portID) +// GetOpenActiveChannel retrieves the active channelID from the store, keyed by the provided connectionID and portID & checks if the channel in question is in state OPEN +func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID string) (string, bool) { + channelID, found := k.GetActiveChannelID(ctx, connectionID, portID) if !found { return "", false } @@ -130,7 +130,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, portID string) (string, bo return "", false } -// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated port identifiers +// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated connection and port identifiers func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix)) @@ -141,8 +141,9 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { keySplit := strings.Split(string(iterator.Key()), "/") ch := icatypes.ActiveChannel{ - PortId: keySplit[1], - ChannelId: string(iterator.Value()), + ConnectionId: keySplit[1], + PortId: keySplit[2], + ChannelId: string(iterator.Value()), } activeChannels = append(activeChannels, ch) @@ -151,15 +152,15 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { return activeChannels } -// SetActiveChannelID stores the active channelID, keyed by the provided portID -func (k Keeper) SetActiveChannelID(ctx sdk.Context, portID, channelID string) { +// SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID +func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) { store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyActiveChannel(portID), []byte(channelID)) + store.Set(icatypes.KeyActiveChannel(connectionID, portID), []byte(channelID)) } -// IsActiveChannel returns true if there exists an active channel for the provided portID, otherwise false -func (k Keeper) IsActiveChannel(ctx sdk.Context, portID string) bool { - _, ok := k.GetActiveChannelID(ctx, portID) +// IsActiveChannel returns true if there exists an active channel for the provided connectionID and portID, otherwise false +func (k Keeper) IsActiveChannel(ctx sdk.Context, connectionID, portID string) bool { + _, ok := k.GetActiveChannelID(ctx, connectionID, 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 2416213ab1a..4799e09f5e9 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -177,16 +177,18 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), expectedPortID, expectedChannelID) + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedChannelID) expectedChannels := []icatypes.ActiveChannel{ { - PortId: TestPortID, - ChannelId: path.EndpointA.ChannelID, + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + ChannelId: path.EndpointA.ChannelID, }, { - PortId: expectedPortID, - ChannelId: expectedChannelID, + ConnectionId: ibctesting.FirstConnectionID, + PortId: expectedPortID, + ChannelId: expectedChannelID, }, } @@ -240,7 +242,7 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() { suite.Require().NoError(err) portID := path.EndpointA.ChannelConfig.PortID - isActive := suite.chainA.GetSimApp().ICAControllerKeeper.IsActiveChannel(suite.chainA.GetContext(), portID) + isActive := suite.chainA.GetSimApp().ICAControllerKeeper.IsActiveChannel(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID) suite.Require().Equal(isActive, true) } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index e0a7a443302..4375b3e3ee0 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -15,11 +15,10 @@ import ( // If the base application has the capability to send on the provided portID. An appropriate // absolute timeoutTimestamp must be provided. If the packet is timed out, the channel will be closed. // In the case of channel closure, a new channel may be reopened to reconnect to the host chain. -func (k Keeper) SendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { - // Check for the active channel - activeChannelID, found := k.GetActiveChannelID(ctx, portID) +func (k Keeper) SendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { + activeChannelID, found := k.GetActiveChannelID(ctx, connectionID, portID) if !found { - return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) + return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) } sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go index 5607ca05861..e687e0a751e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go @@ -96,7 +96,7 @@ func (suite *KeeperTestSuite) TestSendTx() { { "channel does not exist", func() { - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, "channel-100") + suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, "channel-100") }, false, }, @@ -160,7 +160,7 @@ func (suite *KeeperTestSuite) TestSendTx() { tc.malleate() // malleate mutates test data - _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), chanCap, path.EndpointA.ChannelConfig.PortID, packetData, timeoutTimestamp) + _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), chanCap, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, packetData, timeoutTimestamp) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index ef60a566d0c..d87d5dda0cb 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -641,7 +641,7 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose() chanCap, ok := suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(path.EndpointA.Chain.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) suite.Require().True(ok) - _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), chanCap, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0)) + _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), chanCap, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0)) suite.Require().NoError(err) path.EndpointB.UpdateClient() @@ -673,7 +673,7 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose() chanCap, ok = suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(path.EndpointA.Chain.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) suite.Require().True(ok) - _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), chanCap, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0)) + _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), chanCap, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0)) suite.Require().NoError(err) path.EndpointB.UpdateClient() diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 814a1e564b1..2a9caa3948b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -19,7 +19,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.HostGenesisState } for _, ch := range state.ActiveChannels { - keeper.SetActiveChannelID(ctx, ch.PortId, ch.ChannelId) + keeper.SetActiveChannelID(ctx, ch.ConnectionId, ch.PortId, ch.ChannelId) } for _, acc := range state.InterchainAccounts { diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index fc5ebe91dfd..78e447878a7 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -13,8 +13,9 @@ func (suite *KeeperTestSuite) TestInitGenesis() { genesisState := icatypes.HostGenesisState{ ActiveChannels: []icatypes.ActiveChannel{ { - PortId: TestPortID, - ChannelId: ibctesting.FirstChannelID, + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + ChannelId: ibctesting.FirstChannelID, }, }, InterchainAccounts: []icatypes.RegisteredInterchainAccount{ @@ -29,7 +30,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) - channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), TestPortID) + channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) suite.Require().True(found) suite.Require().Equal(ibctesting.FirstChannelID, channelID) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 78ae446e2f3..e5f61cfb7c6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -73,8 +73,12 @@ func (k Keeper) OnChanOpenConfirm( portID, channelID string, ) error { + channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) + if !found { + return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) + } - k.SetActiveChannelID(ctx, portID, channelID) + k.SetActiveChannelID(ctx, channel.ConnectionHops[0], portID, channelID) return nil } diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 1cab5af6ac7..beadf23b674 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -176,6 +176,14 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() { { "success", func() {}, true, }, + { + "channel not found", + func() { + path.EndpointB.ChannelID = "invalid-channel-id" + path.EndpointB.ChannelConfig.PortID = "invalid-port-id" + }, + false, + }, } for _, tc := range testCases { @@ -199,7 +207,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() { tc.malleate() // malleate mutates test data err = suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenConfirm(suite.chainB.GetContext(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index df53e18b086..da3c23062c7 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -90,10 +90,10 @@ 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 -func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool) { +// GetActiveChannelID retrieves the active channelID from the store keyed by the provided connectionID and portID +func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := icatypes.KeyActiveChannel(portID) + key := icatypes.KeyActiveChannel(connectionID, portID) if !store.Has(key) { return "", false @@ -102,7 +102,7 @@ func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool return string(store.Get(key)), true } -// GetAllActiveChannels returns a list of all active interchain accounts host channels and their associated port identifiers +// GetAllActiveChannels returns a list of all active interchain accounts host channels and their associated connection and port identifiers func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix)) @@ -113,8 +113,9 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { keySplit := strings.Split(string(iterator.Key()), "/") ch := icatypes.ActiveChannel{ - PortId: keySplit[1], - ChannelId: string(iterator.Value()), + ConnectionId: keySplit[1], + PortId: keySplit[2], + ChannelId: string(iterator.Value()), } activeChannels = append(activeChannels, ch) @@ -123,15 +124,15 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel { return activeChannels } -// SetActiveChannelID stores the active channelID, keyed by the provided portID -func (k Keeper) SetActiveChannelID(ctx sdk.Context, portID, channelID string) { +// SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID +func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) { store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyActiveChannel(portID), []byte(channelID)) + store.Set(icatypes.KeyActiveChannel(connectionID, portID), []byte(channelID)) } -// IsActiveChannel returns true if there exists an active channel for the provided portID, otherwise false -func (k Keeper) IsActiveChannel(ctx sdk.Context, portID string) bool { - _, ok := k.GetActiveChannelID(ctx, portID) +// IsActiveChannel returns true if there exists an active channel for the provided connectionID and portID, otherwise false +func (k Keeper) IsActiveChannel(ctx sdk.Context, connectionID, portID string) bool { + _, ok := k.GetActiveChannelID(ctx, connectionID, 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 437f37d1455..45f2d4bc848 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -161,16 +161,18 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), expectedPortID, expectedChannelID) + suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedChannelID) expectedChannels := []icatypes.ActiveChannel{ { - PortId: path.EndpointB.ChannelConfig.PortID, - ChannelId: path.EndpointB.ChannelID, + ConnectionId: ibctesting.FirstConnectionID, + PortId: path.EndpointB.ChannelConfig.PortID, + ChannelId: path.EndpointB.ChannelID, }, { - PortId: expectedPortID, - ChannelId: expectedChannelID, + ConnectionId: ibctesting.FirstConnectionID, + PortId: expectedPortID, + ChannelId: expectedChannelID, }, } @@ -222,7 +224,7 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - isActive := suite.chainB.GetSimApp().ICAHostKeeper.IsActiveChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID) + isActive := suite.chainB.GetSimApp().ICAHostKeeper.IsActiveChannel(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointB.ChannelConfig.PortID) suite.Require().True(isActive) } diff --git a/modules/apps/27-interchain-accounts/types/genesis.pb.go b/modules/apps/27-interchain-accounts/types/genesis.pb.go index 05906998f7d..c73f5c395f0 100644 --- a/modules/apps/27-interchain-accounts/types/genesis.pb.go +++ b/modules/apps/27-interchain-accounts/types/genesis.pb.go @@ -216,10 +216,11 @@ func (m *HostGenesisState) GetParams() types1.Params { return types1.Params{} } -// ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel +// ActiveChannel contains a connection ID, port ID and associated active channel ID type ActiveChannel struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` - ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` + ConnectionId string `protobuf:"bytes,1,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + ChannelId string `protobuf:"bytes,3,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` } func (m *ActiveChannel) Reset() { *m = ActiveChannel{} } @@ -255,6 +256,13 @@ func (m *ActiveChannel) XXX_DiscardUnknown() { var xxx_messageInfo_ActiveChannel proto.InternalMessageInfo +func (m *ActiveChannel) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + func (m *ActiveChannel) GetPortId() string { if m != nil { return m.PortId @@ -343,48 +351,48 @@ func init() { } var fileDescriptor_629b3ced0911516b = []byte{ - // 643 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x95, 0x3d, 0x6f, 0x13, 0x31, - 0x18, 0xc7, 0x73, 0x49, 0x29, 0x8a, 0xfb, 0x42, 0x31, 0xa5, 0x3a, 0x82, 0x74, 0x09, 0x5e, 0x1a, - 0x09, 0xf5, 0x4e, 0x7d, 0x81, 0x8a, 0x4a, 0x08, 0xf5, 0x02, 0x82, 0x6c, 0xc8, 0x2c, 0x88, 0xe5, - 0xe4, 0xf8, 0xac, 0xc4, 0x52, 0x72, 0x8e, 0xce, 0x6e, 0xa4, 0x4e, 0xec, 0x4c, 0x6c, 0x88, 0x15, - 0x89, 0xef, 0xc1, 0xd8, 0x09, 0x75, 0x64, 0x8a, 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, 0x86, 0x3a, 0x1d, 0x32, 0xd9, - 0x59, 0x36, 0x2f, 0xc6, 0xfe, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x34, 0x02, 0xec, 0x0d, 0x27, - 0x07, 0x00, 0x00, + // 645 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x95, 0x3f, 0x6f, 0x13, 0x3f, + 0x18, 0xc7, 0xe3, 0xa4, 0xbf, 0xfe, 0x14, 0xf7, 0x0f, 0xc5, 0x94, 0xea, 0x08, 0xd2, 0x25, 0x78, + 0x69, 0x24, 0xd4, 0x3b, 0xf5, 0x0f, 0x54, 0x54, 0x42, 0xa8, 0x17, 0x10, 0x64, 0x43, 0x66, 0x41, + 0x2c, 0x27, 0xc7, 0x67, 0x25, 0x96, 0x92, 0x73, 0x74, 0x76, 0x23, 0x75, 0x62, 0x67, 0x62, 0x43, + 0xac, 0x48, 0xbc, 0x00, 0xde, 0x01, 0x63, 0x27, 0xd4, 0x91, 0x29, 0x42, 0xed, 0x3b, 0xc8, 0x2b, + 0x40, 0xf6, 0x9d, 0x92, 0xf4, 0x48, 0xab, 0x9b, 0x98, 0x98, 0x62, 0xdf, 0xe3, 0xef, 0xf7, 0xf9, + 0x3c, 0x7e, 0x1c, 0x1b, 0x3e, 0x12, 0x1d, 0xe6, 0xd3, 0xe1, 0xb0, 0x2f, 0x18, 0xd5, 0x42, 0xc6, + 0xca, 0x17, 0xb1, 0xe6, 0x09, 0xeb, 0x51, 0x11, 0x87, 0x94, 0x31, 0x79, 0x12, 0x6b, 0xe5, 0x8f, + 0x76, 0xfd, 0x2e, 0x8f, 0xb9, 0x12, 0xca, 0x1b, 0x26, 0x52, 0x4b, 0xb4, 0x2d, 0x3a, 0xcc, 0x9b, + 0x97, 0x79, 0x0b, 0x64, 0xde, 0x68, 0xb7, 0xb6, 0xd9, 0x95, 0x5d, 0x69, 0x35, 0xbe,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0x00, 0x78, 0xff, 0x86, + 0x3d, 0xff, 0xab, 0x15, 0xb4, 0xcc, 0x21, 0xb6, 0x69, 0x43, 0x1a, 0x45, 0x09, 0x57, 0x2a, 0x2b, + 0xa3, 0x36, 0x7f, 0x10, 0xaf, 0x2c, 0xb0, 0x07, 0xd1, 0x7e, 0x39, 0x4e, 0x3f, 0x04, 0xe1, 0xd9, + 0x85, 0x0b, 0xce, 0x2f, 0x5c, 0xf0, 0xeb, 0xc2, 0x05, 0x1f, 0x2f, 0xdd, 0xd2, 0xf9, 0xa5, 0x5b, + 0xfa, 0x79, 0xe9, 0x96, 0xde, 0xbd, 0xe8, 0x0a, 0xdd, 0x3b, 0xe9, 0x78, 0x4c, 0x0e, 0x7c, 0x26, + 0xd5, 0x40, 0x2a, 0x5f, 0x74, 0xd8, 0x4e, 0x57, 0xfa, 0xa3, 0x7d, 0x7f, 0x20, 0xa3, 0x93, 0x3e, + 0x57, 0xe6, 0xf1, 0x51, 0xfe, 0xde, 0xe1, 0xce, 0xac, 0xf9, 0x3b, 0xd3, 0x77, 0x47, 0x9f, 0x0e, + 0xb9, 0xea, 0x2c, 0xdb, 0x17, 0x67, 0xff, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf5, 0x08, 0x8f, + 0x1f, 0x67, 0x07, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -593,13 +601,20 @@ func (m *ActiveChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.ChannelId) i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.PortId) > 0 { i -= len(m.PortId) copy(dAtA[i:], m.PortId) i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) i-- + dAtA[i] = 0x12 + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ConnectionId))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -735,6 +750,10 @@ func (m *ActiveChannel) Size() (n int) { } var l int _ = l + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } l = len(m.PortId) if l > 0 { n += 1 + l + sovGenesis(uint64(l)) @@ -1285,6 +1304,38 @@ func (m *ActiveChannel) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) } @@ -1316,7 +1367,7 @@ func (m *ActiveChannel) Unmarshal(dAtA []byte) error { } m.PortId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) } diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index e63e32787ca..d120fe6ac7c 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -39,8 +39,8 @@ var ( ) // KeyActiveChannel creates and returns a new key used for active channels store operations -func KeyActiveChannel(portID string) []byte { - return []byte(fmt.Sprintf("%s/%s", ActiveChannelKeyPrefix, portID)) +func KeyActiveChannel(connectionID, portID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", ActiveChannelKeyPrefix, connectionID, portID)) } // KeyOwnerAccount creates and returns a new key used for interchain account store operations diff --git a/modules/apps/27-interchain-accounts/types/keys_test.go b/modules/apps/27-interchain-accounts/types/keys_test.go index e321aea0bd5..4fe7b5a813f 100644 --- a/modules/apps/27-interchain-accounts/types/keys_test.go +++ b/modules/apps/27-interchain-accounts/types/keys_test.go @@ -5,8 +5,8 @@ import ( ) func (suite *TypesTestSuite) TestKeyActiveChannel() { - key := types.KeyActiveChannel("port-id") - suite.Require().Equal("activeChannel/port-id", string(key)) + key := types.KeyActiveChannel("connection-id", "port-id") + suite.Require().Equal("activeChannel/connection-id/port-id", string(key)) } func (suite *TypesTestSuite) TestKeyOwnerAccount() { diff --git a/proto/ibc/applications/interchain_accounts/v1/genesis.proto b/proto/ibc/applications/interchain_accounts/v1/genesis.proto index 342ee17c2ee..3902f890708 100644 --- a/proto/ibc/applications/interchain_accounts/v1/genesis.proto +++ b/proto/ibc/applications/interchain_accounts/v1/genesis.proto @@ -36,10 +36,11 @@ message HostGenesisState { ibc.applications.interchain_accounts.host.v1.Params params = 4 [(gogoproto.nullable) = false]; } -// ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel +// ActiveChannel contains a connection ID, port ID and associated active channel ID message ActiveChannel { - string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; - string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""]; + string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""]; + string port_id = 2 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; } // RegisteredInterchainAccount contains a connection ID, port ID and associated interchain account address