From 2e07ac5719f096e3625873cb6b6a46d4c2bfdaf4 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 16 Feb 2022 18:44:11 +0100 Subject: [PATCH 1/4] fix: counterparty address must chain channelID --- docs/ibc/proto-docs.md | 2 + modules/apps/29-fee/ibc_module.go | 2 +- modules/apps/29-fee/ibc_module_test.go | 4 +- modules/apps/29-fee/keeper/genesis.go | 2 +- modules/apps/29-fee/keeper/genesis_test.go | 5 +- modules/apps/29-fee/keeper/keeper.go | 9 +- modules/apps/29-fee/keeper/keeper_test.go | 3 +- modules/apps/29-fee/keeper/msg_server.go | 2 +- modules/apps/29-fee/keeper/msg_server_test.go | 5 +- modules/apps/29-fee/transfer_test.go | 2 +- modules/apps/29-fee/types/genesis.pb.go | 122 +++++++++++++----- modules/apps/29-fee/types/keys.go | 4 +- modules/apps/29-fee/types/keys_test.go | 5 +- modules/apps/29-fee/types/msgs.go | 3 +- modules/apps/29-fee/types/msgs_test.go | 11 +- modules/apps/29-fee/types/tx.pb.go | 121 +++++++++++------ proto/ibc/applications/fee/v1/genesis.proto | 1 + proto/ibc/applications/fee/v1/tx.proto | 1 + 18 files changed, 206 insertions(+), 98 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 84127283e32..440fe1dc3eb 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -829,6 +829,7 @@ RegisteredRelayerAddress contains the address and counterparty address for a spe | ----- | ---- | ----- | ----------- | | `address` | [string](#string) | | | | `counterparty_address` | [string](#string) | | | +| `channel_id` | [string](#string) | | | @@ -1040,6 +1041,7 @@ MsgRegisterCounterpartyAddress is the request type for registering the counterpa | ----- | ---- | ----- | ----------- | | `address` | [string](#string) | | | | `counterparty_address` | [string](#string) | | | +| `channel_id` | [string](#string) | | | diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index 66e40d5d8d8..95abf578fa2 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -196,7 +196,7 @@ func (im IBCModule) OnRecvPacket( ack := im.app.OnRecvPacket(ctx, packet, relayer) - forwardRelayer, found := im.keeper.GetCounterpartyAddress(ctx, relayer.String()) + forwardRelayer, found := im.keeper.GetCounterpartyAddress(ctx, relayer.String(), packet.DestinationChannel) // incase of async aknowledgement (ack == nil) store the ForwardRelayer address for use later if ack == nil && found { diff --git a/modules/apps/29-fee/ibc_module_test.go b/modules/apps/29-fee/ibc_module_test.go index 858a6ce9dcd..a119a9b0792 100644 --- a/modules/apps/29-fee/ibc_module_test.go +++ b/modules/apps/29-fee/ibc_module_test.go @@ -448,7 +448,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { { "source relayer is empty string", func() { - suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), "") + suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), "", suite.path.EndpointB.ChannelID) }, false, true, @@ -486,7 +486,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { cbs, ok := suite.chainB.App.GetIBCKeeper().Router.GetRoute(module) suite.Require().True(ok) - suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) + suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.path.EndpointB.ChannelID) // malleate test case tc.malleate() diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index 3eec4716bec..a05f26e7677 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -13,7 +13,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { } for _, addr := range state.RegisteredRelayers { - k.SetCounterpartyAddress(ctx, addr.Address, addr.CounterpartyAddress) + k.SetCounterpartyAddress(ctx, addr.Address, addr.CounterpartyAddress, addr.ChannelId) } for _, forwardAddr := range state.ForwardRelayers { diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index 3d4f42a3c28..251585c6239 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -46,6 +46,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { { Address: sender, CounterpartyAddress: counterparty, + ChannelId: ibctesting.FirstChannelID, }, }, } @@ -62,7 +63,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().True(isEnabled) // check relayers - addr, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(suite.chainA.GetContext(), sender) + addr, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(suite.chainA.GetContext(), sender, ibctesting.FirstChannelID) suite.Require().True(found) suite.Require().Equal(genesisState.RegisteredRelayers[0].CounterpartyAddress, addr) } @@ -88,7 +89,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { sender := suite.chainA.SenderAccount.GetAddress().String() counterparty := suite.chainB.SenderAccount.GetAddress().String() // set counterparty address - suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty, ibctesting.FirstChannelID) // set forward relayer address suite.chainA.GetSimApp().IBCFeeKeeper.SetForwardRelayerAddress(suite.chainA.GetContext(), packetID, sender) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index d82e17b69a4..0778d6652cf 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -135,15 +135,15 @@ func (k Keeper) DisableAllChannels(ctx sdk.Context) { // SetCounterpartyAddress maps the destination chain relayer address to the source relayer address // The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel -func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) { +func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress, channelID string) { store := ctx.KVStore(k.storeKey) - store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress)) + store.Set(types.KeyRelayerAddress(address, channelID), []byte(counterpartyAddress)) } // GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address -func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address string) (string, bool) { +func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address, channelID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeyRelayerAddress(address) + key := types.KeyRelayerAddress(address, channelID) if !store.Has(key) { return "", false @@ -166,6 +166,7 @@ func (k Keeper) GetAllRelayerAddresses(ctx sdk.Context) []*types.RegisteredRelay addr := &types.RegisteredRelayerAddress{ Address: keySplit[1], CounterpartyAddress: string(iterator.Value()), + ChannelId: keySplit[2], } registeredAddrArr = append(registeredAddrArr, addr) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index b510aa7b7c9..43b4456293e 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -156,12 +156,13 @@ func (suite *KeeperTestSuite) TestGetAllRelayerAddresses() { sender := suite.chainA.SenderAccount.GetAddress().String() counterparty := suite.chainB.SenderAccount.GetAddress().String() - suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty, ibctesting.FirstChannelID) expectedAddr := []*types.RegisteredRelayerAddress{ { Address: sender, CounterpartyAddress: counterparty, + ChannelId: ibctesting.FirstChannelID, }, } diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 3ef24d2c443..eeff0d5ba7a 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -18,7 +18,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms ctx := sdk.UnwrapSDKContext(goCtx) k.SetCounterpartyAddress( - ctx, msg.Address, msg.CounterpartyAddress, + ctx, msg.Address, msg.CounterpartyAddress, msg.ChannelId, ) k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress) diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index f541dd3fd36..0a8ad4b7d06 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v3/testing" ) func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { @@ -35,14 +36,14 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { sender = suite.chainA.SenderAccount.GetAddress().String() counterparty = suite.chainB.SenderAccount.GetAddress().String() tc.malleate() - msg := types.NewMsgRegisterCounterpartyAddress(sender, counterparty) + msg := types.NewMsgRegisterCounterpartyAddress(sender, counterparty, ibctesting.FirstChannelID) _, err := suite.chainA.SendMsgs(msg) if tc.expPass { suite.Require().NoError(err) // message committed - counterpartyAddress, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(ctx, suite.chainA.SenderAccount.GetAddress().String()) + counterpartyAddress, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(ctx, suite.chainA.SenderAccount.GetAddress().String(), ibctesting.FirstChannelID) suite.Require().Equal(counterparty, counterpartyAddress) } else { suite.Require().Error(err) diff --git a/modules/apps/29-fee/transfer_test.go b/modules/apps/29-fee/transfer_test.go index 863b728d45f..a07d841d07c 100644 --- a/modules/apps/29-fee/transfer_test.go +++ b/modules/apps/29-fee/transfer_test.go @@ -46,7 +46,7 @@ func (suite *FeeTestSuite) TestFeeTransfer() { // to differentiate from the chainA.SenderAccount for checking successful relay payouts relayerAddress := suite.chainB.SenderAccount.GetAddress() - msgRegister := types.NewMsgRegisterCounterpartyAddress(suite.chainB.SenderAccount.GetAddress().String(), relayerAddress.String()) + msgRegister := types.NewMsgRegisterCounterpartyAddress(suite.chainB.SenderAccount.GetAddress().String(), relayerAddress.String(), ibctesting.FirstChannelID) _, err = suite.chainB.SendMsgs(msgRegister) suite.Require().NoError(err) // message committed diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index 6bcc498ac87..fbf5ccc4921 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -150,6 +150,7 @@ func (m *FeeEnabledChannel) GetChannelId() string { type RegisteredRelayerAddress struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` CounterpartyAddress string `protobuf:"bytes,2,opt,name=counterparty_address,json=counterpartyAddress,proto3" json:"counterparty_address,omitempty" yaml:"counterparty_address"` + ChannelId string `protobuf:"bytes,3,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` } func (m *RegisteredRelayerAddress) Reset() { *m = RegisteredRelayerAddress{} } @@ -199,6 +200,13 @@ func (m *RegisteredRelayerAddress) GetCounterpartyAddress() string { return "" } +func (m *RegisteredRelayerAddress) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + // ForwardRelayerAddress contains the forward relayer address and packetId used for async acknowledgements type ForwardRelayerAddress struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` @@ -264,43 +272,44 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 572 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xbf, 0x6f, 0xd4, 0x30, + // 580 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xbf, 0x6f, 0xd4, 0x30, 0x18, 0xbd, 0xb4, 0x55, 0x4b, 0x5d, 0xd4, 0x1f, 0x6e, 0x4b, 0xa3, 0x56, 0x24, 0xc5, 0x12, 0x52, 0x05, 0x34, 0xd1, 0xb5, 0x30, 0xc0, 0xc6, 0x21, 0x8a, 0x6e, 0x02, 0x19, 0x26, 0x96, 0x53, 0x2e, - 0xf9, 0x92, 0x5a, 0xe4, 0xe2, 0xc8, 0xf6, 0x05, 0xdd, 0xc0, 0x00, 0x0b, 0x8c, 0xfc, 0x59, 0x1d, - 0x3b, 0x32, 0x45, 0xa8, 0xfd, 0x0f, 0xf2, 0x17, 0xa0, 0xc4, 0x49, 0x7b, 0x1c, 0x17, 0xb6, 0x2f, - 0xf6, 0x7b, 0xdf, 0x7b, 0x7e, 0xce, 0x67, 0xf4, 0x90, 0x0d, 0x7d, 0xd7, 0x4b, 0xd3, 0x98, 0xf9, - 0x9e, 0x62, 0x3c, 0x91, 0x6e, 0x08, 0xe0, 0x66, 0x5d, 0x37, 0x82, 0x04, 0x24, 0x93, 0x4e, 0x2a, - 0xb8, 0xe2, 0x78, 0x8f, 0x0d, 0x7d, 0x67, 0x1a, 0xe6, 0x84, 0x00, 0x4e, 0xd6, 0xdd, 0xdf, 0x89, - 0x78, 0xc4, 0x2b, 0x8c, 0x5b, 0x56, 0x1a, 0xbe, 0xff, 0xa0, 0xad, 0x6b, 0xc9, 0x9a, 0x82, 0xf8, - 0x5c, 0x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x8c, 0x56, 0x12, 0x2e, 0x54, 0x8f, 0x05, 0xa6, 0x71, 0x68, 0x1c, 0xad, 0x76, 0x70, + 0x9e, 0xd9, 0xeb, 0xba, 0x67, 0x75, 0x40, 0xe8, 0x72, 0x51, 0x75, 0x03, 0xfc, 0x14, 0xa1, 0x2a, + 0xdf, 0x02, 0xbf, 0x50, 0xe2, 0x77, 0xf3, 0xcc, 0xde, 0xd2, 0xf8, 0x9b, 0x33, 0x42, 0x57, 0xab, + 0x45, 0x37, 0x20, 0x3f, 0x0d, 0x64, 0x36, 0x05, 0x88, 0x4d, 0xb4, 0xe2, 0xe9, 0x52, 0xeb, 0xd3, + 0x7a, 0x89, 0x29, 0xda, 0xf1, 0xf9, 0x28, 0x56, 0x20, 0x12, 0x4f, 0xa8, 0x71, 0xaf, 0x86, 0x69, + 0xd9, 0xa9, 0xe7, 0x9f, 0x87, 0x22, 0x74, 0x7b, 0x7a, 0xbb, 0x56, 0xbb, 0x7d, 0x81, 0xc5, 0xff, + 0xbc, 0xc0, 0x77, 0x03, 0xed, 0xce, 0x7d, 0x80, 0x7f, 0xb8, 0xff, 0x80, 0x56, 0x93, 0x72, 0x4a, + 0xea, 0xa4, 0xd6, 0x4e, 0xee, 0x97, 0xaf, 0x5b, 0xcc, 0xa9, 0x53, 0x0f, 0x67, 0xda, 0x76, 0xf4, + 0x2c, 0x75, 0x83, 0x8e, 0x59, 0x8d, 0xd2, 0x66, 0x15, 0x7e, 0xcd, 0x26, 0xf4, 0x4e, 0x52, 0x63, + 0xde, 0x5e, 0x5c, 0x59, 0xc6, 0xe5, 0x95, 0x65, 0xfc, 0xbe, 0xb2, 0x8c, 0x1f, 0x13, 0xab, 0x75, + 0x39, 0xb1, 0x5a, 0xbf, 0x26, 0x56, 0xeb, 0xe3, 0xb3, 0x01, 0x53, 0xe7, 0xa3, 0xbe, 0xe3, 0xf3, + 0xa1, 0xeb, 0x73, 0x39, 0xe4, 0xd2, 0x65, 0x7d, 0xff, 0x78, 0xc0, 0xdd, 0xf4, 0xd4, 0x1d, 0xf2, + 0x60, 0x14, 0x81, 0x2c, 0xbe, 0x11, 0xe9, 0x9e, 0x3c, 0x3f, 0x2e, 0x7e, 0x10, 0x35, 0x4e, 0x40, + 0xf6, 0x97, 0xcb, 0xef, 0xe1, 0xf4, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x11, 0xd7, 0x15, 0xf2, + 0xbc, 0x04, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -439,6 +448,13 @@ func (m *RegisteredRelayerAddress) MarshalToSizedBuffer(dAtA []byte) (int, error _ = i var l int _ = l + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x1a + } if len(m.CounterpartyAddress) > 0 { i -= len(m.CounterpartyAddress) copy(dAtA[i:], m.CounterpartyAddress) @@ -571,6 +587,10 @@ func (m *RegisteredRelayerAddress) Size() (n int) { if l > 0 { n += 1 + l + sovGenesis(uint64(l)) } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -988,6 +1008,38 @@ func (m *RegisteredRelayerAddress) Unmarshal(dAtA []byte) error { } m.CounterpartyAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", 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.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index b13aa2ba4b8..a8abc49d04c 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -44,8 +44,8 @@ func FeeEnabledKey(portID, channelID string) []byte { } // KeyRelayerAddress returns the key for relayer address -> counteryparty address mapping -func KeyRelayerAddress(address string) []byte { - return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) +func KeyRelayerAddress(address, channelID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", RelayerAddressKeyPrefix, address, channelID)) } // KeyForwardRelayerAddress returns the key for packetID -> forwardAddress mapping diff --git a/modules/apps/29-fee/types/keys_test.go b/modules/apps/29-fee/types/keys_test.go index fbe2c2bbdde..da652c1a274 100644 --- a/modules/apps/29-fee/types/keys_test.go +++ b/modules/apps/29-fee/types/keys_test.go @@ -12,8 +12,9 @@ import ( func TestKeyRelayerAddress(t *testing.T) { var ( relayerAddress = "relayer_address" + channelID = "channel-0" ) - key := types.KeyRelayerAddress(relayerAddress) - require.Equal(t, string(key), fmt.Sprintf("%s/relayer_address", types.RelayerAddressKeyPrefix)) + key := types.KeyRelayerAddress(relayerAddress, channelID) + require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.RelayerAddressKeyPrefix, relayerAddress, channelID)) } diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index f3abe737472..361952afced 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -17,10 +17,11 @@ const ( ) // NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress -func NewMsgRegisterCounterpartyAddress(address, counterpartyAddress string) *MsgRegisterCounterpartyAddress { +func NewMsgRegisterCounterpartyAddress(address, counterpartyAddress, channelID string) *MsgRegisterCounterpartyAddress { return &MsgRegisterCounterpartyAddress{ Address: address, CounterpartyAddress: counterpartyAddress, + ChannelId: channelID, } } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 57b38a07086..829d7adc9be 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" ) @@ -26,10 +27,10 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { msg *MsgRegisterCounterpartyAddress expPass bool }{ - {"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true}, - {"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false}, - {"invalid counterparty address", NewMsgRegisterCounterpartyAddress(validAddr, ""), false}, - {"invalid counterparty address: whitespaced empty string", NewMsgRegisterCounterpartyAddress(validAddr, " "), false}, + {"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr, validChannelID), true}, + {"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr, validChannelID), false}, + {"invalid counterparty address", NewMsgRegisterCounterpartyAddress(validAddr, "", validChannelID), false}, + {"invalid counterparty address: whitespaced empty string", NewMsgRegisterCounterpartyAddress(validAddr, " ", validChannelID), false}, } for i, tc := range testCases { @@ -46,7 +47,7 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { func TestRegisterCountepartyAddressGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) // build message - msg := NewMsgRegisterCounterpartyAddress(addr.String(), "counterparty") + msg := NewMsgRegisterCounterpartyAddress(addr.String(), "counterparty", validChannelID) // GetSigners res := msg.GetSigners() diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 624c6d8279a..a7f8e1d3bee 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -32,6 +32,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MsgRegisterCounterpartyAddress struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` CounterpartyAddress string `protobuf:"bytes,2,opt,name=counterparty_address,json=counterpartyAddress,proto3" json:"counterparty_address,omitempty" yaml:"counterparty_address"` + ChannelId string `protobuf:"bytes,3,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` } func (m *MsgRegisterCounterpartyAddress) Reset() { *m = MsgRegisterCounterpartyAddress{} } @@ -280,44 +281,45 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 577 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x4f, 0xdb, 0x4c, - 0x10, 0xc6, 0x6d, 0xc2, 0xcb, 0x0b, 0x5b, 0x54, 0x84, 0x09, 0x25, 0x98, 0xc8, 0x4e, 0xad, 0xaa, - 0xca, 0xa1, 0xb1, 0x4b, 0x28, 0xaa, 0xca, 0x05, 0x11, 0x24, 0xd4, 0x1c, 0xa2, 0x46, 0x3e, 0xf6, - 0x12, 0x39, 0xeb, 0x89, 0xd9, 0x36, 0xf1, 0x5a, 0xbb, 0x9b, 0xa8, 0xfe, 0x02, 0xa8, 0x47, 0x6e, - 0xed, 0x91, 0x6b, 0xbf, 0x09, 0x47, 0x8e, 0x3d, 0x45, 0x55, 0x72, 0xe9, 0x39, 0x9f, 0xa0, 0xb2, - 0x9d, 0x84, 0x84, 0xfc, 0x11, 0xed, 0xcd, 0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0xe9, 0xcb, 0x47, 0x4c, 0x3d, 0xfd, 0xc7, 0xc0, 0x51, 0x85, 0xca, 0x27, - 0xb4, 0x39, 0x35, 0x97, 0xf9, 0x65, 0x82, 0x93, 0xa4, 0xfa, 0xfa, 0xb1, 0xe4, 0x38, 0x57, 0x88, - 0xb6, 0x67, 0xff, 0x6a, 0xe1, 0xb1, 0x32, 0x31, 0xae, 0x1e, 0xff, 0x15, 0x3e, 0x4a, 0x5d, 0xfa, - 0x70, 0xdb, 0xd3, 0xe4, 0xbb, 0x9e, 0x26, 0xff, 0xea, 0x69, 0xf2, 0x75, 0x5f, 0x93, 0xee, 0xfa, - 0x9a, 0xf4, 0xb3, 0xaf, 0x49, 0x1f, 0x8f, 0x3d, 0x22, 0x2e, 0xdb, 0x75, 0x13, 0xd3, 0x96, 0x85, - 0x29, 0x6f, 0x51, 0x6e, 0x91, 0x3a, 0x2e, 0x78, 0xd4, 0xea, 0x1c, 0x59, 0x2d, 0xea, 0xb6, 0x9b, - 0xc0, 0xa3, 0x25, 0xc5, 0xad, 0xe2, 0xbb, 0x42, 0xb4, 0x9f, 0x44, 0x18, 0x00, 0xaf, 0xaf, 0xc5, - 0xfb, 0xe9, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x81, 0xea, 0x8a, 0x9a, 0x15, 0x05, 0x00, - 0x00, + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4d, 0x4f, 0xdb, 0x4c, + 0x10, 0xc7, 0x6d, 0xc2, 0xc3, 0x03, 0x5b, 0x54, 0x84, 0x81, 0x62, 0x4c, 0x64, 0x53, 0xab, 0xaa, + 0x72, 0x28, 0x76, 0x79, 0x53, 0x55, 0x2e, 0x88, 0x20, 0xa1, 0x72, 0x40, 0x8d, 0x7c, 0xec, 0x25, + 0x72, 0xd6, 0x13, 0xb3, 0x6d, 0xe2, 0xb5, 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 0xa6, 0xba, 0x78, 0x91, 0x57, 0xe5, 0x92, 0xd5, 0x17, 0xb1, 0xab, 0x83, + 0x48, 0x2b, 0xa7, 0x23, 0x4f, 0x14, 0xd6, 0xad, 0x35, 0x32, 0x5e, 0x5a, 0x18, 0x43, 0x45, 0xe5, + 0x49, 0xad, 0x66, 0xb3, 0xec, 0x5f, 0x97, 0x50, 0xe9, 0x92, 0xb9, 0xd2, 0x57, 0x11, 0x6d, 0xcf, + 0x7a, 0xf9, 0x6f, 0xa6, 0xb6, 0x3e, 0xfb, 0x89, 0x29, 0x27, 0xff, 0x58, 0x98, 0x75, 0x28, 0x7d, + 0x44, 0xcb, 0x23, 0xef, 0xb2, 0x32, 0x4b, 0xb0, 0x48, 0x2a, 0xaf, 0x1f, 0x4b, 0xe6, 0x67, 0x85, + 0x68, 0x75, 0xfc, 0x56, 0x77, 0x1f, 0x2b, 0x93, 0xe0, 0xca, 0xd1, 0x5f, 0xe1, 0xd9, 0xd1, 0xd5, + 0xf7, 0x77, 0x3d, 0x55, 0xbc, 0xef, 0xa9, 0xe2, 0xcf, 0x9e, 0x2a, 0xde, 0xf4, 0x55, 0xe1, 0xbe, + 0xaf, 0x0a, 0x3f, 0xfa, 0xaa, 0xf0, 0xe1, 0xc8, 0x25, 0xfc, 0xaa, 0xd3, 0x30, 0x30, 0x6d, 0x9b, + 0x98, 0xb2, 0x36, 0x65, 0x26, 0x69, 0xe0, 0x5d, 0x97, 0x9a, 0xdd, 0x03, 0xb3, 0x4d, 0x9d, 0x4e, + 0x0b, 0x58, 0xfc, 0xb5, 0x31, 0x73, 0xff, 0xed, 0x6e, 0xfc, 0xab, 0xf1, 0xd0, 0x07, 0xd6, 0x58, + 0x48, 0x7e, 0xb5, 0x83, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcf, 0x27, 0xb3, 0x4f, 0x4b, 0x05, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -514,6 +516,13 @@ func (m *MsgRegisterCounterpartyAddress) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x1a + } if len(m.CounterpartyAddress) > 0 { i -= len(m.CounterpartyAddress) copy(dAtA[i:], m.CounterpartyAddress) @@ -721,6 +730,10 @@ func (m *MsgRegisterCounterpartyAddress) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -890,6 +903,38 @@ func (m *MsgRegisterCounterpartyAddress) Unmarshal(dAtA []byte) error { } m.CounterpartyAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index 2396cf6d272..9abb0c722f9 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -27,6 +27,7 @@ message FeeEnabledChannel { message RegisteredRelayerAddress { string address = 1; string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; + string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; } // ForwardRelayerAddress contains the forward relayer address and packetId used for async acknowledgements diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 900764f9343..532524cd4b2 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -32,6 +32,7 @@ message MsgRegisterCounterpartyAddress { string address = 1; string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; + string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; } // MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type From b0f21d323f90f5ddc44b5153db42dde5ee0ffab9 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 21 Feb 2022 15:58:00 +0100 Subject: [PATCH 2/4] nit: updating var name --- modules/apps/29-fee/keeper/genesis.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index a05f26e7677..aff999ec8aa 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -12,8 +12,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { k.SetFeeInEscrow(ctx, fee) } - for _, addr := range state.RegisteredRelayers { - k.SetCounterpartyAddress(ctx, addr.Address, addr.CounterpartyAddress, addr.ChannelId) + for _, relayer := range state.RegisteredRelayers { + k.SetCounterpartyAddress(ctx, relayer.Address, relayer.CounterpartyAddress, relayer.ChannelId) } for _, forwardAddr := range state.ForwardRelayers { From b636a81b6ac4c551dbdc7fc2712f17b9cc628749 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 21 Feb 2022 16:04:03 +0100 Subject: [PATCH 3/4] test: adding validation check for channelID --- modules/apps/29-fee/types/msgs.go | 5 +++++ modules/apps/29-fee/types/msgs_test.go | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 361952afced..50e6584e26b 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -36,6 +36,11 @@ func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { return ErrCounterpartyAddressEmpty } + // validate channelId + if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil { + return err + } + return nil } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 829d7adc9be..c4ee1a477f1 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -11,13 +11,14 @@ import ( ) var ( - validChannelID = "channel-1" - validPortID = "validPortId" - invalidID = "this identifier is too long to be used as a valid identifier" - validCoins = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} - invalidCoins = sdk.Coins{sdk.Coin{Denom: "invalid-denom", Amount: sdk.NewInt(-2)}} - validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - invalidAddr = "invalid_address" + validChannelID = "channel-1" + invalidChannelID = "ch-1" + validPortID = "validPortId" + invalidID = "this identifier is too long to be used as a valid identifier" + validCoins = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} + invalidCoins = sdk.Coins{sdk.Coin{Denom: "invalid-denom", Amount: sdk.NewInt(-2)}} + validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + invalidAddr = "invalid_address" ) // TestMsgTransferValidation tests ValidateBasic for MsgTransfer @@ -31,6 +32,7 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { {"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr, validChannelID), false}, {"invalid counterparty address", NewMsgRegisterCounterpartyAddress(validAddr, "", validChannelID), false}, {"invalid counterparty address: whitespaced empty string", NewMsgRegisterCounterpartyAddress(validAddr, " ", validChannelID), false}, + {"invalid channelID", NewMsgRegisterCounterpartyAddress(validAddr, validAddr, invalidChannelID), false}, } for i, tc := range testCases { From 4d9836114a28268dbc20f3704c0becdb7e52afbb Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 22 Feb 2022 12:26:58 +0100 Subject: [PATCH 4/4] nit: fn names --- modules/apps/29-fee/keeper/keeper.go | 6 +++--- modules/apps/29-fee/types/keys.go | 10 +++++----- modules/apps/29-fee/types/keys_test.go | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index ea5875f3690..390d2f5e51c 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -137,13 +137,13 @@ func (k Keeper) DisableAllChannels(ctx sdk.Context) { // The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress, channelID string) { store := ctx.KVStore(k.storeKey) - store.Set(types.KeyRelayerAddress(address, channelID), []byte(counterpartyAddress)) + store.Set(types.KeyCounterpartyRelayer(address, channelID), []byte(counterpartyAddress)) } // GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address, channelID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeyRelayerAddress(address, channelID) + key := types.KeyCounterpartyRelayer(address, channelID) if !store.Has(key) { return "", false @@ -156,7 +156,7 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address, channelID strin // GetAllRelayerAddresses returns all registered relayer addresses func (k Keeper) GetAllRelayerAddresses(ctx sdk.Context) []types.RegisteredRelayerAddress { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte(types.RelayerAddressKeyPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.CounterpartyRelayerAddressKeyPrefix)) defer iterator.Close() var registeredAddrArr []types.RegisteredRelayerAddress diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 2c16f14cbed..d65d8efcbef 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -24,8 +24,8 @@ const ( // FeeEnabledPrefix is the key prefix for storing fee enabled flag FeeEnabledKeyPrefix = "feeEnabled" - // RelayerAddressKeyPrefix is the key prefix for relayer address mapping - RelayerAddressKeyPrefix = "relayerAddress" + // CounterpartyRelayerAddressKeyPrefix is the key prefix for relayer address mapping + CounterpartyRelayerAddressKeyPrefix = "relayerAddress" // FeeInEscrowPrefix is the key prefix for fee in escrow mapping FeeInEscrowPrefix = "feeInEscrow" @@ -47,9 +47,9 @@ func FeeEnabledKey(portID, channelID string) []byte { return []byte(fmt.Sprintf("%s/%s/%s", FeeEnabledKeyPrefix, portID, channelID)) } -// KeyRelayerAddress returns the key for relayer address -> counteryparty address mapping -func KeyRelayerAddress(address, channelID string) []byte { - return []byte(fmt.Sprintf("%s/%s/%s", RelayerAddressKeyPrefix, address, channelID)) +// KeyCounterpartyRelayer returns the key for relayer address -> counteryparty address mapping +func KeyCounterpartyRelayer(address, channelID string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", CounterpartyRelayerAddressKeyPrefix, address, channelID)) } // KeyForwardRelayerAddress returns the key for packetID -> forwardAddress mapping diff --git a/modules/apps/29-fee/types/keys_test.go b/modules/apps/29-fee/types/keys_test.go index da652c1a274..a49532b753b 100644 --- a/modules/apps/29-fee/types/keys_test.go +++ b/modules/apps/29-fee/types/keys_test.go @@ -9,12 +9,12 @@ import ( "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" ) -func TestKeyRelayerAddress(t *testing.T) { +func TestKeyCounterpartyRelayer(t *testing.T) { var ( relayerAddress = "relayer_address" channelID = "channel-0" ) - key := types.KeyRelayerAddress(relayerAddress, channelID) - require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.RelayerAddressKeyPrefix, relayerAddress, channelID)) + key := types.KeyCounterpartyRelayer(relayerAddress, channelID) + require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.CounterpartyRelayerAddressKeyPrefix, relayerAddress, channelID)) }