From f39389388b807434a27a618fbdf71cd19b900210 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 28 Jan 2022 14:12:15 +0100 Subject: [PATCH] chore: use connection ID in interchain account store keys (#791) * updating protos to include connection id * updating interchain account store key to include conn id * updating arg names * updating proto comments * cleanup * rename connID -> connectionID in AuthenticateTx arg * updating to use controller connection id in controller store key * chore: use connection ID in active channel store keys (#807) * adding connection id to active channel genesis protobuf type * adding connection id to active channel store key * updating protodoc * fixing doc typo * updating godocs to include connection ID * readding active channel check in SendTx --- docs/ibc/proto-docs.md | 6 +- .../controller/keeper/account_test.go | 2 +- .../controller/keeper/genesis.go | 4 +- .../controller/keeper/genesis_test.go | 10 +- .../controller/keeper/handshake.go | 6 +- .../controller/keeper/handshake_test.go | 8 +- .../controller/keeper/keeper.go | 48 +++-- .../controller/keeper/keeper_test.go | 26 ++- .../controller/keeper/relay.go | 7 +- .../controller/keeper/relay_test.go | 10 +- .../host/ibc_module_test.go | 10 +- .../host/keeper/account.go | 11 +- .../host/keeper/account_test.go | 3 +- .../host/keeper/genesis.go | 4 +- .../host/keeper/genesis_test.go | 10 +- .../host/keeper/handshake.go | 8 +- .../host/keeper/handshake_test.go | 10 +- .../host/keeper/keeper.go | 42 ++-- .../host/keeper/keeper_test.go | 26 ++- .../host/keeper/relay.go | 11 +- .../host/keeper/relay_test.go | 20 +- .../types/genesis.pb.go | 204 +++++++++++++----- .../apps/27-interchain-accounts/types/keys.go | 8 +- .../27-interchain-accounts/types/keys_test.go | 8 +- .../interchain_accounts/v1/genesis.proto | 16 +- 25 files changed, 330 insertions(+), 188 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 889aee1bad7..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) | | | @@ -379,11 +380,12 @@ HostGenesisState defines the interchain accounts host genesis state ### RegisteredInterchainAccount -RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address +RegisteredInterchainAccount contains a connection ID, port ID and associated interchain account address | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | +| `connection_id` | [string](#string) | | | | `port_id` | [string](#string) | | | | `account_address` | [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 8b0d8b896ee..eab7687236e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -21,11 +21,11 @@ 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 { - keeper.SetInterchainAccountAddress(ctx, acc.PortId, acc.AccountAddress) + keeper.SetInterchainAccountAddress(ctx, acc.ConnectionId, acc.PortId, acc.AccountAddress) } keeper.SetParams(ctx, state.Params) 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 fca58db2e44..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,12 +13,14 @@ 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{ { + ConnectionId: ibctesting.FirstConnectionID, PortId: TestPortID, AccountAddress: TestAccAddress.String(), }, @@ -28,11 +30,11 @@ 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) - accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), TestPortID) + accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) suite.Require().True(found) suite.Require().Equal(TestAccAddress.String(), accountAdrr) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index fb38401a0b2..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,8 +92,8 @@ func (k Keeper) OnChanOpenAck( return sdkerrors.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be empty") } - k.SetActiveChannelID(ctx, portID, channelID) - k.SetInterchainAccountAddress(ctx, portID, metadata.Address) + 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 990787af38f..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,12 +279,12 @@ 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) - interchainAccAddress, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccAddress, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) suite.Require().Equal(metadata.Address, interchainAccAddress) @@ -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 afc1a2eda5d..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,22 +152,22 @@ 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 } -// GetInterchainAccountAddress retrieves the InterchainAccount address from the store keyed by the provided portID -func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (string, bool) { +// GetInterchainAccountAddress retrieves the InterchainAccount address from the store associated with the provided connectionID and portID +func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := icatypes.KeyOwnerAccount(portID) + key := icatypes.KeyOwnerAccount(connectionID, portID) if !store.Has(key) { return "", false @@ -175,7 +176,7 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str return string(store.Get(key)), true } -// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers +// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated connection and controller port identifiers func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredInterchainAccount { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix)) @@ -185,7 +186,8 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredI keySplit := strings.Split(string(iterator.Key()), "/") acc := icatypes.RegisteredInterchainAccount{ - PortId: keySplit[1], + ConnectionId: keySplit[1], + PortId: keySplit[2], AccountAddress: string(iterator.Value()), } @@ -195,8 +197,8 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredI return interchainAccounts } -// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated portID -func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, portID string, address string) { +// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated connectionID and portID +func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portID, address string) { store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyOwnerAccount(portID), []byte(address)) + store.Set(icatypes.KeyOwnerAccount(connectionID, portID), []byte(address)) } 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 68a9c641252..4799e09f5e9 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -154,11 +154,11 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { counterpartyPortID := path.EndpointA.ChannelConfig.PortID expectedAddr := authtypes.NewBaseAccountWithAddress(icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), counterpartyPortID)).GetAddress() - retrievedAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), counterpartyPortID) + retrievedAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, counterpartyPortID) suite.Require().True(found) suite.Require().Equal(expectedAddr.String(), retrievedAddr) - retrievedAddr, found = suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), "invalid port") + retrievedAddr, found = suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), "invalid conn", "invalid port") suite.Require().False(found) suite.Require().Empty(retrievedAddr) } @@ -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, }, } @@ -209,14 +211,16 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID, expectedAccAddr) + suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr) expectedAccounts := []icatypes.RegisteredInterchainAccount{ { + ConnectionId: ibctesting.FirstConnectionID, PortId: TestPortID, AccountAddress: TestAccAddress.String(), }, { + ConnectionId: ibctesting.FirstConnectionID, PortId: expectedPortID, AccountAddress: expectedAccAddr, }, @@ -238,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) } @@ -248,9 +252,9 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { expectedPortID string = "test-port" ) - suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID, expectedAccAddr) + suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr) - retrievedAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID) + retrievedAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID) suite.Require().True(found) suite.Require().Equal(expectedAccAddr, retrievedAddr) } 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 96a4e74f89c..e687e0a751e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go @@ -28,7 +28,7 @@ func (suite *KeeperTestSuite) TestSendTx() { { "success", func() { - interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msg := &banktypes.MsgSend{ @@ -50,7 +50,7 @@ func (suite *KeeperTestSuite) TestSendTx() { { "success with multiple sdk.Msg", func() { - interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msgsBankSend := []sdk.Msg{ @@ -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, }, @@ -118,7 +118,7 @@ func (suite *KeeperTestSuite) TestSendTx() { { "timeout timestamp is not in the future", func() { - interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msg := &banktypes.MsgSend{ @@ -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 37c81bfd955..d87d5dda0cb 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -437,7 +437,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { // send 100stake to interchain account wallet amount, _ := sdk.ParseCoinsNormalized("100stake") - interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) bankMsg := &banktypes.MsgSend{FromAddress: suite.chainB.SenderAccount.GetAddress().String(), ToAddress: interchainAccountAddr, Amount: amount} _, err = suite.chainB.SendMsgs(bankMsg) @@ -592,7 +592,7 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { } func (suite *InterchainAccountsTestSuite) fundICAWallet(ctx sdk.Context, portID string, amount sdk.Coins) { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, portID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, ibctesting.FirstConnectionID, portID) suite.Require().True(found) msgBankSend := &banktypes.MsgSend{ @@ -617,7 +617,7 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose() // check that the account is working as expected suite.fundICAWallet(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000)))) - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) tokenAmt := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5000))) @@ -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/account.go b/modules/apps/27-interchain-accounts/host/keeper/account.go index e88c82b16c6..d37cc21f1c2 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/account.go +++ b/modules/apps/27-interchain-accounts/host/keeper/account.go @@ -7,20 +7,21 @@ import ( icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" ) -// RegisterInterchainAccount attempts to create a new account using the provided address and stores it in state keyed by the provided port identifier +// RegisterInterchainAccount attempts to create a new account using the provided address and +// stores it in state keyed by the provided connection and port identifiers // If an account for the provided address already exists this function returns early (no-op) -func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, accAddr sdk.AccAddress, controllerPortID string) { - if acc := k.accountKeeper.GetAccount(ctx, accAddr); acc != nil { +func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, controllerPortID string, accAddress sdk.AccAddress) { + if acc := k.accountKeeper.GetAccount(ctx, accAddress); acc != nil { return } interchainAccount := icatypes.NewInterchainAccount( - authtypes.NewBaseAccountWithAddress(accAddr), + authtypes.NewBaseAccountWithAddress(accAddress), controllerPortID, ) k.accountKeeper.NewAccount(ctx, interchainAccount) k.accountKeeper.SetAccount(ctx, interchainAccount) - k.SetInterchainAccountAddress(ctx, controllerPortID, interchainAccount.Address) + k.SetInterchainAccountAddress(ctx, connectionID, controllerPortID, interchainAccount.Address) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/account_test.go b/modules/apps/27-interchain-accounts/host/keeper/account_test.go index 63ff416cfbb..df1966277e4 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/account_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/account_test.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" + ibctesting "github.com/cosmos/ibc-go/v3/testing" ) func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { @@ -20,7 +21,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { suite.Require().NoError(err) // Get the address of the interchain account stored in state during handshake step - storedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), portID) + storedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, portID) suite.Require().True(found) icaAddr, err := sdk.AccAddressFromBech32(storedAddr) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index b784486c150..2a9caa3948b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -19,11 +19,11 @@ 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 { - keeper.SetInterchainAccountAddress(ctx, acc.PortId, acc.AccountAddress) + keeper.SetInterchainAccountAddress(ctx, acc.ConnectionId, acc.PortId, acc.AccountAddress) } keeper.SetParams(ctx, state.Params) 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 c2da967c56f..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,12 +13,14 @@ 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{ { + ConnectionId: ibctesting.FirstConnectionID, PortId: TestPortID, AccountAddress: TestAccAddress.String(), }, @@ -28,11 +30,11 @@ 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) - accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), TestPortID) + accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) suite.Require().True(found) suite.Require().Equal(TestAccAddress.String(), accountAdrr) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index a023e42c110..e5f61cfb7c6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -56,7 +56,7 @@ func (k Keeper) OnChanOpenTry( accAddress := icatypes.GenerateAddress(k.accountKeeper.GetModuleAddress(icatypes.ModuleName), counterparty.PortId) // Register interchain account if it does not already exist - k.RegisterInterchainAccount(ctx, accAddress, counterparty.PortId) + k.RegisterInterchainAccount(ctx, metadata.HostConnectionId, counterparty.PortId, accAddress) metadata.Address = accAddress.String() versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) @@ -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 bf76bce737d..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,22 +124,22 @@ 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 } -// GetInterchainAccountAddress retrieves the InterchainAccount address from the store keyed by the provided portID -func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (string, bool) { +// GetInterchainAccountAddress retrieves the InterchainAccount address from the store associated with the provided connectionID and portID +func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := icatypes.KeyOwnerAccount(portID) + key := icatypes.KeyOwnerAccount(connectionID, portID) if !store.Has(key) { return "", false @@ -147,7 +148,7 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str return string(store.Get(key)), true } -// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers +// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated connection and controller port identifiers func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredInterchainAccount { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix)) @@ -157,7 +158,8 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredI keySplit := strings.Split(string(iterator.Key()), "/") acc := icatypes.RegisteredInterchainAccount{ - PortId: keySplit[1], + ConnectionId: keySplit[1], + PortId: keySplit[2], AccountAddress: string(iterator.Value()), } @@ -167,8 +169,8 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredI return interchainAccounts } -// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated portID -func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, portID string, address string) { +// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated connectionID and portID +func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portID, address string) { store := ctx.KVStore(k.storeKey) - store.Set(icatypes.KeyOwnerAccount(portID), []byte(address)) + store.Set(icatypes.KeyOwnerAccount(connectionID, portID), []byte(address)) } 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 40ca865c444..45f2d4bc848 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -138,11 +138,11 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { counterpartyPortID := path.EndpointA.ChannelConfig.PortID expectedAddr := authtypes.NewBaseAccountWithAddress(icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), counterpartyPortID)).GetAddress() - retrievedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), counterpartyPortID) + retrievedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, counterpartyPortID) suite.Require().True(found) suite.Require().Equal(expectedAddr.String(), retrievedAddr) - retrievedAddr, found = suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), "invalid port") + retrievedAddr, found = suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, "invalid port") suite.Require().False(found) suite.Require().Empty(retrievedAddr) } @@ -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, }, } @@ -193,14 +195,16 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), expectedPortID, expectedAccAddr) + suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr) expectedAccounts := []icatypes.RegisteredInterchainAccount{ { + ConnectionId: ibctesting.FirstConnectionID, PortId: TestPortID, AccountAddress: TestAccAddress.String(), }, { + ConnectionId: ibctesting.FirstConnectionID, PortId: expectedPortID, AccountAddress: expectedAccAddr, }, @@ -220,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) } @@ -230,9 +234,9 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { expectedPortID string = "test-port" ) - suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), expectedPortID, expectedAccAddr) + suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr) - retrievedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), expectedPortID) + retrievedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID) suite.Require().True(found) suite.Require().Equal(expectedAccAddr, retrievedAddr) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index 80d434309f4..803045794ad 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -36,7 +36,12 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) error } func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel string, msgs []sdk.Msg) error { - if err := k.authenticateTx(ctx, msgs, sourcePort); err != nil { + channel, found := k.channelKeeper.GetChannel(ctx, destPort, destChannel) + if !found { + return channeltypes.ErrChannelNotFound + } + + if err := k.authenticateTx(ctx, msgs, channel.ConnectionHops[0], sourcePort); err != nil { return err } @@ -62,8 +67,8 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str // authenticateTx ensures the provided msgs contain the correct interchain account signer address retrieved // from state using the provided controller port identifier -func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, portID string) error { - interchainAccountAddr, found := k.GetInterchainAccountAddress(ctx, portID) +func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, connectionID, portID string) error { + interchainAccountAddr, found := k.GetInterchainAccountAddress(ctx, connectionID, portID) if !found { return sdkerrors.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go index 37cefe34bba..f128804b415 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go @@ -32,7 +32,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes banktypes.MsgSend", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msg := &banktypes.MsgSend{ @@ -59,7 +59,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes stakingtypes.MsgDelegate", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) validatorAddr := (sdk.ValAddress)(suite.chainB.Vals.Validators[0].Address) @@ -87,7 +87,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes stakingtypes.MsgDelegate and stakingtypes.MsgUndelegate sequentially", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) validatorAddr := (sdk.ValAddress)(suite.chainB.Vals.Validators[0].Address) @@ -121,7 +121,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes govtypes.MsgSubmitProposal", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) testProposal := &govtypes.TextProposal{ @@ -156,7 +156,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes govtypes.MsgVote", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) // Populate the gov keeper in advance with an active proposal @@ -195,7 +195,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes disttypes.MsgFundCommunityPool", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msg := &disttypes.MsgFundCommunityPool{ @@ -221,7 +221,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { { "interchain account successfully executes disttypes.MsgSetWithdrawAddress", func() { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msg := &disttypes.MsgSetWithdrawAddress{ @@ -255,7 +255,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.coordinator.Setup(transferPath) - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().True(found) msg := &transfertypes.MsgTransfer{ @@ -399,7 +399,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.Require().NoError(err) // Get the address of the interchain account stored in state during handshake step - storedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), portID) + storedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, portID) suite.Require().True(found) icaAddr, err := sdk.AccAddressFromBech32(storedAddr) @@ -436,7 +436,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } func (suite *KeeperTestSuite) fundICAWallet(ctx sdk.Context, portID string, amount sdk.Coins) { - interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, portID) + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, ibctesting.FirstConnectionID, portID) suite.Require().True(found) msgBankSend := &banktypes.MsgSend{ diff --git a/modules/apps/27-interchain-accounts/types/genesis.pb.go b/modules/apps/27-interchain-accounts/types/genesis.pb.go index 4680272f5c5..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 @@ -269,10 +277,11 @@ func (m *ActiveChannel) GetChannelId() string { return "" } -// RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address +// RegisteredInterchainAccount contains a connection ID, port ID and associated interchain account address type RegisteredInterchainAccount struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` - AccountAddress string `protobuf:"bytes,2,opt,name=account_address,json=accountAddress,proto3" json:"account_address,omitempty" yaml:"account_address"` + 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"` + AccountAddress string `protobuf:"bytes,3,opt,name=account_address,json=accountAddress,proto3" json:"account_address,omitempty" yaml:"account_address"` } func (m *RegisteredInterchainAccount) Reset() { *m = RegisteredInterchainAccount{} } @@ -308,6 +317,13 @@ func (m *RegisteredInterchainAccount) XXX_DiscardUnknown() { var xxx_messageInfo_RegisteredInterchainAccount proto.InternalMessageInfo +func (m *RegisteredInterchainAccount) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + func (m *RegisteredInterchainAccount) GetPortId() string { if m != nil { return m.PortId @@ -335,46 +351,48 @@ func init() { } var fileDescriptor_629b3ced0911516b = []byte{ - // 611 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x94, 0x4f, 0x6f, 0xd3, 0x3e, - 0x18, 0xc7, 0x9b, 0x66, 0xbf, 0xfd, 0x54, 0x0f, 0xc6, 0x30, 0x63, 0x0a, 0x45, 0x4a, 0x8b, 0x2f, - 0xab, 0x84, 0x96, 0x68, 0x7f, 0x60, 0x62, 0x17, 0xb4, 0x14, 0x04, 0xbb, 0xa1, 0x70, 0x41, 0x5c, - 0x22, 0xd7, 0xb1, 0x52, 0x4b, 0x69, 0x1c, 0xc5, 0x5e, 0xa5, 0x9d, 0xb8, 0x73, 0x81, 0x1b, 0xe2, - 0x8a, 0xc4, 0xfb, 0xe0, 0xb8, 0xe3, 0x8e, 0x9c, 0x2a, 0xd4, 0xbe, 0x83, 0xbe, 0x02, 0x64, 0x27, - 0xea, 0x9f, 0xd0, 0x4d, 0xe1, 0xce, 0xa9, 0x76, 0xfc, 0x7c, 0xbf, 0xcf, 0xe7, 0xf1, 0xe3, 0x3e, - 0xe0, 0x09, 0xeb, 0x11, 0x17, 0xa7, 0x69, 0xcc, 0x08, 0x96, 0x8c, 0x27, 0xc2, 0x65, 0x89, 0xa4, - 0x19, 0xe9, 0x63, 0x96, 0x04, 0x98, 0x10, 0x7e, 0x9e, 0x48, 0xe1, 0x0e, 0xf7, 0xdd, 0x88, 0x26, - 0x54, 0x30, 0xe1, 0xa4, 0x19, 0x97, 0x1c, 0xee, 0xb2, 0x1e, 0x71, 0x16, 0x65, 0xce, 0x0a, 0x99, - 0x33, 0xdc, 0x6f, 0x6e, 0x47, 0x3c, 0xe2, 0x5a, 0xe3, 0xaa, 0x55, 0x2e, 0x6f, 0x76, 0x2b, 0x65, - 0x25, 0x3c, 0x91, 0x19, 0x8f, 0x63, 0x9a, 0x29, 0x80, 0xf9, 0xae, 0x30, 0x39, 0xae, 0x64, 0xd2, - 0xe7, 0x42, 0x2a, 0xb9, 0xfa, 0xcd, 0x85, 0xe8, 0x47, 0x1d, 0xdc, 0x7a, 0x95, 0x97, 0xf3, 0x56, - 0x62, 0x49, 0xe1, 0x37, 0x03, 0x58, 0x73, 0xfb, 0xa0, 0x28, 0x35, 0x10, 0xea, 0xd0, 0x32, 0xda, - 0x46, 0x67, 0xe3, 0xe0, 0xb9, 0x53, 0xb1, 0x62, 0xa7, 0x3b, 0x33, 0x5a, 0xcc, 0xe1, 0xed, 0x5e, - 0x8e, 0x5a, 0xb5, 0xe9, 0xa8, 0xd5, 0xba, 0xc0, 0x83, 0xf8, 0x04, 0x5d, 0x97, 0x0e, 0xf9, 0x3b, - 0x64, 0xa5, 0x01, 0xfc, 0x68, 0x00, 0xa8, 0x8a, 0x28, 0xe1, 0xd5, 0x35, 0xde, 0xb3, 0xca, 0x78, - 0xaf, 0xb9, 0x90, 0x4b, 0x60, 0x8f, 0x0a, 0xb0, 0x07, 0x39, 0xd8, 0x9f, 0x29, 0x90, 0xbf, 0xd5, - 0x2f, 0x89, 0xd0, 0x77, 0x13, 0xec, 0xac, 0x2e, 0x14, 0x7e, 0x00, 0x77, 0x30, 0x91, 0x6c, 0x48, - 0x03, 0xd2, 0xc7, 0x49, 0x42, 0x63, 0x61, 0x19, 0x6d, 0xb3, 0xb3, 0x71, 0xf0, 0xb4, 0x32, 0xe3, - 0xa9, 0xd6, 0x77, 0x73, 0xb9, 0x67, 0x17, 0x80, 0x3b, 0x39, 0x60, 0xc9, 0x1c, 0xf9, 0x9b, 0x78, - 0x31, 0x5c, 0xc0, 0xaf, 0x06, 0xb8, 0xb7, 0xc2, 0xd8, 0xaa, 0x6b, 0x8a, 0x17, 0x95, 0x29, 0x7c, - 0x1a, 0x31, 0x21, 0x69, 0x46, 0xc3, 0xb3, 0x59, 0xc0, 0x69, 0x7e, 0xee, 0xa1, 0x82, 0xa9, 0x99, - 0x33, 0xad, 0x70, 0x40, 0x3e, 0x64, 0x65, 0x99, 0x80, 0xdb, 0xe0, 0xbf, 0x94, 0x67, 0x52, 0x58, - 0x66, 0xdb, 0xec, 0x34, 0xfc, 0x7c, 0x03, 0xdf, 0x81, 0xf5, 0x14, 0x67, 0x78, 0x20, 0xac, 0x35, - 0xdd, 0xcd, 0x93, 0x6a, 0x8c, 0x0b, 0xff, 0x88, 0xe1, 0xbe, 0xf3, 0x46, 0x3b, 0x78, 0x6b, 0x8a, - 0xcc, 0x2f, 0xfc, 0xd0, 0x17, 0x13, 0x6c, 0x95, 0x3b, 0xfe, 0xaf, 0x43, 0x37, 0x75, 0x08, 0x82, - 0x35, 0xd5, 0x14, 0xcb, 0x6c, 0x1b, 0x9d, 0x86, 0xaf, 0xd7, 0xd0, 0x2f, 0xf5, 0xe7, 0xa8, 0x1a, - 0xa1, 0x1e, 0x39, 0xd7, 0x75, 0x26, 0x03, 0xb7, 0x97, 0x2e, 0x11, 0x3e, 0x06, 0xff, 0xab, 0x64, - 0x01, 0x0b, 0xf5, 0xc8, 0x69, 0x78, 0x70, 0x3a, 0x6a, 0x6d, 0xe6, 0xf4, 0xc5, 0x01, 0xf2, 0xd7, - 0xd5, 0xea, 0x2c, 0x84, 0x47, 0x00, 0x14, 0xd7, 0xab, 0xe2, 0xeb, 0x3a, 0xfe, 0xfe, 0x74, 0xd4, - 0xba, 0x5b, 0x4c, 0x97, 0xd9, 0x19, 0xf2, 0x1b, 0xc5, 0xe6, 0x2c, 0x44, 0x9f, 0x0c, 0xf0, 0xf0, - 0x86, 0x3b, 0xfb, 0x3b, 0x84, 0xae, 0x7a, 0x45, 0x5a, 0x17, 0xe0, 0x30, 0xcc, 0xa8, 0x10, 0x05, - 0x47, 0x73, 0xf1, 0x25, 0x2c, 0x05, 0xe8, 0x97, 0xa0, 0xbf, 0x9c, 0xe6, 0x1f, 0xbc, 0xe0, 0x72, - 0x6c, 0x1b, 0x57, 0x63, 0xdb, 0xf8, 0x35, 0xb6, 0x8d, 0xcf, 0x13, 0xbb, 0x76, 0x35, 0xb1, 0x6b, - 0x3f, 0x27, 0x76, 0xed, 0xfd, 0xcb, 0x88, 0xc9, 0xfe, 0x79, 0xcf, 0x21, 0x7c, 0xe0, 0x12, 0x2e, - 0x06, 0x5c, 0xb8, 0xac, 0x47, 0xf6, 0x22, 0xee, 0x0e, 0x0f, 0xdd, 0x01, 0x0f, 0xcf, 0x63, 0x2a, - 0xd4, 0xf4, 0x17, 0xee, 0xc1, 0xf1, 0xde, 0xfc, 0xf6, 0xf7, 0x66, 0x83, 0x5f, 0x5e, 0xa4, 0x54, - 0xf4, 0xd6, 0xf5, 0xc8, 0x3f, 0xfc, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xf2, 0xb9, 0x8d, 0x2d, 0xe8, - 0x06, 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, 0x19, 0xa5, + 0xf2, 0x5a, 0xab, 0x50, 0x56, 0x26, 0x63, 0x9d, 0xc8, 0x7e, 0x9f, 0x27, 0x06, 0x60, 0x36, 0xcb, + 0x4c, 0x0e, 0x0b, 0x99, 0xf4, 0xa4, 0xd2, 0x46, 0x6e, 0x7e, 0x53, 0x21, 0xfe, 0x5e, 0x86, 0xab, + 0x2f, 0xd3, 0x72, 0xde, 0x68, 0xaa, 0x39, 0xfa, 0x02, 0xa0, 0x33, 0xb3, 0x0f, 0xb3, 0x52, 0x43, + 0x65, 0x82, 0x0e, 0x68, 0x80, 0xe6, 0xca, 0xde, 0x33, 0xaf, 0x60, 0xc5, 0x5e, 0x6b, 0x6a, 0x34, + 0x9f, 0x23, 0xd8, 0x3e, 0x1b, 0xd7, 0x4b, 0x93, 0x71, 0xbd, 0x7e, 0x4a, 0x07, 0xfd, 0x23, 0x7c, + 0x5d, 0x3a, 0x4c, 0xb6, 0xd8, 0x42, 0x03, 0xf4, 0x01, 0x40, 0x64, 0x8a, 0xc8, 0xe1, 0x95, 0x2d, + 0xde, 0x93, 0xc2, 0x78, 0xaf, 0xa4, 0xd2, 0x57, 0xc0, 0x1e, 0x64, 0x60, 0xf7, 0x52, 0xb0, 0x3f, + 0x53, 0x60, 0xb2, 0xd1, 0xcb, 0x89, 0xf0, 0xd7, 0x0a, 0xdc, 0x5a, 0x5c, 0x28, 0x7a, 0x0f, 0x6f, + 0x51, 0xa6, 0xc5, 0x88, 0x87, 0xac, 0x47, 0xe3, 0x98, 0xf7, 0x95, 0x03, 0x1a, 0x95, 0xe6, 0xca, + 0xde, 0xe3, 0xc2, 0x8c, 0xc7, 0x56, 0xdf, 0x4a, 0xe5, 0x81, 0x9b, 0x01, 0x6e, 0xa5, 0x80, 0x39, + 0x73, 0x4c, 0xd6, 0xe9, 0xfc, 0x72, 0x85, 0x3e, 0x03, 0x78, 0x67, 0x81, 0xb1, 0x53, 0xb6, 0x14, + 0xcf, 0x0b, 0x53, 0x10, 0xde, 0x15, 0x4a, 0xf3, 0x84, 0x47, 0xed, 0xe9, 0x82, 0xe3, 0x34, 0x1e, + 0xe0, 0x8c, 0xa9, 0x96, 0x32, 0x2d, 0x70, 0xc0, 0x04, 0x89, 0xbc, 0x4c, 0xa1, 0x4d, 0xf8, 0xdf, + 0x50, 0x26, 0x5a, 0x39, 0x95, 0x46, 0xa5, 0x59, 0x25, 0xe9, 0x04, 0xbd, 0x85, 0xcb, 0x43, 0x9a, + 0xd0, 0x81, 0x72, 0x96, 0x6c, 0x37, 0x8f, 0x8a, 0x31, 0xce, 0xfd, 0x23, 0x46, 0xbb, 0xde, 0x6b, + 0xeb, 0x10, 0x2c, 0x19, 0x32, 0x92, 0xf9, 0xe1, 0x4f, 0x15, 0xb8, 0x91, 0xef, 0xf8, 0xbf, 0x0e, + 0xdd, 0xd4, 0x21, 0x04, 0x97, 0x4c, 0x53, 0x9c, 0x4a, 0x03, 0x34, 0xab, 0xc4, 0x8e, 0x11, 0xc9, + 0xf5, 0xe7, 0xa0, 0x18, 0xa1, 0xbd, 0x72, 0xae, 0xeb, 0xcc, 0x37, 0x00, 0xd7, 0xae, 0xec, 0x22, + 0x7a, 0x0a, 0xd7, 0x98, 0x8c, 0x63, 0xce, 0x8c, 0x63, 0x28, 0x22, 0x7b, 0xf3, 0x54, 0x03, 0x67, + 0x32, 0xae, 0x6f, 0x4e, 0x2f, 0x8d, 0x59, 0x18, 0x93, 0xd5, 0xd9, 0xbc, 0x1d, 0xa1, 0x87, 0xf0, + 0x7f, 0x03, 0x6b, 0x84, 0x65, 0x2b, 0x44, 0x93, 0x71, 0x7d, 0x3d, 0x15, 0x66, 0x01, 0x4c, 0x96, + 0xcd, 0xa8, 0x1d, 0xa1, 0x03, 0x08, 0xb3, 0xf6, 0x98, 0xf5, 0xb6, 0xd6, 0xe0, 0xee, 0x64, 0x5c, + 0xbf, 0x9d, 0x25, 0x9a, 0xc6, 0x30, 0xa9, 0x66, 0x93, 0x76, 0x84, 0x7f, 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) { @@ -583,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 @@ -620,13 +645,20 @@ func (m *RegisteredInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, er copy(dAtA[i:], m.AccountAddress) i = encodeVarintGenesis(dAtA, i, uint64(len(m.AccountAddress))) 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 @@ -718,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)) @@ -735,6 +771,10 @@ func (m *RegisteredInterchainAccount) 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)) @@ -1264,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) } @@ -1295,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) } @@ -1378,6 +1450,38 @@ func (m *RegisteredInterchainAccount) 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) } @@ -1409,7 +1513,7 @@ func (m *RegisteredInterchainAccount) 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 AccountAddress", wireType) } diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index a855d878d30..d120fe6ac7c 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -39,13 +39,13 @@ 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 -func KeyOwnerAccount(portID string) []byte { - return []byte(fmt.Sprintf("%s/%s", OwnerKeyPrefix, portID)) +func KeyOwnerAccount(connectionID, portID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", OwnerKeyPrefix, connectionID, portID)) } // KeyPort creates and returns a new key used for port 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 f5d48a1f641..4fe7b5a813f 100644 --- a/modules/apps/27-interchain-accounts/types/keys_test.go +++ b/modules/apps/27-interchain-accounts/types/keys_test.go @@ -5,11 +5,11 @@ 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() { - key := types.KeyOwnerAccount("port-id") - suite.Require().Equal("owner/port-id", string(key)) + key := types.KeyOwnerAccount("connection-id", "port-id") + suite.Require().Equal("owner/connection-id/port-id", string(key)) } diff --git a/proto/ibc/applications/interchain_accounts/v1/genesis.proto b/proto/ibc/applications/interchain_accounts/v1/genesis.proto index 7fa49cbe2a3..3902f890708 100644 --- a/proto/ibc/applications/interchain_accounts/v1/genesis.proto +++ b/proto/ibc/applications/interchain_accounts/v1/genesis.proto @@ -36,14 +36,16 @@ 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 pairing of controller port ID and associated interchain account address +// RegisteredInterchainAccount contains a connection ID, port ID and associated interchain account address message RegisteredInterchainAccount { - string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; - string account_address = 2 [(gogoproto.moretags) = "yaml:\"account_address\""]; -} + string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""]; + string port_id = 2 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string account_address = 3 [(gogoproto.moretags) = "yaml:\"account_address\""]; +} \ No newline at end of file