From ef53ea17bb72fd03302e5f978f355052ba7e3578 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 3 Sep 2021 18:12:06 +0200 Subject: [PATCH 01/15] feat: adding MsgServer for RegisterCounterPartyAddress & EscrowPacketFree --- docs/ibc/proto-docs.md | 24 ++-- modules/apps/29-fee/keeper/keeper.go | 31 ++-- modules/apps/29-fee/keeper/msg_server.go | 37 ++++- modules/apps/29-fee/types/expected_keepers.go | 2 - modules/apps/29-fee/types/keys.go | 10 ++ modules/apps/29-fee/types/msgs.go | 36 +++-- modules/apps/29-fee/types/tx.pb.go | 132 +++++++++--------- proto/ibc/applications/fee/v1/tx.proto | 6 +- 8 files changed, 169 insertions(+), 109 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index f571101508f..ff79278b80a 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -49,8 +49,8 @@ - [ibc/applications/fee/v1/tx.proto](#ibc/applications/fee/v1/tx.proto) - [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee) - [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse) - - [MsgRegisterCounterPartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse) - [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) + - [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) - [Msg](#ibc.applications.fee.v1.Msg) @@ -915,16 +915,6 @@ MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee - - -### MsgRegisterCounterPartyAddressResponse -MsgRegisterCounterPartyAddressResponse defines the Msg/RegisterCounteryPartyAddress response type - - - - - - ### MsgRegisterCounterpartyAddress @@ -940,6 +930,16 @@ MsgRegisterCounterpartyAddress is the request type for registering the counter p + + + +### MsgRegisterCounterpartyAddressResponse +MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type + + + + + @@ -954,7 +954,7 @@ Msg defines the ibc/fee Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `RegisterCounterPartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterPartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | | +| `RegisterCounterpartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | | | `EscrowPacketFee` | [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee) | [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse) | EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of the given packet. | | diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index db304dd4cf9..9b7eecc6d31 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -1,15 +1,13 @@ package keeper -/* import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/ibc-go/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" host "github.com/cosmos/ibc-go/modules/core/24-host" ) @@ -25,7 +23,6 @@ type Keeper struct { scopedKeeper capabilitykeeper.ScopedKeeper } - // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, @@ -49,6 +46,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName) } +/* // IsBound checks if the transfer module is already bound to the desired port func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) @@ -62,12 +60,6 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error { return k.ClaimCapability(ctx, cap, host.PortPath(portID)) } -// GetPort returns the portID for the transfer module. Used in ExportGenesis -func (k Keeper) GetPort(ctx sdk.Context) string { - store := ctx.KVStore(k.storeKey) - return string(store.Get(types.PortKey)) -} - // SetPort sets the portID for the transfer module. Used in InitGenesis func (k Keeper) SetPort(ctx sdk.Context, portID string) { store := ctx.KVStore(k.storeKey) @@ -85,3 +77,22 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability return k.scopedKeeper.ClaimCapability(ctx, cap, name) } */ + +// SetCounterPartyAddress maps the counterparty relayer address to the source relayer address +func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, SourceAddress, CounterpartyAddress string) { + store := ctx.KVStore(k.storeKey) + store.Set(types.KeySourceAddress(SourceAddress), []byte(CounterpartyAddress)) +} + +// GetCounterPartyAddress gets the relayer counterparty address given a source address +func (k Keeper) GetCounterPartyAddress(ctx sdk.Context, sourceAddress sdk.AccAddress) (sdk.AccAddress, bool) { + store := ctx.KVStore(k.storeKey) + key := types.KeySourceAddress(sourceAddress.String()) + + if !store.Has(key) { + // TODO: add logging here + return []byte{}, false + } + + return store.Get(key), true +} diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 2194eed8a68..d10f424330c 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -1,4 +1,37 @@ package keeper -// TODO -//var _ types.MsgServer = Keeper{} +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" +) + +var _ types.MsgServer = Keeper{} + +// RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying +// This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement +// This function may be called more than once by relayer, in which case, latest counterparty address is always used. +func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if err := msg.ValidateBasic(); err != nil { + return &types.MsgRegisterCounterpartyAddressResponse{}, nil + } + + k.SetCounterpartyAddress( + ctx, msg.Address, msg.CounterpartyAddress, + ) + + k.Logger(ctx).Info("Registering counterparty address for relayer with:", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress) + + return &types.MsgRegisterCounterPartyAddressResponse{}, nil +} + +// EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee +// EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to +// incentivize the relaying of the given packet. +func (k Keeper) EscrowPacketFee(goCtx context.Context, msg *types.MsgEscrowPacketFee) (*types.MsgEscrowPacketFeeResponse, error) { + return &types.MsgEscrowPacketFeeResponse{}, nil +} diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 68513b476a5..df16f947c4b 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -1,6 +1,5 @@ package types -/* import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -47,4 +46,3 @@ type ConnectionKeeper interface { type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability } -*/ diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 769113f504a..0be960b9cfd 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -1,5 +1,7 @@ package types +import fmt "fmt" + const ( // ModuleName defines the 29-fee name ModuleName = "ibcfee" @@ -7,9 +9,17 @@ const ( // StoreKey is the store key string for IBC transfer StoreKey = ModuleName + // PortKey is the port id that is wrapped by fee middleware + PortKey = "feetransfer" + // RouterKey is the message route for IBC transfer RouterKey = ModuleName // QuerierRoute is the querier route for IBC transfer QuerierRoute = ModuleName ) + +// Key for relayer source address -> counteryparty address mapping +func KeySourceAddress(sourceAddress string) []byte { + return []byte(fmt.Sprintf("relayerSourceAddress/%s", sourceAddress)) +} diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 4df0e84ff1a..fbfc6f89a30 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -1,32 +1,40 @@ package types -/* import ( - "strings" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" - host "github.com/cosmos/ibc-go/modules/core/24-host" ) -// NewMsg -func NewMsg() *Msg { - return &Msg{ - } +// msg types +const ( + TypeMsgRegisterCounterPartyAddress = "registerCounterPartyAddress" +) + +// NewMsgRegisterCounterPartyAddress +func NewMsgRegisterCounterPartyAddress(sourceAddress, counterPartyAddress string) *MsgRegisterCounterpartyAddress { + return &MsgRegisterCounterpartyAddress{Address: sourceAddress, CounterpartyAddress: counterPartyAddress} } -// ValidateBasic performs a basic check of the Msg fields. -func (msg Msg) ValidateBasic() error { +// ValidateBasic performs a basic check of the Msg fields +func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Address) + if err != nil { + return sdkerrors.Wrap(err, "Incorrect source relayer address") + } + + _, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress) + if err != nil { + return sdkerrors.Wrap(err, "Incorrect counterparty relayer address") + } + return nil } // GetSigners implements sdk.Msg -func (msg MsgTransfer) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Sender) +func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { panic(err) } return []sdk.AccAddress{signer} } -*/ diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index cb46345e9f1..c9fb330d12b 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -68,24 +68,24 @@ func (m *MsgRegisterCounterpartyAddress) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterCounterpartyAddress proto.InternalMessageInfo -// MsgRegisterCounterPartyAddressResponse defines the Msg/RegisterCounteryPartyAddress response type -type MsgRegisterCounterPartyAddressResponse struct { +// MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type +type MsgRegisterCounterpartyAddressResponse struct { } -func (m *MsgRegisterCounterPartyAddressResponse) Reset() { - *m = MsgRegisterCounterPartyAddressResponse{} +func (m *MsgRegisterCounterpartyAddressResponse) Reset() { + *m = MsgRegisterCounterpartyAddressResponse{} } -func (m *MsgRegisterCounterPartyAddressResponse) String() string { return proto.CompactTextString(m) } -func (*MsgRegisterCounterPartyAddressResponse) ProtoMessage() {} -func (*MsgRegisterCounterPartyAddressResponse) Descriptor() ([]byte, []int) { +func (m *MsgRegisterCounterpartyAddressResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterCounterpartyAddressResponse) ProtoMessage() {} +func (*MsgRegisterCounterpartyAddressResponse) Descriptor() ([]byte, []int) { return fileDescriptor_05c93128649f1b96, []int{1} } -func (m *MsgRegisterCounterPartyAddressResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgRegisterCounterpartyAddressResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgRegisterCounterPartyAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgRegisterCounterpartyAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgRegisterCounterPartyAddressResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgRegisterCounterpartyAddressResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -95,17 +95,17 @@ func (m *MsgRegisterCounterPartyAddressResponse) XXX_Marshal(b []byte, determini return b[:n], nil } } -func (m *MsgRegisterCounterPartyAddressResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgRegisterCounterPartyAddressResponse.Merge(m, src) +func (m *MsgRegisterCounterpartyAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterCounterpartyAddressResponse.Merge(m, src) } -func (m *MsgRegisterCounterPartyAddressResponse) XXX_Size() int { +func (m *MsgRegisterCounterpartyAddressResponse) XXX_Size() int { return m.Size() } -func (m *MsgRegisterCounterPartyAddressResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgRegisterCounterPartyAddressResponse.DiscardUnknown(m) +func (m *MsgRegisterCounterpartyAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterCounterpartyAddressResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgRegisterCounterPartyAddressResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgRegisterCounterpartyAddressResponse proto.InternalMessageInfo // MsgEscrowPacketFee defines the request type EscrowPacketFee RPC type MsgEscrowPacketFee struct { @@ -185,7 +185,7 @@ var xxx_messageInfo_MsgEscrowPacketFeeResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgRegisterCounterpartyAddress)(nil), "ibc.applications.fee.v1.MsgRegisterCounterpartyAddress") - proto.RegisterType((*MsgRegisterCounterPartyAddressResponse)(nil), "ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse") + proto.RegisterType((*MsgRegisterCounterpartyAddressResponse)(nil), "ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse") proto.RegisterType((*MsgEscrowPacketFee)(nil), "ibc.applications.fee.v1.MsgEscrowPacketFee") proto.RegisterType((*MsgEscrowPacketFeeResponse)(nil), "ibc.applications.fee.v1.MsgEscrowPacketFeeResponse") } @@ -193,36 +193,36 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 454 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcf, 0x6b, 0xd4, 0x40, + // 451 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x41, 0x6b, 0xd4, 0x40, 0x14, 0xc7, 0x93, 0x16, 0xb4, 0x1d, 0x0f, 0xc2, 0xb4, 0x60, 0x49, 0x25, 0xa9, 0x39, 0xc8, 0x82, - 0x36, 0x43, 0xb7, 0x07, 0xb1, 0x17, 0x71, 0x45, 0x41, 0x70, 0xa1, 0xe4, 0xe8, 0xa5, 0x4c, 0x26, - 0x6f, 0xa7, 0x83, 0xd9, 0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xa9, 0x59, 0x5f, 0xe7, 0x83, 0x02, 0xd0, 0xad, 0x0c, 0xb2, 0xf6, 0xf3, 0x7d, 0xb7, 0x2d, - 0x76, 0x54, 0x01, 0x66, 0x77, 0xa6, 0xab, 0x70, 0xf8, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x58, 0x35, - 0x6c, 0xa4, 0xa3, 0x03, 0x00, 0x00, + 0x36, 0x43, 0xb7, 0x07, 0xb1, 0x17, 0x71, 0x45, 0x41, 0x70, 0x41, 0x72, 0xf4, 0x52, 0x26, 0x93, + 0xb7, 0xd3, 0xc1, 0x6c, 0x26, 0xcc, 0x9b, 0x5d, 0x5d, 0xc1, 0xbb, 0x47, 0x0f, 0x82, 0x1e, 0xfb, + 0x35, 0xfc, 0x06, 0x1e, 0x7b, 0xf4, 0x54, 0x64, 0xf7, 0xe2, 0xb9, 0x9f, 0x40, 0x66, 0x63, 0x4a, + 0x68, 0x77, 0x17, 0xf4, 0xf6, 0x26, 0xf3, 0xfb, 0xbf, 0x79, 0xff, 0x7f, 0x78, 0x64, 0x4f, 0x65, + 0x82, 0xf1, 0xaa, 0x2a, 0x94, 0xe0, 0x56, 0xe9, 0x12, 0xd9, 0x00, 0x80, 0x8d, 0x0f, 0x98, 0x7d, + 0x9f, 0x54, 0x46, 0x5b, 0x4d, 0xef, 0xa8, 0x4c, 0x24, 0x6d, 0x22, 0x19, 0x00, 0x24, 0xe3, 0x83, + 0x60, 0x5b, 0x6a, 0xa9, 0xe7, 0x0c, 0x73, 0x55, 0x8d, 0x07, 0xf7, 0x96, 0x35, 0x74, 0xaa, 0x16, + 0x22, 0xb4, 0x01, 0x26, 0x4e, 0x78, 0x59, 0x42, 0xe1, 0xae, 0xff, 0x96, 0x35, 0x12, 0x7f, 0xf3, + 0x49, 0xd8, 0x47, 0x99, 0x82, 0x54, 0x68, 0xc1, 0x3c, 0xd3, 0xa3, 0xd2, 0x82, 0xa9, 0xb8, 0xb1, + 0x93, 0xa7, 0x79, 0x6e,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35, 0xf7, 0x07, 0xab, 0x7a, 0x5e, 0x81, 0x83, + 0xc3, 0x7f, 0x80, 0x9b, 0x47, 0x7b, 0xaf, 0x7e, 0x4c, 0x43, 0xff, 0x6c, 0x1a, 0xfa, 0xbf, 0xa6, + 0xa1, 0xff, 0x79, 0x16, 0x7a, 0x67, 0xb3, 0xd0, 0xfb, 0x39, 0x0b, 0xbd, 0x37, 0x5d, 0xa9, 0xec, + 0xc9, 0x28, 0x4b, 0x84, 0x1e, 0x32, 0xa1, 0x71, 0xa8, 0x91, 0xa9, 0x4c, 0xec, 0x4b, 0xcd, 0x86, + 0x3a, 0x1f, 0x15, 0x80, 0x6e, 0x65, 0x90, 0x75, 0x1f, 0xef, 0xbb, 0x6d, 0xb1, 0x93, 0x0a, 0x30, + 0xbb, 0x31, 0x5f, 0x85, 0xc3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x9e, 0xf3, 0xe6, 0xf1, 0xa3, + 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -242,7 +242,7 @@ type MsgClient interface { // counterparty address before relaying. This ensures they will be properly compensated for forward relaying since // destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function // may be called more than once by a relayer, in which case, latest counterparty address is always used. - RegisterCounterPartyAddress(ctx context.Context, in *MsgRegisterCounterpartyAddress, opts ...grpc.CallOption) (*MsgRegisterCounterPartyAddressResponse, error) + RegisterCounterpartyAddress(ctx context.Context, in *MsgRegisterCounterpartyAddress, opts ...grpc.CallOption) (*MsgRegisterCounterpartyAddressResponse, error) // EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee // EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to // incentivize the relaying of the given packet. @@ -257,9 +257,9 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) RegisterCounterPartyAddress(ctx context.Context, in *MsgRegisterCounterpartyAddress, opts ...grpc.CallOption) (*MsgRegisterCounterPartyAddressResponse, error) { - out := new(MsgRegisterCounterPartyAddressResponse) - err := c.cc.Invoke(ctx, "/ibc.applications.fee.v1.Msg/RegisterCounterPartyAddress", in, out, opts...) +func (c *msgClient) RegisterCounterpartyAddress(ctx context.Context, in *MsgRegisterCounterpartyAddress, opts ...grpc.CallOption) (*MsgRegisterCounterpartyAddressResponse, error) { + out := new(MsgRegisterCounterpartyAddressResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.fee.v1.Msg/RegisterCounterpartyAddress", in, out, opts...) if err != nil { return nil, err } @@ -282,7 +282,7 @@ type MsgServer interface { // counterparty address before relaying. This ensures they will be properly compensated for forward relaying since // destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function // may be called more than once by a relayer, in which case, latest counterparty address is always used. - RegisterCounterPartyAddress(context.Context, *MsgRegisterCounterpartyAddress) (*MsgRegisterCounterPartyAddressResponse, error) + RegisterCounterpartyAddress(context.Context, *MsgRegisterCounterpartyAddress) (*MsgRegisterCounterpartyAddressResponse, error) // EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee // EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to // incentivize the relaying of the given packet. @@ -293,8 +293,8 @@ type MsgServer interface { type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) RegisterCounterPartyAddress(ctx context.Context, req *MsgRegisterCounterpartyAddress) (*MsgRegisterCounterPartyAddressResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method RegisterCounterPartyAddress not implemented") +func (*UnimplementedMsgServer) RegisterCounterpartyAddress(ctx context.Context, req *MsgRegisterCounterpartyAddress) (*MsgRegisterCounterpartyAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterCounterpartyAddress not implemented") } func (*UnimplementedMsgServer) EscrowPacketFee(ctx context.Context, req *MsgEscrowPacketFee) (*MsgEscrowPacketFeeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method EscrowPacketFee not implemented") @@ -304,20 +304,20 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_RegisterCounterPartyAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Msg_RegisterCounterpartyAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgRegisterCounterpartyAddress) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).RegisterCounterPartyAddress(ctx, in) + return srv.(MsgServer).RegisterCounterpartyAddress(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/ibc.applications.fee.v1.Msg/RegisterCounterPartyAddress", + FullMethod: "/ibc.applications.fee.v1.Msg/RegisterCounterpartyAddress", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).RegisterCounterPartyAddress(ctx, req.(*MsgRegisterCounterpartyAddress)) + return srv.(MsgServer).RegisterCounterpartyAddress(ctx, req.(*MsgRegisterCounterpartyAddress)) } return interceptor(ctx, in, info, handler) } @@ -345,8 +345,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "RegisterCounterPartyAddress", - Handler: _Msg_RegisterCounterPartyAddress_Handler, + MethodName: "RegisterCounterpartyAddress", + Handler: _Msg_RegisterCounterpartyAddress_Handler, }, { MethodName: "EscrowPacketFee", @@ -394,7 +394,7 @@ func (m *MsgRegisterCounterpartyAddress) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } -func (m *MsgRegisterCounterPartyAddressResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgRegisterCounterpartyAddressResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -404,12 +404,12 @@ func (m *MsgRegisterCounterPartyAddressResponse) Marshal() (dAtA []byte, err err return dAtA[:n], nil } -func (m *MsgRegisterCounterPartyAddressResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRegisterCounterpartyAddressResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRegisterCounterPartyAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRegisterCounterpartyAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -512,7 +512,7 @@ func (m *MsgRegisterCounterpartyAddress) Size() (n int) { return n } -func (m *MsgRegisterCounterPartyAddressResponse) Size() (n int) { +func (m *MsgRegisterCounterpartyAddressResponse) Size() (n int) { if m == nil { return 0 } @@ -669,7 +669,7 @@ func (m *MsgRegisterCounterpartyAddress) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgRegisterCounterPartyAddressResponse) Unmarshal(dAtA []byte) error { +func (m *MsgRegisterCounterpartyAddressResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -692,10 +692,10 @@ func (m *MsgRegisterCounterPartyAddressResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgRegisterCounterPartyAddressResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgRegisterCounterpartyAddressResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgRegisterCounterPartyAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgRegisterCounterpartyAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 85ee09d0672..f9b56cf5011 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -14,7 +14,7 @@ service Msg { // counterparty address before relaying. This ensures they will be properly compensated for forward relaying since // destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function // may be called more than once by a relayer, in which case, latest counterparty address is always used. - rpc RegisterCounterPartyAddress(MsgRegisterCounterpartyAddress) returns (MsgRegisterCounterPartyAddressResponse); + rpc RegisterCounterpartyAddress(MsgRegisterCounterpartyAddress) returns (MsgRegisterCounterpartyAddressResponse); // EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee // EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to // incentivize the relaying of the given packet. @@ -30,8 +30,8 @@ message MsgRegisterCounterpartyAddress { string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; } -// MsgRegisterCounterPartyAddressResponse defines the Msg/RegisterCounteryPartyAddress response type -message MsgRegisterCounterPartyAddressResponse {} +// MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type +message MsgRegisterCounterpartyAddressResponse {} // MsgEscrowPacketFee defines the request type EscrowPacketFee RPC message MsgEscrowPacketFee { From 1f6271b81ec765d5b8815c35c7e127602ba3eb91 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 3 Sep 2021 19:11:46 +0200 Subject: [PATCH 02/15] test: adding test for ValidateBasic --- modules/apps/29-fee/keeper/keeper_test.go | 14 -------- modules/apps/29-fee/keeper/msg_server.go | 2 +- modules/apps/29-fee/types/msgs.go | 4 +-- modules/apps/29-fee/types/msgs_test.go | 40 ++++++++++++----------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index b355ccfe847..f227c98171c 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -1,15 +1,10 @@ package keeper_test -/* import ( "testing" "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/modules/apps/transfer/types" ibctesting "github.com/cosmos/ibc-go/testing" ) @@ -31,15 +26,6 @@ func (suite *KeeperTestSuite) SetupTest() { suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2)) } -func NewFeePath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { - path := ibctesting.NewPath(chainA, chainB) - path.EndpointA.ChannelConfig.PortID = ibctesting.FeePort - path.EndpointB.ChannelConfig.PortID = ibctesting.FeePort - - return path -} - func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } -*/ diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index d10f424330c..eec106f87e6 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -26,7 +26,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms k.Logger(ctx).Info("Registering counterparty address for relayer with:", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress) - return &types.MsgRegisterCounterPartyAddressResponse{}, nil + return &types.MsgRegisterCounterpartyAddressResponse{}, nil } // EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index fbfc6f89a30..2669dc8d3fd 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -11,8 +11,8 @@ const ( ) // NewMsgRegisterCounterPartyAddress -func NewMsgRegisterCounterPartyAddress(sourceAddress, counterPartyAddress string) *MsgRegisterCounterpartyAddress { - return &MsgRegisterCounterpartyAddress{Address: sourceAddress, CounterpartyAddress: counterPartyAddress} +func NewMsgRegisterCounterpartyAddress(sourceAddress, counterpartyAddress string) *MsgRegisterCounterpartyAddress { + return &MsgRegisterCounterpartyAddress{Address: sourceAddress, CounterpartyAddress: counterpartyAddress} } // ValidateBasic performs a basic check of the Msg fields diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 132bde75752..893b6624fc4 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -1,36 +1,38 @@ package types -/* import ( - "fmt" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/secp256k1" +) - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" +var ( + validAadr1 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + validAadr2 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + invalidAadr1 = "invalid_address" + invalidAadr2 = "invalid_address" ) -func (suite *TypesTestSuite) TestMsgValidateBasic() { +// TestMsgTransferValidation tests ValidateBasic for MsgTransfer +func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { testCases := []struct { name string - msg *types.Msg + msg *MsgRegisterCounterpartyAddress expPass bool }{ - {"", types.NewMsg(), true}, + {"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAadr1, validAadr2), true}, + {"validate with incorrect source relayer address", NewMsgRegisterCounterpartyAddress(invalidAadr1, validAadr2), false}, + {"validate with incorrect counterparty source relayer address", NewMsgRegisterCounterpartyAddress(validAadr1, invalidAadr2), false}, } - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - err := tc.msg.ValidateBasic() - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - }) + for i, tc := range testCases { + err := tc.msg.ValidateBasic() + if tc.expPass { + require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) + } else { + require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) + } } } -*/ From 325ff94a1ac60416610e6315d9f042200eba52ef Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 6 Sep 2021 15:09:00 +0200 Subject: [PATCH 03/15] fix: removing validate basic check --- modules/apps/29-fee/keeper/msg_server.go | 4 ---- modules/apps/29-fee/keeper/msg_server_test.go | 0 2 files changed, 4 deletions(-) create mode 100644 modules/apps/29-fee/keeper/msg_server_test.go diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index eec106f87e6..58f7e22144e 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -16,10 +16,6 @@ var _ types.MsgServer = Keeper{} func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if err := msg.ValidateBasic(); err != nil { - return &types.MsgRegisterCounterpartyAddressResponse{}, nil - } - k.SetCounterpartyAddress( ctx, msg.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 new file mode 100644 index 00000000000..e69de29bb2d From 019baeba191c0f73c92669ddbe7a436b1ab399c3 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 6 Sep 2021 15:17:23 +0200 Subject: [PATCH 04/15] fix: removing empty file --- modules/apps/29-fee/keeper/msg_server_test.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 modules/apps/29-fee/keeper/msg_server_test.go diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go deleted file mode 100644 index e69de29bb2d..00000000000 From b658d02854e8753de3d432d91c0bc4b267956a80 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 6 Sep 2021 16:57:16 +0200 Subject: [PATCH 05/15] Update modules/apps/29-fee/keeper/msg_server.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/29-fee/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 58f7e22144e..46f7757a43b 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -20,7 +20,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms ctx, msg.Address, msg.CounterpartyAddress, ) - k.Logger(ctx).Info("Registering counterparty address for relayer with:", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress) + k.Logger(ctx).Info("Registering counterparty address for relayer with", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress) return &types.MsgRegisterCounterpartyAddressResponse{}, nil } From 353fb979abf04fd631adbd706ae5727b231524c1 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 6 Sep 2021 16:59:48 +0200 Subject: [PATCH 06/15] Update modules/apps/29-fee/types/msgs.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/29-fee/types/msgs.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 2669dc8d3fd..023d13446b6 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -12,7 +12,10 @@ const ( // NewMsgRegisterCounterPartyAddress func NewMsgRegisterCounterpartyAddress(sourceAddress, counterpartyAddress string) *MsgRegisterCounterpartyAddress { - return &MsgRegisterCounterpartyAddress{Address: sourceAddress, CounterpartyAddress: counterpartyAddress} + return &MsgRegisterCounterpartyAddress{ + Address: sourceAddress, + CounterpartyAddress: counterpartyAddress, + } } // ValidateBasic performs a basic check of the Msg fields From 9bfd2993f5830c4486a40547bf44c8e784dbb276 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 6 Sep 2021 16:59:57 +0200 Subject: [PATCH 07/15] Update modules/apps/29-fee/types/keys.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/29-fee/types/keys.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 0be960b9cfd..f3dabe52d80 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -1,6 +1,6 @@ package types -import fmt "fmt" +import "fmt" const ( // ModuleName defines the 29-fee name From 89affa4f9f5d173a28209d84a9a761041a4e90ea Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 6 Sep 2021 17:15:34 +0200 Subject: [PATCH 08/15] Update modules/apps/29-fee/keeper/keeper.go Co-authored-by: Aditya --- modules/apps/29-fee/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 9b7eecc6d31..d42b64cb36d 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -79,7 +79,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability */ // SetCounterPartyAddress maps the counterparty relayer address to the source relayer address -func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, SourceAddress, CounterpartyAddress string) { +func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, CounterpartyAddress string) { store := ctx.KVStore(k.storeKey) store.Set(types.KeySourceAddress(SourceAddress), []byte(CounterpartyAddress)) } From 9e8a8d859edaf7dbd8e320c6fa535031d3cfc2d8 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 7 Sep 2021 12:42:18 +0200 Subject: [PATCH 09/15] fix: fixing typos, variable names, comments --- modules/apps/29-fee/keeper/keeper.go | 14 +++++++------- modules/apps/29-fee/types/keys.go | 7 +++++-- modules/apps/29-fee/types/msgs.go | 14 +++++++------- modules/apps/29-fee/types/msgs_test.go | 12 +++++------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index d42b64cb36d..effd18d5743 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -78,19 +78,19 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability } */ -// SetCounterPartyAddress maps the counterparty relayer address to the source relayer address -func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, CounterpartyAddress string) { +// 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) { store := ctx.KVStore(k.storeKey) - store.Set(types.KeySourceAddress(SourceAddress), []byte(CounterpartyAddress)) + store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress)) } -// GetCounterPartyAddress gets the relayer counterparty address given a source address -func (k Keeper) GetCounterPartyAddress(ctx sdk.Context, sourceAddress sdk.AccAddress) (sdk.AccAddress, bool) { +// GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address +func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeySourceAddress(sourceAddress.String()) + key := types.KeyRelayerAddress(address.String()) if !store.Has(key) { - // TODO: add logging here return []byte{}, false } diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index f3dabe52d80..3dc2a9658c0 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -17,9 +17,12 @@ const ( // QuerierRoute is the querier route for IBC transfer QuerierRoute = ModuleName + + // Key prefix for relayer address mapping + RelayerAddressKeyPrefix = "relayerAddress" ) // Key for relayer source address -> counteryparty address mapping -func KeySourceAddress(sourceAddress string) []byte { - return []byte(fmt.Sprintf("relayerSourceAddress/%s", sourceAddress)) +func KeyRelayerAddress(address string) []byte { + return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) } diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 023d13446b6..fdc9b5f4f55 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -7,27 +7,27 @@ import ( // msg types const ( - TypeMsgRegisterCounterPartyAddress = "registerCounterPartyAddress" + TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress" ) -// NewMsgRegisterCounterPartyAddress +// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress func NewMsgRegisterCounterpartyAddress(sourceAddress, counterpartyAddress string) *MsgRegisterCounterpartyAddress { return &MsgRegisterCounterpartyAddress{ - Address: sourceAddress, - CounterpartyAddress: counterpartyAddress, + Address: sourceAddress, + CounterpartyAddress: counterpartyAddress, } } -// ValidateBasic performs a basic check of the Msg fields +// ValidateBasic performs a basic check of the MsgRegisterCounterpartyAddress fields func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - return sdkerrors.Wrap(err, "Incorrect source relayer address") + return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") } _, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress) if err != nil { - return sdkerrors.Wrap(err, "Incorrect counterparty relayer address") + return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") } return nil diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 893b6624fc4..d29073f75a7 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -9,10 +9,8 @@ import ( ) var ( - validAadr1 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - validAadr2 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - invalidAadr1 = "invalid_address" - invalidAadr2 = "invalid_address" + validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + invalidAddr = "invalid_address" ) // TestMsgTransferValidation tests ValidateBasic for MsgTransfer @@ -22,9 +20,9 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { msg *MsgRegisterCounterpartyAddress expPass bool }{ - {"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAadr1, validAadr2), true}, - {"validate with incorrect source relayer address", NewMsgRegisterCounterpartyAddress(invalidAadr1, validAadr2), false}, - {"validate with incorrect counterparty source relayer address", NewMsgRegisterCounterpartyAddress(validAadr1, invalidAadr2), false}, + {"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true}, + {"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false}, + {"validate with incorrect counterparty relayer address", NewMsgRegisterCounterpartyAddress(validAddr, invalidAddr), false}, } for i, tc := range testCases { From c1bf0a54e29a44bbda6f857ca70896dcdab8d64a Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 7 Sep 2021 12:49:34 +0200 Subject: [PATCH 10/15] fix: updating import comments --- modules/apps/29-fee/client/cli/cli.go | 4 ++-- modules/apps/29-fee/keeper/keeper.go | 6 ++++-- modules/apps/29-fee/keeper/keeper_test.go | 3 +++ modules/apps/29-fee/types/expected_keepers.go | 3 +++ modules/apps/29-fee/types/keys.go | 1 + modules/apps/29-fee/types/msgs.go | 1 + 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/apps/29-fee/client/cli/cli.go b/modules/apps/29-fee/client/cli/cli.go index fb8b9db8320..c7be975a534 100644 --- a/modules/apps/29-fee/client/cli/cli.go +++ b/modules/apps/29-fee/client/cli/cli.go @@ -1,9 +1,9 @@ package cli import ( - "github.com/spf13/cobra" - + // external library imports "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" ) // GetQueryCmd returns the query commands for 29-fee diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index effd18d5743..a8319944613 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -1,12 +1,14 @@ package keeper import ( - "github.com/tendermint/tendermint/libs/log" - + // external library imports "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/tendermint/tendermint/libs/log" + + // ibc-go imports "github.com/cosmos/ibc-go/modules/apps/29-fee/types" host "github.com/cosmos/ibc-go/modules/core/24-host" ) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index f227c98171c..11c1768a1cf 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -1,10 +1,13 @@ package keeper_test import ( + // standard library importsn "testing" + // external library imports "github.com/stretchr/testify/suite" + // ibc-go imports ibctesting "github.com/cosmos/ibc-go/testing" ) diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index df16f947c4b..a17a443623d 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -1,9 +1,12 @@ package types import ( + //external library imports sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + + // ibc-go imports connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/modules/core/exported" diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 3dc2a9658c0..4066ebb24aa 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -1,5 +1,6 @@ package types +// standard library imports import "fmt" const ( diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index fdc9b5f4f55..7a119403e78 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + // external library imports sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) From 0b63aaf7da791f2bfad1c968b0b83a2bf3eadf24 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 7 Sep 2021 13:03:55 +0200 Subject: [PATCH 11/15] test: adding test for KeyRelayerAddress --- modules/apps/29-fee/types/keys_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 modules/apps/29-fee/types/keys_test.go diff --git a/modules/apps/29-fee/types/keys_test.go b/modules/apps/29-fee/types/keys_test.go new file mode 100644 index 00000000000..a8ed8524035 --- /dev/null +++ b/modules/apps/29-fee/types/keys_test.go @@ -0,0 +1,18 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" +) + +func TestKeyRelayerAddress(t *testing.T) { + var ( + relayerAddress = "relayer_address" + ) + + key := types.KeyRelayerAddress(relayerAddress) + require.Equal(t, string(key), "relayerAddress/relayer_address") +} From acae9d6cc5f2c8dfc09f58d23d9b3f42bbcc9b8b Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 8 Sep 2021 12:53:31 +0200 Subject: [PATCH 12/15] update: comments & key_test --- modules/apps/29-fee/types/keys.go | 4 ++-- modules/apps/29-fee/types/keys_test.go | 3 ++- modules/apps/29-fee/types/msgs.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 4066ebb24aa..5d1057dccca 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -19,11 +19,11 @@ const ( // QuerierRoute is the querier route for IBC transfer QuerierRoute = ModuleName - // Key prefix for relayer address mapping + // RelayerAddressKeyPrefix is the key prefix for relayer address mapping RelayerAddressKeyPrefix = "relayerAddress" ) -// Key for relayer source address -> counteryparty address mapping +// KeyRelayerAddress returns the key for relayer address -> counteryparty address mapping func KeyRelayerAddress(address string) []byte { return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) } diff --git a/modules/apps/29-fee/types/keys_test.go b/modules/apps/29-fee/types/keys_test.go index a8ed8524035..312188c5e21 100644 --- a/modules/apps/29-fee/types/keys_test.go +++ b/modules/apps/29-fee/types/keys_test.go @@ -1,6 +1,7 @@ package types_test import ( + fmt "fmt" "testing" "github.com/stretchr/testify/require" @@ -14,5 +15,5 @@ func TestKeyRelayerAddress(t *testing.T) { ) key := types.KeyRelayerAddress(relayerAddress) - require.Equal(t, string(key), "relayerAddress/relayer_address") + require.Equal(t, string(key), fmt.Sprintf("%s/relayer_address", types.RelayerAddressKeyPrefix)) } diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 7a119403e78..3ac3c841329 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -12,9 +12,9 @@ const ( ) // NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress -func NewMsgRegisterCounterpartyAddress(sourceAddress, counterpartyAddress string) *MsgRegisterCounterpartyAddress { +func NewMsgRegisterCounterpartyAddress(address, counterpartyAddress string) *MsgRegisterCounterpartyAddress { return &MsgRegisterCounterpartyAddress{ - Address: sourceAddress, + Address: address, CounterpartyAddress: counterpartyAddress, } } From 7552b7905e92c05aab5b6252295dcbce289251b0 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 8 Sep 2021 12:54:35 +0200 Subject: [PATCH 13/15] Update modules/apps/29-fee/keeper/msg_server.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/29-fee/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 46f7757a43b..e889e435449 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -20,7 +20,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms ctx, msg.Address, msg.CounterpartyAddress, ) - k.Logger(ctx).Info("Registering counterparty address for relayer with", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress) + k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress) return &types.MsgRegisterCounterpartyAddressResponse{}, nil } From 4e22511e550082cabbf8776186316d112536d832 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 8 Sep 2021 12:54:56 +0200 Subject: [PATCH 14/15] fix: error message --- modules/apps/29-fee/types/msgs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 3ac3c841329..6d1a92ef945 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -28,7 +28,7 @@ func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { _, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress) if err != nil { - return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") + return sdkerrors.Wrap(err, "failed to convert msg.CounterpartyAddress into sdk.AccAddress") } return nil From 0603eee146ecdf9c01a69818ff0d2d8187e07e11 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 8 Sep 2021 12:57:25 +0200 Subject: [PATCH 15/15] docs: updating RegisterCounterpartyAddress fn description --- modules/apps/29-fee/keeper/msg_server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index e889e435449..54b0dadbc37 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -11,8 +11,8 @@ import ( var _ types.MsgServer = Keeper{} // RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying -// This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement -// This function may be called more than once by relayer, in which case, latest counterparty address is always used. +// This ensures they will be properly compensated for forward relaying on the source chain since the destination chain must send back relayer's source address (counterparty address) in acknowledgement +// This function may be called more than once by relayers, in which case, the previous counterparty address will be overwritten by the new counterparty address func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx)