From 435efc7b1d68eb380b1b2e2eb83e917850ec0b00 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 1 Oct 2021 16:14:48 +0200 Subject: [PATCH 01/50] fix: adding second endpoint for async pay fee + renaming types --- docs/ibc/proto-docs.md | 62 +- modules/apps/29-fee/keeper/msg_server.go | 19 +- modules/apps/29-fee/types/fee.pb.go | 393 +++++------ modules/apps/29-fee/types/genesis.pb.go | 94 +-- modules/apps/29-fee/types/tx.pb.go | 741 +++++++++++++++++--- proto/ibc/applications/fee/v1/fee.proto | 12 +- proto/ibc/applications/fee/v1/genesis.proto | 4 +- proto/ibc/applications/fee/v1/tx.proto | 36 +- 8 files changed, 914 insertions(+), 447 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index ff79278b80a..2a07e51efd0 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -47,8 +47,10 @@ - [Query](#ibc.applications.fee.v1.Query) - [ibc/applications/fee/v1/tx.proto](#ibc/applications/fee/v1/tx.proto) - - [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee) - - [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse) + - [MsgPayPacketFee](#ibc.applications.fee.v1.MsgPayPacketFee) + - [MsgPayPacketFeeAsync](#ibc.applications.fee.v1.MsgPayPacketFeeAsync) + - [MsgPayPacketFeeAsyncResponse](#ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse) + - [MsgPayPacketFeeResponse](#ibc.applications.fee.v1.MsgPayPacketFeeResponse) - [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) - [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) @@ -628,7 +630,9 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middl | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `receive_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `ack_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `timeout_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | @@ -644,10 +648,7 @@ Fee associated with a packet_id | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | -| `receive_fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | -| `ack_fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | -| `timeout_fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | -| `relayers` | [string](#string) | repeated | | +| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | @@ -676,11 +677,6 @@ Fee associated with a packet_id GenesisState defines the fee middleware genesis state -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `packets_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | A mapping of packets -> escrowed fees | - - @@ -889,15 +885,34 @@ Query provides defines the gRPC querier service. - + -### MsgEscrowPacketFee +### MsgPayPacketFee MsgEscrowPacketFee defines the request type EscrowPacketFee RPC | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `incentivized_packet` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | | +| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | +| `source_port_id` | [string](#string) | | source channel port identifier | +| `source_channel_id` | [string](#string) | | source channel unique identifier | +| `relayers` | [string](#string) | repeated | | + + + + + + + + +### MsgPayPacketFeeAsync +MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | +| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | | `relayers` | [string](#string) | repeated | | @@ -905,9 +920,19 @@ MsgEscrowPacketFee defines the request type EscrowPacketFee RPC - + + +### MsgPayPacketFeeAsyncResponse +MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync + + + + + + + -### MsgEscrowPacketFeeResponse +### MsgPayPacketFeeResponse MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee @@ -955,7 +980,8 @@ 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. | | -| `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. | | +| `PayPacketFee` | [MsgPayPacketFee](#ibc.applications.fee.v1.MsgPayPacketFee) | [MsgPayPacketFeeResponse](#ibc.applications.fee.v1.MsgPayPacketFeeResponse) | PayPacketFee defines a rpc handler method for MsgPayPacketFee PayPacketFee 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. | | +| `PayPacketFeeAsync` | [MsgPayPacketFeeAsync](#ibc.applications.fee.v1.MsgPayPacketFeeAsync) | [MsgPayPacketFeeAsyncResponse](#ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse) | PayPacketFee defines a rpc handler method for MsgPayPacketFee PayPacketFee 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/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 54b0dadbc37..ac44212f373 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -28,6 +28,21 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms // 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 +func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) (*types.MsgPayPacketFeeResponse, error) { + // get the next sequence + /* + sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) + if !found { + return []byte{}, channeltypes.ErrSequenceSendNotFound + } + */ + + return &types.MsgPayPacketFeeResponse{}, nil +} + +// PayPacketFee defines a rpc handler method for MsgEscrowPacketFee +// PayPacketFee 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) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacketFeeAsync) (*types.MsgPayPacketFeeAsyncResponse, error) { + return &types.MsgPayPacketFeeAsyncResponse{}, nil } diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index d6597e1c0f8..0e5bbcad62d 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -5,7 +5,6 @@ package types import ( fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" types1 "github.com/cosmos/ibc-go/modules/core/04-channel/types" _ "github.com/gogo/protobuf/gogoproto" @@ -30,7 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // See Fee Payment Middleware spec: // https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract type Fee struct { - Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` + ReceiveFee []*types.Coin `protobuf:"bytes,1,rep,name=receive_fee,json=receiveFee,proto3" json:"receive_fee,omitempty" yaml:"receive_fee"` + AckFee []*types.Coin `protobuf:"bytes,2,rep,name=ack_fee,json=ackFee,proto3" json:"ack_fee,omitempty" yaml:"ack_fee"` + TimeoutFee []*types.Coin `protobuf:"bytes,3,rep,name=timeout_fee,json=timeoutFee,proto3" json:"timeout_fee,omitempty" yaml:"timeout_fee"` } func (m *Fee) Reset() { *m = Fee{} } @@ -66,20 +67,31 @@ func (m *Fee) XXX_DiscardUnknown() { var xxx_messageInfo_Fee proto.InternalMessageInfo -func (m *Fee) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { +func (m *Fee) GetReceiveFee() []*types.Coin { if m != nil { - return m.Amount + return m.ReceiveFee + } + return nil +} + +func (m *Fee) GetAckFee() []*types.Coin { + if m != nil { + return m.AckFee + } + return nil +} + +func (m *Fee) GetTimeoutFee() []*types.Coin { + if m != nil { + return m.TimeoutFee } return nil } // Fee associated with a packet_id type IdentifiedPacketFee struct { - PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` - ReceiveFee *Fee `protobuf:"bytes,2,opt,name=receive_fee,json=receiveFee,proto3" json:"receive_fee,omitempty" yaml:"receive_fee"` - AckFee *Fee `protobuf:"bytes,3,opt,name=ack_fee,json=ackFee,proto3" json:"ack_fee,omitempty" yaml:"ack_fee"` - TimeoutFee *Fee `protobuf:"bytes,4,opt,name=timeout_fee,json=timeoutFee,proto3" json:"timeout_fee,omitempty" yaml:"timeout_fee"` - Relayers []string `protobuf:"bytes,5,rep,name=relayers,proto3" json:"relayers,omitempty"` + PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` + Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` } func (m *IdentifiedPacketFee) Reset() { *m = IdentifiedPacketFee{} } @@ -122,30 +134,9 @@ func (m *IdentifiedPacketFee) GetPacketId() *types1.PacketId { return nil } -func (m *IdentifiedPacketFee) GetReceiveFee() *Fee { - if m != nil { - return m.ReceiveFee - } - return nil -} - -func (m *IdentifiedPacketFee) GetAckFee() *Fee { +func (m *IdentifiedPacketFee) GetFee() *Fee { if m != nil { - return m.AckFee - } - return nil -} - -func (m *IdentifiedPacketFee) GetTimeoutFee() *Fee { - if m != nil { - return m.TimeoutFee - } - return nil -} - -func (m *IdentifiedPacketFee) GetRelayers() []string { - if m != nil { - return m.Relayers + return m.Fee } return nil } @@ -158,35 +149,32 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 443 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x3f, 0x8f, 0xd3, 0x30, - 0x18, 0xc6, 0x9b, 0x2b, 0x94, 0x3b, 0x57, 0x42, 0x28, 0x9c, 0xa0, 0x54, 0x90, 0x94, 0x4c, 0x5d, - 0x6a, 0xd3, 0x32, 0xc1, 0x18, 0xa4, 0x93, 0x2a, 0x31, 0x9c, 0x22, 0xdd, 0xc2, 0x72, 0x72, 0x9c, - 0xb7, 0x39, 0x93, 0x3f, 0x8e, 0x62, 0x27, 0x52, 0xbf, 0x05, 0x9f, 0x83, 0x4f, 0x72, 0xe3, 0x8d, - 0x4c, 0x01, 0xb5, 0xdf, 0xa0, 0x33, 0x03, 0xb2, 0x63, 0x4e, 0x95, 0x10, 0x12, 0x4c, 0x7e, 0x5f, - 0xdb, 0xcf, 0xef, 0x79, 0x64, 0xbf, 0xe8, 0x35, 0x8f, 0x19, 0xa1, 0x55, 0x95, 0x73, 0x46, 0x15, - 0x17, 0xa5, 0x24, 0x1b, 0x00, 0xd2, 0x2e, 0xf5, 0x82, 0xab, 0x5a, 0x28, 0xe1, 0x3e, 0xe7, 0x31, - 0xc3, 0xc7, 0x57, 0xb0, 0x3e, 0x6b, 0x97, 0x53, 0x8f, 0x09, 0x59, 0x08, 0x49, 0x62, 0x2a, 0xb5, - 0x24, 0x06, 0x45, 0x97, 0x84, 0x09, 0x5e, 0xf6, 0xc2, 0xe9, 0x79, 0x2a, 0x52, 0x61, 0x4a, 0xa2, - 0x2b, 0xbb, 0x6b, 0x1c, 0x99, 0xa8, 0x81, 0xb0, 0x1b, 0x5a, 0x96, 0x90, 0x6b, 0x37, 0x5b, 0xf6, - 0x57, 0x82, 0xcf, 0x68, 0x78, 0x01, 0xe0, 0x32, 0x34, 0xa2, 0x85, 0x68, 0x4a, 0x35, 0x71, 0x66, - 0xc3, 0xf9, 0x78, 0xf5, 0x02, 0xf7, 0x86, 0x58, 0x1b, 0x62, 0x6b, 0x88, 0x3f, 0x08, 0x5e, 0x86, - 0x6f, 0x6e, 0x3b, 0x7f, 0xf0, 0xf5, 0xbb, 0x3f, 0x4f, 0xb9, 0xba, 0x69, 0x62, 0xcc, 0x44, 0x41, - 0x6c, 0xba, 0x7e, 0x59, 0xc8, 0x24, 0x23, 0x6a, 0x5b, 0x81, 0x34, 0x02, 0x19, 0x59, 0x74, 0xf0, - 0xf3, 0x04, 0x3d, 0x5d, 0x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 0x24, 0x4d, 0x0e, 0x52, 0x8f, 0xad, - 0x24, 0xab, 0x77, 0x0b, 0x3d, 0xb1, 0xe6, 0x6b, 0xe3, 0x91, 0x99, 0x9f, 0xb7, 0xbf, 0x02, 0x00, - 0x00, 0xff, 0xff, 0x94, 0x57, 0xcf, 0x1b, 0xd6, 0x02, 0x00, 0x00, + // 396 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x31, 0x6b, 0xe3, 0x30, + 0x14, 0xc7, 0xa3, 0x33, 0xe4, 0xee, 0x14, 0x38, 0x0e, 0x5f, 0xb8, 0xcb, 0x85, 0x3b, 0x27, 0xe7, + 0x29, 0x4b, 0x24, 0xec, 0x9b, 0xda, 0x31, 0x05, 0x43, 0xa0, 0x43, 0xf0, 0xd8, 0x25, 0xc8, 0xf2, + 0x8b, 0x23, 0x62, 0x5b, 0x26, 0x56, 0x0c, 0xf9, 0x16, 0xdd, 0xfa, 0x95, 0x3a, 0x66, 0xec, 0x14, + 0x4a, 0xf2, 0x0d, 0x02, 0xdd, 0x8b, 0x6c, 0xb5, 0x64, 0x29, 0xa5, 0x93, 0xde, 0x93, 0xde, 0xef, + 0xff, 0x17, 0xef, 0x3d, 0xfc, 0x4f, 0x44, 0x9c, 0xb2, 0xa2, 0x48, 0x05, 0x67, 0x4a, 0xc8, 0xbc, + 0xa4, 0x0b, 0x00, 0x5a, 0x79, 0xfa, 0x20, 0xc5, 0x5a, 0x2a, 0x69, 0xff, 0x12, 0x11, 0x27, 0xe7, + 0x25, 0x44, 0xbf, 0x55, 0x5e, 0xdf, 0xe1, 0xb2, 0xcc, 0x64, 0x49, 0x23, 0x56, 0x6a, 0x24, 0x02, + 0xc5, 0x3c, 0xca, 0xa5, 0xc8, 0x1b, 0xb0, 0xdf, 0x4d, 0x64, 0x22, 0xeb, 0x90, 0xea, 0xc8, 0xdc, + 0xd6, 0x8e, 0x5c, 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xa0, 0xc7, 0x83, 0x83, 0x6e, 0x8f, + 0x4e, 0x6b, 0x77, 0x74, 0x5a, 0x0f, 0x47, 0xa7, 0x75, 0xe3, 0x27, 0x42, 0x2d, 0x37, 0x11, 0xe1, + 0x32, 0xa3, 0x66, 0x1f, 0x44, 0xc4, 0xc7, 0x89, 0xa4, 0x99, 0x8c, 0x37, 0x29, 0x94, 0x7a, 0xbb, + 0x4a, 0xea, 0x5f, 0x8c, 0xf5, 0x62, 0xa9, 0x6d, 0x01, 0x65, 0xd4, 0xae, 0xc7, 0xfc, 0xff, 0x39, + 0x00, 0x00, 0xff, 0xff, 0x15, 0xa1, 0x8a, 0x94, 0x7d, 0x02, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -209,10 +197,38 @@ func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Amount) > 0 { - for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + if len(m.TimeoutFee) > 0 { + for iNdEx := len(m.TimeoutFee) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.TimeoutFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.AckFee) > 0 { + for iNdEx := len(m.AckFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AckFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.ReceiveFee) > 0 { + for iNdEx := len(m.ReceiveFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ReceiveFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -246,42 +262,9 @@ func (m *IdentifiedPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Relayers) > 0 { - for iNdEx := len(m.Relayers) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Relayers[iNdEx]) - copy(dAtA[i:], m.Relayers[iNdEx]) - i = encodeVarintFee(dAtA, i, uint64(len(m.Relayers[iNdEx]))) - i-- - dAtA[i] = 0x2a - } - } - if m.TimeoutFee != nil { - { - size, err := m.TimeoutFee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - if m.AckFee != nil { + if m.Fee != nil { { - size, err := m.AckFee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if m.ReceiveFee != nil { - { - size, err := m.ReceiveFee.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -323,8 +306,20 @@ func (m *Fee) Size() (n int) { } var l int _ = l - if len(m.Amount) > 0 { - for _, e := range m.Amount { + if len(m.ReceiveFee) > 0 { + for _, e := range m.ReceiveFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } + } + if len(m.AckFee) > 0 { + for _, e := range m.AckFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } + } + if len(m.TimeoutFee) > 0 { + for _, e := range m.TimeoutFee { l = e.Size() n += 1 + l + sovFee(uint64(l)) } @@ -342,24 +337,10 @@ func (m *IdentifiedPacketFee) Size() (n int) { l = m.PacketId.Size() n += 1 + l + sovFee(uint64(l)) } - if m.ReceiveFee != nil { - l = m.ReceiveFee.Size() - n += 1 + l + sovFee(uint64(l)) - } - if m.AckFee != nil { - l = m.AckFee.Size() + if m.Fee != nil { + l = m.Fee.Size() n += 1 + l + sovFee(uint64(l)) } - if m.TimeoutFee != nil { - l = m.TimeoutFee.Size() - n += 1 + l + sovFee(uint64(l)) - } - if len(m.Relayers) > 0 { - for _, s := range m.Relayers { - l = len(s) - n += 1 + l + sovFee(uint64(l)) - } - } return n } @@ -400,7 +381,7 @@ func (m *Fee) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ReceiveFee", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -427,64 +408,14 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Amount = append(m.Amount, types.Coin{}) - if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ReceiveFee = append(m.ReceiveFee, &types.Coin{}) + if err := m.ReceiveFee[len(m.ReceiveFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFee(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFee - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFee - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: IdentifiedPacketFee: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: IdentifiedPacketFee: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PacketId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AckFee", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -511,16 +442,14 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.PacketId == nil { - m.PacketId = &types1.PacketId{} - } - if err := m.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.AckFee = append(m.AckFee, &types.Coin{}) + if err := m.AckFee[len(m.AckFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 2: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ReceiveFee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutFee", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -547,52 +476,64 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.ReceiveFee == nil { - m.ReceiveFee = &Fee{} - } - if err := m.ReceiveFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.TimeoutFee = append(m.TimeoutFee, &types.Coin{}) + if err := m.TimeoutFee[len(m.TimeoutFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AckFee", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFee - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthFee + default: + iNdEx = preIndex + skippy, err := skipFee(dAtA[iNdEx:]) + if err != nil { + return err } - postIndex := iNdEx + msglen - if postIndex < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthFee } - if postIndex > l { + if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - if m.AckFee == nil { - m.AckFee = &Fee{} + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee } - if err := m.AckFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + if iNdEx >= l { + return io.ErrUnexpectedEOF } - iNdEx = postIndex - case 4: + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IdentifiedPacketFee: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IdentifiedPacketFee: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TimeoutFee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PacketId", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -619,18 +560,18 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.TimeoutFee == nil { - m.TimeoutFee = &Fee{} + if m.PacketId == nil { + m.PacketId = &types1.PacketId{} } - if err := m.TimeoutFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 5: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Relayers", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowFee @@ -640,23 +581,27 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthFee } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthFee } if postIndex > l { return io.ErrUnexpectedEOF } - m.Relayers = append(m.Relayers, string(dAtA[iNdEx:postIndex])) + if m.Fee == nil { + m.Fee = &Fee{} + } + if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index e108131adfc..b07a497011f 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -25,8 +25,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fee middleware genesis state type GenesisState struct { - // A mapping of packets -> escrowed fees - PacketsFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=packets_fees,json=packetsFees,proto3" json:"packets_fees,omitempty" yaml:"packets_fees"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -62,13 +60,6 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetPacketsFees() []*IdentifiedPacketFee { - if m != nil { - return m.PacketsFees - } - return nil -} - func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.fee.v1.GenesisState") } @@ -78,24 +69,19 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 260 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00,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, 0xdf, 0x19, 0x00, 0x4f, 0x1f, 0xbe, - 0x6a, 0x11, 0xae, 0x6b, 0x11, 0xfe, 0xd6, 0x22, 0xfc, 0x6c, 0x44, 0xb0, 0x6e, 0x44, 0xf0, 0xdd, - 0x88, 0xe0, 0x25, 0xb1, 0xe8, 0xe7, 0x0b, 0x2d, 0x0d, 0x95, 0xca, 0x10, 0x97, 0xc4, 0x0a, 0xb5, - 0x19, 0x5b, 0x52, 0x25, 0x65, 0x8b, 0x02, 0xb8, 0x75, 0x62, 0x95, 0xdc, 0x8c, 0x5b, 0x1d, 0xbf, - 0x72, 0xc0, 0xfa, 0xb0, 0xd3, 0xb9, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x42, 0xac, 0xef, 0xaa, - 0x49, 0x01, 0x00, 0x00, + // 192 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, + 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x4f, 0x4b, 0x4d, + 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x12, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xa6, 0x97, 0x96, 0x9a, 0xaa, 0x57, 0x66, + 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0x29, 0xe2, + 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0x89, 0x8f, 0x8b, 0xc7, 0x1d, 0x62, 0x45, 0x70, 0x49, 0x62, + 0x49, 0xaa, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, + 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, + 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, + 0xeb, 0x67, 0x26, 0x25, 0xeb, 0xa6, 0xe7, 0xeb, 0xe7, 0xe6, 0xa7, 0x94, 0xe6, 0xa4, 0x16, 0x83, + 0x6c, 0x2a, 0xd6, 0x37, 0xb2, 0xd4, 0x05, 0x59, 0x52, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, + 0xb6, 0xc4, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x90, 0xf8, 0xaf, 0x33, 0xdf, 0x00, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -118,20 +104,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.PacketsFees) > 0 { - for iNdEx := len(m.PacketsFees) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.PacketsFees[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } return len(dAtA) - i, nil } @@ -152,12 +124,6 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - if len(m.PacketsFees) > 0 { - for _, e := range m.PacketsFees { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } return n } @@ -196,40 +162,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PacketsFees", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PacketsFees = append(m.PacketsFees, &IdentifiedPacketFee{}) - if err := m.PacketsFees[len(m.PacketsFees)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index c9fb330d12b..bad5686276d 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -6,7 +6,7 @@ package types import ( context "context" fmt "fmt" - _ "github.com/cosmos/ibc-go/modules/core/04-channel/types" + types "github.com/cosmos/ibc-go/modules/core/04-channel/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -108,23 +108,27 @@ func (m *MsgRegisterCounterpartyAddressResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterCounterpartyAddressResponse proto.InternalMessageInfo // MsgEscrowPacketFee defines the request type EscrowPacketFee RPC -type MsgEscrowPacketFee struct { - IncentivizedPacket *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=incentivized_packet,json=incentivizedPacket,proto3" json:"incentivized_packet,omitempty" yaml:"incentivized_packet"` - Relayers []string `protobuf:"bytes,2,rep,name=relayers,proto3" json:"relayers,omitempty"` +type MsgPayPacketFee struct { + Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + // source channel port identifier + SourcePortId string `protobuf:"bytes,2,opt,name=source_port_id,json=sourcePortId,proto3" json:"source_port_id,omitempty" yaml:"source_port_id"` + // source channel unique identifier + SourceChannelId string `protobuf:"bytes,3,opt,name=source_channel_id,json=sourceChannelId,proto3" json:"source_channel_id,omitempty" yaml:"source_channel_id"` + Relayers []string `protobuf:"bytes,4,rep,name=relayers,proto3" json:"relayers,omitempty"` } -func (m *MsgEscrowPacketFee) Reset() { *m = MsgEscrowPacketFee{} } -func (m *MsgEscrowPacketFee) String() string { return proto.CompactTextString(m) } -func (*MsgEscrowPacketFee) ProtoMessage() {} -func (*MsgEscrowPacketFee) Descriptor() ([]byte, []int) { +func (m *MsgPayPacketFee) Reset() { *m = MsgPayPacketFee{} } +func (m *MsgPayPacketFee) String() string { return proto.CompactTextString(m) } +func (*MsgPayPacketFee) ProtoMessage() {} +func (*MsgPayPacketFee) Descriptor() ([]byte, []int) { return fileDescriptor_05c93128649f1b96, []int{2} } -func (m *MsgEscrowPacketFee) XXX_Unmarshal(b []byte) error { +func (m *MsgPayPacketFee) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgEscrowPacketFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgPayPacketFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgEscrowPacketFee.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgPayPacketFee.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -134,34 +138,34 @@ func (m *MsgEscrowPacketFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *MsgEscrowPacketFee) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgEscrowPacketFee.Merge(m, src) +func (m *MsgPayPacketFee) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPayPacketFee.Merge(m, src) } -func (m *MsgEscrowPacketFee) XXX_Size() int { +func (m *MsgPayPacketFee) XXX_Size() int { return m.Size() } -func (m *MsgEscrowPacketFee) XXX_DiscardUnknown() { - xxx_messageInfo_MsgEscrowPacketFee.DiscardUnknown(m) +func (m *MsgPayPacketFee) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPayPacketFee.DiscardUnknown(m) } -var xxx_messageInfo_MsgEscrowPacketFee proto.InternalMessageInfo +var xxx_messageInfo_MsgPayPacketFee proto.InternalMessageInfo // MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee -type MsgEscrowPacketFeeResponse struct { +type MsgPayPacketFeeResponse struct { } -func (m *MsgEscrowPacketFeeResponse) Reset() { *m = MsgEscrowPacketFeeResponse{} } -func (m *MsgEscrowPacketFeeResponse) String() string { return proto.CompactTextString(m) } -func (*MsgEscrowPacketFeeResponse) ProtoMessage() {} -func (*MsgEscrowPacketFeeResponse) Descriptor() ([]byte, []int) { +func (m *MsgPayPacketFeeResponse) Reset() { *m = MsgPayPacketFeeResponse{} } +func (m *MsgPayPacketFeeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgPayPacketFeeResponse) ProtoMessage() {} +func (*MsgPayPacketFeeResponse) Descriptor() ([]byte, []int) { return fileDescriptor_05c93128649f1b96, []int{3} } -func (m *MsgEscrowPacketFeeResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgPayPacketFeeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgEscrowPacketFeeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgPayPacketFeeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgEscrowPacketFeeResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgPayPacketFeeResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -171,58 +175,144 @@ func (m *MsgEscrowPacketFeeResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *MsgEscrowPacketFeeResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgEscrowPacketFeeResponse.Merge(m, src) +func (m *MsgPayPacketFeeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPayPacketFeeResponse.Merge(m, src) } -func (m *MsgEscrowPacketFeeResponse) XXX_Size() int { +func (m *MsgPayPacketFeeResponse) XXX_Size() int { return m.Size() } -func (m *MsgEscrowPacketFeeResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgEscrowPacketFeeResponse.DiscardUnknown(m) +func (m *MsgPayPacketFeeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPayPacketFeeResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgEscrowPacketFeeResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo + +// MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +type MsgPayPacketFeeAsync struct { + Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + PacketId *types.PacketId `protobuf:"bytes,2,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` + Relayers []string `protobuf:"bytes,3,rep,name=relayers,proto3" json:"relayers,omitempty"` +} + +func (m *MsgPayPacketFeeAsync) Reset() { *m = MsgPayPacketFeeAsync{} } +func (m *MsgPayPacketFeeAsync) String() string { return proto.CompactTextString(m) } +func (*MsgPayPacketFeeAsync) ProtoMessage() {} +func (*MsgPayPacketFeeAsync) Descriptor() ([]byte, []int) { + return fileDescriptor_05c93128649f1b96, []int{4} +} +func (m *MsgPayPacketFeeAsync) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPayPacketFeeAsync) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPayPacketFeeAsync.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgPayPacketFeeAsync) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPayPacketFeeAsync.Merge(m, src) +} +func (m *MsgPayPacketFeeAsync) XXX_Size() int { + return m.Size() +} +func (m *MsgPayPacketFeeAsync) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPayPacketFeeAsync.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPayPacketFeeAsync proto.InternalMessageInfo + +// MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +type MsgPayPacketFeeAsyncResponse struct { +} + +func (m *MsgPayPacketFeeAsyncResponse) Reset() { *m = MsgPayPacketFeeAsyncResponse{} } +func (m *MsgPayPacketFeeAsyncResponse) String() string { return proto.CompactTextString(m) } +func (*MsgPayPacketFeeAsyncResponse) ProtoMessage() {} +func (*MsgPayPacketFeeAsyncResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_05c93128649f1b96, []int{5} +} +func (m *MsgPayPacketFeeAsyncResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPayPacketFeeAsyncResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPayPacketFeeAsyncResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgPayPacketFeeAsyncResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPayPacketFeeAsyncResponse.Merge(m, src) +} +func (m *MsgPayPacketFeeAsyncResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgPayPacketFeeAsyncResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPayPacketFeeAsyncResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPayPacketFeeAsyncResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgRegisterCounterpartyAddress)(nil), "ibc.applications.fee.v1.MsgRegisterCounterpartyAddress") 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") + proto.RegisterType((*MsgPayPacketFee)(nil), "ibc.applications.fee.v1.MsgPayPacketFee") + proto.RegisterType((*MsgPayPacketFeeResponse)(nil), "ibc.applications.fee.v1.MsgPayPacketFeeResponse") + proto.RegisterType((*MsgPayPacketFeeAsync)(nil), "ibc.applications.fee.v1.MsgPayPacketFeeAsync") + proto.RegisterType((*MsgPayPacketFeeAsyncResponse)(nil), "ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse") } func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 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, 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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ytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0x63, 0x8c, 0x20, 0xb9, 0x56, 0x94, 0x9a, 0xa0, 0xa6, 0x6e, 0xb0, 0x83, 0x07, 0x94, + 0x25, 0x36, 0x09, 0x42, 0x88, 0x2e, 0x55, 0x53, 0xa9, 0x22, 0x12, 0x91, 0xa2, 0x1b, 0x59, 0x22, + 0xe7, 0xfc, 0xe2, 0x1a, 0x12, 0x9f, 0x75, 0x77, 0x89, 0xf0, 0x17, 0x40, 0x8c, 0x6c, 0x30, 0xf6, + 0x93, 0x30, 0x33, 0x76, 0x64, 0x8a, 0x50, 0xb2, 0x30, 0xe7, 0x13, 0x20, 0xdb, 0x71, 0x70, 0xda, + 0x26, 0x6a, 0xbb, 0x9d, 0xef, 0xfd, 0xde, 0xff, 0xbd, 0xff, 0xf3, 0xd3, 0xa1, 0x8a, 0xd7, 0x23, + 0x96, 0x1d, 0x04, 0x03, 0x8f, 0xd8, 0xc2, 0xa3, 0x3e, 0xb7, 0xfa, 0x00, 0xd6, 0xb8, 0x6e, 0x89, + 0xcf, 0x66, 0xc0, 0xa8, 0xa0, 0xca, 0x9e, 0xd7, 0x23, 0x66, 0x96, 0x30, 0xfb, 0x00, 0xe6, 0xb8, + 0xae, 0x16, 0x5d, 0xea, 0xd2, 0x98, 0xb1, 0xa2, 0x53, 0x82, 0xab, 0xcf, 0xd7, 0x09, 0x46, 0x59, + 0x19, 0x84, 0x50, 0x06, 0x16, 0x39, 0xb3, 0x7d, 0x1f, 0x06, 0x51, 0x78, 0x71, 0x4c, 0x10, 0xe3, + 0x87, 0x84, 0xb4, 0x36, 0x77, 0x31, 0xb8, 0x1e, 0x17, 0xc0, 0x4e, 0xe8, 0xc8, 0x17, 0xc0, 0x02, + 0x9b, 0x89, 0xf0, 0xd8, 0x71, 0x18, 0x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c, 0x26, 0xbd, 0xfa, 0x17, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x1d, 0xc3, 0xf4, 0x2c, 0x05, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -243,10 +333,14 @@ type MsgClient interface { // 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) - // 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 + // PayPacketFee defines a rpc handler method for MsgPayPacketFee + // PayPacketFee 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. - EscrowPacketFee(ctx context.Context, in *MsgEscrowPacketFee, opts ...grpc.CallOption) (*MsgEscrowPacketFeeResponse, error) + PayPacketFee(ctx context.Context, in *MsgPayPacketFee, opts ...grpc.CallOption) (*MsgPayPacketFeeResponse, error) + // PayPacketFee defines a rpc handler method for MsgPayPacketFee + // PayPacketFee 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. + PayPacketFeeAsync(ctx context.Context, in *MsgPayPacketFeeAsync, opts ...grpc.CallOption) (*MsgPayPacketFeeAsyncResponse, error) } type msgClient struct { @@ -266,9 +360,18 @@ func (c *msgClient) RegisterCounterpartyAddress(ctx context.Context, in *MsgRegi return out, nil } -func (c *msgClient) EscrowPacketFee(ctx context.Context, in *MsgEscrowPacketFee, opts ...grpc.CallOption) (*MsgEscrowPacketFeeResponse, error) { - out := new(MsgEscrowPacketFeeResponse) - err := c.cc.Invoke(ctx, "/ibc.applications.fee.v1.Msg/EscrowPacketFee", in, out, opts...) +func (c *msgClient) PayPacketFee(ctx context.Context, in *MsgPayPacketFee, opts ...grpc.CallOption) (*MsgPayPacketFeeResponse, error) { + out := new(MsgPayPacketFeeResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.fee.v1.Msg/PayPacketFee", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) PayPacketFeeAsync(ctx context.Context, in *MsgPayPacketFeeAsync, opts ...grpc.CallOption) (*MsgPayPacketFeeAsyncResponse, error) { + out := new(MsgPayPacketFeeAsyncResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.fee.v1.Msg/PayPacketFeeAsync", in, out, opts...) if err != nil { return nil, err } @@ -283,10 +386,14 @@ type MsgServer interface { // 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) - // 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 + // PayPacketFee defines a rpc handler method for MsgPayPacketFee + // PayPacketFee 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. + PayPacketFee(context.Context, *MsgPayPacketFee) (*MsgPayPacketFeeResponse, error) + // PayPacketFee defines a rpc handler method for MsgPayPacketFee + // PayPacketFee 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. - EscrowPacketFee(context.Context, *MsgEscrowPacketFee) (*MsgEscrowPacketFeeResponse, error) + PayPacketFeeAsync(context.Context, *MsgPayPacketFeeAsync) (*MsgPayPacketFeeAsyncResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -296,8 +403,11 @@ 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) EscrowPacketFee(ctx context.Context, req *MsgEscrowPacketFee) (*MsgEscrowPacketFeeResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method EscrowPacketFee not implemented") +func (*UnimplementedMsgServer) PayPacketFee(ctx context.Context, req *MsgPayPacketFee) (*MsgPayPacketFeeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PayPacketFee not implemented") +} +func (*UnimplementedMsgServer) PayPacketFeeAsync(ctx context.Context, req *MsgPayPacketFeeAsync) (*MsgPayPacketFeeAsyncResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PayPacketFeeAsync not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { @@ -322,20 +432,38 @@ func _Msg_RegisterCounterpartyAddress_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } -func _Msg_EscrowPacketFee_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgEscrowPacketFee) +func _Msg_PayPacketFee_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgPayPacketFee) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).PayPacketFee(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.fee.v1.Msg/PayPacketFee", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).PayPacketFee(ctx, req.(*MsgPayPacketFee)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_PayPacketFeeAsync_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgPayPacketFeeAsync) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).EscrowPacketFee(ctx, in) + return srv.(MsgServer).PayPacketFeeAsync(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/ibc.applications.fee.v1.Msg/EscrowPacketFee", + FullMethod: "/ibc.applications.fee.v1.Msg/PayPacketFeeAsync", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).EscrowPacketFee(ctx, req.(*MsgEscrowPacketFee)) + return srv.(MsgServer).PayPacketFeeAsync(ctx, req.(*MsgPayPacketFeeAsync)) } return interceptor(ctx, in, info, handler) } @@ -349,8 +477,12 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_RegisterCounterpartyAddress_Handler, }, { - MethodName: "EscrowPacketFee", - Handler: _Msg_EscrowPacketFee_Handler, + MethodName: "PayPacketFee", + Handler: _Msg_PayPacketFee_Handler, + }, + { + MethodName: "PayPacketFeeAsync", + Handler: _Msg_PayPacketFeeAsync_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -417,7 +549,7 @@ func (m *MsgRegisterCounterpartyAddressResponse) MarshalToSizedBuffer(dAtA []byt return len(dAtA) - i, nil } -func (m *MsgEscrowPacketFee) Marshal() (dAtA []byte, err error) { +func (m *MsgPayPacketFee) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -427,12 +559,12 @@ func (m *MsgEscrowPacketFee) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgEscrowPacketFee) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgPayPacketFee) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgEscrowPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgPayPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -443,12 +575,26 @@ func (m *MsgEscrowPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Relayers[iNdEx]) i = encodeVarintTx(dAtA, i, uint64(len(m.Relayers[iNdEx]))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x22 } } - if m.IncentivizedPacket != nil { + if len(m.SourceChannelId) > 0 { + i -= len(m.SourceChannelId) + copy(dAtA[i:], m.SourceChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourceChannelId))) + i-- + dAtA[i] = 0x1a + } + if len(m.SourcePortId) > 0 { + i -= len(m.SourcePortId) + copy(dAtA[i:], m.SourcePortId) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourcePortId))) + i-- + dAtA[i] = 0x12 + } + if m.Fee != nil { { - size, err := m.IncentivizedPacket.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -461,7 +607,7 @@ func (m *MsgEscrowPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgEscrowPacketFeeResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgPayPacketFeeResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -471,12 +617,91 @@ func (m *MsgEscrowPacketFeeResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgEscrowPacketFeeResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgPayPacketFeeResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgEscrowPacketFeeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgPayPacketFeeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgPayPacketFeeAsync) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgPayPacketFeeAsync) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPayPacketFeeAsync) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Relayers) > 0 { + for iNdEx := len(m.Relayers) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Relayers[iNdEx]) + copy(dAtA[i:], m.Relayers[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Relayers[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if m.PacketId != nil { + { + size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Fee != nil { + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgPayPacketFeeAsyncResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgPayPacketFeeAsyncResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPayPacketFeeAsyncResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -521,14 +746,22 @@ func (m *MsgRegisterCounterpartyAddressResponse) Size() (n int) { return n } -func (m *MsgEscrowPacketFee) Size() (n int) { +func (m *MsgPayPacketFee) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.IncentivizedPacket != nil { - l = m.IncentivizedPacket.Size() + if m.Fee != nil { + l = m.Fee.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SourcePortId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SourceChannelId) + if l > 0 { n += 1 + l + sovTx(uint64(l)) } if len(m.Relayers) > 0 { @@ -540,7 +773,39 @@ func (m *MsgEscrowPacketFee) Size() (n int) { return n } -func (m *MsgEscrowPacketFeeResponse) Size() (n int) { +func (m *MsgPayPacketFeeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgPayPacketFeeAsync) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Fee != nil { + l = m.Fee.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.PacketId != nil { + l = m.PacketId.Size() + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Relayers) > 0 { + for _, s := range m.Relayers { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgPayPacketFeeAsyncResponse) Size() (n int) { if m == nil { return 0 } @@ -719,7 +984,7 @@ func (m *MsgRegisterCounterpartyAddressResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgEscrowPacketFee) Unmarshal(dAtA []byte) error { +func (m *MsgPayPacketFee) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -742,15 +1007,15 @@ func (m *MsgEscrowPacketFee) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgEscrowPacketFee: wiretype end group for non-group") + return fmt.Errorf("proto: MsgPayPacketFee: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgEscrowPacketFee: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgPayPacketFee: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field IncentivizedPacket", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -777,14 +1042,282 @@ func (m *MsgEscrowPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.IncentivizedPacket == nil { - m.IncentivizedPacket = &IdentifiedPacketFee{} + if m.Fee == nil { + m.Fee = &Fee{} } - if err := m.IncentivizedPacket.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourcePortId", 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.SourcePortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourceChannelId", 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.SourceChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Relayers", 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.Relayers = append(m.Relayers, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgPayPacketFeeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgPayPacketFeeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPayPacketFeeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgPayPacketFeeAsync: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPayPacketFeeAsync: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Fee == nil { + m.Fee = &Fee{} + } + if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketId", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PacketId == nil { + m.PacketId = &types.PacketId{} + } + if err := m.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Relayers", wireType) } @@ -837,7 +1370,7 @@ func (m *MsgEscrowPacketFee) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgEscrowPacketFeeResponse) Unmarshal(dAtA []byte) error { +func (m *MsgPayPacketFeeAsyncResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -860,10 +1393,10 @@ func (m *MsgEscrowPacketFeeResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgEscrowPacketFeeResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgPayPacketFeeAsyncResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgEscrowPacketFeeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgPayPacketFeeAsyncResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index 888ade35acb..8ba5421b18a 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -10,15 +10,13 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // See Fee Payment Middleware spec: // https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract message Fee { - repeated cosmos.base.v1beta1.Coin amount = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + repeated cosmos.base.v1beta1.Coin receive_fee = 1 [(gogoproto.moretags) = "yaml:\"receive_fee\""]; + repeated cosmos.base.v1beta1.Coin ack_fee = 2 [(gogoproto.moretags) = "yaml:\"ack_fee\""]; + repeated cosmos.base.v1beta1.Coin timeout_fee = 3 [(gogoproto.moretags) = "yaml:\"timeout_fee\""]; } // Fee associated with a packet_id message IdentifiedPacketFee { - ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; - Fee receive_fee = 2 [(gogoproto.moretags) = "yaml:\"receive_fee\""]; - Fee ack_fee = 3 [(gogoproto.moretags) = "yaml:\"ack_fee\""]; - Fee timeout_fee = 4 [(gogoproto.moretags) = "yaml:\"timeout_fee\""]; - repeated string relayers = 5; + ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; + Fee fee = 2; } diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index 373fd7786c4..4006b5fdc9d 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -7,7 +7,5 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // GenesisState defines the fee middleware genesis state message GenesisState { - // A mapping of packets -> escrowed fees - repeated ibc.applications.fee.v1.IdentifiedPacketFee packets_fees = 1 - [(gogoproto.moretags) = "yaml:\"packets_fees\""]; + // TODO } diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index f9b56cf5011..1d3a9dab07d 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -15,10 +15,14 @@ service Msg { // 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); - // 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 + // PayPacketFee defines a rpc handler method for MsgPayPacketFee + // PayPacketFee 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. - rpc EscrowPacketFee(MsgEscrowPacketFee) returns (MsgEscrowPacketFeeResponse); + rpc PayPacketFee(MsgPayPacketFee) returns (MsgPayPacketFeeResponse); + // PayPacketFee defines a rpc handler method for MsgPayPacketFee + // PayPacketFee 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. + rpc PayPacketFeeAsync(MsgPayPacketFeeAsync) returns (MsgPayPacketFeeAsyncResponse); } // MsgRegisterCounterpartyAddress is the request type for registering the counter party address @@ -34,14 +38,30 @@ message MsgRegisterCounterpartyAddress { message MsgRegisterCounterpartyAddressResponse {} // MsgEscrowPacketFee defines the request type EscrowPacketFee RPC -message MsgEscrowPacketFee { +message MsgPayPacketFee { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - ibc.applications.fee.v1.IdentifiedPacketFee incentivized_packet = 1 - [(gogoproto.moretags) = "yaml:\"incentivized_packet\""]; - repeated string relayers = 2; + ibc.applications.fee.v1.Fee fee = 1; + // source channel port identifier + string source_port_id = 2 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; + // source channel unique identifier + string source_channel_id = 3 [(gogoproto.moretags) = "yaml:\"source_channel_id\""]; + repeated string relayers = 4; } // MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee -message MsgEscrowPacketFeeResponse {} +message MsgPayPacketFeeResponse {} + +// MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +message MsgPayPacketFeeAsync { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + ibc.applications.fee.v1.Fee fee = 1; + ibc.core.channel.v1.PacketId packet_id = 2 [(gogoproto.moretags) = "yaml:\"packet_id\""]; + repeated string relayers = 3; +} + +// MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +message MsgPayPacketFeeAsyncResponse {} From 8f2c51ae9e9913412e122a5abec9778fb08313c7 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 1 Oct 2021 19:09:10 +0200 Subject: [PATCH 02/50] feat: adding escrow logic --- docs/ibc/proto-docs.md | 1 + modules/apps/29-fee/keeper/keeper.go | 18 ++- modules/apps/29-fee/keeper/msg_server.go | 62 ++++++++-- modules/apps/29-fee/types/expected_keepers.go | 13 +++ modules/apps/29-fee/types/fee.pb.go | 109 +++++++++++++----- modules/apps/29-fee/types/keys.go | 8 ++ proto/ibc/applications/fee/v1/fee.proto | 5 +- 7 files changed, 175 insertions(+), 41 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 2a07e51efd0..5f237012d4c 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -649,6 +649,7 @@ Fee associated with a packet_id | ----- | ---- | ----- | ----------- | | `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | | `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | +| `refund_account` | [string](#string) | | | diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index eb14e1a3a1f..01e66dbf91e 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -10,6 +10,9 @@ import ( "github.com/cosmos/ibc-go/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + host "github.com/cosmos/ibc-go/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/modules/core/exported" ) @@ -26,14 +29,16 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryCodec + authKeeper types.AccountKeeper channelKeeper types.ChannelKeeper portKeeper types.PortKeeper + bankKeeper types.BankKeeper } // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, + channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ) Keeper { return Keeper{ @@ -41,6 +46,8 @@ func NewKeeper( storeKey: key, channelKeeper: channelKeeper, portKeeper: portKeeper, + authKeeper: authKeeper, + bankKeeper: bankKeeper, } } @@ -70,6 +77,15 @@ func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) ( return k.channelKeeper.GetNextSequenceSend(ctx, portID, channelID) } +// GetFeeAccount returns the ICS29 - fee ModuleAccount +func (k Keeper) GetFeeAccount(ctx sdk.Context) authtypes.ModuleAccountI { + return k.authKeeper.GetModuleAccount(ctx, types.ModuleName) +} + +func (k Keeper) GetFeeModuleAddress() sdk.AccAddress { + return k.authKeeper.GetModuleAddress(types.ModuleName) +} + // SendPacket wraps IBC ChannelKeeper's SendPacket function func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI) error { return k.channelKeeper.SendPacket(ctx, chanCap, packet) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index ac44212f373..02994064f2a 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" ) @@ -25,24 +27,64 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms 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. +// PayPacketFee defines a rpc handler method for MsgPayPacketFee +// PayPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to relay a packet func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) (*types.MsgPayPacketFeeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + // get the next sequence - /* - sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) - if !found { - return []byte{}, channeltypes.ErrSequenceSendNotFound - } - */ + sequence, found := k.GetNextSequenceSend(ctx, msg.SourcePortId, msg.SourceChannelId) + if !found { + return nil, channeltypes.ErrSequenceSendNotFound + } + + packetId := &channeltypes.PacketId{ + PortId: msg.SourcePortId, + ChannelId: msg.SourceChannelId, + Sequence: sequence, + } + + err := k.escrowPacketFee(ctx, msg.Fee, packetId) + if err != nil { + return nil, err + } return &types.MsgPayPacketFeeResponse{}, nil } -// PayPacketFee defines a rpc handler method for MsgEscrowPacketFee +// PayPacketFee defines a rpc handler method for MsgPayPacketFee // PayPacketFee 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) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacketFeeAsync) (*types.MsgPayPacketFeeAsyncResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + err := k.escrowPacketFee(ctx, msg.Fee, msg.PacketId) + if err != nil { + return nil, err + } + return &types.MsgPayPacketFeeAsyncResponse{}, nil } + +func (k Keeper) escrowPacketFee(ctx sdk.Ctx, fee *types.Fee, packetID *channeltypes.PacketId) error { + // TODO: check if there is a packet that needs to be relayed with packetId if not return err + // TODO: check if there is an account that exists for fee.refundAccount. Return err if not + + // Get the fee module account address + feeEscrowAccAddr := k.GetFeeModuleAddress() + + // TODO: get max(timeoutFee, ackFee, onRecvFee) + totalFee := sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} + + // escrow tokens for fee. It fails if balance insufficient. + if err := k.bankKeeper.SendCoinsFromAccountToModule( + ctx, fee.RefundAccount, types.ModuleName, totalFee, + ); err != nil { + return err + } + + // Store fee in state for reference later + + // refund-account/channel-id/packet/sequence-id/ -> Fee (timeout, ack, onrecv) + return nil +} diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 8e49bbe8ab0..613c24e0728 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -2,11 +2,18 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/modules/core/exported" ) +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI +} + // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) @@ -19,3 +26,9 @@ type ChannelKeeper interface { type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability } + +// BankKeeper defines the expected bank keeper +type BankKeeper interface { + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error +} diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 0e5bbcad62d..42e2759643b 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -90,8 +90,9 @@ func (m *Fee) GetTimeoutFee() []*types.Coin { // Fee associated with a packet_id type IdentifiedPacketFee struct { - PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` - Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` + PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` + Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` + RefundAccount string `protobuf:"bytes,3,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"refund_account"` } func (m *IdentifiedPacketFee) Reset() { *m = IdentifiedPacketFee{} } @@ -141,6 +142,13 @@ func (m *IdentifiedPacketFee) GetFee() *Fee { return nil } +func (m *IdentifiedPacketFee) GetRefundAccount() string { + if m != nil { + return m.RefundAccount + } + return "" +} + func init() { proto.RegisterType((*Fee)(nil), "ibc.applications.fee.v1.Fee") proto.RegisterType((*IdentifiedPacketFee)(nil), "ibc.applications.fee.v1.IdentifiedPacketFee") @@ -149,32 +157,34 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 396 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x31, 0x6b, 0xe3, 0x30, - 0x14, 0xc7, 0xa3, 0x33, 0xe4, 0xee, 0x14, 0x38, 0x0e, 0x5f, 0xb8, 0xcb, 0x85, 0x3b, 0x27, 0xe7, - 0x29, 0x4b, 0x24, 0xec, 0x9b, 0xda, 0x31, 0x05, 0x43, 0xa0, 0x43, 0xf0, 0xd8, 0x25, 0xc8, 0xf2, - 0x8b, 0x23, 0x62, 0x5b, 0x26, 0x56, 0x0c, 0xf9, 0x16, 0xdd, 0xfa, 0x95, 0x3a, 0x66, 0xec, 0x14, - 0x4a, 0xf2, 0x0d, 0x02, 0xdd, 0x8b, 0x6c, 0xb5, 0x64, 0x29, 0xa5, 0x93, 0xde, 0x93, 0xde, 0xef, - 0xff, 0x17, 0xef, 0x3d, 0xfc, 0x4f, 0x44, 0x9c, 0xb2, 0xa2, 0x48, 0x05, 0x67, 0x4a, 0xc8, 0xbc, - 0xa4, 0x0b, 0x00, 0x5a, 0x79, 0xfa, 0x20, 0xc5,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0xe9, 0x5d, - 0xe5, 0x91, 0x06, 0x99, 0xc6, 0x93, 0xee, 0x69, 0x3f, 0xf8, 0xde, 0xb8, 0xbd, 0x92, 0x6e, 0xf8, - 0xa5, 0x30, 0xef, 0x36, 0xc1, 0x56, 0xd3, 0x01, 0xad, 0xf5, 0x87, 0xbc, 0x31, 0x61, 0x12, 0x00, - 0x84, 0xba, 0x70, 0x72, 0x7d, 0x7f, 0x70, 0xd0, 0xee, 0xe0, 0xa0, 0xc7, 0x83, 0x83, 0x6e, 0x8f, - 0x4e, 0x6b, 0x77, 0x74, 0x5a, 0x0f, 0x47, 0xa7, 0x75, 0xe3, 0x27, 0x42, 0x2d, 0x37, 0x11, 0xe1, - 0x32, 0xa3, 0x66, 0x1f, 0x44, 0xc4, 0xc7, 0x89, 0xa4, 0x99, 0x8c, 0x37, 0x29, 0x94, 0x7a, 0xbb, - 0x4a, 0xea, 0x5f, 0x8c, 0xf5, 0x62, 0xa9, 0x6d, 0x01, 0x65, 0xd4, 0xae, 0xc7, 0xfc, 0xff, 0x39, - 0x00, 0x00, 0xff, 0xff, 0x15, 0xa1, 0x8a, 0x94, 0x7d, 0x02, 0x00, 0x00, + // 431 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xbf, 0x8f, 0xd3, 0x30, + 0x14, 0xae, 0x89, 0x74, 0x70, 0xae, 0x38, 0xa1, 0x70, 0x40, 0xef, 0x04, 0x69, 0xf1, 0xd4, 0xe5, + 0x6c, 0xb5, 0x4c, 0x30, 0x41, 0x91, 0x2a, 0x9d, 0xc4, 0x70, 0xca, 0xc8, 0x52, 0x39, 0xce, 0x6b, + 0xcf, 0x6a, 0x63, 0x47, 0x89, 0x13, 0xe9, 0xfe, 0x0b, 0xfe, 0x2c, 0xc6, 0x1b, 0x61, 0x89, 0x50, + 0xfb, 0x1f, 0x44, 0x62, 0x47, 0x8e, 0x5d, 0x94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0xc8, + 0xb5, 0x84, 0xf4, 0x86, 0x8b, 0x2d, 0xd8, 0x7a, 0x78, 0x83, 0x4f, 0xf3, 0x2e, 0x59, 0xc9, 0x74, + 0x84, 0x26, 0x68, 0x3a, 0x9c, 0xbf, 0xa1, 0xf6, 0x2a, 0x76, 0x8d, 0xf4, 0xb8, 0xbb, 0x7a, 0x46, + 0x1d, 0xe4, 0x3a, 0x5d, 0x9c, 0xb7, 0xcd, 0xf8, 0x99, 0x53, 0xfb, 0x8b, 0x24, 0xf1, 0x93, 0xdc, + 0xf7, 0x43, 0x8a, 0x03, 0xb7, 0x01, 0xcb, 0xf5, 0x9a, 0xfe, 0xe3, 0xc2, 0x74, 0x09, 0x10, 0xdb, + 0xc1, 0xf0, 0x23, 0x3e, 0x2b, 0x60, 0x5d, 0xa9, 0x74, 0xc5, 0x85, 0xd0, 0x95, 0x32, 0xa3, 0x60, + 0x82, 0xa6, 0xa7, 0x8b, 0x8b, 0xb6, 0x19, 0xbf, 0x38, 0x6e, 0xbc, 0xdf, 0x27, 0xf1, 0x53, 0x57, + 0xf8, 0xe4, 0xf2, 0xc5, 0x97, 0xef, 0xfb, 0x08, 0xdd, 0xef, 0x23, 0xf4, 0x6b, 0x1f, 0xa1, 0x6f, + 0x87, 0x68, 0x70, 0x7f, 0x88, 0x06, 0x3f, 0x0e, 0xd1, 0xe0, 0xeb, 0x7c, 0x23, 0xcd, 0x6d, 0x95, + 0x50, 0xa1, 0x33, 0xe6, 0x1d, 0x25, 0x13, 0x71, 0xb5, 0xd1, 0x2c, 0xd3, 0x69, 0xb5, 0x83, 0xd2, + 0xfa, 0xb3, 0x64, 0xf3, 0xf7, 0x57, 0xd6, 0x9a, 0xe6, 0x2e, 0x87, 0x32, 0x39, 0xe9, 0x8c, 0xf2, + 0xee, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x42, 0x00, 0x37, 0xbf, 0x02, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -262,6 +272,13 @@ func (m *IdentifiedPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.RefundAccount) > 0 { + i -= len(m.RefundAccount) + copy(dAtA[i:], m.RefundAccount) + i = encodeVarintFee(dAtA, i, uint64(len(m.RefundAccount))) + i-- + dAtA[i] = 0x1a + } if m.Fee != nil { { size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) @@ -341,6 +358,10 @@ func (m *IdentifiedPacketFee) Size() (n int) { l = m.Fee.Size() n += 1 + l + sovFee(uint64(l)) } + l = len(m.RefundAccount) + if l > 0 { + n += 1 + l + sovFee(uint64(l)) + } return n } @@ -603,6 +624,38 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RefundAccount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee + } + 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 ErrInvalidLengthFee + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RefundAccount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipFee(dAtA[iNdEx:]) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 39bbfe5ff85..7174c551d96 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -25,6 +25,9 @@ const ( // RelayerAddressKeyPrefix is the key prefix for relayer address mapping RelayerAddressKeyPrefix = "relayerAddress" + + // RelayerAddressKeyPrefix is the key prefix for relayer address mapping + FeeInEscrowPrefix = "feeInEscrow" ) // FeeEnabledKey returns the key that stores a flag to determine if fee logic should @@ -37,3 +40,8 @@ func FeeEnabledKey(portID, channelID string) []byte { func KeyRelayerAddress(address string) []byte { return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) } + +// KeyFeeInEscrow returns the key for escrowed fees +func KeyFeeInEscrow(account, channelId, sequenceId string) []byte { + return []byte(fmt.Sprintf("%s/%s/%s/packet/%s", FeeInEscrowPrefix, account, channelId, sequenceId)) +} diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index 8ba5421b18a..e58d03c9890 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -17,6 +17,7 @@ message Fee { // Fee associated with a packet_id message IdentifiedPacketFee { - ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; - Fee fee = 2; + ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; + Fee fee = 2; + string refund_account = 3 [(gogoproto.moretags) = "yaml:\"refund_account\""]; } From a410af65900a023960fc84810a4340c6b254e4a4 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 4 Oct 2021 19:58:14 +0200 Subject: [PATCH 03/50] feat: updating proto types & escrow logic --- docs/ibc/proto-docs.md | 12 +- modules/apps/29-fee/keeper/escrow.go | 48 +++++ modules/apps/29-fee/keeper/keeper.go | 35 ++++ modules/apps/29-fee/keeper/msg_server.go | 43 ++--- modules/apps/29-fee/types/errors.go | 4 +- modules/apps/29-fee/types/expected_keepers.go | 2 + modules/apps/29-fee/types/fee.pb.go | 170 ++++++++--------- modules/apps/29-fee/types/keys.go | 2 +- modules/apps/29-fee/types/tx.pb.go | 179 +++++++++++++----- proto/ibc/applications/fee/v1/fee.proto | 6 +- proto/ibc/applications/fee/v1/tx.proto | 14 +- testing/simapp/app.go | 2 +- 12 files changed, 343 insertions(+), 174 deletions(-) create mode 100644 modules/apps/29-fee/keeper/escrow.go diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 5f237012d4c..f8eddb6a135 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -630,9 +630,9 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middl | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `receive_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | -| `ack_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | -| `timeout_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `receive_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `ack_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `timeout_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | @@ -897,6 +897,7 @@ MsgEscrowPacketFee defines the request type EscrowPacketFee RPC | `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | | `source_port_id` | [string](#string) | | source channel port identifier | | `source_channel_id` | [string](#string) | | source channel unique identifier | +| `refund_account` | [string](#string) | | account address to refund fee if necessary | | `relayers` | [string](#string) | repeated | | @@ -912,8 +913,9 @@ MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | -| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | +| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | source channel port identifier | +| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | source channel unique identifier | +| `refund_account` | [string](#string) | | account address to refund fee if necessary | | `relayers` | [string](#string) | repeated | | diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go new file mode 100644 index 00000000000..9593a65a426 --- /dev/null +++ b/modules/apps/29-fee/keeper/escrow.go @@ -0,0 +1,48 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" +) + +func (k Keeper) escrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.Fee, packetID channeltypes.PacketId) error { + // check if the refund account exists + hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) + if hasRefundAcc == nil { + return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc.String())) + } + + fees := sdk.Coins{ + *fee.AckFee, *fee.ReceiveFee, *fee.TimeoutFee, + } + + // check if refundAcc has balance for each fee + for _, f := range fees { + hasBalance := k.bankKeeper.HasBalance(ctx, refundAcc, f) + if !hasBalance { + return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("", refundAcc.String())) + } + } + + // escrow each fee with account module + if err := k.bankKeeper.SendCoinsFromAccountToModule( + ctx, refundAcc, types.ModuleName, fees, + ); err != nil { + return err + } + + // Store fee in state for reference later + // //packet// -> Fee (timeout, ack, onrecv) + k.SetFeeInEscrow(ctx, fee, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + return nil +} + +//TODO: implement +func (k Keeper) PayFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.fee, packetID channeltypes.PacketId) error { + return nil +} diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 01e66dbf91e..c37dbe7c907 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -129,3 +129,38 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) return store.Get(key), true } + +// Stores a Fee for a given packet in state +func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.Fee, account, channelId string, sequenceId uint64) { + store := ctx.KVStore(k.storeKey) + bz := k.MustMarshalFee(fee) + store.Set(types.KeyFeeInEscrow(account, channelId, sequenceId), bz) +} + +// Gets a Fee for a given packet +func (k Keeper) GetFeeInEscrow(ctx sdk.Context, account, channelId string, sequenceId uint64) (types.Fee, bool) { + store := ctx.KVStore(k.storeKey) + key := types.KeyFeeInEscrow(account, channelId, sequenceId) + bz := store.Get(key) + if bz == nil { + return types.Fee{}, false + } + + fee := k.MustUnmarshalFee(bz) + + return fee, true +} + +// MustMarshalFee attempts to encode a Fee object and returns the +// raw encoded bytes. It panics on error. +func (k Keeper) MustMarshalFee(fee types.Fee) []byte { + return k.cdc.MustMarshal(&fee) +} + +// MustUnmarshalFee attempts to decode and return a Fee object from +// raw encoded bytes. It panics on error. +func (k Keeper) MustUnmarshalFee(bz []byte) types.Fee { + var fee types.Fee + k.cdc.MustUnmarshal(bz, &fee) + return fee +} diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 02994064f2a..ca557bc70fe 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -28,7 +28,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms } // PayPacketFee defines a rpc handler method for MsgPayPacketFee -// PayPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to relay a packet +// PayPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to relay the packet with the next sequence func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) (*types.MsgPayPacketFeeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -38,13 +38,18 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) return nil, channeltypes.ErrSequenceSendNotFound } - packetId := &channeltypes.PacketId{ + packetId := channeltypes.PacketId{ PortId: msg.SourcePortId, ChannelId: msg.SourceChannelId, Sequence: sequence, } - err := k.escrowPacketFee(ctx, msg.Fee, packetId) + refundAccAddr, err := sdk.AccAddressFromBech32(msg.RefundAccount) + if err != nil { + return &types.MsgPayPacketFeeResponse{}, err + } + + err = k.escrowPacketFee(ctx, refundAccAddr, *msg.Fee, packetId) if err != nil { return nil, err } @@ -54,37 +59,19 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) // PayPacketFee defines a rpc handler method for MsgPayPacketFee // PayPacketFee 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. +// incentivize the relaying of a known packet func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacketFeeAsync) (*types.MsgPayPacketFeeAsyncResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - err := k.escrowPacketFee(ctx, msg.Fee, msg.PacketId) + refundAccAddr, err := sdk.AccAddressFromBech32(msg.RefundAccount) if err != nil { - return nil, err + return &types.MsgPayPacketFeeAsyncResponse{}, err } - return &types.MsgPayPacketFeeAsyncResponse{}, nil -} - -func (k Keeper) escrowPacketFee(ctx sdk.Ctx, fee *types.Fee, packetID *channeltypes.PacketId) error { - // TODO: check if there is a packet that needs to be relayed with packetId if not return err - // TODO: check if there is an account that exists for fee.refundAccount. Return err if not - - // Get the fee module account address - feeEscrowAccAddr := k.GetFeeModuleAddress() - - // TODO: get max(timeoutFee, ackFee, onRecvFee) - totalFee := sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} - - // escrow tokens for fee. It fails if balance insufficient. - if err := k.bankKeeper.SendCoinsFromAccountToModule( - ctx, fee.RefundAccount, types.ModuleName, totalFee, - ); err != nil { - return err + err = k.escrowPacketFee(ctx, refundAccAddr, *msg.Fee, *msg.PacketId) + if err != nil { + return nil, err } - // Store fee in state for reference later - - // refund-account/channel-id/packet/sequence-id/ -> Fee (timeout, ack, onrecv) - return nil + return &types.MsgPayPacketFeeAsyncResponse{}, nil } diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 5536d326fc0..fcd7b3d3594 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -6,5 +6,7 @@ import ( // 29-fee sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") + ErrInvalidVersion = sdkerrors.Register(ModuleName, 1, "invalid ICS29 middleware version") + ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 2, "No account found for given refund address") + ErrBalanceNotFound = sdkerrors.Register(ModuleName, 3, "Balance not found for given account address") ) diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 613c24e0728..e38832f4952 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -12,6 +12,7 @@ import ( type AccountKeeper interface { GetModuleAddress(name string) sdk.AccAddress GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI + GetAccount(sdk.Context, sdk.AccAddress) types.AccountI } // ChannelKeeper defines the expected IBC channel keeper @@ -29,6 +30,7 @@ type PortKeeper interface { // BankKeeper defines the expected bank keeper type BankKeeper interface { + HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 42e2759643b..47a7f759be2 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -29,9 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // See Fee Payment Middleware spec: // https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract type Fee struct { - ReceiveFee []*types.Coin `protobuf:"bytes,1,rep,name=receive_fee,json=receiveFee,proto3" json:"receive_fee,omitempty" yaml:"receive_fee"` - AckFee []*types.Coin `protobuf:"bytes,2,rep,name=ack_fee,json=ackFee,proto3" json:"ack_fee,omitempty" yaml:"ack_fee"` - TimeoutFee []*types.Coin `protobuf:"bytes,3,rep,name=timeout_fee,json=timeoutFee,proto3" json:"timeout_fee,omitempty" yaml:"timeout_fee"` + ReceiveFee *types.Coin `protobuf:"bytes,1,opt,name=receive_fee,json=receiveFee,proto3" json:"receive_fee,omitempty" yaml:"receive_fee"` + AckFee *types.Coin `protobuf:"bytes,2,opt,name=ack_fee,json=ackFee,proto3" json:"ack_fee,omitempty" yaml:"ack_fee"` + TimeoutFee *types.Coin `protobuf:"bytes,3,opt,name=timeout_fee,json=timeoutFee,proto3" json:"timeout_fee,omitempty" yaml:"timeout_fee"` } func (m *Fee) Reset() { *m = Fee{} } @@ -67,21 +67,21 @@ func (m *Fee) XXX_DiscardUnknown() { var xxx_messageInfo_Fee proto.InternalMessageInfo -func (m *Fee) GetReceiveFee() []*types.Coin { +func (m *Fee) GetReceiveFee() *types.Coin { if m != nil { return m.ReceiveFee } return nil } -func (m *Fee) GetAckFee() []*types.Coin { +func (m *Fee) GetAckFee() *types.Coin { if m != nil { return m.AckFee } return nil } -func (m *Fee) GetTimeoutFee() []*types.Coin { +func (m *Fee) GetTimeoutFee() *types.Coin { if m != nil { return m.TimeoutFee } @@ -157,34 +157,34 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 431 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xbf, 0x8f, 0xd3, 0x30, - 0x14, 0xae, 0x89, 0x74, 0x70, 0xae, 0x38, 0xa1, 0x70, 0x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x25, 0x13, 0x71, 0xb5, 0xd1, 0x2c, 0xd3, 0x69, 0xb5, 0x83, 0xd2, - 0xfa, 0xb3, 0x64, 0xf3, 0xf7, 0x57, 0xd6, 0x9a, 0xe6, 0x2e, 0x87, 0x32, 0x39, 0xe9, 0x8c, 0xf2, - 0xee, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x42, 0x00, 0x37, 0xbf, 0x02, 0x00, 0x00, + // 423 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x3d, 0x6f, 0xd4, 0x30, + 0x18, 0xbe, 0x70, 0x52, 0xa1, 0xae, 0xa8, 0x50, 0x28, 0x1f, 0xad, 0x20, 0x07, 0x9e, 0x58, 0x6a, + 0x2b, 0xc7, 0x04, 0x13, 0x04, 0x29, 0x52, 0x25, 0x86, 0x2a, 0x23, 0xcb, 0xc9, 0x71, 0xde, 0xa4, + 0xd6, 0x25, 0x76, 0x94, 0x38, 0x91, 0xfa, 0x2f, 0xf8, 0x59, 0x8c, 0x1d, 0x61, 0x89, 0xd0, 0xdd, + 0x3f, 0x88, 0xc4, 0x8e, 0x1c, 0xbb, 0x90, 0x05, 0xa1, 0x4e, 0x79, 0xbf, 0x9e, 0xe7, 0x71, 0x9e, + 0xf7, 0x45, 0xaf, 0x45, 0xca, 0x29, 0xab, 0xeb, 0x52, 0x70, 0xa6, 0x85, 0x92, 0x2d, 0xcd, 0x01, + 0x68, 0x1f, 0x9a, 0x0f, 0xa9, 0x1b, 0xa5, 0x95, 0xff, 0x4c, 0xa4, 0x9c, 0xcc, 0x47, 0x88, 0xe9, + 0xf5, 0xe1, 0x59, 0xc0, 0x55, 0x5b, 0xa9, 0x96, 0xa6, 0xac, 0x35, 0x90, 0x14, 0x34, 0x0b, 0x29, + 0x57, 0x42, 0x5a, 0xe0, 0xd9, 0x49, 0xa1, 0x0a, 0x35, 0x85, 0xd4, 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, + 0x9d, 0xcc, 0x36, 0x8c, 0x73, 0xd5, 0x49, 0x3d, 0xfd, 0xf0, 0x61, 0x74, 0x3a, 0x0e, 0xab, 0x27, + 0xb7, 0x8e, 0xcf, 0xfb, 0x38, 0x79, 0x68, 0x0b, 0x1f, 0x6d, 0x1e, 0x7d, 0xfe, 0xb6, 0x0b, 0xbc, + 0x9b, 0x5d, 0xe0, 0xfd, 0xdc, 0x05, 0xde, 0xd7, 0x7d, 0xb0, 0xb8, 0xd9, 0x07, 0x8b, 0xef, 0xfb, + 0x60, 0xf1, 0x65, 0x5d, 0x08, 0x7d, 0xd5, 0xa5, 0x84, 0xab, 0x8a, 0xba, 0x8b, 0x12, 0x29, 0x3f, + 0x2f, 0x14, 0xad, 0x54, 0xd6, 0x95, 0xd0, 0x9a, 0xfb, 0x6c, 0xe9, 0xfa, 0xdd, 0xb9, 0x39, 0x4d, + 0x7d, 0x5d, 0x43, 0x9b, 0x1e, 0x4c, 0x87, 0xf2, 0xf6, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe5, + 0xf0, 0x08, 0xe4, 0xbf, 0x02, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -207,47 +207,41 @@ func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.TimeoutFee) > 0 { - for iNdEx := len(m.TimeoutFee) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.TimeoutFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + if m.TimeoutFee != nil { + { + size, err := m.TimeoutFee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x1a + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x1a } - if len(m.AckFee) > 0 { - for iNdEx := len(m.AckFee) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.AckFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + if m.AckFee != nil { + { + size, err := m.AckFee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 } - if len(m.ReceiveFee) > 0 { - for iNdEx := len(m.ReceiveFee) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ReceiveFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + if m.ReceiveFee != nil { + { + size, err := m.ReceiveFee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -323,23 +317,17 @@ func (m *Fee) Size() (n int) { } var l int _ = l - if len(m.ReceiveFee) > 0 { - for _, e := range m.ReceiveFee { - l = e.Size() - n += 1 + l + sovFee(uint64(l)) - } + if m.ReceiveFee != nil { + l = m.ReceiveFee.Size() + n += 1 + l + sovFee(uint64(l)) } - if len(m.AckFee) > 0 { - for _, e := range m.AckFee { - l = e.Size() - n += 1 + l + sovFee(uint64(l)) - } + if m.AckFee != nil { + l = m.AckFee.Size() + n += 1 + l + sovFee(uint64(l)) } - if len(m.TimeoutFee) > 0 { - for _, e := range m.TimeoutFee { - l = e.Size() - n += 1 + l + sovFee(uint64(l)) - } + if m.TimeoutFee != nil { + l = m.TimeoutFee.Size() + n += 1 + l + sovFee(uint64(l)) } return n } @@ -429,8 +417,10 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ReceiveFee = append(m.ReceiveFee, &types.Coin{}) - if err := m.ReceiveFee[len(m.ReceiveFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.ReceiveFee == nil { + m.ReceiveFee = &types.Coin{} + } + if err := m.ReceiveFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -463,8 +453,10 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.AckFee = append(m.AckFee, &types.Coin{}) - if err := m.AckFee[len(m.AckFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.AckFee == nil { + m.AckFee = &types.Coin{} + } + if err := m.AckFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -497,8 +489,10 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.TimeoutFee = append(m.TimeoutFee, &types.Coin{}) - if err := m.TimeoutFee[len(m.TimeoutFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.TimeoutFee == nil { + m.TimeoutFee = &types.Coin{} + } + if err := m.TimeoutFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 7174c551d96..23cca52ac0b 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -42,6 +42,6 @@ func KeyRelayerAddress(address string) []byte { } // KeyFeeInEscrow returns the key for escrowed fees -func KeyFeeInEscrow(account, channelId, sequenceId string) []byte { +func KeyFeeInEscrow(account, channelId string, sequenceId uint64) []byte { return []byte(fmt.Sprintf("%s/%s/%s/packet/%s", FeeInEscrowPrefix, account, channelId, sequenceId)) } diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index bad5686276d..40ed60ca5dc 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -113,8 +113,10 @@ type MsgPayPacketFee struct { // source channel port identifier SourcePortId string `protobuf:"bytes,2,opt,name=source_port_id,json=sourcePortId,proto3" json:"source_port_id,omitempty" yaml:"source_port_id"` // source channel unique identifier - SourceChannelId string `protobuf:"bytes,3,opt,name=source_channel_id,json=sourceChannelId,proto3" json:"source_channel_id,omitempty" yaml:"source_channel_id"` - Relayers []string `protobuf:"bytes,4,rep,name=relayers,proto3" json:"relayers,omitempty"` + SourceChannelId string `protobuf:"bytes,3,opt,name=source_channel_id,json=sourceChannelId,proto3" json:"source_channel_id,omitempty" yaml:"source_channel_id"` + // account address to refund fee if necessary + RefundAccount string `protobuf:"bytes,4,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"source_port_id"` + Relayers []string `protobuf:"bytes,5,rep,name=relayers,proto3" json:"relayers,omitempty"` } func (m *MsgPayPacketFee) Reset() { *m = MsgPayPacketFee{} } @@ -189,9 +191,13 @@ var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo // MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC type MsgPayPacketFeeAsync struct { - Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + // source channel port identifier + Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + // source channel unique identifier PacketId *types.PacketId `protobuf:"bytes,2,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` - Relayers []string `protobuf:"bytes,3,rep,name=relayers,proto3" json:"relayers,omitempty"` + // account address to refund fee if necessary + RefundAccount string `protobuf:"bytes,3,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"source_port_id"` + Relayers []string `protobuf:"bytes,4,rep,name=relayers,proto3" json:"relayers,omitempty"` } func (m *MsgPayPacketFeeAsync) Reset() { *m = MsgPayPacketFeeAsync{} } @@ -276,43 +282,44 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 562 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x63, 0x8c, 0x20, 0xb9, 0x56, 0x94, 0x9a, 0xa0, 0xa6, 0x6e, 0xb0, 0x83, 0x07, 0x94, - 0x25, 0x36, 0x09, 0x42, 0x88, 0x2e, 0x55, 0x53, 0xa9, 0x22, 0x12, 0x91, 0xa2, 0x1b, 0x59, 0x22, - 0xe7, 0xfc, 0xe2, 0x1a, 0x12, 0x9f, 0x75, 0x77, 0x89, 0xf0, 0x17, 0x40, 0x8c, 0x6c, 0x30, 0xf6, - 0x93, 0x30, 0x33, 0x76, 0x64, 0x8a, 0x50, 0xb2, 0x30, 0xe7, 0x13, 0x20, 0xdb, 0x71, 0x70, 0xda, - 0x26, 0x6a, 0xbb, 0x9d, 0xef, 0xfd, 0xde, 0xff, 0xbd, 0xff, 0xf3, 0xd3, 0xa1, 0x8a, 0xd7, 0x23, - 0x96, 0x1d, 0x04, 0x03, 0x8f, 0xd8, 0xc2, 0xa3, 0x3e, 0xb7, 0xfa, 0x00, 0xd6, 0xb8, 0x6e, 0x89, - 0xcf, 0x66, 0xc0, 0xa8, 0xa0, 0xca, 0x9e, 0xd7, 0x23, 0x66, 0x96, 0x30, 0xfb, 0x00, 0xe6, 0xb8, - 0xae, 0x16, 0x5d, 0xea, 0xd2, 0x98, 0xb1, 0xa2, 0x53, 0x82, 0xab, 0xcf, 0xd7, 0x09, 0x46, 0x59, - 0x19, 0x84, 0x50, 0x06, 0x16, 0x39, 0xb3, 0x7d, 0x1f, 0x06, 0x51, 0x78, 0x71, 0x4c, 0x10, 0xe3, - 0x87, 0x84, 0xb4, 0x36, 0x77, 0x31, 0xb8, 0x1e, 0x17, 0xc0, 0x4e, 0xe8, 0xc8, 0x17, 0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xd1, 0xb3, 0x25, 0xc2, 0x00, 0x78, 0xef, - 0x41, 0xfc, 0x26, 0xbd, 0xfa, 0x17, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x1d, 0xc3, 0xf4, 0x2c, 0x05, - 0x00, 0x00, + // 592 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0xe3, 0xba, 0x40, 0x72, 0x2d, 0x2d, 0x35, 0x41, 0x4d, 0xdd, 0x60, 0x07, 0x0f, 0x28, + 0x4b, 0x6c, 0x12, 0x84, 0x10, 0x5d, 0x4a, 0x52, 0xa9, 0x22, 0x12, 0x91, 0x22, 0x8f, 0x2c, 0x91, + 0x73, 0x7e, 0x71, 0x0d, 0x89, 0xcf, 0xba, 0x73, 0x22, 0xbc, 0x31, 0x21, 0x46, 0x36, 0x18, 0xfb, + 0x21, 0xf8, 0x10, 0x8c, 0x1d, 0x99, 0x22, 0x94, 0x2c, 0xcc, 0xf9, 0x04, 0xc8, 0xbe, 0x38, 0x24, + 0x6d, 0x12, 0x5a, 0xd8, 0xee, 0xee, 0xfd, 0xde, 0xff, 0xbd, 0xfb, 0xeb, 0xdd, 0xa1, 0x82, 0xdb, + 0xc6, 0x86, 0xe5, 0xfb, 0x5d, 0x17, 0x5b, 0x81, 0x4b, 0x3c, 0x66, 0x74, 0x00, 0x8c, 0x41, 0xd9, + 0x08, 0xde, 0xeb, 0x3e, 0x25, 0x01, 0x91, 0xf6, 0xdd, 0x36, 0xd6, 0xe7, 0x09, 0xbd, 0x03, 0xa0, + 0x0f, 0xca, 0x72, 0xd6, 0x21, 0x0e, 0x89, 0x19, 0x23, 0x5a, 0x71, 0x5c, 0x7e, 0xb4, 0x4a, 0x30, + 0xca, 0x9a, 0x43, 0x30, 0xa1, 0x60, 0xe0, 0x33, 0xcb, 0xf3, 0xa0, 0x1b, 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8, 0x39, 0x52, 0x84, 0xcf, 0x63, 0x25, 0x75, 0x31, + 0x56, 0x52, 0x3f, 0xc6, 0x4a, 0xea, 0x4d, 0xc5, 0x71, 0x83, 0xb3, 0x7e, 0x5b, 0xc7, 0xa4, 0x67, + 0x60, 0xc2, 0x7a, 0x84, 0x19, 0x6e, 0x1b, 0x97, 0x1c, 0x62, 0xf4, 0x88, 0xdd, 0xef, 0x02, 0x8b, + 0xfe, 0x4f, 0x66, 0x54, 0x5e, 0x94, 0xa2, 0xaf, 0x33, 0x08, 0x7d, 0x60, 0xed, 0xdb, 0xf1, 0xbf, + 0xf8, 0xf4, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x71, 0x80, 0x01, 0xb4, 0xb0, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -575,9 +582,16 @@ func (m *MsgPayPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Relayers[iNdEx]) i = encodeVarintTx(dAtA, i, uint64(len(m.Relayers[iNdEx]))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } } + if len(m.RefundAccount) > 0 { + i -= len(m.RefundAccount) + copy(dAtA[i:], m.RefundAccount) + i = encodeVarintTx(dAtA, i, uint64(len(m.RefundAccount))) + i-- + dAtA[i] = 0x22 + } if len(m.SourceChannelId) > 0 { i -= len(m.SourceChannelId) copy(dAtA[i:], m.SourceChannelId) @@ -656,9 +670,16 @@ func (m *MsgPayPacketFeeAsync) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Relayers[iNdEx]) i = encodeVarintTx(dAtA, i, uint64(len(m.Relayers[iNdEx]))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } } + if len(m.RefundAccount) > 0 { + i -= len(m.RefundAccount) + copy(dAtA[i:], m.RefundAccount) + i = encodeVarintTx(dAtA, i, uint64(len(m.RefundAccount))) + i-- + dAtA[i] = 0x1a + } if m.PacketId != nil { { size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) @@ -764,6 +785,10 @@ func (m *MsgPayPacketFee) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.RefundAccount) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } if len(m.Relayers) > 0 { for _, s := range m.Relayers { l = len(s) @@ -796,6 +821,10 @@ func (m *MsgPayPacketFeeAsync) Size() (n int) { l = m.PacketId.Size() n += 1 + l + sovTx(uint64(l)) } + l = len(m.RefundAccount) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } if len(m.Relayers) > 0 { for _, s := range m.Relayers { l = len(s) @@ -1114,6 +1143,38 @@ func (m *MsgPayPacketFee) Unmarshal(dAtA []byte) error { m.SourceChannelId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RefundAccount", 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.RefundAccount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Relayers", wireType) } @@ -1318,6 +1379,38 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RefundAccount", 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.RefundAccount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Relayers", wireType) } diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index e58d03c9890..57561aa3100 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -10,9 +10,9 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // See Fee Payment Middleware spec: // https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract message Fee { - repeated cosmos.base.v1beta1.Coin receive_fee = 1 [(gogoproto.moretags) = "yaml:\"receive_fee\""]; - repeated cosmos.base.v1beta1.Coin ack_fee = 2 [(gogoproto.moretags) = "yaml:\"ack_fee\""]; - repeated cosmos.base.v1beta1.Coin timeout_fee = 3 [(gogoproto.moretags) = "yaml:\"timeout_fee\""]; + cosmos.base.v1beta1.Coin receive_fee = 1 [(gogoproto.moretags) = "yaml:\"receive_fee\""]; + cosmos.base.v1beta1.Coin ack_fee = 2 [(gogoproto.moretags) = "yaml:\"ack_fee\""]; + cosmos.base.v1beta1.Coin timeout_fee = 3 [(gogoproto.moretags) = "yaml:\"timeout_fee\""]; } // Fee associated with a packet_id diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 1d3a9dab07d..2623aa68c58 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -46,8 +46,10 @@ message MsgPayPacketFee { // source channel port identifier string source_port_id = 2 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; // source channel unique identifier - string source_channel_id = 3 [(gogoproto.moretags) = "yaml:\"source_channel_id\""]; - repeated string relayers = 4; + string source_channel_id = 3 [(gogoproto.moretags) = "yaml:\"source_channel_id\""]; + // account address to refund fee if necessary + string refund_account = 4 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; + repeated string relayers = 5; } // MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee @@ -58,9 +60,13 @@ message MsgPayPacketFeeAsync { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - ibc.applications.fee.v1.Fee fee = 1; + // source channel port identifier + ibc.applications.fee.v1.Fee fee = 1; + // source channel unique identifier ibc.core.channel.v1.PacketId packet_id = 2 [(gogoproto.moretags) = "yaml:\"packet_id\""]; - repeated string relayers = 3; + // account address to refund fee if necessary + string refund_account = 3 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; + repeated string relayers = 4; } // MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 83cdf6ff2a7..dbd65bd4b2c 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -322,7 +322,7 @@ func NewSimApp( ) app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(appCodec, keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, ) // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper From 0e6823f9cb8526726ee8257c5485ceb7c01b9df6 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 5 Oct 2021 08:20:57 +0200 Subject: [PATCH 04/50] fix: stub fn & proto comment --- docs/ibc/proto-docs.md | 5 +- modules/apps/29-fee/keeper/escrow.go | 2 +- modules/apps/29-fee/types/fee.pb.go | 109 ++++++------------------ modules/apps/29-fee/types/tx.pb.go | 97 ++++++++++----------- proto/ibc/applications/fee/v1/fee.proto | 5 +- proto/ibc/applications/fee/v1/tx.proto | 12 +-- 6 files changed, 88 insertions(+), 142 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index f8eddb6a135..272bf622cf6 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -649,7 +649,6 @@ Fee associated with a packet_id | ----- | ---- | ----- | ----------- | | `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | | `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | -| `refund_account` | [string](#string) | | | @@ -983,8 +982,8 @@ 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. | | -| `PayPacketFee` | [MsgPayPacketFee](#ibc.applications.fee.v1.MsgPayPacketFee) | [MsgPayPacketFeeResponse](#ibc.applications.fee.v1.MsgPayPacketFeeResponse) | PayPacketFee defines a rpc handler method for MsgPayPacketFee PayPacketFee 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. | | -| `PayPacketFeeAsync` | [MsgPayPacketFeeAsync](#ibc.applications.fee.v1.MsgPayPacketFeeAsync) | [MsgPayPacketFeeAsyncResponse](#ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse) | PayPacketFee defines a rpc handler method for MsgPayPacketFee PayPacketFee 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. | | +| `PayPacketFee` | [MsgPayPacketFee](#ibc.applications.fee.v1.MsgPayPacketFee) | [MsgPayPacketFeeResponse](#ibc.applications.fee.v1.MsgPayPacketFeeResponse) | PayPacketFee defines a rpc handler method for MsgPayPacketFee PayPacketFee 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 packet at the next sequence | | +| `PayPacketFeeAsync` | [MsgPayPacketFeeAsync](#ibc.applications.fee.v1.MsgPayPacketFeeAsync) | [MsgPayPacketFeeAsyncResponse](#ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse) | PayPacketFeeAsync defines a rpc handler method for MsgPayPacketFeeAsync PayPacketFeeAsync is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of a known packet | | diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 9593a65a426..23183b220fe 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -43,6 +43,6 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t } //TODO: implement -func (k Keeper) PayFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.fee, packetID channeltypes.PacketId) error { +func (k Keeper) PayFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.Fee, packetID channeltypes.PacketId) error { return nil } diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 47a7f759be2..16dbe16fd38 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -90,9 +90,8 @@ func (m *Fee) GetTimeoutFee() *types.Coin { // Fee associated with a packet_id type IdentifiedPacketFee struct { - PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` - Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` - RefundAccount string `protobuf:"bytes,3,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"refund_account"` + PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` + Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` } func (m *IdentifiedPacketFee) Reset() { *m = IdentifiedPacketFee{} } @@ -142,13 +141,6 @@ func (m *IdentifiedPacketFee) GetFee() *Fee { return nil } -func (m *IdentifiedPacketFee) GetRefundAccount() string { - if m != nil { - return m.RefundAccount - } - return "" -} - func init() { proto.RegisterType((*Fee)(nil), "ibc.applications.fee.v1.Fee") proto.RegisterType((*IdentifiedPacketFee)(nil), "ibc.applications.fee.v1.IdentifiedPacketFee") @@ -157,34 +149,32 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 423 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x3d, 0x6f, 0xd4, 0x30, - 0x18, 0xbe, 0x70, 0x52, 0xa1, 0xae, 0xa8, 0x50, 0x28, 0x1f, 0xad, 0x20, 0x07, 0x9e, 0x58, 0x6a, - 0x2b, 0xc7, 0x04, 0x13, 0x04, 0x29, 0x52, 0x25, 0x86, 0x2a, 0x23, 0xcb, 0xc9, 0x71, 0xde, 0xa4, - 0xd6, 0x25, 0x76, 0x94, 0x38, 0x91, 0xfa, 0x2f, 0xf8, 0x59, 0x8c, 0x1d, 0x61, 0x89, 0xd0, 0xdd, - 0x3f, 0x88, 0xc4, 0x8e, 0x1c, 0xbb, 0x90, 0x05, 0xa1, 0x4e, 0x79, 0xbf, 0x9e, 0xe7, 0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f1, 0x2d, 0x98, 0xba, 0x7f, 0x89, 0x0e, 0xeb, 0x29, 0xd9, 0x88, 0xcc, 0xb9, - 0xf0, 0x92, 0x98, 0xad, 0x18, 0x1b, 0xc9, 0xad, 0x77, 0x7d, 0x48, 0x2c, 0xe4, 0x22, 0x8b, 0x4e, - 0xc6, 0x61, 0xf5, 0xc8, 0xaa, 0xfd, 0x41, 0xe2, 0xe4, 0x41, 0xed, 0xfa, 0x3e, 0x41, 0xcb, 0xbf, - 0x0e, 0xbc, 0x20, 0xff, 0xd8, 0x30, 0x89, 0x01, 0x12, 0x33, 0xe8, 0x7f, 0x40, 0xc7, 0x0d, 0xe4, - 0x9d, 0xcc, 0x36, 0x8c, 0x73, 0xd5, 0x49, 0x3d, 0xfd, 0xf0, 0x61, 0x74, 0x3a, 0x0e, 0xab, 0x27, - 0xb7, 0x8e, 0xcf, 0xfb, 0x38, 0x79, 0x68, 0x0b, 0x1f, 0x6d, 0x1e, 0x7d, 0xfe, 0xb6, 0x0b, 0xbc, - 0x9b, 0x5d, 0xe0, 0xfd, 0xdc, 0x05, 0xde, 0xd7, 0x7d, 0xb0, 0xb8, 0xd9, 0x07, 0x8b, 0xef, 0xfb, - 0x60, 0xf1, 0x65, 0x5d, 0x08, 0x7d, 0xd5, 0xa5, 0x84, 0xab, 0x8a, 0xba, 0x8b, 0x12, 0x29, 0x3f, - 0x2f, 0x14, 0xad, 0x54, 0xd6, 0x95, 0xd0, 0x9a, 0xfb, 0x6c, 0xe9, 0xfa, 0xdd, 0xb9, 0x39, 0x4d, - 0x7d, 0x5d, 0x43, 0x9b, 0x1e, 0x4c, 0x87, 0xf2, 0xf6, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe5, - 0xf0, 0x08, 0xe4, 0xbf, 0x02, 0x00, 0x00, + // 388 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4f, 0x4b,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ff, 0xff, 0x14, 0x78, 0xaf, 0x83, + 0x7d, 0x02, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -266,13 +256,6 @@ func (m *IdentifiedPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.RefundAccount) > 0 { - i -= len(m.RefundAccount) - copy(dAtA[i:], m.RefundAccount) - i = encodeVarintFee(dAtA, i, uint64(len(m.RefundAccount))) - i-- - dAtA[i] = 0x1a - } if m.Fee != nil { { size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) @@ -346,10 +329,6 @@ func (m *IdentifiedPacketFee) Size() (n int) { l = m.Fee.Size() n += 1 + l + sovFee(uint64(l)) } - l = len(m.RefundAccount) - if l > 0 { - n += 1 + l + sovFee(uint64(l)) - } return n } @@ -618,38 +597,6 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RefundAccount", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFee - } - 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 ErrInvalidLengthFee - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFee - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RefundAccount = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipFee(dAtA[iNdEx:]) diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 40ed60ca5dc..2f2f6313785 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -115,7 +115,7 @@ type MsgPayPacketFee struct { // source channel unique identifier SourceChannelId string `protobuf:"bytes,3,opt,name=source_channel_id,json=sourceChannelId,proto3" json:"source_channel_id,omitempty" yaml:"source_channel_id"` // account address to refund fee if necessary - RefundAccount string `protobuf:"bytes,4,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"source_port_id"` + RefundAccount string `protobuf:"bytes,4,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"refund_account"` Relayers []string `protobuf:"bytes,5,rep,name=relayers,proto3" json:"relayers,omitempty"` } @@ -196,7 +196,7 @@ type MsgPayPacketFeeAsync struct { // source channel unique identifier PacketId *types.PacketId `protobuf:"bytes,2,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` // account address to refund fee if necessary - RefundAccount string `protobuf:"bytes,3,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"source_port_id"` + RefundAccount string `protobuf:"bytes,3,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"refund_account"` Relayers []string `protobuf:"bytes,4,rep,name=relayers,proto3" json:"relayers,omitempty"` } @@ -282,44 +282,45 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 592 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xe3, 0xba, 0x40, 0x72, 0x2d, 0x2d, 0x35, 0x41, 0x4d, 0xdd, 0x60, 0x07, 0x0f, 0x28, - 0x4b, 0x6c, 0x12, 0x84, 0x10, 0x5d, 0x4a, 0x52, 0xa9, 0x22, 0x12, 0x91, 0x22, 0x8f, 0x2c, 0x91, - 0x73, 0x7e, 0x71, 0x0d, 0x89, 0xcf, 0xba, 0x73, 0x22, 0xbc, 0x31, 0x21, 0x46,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 0xa1, 0x7a, 0x8f, 0xdf, 0x72, 0x96, 0xa9, - 0x99, 0x69, 0x7f, 0x1a, 0x5f, 0xe2, 0x8e, 0xf8, 0x1f, 0xee, 0x6c, 0xae, 0x74, 0x47, 0x41, 0xf9, - 0x65, 0x0e, 0x24, 0x16, 0x55, 0x3e, 0x8a, 0x48, 0x6c, 0x30, 0x47, 0xfa, 0x22, 0xa0, 0xc3, 0x75, - 0xcf, 0xe7, 0xf9, 0x4a, 0x93, 0xd6, 0x4f, 0xb7, 0x7c, 0xfc, 0x8f, 0x89, 0x49, 0x87, 0xd2, 0x5b, - 0xb4, 0xbd, 0xf0, 0x24, 0x8a, 0xeb, 0x04, 0xe7, 0x49, 0xf9, 0xc9, 0x75, 0xc9, 0x59, 0xad, 0x10, - 0xed, 0x5d, 0x1d, 0x96, 0xd2, 0x75, 0x65, 0x62, 0x5c, 0x7e, 0x76, 0x23, 0x3c, 0x29, 0x5d, 0x7b, - 0xfd, 0x7d, 0xa4, 0x08, 0x17, 0x23, 0x45, 0xf8, 0x39, 0x52, 0x84, 0xcf, 0x63, 0x25, 0x75, 0x31, - 0x56, 0x52, 0x3f, 0xc6, 0x4a, 0xea, 0x4d, 0xc5, 0x71, 0x83, 0xb3, 0x7e, 0x5b, 0xc7, 0xa4, 0x67, - 0x60, 0xc2, 0x7a, 0x84, 0x19, 0x6e, 0x1b, 0x97, 0x1c, 0x62, 0xf4, 0x88, 0xdd, 0xef, 0x02, 0x8b, - 0xfe, 0x4f, 0x66, 0x54, 0x5e, 0x94, 0xa2, 0xaf, 0x33, 0x08, 0x7d, 0x60, 0xed, 0xdb, 0xf1, 0xbf, - 0xf8, 0xf4, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x71, 0x80, 0x01, 0xb4, 0xb0, 0x05, 0x00, 0x00, + // 596 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xb1,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x3d, + 0x62, 0xf7, 0xbb, 0xc0, 0xa2, 0xff, 0x93, 0x19, 0x95, 0x17, 0xa5, 0xe8, 0xeb, 0x0c, 0x42, 0x1f, + 0x58, 0xfb, 0xff, 0xf8, 0x5f, 0x7c, 0xfa, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x89, 0x65, 0x89, 0x0f, + 0xb0, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -342,11 +343,11 @@ type MsgClient interface { RegisterCounterpartyAddress(ctx context.Context, in *MsgRegisterCounterpartyAddress, opts ...grpc.CallOption) (*MsgRegisterCounterpartyAddressResponse, error) // PayPacketFee defines a rpc handler method for MsgPayPacketFee // PayPacketFee 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. + // incentivize the relaying of the packet at the next sequence PayPacketFee(ctx context.Context, in *MsgPayPacketFee, opts ...grpc.CallOption) (*MsgPayPacketFeeResponse, error) - // PayPacketFee defines a rpc handler method for MsgPayPacketFee - // PayPacketFee 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. + // PayPacketFeeAsync defines a rpc handler method for MsgPayPacketFeeAsync + // PayPacketFeeAsync is an open callback that may be called by any module/user that wishes to escrow funds in order to + // incentivize the relaying of a known packet PayPacketFeeAsync(ctx context.Context, in *MsgPayPacketFeeAsync, opts ...grpc.CallOption) (*MsgPayPacketFeeAsyncResponse, error) } @@ -395,11 +396,11 @@ type MsgServer interface { RegisterCounterpartyAddress(context.Context, *MsgRegisterCounterpartyAddress) (*MsgRegisterCounterpartyAddressResponse, error) // PayPacketFee defines a rpc handler method for MsgPayPacketFee // PayPacketFee 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. + // incentivize the relaying of the packet at the next sequence PayPacketFee(context.Context, *MsgPayPacketFee) (*MsgPayPacketFeeResponse, error) - // PayPacketFee defines a rpc handler method for MsgPayPacketFee - // PayPacketFee 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. + // PayPacketFeeAsync defines a rpc handler method for MsgPayPacketFeeAsync + // PayPacketFeeAsync is an open callback that may be called by any module/user that wishes to escrow funds in order to + // incentivize the relaying of a known packet PayPacketFeeAsync(context.Context, *MsgPayPacketFeeAsync) (*MsgPayPacketFeeAsyncResponse, error) } diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index 57561aa3100..609672e40f7 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -17,7 +17,6 @@ message Fee { // Fee associated with a packet_id message IdentifiedPacketFee { - ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; - Fee fee = 2; - string refund_account = 3 [(gogoproto.moretags) = "yaml:\"refund_account\""]; + ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; + Fee fee = 2; } diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 2623aa68c58..8a4199f2a7d 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -17,11 +17,11 @@ service Msg { rpc RegisterCounterpartyAddress(MsgRegisterCounterpartyAddress) returns (MsgRegisterCounterpartyAddressResponse); // PayPacketFee defines a rpc handler method for MsgPayPacketFee // PayPacketFee 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. + // incentivize the relaying of the packet at the next sequence rpc PayPacketFee(MsgPayPacketFee) returns (MsgPayPacketFeeResponse); - // PayPacketFee defines a rpc handler method for MsgPayPacketFee - // PayPacketFee 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. + // PayPacketFeeAsync defines a rpc handler method for MsgPayPacketFeeAsync + // PayPacketFeeAsync is an open callback that may be called by any module/user that wishes to escrow funds in order to + // incentivize the relaying of a known packet rpc PayPacketFeeAsync(MsgPayPacketFeeAsync) returns (MsgPayPacketFeeAsyncResponse); } @@ -48,7 +48,7 @@ message MsgPayPacketFee { // source channel unique identifier string source_channel_id = 3 [(gogoproto.moretags) = "yaml:\"source_channel_id\""]; // account address to refund fee if necessary - string refund_account = 4 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; + string refund_account = 4 [(gogoproto.moretags) = "yaml:\"refund_account\""]; repeated string relayers = 5; } @@ -65,7 +65,7 @@ message MsgPayPacketFeeAsync { // source channel unique identifier ibc.core.channel.v1.PacketId packet_id = 2 [(gogoproto.moretags) = "yaml:\"packet_id\""]; // account address to refund fee if necessary - string refund_account = 3 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; + string refund_account = 3 [(gogoproto.moretags) = "yaml:\"refund_account\""]; repeated string relayers = 4; } From f41e52042f521b3819242463eee05bf8a3be8c36 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 6 Oct 2021 17:35:20 +0200 Subject: [PATCH 05/50] feat: adding PayFee & PayFeeTimeout & escrow_test --- modules/apps/29-fee/keeper/escrow.go | 92 ++++++++++++++++++- modules/apps/29-fee/keeper/escrow_test.go | 51 ++++++++++ modules/apps/29-fee/keeper/keeper.go | 8 +- modules/apps/29-fee/keeper/msg_server.go | 4 +- modules/apps/29-fee/keeper/msg_server_test.go | 1 + modules/apps/29-fee/types/errors.go | 1 + modules/apps/29-fee/types/expected_keepers.go | 3 +- modules/apps/29-fee/types/keys.go | 2 +- 8 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 modules/apps/29-fee/keeper/escrow_test.go create mode 100644 modules/apps/29-fee/keeper/msg_server_test.go diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 23183b220fe..6ea742bf4df 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -10,7 +10,8 @@ import ( channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) -func (k Keeper) escrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.Fee, packetID channeltypes.PacketId) error { +// TODO: add optional relayers arr +func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.Fee, packetID channeltypes.PacketId) error { // check if the refund account exists hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) if hasRefundAcc == nil { @@ -25,7 +26,7 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t for _, f := range fees { hasBalance := k.bankKeeper.HasBalance(ctx, refundAcc, f) if !hasBalance { - return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("", refundAcc.String())) + return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("%s", refundAcc.String())) } } @@ -37,12 +38,93 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t } // Store fee in state for reference later - // //packet// -> Fee (timeout, ack, onrecv) + // feeInEscrow///packet// -> Fee (timeout, ack, onrecv) k.SetFeeInEscrow(ctx, fee, refundAcc.String(), packetID.ChannelId, packetID.Sequence) return nil } -//TODO: implement -func (k Keeper) PayFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.Fee, packetID channeltypes.PacketId) error { +func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { + // check if there is a Fee in escrow for the given packetId + feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + if !hasFee { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + + // get module accAddr + feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) + + // send ack fee to forward relayer + if feeInEscrow.AckFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + feeInEscrow.AckFee = nil + k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + } + + // send ack fee to forward relayer + if feeInEscrow.ReceiveFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + feeInEscrow.ReceiveFee = nil + k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + } + + // refund timeout fee to refundAddr + if feeInEscrow.TimeoutFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + // set fee as an empty struct (if we reach this point Fee is paid in full) + k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + } + + return nil +} + +func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { + // check if there is a Fee in escrow for the given packetId + feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + if !hasFee { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + + // get module accAddr + feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) + + // send ack fee to forward relayer + if feeInEscrow.AckFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + feeInEscrow.AckFee = nil + k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + } + + // send ack fee to forward relayer + if feeInEscrow.ReceiveFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + feeInEscrow.ReceiveFee = nil + k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + } + + // refund timeout fee to refundAddr + if feeInEscrow.TimeoutFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + } + // set fee as an empty struct (if we reach this point Fee is paid in full) + k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + } + return nil } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go new file mode 100644 index 00000000000..04bcd33ca1e --- /dev/null +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -0,0 +1,51 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" +) + +func (suite *KeeperTestSuite) TestEscrowPacketFee() { + var ( + err error + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", func() {}, true, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + // setup + refundAcc := suite.chainA.SenderAccount.GetAddress() + ackFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} + recieveFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} + timeoutFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} + fee := types.Fee{ackFee, recieveFee, timeoutFee} + packetId := channeltypes.PacketId{ChannelId: "channel-0", PortId: "fee", Sequence: uint64(1)} + + tc.malleate() // explicitly change fields in channel and testChannel + + // escrow the packet fee + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + + }) + } +} diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index c37dbe7c907..8f6b9c76b0d 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -11,8 +11,6 @@ import ( "github.com/cosmos/ibc-go/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - host "github.com/cosmos/ibc-go/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/modules/core/exported" ) @@ -77,11 +75,7 @@ func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) ( return k.channelKeeper.GetNextSequenceSend(ctx, portID, channelID) } -// GetFeeAccount returns the ICS29 - fee ModuleAccount -func (k Keeper) GetFeeAccount(ctx sdk.Context) authtypes.ModuleAccountI { - return k.authKeeper.GetModuleAccount(ctx, types.ModuleName) -} - +// GetFeeAccount returns the ICS29 - fee ModuleAccount address func (k Keeper) GetFeeModuleAddress() sdk.AccAddress { return k.authKeeper.GetModuleAddress(types.ModuleName) } diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index ca557bc70fe..9385d14dab8 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -49,7 +49,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) return &types.MsgPayPacketFeeResponse{}, err } - err = k.escrowPacketFee(ctx, refundAccAddr, *msg.Fee, packetId) + err = k.EscrowPacketFee(ctx, refundAccAddr, *msg.Fee, packetId) if err != nil { return nil, err } @@ -68,7 +68,7 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket return &types.MsgPayPacketFeeAsyncResponse{}, err } - err = k.escrowPacketFee(ctx, refundAccAddr, *msg.Fee, *msg.PacketId) + err = k.EscrowPacketFee(ctx, refundAccAddr, *msg.Fee, *msg.PacketId) if err != nil { return nil, err } 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..9429264902a --- /dev/null +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -0,0 +1 @@ +package keeper_test diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index fcd7b3d3594..a01008c2d49 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -9,4 +9,5 @@ var ( ErrInvalidVersion = sdkerrors.Register(ModuleName, 1, "invalid ICS29 middleware version") ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 2, "No account found for given refund address") ErrBalanceNotFound = sdkerrors.Register(ModuleName, 3, "Balance not found for given account address") + ErrFeeNotFound = sdkerrors.Register(ModuleName, 4, "There is no fee escrowed for the given packetId") ) diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index e38832f4952..33edb1c01ce 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -11,7 +11,6 @@ import ( // AccountKeeper defines the contract required for account APIs. type AccountKeeper interface { GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI GetAccount(sdk.Context, sdk.AccAddress) types.AccountI } @@ -31,6 +30,6 @@ type PortKeeper interface { // BankKeeper defines the expected bank keeper type BankKeeper interface { HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool - SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error } diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 23cca52ac0b..156d5e32f26 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -43,5 +43,5 @@ func KeyRelayerAddress(address string) []byte { // KeyFeeInEscrow returns the key for escrowed fees func KeyFeeInEscrow(account, channelId string, sequenceId uint64) []byte { - return []byte(fmt.Sprintf("%s/%s/%s/packet/%s", FeeInEscrowPrefix, account, channelId, sequenceId)) + return []byte(fmt.Sprintf("%s/%s/%s/packet/%d", FeeInEscrowPrefix, account, channelId, sequenceId)) } From e4bd49aec309c3400e583b1461cd7b6757f37fd8 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 6 Oct 2021 18:16:27 +0200 Subject: [PATCH 06/50] test: adding happy path for EscrowPacketFee --- modules/apps/29-fee/keeper/escrow.go | 12 +++++++----- testing/simapp/app.go | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 6ea742bf4df..c7093e426be 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -30,11 +30,13 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t } } - // escrow each fee with account module - if err := k.bankKeeper.SendCoinsFromAccountToModule( - ctx, refundAcc, types.ModuleName, fees, - ); err != nil { - return err + for _, coin := range fees { + // escrow each fee with account module + if err := k.bankKeeper.SendCoinsFromAccountToModule( + ctx, refundAcc, types.ModuleName, sdk.Coins{coin}, + ); err != nil { + return err + } } // Store fee in state for reference later diff --git a/testing/simapp/app.go b/testing/simapp/app.go index dbd65bd4b2c..58b2a79006d 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -147,6 +147,7 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + ibcfeetypes.ModuleName: nil, } ) From ca7f4e24445fd68dca1668e84cebc3953ff33dd0 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 7 Oct 2021 13:25:55 +0200 Subject: [PATCH 07/50] fix: comments, error handling --- modules/apps/29-fee/keeper/escrow.go | 48 +++++++++++------------ modules/apps/29-fee/keeper/escrow_test.go | 2 +- modules/apps/29-fee/types/errors.go | 8 ++-- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index c7093e426be..71757bbbfd5 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -45,6 +45,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t return nil } +// PayFee pays the acknowledgement fee & recieve fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) @@ -59,36 +60,34 @@ func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye if feeInEscrow.AckFee != nil { err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.AckFee}) if err != nil { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.AckFee.Denom, feeInEscrow.AckFee.Amount)) } - feeInEscrow.AckFee = nil - k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) } // send ack fee to forward relayer if feeInEscrow.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.ReceiveFee}) if err != nil { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.ReceiveFee.Denom, feeInEscrow.ReceiveFee.Amount)) } - feeInEscrow.ReceiveFee = nil - k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) } // refund timeout fee to refundAddr if feeInEscrow.TimeoutFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.TimeoutFee}) if err != nil { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.TimeoutFee.Denom, feeInEscrow.TimeoutFee.Amount)) } - // set fee as an empty struct (if we reach this point Fee is paid in full) - k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) } + // set fee as an empty struct (if we reach this point Fee is paid in full) + k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + return nil } -func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { +// PayFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & recieve fee to the refund account associated with the Fee +func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) if !hasFee { @@ -98,35 +97,32 @@ func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, forwardRelayer, revers // get module accAddr feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) - // send ack fee to forward relayer + // refund the ack fee if feeInEscrow.AckFee != nil { err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) if err != nil { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.AckFee.Denom, feeInEscrow.AckFee.Amount)) } - feeInEscrow.AckFee = nil - k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) } - // send ack fee to forward relayer + // refund the recieve fee if feeInEscrow.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.ReceiveFee}) if err != nil { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.ReceiveFee.Denom, feeInEscrow.ReceiveFee.Amount)) } - feeInEscrow.ReceiveFee = nil - k.SetFeeInEscrow(ctx, feeInEscrow, refundAcc.String(), packetID.ChannelId, packetID.Sequence) } - // refund timeout fee to refundAddr + // pay the timeout fee to the reverse relayer if feeInEscrow.TimeoutFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.TimeoutFee}) if err != nil { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.TimeoutFee.Denom, feeInEscrow.TimeoutFee.Amount)) } - // set fee as an empty struct (if we reach this point Fee is paid in full) - k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) } + // set fee as an empty struct (if we reach this point Fee is paid in full) + k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + return nil } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 04bcd33ca1e..a864de890d1 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -35,7 +35,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { fee := types.Fee{ackFee, recieveFee, timeoutFee} packetId := channeltypes.PacketId{ChannelId: "channel-0", PortId: "fee", Sequence: uint64(1)} - tc.malleate() // explicitly change fields in channel and testChannel + tc.malleate() // escrow the packet fee err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index a01008c2d49..839aca42964 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -7,7 +7,9 @@ import ( // 29-fee sentinel errors var ( ErrInvalidVersion = sdkerrors.Register(ModuleName, 1, "invalid ICS29 middleware version") - ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 2, "No account found for given refund address") - ErrBalanceNotFound = sdkerrors.Register(ModuleName, 3, "Balance not found for given account address") - ErrFeeNotFound = sdkerrors.Register(ModuleName, 4, "There is no fee escrowed for the given packetId") + ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 2, "no account found for given refund address") + ErrBalanceNotFound = sdkerrors.Register(ModuleName, 3, "balance not found for given account address") + ErrFeeNotFound = sdkerrors.Register(ModuleName, 4, "there is no fee escrowed for the given packetId") + ErrPayingFee = sdkerrors.Register(ModuleName, 5, "error while paying fee") + ErrRefundingFee = sdkerrors.Register(ModuleName, 6, "error while refunding fee") ) From 6a5add720bd4cdc9b862f4cb28c6168d4ee5bdb3 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 7 Oct 2021 13:32:57 +0200 Subject: [PATCH 08/50] fix: comments & grammar --- modules/apps/29-fee/keeper/escrow.go | 14 +++++++------- modules/apps/29-fee/keeper/escrow_test.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 71757bbbfd5..89b461627bd 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -45,7 +45,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t return nil } -// PayFee pays the acknowledgement fee & recieve fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee +// PayFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) @@ -56,17 +56,17 @@ func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye // get module accAddr feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) - // send ack fee to forward relayer + // send ack fee to reverse relayer if feeInEscrow.AckFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.AckFee}) if err != nil { return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.AckFee.Denom, feeInEscrow.AckFee.Amount)) } } - // send ack fee to forward relayer + // send receive fee to forward relayer if feeInEscrow.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.ReceiveFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.ReceiveFee}) if err != nil { return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.ReceiveFee.Denom, feeInEscrow.ReceiveFee.Amount)) } @@ -86,7 +86,7 @@ func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye return nil } -// PayFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & recieve fee to the refund account associated with the Fee +// PayFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) @@ -105,7 +105,7 @@ func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.Acc } } - // refund the recieve fee + // refund the receive fee if feeInEscrow.ReceiveFee != nil { err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.ReceiveFee}) if err != nil { diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index a864de890d1..c74426b27c3 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -30,9 +30,9 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { // setup refundAcc := suite.chainA.SenderAccount.GetAddress() ackFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} - recieveFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} + receiveFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} timeoutFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} - fee := types.Fee{ackFee, recieveFee, timeoutFee} + fee := types.Fee{ackFee, receiveFee, timeoutFee} packetId := channeltypes.PacketId{ChannelId: "channel-0", PortId: "fee", Sequence: uint64(1)} tc.malleate() From 535e2c6a71f2fb198c21100f8727188c6f1b1ca6 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 8 Oct 2021 14:55:58 +0200 Subject: [PATCH 09/50] test: adding unhappy path for escrow --- modules/apps/29-fee/keeper/escrow.go | 2 + modules/apps/29-fee/keeper/escrow_test.go | 49 +++++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 89b461627bd..bb8a39e0e95 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -24,7 +24,9 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t // check if refundAcc has balance for each fee for _, f := range fees { + fmt.Print(f) hasBalance := k.bankKeeper.HasBalance(ctx, refundAcc, f) + fmt.Print(hasBalance) if !hasBalance { return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("%s", refundAcc.String())) } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index c74426b27c3..d2fc0497432 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -8,9 +8,17 @@ import ( func (suite *KeeperTestSuite) TestEscrowPacketFee() { var ( - err error + err error + refundAcc sdk.AccAddress + ackFee *sdk.Coin + receiveFee *sdk.Coin + timeoutFee *sdk.Coin ) + // refundAcc does not have balance for the following Coin + invalidCoin := &sdk.Coin{Denom: "cosmos", Amount: sdk.NewInt(8000000000)} + validChannelId := "channel-0" + testCases := []struct { name string malleate func() @@ -19,6 +27,27 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { { "success", func() {}, true, }, + { + "refundAcc does not exist", func() { + // this acc does nto exist on chainA + refundAcc = suite.chainB.SenderAccount.GetAddress() + }, false, + }, + { + "ackFee balance not found", func() { + ackFee = invalidCoin + }, false, + }, + { + "receive balance not found", func() { + receiveFee = invalidCoin + }, false, + }, + { + "timeout balance not found", func() { + timeoutFee = invalidCoin + }, false, + }, } for _, tc := range testCases { @@ -28,24 +57,28 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { suite.SetupTest() // reset // setup - refundAcc := suite.chainA.SenderAccount.GetAddress() - ackFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} - receiveFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} - timeoutFee := &sdk.Coin{Denom: "stake", Amount: sdk.NewInt(100)} - fee := types.Fee{ackFee, receiveFee, timeoutFee} - packetId := channeltypes.PacketId{ChannelId: "channel-0", PortId: "fee", Sequence: uint64(1)} + refundAcc = suite.chainA.SenderAccount.GetAddress() + validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + ackFee = validCoin + receiveFee = validCoin + timeoutFee = validCoin + packetId := channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} tc.malleate() + fee := types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) if tc.expPass { + feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + suite.Require().Equal(fee.AckFee, feeInEscrow.AckFee) + suite.Require().Equal(fee.ReceiveFee, feeInEscrow.ReceiveFee) + suite.Require().Equal(fee.TimeoutFee, feeInEscrow.TimeoutFee) suite.Require().NoError(err) } else { suite.Require().Error(err) } - }) } } From 5bd0e325b5dadd2a8741b3e824f4adb04e50227c Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 8 Oct 2021 16:05:49 +0200 Subject: [PATCH 10/50] tests(escrow): adding hasBalance check for module acc --- modules/apps/29-fee/keeper/escrow.go | 1 - modules/apps/29-fee/keeper/escrow_test.go | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index bb8a39e0e95..f102a893e82 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -26,7 +26,6 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t for _, f := range fees { fmt.Print(f) hasBalance := k.bankKeeper.HasBalance(ctx, refundAcc, f) - fmt.Print(hasBalance) if !hasBalance { return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("%s", refundAcc.String())) } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index d2fc0497432..5a92f25a43b 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -72,9 +72,13 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { if tc.expPass { feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + // check if the escrowed fee is set in state suite.Require().Equal(fee.AckFee, feeInEscrow.AckFee) suite.Require().Equal(fee.ReceiveFee, feeInEscrow.ReceiveFee) suite.Require().Equal(fee.TimeoutFee, feeInEscrow.TimeoutFee) + // check if the balance for the module account is correct and the fee is correctly escrowed + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}) + suite.Require().True(hasBalance) suite.Require().NoError(err) } else { suite.Require().Error(err) From 31fcee315f0f1d77ebf0ae109b4e3a473665ce9f Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 8 Oct 2021 18:39:58 +0200 Subject: [PATCH 11/50] test(PayFee): adding happy path for PayFee tests --- modules/apps/29-fee/keeper/escrow.go | 4 +- modules/apps/29-fee/keeper/escrow_test.go | 62 ++++++++++++++++++++++- modules/apps/29-fee/keeper/keeper.go | 19 +++++++ 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index f102a893e82..835525d0618 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -47,7 +47,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t } // PayFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee -func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { +func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) if !hasFee { @@ -88,7 +88,7 @@ func (k Keeper) payFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye } // PayFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee -func (k Keeper) payFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { +func (k Keeper) PayFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) if !hasFee { diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 5a92f25a43b..dc95f113c28 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -76,7 +76,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { suite.Require().Equal(fee.AckFee, feeInEscrow.AckFee) suite.Require().Equal(fee.ReceiveFee, feeInEscrow.ReceiveFee) suite.Require().Equal(fee.TimeoutFee, feeInEscrow.TimeoutFee) - // check if the balance for the module account is correct and the fee is correctly escrowed + // check if the fee is escrowed correctly hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}) suite.Require().True(hasBalance) suite.Require().NoError(err) @@ -86,3 +86,63 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { }) } } + +func (suite *KeeperTestSuite) TestPayFee() { + var ( + err error + refundAcc sdk.AccAddress + ackFee *sdk.Coin + receiveFee *sdk.Coin + timeoutFee *sdk.Coin + ) + + // refundAcc does not have balance for the following Coin + validChannelId := "channel-0" + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", func() {}, true, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + // setup + refundAcc = suite.chainA.SenderAccount.GetAddress() + validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + ackFee = validCoin + receiveFee = validCoin + timeoutFee = validCoin + packetId := channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} + fee := types.Fee{ackFee, receiveFee, timeoutFee} + + // escrow the packet fee & store the fee in state + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) + suite.Require().NoError(err) + + tc.malleate() + + err = suite.chainA.GetSimApp().IBCFeeKeeper.PayFee(suite.chainA.GetContext(), refundAcc, refundAcc, refundAcc, packetId) + + if tc.expPass { + suite.Require().NoError(err) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + // there should no longer be a fee in escrow for this packet + suite.Require().False(hasFeeInEscrow) + } else { + suite.Require().Error(err) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + // there should still be a fee in escrow for this packet + suite.Require().True(hasFeeInEscrow) + } + }) + } +} diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 8f6b9c76b0d..86a7a64fb9c 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -145,6 +145,25 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, account, channelId string, seque return fee, true } +// GetFeeInEscrow returns true if there is a Fee still to be escrowed for a given packet +func (k Keeper) HasFeeInEscrow(ctx sdk.Context, account, channelId string, sequenceId uint64) bool { + store := ctx.KVStore(k.storeKey) + key := types.KeyFeeInEscrow(account, channelId, sequenceId) + bz := store.Get(key) + if bz == nil { + return false + } + + fee := k.MustUnmarshalFee(bz) + + // if the returned Fee is empty return false + if (types.Fee{}) == fee { + return false + } + + return true +} + // MustMarshalFee attempts to encode a Fee object and returns the // raw encoded bytes. It panics on error. func (k Keeper) MustMarshalFee(fee types.Fee) []byte { From 487f78dda81bfdff2008bf9bf665a63fb9eb4fe5 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 8 Oct 2021 19:18:43 +0200 Subject: [PATCH 12/50] tests(PayFee, PayFeeTimeout): adding tests --- modules/apps/29-fee/keeper/escrow.go | 1 - modules/apps/29-fee/keeper/escrow_test.go | 98 +++++++++++++++++++++-- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 835525d0618..6d8e2812388 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -24,7 +24,6 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t // check if refundAcc has balance for each fee for _, f := range fees { - fmt.Print(f) hasBalance := k.bankKeeper.HasBalance(ctx, refundAcc, f) if !hasBalance { return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("%s", refundAcc.String())) diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index dc95f113c28..086e6e001a5 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -89,15 +89,19 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { func (suite *KeeperTestSuite) TestPayFee() { var ( - err error - refundAcc sdk.AccAddress - ackFee *sdk.Coin - receiveFee *sdk.Coin - timeoutFee *sdk.Coin + err error + ackFee *sdk.Coin + receiveFee *sdk.Coin + timeoutFee *sdk.Coin + packetId channeltypes.PacketId + reverseRelayer sdk.AccAddress + forwardRelayer sdk.AccAddress + refundAcc sdk.AccAddress ) // refundAcc does not have balance for the following Coin validChannelId := "channel-0" + validSeq := uint64(1) testCases := []struct { name string @@ -107,6 +111,12 @@ func (suite *KeeperTestSuite) TestPayFee() { { "success", func() {}, true, }, + { + "fee not found for packet", func() { + // setting packetId with an invalid sequence of 2 + packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + }, false, + }, } for _, tc := range testCases { @@ -117,11 +127,14 @@ func (suite *KeeperTestSuite) TestPayFee() { // setup refundAcc = suite.chainA.SenderAccount.GetAddress() + reverseRelayer = suite.chainA.SenderAccount.GetAddress() + forwardRelayer = suite.chainA.SenderAccount.GetAddress() + validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} ackFee = validCoin receiveFee = validCoin timeoutFee = validCoin - packetId := channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} + packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} fee := types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state @@ -130,7 +143,7 @@ func (suite *KeeperTestSuite) TestPayFee() { tc.malleate() - err = suite.chainA.GetSimApp().IBCFeeKeeper.PayFee(suite.chainA.GetContext(), refundAcc, refundAcc, refundAcc, packetId) + err = suite.chainA.GetSimApp().IBCFeeKeeper.PayFee(suite.chainA.GetContext(), refundAcc, forwardRelayer, reverseRelayer, packetId) if tc.expPass { suite.Require().NoError(err) @@ -139,7 +152,78 @@ func (suite *KeeperTestSuite) TestPayFee() { suite.Require().False(hasFeeInEscrow) } else { suite.Require().Error(err) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, 1) + // there should still be a fee in escrow for this packet + suite.Require().True(hasFeeInEscrow) + } + }) + } +} + +func (suite *KeeperTestSuite) TestPayTimeoutFee() { + var ( + err error + ackFee *sdk.Coin + receiveFee *sdk.Coin + timeoutFee *sdk.Coin + packetId channeltypes.PacketId + reverseRelayer sdk.AccAddress + refundAcc sdk.AccAddress + ) + + // refundAcc does not have balance for the following Coin + validChannelId := "channel-0" + validSeq := uint64(1) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", func() {}, true, + }, + { + "fee not found for packet", func() { + // setting packetId with an invalid sequence of 2 + packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + }, false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + // setup + refundAcc = suite.chainA.SenderAccount.GetAddress() + reverseRelayer = suite.chainA.SenderAccount.GetAddress() + + validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + ackFee = validCoin + receiveFee = validCoin + timeoutFee = validCoin + packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + fee := types.Fee{ackFee, receiveFee, timeoutFee} + + // escrow the packet fee & store the fee in state + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) + suite.Require().NoError(err) + + tc.malleate() + + err = suite.chainA.GetSimApp().IBCFeeKeeper.PayFeeTimeout(suite.chainA.GetContext(), refundAcc, reverseRelayer, packetId) + + if tc.expPass { + suite.Require().NoError(err) hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + // there should no longer be a fee in escrow for this packet + suite.Require().False(hasFeeInEscrow) + } else { + suite.Require().Error(err) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, 1) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) } From f25932f1cad76dc7c8eb1295cd570292ecd7e115 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 11 Oct 2021 12:12:03 +0200 Subject: [PATCH 13/50] fix: adding relayers back to IdentifiedPacket --- docs/ibc/proto-docs.md | 1 + modules/apps/29-fee/types/fee.pb.go | 108 ++++++++++++++++++------ proto/ibc/applications/fee/v1/fee.proto | 1 + 3 files changed, 84 insertions(+), 26 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 272bf622cf6..2587ecc6236 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -649,6 +649,7 @@ Fee associated with a packet_id | ----- | ---- | ----- | ----------- | | `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | | `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | +| `relayers` | [string](#string) | repeated | | diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 16dbe16fd38..6f563911a50 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -92,6 +92,7 @@ func (m *Fee) GetTimeoutFee() *types.Coin { type IdentifiedPacketFee struct { PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` + Relayers []string `protobuf:"bytes,3,rep,name=relayers,proto3" json:"relayers,omitempty"` } func (m *IdentifiedPacketFee) Reset() { *m = IdentifiedPacketFee{} } @@ -141,6 +142,13 @@ func (m *IdentifiedPacketFee) GetFee() *Fee { return nil } +func (m *IdentifiedPacketFee) GetRelayers() []string { + if m != nil { + return m.Relayers + } + return nil +} + func init() { proto.RegisterType((*Fee)(nil), "ibc.applications.fee.v1.Fee") proto.RegisterType((*IdentifiedPacketFee)(nil), "ibc.applications.fee.v1.IdentifiedPacketFee") @@ -149,32 +157,33 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 388 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4f, 0x4b, 0xfb, 0x40, - 0x10, 0x6d, 0x7e, 0x85, 0xfe, 0x74, 0x0b, 0x22, 0xb1, 0xf8, 0xa7, 0x68, 0xaa, 0x39, 0x79, 0xe9, - 0x2e, 0xa9, 0x27, 0x3d, 0x56, 0x08, 0x14, 0x3c, 0x94, 0x1c, 0xbd, 0x94, 0xcd, 0x66, 0x9a, 0x2e, - 0x4d, 0xb2, 0xa1, 0xbb, 0x0d, 0xf4, 0x5b, 0x78, 0xf3, 0x2b, 0x79, 0xec, 0xd1, 0x53, 0x91, 0xf6, - 0x1b, 0x14, 0xbc, 0xcb, 0x26, 0xab, 0xf6, 0x22, 0xe2, 0x69, 0x67, 0x76, 0xe6, 0xbd, 0x37, 0xbc, - 0x19, 0x74, 0xc5, 0x43, 0x46, 0x68, 0x9e, 0x27, 0x9c, 0x51, 0xc5, 0x45, 0x26, 0xc9, 0x18, 0x80, - 0x14, 0x9e, 0x7e, 0x70, 0x3e, 0x13, 0x4a, 0xd8, 0x27, 0x3c, 0x64, 0x78, 0xb7, 0x05, 0xeb, 0x5a, - 0xe1, 0xb5, 0x1d, 0x26, 0x64, 0x2a, 0x24, 0x09, 0xa9, 0xd4, 0x90, 0x10, 0x14, 0xf5, 0x08, 0x13, - 0x3c, 0xab, 0x80, 0xed, 0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, 0xfd, 0x87, 0x97, 0xb5, 0x63, 0x2d, - 0xd7, 0x8e, 0xf5, 0xb6, 0x76, 0xac, 0xa7, 0x8d, 0x53, 0x5b, 0x6e, 0x9c, 0xda, 0xeb, 0xc6, 0xa9, - 0x3d, 0xf6, 0x62, 0xae, 0x26, 0xf3, 0x10, 0x33, 0x91, 0x12, 0x73, 0x0f, 0x3c, 0x64, 0xdd, 0x58, - 0x90, 0x54, 0x44, 0xf3, 0x04, 0xa4, 0xbe, 0x2e, 0x49, 0x7a, 0xb7, 0x5d, 0x7d, 0x58, 0x6a, 0x91, - 0x83, 0x0c, 0x1b, 0xe5, 0x9a, 0x6f, 0x3e, 0x02, 0x00, 0x00, 0xff, 0xff, 0x14, 0x78, 0xaf, 0x83, - 0x7d, 0x02, 0x00, 0x00, + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xc1, 0xaa, 0xda, 0x40, + 0x14, 0x35, 0x0d, 0x58, 0x1d, 0xa1, 0x94, 0x54, 0x5a, 0x2b, 0x6d, 0xb4, 0x59, 0xb9, 0x71, 0x86, + 0xd8, 0x55, 0xbb, 0xb4, 0x10, 0x10, 0xba, 0x90, 0x2c, 0xbb, 0x91, 0xc9, 0xe4, 0x1a, 0x07, 0x93, + 0x4c, 0xc8, 0x8c, 0x01, 0xff, 0xa2, 0xff, 0xd2, 0x9f, 0xe8, 0xd2, 0x65, 0x57, 0x52, 0xf4, 0x0f, + 0x84, 0xb7, 0x7f, 0x4c, 0x32, 0xcf, 0xe7, 0xe6, 0xf1, 0x78, 0xab, 0xb9, 0x77, 0xe6, 0x9e, 0x73, + 0x86, 0x73, 0x0f, 0xfa, 0xc2, 0x23, 0x46, 0x68, 0x51, 0xa4, 0x9c, 0x51, 0xc5, 0x45, 0x2e, 0xc9, + 0x1a, 0x80, 0x54, 0xbe, 0x3e, 0x70, 0x51, 0x0a, 0x25, 0x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 0xef, 0x5f, 0x8e, 0xa3, 0xb7, 0x8d, 0xda, 0x15, 0xe9, 0x85, 0x9d, 0xc2, 0xbc, 0x3b, 0x18, + 0xd9, 0x8f, 0x0e, 0x7c, 0xc2, 0x4f, 0x6c, 0x18, 0x07, 0x00, 0xa1, 0x1e, 0x74, 0x86, 0xa8, 0x53, + 0x42, 0x4a, 0xf7, 0x50, 0xca, 0x81, 0x3d, 0xb6, 0x27, 0xdd, 0xf0, 0xda, 0xcf, 0x7f, 0xfe, 0x3d, + 0xb9, 0xd6, 0xe1, 0xe4, 0x5a, 0xff, 0x4f, 0xae, 0xf5, 0xfb, 0xec, 0xb6, 0x0e, 0x67, 0xb7, 0xf5, + 0xef, 0xec, 0xb6, 0x7e, 0xcd, 0x12, 0xae, 0x36, 0xbb, 0x08, 0x33, 0x91, 0x11, 0x93, 0x15, 0x1e, + 0xb1, 0x69, 0x22, 0x48, 0x26, 0xe2, 0x5d, 0x0a, 0x52, 0x27, 0x4f, 0x92, 0xd9, 0xb7, 0xa9, 0x0e, + 0x9d, 0xda, 0x17, 0x20, 0xa3, 0x76, 0x1d, 0x81, 0xaf, 0xf7, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8b, + 0x8a, 0xda, 0xb4, 0x99, 0x02, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -256,6 +265,15 @@ func (m *IdentifiedPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Relayers) > 0 { + for iNdEx := len(m.Relayers) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Relayers[iNdEx]) + copy(dAtA[i:], m.Relayers[iNdEx]) + i = encodeVarintFee(dAtA, i, uint64(len(m.Relayers[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } if m.Fee != nil { { size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) @@ -329,6 +347,12 @@ func (m *IdentifiedPacketFee) Size() (n int) { l = m.Fee.Size() n += 1 + l + sovFee(uint64(l)) } + if len(m.Relayers) > 0 { + for _, s := range m.Relayers { + l = len(s) + n += 1 + l + sovFee(uint64(l)) + } + } return n } @@ -597,6 +621,38 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Relayers", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee + } + 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 ErrInvalidLengthFee + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Relayers = append(m.Relayers, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipFee(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index 609672e40f7..8023ac2403e 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -19,4 +19,5 @@ message Fee { message IdentifiedPacketFee { ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; Fee fee = 2; + repeated string relayers = 3; } From 38566bcf602ed88d112b0fd99a54b8d7a20ecfcc Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 11 Oct 2021 15:06:15 +0200 Subject: [PATCH 14/50] fix: removing refund acc from key --- modules/apps/29-fee/keeper/escrow.go | 8 ++++---- modules/apps/29-fee/keeper/keeper.go | 8 ++++---- modules/apps/29-fee/types/keys.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 6d8e2812388..8324a56be86 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -40,8 +40,8 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t } // Store fee in state for reference later - // feeInEscrow///packet// -> Fee (timeout, ack, onrecv) - k.SetFeeInEscrow(ctx, fee, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + // feeInEscrow//packet// -> Fee (timeout, ack, onrecv) + k.SetFeeInEscrow(ctx, fee, packetID.ChannelId, packetID.Sequence) return nil } @@ -81,7 +81,7 @@ func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye } // set fee as an empty struct (if we reach this point Fee is paid in full) - k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + k.SetFeeInEscrow(ctx, types.Fee{}, packetID.ChannelId, packetID.Sequence) return nil } @@ -122,7 +122,7 @@ func (k Keeper) PayFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.Acc } // set fee as an empty struct (if we reach this point Fee is paid in full) - k.SetFeeInEscrow(ctx, types.Fee{}, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + k.SetFeeInEscrow(ctx, types.Fee{}, packetID.ChannelId, packetID.Sequence) return nil } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 86a7a64fb9c..e357f11f326 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -125,16 +125,16 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) } // Stores a Fee for a given packet in state -func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.Fee, account, channelId string, sequenceId uint64) { +func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.Fee, channelId string, sequenceId uint64) { store := ctx.KVStore(k.storeKey) bz := k.MustMarshalFee(fee) - store.Set(types.KeyFeeInEscrow(account, channelId, sequenceId), bz) + store.Set(types.KeyFeeInEscrow(channelId, sequenceId), bz) } // Gets a Fee for a given packet func (k Keeper) GetFeeInEscrow(ctx sdk.Context, account, channelId string, sequenceId uint64) (types.Fee, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeyFeeInEscrow(account, channelId, sequenceId) + key := types.KeyFeeInEscrow(channelId, sequenceId) bz := store.Get(key) if bz == nil { return types.Fee{}, false @@ -148,7 +148,7 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, account, channelId string, seque // GetFeeInEscrow returns true if there is a Fee still to be escrowed for a given packet func (k Keeper) HasFeeInEscrow(ctx sdk.Context, account, channelId string, sequenceId uint64) bool { store := ctx.KVStore(k.storeKey) - key := types.KeyFeeInEscrow(account, channelId, sequenceId) + key := types.KeyFeeInEscrow(channelId, sequenceId) bz := store.Get(key) if bz == nil { return false diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 156d5e32f26..98c4d7b9978 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -42,6 +42,6 @@ func KeyRelayerAddress(address string) []byte { } // KeyFeeInEscrow returns the key for escrowed fees -func KeyFeeInEscrow(account, channelId string, sequenceId uint64) []byte { - return []byte(fmt.Sprintf("%s/%s/%s/packet/%d", FeeInEscrowPrefix, account, channelId, sequenceId)) +func KeyFeeInEscrow(channelId string, sequenceId uint64) []byte { + return []byte(fmt.Sprintf("%s/%s/packet/%d", FeeInEscrowPrefix, channelId, sequenceId)) } From dd0044b06c5985732eabe646de2dfb31afb796ae Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 11 Oct 2021 16:26:22 +0200 Subject: [PATCH 15/50] fix: storing IdentifiedPacketFee in state instead of Fee --- modules/apps/29-fee/keeper/escrow.go | 58 ++++++++++++----------- modules/apps/29-fee/keeper/escrow_test.go | 46 ++++++++++-------- modules/apps/29-fee/keeper/keeper.go | 18 +++---- modules/apps/29-fee/keeper/msg_server.go | 8 ++-- 4 files changed, 69 insertions(+), 61 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 8324a56be86..d2ce23eefa9 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -10,8 +10,8 @@ import ( channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) -// TODO: add optional relayers arr -func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee types.Fee, packetID channeltypes.PacketId) error { +// TODO: add logic for optional relayers arr +func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, identifiedFee types.IdentifiedPacketFee) error { // check if the refund account exists hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) if hasRefundAcc == nil { @@ -19,7 +19,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t } fees := sdk.Coins{ - *fee.AckFee, *fee.ReceiveFee, *fee.TimeoutFee, + *identifiedFee.Fee.AckFee, *identifiedFee.Fee.ReceiveFee, *identifiedFee.Fee.TimeoutFee, } // check if refundAcc has balance for each fee @@ -41,14 +41,14 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, fee t // Store fee in state for reference later // feeInEscrow//packet// -> Fee (timeout, ack, onrecv) - k.SetFeeInEscrow(ctx, fee, packetID.ChannelId, packetID.Sequence) + k.SetFeeInEscrow(ctx, identifiedFee) return nil } // PayFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee -func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { +func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId - feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID.ChannelId, packetID.Sequence) if !hasFee { return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) } @@ -57,39 +57,40 @@ func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // send ack fee to reverse relayer - if feeInEscrow.AckFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.AckFee}) + if feeInEscrow.Fee.AckFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.AckFee}) if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.AckFee.Denom, feeInEscrow.AckFee.Amount)) + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) } } // send receive fee to forward relayer - if feeInEscrow.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.ReceiveFee}) + if feeInEscrow.Fee.ReceiveFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.ReceiveFee.Denom, feeInEscrow.ReceiveFee.Amount)) + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) } } // refund timeout fee to refundAddr - if feeInEscrow.TimeoutFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.TimeoutFee}) + if feeInEscrow.Fee.TimeoutFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.TimeoutFee.Denom, feeInEscrow.TimeoutFee.Amount)) + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) } } // set fee as an empty struct (if we reach this point Fee is paid in full) - k.SetFeeInEscrow(ctx, types.Fee{}, packetID.ChannelId, packetID.Sequence) + identifiedPacket := types.IdentifiedPacketFee{PacketId: packetID, Fee: &types.Fee{}, Relayers: []string{}} + k.SetFeeInEscrow(ctx, identifiedPacket) return nil } // PayFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee -func (k Keeper) PayFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID channeltypes.PacketId) error { +func (k Keeper) PayFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId - feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, refundAcc.String(), packetID.ChannelId, packetID.Sequence) + feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID.ChannelId, packetID.Sequence) if !hasFee { return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) } @@ -98,31 +99,32 @@ func (k Keeper) PayFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.Acc feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // refund the ack fee - if feeInEscrow.AckFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.AckFee}) + if feeInEscrow.Fee.AckFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.AckFee}) if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.AckFee.Denom, feeInEscrow.AckFee.Amount)) + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) } } // refund the receive fee - if feeInEscrow.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.ReceiveFee}) + if feeInEscrow.Fee.ReceiveFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.ReceiveFee.Denom, feeInEscrow.ReceiveFee.Amount)) + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) } } // pay the timeout fee to the reverse relayer - if feeInEscrow.TimeoutFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.TimeoutFee}) + if feeInEscrow.Fee.TimeoutFee != nil { + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.TimeoutFee.Denom, feeInEscrow.TimeoutFee.Amount)) + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) } } // set fee as an empty struct (if we reach this point Fee is paid in full) - k.SetFeeInEscrow(ctx, types.Fee{}, packetID.ChannelId, packetID.Sequence) + identifiedPacket := types.IdentifiedPacketFee{PacketId: packetID, Fee: &types.Fee{}, Relayers: []string{}} + k.SetFeeInEscrow(ctx, identifiedPacket) return nil } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 086e6e001a5..7d0b00c1736 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -62,20 +62,21 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { ackFee = validCoin receiveFee = validCoin timeoutFee = validCoin - packetId := channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} + packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} tc.malleate() - fee := types.Fee{ackFee, receiveFee, timeoutFee} + fee := &types.Fee{ackFee, receiveFee, timeoutFee} + identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} // escrow the packet fee - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) if tc.expPass { - feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, packetId.Sequence) // check if the escrowed fee is set in state - suite.Require().Equal(fee.AckFee, feeInEscrow.AckFee) - suite.Require().Equal(fee.ReceiveFee, feeInEscrow.ReceiveFee) - suite.Require().Equal(fee.TimeoutFee, feeInEscrow.TimeoutFee) + suite.Require().Equal(fee.AckFee, feeInEscrow.Fee.AckFee) + suite.Require().Equal(fee.ReceiveFee, feeInEscrow.Fee.ReceiveFee) + suite.Require().Equal(fee.TimeoutFee, feeInEscrow.Fee.TimeoutFee) // check if the fee is escrowed correctly hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}) suite.Require().True(hasBalance) @@ -93,7 +94,7 @@ func (suite *KeeperTestSuite) TestPayFee() { ackFee *sdk.Coin receiveFee *sdk.Coin timeoutFee *sdk.Coin - packetId channeltypes.PacketId + packetId *channeltypes.PacketId reverseRelayer sdk.AccAddress forwardRelayer sdk.AccAddress refundAcc sdk.AccAddress @@ -114,7 +115,7 @@ func (suite *KeeperTestSuite) TestPayFee() { { "fee not found for packet", func() { // setting packetId with an invalid sequence of 2 - packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} }, false, }, } @@ -134,11 +135,13 @@ func (suite *KeeperTestSuite) TestPayFee() { ackFee = validCoin receiveFee = validCoin timeoutFee = validCoin - packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} - fee := types.Fee{ackFee, receiveFee, timeoutFee} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + fee := &types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) + identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) suite.Require().NoError(err) tc.malleate() @@ -147,12 +150,12 @@ func (suite *KeeperTestSuite) TestPayFee() { if tc.expPass { suite.Require().NoError(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, packetId.Sequence) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) } else { suite.Require().Error(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, 1) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, 1) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) } @@ -166,7 +169,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { ackFee *sdk.Coin receiveFee *sdk.Coin timeoutFee *sdk.Coin - packetId channeltypes.PacketId + packetId *channeltypes.PacketId reverseRelayer sdk.AccAddress refundAcc sdk.AccAddress ) @@ -186,7 +189,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { { "fee not found for packet", func() { // setting packetId with an invalid sequence of 2 - packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} }, false, }, } @@ -205,11 +208,12 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { ackFee = validCoin receiveFee = validCoin timeoutFee = validCoin - packetId = channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} - fee := types.Fee{ackFee, receiveFee, timeoutFee} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + fee := &types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, fee, packetId) + identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) suite.Require().NoError(err) tc.malleate() @@ -218,12 +222,12 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { if tc.expPass { suite.Require().NoError(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, packetId.Sequence) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, packetId.Sequence) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) } else { suite.Require().Error(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), refundAcc.String(), packetId.ChannelId, 1) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, 1) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index e357f11f326..c0f8efb54f4 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -125,19 +125,19 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) } // Stores a Fee for a given packet in state -func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.Fee, channelId string, sequenceId uint64) { +func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.IdentifiedPacketFee) { store := ctx.KVStore(k.storeKey) bz := k.MustMarshalFee(fee) - store.Set(types.KeyFeeInEscrow(channelId, sequenceId), bz) + store.Set(types.KeyFeeInEscrow(fee.PacketId.ChannelId, fee.PacketId.Sequence), bz) } // Gets a Fee for a given packet -func (k Keeper) GetFeeInEscrow(ctx sdk.Context, account, channelId string, sequenceId uint64) (types.Fee, bool) { +func (k Keeper) GetFeeInEscrow(ctx sdk.Context, channelId string, sequenceId uint64) (types.IdentifiedPacketFee, bool) { store := ctx.KVStore(k.storeKey) key := types.KeyFeeInEscrow(channelId, sequenceId) bz := store.Get(key) if bz == nil { - return types.Fee{}, false + return types.IdentifiedPacketFee{}, false } fee := k.MustUnmarshalFee(bz) @@ -146,7 +146,7 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, account, channelId string, seque } // GetFeeInEscrow returns true if there is a Fee still to be escrowed for a given packet -func (k Keeper) HasFeeInEscrow(ctx sdk.Context, account, channelId string, sequenceId uint64) bool { +func (k Keeper) HasFeeInEscrow(ctx sdk.Context, channelId string, sequenceId uint64) bool { store := ctx.KVStore(k.storeKey) key := types.KeyFeeInEscrow(channelId, sequenceId) bz := store.Get(key) @@ -157,7 +157,7 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, account, channelId string, seque fee := k.MustUnmarshalFee(bz) // if the returned Fee is empty return false - if (types.Fee{}) == fee { + if (types.Fee{}) == *fee.Fee { return false } @@ -166,14 +166,14 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, account, channelId string, seque // MustMarshalFee attempts to encode a Fee object and returns the // raw encoded bytes. It panics on error. -func (k Keeper) MustMarshalFee(fee types.Fee) []byte { +func (k Keeper) MustMarshalFee(fee types.IdentifiedPacketFee) []byte { return k.cdc.MustMarshal(&fee) } // MustUnmarshalFee attempts to decode and return a Fee object from // raw encoded bytes. It panics on error. -func (k Keeper) MustUnmarshalFee(bz []byte) types.Fee { - var fee types.Fee +func (k Keeper) MustUnmarshalFee(bz []byte) types.IdentifiedPacketFee { + var fee types.IdentifiedPacketFee k.cdc.MustUnmarshal(bz, &fee) return fee } diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 9385d14dab8..49653f6f23a 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -38,7 +38,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) return nil, channeltypes.ErrSequenceSendNotFound } - packetId := channeltypes.PacketId{ + packetId := &channeltypes.PacketId{ PortId: msg.SourcePortId, ChannelId: msg.SourceChannelId, Sequence: sequence, @@ -49,7 +49,8 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) return &types.MsgPayPacketFeeResponse{}, err } - err = k.EscrowPacketFee(ctx, refundAccAddr, *msg.Fee, packetId) + identifiedPacket := types.IdentifiedPacketFee{PacketId: packetId, Fee: msg.Fee, Relayers: msg.Relayers} + err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket) if err != nil { return nil, err } @@ -68,7 +69,8 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket return &types.MsgPayPacketFeeAsyncResponse{}, err } - err = k.EscrowPacketFee(ctx, refundAccAddr, *msg.Fee, *msg.PacketId) + identifiedPacket := types.IdentifiedPacketFee{PacketId: msg.PacketId, Fee: msg.Fee, Relayers: msg.Relayers} + err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket) if err != nil { return nil, err } From 5b4a395d38b36bfbe62b78936d8bcc0c8ab738fa Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 11 Oct 2021 17:20:23 +0200 Subject: [PATCH 16/50] feat: adding msg_server test for registerCPAddr, wiring for codec + stubs for sdk.Msg interface --- modules/apps/29-fee/keeper/keeper.go | 4 +- modules/apps/29-fee/keeper/msg_server.go | 7 ++- modules/apps/29-fee/keeper/msg_server_test.go | 44 ++++++++++++++++ modules/apps/29-fee/module.go | 4 +- modules/apps/29-fee/types/codec.go | 36 +++++++++++-- modules/apps/29-fee/types/msgs.go | 51 +++++++++++++++++++ 6 files changed, 137 insertions(+), 9 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index c0f8efb54f4..4f5930e9d36 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -107,9 +107,9 @@ func (k Keeper) IsFeeEnabled(ctx sdk.Context, portID, channelID string) bool { // 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 string, counterpartyAddress sdk.AccAddress) { store := ctx.KVStore(k.storeKey) - store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress)) + store.Set(types.KeyRelayerAddress(address), counterpartyAddress) } // GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 49653f6f23a..d3ab73c1e2c 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -18,8 +18,13 @@ var _ types.MsgServer = Keeper{} func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + counterpartyAddress, err := sdk.AccAddressFromBech32(msg.CounterpartyAddress) + if err != nil { + return &types.MsgRegisterCounterpartyAddressResponse{}, err + } + k.SetCounterpartyAddress( - ctx, msg.Address, msg.CounterpartyAddress, + ctx, msg.Address, counterpartyAddress, ) 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 9429264902a..fb3ca4f0e5f 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -1 +1,45 @@ package keeper_test + +import ( + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" +) + +func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { + var ( + addr string + addr2 string + ) + + testCases := []struct { + name string + expPass bool + malleate func() + }{ + { + "CounterpartyAddress registered", + true, + func() {}, + }, + } + + for _, tc := range testCases { + suite.SetupTest() + ctx := suite.chainA.GetContext() + + addr = suite.chainA.SenderAccount.GetAddress().String() + addr2 = suite.chainB.SenderAccount.GetAddress().String() + msg := types.NewMsgRegisterCounterpartyAddress(addr, addr2) + tc.malleate() + + _, 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()) + suite.Require().Equal(addr2, counterpartyAddress.String()) + } else { + suite.Require().Error(err) + } + } +} diff --git a/modules/apps/29-fee/module.go b/modules/apps/29-fee/module.go index 6e73a3b9b08..61e39846584 100644 --- a/modules/apps/29-fee/module.go +++ b/modules/apps/29-fee/module.go @@ -45,7 +45,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers module concrete types into protobuf Any. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - // types.RegisterInterfaces(registry) + types.RegisterInterfaces(registry) } // DefaultGenesis returns default genesis state as raw bytes for the ibc @@ -120,7 +120,7 @@ func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { - // types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) // types.RegisterQueryServer(cfg.QueryServer(), am.keeper) } diff --git a/modules/apps/29-fee/types/codec.go b/modules/apps/29-fee/types/codec.go index c9dac580ea5..b0561bed263 100644 --- a/modules/apps/29-fee/types/codec.go +++ b/modules/apps/29-fee/types/codec.go @@ -1,16 +1,44 @@ package types -/* import ( + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) +// RegisterLegacyAminoCodec registers the necessary x/ibc 29-fee interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgRegisterCounterpartyAddress{}, "cosmos-sdk/MsgRegisterCounterpartyAddress", nil) + cdc.RegisterConcrete(&MsgPayPacketFee{}, "cosmos-sdk/MsgPayPacketFee", nil) + cdc.RegisterConcrete(&MsgPayPacketFeeAsync{}, "cosmos-sdk/MsgPayPacketFeeAsync", nil) +} + // RegisterInterfaces register the 29-fee module interfaces to protobuf // Any. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { - // registry.RegisterImplementations((*sdk.Msg)(nil), &Msg{}) - + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterCounterpartyAddress{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgPayPacketFee{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgPayPacketFeeAsync{}) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -*/ + +var ( + amino = codec.NewLegacyAmino() + + // ModuleCdc references the global x/ibc-transfer module codec. Note, the codec + // should ONLY be used in certain instances of tests and for JSON encoding. + // + // The actual codec used for serialization should be provided to x/ibc transfer and + // defined at the application level. + ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + + // AminoCdc is a amino codec created to support amino json compatible msgs. + AminoCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + amino.Seal() +} diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 7e330d547bb..93af1075bb5 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -3,11 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) // msg types const ( TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress" + TypePayPacketFee = "payPacketFee" ) // NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress @@ -41,3 +43,52 @@ func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress { } return []sdk.AccAddress{signer} } + +// NewMsgPayPacketFee creates a new instance of MsgPayPacketFee +func NewMsgPayPacketFee(fee *Fee, sourcePortId, sourceChannelId, refundAccount string, relayers []string) *MsgPayPacketFee { + return &MsgPayPacketFee{ + Fee: fee, + SourcePortId: sourcePortId, + SourceChannelId: sourceChannelId, + RefundAccount: refundAccount, + Relayers: relayers, + } +} + +// ValidateBasic performs a basic check of the MsgPayPacketFee fields +func (msg MsgPayPacketFee) ValidateBasic() error { + return nil +} + +// GetSigners implements sdk.Msg +func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.RefundAccount) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +// NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee +func NewMsgPayPacketAsync(fee *Fee, packetId *channeltypes.PacketId, refundAccount string, relayers []string) *MsgPayPacketFeeAsync { + return &MsgPayPacketFeeAsync{ + Fee: fee, + PacketId: packetId, + RefundAccount: refundAccount, + Relayers: relayers, + } +} + +// ValidateBasic performs a basic check of the MsgPayPacketFeeAsync fields +func (msg MsgPayPacketFeeAsync) ValidateBasic() error { + return nil +} + +// GetSigners implements sdk.Msg +func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.RefundAccount) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} From c9af582851a2ffc017bca235e7b036e25e573ce7 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 12 Oct 2021 09:46:18 +0200 Subject: [PATCH 17/50] test: adding msg_server test for PayPacketFee --- modules/apps/29-fee/keeper/keeper_test.go | 37 +++++++++++++++-- modules/apps/29-fee/keeper/msg_server_test.go | 41 ++++++++++++++++++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index f227c98171c..ab4ce879a29 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -5,6 +5,9 @@ import ( "github.com/stretchr/testify/suite" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/testing" ) @@ -16,14 +19,42 @@ type KeeperTestSuite struct { // testing chains used for convenience and readability chainA *ibctesting.TestChain chainB *ibctesting.TestChain - chainC *ibctesting.TestChain + + path *ibctesting.Path } func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + + path := ibctesting.NewPath(suite.chainA, suite.chainB) + feeTransferVersion := channeltypes.MergeChannelVersions(types.Version, transfertypes.Version) + path.EndpointA.ChannelConfig.Version = feeTransferVersion + path.EndpointB.ChannelConfig.Version = feeTransferVersion + path.EndpointA.ChannelConfig.PortID = transfertypes.PortID + path.EndpointB.ChannelConfig.PortID = transfertypes.PortID + suite.path = path +} + +func SetupFeePath(path *ibctesting.Path) error { + if err := path.EndpointA.ChanOpenInit(); err != nil { + return err + } + + if err := path.EndpointB.ChanOpenTry(); err != nil { + return err + } + + if err := path.EndpointA.ChanOpenAck(); err != nil { + return err + } + + if err := path.EndpointB.ChanOpenConfirm(); err != nil { + return err + } + + return nil } func TestKeeperTestSuite(t *testing.T) { diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index fb3ca4f0e5f..16800d06890 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" ) @@ -16,7 +17,7 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { malleate func() }{ { - "CounterpartyAddress registered", + "success", true, func() {}, }, @@ -43,3 +44,41 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { } } } + +func (suite *KeeperTestSuite) TestPayPacketFee() { + testCases := []struct { + name string + expPass bool + malleate func() + }{ + { + "success", + true, + func() {}, + }, + } + + for _, tc := range testCases { + suite.SetupTest() + suite.coordinator.SetupConnections(suite.path) + SetupFeePath(suite.path) + refundAcc := suite.chainA.SenderAccount.GetAddress() + validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + ackFee := validCoin + receiveFee := validCoin + timeoutFee := validCoin + + fee := &types.Fee{ackFee, receiveFee, timeoutFee} + msg := types.NewMsgPayPacketFee(fee, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, refundAcc.String(), []string{}) + + tc.malleate() + _, err := suite.chainA.SendMsgs(msg) + suite.Require().NoError(err) // message committed + + if tc.expPass { + suite.Require().NoError(err) // message committed + } else { + suite.Require().Error(err) + } + } +} From d3251463b1ee797cbb7354809046a34019c5adbb Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 12 Oct 2021 12:56:47 +0200 Subject: [PATCH 18/50] test: adding PayPacketFeeAsync msg_server test --- modules/apps/29-fee/keeper/msg_server_test.go | 46 ++++++++++++++++--- modules/apps/29-fee/types/msgs.go | 2 +- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 16800d06890..1667ef07378 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 ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { @@ -64,16 +65,49 @@ func (suite *KeeperTestSuite) TestPayPacketFee() { SetupFeePath(suite.path) refundAcc := suite.chainA.SenderAccount.GetAddress() validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} - ackFee := validCoin - receiveFee := validCoin - timeoutFee := validCoin + channelID := suite.path.EndpointA.ChannelID + fee := &types.Fee{validCoin, validCoin, validCoin} + msg := types.NewMsgPayPacketFee(fee, suite.path.EndpointA.ChannelConfig.PortID, channelID, refundAcc.String(), []string{}) - fee := &types.Fee{ackFee, receiveFee, timeoutFee} - msg := types.NewMsgPayPacketFee(fee, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, refundAcc.String(), []string{}) + tc.malleate() + _, err := suite.chainA.SendMsgs(msg) + + if tc.expPass { + suite.Require().NoError(err) // message committed + } else { + suite.Require().Error(err) + } + } +} + +func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { + testCases := []struct { + name string + expPass bool + malleate func() + }{ + { + "success", + true, + func() {}, + }, + } + + for _, tc := range testCases { + suite.SetupTest() + suite.coordinator.SetupConnections(suite.path) + SetupFeePath(suite.path) + refundAcc := suite.chainA.SenderAccount.GetAddress() + validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + channelID := suite.path.EndpointA.ChannelID + fee := &types.Fee{validCoin, validCoin, validCoin} + ctxA := suite.chainA.GetContext() + seq, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(ctxA, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) + packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: suite.path.EndpointA.ChannelConfig.PortID, Sequence: seq} + msg := types.NewMsgPayPacketFeeAsync(fee, packetId, refundAcc.String(), []string{}) tc.malleate() _, err := suite.chainA.SendMsgs(msg) - suite.Require().NoError(err) // message committed if tc.expPass { suite.Require().NoError(err) // message committed diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 93af1075bb5..49df3ec53fc 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -70,7 +70,7 @@ func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress { } // NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee -func NewMsgPayPacketAsync(fee *Fee, packetId *channeltypes.PacketId, refundAccount string, relayers []string) *MsgPayPacketFeeAsync { +func NewMsgPayPacketFeeAsync(fee *Fee, packetId *channeltypes.PacketId, refundAccount string, relayers []string) *MsgPayPacketFeeAsync { return &MsgPayPacketFeeAsync{ Fee: fee, PacketId: packetId, From ea9b30bb4330171c3adfe49d5af185ce37fe9426 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 13 Oct 2021 09:41:46 +0200 Subject: [PATCH 19/50] chore: updating PayFee -> DistributeFee & minor nits --- docs/ibc/proto-docs.md | 8 ++++---- modules/apps/29-fee/keeper/escrow.go | 10 +++++----- modules/apps/29-fee/keeper/escrow_test.go | 4 ++-- modules/apps/29-fee/types/tx.pb.go | 8 ++++---- proto/ibc/applications/fee/v1/tx.proto | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 2587ecc6236..f4a5cff5d14 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -889,7 +889,7 @@ Query provides defines the gRPC querier service. ### MsgPayPacketFee -MsgEscrowPacketFee defines the request type EscrowPacketFee RPC +MsgPayPacketFee defines the request type EscrowPacketFee RPC | Field | Type | Label | Description | @@ -908,7 +908,7 @@ MsgEscrowPacketFee defines the request type EscrowPacketFee RPC ### MsgPayPacketFeeAsync -MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC | Field | Type | Label | Description | @@ -926,7 +926,7 @@ MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC ### MsgPayPacketFeeAsyncResponse -MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync @@ -936,7 +936,7 @@ MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFe ### MsgPayPacketFeeResponse -MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee +MsgPayPacketFeeResponse defines the response type for Msg/EscrowPacketFee diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index d2ce23eefa9..3f244684835 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -10,7 +10,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) -// TODO: add logic for optional relayers arr +// EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, identifiedFee types.IdentifiedPacketFee) error { // check if the refund account exists hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) @@ -45,8 +45,8 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, ident return nil } -// PayFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee -func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { +// DistributeFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee +func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID.ChannelId, packetID.Sequence) if !hasFee { @@ -87,8 +87,8 @@ func (k Keeper) PayFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelaye return nil } -// PayFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee -func (k Keeper) PayFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { +// DistributeFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee +func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID.ChannelId, packetID.Sequence) if !hasFee { diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 7d0b00c1736..5fe24869660 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -146,7 +146,7 @@ func (suite *KeeperTestSuite) TestPayFee() { tc.malleate() - err = suite.chainA.GetSimApp().IBCFeeKeeper.PayFee(suite.chainA.GetContext(), refundAcc, forwardRelayer, reverseRelayer, packetId) + err = suite.chainA.GetSimApp().IBCFeeKeeper.DistributeFee(suite.chainA.GetContext(), refundAcc, forwardRelayer, reverseRelayer, packetId) if tc.expPass { suite.Require().NoError(err) @@ -218,7 +218,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { tc.malleate() - err = suite.chainA.GetSimApp().IBCFeeKeeper.PayFeeTimeout(suite.chainA.GetContext(), refundAcc, reverseRelayer, packetId) + err = suite.chainA.GetSimApp().IBCFeeKeeper.DistributeFeeTimeout(suite.chainA.GetContext(), refundAcc, reverseRelayer, packetId) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 2f2f6313785..6a528ff48dc 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -107,7 +107,7 @@ func (m *MsgRegisterCounterpartyAddressResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterCounterpartyAddressResponse proto.InternalMessageInfo -// MsgEscrowPacketFee defines the request type EscrowPacketFee RPC +// MsgPayPacketFee defines the request type EscrowPacketFee RPC type MsgPayPacketFee struct { Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` // source channel port identifier @@ -152,7 +152,7 @@ func (m *MsgPayPacketFee) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFee proto.InternalMessageInfo -// MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee +// MsgPayPacketFeeResponse defines the response type for Msg/EscrowPacketFee type MsgPayPacketFeeResponse struct { } @@ -189,7 +189,7 @@ func (m *MsgPayPacketFeeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo -// MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +// MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC type MsgPayPacketFeeAsync struct { // source channel port identifier Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` @@ -233,7 +233,7 @@ func (m *MsgPayPacketFeeAsync) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFeeAsync proto.InternalMessageInfo -// MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +// MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync type MsgPayPacketFeeAsyncResponse struct { } diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 8a4199f2a7d..9eb8536eb9a 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -37,7 +37,7 @@ message MsgRegisterCounterpartyAddress { // MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type message MsgRegisterCounterpartyAddressResponse {} -// MsgEscrowPacketFee defines the request type EscrowPacketFee RPC +// MsgPayPacketFee defines the request type EscrowPacketFee RPC message MsgPayPacketFee { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; @@ -52,10 +52,10 @@ message MsgPayPacketFee { repeated string relayers = 5; } -// MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee +// MsgPayPacketFeeResponse defines the response type for Msg/EscrowPacketFee message MsgPayPacketFeeResponse {} -// MsgEscrowPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +// MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC message MsgPayPacketFeeAsync { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; @@ -69,5 +69,5 @@ message MsgPayPacketFeeAsync { repeated string relayers = 4; } -// MsgEscrowPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +// MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync message MsgPayPacketFeeAsyncResponse {} From ac7584fd1aee085d3d7bc654e782bb8e7eb50bfb Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 13 Oct 2021 10:05:59 +0200 Subject: [PATCH 20/50] nit: removing unnecessary nil check --- modules/apps/29-fee/keeper/escrow.go | 48 +++++++++++----------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 3f244684835..47c1a669c1a 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -57,27 +57,21 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // send ack fee to reverse relayer - if feeInEscrow.Fee.AckFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.AckFee}) - if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) - } + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) } // send receive fee to forward relayer - if feeInEscrow.Fee.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) - if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) - } + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) } // refund timeout fee to refundAddr - if feeInEscrow.Fee.TimeoutFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) - if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) - } + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) } // set fee as an empty struct (if we reach this point Fee is paid in full) @@ -99,27 +93,21 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // refund the ack fee - if feeInEscrow.Fee.AckFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.AckFee}) - if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) - } + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.AckFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) } // refund the receive fee - if feeInEscrow.Fee.ReceiveFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) - if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) - } + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) } // pay the timeout fee to the reverse relayer - if feeInEscrow.Fee.TimeoutFee != nil { - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) - if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) - } + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) + if err != nil { + return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) } // set fee as an empty struct (if we reach this point Fee is paid in full) From c44a81c2b4c02e244a57c0abd3affb50ff95b510 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 13 Oct 2021 15:20:59 +0200 Subject: [PATCH 21/50] refactor: add portId to store key & use packetId as param --- modules/apps/29-fee/keeper/escrow.go | 6 +++--- modules/apps/29-fee/keeper/escrow_test.go | 12 +++++++----- modules/apps/29-fee/keeper/keeper.go | 10 +++++----- modules/apps/29-fee/types/keys.go | 10 +++++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 47c1a669c1a..44b48729fd8 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -48,8 +48,8 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, ident // DistributeFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId - feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID.ChannelId, packetID.Sequence) - if !hasFee { + feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) + if !found { return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) } @@ -84,7 +84,7 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers // DistributeFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId - feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID.ChannelId, packetID.Sequence) + feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID) if !hasFee { return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 5fe24869660..b40e89e66f7 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -72,7 +72,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) if tc.expPass { - feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, packetId.Sequence) + feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId) // check if the escrowed fee is set in state suite.Require().Equal(fee.AckFee, feeInEscrow.Fee.AckFee) suite.Require().Equal(fee.ReceiveFee, feeInEscrow.Fee.ReceiveFee) @@ -150,12 +150,13 @@ func (suite *KeeperTestSuite) TestPayFee() { if tc.expPass { suite.Require().NoError(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, packetId.Sequence) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) } else { suite.Require().Error(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, 1) + invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), invalidPacketID) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) } @@ -222,12 +223,13 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { if tc.expPass { suite.Require().NoError(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, packetId.Sequence) + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) } else { suite.Require().Error(err) - hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId.ChannelId, 1) + invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} + hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), invalidPacketID) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 4f5930e9d36..12044cd15d3 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -128,13 +128,13 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.IdentifiedPacketFee) { store := ctx.KVStore(k.storeKey) bz := k.MustMarshalFee(fee) - store.Set(types.KeyFeeInEscrow(fee.PacketId.ChannelId, fee.PacketId.Sequence), bz) + store.Set(types.KeyFeeInEscrow(fee.PacketId), bz) } // Gets a Fee for a given packet -func (k Keeper) GetFeeInEscrow(ctx sdk.Context, channelId string, sequenceId uint64) (types.IdentifiedPacketFee, bool) { +func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) (types.IdentifiedPacketFee, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeyFeeInEscrow(channelId, sequenceId) + key := types.KeyFeeInEscrow(packetId) bz := store.Get(key) if bz == nil { return types.IdentifiedPacketFee{}, false @@ -146,9 +146,9 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, channelId string, sequenceId uin } // GetFeeInEscrow returns true if there is a Fee still to be escrowed for a given packet -func (k Keeper) HasFeeInEscrow(ctx sdk.Context, channelId string, sequenceId uint64) bool { +func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) bool { store := ctx.KVStore(k.storeKey) - key := types.KeyFeeInEscrow(channelId, sequenceId) + key := types.KeyFeeInEscrow(packetId) bz := store.Get(key) if bz == nil { return false diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 98c4d7b9978..d19dcb794b1 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -1,6 +1,10 @@ package types -import "fmt" +import ( + "fmt" + + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" +) const ( // ModuleName defines the 29-fee name @@ -42,6 +46,6 @@ func KeyRelayerAddress(address string) []byte { } // KeyFeeInEscrow returns the key for escrowed fees -func KeyFeeInEscrow(channelId string, sequenceId uint64) []byte { - return []byte(fmt.Sprintf("%s/%s/packet/%d", FeeInEscrowPrefix, channelId, sequenceId)) +func KeyFeeInEscrow(packetId *channeltypes.PacketId) []byte { + return []byte(fmt.Sprintf("%s/%s/%s/packet/%d", FeeInEscrowPrefix, packetId.PortId, packetId.ChannelId, packetId.Sequence)) } From a8c3cff364c6ecefc894c75269e1cbfc08e5244b Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 13 Oct 2021 15:42:44 +0200 Subject: [PATCH 22/50] fix: add DeleteFeeInEscrow & remove fee on successful distribution --- modules/apps/29-fee/keeper/escrow.go | 10 ++++------ modules/apps/29-fee/keeper/keeper.go | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 44b48729fd8..3fc0b203d85 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -74,9 +74,8 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) } - // set fee as an empty struct (if we reach this point Fee is paid in full) - identifiedPacket := types.IdentifiedPacketFee{PacketId: packetID, Fee: &types.Fee{}, Relayers: []string{}} - k.SetFeeInEscrow(ctx, identifiedPacket) + // removes the fee from the store as fee is now paid + k.DeleteFeeInEscrow(ctx, packetID) return nil } @@ -110,9 +109,8 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) } - // set fee as an empty struct (if we reach this point Fee is paid in full) - identifiedPacket := types.IdentifiedPacketFee{PacketId: packetID, Fee: &types.Fee{}, Relayers: []string{}} - k.SetFeeInEscrow(ctx, identifiedPacket) + // removes the fee from the store as fee is now paid + k.DeleteFeeInEscrow(ctx, packetID) return nil } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 12044cd15d3..fd0f328a417 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -145,6 +145,13 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) return fee, true } +// Deletes the fee associated with the given packetId +func (k Keeper) DeleteFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) { + store := ctx.KVStore(k.storeKey) + key := types.KeyFeeInEscrow(packetId) + store.Delete(key) +} + // GetFeeInEscrow returns true if there is a Fee still to be escrowed for a given packet func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) bool { store := ctx.KVStore(k.storeKey) From 4f490ea0864bdd5dbaed37eb6fdd38606b4ca82d Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 13 Oct 2021 18:57:53 +0200 Subject: [PATCH 23/50] tests: adding validation & signer tests for PayFee/Async & updating proto to use Signer sdk standard --- docs/ibc/proto-docs.md | 14 +- modules/apps/29-fee/keeper/escrow.go | 2 +- modules/apps/29-fee/keeper/escrow_test.go | 6 +- modules/apps/29-fee/keeper/keeper.go | 6 +- modules/apps/29-fee/keeper/msg_server.go | 9 +- modules/apps/29-fee/keeper/msg_server_test.go | 3 +- modules/apps/29-fee/types/errors.go | 2 + modules/apps/29-fee/types/msgs.go | 79 +++++- modules/apps/29-fee/types/msgs_test.go | 225 +++++++++++++++- modules/apps/29-fee/types/tx.pb.go | 240 +++++------------- proto/ibc/applications/fee/v1/tx.proto | 19 +- 11 files changed, 389 insertions(+), 216 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index f4a5cff5d14..04e17582a6b 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -897,7 +897,7 @@ MsgPayPacketFee defines the request type EscrowPacketFee RPC | `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | | `source_port_id` | [string](#string) | | source channel port identifier | | `source_channel_id` | [string](#string) | | source channel unique identifier | -| `refund_account` | [string](#string) | | account address to refund fee if necessary | +| `signer` | [string](#string) | | account address to refund fee if necessary | | `relayers` | [string](#string) | repeated | | @@ -908,15 +908,13 @@ MsgPayPacketFee defines the request type EscrowPacketFee RPC ### MsgPayPacketFeeAsync -MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | source channel port identifier | -| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | source channel unique identifier | -| `refund_account` | [string](#string) | | account address to refund fee if necessary | -| `relayers` | [string](#string) | repeated | | +| `identified_packet_fee` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | packet to pay fee for | +| `signer` | [string](#string) | | account address to refund fee if necessary | @@ -926,7 +924,7 @@ MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC ### MsgPayPacketFeeAsyncResponse -MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +MsgPayPacketFeeAsyncResponse defines the response type for Msg/PayPacketFeeAsync @@ -936,7 +934,7 @@ MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAs ### MsgPayPacketFeeResponse -MsgPayPacketFeeResponse defines the response type for Msg/EscrowPacketFee +MsgPayPacketFeeResponse defines the response type for Msg/PayPacketFee diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 3fc0b203d85..081056ac2e8 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -11,7 +11,7 @@ import ( ) // EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow -func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, identifiedFee types.IdentifiedPacketFee) error { +func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, identifiedFee *types.IdentifiedPacketFee) error { // check if the refund account exists hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) if hasRefundAcc == nil { diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index b40e89e66f7..172ef6b68bc 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -66,7 +66,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { tc.malleate() fee := &types.Fee{ackFee, receiveFee, timeoutFee} - identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} // escrow the packet fee err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) @@ -139,7 +139,7 @@ func (suite *KeeperTestSuite) TestPayFee() { fee := &types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state - identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) suite.Require().NoError(err) @@ -213,7 +213,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { fee := &types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state - identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) suite.Require().NoError(err) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index fd0f328a417..b33c877f718 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -125,7 +125,7 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) } // Stores a Fee for a given packet in state -func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.IdentifiedPacketFee) { +func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee *types.IdentifiedPacketFee) { store := ctx.KVStore(k.storeKey) bz := k.MustMarshalFee(fee) store.Set(types.KeyFeeInEscrow(fee.PacketId), bz) @@ -173,8 +173,8 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) // MustMarshalFee attempts to encode a Fee object and returns the // raw encoded bytes. It panics on error. -func (k Keeper) MustMarshalFee(fee types.IdentifiedPacketFee) []byte { - return k.cdc.MustMarshal(&fee) +func (k Keeper) MustMarshalFee(fee *types.IdentifiedPacketFee) []byte { + return k.cdc.MustMarshal(fee) } // MustUnmarshalFee attempts to decode and return a Fee object from diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index d3ab73c1e2c..b93a00fb8e5 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -49,12 +49,12 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) Sequence: sequence, } - refundAccAddr, err := sdk.AccAddressFromBech32(msg.RefundAccount) + refundAccAddr, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return &types.MsgPayPacketFeeResponse{}, err } - identifiedPacket := types.IdentifiedPacketFee{PacketId: packetId, Fee: msg.Fee, Relayers: msg.Relayers} + identifiedPacket := &types.IdentifiedPacketFee{PacketId: packetId, Fee: msg.Fee, Relayers: msg.Relayers} err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket) if err != nil { return nil, err @@ -69,13 +69,12 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacketFeeAsync) (*types.MsgPayPacketFeeAsyncResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - refundAccAddr, err := sdk.AccAddressFromBech32(msg.RefundAccount) + refundAccAddr, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return &types.MsgPayPacketFeeAsyncResponse{}, err } - identifiedPacket := types.IdentifiedPacketFee{PacketId: msg.PacketId, Fee: msg.Fee, Relayers: msg.Relayers} - err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket) + err = k.EscrowPacketFee(ctx, refundAccAddr, msg.IdentifiedPacketFee) if err != nil { return nil, err } diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 1667ef07378..a2469359164 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -104,7 +104,8 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { ctxA := suite.chainA.GetContext() seq, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(ctxA, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: suite.path.EndpointA.ChannelConfig.PortID, Sequence: seq} - msg := types.NewMsgPayPacketFeeAsync(fee, packetId, refundAcc.String(), []string{}) + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee, refundAcc.String()) tc.malleate() _, err := suite.chainA.SendMsgs(msg) diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 839aca42964..65f9c198cc5 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -12,4 +12,6 @@ var ( ErrFeeNotFound = sdkerrors.Register(ModuleName, 4, "there is no fee escrowed for the given packetId") ErrPayingFee = sdkerrors.Register(ModuleName, 5, "error while paying fee") ErrRefundingFee = sdkerrors.Register(ModuleName, 6, "error while refunding fee") + ErrFeeEmpty = sdkerrors.Register(ModuleName, 7, "fee struct cannot be empty") + ErrRelayersNotNil = sdkerrors.Register(ModuleName, 8, "relayers must be nil. This feature is not supported") ) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 49df3ec53fc..ba1ef4de499 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -3,7 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/modules/core/24-host" ) // msg types @@ -45,24 +45,52 @@ func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress { } // NewMsgPayPacketFee creates a new instance of MsgPayPacketFee -func NewMsgPayPacketFee(fee *Fee, sourcePortId, sourceChannelId, refundAccount string, relayers []string) *MsgPayPacketFee { +func NewMsgPayPacketFee(fee *Fee, sourcePortId, sourceChannelId, signer string, relayers []string) *MsgPayPacketFee { return &MsgPayPacketFee{ Fee: fee, SourcePortId: sourcePortId, SourceChannelId: sourceChannelId, - RefundAccount: refundAccount, + Signer: signer, Relayers: relayers, } } // ValidateBasic performs a basic check of the MsgPayPacketFee fields func (msg MsgPayPacketFee) ValidateBasic() error { + // fee cannot be empty + if (Fee{}) == *msg.Fee { + return ErrFeeEmpty + } + + // validate channelId + err := host.ChannelIdentifierValidator(msg.SourceChannelId) + if err != nil { + return err + } + + // validate portId + err = host.PortIdentifierValidator(msg.SourcePortId) + if err != nil { + return err + } + + // signer check + _, err = sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return sdkerrors.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") + } + + // enforce relayer is nil + if msg.Relayers != nil { + return ErrRelayersNotNil + } + return nil } // GetSigners implements sdk.Msg func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.RefundAccount) + signer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { panic(err) } @@ -70,23 +98,54 @@ func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress { } // NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee -func NewMsgPayPacketFeeAsync(fee *Fee, packetId *channeltypes.PacketId, refundAccount string, relayers []string) *MsgPayPacketFeeAsync { +func NewMsgPayPacketFeeAsync(identifiedPacketFee *IdentifiedPacketFee, signer string) *MsgPayPacketFeeAsync { return &MsgPayPacketFeeAsync{ - Fee: fee, - PacketId: packetId, - RefundAccount: refundAccount, - Relayers: relayers, + IdentifiedPacketFee: identifiedPacketFee, + Signer: signer, } } // ValidateBasic performs a basic check of the MsgPayPacketFeeAsync fields func (msg MsgPayPacketFeeAsync) ValidateBasic() error { + // fee cannot be empty + if (Fee{}) == *msg.IdentifiedPacketFee.Fee { + return ErrFeeEmpty + } + + // validate channelId + err := host.ChannelIdentifierValidator(msg.IdentifiedPacketFee.PacketId.ChannelId) + if err != nil { + return err + } + + // validate portId + err = host.PortIdentifierValidator(msg.IdentifiedPacketFee.PacketId.PortId) + if err != nil { + return err + } + + // signer check + _, err = sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return sdkerrors.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") + } + + // enforce relayer is nil + if msg.IdentifiedPacketFee.Relayers != nil { + return ErrRelayersNotNil + } + + // enforce relayer is nil + if msg.IdentifiedPacketFee.PacketId.Sequence == 0 { + return sdkerrors.ErrInvalidSequence + } + return nil } // GetSigners implements sdk.Msg func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.RefundAccount) + signer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { panic(err) } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index d29073f75a7..3cf3959abb7 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -4,13 +4,18 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" ) var ( - validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - invalidAddr = "invalid_address" + validChannelID = "channel-1" + validPortID = "validPortId" + invalidID = "this identifier is too long to be used as a valid identifier" + validCoin = &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() + invalidAddr = "invalid_address" ) // TestMsgTransferValidation tests ValidateBasic for MsgTransfer @@ -34,3 +39,219 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { } } } + +// TestRegisterCounterpartyAddressGetSigners tests GetSigners +func TestRegisterCountepartyAddressGetSigners(t *testing.T) { + addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + // build message + msg := NewMsgRegisterCounterpartyAddress(addr.String(), addr.String()) + + // GetSigners + res := msg.GetSigners() + + require.Equal(t, []sdk.AccAddress{addr}, res) +} + +// TestMsgPayPacketFeeValidation tests ValidateBasic +func TestMsgPayPacketFeeValidation(t *testing.T) { + var ( + signer string + channelID string + portID string + fee *Fee + relayers []string + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() {}, + true, + }, + { + "fee is empty", + func() { + fee = &Fee{} + }, + false, + }, + { + "invalid channelID", + func() { + channelID = invalidID + }, + false, + }, + { + "invalid portID", + func() { + portID = invalidID + }, + false, + }, + { + "relayers is not nil", + func() { + relayers = []string{validAddr} + }, + false, + }, + { + "invalid signer address", + func() { + signer = "invalid-addr" + }, + false, + }, + } + + for _, tc := range testCases { + // build message + signer = validAddr + channelID = validChannelID + portID = validPortID + fee = &Fee{validCoin, validCoin, validCoin} + relayers = nil + + // malleate + tc.malleate() + msg := NewMsgPayPacketFee(fee, portID, channelID, signer, relayers) + + err := msg.ValidateBasic() + + if tc.expPass { + require.NoError(t, err) + } else { + require.Error(t, err) + } + } +} + +// TestPayPacketFeeGetSigners tests GetSigners +func TestPayPacketFeeGetSigners(t *testing.T) { + addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + // build message + signer := addr.String() + channelID := validChannelID + portID := validPortID + fee := &Fee{validCoin, validCoin, validCoin} + msg := NewMsgPayPacketFee(fee, portID, channelID, signer, nil) + + // GetSigners + res := msg.GetSigners() + + require.Equal(t, []sdk.AccAddress{addr}, res) +} + +// TestMsgPayPacketFeeAsyncValidation tests ValidateBasic +func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { + var ( + signer string + channelID string + portID string + fee *Fee + relayers []string + seq uint64 + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() {}, + true, + }, + { + "fee is empty", + func() { + fee = &Fee{} + }, + false, + }, + { + "invalid channelID", + func() { + channelID = invalidID + }, + false, + }, + { + "invalid portID", + func() { + portID = invalidID + }, + false, + }, + { + "relayers is not nil", + func() { + relayers = []string{validAddr} + }, + false, + }, + { + "invalid signer address", + func() { + signer = "invalid-addr" + }, + false, + }, + { + "invalid sequence", + func() { + seq = 0 + }, + false, + }, + } + + for _, tc := range testCases { + // build message + signer = validAddr + channelID = validChannelID + portID = validPortID + fee = &Fee{validCoin, validCoin, validCoin} + relayers = nil + seq = 1 + + // malleate + tc.malleate() + + packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: portID, Sequence: seq} + identifiedPacketFee := &IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: relayers} + msg := NewMsgPayPacketFeeAsync(identifiedPacketFee, signer) + + err := msg.ValidateBasic() + + if tc.expPass { + require.NoError(t, err) + } else { + require.Error(t, err) + } + } +} + +// TestRegisterCounterpartyAddressGetSigners tests GetSigners +func TestPayPacketFeeAsyncGetSigners(t *testing.T) { + addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + // build message + channelID := validChannelID + portID := validPortID + fee := &Fee{validCoin, validCoin, validCoin} + seq := uint64(1) + packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: portID, Sequence: seq} + identifiedPacketFee := &IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: nil} + msg := NewMsgPayPacketFeeAsync(identifiedPacketFee, addr.String()) + + // GetSigners + res := msg.GetSigners() + + require.Equal(t, []sdk.AccAddress{addr}, res) +} diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 6a528ff48dc..99f4feba458 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -6,7 +6,7 @@ package types import ( context "context" fmt "fmt" - types "github.com/cosmos/ibc-go/modules/core/04-channel/types" + _ "github.com/cosmos/ibc-go/modules/core/04-channel/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -115,8 +115,8 @@ type MsgPayPacketFee struct { // source channel unique identifier SourceChannelId string `protobuf:"bytes,3,opt,name=source_channel_id,json=sourceChannelId,proto3" json:"source_channel_id,omitempty" yaml:"source_channel_id"` // account address to refund fee if necessary - RefundAccount string `protobuf:"bytes,4,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"refund_account"` - Relayers []string `protobuf:"bytes,5,rep,name=relayers,proto3" json:"relayers,omitempty"` + Signer string `protobuf:"bytes,4,opt,name=signer,proto3" json:"signer,omitempty"` + Relayers []string `protobuf:"bytes,5,rep,name=relayers,proto3" json:"relayers,omitempty"` } func (m *MsgPayPacketFee) Reset() { *m = MsgPayPacketFee{} } @@ -152,7 +152,7 @@ func (m *MsgPayPacketFee) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFee proto.InternalMessageInfo -// MsgPayPacketFeeResponse defines the response type for Msg/EscrowPacketFee +// MsgPayPacketFeeResponse defines the response type for Msg/PayPacketFee type MsgPayPacketFeeResponse struct { } @@ -189,15 +189,12 @@ func (m *MsgPayPacketFeeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo -// MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +// MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC type MsgPayPacketFeeAsync struct { - // source channel port identifier - Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` - // source channel unique identifier - PacketId *types.PacketId `protobuf:"bytes,2,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` + // packet to pay fee for + IdentifiedPacketFee *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee,omitempty"` // account address to refund fee if necessary - RefundAccount string `protobuf:"bytes,3,opt,name=refund_account,json=refundAccount,proto3" json:"refund_account,omitempty" yaml:"refund_account"` - Relayers []string `protobuf:"bytes,4,rep,name=relayers,proto3" json:"relayers,omitempty"` + Signer string `protobuf:"bytes,2,opt,name=signer,proto3" json:"signer,omitempty"` } func (m *MsgPayPacketFeeAsync) Reset() { *m = MsgPayPacketFeeAsync{} } @@ -233,7 +230,7 @@ func (m *MsgPayPacketFeeAsync) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFeeAsync proto.InternalMessageInfo -// MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +// MsgPayPacketFeeAsyncResponse defines the response type for Msg/PayPacketFeeAsync type MsgPayPacketFeeAsyncResponse struct { } @@ -282,45 +279,43 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 596 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xb1, 0x6f, 0xd3, 0x4e, - 0x14, 0xc7, 0xe3, 0xba, 0xbf, 0x1f, 0xc9, 0xb5, 0xb4, 0xd4, 0x04, 0x35, 0x75, 0x83, 0x1d, 0x3c, - 0xa0, 0x2c, 0xb1, 0x49, 0x10, 0x42, 0x74, 0x29, 0x49, 0xa5, 0x8a, 0x48, 0x44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0f, - 0xb0, 0x05, 0x00, 0x00, + // 570 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x4c, + 0x10, 0xc6, 0xe3, 0xe4, 0x7d, 0x4b, 0xbb, 0x54, 0x54, 0xdd, 0xa6, 0x34, 0x75, 0x23, 0x3b, 0xf8, + 0x80, 0x72, 0x20, 0x36, 0x0d, 0x42, 0x88, 0x5e, 0xaa, 0xb6, 0x52, 0x45, 0x24, 0x22, 0x45, 0x3e, + 0x72, 0x09, 0xce, 0x7a, 0xe2, 0x2e, 0x24, 0x5e, 0x6b, 0x77, 0x53, 0xe1, 0x2f, 0x80, 0x10, 0x27, + 0x6e, 0x20, 0x4e, 0xfd, 0x38, 0x1c, 0x7b, 0xe4, 0x14, 0xa1, 0xe4, 0xc2, 0x39, 0x9f, 0x00, 0xd9, + 0xce, 0x1f, 0xa7, 0x69, 0xa2, 0xc2, 0xcd, 0x3b, 0xf3, 0x9b, 0x99, 0x67, 0x1e, 0xaf, 0x16, 0x95, + 0x68, 0x8b, 0x58, 0x4e, 0x10, 0x74, 0x28, 0x71, 0x24, 0x65, 0xbe, 0xb0, 0xda, 0x00, 0xd6, 0xe5, + 0xa1, 0x25, 0x3f, 0x98, 0x01, 0x67, 0x92, 0xe1, 0x3d, 0xda, 0x22, 0x66, 0x9a, 0x30, 0xdb, 0x00, + 0xe6, 0xe5, 0xa1, 0x9a, 0xf7, 0x98, 0xc7, 0x62, 0xc6, 0x8a, 0xbe, 0x12, 0x5c, 0x7d, 0xb4, 0xac, + 0x61, 0x54, 0x95, 0x42, 0x08, 0xe3, 0x60, 0x91, 0x0b, 0xc7, 0xf7, 0xa1, 0x13, 0xa5, 0xc7, 0x9f, + 0x09, 0x62, 0x7c, 0x53, 0x90, 0x56, 0x17, 0x9e, 0x0d, 0x1e, 0x15, 0x12, 0xf8, 0x19, 0xeb, 0xf9, + 0x12, 0x78, 0xe0, 0x70, 0x19, 0x9e, 0xb8, 0x2e, 0x07, 0x21, 0x70, 0x01, 0xdd, 0x73, 0x92, 0xcf, + 0x82, 0x52, 0x52, 0xca, 0x1b, 0xf6, 0xe4, 0x88, 0x6d, 0x94, 0x27, 0xa9, 0x82, 0xe6, 0x04, 0xcb, + 0x46, 0xd8, 0xa9, 0x3e, 0xea, 0xeb, 0x07, 0xa1, 0xd3, 0xed, 0x1c, 0x19, 0xb7, 0x51, 0x86, 0xbd, + 0x43, 0x16, 0xa7, 0x1d, 0xad, 0x7f, 0xba, 0xd2, 0x33, 0xbf, 0xaf, 0xf4, 0x8c, 0x51, 0x46, 0x8f, + 0x57, 0x2b, 0xb3, 0x41, 0x04, 0xcc, 0x17, 0x60, 0x7c, 0xce, 0xa2, 0xad, 0xba, 0xf0, 0x1a, 0x4e, + 0xd8, 0x70, 0xc8, 0x7b, 0x90, 0xe7, 0x00, 0xd8, 0x44, 0xb9, 0x36, 0x40, 0xac, 0xf8, 0x7e, 0xb5, + 0x68, 0x2e, 0xf1, 0xd6, 0x3c, 0x07, 0xb0, 0x23, 0x10, 0x1f, 0xa3, 0x07, 0x82, 0xf5, 0x38, 0x81, + 0x66, 0xc0, 0xb8, 0x6c, 0x52, 0x77, 0xbc, 0xc5, 0xfe, 0xa8, 0xaf, 0xef, 0x26, 0x5b, 0xcc, 0xe7, + 0x0d, 0x7b, 0x33, 0x09, 0x34, 0x18, 0x97, 0x35, 0x17, 0xbf, 0x42, 0xdb, 0x63, 0x60, 0xec, 0x70, + 0xd4, 0x23, 0x17, 0xf7, 0x28, 0x8e, 0xfa, 0x7a, 0x61, 0xae, 0xc7, 0x0c, 0x31, 0xec, 0xad, 0x24, + 0x76, 0x96, 0x84, 0x6a, 0x2e, 0x7e, 0x88, 0xd6, 0x04, 0xf5, 0x7c, 0xe0, 0x85, 0xff, 0x62, 0xbf, + 0xc7, 0x27, 0xac, 0xa2, 0x75, 0x0e, 0x1d, 0x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, 0x09, 0xab, 0xfa, 0xb2, + 0x12, 0x3d, 0x55, 0x32, 0x0c, 0x40, 0xb4, 0xd6, 0xe2, 0x77, 0xe8, 0xd9, 0x9f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xe0, 0x4e, 0x96, 0x6f, 0x20, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -586,10 +581,10 @@ func (m *MsgPayPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x2a } } - if len(m.RefundAccount) > 0 { - i -= len(m.RefundAccount) - copy(dAtA[i:], m.RefundAccount) - i = encodeVarintTx(dAtA, i, uint64(len(m.RefundAccount))) + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) i-- dAtA[i] = 0x22 } @@ -665,37 +660,16 @@ func (m *MsgPayPacketFeeAsync) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Relayers) > 0 { - for iNdEx := len(m.Relayers) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Relayers[iNdEx]) - copy(dAtA[i:], m.Relayers[iNdEx]) - i = encodeVarintTx(dAtA, i, uint64(len(m.Relayers[iNdEx]))) - i-- - dAtA[i] = 0x22 - } - } - if len(m.RefundAccount) > 0 { - i -= len(m.RefundAccount) - copy(dAtA[i:], m.RefundAccount) - i = encodeVarintTx(dAtA, i, uint64(len(m.RefundAccount))) - i-- - dAtA[i] = 0x1a - } - if m.PacketId != nil { - { - size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) i-- dAtA[i] = 0x12 } - if m.Fee != nil { + if m.IdentifiedPacketFee != nil { { - size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.IdentifiedPacketFee.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -786,7 +760,7 @@ func (m *MsgPayPacketFee) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.RefundAccount) + l = len(m.Signer) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -814,24 +788,14 @@ func (m *MsgPayPacketFeeAsync) Size() (n int) { } var l int _ = l - if m.Fee != nil { - l = m.Fee.Size() + if m.IdentifiedPacketFee != nil { + l = m.IdentifiedPacketFee.Size() n += 1 + l + sovTx(uint64(l)) } - if m.PacketId != nil { - l = m.PacketId.Size() - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.RefundAccount) + l = len(m.Signer) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if len(m.Relayers) > 0 { - for _, s := range m.Relayers { - l = len(s) - n += 1 + l + sovTx(uint64(l)) - } - } return n } @@ -1145,7 +1109,7 @@ func (m *MsgPayPacketFee) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RefundAccount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1173,7 +1137,7 @@ func (m *MsgPayPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.RefundAccount = string(dAtA[iNdEx:postIndex]) + m.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 5: if wireType != 2 { @@ -1309,7 +1273,7 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field IdentifiedPacketFee", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1336,84 +1300,16 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Fee == nil { - m.Fee = &Fee{} + if m.IdentifiedPacketFee == nil { + m.IdentifiedPacketFee = &IdentifiedPacketFee{} } - if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.IdentifiedPacketFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PacketId", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.PacketId == nil { - m.PacketId = &types.PacketId{} - } - if err := m.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RefundAccount", 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.RefundAccount = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Relayers", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1441,7 +1337,7 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Relayers = append(m.Relayers, string(dAtA[iNdEx:postIndex])) + m.Signer = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 9eb8536eb9a..79afc5cad30 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -48,26 +48,23 @@ message MsgPayPacketFee { // source channel unique identifier string source_channel_id = 3 [(gogoproto.moretags) = "yaml:\"source_channel_id\""]; // account address to refund fee if necessary - string refund_account = 4 [(gogoproto.moretags) = "yaml:\"refund_account\""]; - repeated string relayers = 5; + string signer = 4; + repeated string relayers = 5; } -// MsgPayPacketFeeResponse defines the response type for Msg/EscrowPacketFee +// MsgPayPacketFeeResponse defines the response type for Msg/PayPacketFee message MsgPayPacketFeeResponse {} -// MsgPayPacketFeeAsync defines the request type EscrowPacketFeeAsync RPC +// MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC message MsgPayPacketFeeAsync { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - // source channel port identifier - ibc.applications.fee.v1.Fee fee = 1; - // source channel unique identifier - ibc.core.channel.v1.PacketId packet_id = 2 [(gogoproto.moretags) = "yaml:\"packet_id\""]; + // packet to pay fee for + ibc.applications.fee.v1.IdentifiedPacketFee identified_packet_fee = 1; // account address to refund fee if necessary - string refund_account = 3 [(gogoproto.moretags) = "yaml:\"refund_account\""]; - repeated string relayers = 4; + string signer = 2; } -// MsgPayPacketFeeAsyncResponse defines the response type for Msg/EscrowPacketFeeAsync +// MsgPayPacketFeeAsyncResponse defines the response type for Msg/PayPacketFeeAsync message MsgPayPacketFeeAsyncResponse {} From f1fde1dee4eb69ea57cd179e53acfffcef229e15 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 13 Oct 2021 19:06:13 +0200 Subject: [PATCH 24/50] chore: adding NewIdentifiedPacketFee fn --- modules/apps/29-fee/keeper/keeper.go | 2 +- modules/apps/29-fee/keeper/msg_server.go | 2 +- modules/apps/29-fee/types/msgs.go | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index b33c877f718..0e51f652103 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -137,7 +137,7 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) key := types.KeyFeeInEscrow(packetId) bz := store.Get(key) if bz == nil { - return types.IdentifiedPacketFee{}, false + return nil, false } fee := k.MustUnmarshalFee(bz) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index b93a00fb8e5..61758f24e7f 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -54,7 +54,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) return &types.MsgPayPacketFeeResponse{}, err } - identifiedPacket := &types.IdentifiedPacketFee{PacketId: packetId, Fee: msg.Fee, Relayers: msg.Relayers} + identifiedPacket := types.NewIdentifiedPacketFee{packetId, msg.Fee, msg.Relayers} err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket) if err != nil { return nil, err diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index ba1ef4de499..c40827e06f9 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -3,13 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/modules/core/24-host" ) // msg types const ( TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress" - TypePayPacketFee = "payPacketFee" ) // NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress @@ -151,3 +151,11 @@ func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress { } return []sdk.AccAddress{signer} } + +func NewIdentifiedPacketFee(packetId *channeltypes.PacketId, fee *Fee, relayers []string) *IdentifiedPacketFee { + return &IdentifiedPacketFee{ + PacketId: packetId, + Fee: fee, + Relayers: relayers, + } +} From eeb4376ce3d9d5919f9c6bee58dbacc7df82ad8c Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 14 Oct 2021 08:22:34 +0200 Subject: [PATCH 25/50] fix: getter/setter for counterparty address + fix NewIdentifiedPacketFee --- modules/apps/29-fee/keeper/escrow.go | 2 +- modules/apps/29-fee/keeper/keeper.go | 15 ++++++++------- modules/apps/29-fee/keeper/msg_server.go | 4 ++-- modules/apps/29-fee/keeper/msg_server_test.go | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 081056ac2e8..8a12993d336 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -40,7 +40,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, ident } // Store fee in state for reference later - // feeInEscrow//packet// -> Fee (timeout, ack, onrecv) + // feeInEscrow///packet// -> Fee (timeout, ack, onrecv) k.SetFeeInEscrow(ctx, identifiedFee) return nil } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 0e51f652103..e11f4d2cc25 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -107,21 +107,22 @@ func (k Keeper) IsFeeEnabled(ctx sdk.Context, portID, channelID string) bool { // 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 string, counterpartyAddress sdk.AccAddress) { +func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) { store := ctx.KVStore(k.storeKey) - store.Set(types.KeyRelayerAddress(address), counterpartyAddress) + store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress)) } // GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address -func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) { +func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeyRelayerAddress(address.String()) + key := types.KeyRelayerAddress(address) if !store.Has(key) { - return []byte{}, false + return "", false } - return store.Get(key), true + addr := string(store.Get(key)) + return addr, true } // Stores a Fee for a given packet in state @@ -137,7 +138,7 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) key := types.KeyFeeInEscrow(packetId) bz := store.Get(key) if bz == nil { - return nil, false + return types.IdentifiedPacketFee{}, false } fee := k.MustUnmarshalFee(bz) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 61758f24e7f..60998e9f48e 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -24,7 +24,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms } k.SetCounterpartyAddress( - ctx, msg.Address, counterpartyAddress, + ctx, msg.Address, counterpartyAddress.String(), ) k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress) @@ -54,7 +54,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) return &types.MsgPayPacketFeeResponse{}, err } - identifiedPacket := types.NewIdentifiedPacketFee{packetId, msg.Fee, msg.Relayers} + identifiedPacket := types.NewIdentifiedPacketFee(packetId, msg.Fee, msg.Relayers) err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket) if err != nil { return nil, err diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index a2469359164..331a2a1bd28 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -38,8 +38,8 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { if tc.expPass { suite.Require().NoError(err) // message committed - counterpartyAddress, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(ctx, suite.chainA.SenderAccount.GetAddress()) - suite.Require().Equal(addr2, counterpartyAddress.String()) + counterpartyAddress, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(ctx, suite.chainA.SenderAccount.GetAddress().String()) + suite.Require().Equal(addr2, counterpartyAddress) } else { suite.Require().Error(err) } From 4612bf29064e0044a295638332cc9779746ea5a1 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 14 Oct 2021 11:57:12 +0200 Subject: [PATCH 26/50] fix: updating EscrowPacketFee with correct usage of coins api --- docs/ibc/proto-docs.md | 6 +- modules/apps/29-fee/keeper/escrow.go | 50 ++--- modules/apps/29-fee/keeper/escrow_test.go | 59 +++--- modules/apps/29-fee/keeper/keeper.go | 9 +- modules/apps/29-fee/keeper/msg_server_test.go | 17 +- modules/apps/29-fee/types/fee.pb.go | 171 +++++++++--------- modules/apps/29-fee/types/msgs.go | 10 - modules/apps/29-fee/types/msgs_test.go | 24 +-- proto/ibc/applications/fee/v1/fee.proto | 19 +- 9 files changed, 174 insertions(+), 191 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 04e17582a6b..9f5397906cd 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -630,9 +630,9 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middl | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `receive_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | -| `ack_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | -| `timeout_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `receive_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `ack_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `timeout_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 8a12993d336..415ed25bc6b 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" @@ -18,25 +19,14 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, ident return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc.String())) } - fees := sdk.Coins{ - *identifiedFee.Fee.AckFee, *identifiedFee.Fee.ReceiveFee, *identifiedFee.Fee.TimeoutFee, - } - - // check if refundAcc has balance for each fee - for _, f := range fees { - hasBalance := k.bankKeeper.HasBalance(ctx, refundAcc, f) - if !hasBalance { - return sdkerrors.Wrap(types.ErrBalanceNotFound, fmt.Sprintf("%s", refundAcc.String())) - } - } + coins := identifiedFee.Fee.AckFee + coins = coins.Add(identifiedFee.Fee.ReceiveFee...) + coins = coins.Add(identifiedFee.Fee.TimeoutFee...) - for _, coin := range fees { - // escrow each fee with account module - if err := k.bankKeeper.SendCoinsFromAccountToModule( - ctx, refundAcc, types.ModuleName, sdk.Coins{coin}, - ); err != nil { - return err - } + if err := k.bankKeeper.SendCoinsFromAccountToModule( + ctx, refundAcc, types.ModuleName, coins, + ); err != nil { + return err } // Store fee in state for reference later @@ -57,21 +47,21 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // send ack fee to reverse relayer - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.AckFee) if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) + return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to reverse relayer")) } // send receive fee to forward relayer - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, feeInEscrow.Fee.ReceiveFee) if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) + return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to forward relayer")) } // refund timeout fee to refundAddr - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.TimeoutFee) if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) + return sdkerrors.Wrap(err, fmt.Sprintf("error refunding timeout fee")) } // removes the fee from the store as fee is now paid @@ -92,21 +82,21 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // refund the ack fee - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.AckFee}) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.AckFee.Denom, feeInEscrow.Fee.AckFee.Amount)) + return sdkerrors.Wrap(err, fmt.Sprintf("error refunding ack fee")) } // refund the receive fee - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, sdk.Coins{*feeInEscrow.Fee.ReceiveFee}) + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee) if err != nil { - return sdkerrors.Wrap(types.ErrRefundingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.ReceiveFee.Denom, feeInEscrow.Fee.ReceiveFee.Amount)) + return sdkerrors.Wrap(err, fmt.Sprintf("error refunding receive fee")) } // pay the timeout fee to the reverse relayer - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, sdk.Coins{*feeInEscrow.Fee.TimeoutFee}) + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.TimeoutFee) if err != nil { - return sdkerrors.Wrap(types.ErrPayingFee, fmt.Sprintf("Error sending coin with Denom: %s for Amount: %d", feeInEscrow.Fee.TimeoutFee.Denom, feeInEscrow.Fee.TimeoutFee.Amount)) + return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to timeout relayer")) } // removes the fee from the store as fee is now paid diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 172ef6b68bc..b25e490b17f 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -6,17 +6,21 @@ import ( channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) +var ( + validCoins = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} + invalidCoins = sdk.Coins{sdk.Coin{Denom: "invalidDenom", Amount: sdk.NewInt(100)}} +) + func (suite *KeeperTestSuite) TestEscrowPacketFee() { var ( err error refundAcc sdk.AccAddress - ackFee *sdk.Coin - receiveFee *sdk.Coin - timeoutFee *sdk.Coin + ackFee sdk.Coins + receiveFee sdk.Coins + timeoutFee sdk.Coins ) // refundAcc does not have balance for the following Coin - invalidCoin := &sdk.Coin{Denom: "cosmos", Amount: sdk.NewInt(8000000000)} validChannelId := "channel-0" testCases := []struct { @@ -29,23 +33,23 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { }, { "refundAcc does not exist", func() { - // this acc does nto exist on chainA + // this acc does not exist on chainA refundAcc = suite.chainB.SenderAccount.GetAddress() }, false, }, { "ackFee balance not found", func() { - ackFee = invalidCoin + ackFee = invalidCoins }, false, }, { "receive balance not found", func() { - receiveFee = invalidCoin + receiveFee = invalidCoins }, false, }, { "timeout balance not found", func() { - timeoutFee = invalidCoin + timeoutFee = invalidCoins }, false, }, } @@ -58,10 +62,9 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { // setup refundAcc = suite.chainA.SenderAccount.GetAddress() - validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} - ackFee = validCoin - receiveFee = validCoin - timeoutFee = validCoin + ackFee = validCoins + receiveFee = validCoins + timeoutFee = validCoins packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} tc.malleate() @@ -74,9 +77,9 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { if tc.expPass { feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId) // check if the escrowed fee is set in state - suite.Require().Equal(fee.AckFee, feeInEscrow.Fee.AckFee) - suite.Require().Equal(fee.ReceiveFee, feeInEscrow.Fee.ReceiveFee) - suite.Require().Equal(fee.TimeoutFee, feeInEscrow.Fee.TimeoutFee) + suite.Require().True(feeInEscrow.Fee.AckFee.IsEqual(fee.AckFee)) + suite.Require().True(feeInEscrow.Fee.ReceiveFee.IsEqual(fee.ReceiveFee)) + suite.Require().True(feeInEscrow.Fee.TimeoutFee.IsEqual(fee.TimeoutFee)) // check if the fee is escrowed correctly hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}) suite.Require().True(hasBalance) @@ -91,9 +94,9 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { func (suite *KeeperTestSuite) TestPayFee() { var ( err error - ackFee *sdk.Coin - receiveFee *sdk.Coin - timeoutFee *sdk.Coin + ackFee sdk.Coins + receiveFee sdk.Coins + timeoutFee sdk.Coins packetId *channeltypes.PacketId reverseRelayer sdk.AccAddress forwardRelayer sdk.AccAddress @@ -131,10 +134,9 @@ func (suite *KeeperTestSuite) TestPayFee() { reverseRelayer = suite.chainA.SenderAccount.GetAddress() forwardRelayer = suite.chainA.SenderAccount.GetAddress() - validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} - ackFee = validCoin - receiveFee = validCoin - timeoutFee = validCoin + ackFee = validCoins + receiveFee = validCoins + timeoutFee = validCoins packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} fee := &types.Fee{ackFee, receiveFee, timeoutFee} @@ -167,9 +169,9 @@ func (suite *KeeperTestSuite) TestPayFee() { func (suite *KeeperTestSuite) TestPayTimeoutFee() { var ( err error - ackFee *sdk.Coin - receiveFee *sdk.Coin - timeoutFee *sdk.Coin + ackFee sdk.Coins + receiveFee sdk.Coins + timeoutFee sdk.Coins packetId *channeltypes.PacketId reverseRelayer sdk.AccAddress refundAcc sdk.AccAddress @@ -205,10 +207,9 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { refundAcc = suite.chainA.SenderAccount.GetAddress() reverseRelayer = suite.chainA.SenderAccount.GetAddress() - validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} - ackFee = validCoin - receiveFee = validCoin - timeoutFee = validCoin + ackFee = validCoins + receiveFee = validCoins + timeoutFee = validCoins packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} fee := &types.Fee{ackFee, receiveFee, timeoutFee} diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index e11f4d2cc25..74f8920ca53 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -157,15 +157,8 @@ func (k Keeper) DeleteFeeInEscrow(ctx sdk.Context, packetId *channeltypes.Packet func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) bool { store := ctx.KVStore(k.storeKey) key := types.KeyFeeInEscrow(packetId) - bz := store.Get(key) - if bz == nil { - return false - } - fee := k.MustUnmarshalFee(bz) - - // if the returned Fee is empty return false - if (types.Fee{}) == *fee.Fee { + if !store.Has(key) { return false } diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 331a2a1bd28..72aafeda49c 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -1,7 +1,6 @@ package keeper_test import ( - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) @@ -64,9 +63,8 @@ func (suite *KeeperTestSuite) TestPayPacketFee() { suite.coordinator.SetupConnections(suite.path) SetupFeePath(suite.path) refundAcc := suite.chainA.SenderAccount.GetAddress() - validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} channelID := suite.path.EndpointA.ChannelID - fee := &types.Fee{validCoin, validCoin, validCoin} + fee := &types.Fee{validCoins, validCoins, validCoins} msg := types.NewMsgPayPacketFee(fee, suite.path.EndpointA.ChannelConfig.PortID, channelID, refundAcc.String(), []string{}) tc.malleate() @@ -97,17 +95,22 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { suite.SetupTest() suite.coordinator.SetupConnections(suite.path) SetupFeePath(suite.path) + ctxA := suite.chainA.GetContext() + refundAcc := suite.chainA.SenderAccount.GetAddress() - validCoin := &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + + // build packetId channelID := suite.path.EndpointA.ChannelID - fee := &types.Fee{validCoin, validCoin, validCoin} - ctxA := suite.chainA.GetContext() + fee := &types.Fee{validCoins, validCoins, validCoins} seq, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(ctxA, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) + + // build fee packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: suite.path.EndpointA.ChannelConfig.PortID, Sequence: seq} identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} - msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee, refundAcc.String()) tc.malleate() + + msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee, refundAcc.String()) _, err := suite.chainA.SendMsgs(msg) if tc.expPass { diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 6f563911a50..5894b21373c 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" types1 "github.com/cosmos/ibc-go/modules/core/04-channel/types" _ "github.com/gogo/protobuf/gogoproto" @@ -29,9 +30,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // See Fee Payment Middleware spec: // https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract type Fee struct { - ReceiveFee *types.Coin `protobuf:"bytes,1,opt,name=receive_fee,json=receiveFee,proto3" json:"receive_fee,omitempty" yaml:"receive_fee"` - AckFee *types.Coin `protobuf:"bytes,2,opt,name=ack_fee,json=ackFee,proto3" json:"ack_fee,omitempty" yaml:"ack_fee"` - TimeoutFee *types.Coin `protobuf:"bytes,3,opt,name=timeout_fee,json=timeoutFee,proto3" json:"timeout_fee,omitempty" yaml:"timeout_fee"` + ReceiveFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=receive_fee,json=receiveFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"receive_fee" yaml:"receive_fee"` + AckFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=ack_fee,json=ackFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"ack_fee" yaml:"ack_fee"` + TimeoutFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=timeout_fee,json=timeoutFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"timeout_fee" yaml:"timeout_fee"` } func (m *Fee) Reset() { *m = Fee{} } @@ -67,21 +68,21 @@ func (m *Fee) XXX_DiscardUnknown() { var xxx_messageInfo_Fee proto.InternalMessageInfo -func (m *Fee) GetReceiveFee() *types.Coin { +func (m *Fee) GetReceiveFee() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.ReceiveFee } return nil } -func (m *Fee) GetAckFee() *types.Coin { +func (m *Fee) GetAckFee() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.AckFee } return nil } -func (m *Fee) GetTimeoutFee() *types.Coin { +func (m *Fee) GetTimeoutFee() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.TimeoutFee } @@ -157,33 +158,35 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 407 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xc1, 0xaa, 0xda, 0x40, - 0x14, 0x35, 0x0d, 0x58, 0x1d, 0xa1, 0x94, 0x54, 0x5a, 0x2b, 0x6d, 0xb4, 0x59, 0xb9, 0x71, 0x86, - 0xd8, 0x55, 0xbb, 0xb4, 0x10, 0x10, 0xba, 0x90, 0x2c, 0xbb, 0x91, 0xc9, 0xe4, 0x1a, 0x07, 0x93, - 0x4c, 0xc8, 0x8c, 0x01, 0xff, 0xa2, 0xff, 0xd2, 0x9f, 0xe8, 0xd2, 0x65, 0x57, 0x52, 0xf4, 0x0f, - 0x84, 0xb7, 0x7f, 0x4c, 0x32, 0xcf, 0xe7, 0xe6, 0xf1, 0x78, 0xab, 0xb9, 0x77, 0xe6, 0x9e, 0x73, - 0x86, 0x73, 0x0f, 0xfa, 0xc2, 0x23, 0x46, 0x68, 0x51, 0xa4, 0x9c, 0x51, 0xc5, 0x45, 0x2e, 0xc9, - 0x1a, 0x80, 0x54, 0xbe, 0x3e, 0x70, 0x51, 0x0a, 0x25, 0x9c, 0x0f, 0x3c, 0x62, 0xf8, 0x76, 0x04, - 0xeb, 0xb7, 0x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0x85, 0x9d, 0xc2, 0xbc, 0x3b, 0x18, - 0xd9, 0x8f, 0x0e, 0x7c, 0xc2, 0x4f, 0x6c, 0x18, 0x07, 0x00, 0xa1, 0x1e, 0x74, 0x86, 0xa8, 0x53, - 0x42, 0x4a, 0xf7, 0x50, 0xca, 0x81, 0x3d, 0xb6, 0x27, 0xdd, 0xf0, 0xda, 0xcf, 0x7f, 0xfe, 0x3d, - 0xb9, 0xd6, 0xe1, 0xe4, 0x5a, 0xff, 0x4f, 0xae, 0xf5, 0xfb, 0xec, 0xb6, 0x0e, 0x67, 0xb7, 0xf5, - 0xef, 0xec, 0xb6, 0x7e, 0xcd, 0x12, 0xae, 0x36, 0xbb, 0x08, 0x33, 0x91, 0x11, 0x93, 0x15, 0x1e, - 0xb1, 0x69, 0x22, 0x48, 0x26, 0xe2, 0x5d, 0x0a, 0x52, 0x27, 0x4f, 0x92, 0xd9, 0xb7, 0xa9, 0x0e, - 0x9d, 0xda, 0x17, 0x20, 0xa3, 0x76, 0x1d, 0x81, 0xaf, 0xf7, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8b, - 0x8a, 0xda, 0xb4, 0x99, 0x02, 0x00, 0x00, + // 438 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xbd, 0x8a, 0x1b, 0x31, + 0x10, 0xc7, 0xad, 0x2c, 0x5c, 0xee, 0x64, 0x08, 0x61, 0x73, 0x90, 0x8b, 0x49, 0xd6, 0x97, 0xad, + 0xdc, 0x58, 0xc2, 0x4e, 0x95, 0x94, 0x0e, 0x2c, 0x1c, 0xa4, 0x38, 0xb6, 0x4c, 0x73, 0x68, 0xb5, + 0xe3, 0x3d, 0xb1, 0x1f, 0x5a, 0x56, 0xf2, 0x82, 0xdb, 0x34, 0x69, 0xf3, 0x1c, 0x69, 0xf3, 0x12, + 0x57, 0x5e, 0x99, 0xca, 0x09, 0xf6, 0x1b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, 0x2b, 0x03, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -206,41 +209,47 @@ func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.TimeoutFee != nil { - { - size, err := m.TimeoutFee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.TimeoutFee) > 0 { + for iNdEx := len(m.TimeoutFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TimeoutFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a } - i-- - dAtA[i] = 0x1a } - if m.AckFee != nil { - { - size, err := m.AckFee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.AckFee) > 0 { + for iNdEx := len(m.AckFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AckFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 } - if m.ReceiveFee != nil { - { - size, err := m.ReceiveFee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.ReceiveFee) > 0 { + for iNdEx := len(m.ReceiveFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ReceiveFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0xa } - i-- - dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -318,17 +327,23 @@ func (m *Fee) Size() (n int) { } var l int _ = l - if m.ReceiveFee != nil { - l = m.ReceiveFee.Size() - n += 1 + l + sovFee(uint64(l)) + if len(m.ReceiveFee) > 0 { + for _, e := range m.ReceiveFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } } - if m.AckFee != nil { - l = m.AckFee.Size() - n += 1 + l + sovFee(uint64(l)) + if len(m.AckFee) > 0 { + for _, e := range m.AckFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } } - if m.TimeoutFee != nil { - l = m.TimeoutFee.Size() - n += 1 + l + sovFee(uint64(l)) + if len(m.TimeoutFee) > 0 { + for _, e := range m.TimeoutFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } } return n } @@ -420,10 +435,8 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.ReceiveFee == nil { - m.ReceiveFee = &types.Coin{} - } - if err := m.ReceiveFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ReceiveFee = append(m.ReceiveFee, types.Coin{}) + if err := m.ReceiveFee[len(m.ReceiveFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -456,10 +469,8 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.AckFee == nil { - m.AckFee = &types.Coin{} - } - if err := m.AckFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.AckFee = append(m.AckFee, types.Coin{}) + if err := m.AckFee[len(m.AckFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -492,10 +503,8 @@ func (m *Fee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.TimeoutFee == nil { - m.TimeoutFee = &types.Coin{} - } - if err := m.TimeoutFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.TimeoutFee = append(m.TimeoutFee, types.Coin{}) + if err := m.TimeoutFee[len(m.TimeoutFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index c40827e06f9..446de5e1312 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -57,11 +57,6 @@ func NewMsgPayPacketFee(fee *Fee, sourcePortId, sourceChannelId, signer string, // ValidateBasic performs a basic check of the MsgPayPacketFee fields func (msg MsgPayPacketFee) ValidateBasic() error { - // fee cannot be empty - if (Fee{}) == *msg.Fee { - return ErrFeeEmpty - } - // validate channelId err := host.ChannelIdentifierValidator(msg.SourceChannelId) if err != nil { @@ -107,11 +102,6 @@ func NewMsgPayPacketFeeAsync(identifiedPacketFee *IdentifiedPacketFee, signer st // ValidateBasic performs a basic check of the MsgPayPacketFeeAsync fields func (msg MsgPayPacketFeeAsync) ValidateBasic() error { - // fee cannot be empty - if (Fee{}) == *msg.IdentifiedPacketFee.Fee { - return ErrFeeEmpty - } - // validate channelId err := host.ChannelIdentifierValidator(msg.IdentifiedPacketFee.PacketId.ChannelId) if err != nil { diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 3cf3959abb7..fe1519560e5 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -13,7 +13,7 @@ var ( validChannelID = "channel-1" validPortID = "validPortId" invalidID = "this identifier is too long to be used as a valid identifier" - validCoin = &sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)} + validCoins = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() invalidAddr = "invalid_address" ) @@ -72,13 +72,6 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { func() {}, true, }, - { - "fee is empty", - func() { - fee = &Fee{} - }, - false, - }, { "invalid channelID", func() { @@ -114,7 +107,7 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { signer = validAddr channelID = validChannelID portID = validPortID - fee = &Fee{validCoin, validCoin, validCoin} + fee = &Fee{validCoins, validCoins, validCoins} relayers = nil // malleate @@ -138,7 +131,7 @@ func TestPayPacketFeeGetSigners(t *testing.T) { signer := addr.String() channelID := validChannelID portID := validPortID - fee := &Fee{validCoin, validCoin, validCoin} + fee := &Fee{validCoins, validCoins, validCoins} msg := NewMsgPayPacketFee(fee, portID, channelID, signer, nil) // GetSigners @@ -168,13 +161,6 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { func() {}, true, }, - { - "fee is empty", - func() { - fee = &Fee{} - }, - false, - }, { "invalid channelID", func() { @@ -217,7 +203,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { signer = validAddr channelID = validChannelID portID = validPortID - fee = &Fee{validCoin, validCoin, validCoin} + fee = &Fee{validCoins, validCoins, validCoins} relayers = nil seq = 1 @@ -244,7 +230,7 @@ func TestPayPacketFeeAsyncGetSigners(t *testing.T) { // build message channelID := validChannelID portID := validPortID - fee := &Fee{validCoin, validCoin, validCoin} + fee := &Fee{validCoins, validCoins, validCoins} seq := uint64(1) packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: portID, Sequence: seq} identifiedPacketFee := &IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: nil} diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index 8023ac2403e..e2b4cce066d 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -10,11 +10,22 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // See Fee Payment Middleware spec: // https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract message Fee { - cosmos.base.v1beta1.Coin receive_fee = 1 [(gogoproto.moretags) = "yaml:\"receive_fee\""]; - cosmos.base.v1beta1.Coin ack_fee = 2 [(gogoproto.moretags) = "yaml:\"ack_fee\""]; - cosmos.base.v1beta1.Coin timeout_fee = 3 [(gogoproto.moretags) = "yaml:\"timeout_fee\""]; + repeated cosmos.base.v1beta1.Coin receive_fee = 1 [ + (gogoproto.moretags) = "yaml:\"receive_fee\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + repeated cosmos.base.v1beta1.Coin ack_fee = 2 [ + (gogoproto.moretags) = "yaml:\"ack_fee\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + repeated cosmos.base.v1beta1.Coin timeout_fee = 3 [ + (gogoproto.moretags) = "yaml:\"timeout_fee\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; } - // Fee associated with a packet_id message IdentifiedPacketFee { ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; From 3494a0fbf466902fbe2659c0f8c00e7a0cb84a4a Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 14 Oct 2021 12:32:55 +0200 Subject: [PATCH 27/50] test: adding balance check for refund acc after escrow --- modules/apps/29-fee/keeper/escrow_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index b25e490b17f..30429d9de9b 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -71,6 +71,9 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { fee := &types.Fee{ackFee, receiveFee, timeoutFee} identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + // refundAcc balance before escrow + originalBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom) + // escrow the packet fee err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) @@ -83,6 +86,10 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { // check if the fee is escrowed correctly hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}) suite.Require().True(hasBalance) + expectedBal := originalBal.Amount.Sub(sdk.NewInt(300)) + // check if the refund acc has sent the fee + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: expectedBal}) + suite.Require().True(hasBalance) suite.Require().NoError(err) } else { suite.Require().Error(err) From f4c37e6ed40b9b0287d0b40eb4ac6d0a063d955f Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 14 Oct 2021 12:34:03 +0200 Subject: [PATCH 28/50] fix: remove unncessary errors --- modules/apps/29-fee/types/errors.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 65f9c198cc5..57a32ce23bd 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -10,8 +10,5 @@ var ( ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 2, "no account found for given refund address") ErrBalanceNotFound = sdkerrors.Register(ModuleName, 3, "balance not found for given account address") ErrFeeNotFound = sdkerrors.Register(ModuleName, 4, "there is no fee escrowed for the given packetId") - ErrPayingFee = sdkerrors.Register(ModuleName, 5, "error while paying fee") - ErrRefundingFee = sdkerrors.Register(ModuleName, 6, "error while refunding fee") - ErrFeeEmpty = sdkerrors.Register(ModuleName, 7, "fee struct cannot be empty") - ErrRelayersNotNil = sdkerrors.Register(ModuleName, 8, "relayers must be nil. This feature is not supported") + ErrRelayersNotNil = sdkerrors.Register(ModuleName, 5, "relayers must be nil. This feature is not supported") ) From 0b733ab88b4fab5d51d398dba42938c1c87d0e0e Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 3 Nov 2021 12:29:47 +0100 Subject: [PATCH 29/50] test: updating escrow tests + miscellaneous fixes --- modules/apps/29-fee/keeper/escrow.go | 20 +++--- modules/apps/29-fee/keeper/escrow_test.go | 26 +++++++- modules/apps/29-fee/types/keys.go | 2 +- modules/apps/29-fee/types/tx.pb.go | 77 ++++++++++++----------- proto/ibc/applications/fee/v1/tx.proto | 3 +- 5 files changed, 75 insertions(+), 53 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 415ed25bc6b..e0835f98674 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -46,22 +46,22 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers // get module accAddr feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) - // send ack fee to reverse relayer - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.AckFee) + // send receive fee to forward relayer + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, feeInEscrow.Fee.ReceiveFee) if err != nil { - return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to reverse relayer")) + return sdkerrors.Wrap(err, "error sending fee to forward relayer") } - // send receive fee to forward relayer - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, feeInEscrow.Fee.ReceiveFee) + // send ack fee to reverse relayer + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.AckFee) if err != nil { - return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to forward relayer")) + return sdkerrors.Wrap(err, "error sending fee to reverse relayer") } // refund timeout fee to refundAddr err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.TimeoutFee) if err != nil { - return sdkerrors.Wrap(err, fmt.Sprintf("error refunding timeout fee")) + return sdkerrors.Wrap(err, "error refunding timeout fee") } // removes the fee from the store as fee is now paid @@ -84,19 +84,19 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer // refund the ack fee err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) if err != nil { - return sdkerrors.Wrap(err, fmt.Sprintf("error refunding ack fee")) + return sdkerrors.Wrap(err, "error refunding ack fee") } // refund the receive fee err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee) if err != nil { - return sdkerrors.Wrap(err, fmt.Sprintf("error refunding receive fee")) + return sdkerrors.Wrap(err, "error refunding receive fee") } // pay the timeout fee to the reverse relayer err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.TimeoutFee) if err != nil { - return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to timeout relayer")) + return sdkerrors.Wrap(err, "error sending fee to timeout relayer") } // removes the fee from the store as fee is now paid diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 30429d9de9b..05bc0ee7dc6 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + "github.com/tendermint/tendermint/crypto/secp256k1" ) var ( @@ -138,8 +139,8 @@ func (suite *KeeperTestSuite) TestPayFee() { // setup refundAcc = suite.chainA.SenderAccount.GetAddress() - reverseRelayer = suite.chainA.SenderAccount.GetAddress() - forwardRelayer = suite.chainA.SenderAccount.GetAddress() + reverseRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + forwardRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) ackFee = validCoins receiveFee = validCoins @@ -162,6 +163,18 @@ func (suite *KeeperTestSuite) TestPayFee() { hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) + // check if the reverse relayer is paid + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), reverseRelayer, validCoins[0]) + suite.Require().True(hasBalance) + // check if the forward relayer is paid + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), forwardRelayer, validCoins[0]) + suite.Require().True(hasBalance) + // check the module acc wallet is now empty + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) + suite.Require().True(hasBalance) + + suite.Require().NoError(err) + } else { suite.Require().Error(err) invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} @@ -212,7 +225,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { // setup refundAcc = suite.chainA.SenderAccount.GetAddress() - reverseRelayer = suite.chainA.SenderAccount.GetAddress() + reverseRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) ackFee = validCoins receiveFee = validCoins @@ -234,6 +247,13 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) + // check if the refund acc has been refunded + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), reverseRelayer, validCoins[0]) + suite.Require().True(hasBalance) + // check the module acc wallet is now empty + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) + suite.Require().True(hasBalance) + } else { suite.Require().Error(err) invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index d19dcb794b1..7a6d4050781 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -30,7 +30,7 @@ const ( // RelayerAddressKeyPrefix is the key prefix for relayer address mapping RelayerAddressKeyPrefix = "relayerAddress" - // RelayerAddressKeyPrefix is the key prefix for relayer address mapping + // FeeInEscrowPrefix is the key prefix for fee in escrow mapping FeeInEscrowPrefix = "feeInEscrow" ) diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 99f4feba458..33d19dbe617 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -192,7 +192,7 @@ var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo // MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC type MsgPayPacketFeeAsync struct { // packet to pay fee for - IdentifiedPacketFee *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee,omitempty"` + IdentifiedPacketFee *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee,omitempty" yaml:"identified_packet_fee"` // account address to refund fee if necessary Signer string `protobuf:"bytes,2,opt,name=signer,proto3" json:"signer,omitempty"` } @@ -279,43 +279,44 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x4c, - 0x10, 0xc6, 0xe3, 0xe4, 0x7d, 0x4b, 0xbb, 0x54, 0x54, 0xdd, 0xa6, 0x34, 0x75, 0x23, 0x3b, 0xf8, - 0x80, 0x72, 0x20, 0x36, 0x0d, 0x42, 0x88, 0x5e, 0xaa, 0xb6, 0x52, 0x45, 0x24, 0x22, 0x45, 0x3e, - 0x72, 0x09, 0xce, 0x7a, 0xe2, 0x2e, 0x24, 0x5e, 0x6b, 0x77, 0x53, 0xe1, 0x2f, 0x80, 0x10, 0x27, - 0x6e, 0x20, 0x4e, 0xfd, 0x38, 0x1c, 0x7b, 0xe4, 0x14, 0xa1, 0xe4, 0xc2, 0x39, 0x9f, 0x00, 0xd9, - 0xce, 0x1f, 0xa7, 0x69, 0xa2, 0xc2, 0xcd, 0x3b, 0xf3, 0x9b, 0x99, 0x67, 0x1e, 0xaf, 0x16, 0x95, - 0x68, 0x8b, 0x58, 0x4e, 0x10, 0x74, 0x28, 0x71, 0x24, 0x65, 0xbe, 0xb0, 0xda, 0x00, 0xd6, 0xe5, - 0xa1, 0x25, 0x3f, 0x98, 0x01, 0x67, 0x92, 0xe1, 0x3d, 0xda, 0x22, 0x66, 0x9a, 0x30, 0xdb, 0x00, - 0xe6, 0xe5, 0xa1, 0x9a, 0xf7, 0x98, 0xc7, 0x62, 0xc6, 0x8a, 0xbe, 0x12, 0x5c, 0x7d, 0xb4, 0xac, - 0x61, 0x54, 0x95, 0x42, 0x08, 0xe3, 0x60, 0x91, 0x0b, 0xc7, 0xf7, 0xa1, 0x13, 0xa5, 0xc7, 0x9f, - 0x09, 0x62, 0x7c, 0x53, 0x90, 0x56, 0x17, 0x9e, 0x0d, 0x1e, 0x15, 0x12, 0xf8, 0x19, 0xeb, 0xf9, - 0x12, 0x78, 0xe0, 0x70, 0x19, 0x9e, 0xb8, 0x2e, 0x07, 0x21, 0x70, 0x01, 0xdd, 0x73, 0x92, 0xcf, - 0x82, 0x52, 0x52, 0xca, 0x1b, 0xf6, 0xe4, 0x88, 0x6d, 0x94, 0x27, 0xa9, 0x82, 0xe6, 0x04, 0xcb, - 0x46, 0xd8, 0xa9, 0x3e, 0xea, 0xeb, 0x07, 0xa1, 0xd3, 0xed, 0x1c, 0x19, 0xb7, 0x51, 0x86, 0xbd, - 0x43, 0x16, 0xa7, 0x1d, 0xad, 0x7f, 0xba, 0xd2, 0x33, 0xbf, 0xaf, 0xf4, 0x8c, 0x51, 0x46, 0x8f, - 0x57, 0x2b, 0xb3, 0x41, 0x04, 0xcc, 0x17, 0x60, 0x7c, 0xce, 0xa2, 0xad, 0xba, 0xf0, 0x1a, 0x4e, - 0xd8, 0x70, 0xc8, 0x7b, 0x90, 0xe7, 0x00, 0xd8, 0x44, 0xb9, 0x36, 0x40, 0xac, 0xf8, 0x7e, 0xb5, - 0x68, 0x2e, 0xf1, 0xd6, 0x3c, 0x07, 0xb0, 0x23, 0x10, 0x1f, 0xa3, 0x07, 0x82, 0xf5, 0x38, 0x81, - 0x66, 0xc0, 0xb8, 0x6c, 0x52, 0x77, 0xbc, 0xc5, 0xfe, 0xa8, 0xaf, 0xef, 0x26, 0x5b, 0xcc, 0xe7, - 0x0d, 0x7b, 0x33, 0x09, 0x34, 0x18, 0x97, 0x35, 0x17, 0xbf, 0x42, 0xdb, 0x63, 0x60, 0xec, 0x70, - 0xd4, 0x23, 0x17, 0xf7, 0x28, 0x8e, 0xfa, 0x7a, 0x61, 0xae, 0xc7, 0x0c, 0x31, 0xec, 0xad, 0x24, - 0x76, 0x96, 0x84, 0x6a, 0x2e, 0x7e, 0x88, 0xd6, 0x04, 0xf5, 0x7c, 0xe0, 0x85, 0xff, 0x62, 0xbf, - 0xc7, 0x27, 0xac, 0xa2, 0x75, 0x0e, 0x1d, 0x27, 0x04, 0x2e, 0x0a, 0xff, 0x97, 0x72, 0x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x55, 0x32, 0x0c, 0x40, 0xb4, 0xd6, 0xe2, 0x77, 0xe8, 0xd9, 0x9f, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xe0, 0x4e, 0x96, 0x6f, 0x20, 0x05, 0x00, 0x00, + // 582 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xbf, 0x6f, 0xd3, 0x4e, + 0x18, 0xc6, 0xe3, 0xe6, 0xfb, 0x2d, 0xed, 0x51, 0x51, 0xf5, 0x9a, 0xd2, 0xd4, 0x8d, 0xec, 0xe0, + 0x01, 0x65, 0x20, 0x36, 0x0d, 0x42, 0x88, 0x2e, 0x55, 0x53, 0xa9, 0x22, 0x12, 0x91, 0x22, 0x8f, + 0x2c, 0x91, 0x73, 0x7e, 0xe3, 0x1e, 0x24, 0x3e, 0xeb, 0xee, 0x52, 0xe1, 0x95, 0x01, 0x21, 0x26, + 0x36, 0x18, 0xfb, 0x8f, 0xb0, 0x33, 0x76, 0x64, 0x8a, 0x50, 0xb2, 0x30, 0xe7, 0x2f, 0x40, 0xb6, + 0x93, 0xd4, 0x69, 0x7e, 0xa8, 0xb0, 0xf9, 0xee, 0xfd, 0xbc, 0xcf, 0xbd, 0xcf, 0xe3, 0xd3, 0xa1, + 0x22, 0x6d, 0x11, 0xcb, 0x09, 0x82, 0x0e, 0x25, 0x8e, 0xa4, 0xcc, 0x17, 0x56, 0x1b, 0xc0, 0xba, + 0x3c, 0xb2, 0xe4, 0x7b, 0x33, 0xe0, 0x4c, 0x32, 0xbc, 0x4f, 0x5b, 0xc4, 0x4c, 0x13, 0x66, 0x1b, + 0xc0, 0xbc, 0x3c, 0x52, 0x73, 0x1e, 0xf3, 0x58, 0xcc, 0x58, 0xd1, 0x57, 0x82, 0xab, 0x8f, 0x96, + 0x09, 0x46, 0x5d, 0x29, 0x84, 0x30, 0x0e, 0x16, 0xb9, 0x70, 0x7c, 0x1f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, 0x6a, 0x99, 0x9f, 0x43, 0x2d, 0xf3, 0xa6, 0xe2, 0x51, + 0x79, 0xd1, 0x6b, 0x99, 0x84, 0x75, 0x2d, 0xc2, 0x44, 0x97, 0x09, 0x8b, 0xb6, 0x48, 0xd9, 0x63, + 0x56, 0x97, 0xb9, 0xbd, 0x0e, 0x88, 0xe8, 0x49, 0x13, 0x56, 0xe5, 0x65, 0x39, 0x7a, 0xcd, 0x64, + 0x18, 0x80, 0x68, 0xad, 0xc7, 0x4f, 0xd5, 0xb3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x16, 0x4e, + 0x6f, 0x61, 0x43, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 79afc5cad30..becda5d14b1 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -61,7 +61,8 @@ message MsgPayPacketFeeAsync { option (gogoproto.goproto_getters) = false; // packet to pay fee for - ibc.applications.fee.v1.IdentifiedPacketFee identified_packet_fee = 1; + ibc.applications.fee.v1.IdentifiedPacketFee identified_packet_fee = 1 + [(gogoproto.moretags) = "yaml:\"identified_packet_fee\""]; // account address to refund fee if necessary string signer = 2; } From 2be4ab5aa86181b382172e42adc0caae75668a17 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 3 Nov 2021 12:45:35 +0100 Subject: [PATCH 30/50] nit: updating var names --- modules/apps/29-fee/keeper/escrow.go | 4 ++-- modules/apps/29-fee/keeper/escrow_test.go | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index e0835f98674..7e4aa9232e1 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -71,7 +71,7 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers } // DistributeFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee -func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { +func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, timeoutRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID) if !hasFee { @@ -94,7 +94,7 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer } // pay the timeout fee to the reverse relayer - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.TimeoutFee) + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, timeoutRelayer, feeInEscrow.Fee.TimeoutFee) if err != nil { return sdkerrors.Wrap(err, "error sending fee to timeout relayer") } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 05bc0ee7dc6..6ac4c25fa6b 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -99,7 +99,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { } } -func (suite *KeeperTestSuite) TestPayFee() { +func (suite *KeeperTestSuite) TestDistributeFee() { var ( err error ackFee sdk.Coins @@ -186,15 +186,14 @@ func (suite *KeeperTestSuite) TestPayFee() { } } -func (suite *KeeperTestSuite) TestPayTimeoutFee() { +func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { var ( - err error - ackFee sdk.Coins - receiveFee sdk.Coins - timeoutFee sdk.Coins - packetId *channeltypes.PacketId - reverseRelayer sdk.AccAddress - refundAcc sdk.AccAddress + err error + ackFee sdk.Coins + receiveFee sdk.Coins + timeoutFee sdk.Coins + packetId *channeltypes.PacketId + refundAcc sdk.AccAddress ) // refundAcc does not have balance for the following Coin @@ -225,7 +224,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { // setup refundAcc = suite.chainA.SenderAccount.GetAddress() - reverseRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + timeoutRelayer := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) ackFee = validCoins receiveFee = validCoins @@ -240,7 +239,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { tc.malleate() - err = suite.chainA.GetSimApp().IBCFeeKeeper.DistributeFeeTimeout(suite.chainA.GetContext(), refundAcc, reverseRelayer, packetId) + err = suite.chainA.GetSimApp().IBCFeeKeeper.DistributeFeeTimeout(suite.chainA.GetContext(), refundAcc, timeoutRelayer, packetId) if tc.expPass { suite.Require().NoError(err) @@ -248,7 +247,7 @@ func (suite *KeeperTestSuite) TestPayTimeoutFee() { // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) // check if the refund acc has been refunded - hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), reverseRelayer, validCoins[0]) + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), timeoutRelayer, validCoins[0]) suite.Require().True(hasBalance) // check the module acc wallet is now empty hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) From cb2cbc34c2b1de5c20860f4c3bbd5fcfb7ccea4d Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 3 Nov 2021 12:49:52 +0100 Subject: [PATCH 31/50] docs: godoc --- docs/ibc/proto-docs.md | 3 +++ modules/apps/29-fee/types/tx.pb.go | 3 +++ proto/ibc/applications/fee/v1/tx.proto | 3 +++ 3 files changed, 9 insertions(+) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 9f5397906cd..5d0b2255aa1 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -890,6 +890,8 @@ Query provides defines the gRPC querier service. ### MsgPayPacketFee MsgPayPacketFee defines the request type EscrowPacketFee RPC +This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be +paid for | Field | Type | Label | Description | @@ -909,6 +911,7 @@ MsgPayPacketFee defines the request type EscrowPacketFee RPC ### MsgPayPacketFeeAsync MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC +This Msg can be used to pay for a packet at a specified sequence (instead of the next sequence send) | Field | Type | Label | Description | diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 33d19dbe617..29e3e02077e 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -108,6 +108,8 @@ func (m *MsgRegisterCounterpartyAddressResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterCounterpartyAddressResponse proto.InternalMessageInfo // MsgPayPacketFee defines the request type EscrowPacketFee RPC +// This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be +// paid for type MsgPayPacketFee struct { Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` // source channel port identifier @@ -190,6 +192,7 @@ func (m *MsgPayPacketFeeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo // MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC +// This Msg can be used to pay for a packet at a specified sequence (instead of the next sequence send) type MsgPayPacketFeeAsync struct { // packet to pay fee for IdentifiedPacketFee *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee,omitempty" yaml:"identified_packet_fee"` diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index becda5d14b1..c9befa4861b 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -38,6 +38,8 @@ message MsgRegisterCounterpartyAddress { message MsgRegisterCounterpartyAddressResponse {} // MsgPayPacketFee defines the request type EscrowPacketFee RPC +// This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be +// paid for message MsgPayPacketFee { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; @@ -56,6 +58,7 @@ message MsgPayPacketFee { message MsgPayPacketFeeResponse {} // MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC +// This Msg can be used to pay for a packet at a specified sequence (instead of the next sequence send) message MsgPayPacketFeeAsync { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; From 66454c60da68978619dda133a1c406c97b5b9a2d Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 3 Nov 2021 13:19:18 +0100 Subject: [PATCH 32/50] refactor: IdentifiedPacketFee & Fee no longer pointers --- modules/apps/29-fee/keeper/escrow_test.go | 14 +- modules/apps/29-fee/keeper/msg_server.go | 2 +- modules/apps/29-fee/keeper/msg_server_test.go | 6 +- modules/apps/29-fee/types/fee.pb.go | 91 ++++++------ modules/apps/29-fee/types/keys.go | 4 +- modules/apps/29-fee/types/msgs.go | 6 +- modules/apps/29-fee/types/msgs_test.go | 16 +-- modules/apps/29-fee/types/tx.pb.go | 134 ++++++++---------- proto/ibc/applications/fee/v1/fee.proto | 2 +- proto/ibc/applications/fee/v1/tx.proto | 4 +- 10 files changed, 129 insertions(+), 150 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 6ac4c25fa6b..25f24641cc9 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -69,7 +69,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} tc.malleate() - fee := &types.Fee{ackFee, receiveFee, timeoutFee} + fee := types.Fee{ackFee, receiveFee, timeoutFee} identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} // refundAcc balance before escrow @@ -146,12 +146,12 @@ func (suite *KeeperTestSuite) TestDistributeFee() { receiveFee = validCoins timeoutFee = validCoins packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} - fee := &types.Fee{ackFee, receiveFee, timeoutFee} + fee := types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state - identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, &identifiedPacketFee) suite.Require().NoError(err) tc.malleate() @@ -230,11 +230,11 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { receiveFee = validCoins timeoutFee = validCoins packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} - fee := &types.Fee{ackFee, receiveFee, timeoutFee} + fee := types.Fee{ackFee, receiveFee, timeoutFee} // escrow the packet fee & store the fee in state - identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee) + identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, &identifiedPacketFee) suite.Require().NoError(err) tc.malleate() diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 60998e9f48e..e309444354b 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -74,7 +74,7 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket return &types.MsgPayPacketFeeAsyncResponse{}, err } - err = k.EscrowPacketFee(ctx, refundAccAddr, msg.IdentifiedPacketFee) + err = k.EscrowPacketFee(ctx, refundAccAddr, &msg.IdentifiedPacketFee) if err != nil { return nil, err } diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 72aafeda49c..c7f67d8950e 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -64,7 +64,7 @@ func (suite *KeeperTestSuite) TestPayPacketFee() { SetupFeePath(suite.path) refundAcc := suite.chainA.SenderAccount.GetAddress() channelID := suite.path.EndpointA.ChannelID - fee := &types.Fee{validCoins, validCoins, validCoins} + fee := types.Fee{validCoins, validCoins, validCoins} msg := types.NewMsgPayPacketFee(fee, suite.path.EndpointA.ChannelConfig.PortID, channelID, refundAcc.String(), []string{}) tc.malleate() @@ -101,12 +101,12 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { // build packetId channelID := suite.path.EndpointA.ChannelID - fee := &types.Fee{validCoins, validCoins, validCoins} + fee := types.Fee{validCoins, validCoins, validCoins} seq, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(ctxA, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) // build fee packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: suite.path.EndpointA.ChannelConfig.PortID, Sequence: seq} - identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} + identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} tc.malleate() diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 5894b21373c..23c7abecd4d 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -92,7 +92,7 @@ func (m *Fee) GetTimeoutFee() github_com_cosmos_cosmos_sdk_types.Coins { // Fee associated with a packet_id type IdentifiedPacketFee struct { PacketId *types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id,omitempty" yaml:"packet_id"` - Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` + Fee Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee"` Relayers []string `protobuf:"bytes,3,rep,name=relayers,proto3" json:"relayers,omitempty"` } @@ -136,11 +136,11 @@ func (m *IdentifiedPacketFee) GetPacketId() *types1.PacketId { return nil } -func (m *IdentifiedPacketFee) GetFee() *Fee { +func (m *IdentifiedPacketFee) GetFee() Fee { if m != nil { return m.Fee } - return nil + return Fee{} } func (m *IdentifiedPacketFee) GetRelayers() []string { @@ -158,35 +158,35 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 438 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xbd, 0x8a, 0x1b, 0x31, - 0x10, 0xc7, 0xad, 0x2c, 0x5c, 0xee, 0x64, 0x08, 0x61, 0x73, 0x90, 0x8b, 0x49, 0xd6, 0x97, 0xad, - 0xdc, 0x58, 0xc2, 0x4e, 0x95, 0x94, 0x0e, 0x2c, 0x1c, 0xa4, 0x38, 0xb6, 0x4c, 0x73, 0x68, 0xb5, - 0xe3, 0x3d, 0xb1, 0x1f, 0x5a, 0x56, 0xf2, 0x82, 0xdb, 0x34, 0x69, 0xf3, 0x1c, 0x69, 0xf3, 0x12, - 0x57, 0x5e, 0x99, 0xca, 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0x74, - 0xda, 0xb7, 0x2b, 0x03, 0x00, 0x00, + // 443 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcd, 0x6e, 0x13, 0x31, + 0x10, 0xc7, 0x63, 0x16, 0x95, 0xd6, 0x91, 0x10, 0x5a, 0x2a, 0x51, 0x22, 0xd8, 0x94, 0x3d, 0xe5, + 0x12, 0x5b, 0x09, 0x5c, 0xe0, 0xb8, 0x48, 0x91, 0x2a, 0x71, 0xa8, 0xf6, 0xc8, 0xa5, 0xf2, 0x7a, + 0x27, 0x5b, 0x6b, 0x3f, 0xbc, 0x5a, 0x3b, 0x2b, 0xe5, 0xca, 0x85, 0x2b, 0xcf, 0xc1, 0x1b, 0xf0, + 0x06, 0x3d, 0xf6, 0xc8, 0x29, 0xa0, 0xe4, 0x0d, 0xfa, 0x04, 0xc8, 0x1f, 0xad, 0x22, 0x21, 0x84, + 0x72, 0xf2, 0xd8, 0x9e, 0xbf, 0x7f, 0x33, 0xe3, 0x19, 0xfc, 0x46, 0x64, 0x9c, 0xb2, 0xb6, 0xad, + 0x04, 0x67, 0x5a, 0xc8, 0x46, 0xd1, 0x25, 0x00, 0xed, 0x67, 0x66, 0x21, 0x6d, 0x27, 0xb5, 0x0c, + 0x5f, 0x88, 0x8c, 0x93, 0x7d, 0x17, 0x62, 0xee, 0xfa, 0xd9, 0x28, 0xe2, 0x52, 0xd5, 0x52, 0xd1, + 0x8c, 0x29, 0x23, 0xc9, 0x40, 0xb3, 0x19, 0xe5, 0x52, 0x34, 0x4e, 0x38, 0x3a, 0x2d, 0x64, 0x21, + 0xad, 0x49, 0x8d, 0xe5, 0x4f, 0x2d, 0x91, 0xcb, 0x0e, 0x28, 0xbf, 0x66, 0x4d, 0x03, 0x95, 0xa1, + 0x79, 0xd3, 0xb9, 0xc4, 0x5f, 0x03, 0x1c, 0x2c, 0x00, 0xc2, 0x2f, 0x08, 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x47, 0xcf, 0x91, 0x05, 0x40, 0xf2, 0xd8, 0x24, 0x9a, 0x1a, 0xf7, 0x70, 0x84, 0x8f, 0x3b, 0xa8, + 0xd8, 0x1a, 0x3a, 0x65, 0x0b, 0x74, 0x92, 0x3e, 0xec, 0x93, 0x4f, 0x37, 0xdb, 0x08, 0xdd, 0x6e, + 0x23, 0xf4, 0x7b, 0x1b, 0xa1, 0x6f, 0xbb, 0x68, 0x70, 0xbb, 0x8b, 0x06, 0x3f, 0x77, 0xd1, 0xe0, + 0xf3, 0xfc, 0xef, 0x5a, 0x88, 0x8c, 0x4f, 0x0b, 0x49, 0x6b, 0x99, 0xaf, 0x2a, 0x50, 0x66, 0x22, + 0x14, 0x9d, 0xbf, 0x9f, 0x9a, 0x61, 0xb0, 0xb5, 0xc9, 0x8e, 0x6c, 0x6b, 0xbe, 0xfd, 0x13, 0x00, + 0x00, 0xff, 0xff, 0x80, 0x3a, 0xb6, 0x74, 0x31, 0x03, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -283,18 +283,16 @@ func (m *IdentifiedPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x1a } } - if m.Fee != nil { - { - size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintFee(dAtA, i, uint64(size)) + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if m.PacketId != nil { { size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) @@ -358,10 +356,8 @@ func (m *IdentifiedPacketFee) Size() (n int) { l = m.PacketId.Size() n += 1 + l + sovFee(uint64(l)) } - if m.Fee != nil { - l = m.Fee.Size() - n += 1 + l + sovFee(uint64(l)) - } + l = m.Fee.Size() + n += 1 + l + sovFee(uint64(l)) if len(m.Relayers) > 0 { for _, s := range m.Relayers { l = len(s) @@ -623,9 +619,6 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Fee == nil { - m.Fee = &Fee{} - } if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 7a6d4050781..174168a32b0 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -46,6 +46,6 @@ func KeyRelayerAddress(address string) []byte { } // KeyFeeInEscrow returns the key for escrowed fees -func KeyFeeInEscrow(packetId *channeltypes.PacketId) []byte { - return []byte(fmt.Sprintf("%s/%s/%s/packet/%d", FeeInEscrowPrefix, packetId.PortId, packetId.ChannelId, packetId.Sequence)) +func KeyFeeInEscrow(packetID *channeltypes.PacketId) []byte { + return []byte(fmt.Sprintf("%s/%s/%s/packet/%d", FeeInEscrowPrefix, packetID.PortId, packetID.ChannelId, packetID.Sequence)) } diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 446de5e1312..32e510c15a8 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -45,7 +45,7 @@ func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress { } // NewMsgPayPacketFee creates a new instance of MsgPayPacketFee -func NewMsgPayPacketFee(fee *Fee, sourcePortId, sourceChannelId, signer string, relayers []string) *MsgPayPacketFee { +func NewMsgPayPacketFee(fee Fee, sourcePortId, sourceChannelId, signer string, relayers []string) *MsgPayPacketFee { return &MsgPayPacketFee{ Fee: fee, SourcePortId: sourcePortId, @@ -93,7 +93,7 @@ func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress { } // NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee -func NewMsgPayPacketFeeAsync(identifiedPacketFee *IdentifiedPacketFee, signer string) *MsgPayPacketFeeAsync { +func NewMsgPayPacketFeeAsync(identifiedPacketFee IdentifiedPacketFee, signer string) *MsgPayPacketFeeAsync { return &MsgPayPacketFeeAsync{ IdentifiedPacketFee: identifiedPacketFee, Signer: signer, @@ -142,7 +142,7 @@ func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{signer} } -func NewIdentifiedPacketFee(packetId *channeltypes.PacketId, fee *Fee, relayers []string) *IdentifiedPacketFee { +func NewIdentifiedPacketFee(packetId *channeltypes.PacketId, fee Fee, relayers []string) *IdentifiedPacketFee { return &IdentifiedPacketFee{ PacketId: packetId, Fee: fee, diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index fe1519560e5..df9d5e57911 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -58,7 +58,7 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { signer string channelID string portID string - fee *Fee + fee Fee relayers []string ) @@ -107,7 +107,7 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { signer = validAddr channelID = validChannelID portID = validPortID - fee = &Fee{validCoins, validCoins, validCoins} + fee = Fee{validCoins, validCoins, validCoins} relayers = nil // malleate @@ -131,7 +131,7 @@ func TestPayPacketFeeGetSigners(t *testing.T) { signer := addr.String() channelID := validChannelID portID := validPortID - fee := &Fee{validCoins, validCoins, validCoins} + fee := Fee{validCoins, validCoins, validCoins} msg := NewMsgPayPacketFee(fee, portID, channelID, signer, nil) // GetSigners @@ -146,7 +146,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { signer string channelID string portID string - fee *Fee + fee Fee relayers []string seq uint64 ) @@ -203,7 +203,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { signer = validAddr channelID = validChannelID portID = validPortID - fee = &Fee{validCoins, validCoins, validCoins} + fee = Fee{validCoins, validCoins, validCoins} relayers = nil seq = 1 @@ -211,7 +211,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { tc.malleate() packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: portID, Sequence: seq} - identifiedPacketFee := &IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: relayers} + identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: relayers} msg := NewMsgPayPacketFeeAsync(identifiedPacketFee, signer) err := msg.ValidateBasic() @@ -230,10 +230,10 @@ func TestPayPacketFeeAsyncGetSigners(t *testing.T) { // build message channelID := validChannelID portID := validPortID - fee := &Fee{validCoins, validCoins, validCoins} + fee := Fee{validCoins, validCoins, validCoins} seq := uint64(1) packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: portID, Sequence: seq} - identifiedPacketFee := &IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: nil} + identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: nil} msg := NewMsgPayPacketFeeAsync(identifiedPacketFee, addr.String()) // GetSigners diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 29e3e02077e..4b73f291954 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -111,7 +111,7 @@ var xxx_messageInfo_MsgRegisterCounterpartyAddressResponse proto.InternalMessage // This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be // paid for type MsgPayPacketFee struct { - Fee *Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + Fee Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee"` // source channel port identifier SourcePortId string `protobuf:"bytes,2,opt,name=source_port_id,json=sourcePortId,proto3" json:"source_port_id,omitempty" yaml:"source_port_id"` // source channel unique identifier @@ -195,7 +195,7 @@ var xxx_messageInfo_MsgPayPacketFeeResponse proto.InternalMessageInfo // This Msg can be used to pay for a packet at a specified sequence (instead of the next sequence send) type MsgPayPacketFeeAsync struct { // packet to pay fee for - IdentifiedPacketFee *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee,omitempty" yaml:"identified_packet_fee"` + IdentifiedPacketFee IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee" yaml:"identified_packet_fee"` // account address to refund fee if necessary Signer string `protobuf:"bytes,2,opt,name=signer,proto3" json:"signer,omitempty"` } @@ -282,44 +282,44 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 582 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xbf, 0x6f, 0xd3, 0x4e, - 0x18, 0xc6, 0xe3, 0xe6, 0xfb, 0x2d, 0xed, 0x51, 0x51, 0xf5, 0x9a, 0xd2, 0xd4, 0x8d, 0xec, 0xe0, - 0x01, 0x65, 0x20, 0x36, 0x0d, 0x42, 0x88, 0x2e, 0x55, 0x53, 0xa9, 0x22, 0x12, 0x91, 0x22, 0x8f, - 0x2c, 0x91, 0x73, 0x7e, 0xe3, 0x1e, 0x24, 0x3e, 0xeb, 0xee, 0x52, 0xe1, 0x95, 0x01, 0x21, 0x26, - 0x36, 0x18, 0xfb, 0x8f, 0xb0, 0x33, 0x76, 0x64, 0x8a, 0x50, 0xb2, 0x30, 0xe7, 0x2f, 0x40, 0xb6, - 0x93, 0xd4, 0x69, 0x7e, 0xa8, 0xb0, 0xf9, 0xee, 0xfd, 0xbc, 0xcf, 0xbd, 0xcf, 0xe3, 0xd3, 0xa1, - 0x22, 0x6d, 0x11, 0xcb, 0x09, 0x82, 0x0e, 0x25, 0x8e, 0xa4, 0xcc, 0x17, 0x56, 0x1b, 0xc0, 0xba, - 0x3c, 0xb2, 0xe4, 0x7b, 0x33, 0xe0, 0x4c,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 0x4e, 0xcf, 0x0a, 0xd1, 0xce, 0xfc, 0x9f, 0x2e, 0xdf, 0x55, 0x26, 0xc6, 0xd5, - 0xe7, 0x7f, 0x85, 0x4f, 0x8e, 0xae, 0xbe, 0xfe, 0x31, 0xd0, 0x94, 0xeb, 0x81, 0xa6, 0xfc, 0x1a, - 0x68, 0xca, 0x97, 0xa1, 0x96, 0xb9, 0x1e, 0x6a, 0x99, 0x9f, 0x43, 0x2d, 0xf3, 0xa6, 0xe2, 0x51, - 0x79, 0xd1, 0x6b, 0x99, 0x84, 0x75, 0x2d, 0xc2, 0x44, 0x97, 0x09, 0x8b, 0xb6, 0x48, 0xd9, 0x63, - 0x56, 0x97, 0xb9, 0xbd, 0x0e, 0x88, 0xe8, 0x49, 0x13, 0x56, 0xe5, 0x65, 0x39, 0x7a, 0xcd, 0x64, - 0x18, 0x80, 0x68, 0xad, 0xc7, 0x4f, 0xd5, 0xb3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x16, 0x4e, - 0x6f, 0x61, 0x43, 0x05, 0x00, 0x00, + // 589 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6f, 0xd3, 0x3e, + 0x18, 0xc7, 0x93, 0x75, 0xbf, 0xfd, 0x36, 0x33, 0x31, 0x2d, 0xeb, 0x58, 0x97, 0x55, 0x49, 0x89, + 0x10, 0xea, 0x81, 0x26, 0xac, 0x80, 0x10, 0xbb, 0x4c, 0xeb, 0xa4, 0x89, 0x4a, 0x54, 0xaa, 0x72, + 0xe4, 0x52, 0xa5, 0xce, 0xd3, 0xcc, 0xd0, 0xc6, 0x91, 0xed, 0x4e, 0xe4, 0x0d, 0x4c, 0x1c, 0x77, + 0x83, 0xe3, 0xde, 0x0a, 0xb7, 0x1d, 0x77, 0xe4, 0x54, 0xa1, 0xf6, 0xc2, 0xb9, 0xaf, 0x00, 0x25, + 0x69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 0xca, 0xcf, 0xb3, + 0x30, 0xf6, 0x58, 0xbe, 0xcc, 0xa0, 0x4c, 0x8d, 0x7b, 0xca, 0x37, 0x19, 0x1d, 0x2c, 0x7b, 0xdb, + 0x6f, 0x17, 0x5a, 0x5a, 0xfe, 0xf4, 0xd4, 0xe3, 0x7f, 0x6c, 0x1c, 0x9f, 0x50, 0xf9, 0x84, 0x36, + 0xa7, 0xde, 0x6b, 0x71, 0x99, 0x60, 0x9a, 0x54, 0x5f, 0x3e, 0x94, 0x9c, 0xec, 0x15, 0xa2, 0xed, + 0xd9, 0xdb, 0x2e, 0x3d, 0x54, 0x26, 0xc6, 0xd5, 0x37, 0x7f, 0x85, 0x8f, 0xb7, 0xae, 0x7c, 0xb8, + 0xe9, 0x6b, 0xf2, 0x6d, 0x5f, 0x93, 0x7f, 0xf5, 0x35, 0xf9, 0x6a, 0xa0, 0x49, 0xb7, 0x03, 0x4d, + 0xfa, 0x39, 0xd0, 0xa4, 0x8f, 0x65, 0x8f, 0x88, 0xf3, 0x6e, 0xd3, 0xc4, 0xb4, 0x63, 0x61, 0xca, + 0x3b, 0x94, 0x5b, 0xa4, 0x89, 0x4b, 0x1e, 0xb5, 0x3a, 0xd4, 0xed, 0xb6, 0x81, 0x47, 0x9f, 0x1b, + 0xb7, 0xca, 0xef, 0x4a, 0xd1, 0xbf, 0x26, 0xc2, 0x00, 0x78, 0x73, 0x2d, 0xfe, 0xb4, 0x5e, 0xfd, + 0x09, 0x00, 0x00, 0xff, 0xff, 0xa7, 0xcb, 0x98, 0x2b, 0x4d, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -606,18 +606,16 @@ func (m *MsgPayPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if m.Fee != nil { - { - size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -671,18 +669,16 @@ func (m *MsgPayPacketFeeAsync) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if m.IdentifiedPacketFee != nil { - { - size, err := m.IdentifiedPacketFee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + { + size, err := m.IdentifiedPacketFee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -752,10 +748,8 @@ func (m *MsgPayPacketFee) Size() (n int) { } var l int _ = l - if m.Fee != nil { - l = m.Fee.Size() - n += 1 + l + sovTx(uint64(l)) - } + l = m.Fee.Size() + n += 1 + l + sovTx(uint64(l)) l = len(m.SourcePortId) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -792,10 +786,8 @@ func (m *MsgPayPacketFeeAsync) Size() (n int) { } var l int _ = l - if m.IdentifiedPacketFee != nil { - l = m.IdentifiedPacketFee.Size() - n += 1 + l + sovTx(uint64(l)) - } + l = m.IdentifiedPacketFee.Size() + n += 1 + l + sovTx(uint64(l)) l = len(m.Signer) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -1040,9 +1032,6 @@ func (m *MsgPayPacketFee) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Fee == nil { - m.Fee = &Fee{} - } if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1304,9 +1293,6 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.IdentifiedPacketFee == nil { - m.IdentifiedPacketFee = &IdentifiedPacketFee{} - } if err := m.IdentifiedPacketFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index e2b4cce066d..121eae2dca4 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -29,6 +29,6 @@ message Fee { // Fee associated with a packet_id message IdentifiedPacketFee { ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.moretags) = "yaml:\"packet_id\""]; - Fee fee = 2; + Fee fee = 2 [(gogoproto.nullable) = false]; repeated string relayers = 3; } diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index c9befa4861b..fd9a338fb04 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -44,7 +44,7 @@ message MsgPayPacketFee { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - ibc.applications.fee.v1.Fee fee = 1; + ibc.applications.fee.v1.Fee fee = 1 [(gogoproto.nullable) = false]; // source channel port identifier string source_port_id = 2 [(gogoproto.moretags) = "yaml:\"source_port_id\""]; // source channel unique identifier @@ -65,7 +65,7 @@ message MsgPayPacketFeeAsync { // packet to pay fee for ibc.applications.fee.v1.IdentifiedPacketFee identified_packet_fee = 1 - [(gogoproto.moretags) = "yaml:\"identified_packet_fee\""]; + [(gogoproto.moretags) = "yaml:\"identified_packet_fee\"", (gogoproto.nullable) = false]; // account address to refund fee if necessary string signer = 2; } From 06d4c25cd1042335a8a8be2280dc7a58b97c3099 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 3 Nov 2021 14:26:57 +0100 Subject: [PATCH 33/50] fixes: small fixes --- modules/apps/29-fee/keeper/escrow.go | 4 ++-- modules/apps/29-fee/keeper/keeper.go | 3 +-- modules/apps/29-fee/keeper/msg_server.go | 7 +++--- modules/apps/29-fee/keeper/msg_server_test.go | 24 +++++++++++-------- modules/apps/29-fee/types/codec.go | 4 +--- modules/apps/29-fee/types/errors.go | 10 ++++---- modules/apps/29-fee/types/msgs.go | 1 + 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 7e4aa9232e1..7fd76a5cd64 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -16,7 +16,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, ident // check if the refund account exists hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) if hasRefundAcc == nil { - return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc.String())) + return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc)) } coins := identifiedFee.Fee.AckFee @@ -40,7 +40,7 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers // check if there is a Fee in escrow for the given packetId feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) if !found { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("with channelID: %s, sequenceId %d", packetID.ChannelId, packetID.Sequence)) } // get module accAddr diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 74f8920ca53..533ac58e3c4 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -75,7 +75,7 @@ func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) ( return k.channelKeeper.GetNextSequenceSend(ctx, portID, channelID) } -// GetFeeAccount returns the ICS29 - fee ModuleAccount address +// GetFeeAccount returns the ICS29 Fee ModuleAccount address func (k Keeper) GetFeeModuleAddress() sdk.AccAddress { return k.authKeeper.GetModuleAddress(types.ModuleName) } @@ -140,7 +140,6 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) if bz == nil { return types.IdentifiedPacketFee{}, false } - fee := k.MustUnmarshalFee(bz) return fee, true diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index e309444354b..2b2cf0736f5 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -5,9 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" - "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ) var _ types.MsgServer = Keeper{} @@ -51,7 +50,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) refundAccAddr, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return &types.MsgPayPacketFeeResponse{}, err + return nil, err } identifiedPacket := types.NewIdentifiedPacketFee(packetId, msg.Fee, msg.Relayers) @@ -71,7 +70,7 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket refundAccAddr, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return &types.MsgPayPacketFeeAsyncResponse{}, err + return nil, err } err = k.EscrowPacketFee(ctx, refundAccAddr, &msg.IdentifiedPacketFee) diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index c7f67d8950e..3766f4f9105 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -7,8 +7,8 @@ import ( func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { var ( - addr string - addr2 string + sender string + counterparty string ) testCases := []struct { @@ -27,9 +27,9 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { suite.SetupTest() ctx := suite.chainA.GetContext() - addr = suite.chainA.SenderAccount.GetAddress().String() - addr2 = suite.chainB.SenderAccount.GetAddress().String() - msg := types.NewMsgRegisterCounterpartyAddress(addr, addr2) + sender = suite.chainA.SenderAccount.GetAddress().String() + counterparty = suite.chainB.SenderAccount.GetAddress().String() + msg := types.NewMsgRegisterCounterpartyAddress(sender, counterparty) tc.malleate() _, err := suite.chainA.SendMsgs(msg) @@ -38,7 +38,7 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { suite.Require().NoError(err) // message committed counterpartyAddress, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(ctx, suite.chainA.SenderAccount.GetAddress().String()) - suite.Require().Equal(addr2, counterpartyAddress) + suite.Require().Equal(counterparty, counterpartyAddress) } else { suite.Require().Error(err) } @@ -61,14 +61,16 @@ func (suite *KeeperTestSuite) TestPayPacketFee() { for _, tc := range testCases { suite.SetupTest() suite.coordinator.SetupConnections(suite.path) - SetupFeePath(suite.path) + err := SetupFeePath(suite.path) + suite.Require().NoError(err) + refundAcc := suite.chainA.SenderAccount.GetAddress() channelID := suite.path.EndpointA.ChannelID fee := types.Fee{validCoins, validCoins, validCoins} msg := types.NewMsgPayPacketFee(fee, suite.path.EndpointA.ChannelConfig.PortID, channelID, refundAcc.String(), []string{}) tc.malleate() - _, err := suite.chainA.SendMsgs(msg) + _, err = suite.chainA.SendMsgs(msg) if tc.expPass { suite.Require().NoError(err) // message committed @@ -94,7 +96,9 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { for _, tc := range testCases { suite.SetupTest() suite.coordinator.SetupConnections(suite.path) - SetupFeePath(suite.path) + err := SetupFeePath(suite.path) + suite.Require().NoError(err) + ctxA := suite.chainA.GetContext() refundAcc := suite.chainA.SenderAccount.GetAddress() @@ -111,7 +115,7 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { tc.malleate() msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee, refundAcc.String()) - _, err := suite.chainA.SendMsgs(msg) + _, err = suite.chainA.SendMsgs(msg) if tc.expPass { suite.Require().NoError(err) // message committed diff --git a/modules/apps/29-fee/types/codec.go b/modules/apps/29-fee/types/codec.go index b0561bed263..846716d740f 100644 --- a/modules/apps/29-fee/types/codec.go +++ b/modules/apps/29-fee/types/codec.go @@ -18,9 +18,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // RegisterInterfaces register the 29-fee module interfaces to protobuf // Any. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { - registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterCounterpartyAddress{}) - registry.RegisterImplementations((*sdk.Msg)(nil), &MsgPayPacketFee{}) - registry.RegisterImplementations((*sdk.Msg)(nil), &MsgPayPacketFeeAsync{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterCounterpartyAddress{}, &MsgPayPacketFee{}, &MsgPayPacketFeeAsync{}) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 57a32ce23bd..07a5ef985f2 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -6,9 +6,9 @@ import ( // 29-fee sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 1, "invalid ICS29 middleware version") - ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 2, "no account found for given refund address") - ErrBalanceNotFound = sdkerrors.Register(ModuleName, 3, "balance not found for given account address") - ErrFeeNotFound = sdkerrors.Register(ModuleName, 4, "there is no fee escrowed for the given packetId") - ErrRelayersNotNil = sdkerrors.Register(ModuleName, 5, "relayers must be nil. This feature is not supported") + ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") + ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 3, "no account found for given refund address") + ErrBalanceNotFound = sdkerrors.Register(ModuleName, 4, "balance not found for given account address") + ErrFeeNotFound = sdkerrors.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") + ErrRelayersNotNil = sdkerrors.Register(ModuleName, 6, "relayers must be nil. This feature is not supported") ) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 32e510c15a8..32dcf4c566d 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -3,6 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/modules/core/24-host" ) From f336ca775363541a990b2639656f424aaa4d25d8 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:07:19 +0100 Subject: [PATCH 34/50] Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: Aditya --- modules/apps/29-fee/keeper/escrow.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 7fd76a5cd64..61315307e97 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -19,8 +19,8 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, ident return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc)) } - coins := identifiedFee.Fee.AckFee - coins = coins.Add(identifiedFee.Fee.ReceiveFee...) + coins := identifiedFee.Fee.ReceiveFee + coins = coins.Add(identifiedFee.Fee.AckFee...) coins = coins.Add(identifiedFee.Fee.TimeoutFee...) if err := k.bankKeeper.SendCoinsFromAccountToModule( From 8e2eb8fd9bc5df4ccf7485cf6d3ef5d0756b0d04 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:07:42 +0100 Subject: [PATCH 35/50] Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: Aditya --- modules/apps/29-fee/keeper/escrow.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 61315307e97..417566e53f4 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -81,17 +81,17 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, timeoutRelayer // get module accAddr feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) - // refund the ack fee - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) - if err != nil { - return sdkerrors.Wrap(err, "error refunding ack fee") - } - // refund the receive fee err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee) if err != nil { return sdkerrors.Wrap(err, "error refunding receive fee") } + + // refund the ack fee + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) + if err != nil { + return sdkerrors.Wrap(err, "error refunding ack fee") + } // pay the timeout fee to the reverse relayer err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, timeoutRelayer, feeInEscrow.Fee.TimeoutFee) From 52fa63ecb0af698c7e1c60c8a02b033761a90dd4 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:08:06 +0100 Subject: [PATCH 36/50] Update modules/apps/29-fee/keeper/keeper.go Co-authored-by: Aditya --- modules/apps/29-fee/keeper/keeper.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 533ac58e3c4..b7e8e0db91a 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -157,11 +157,7 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) store := ctx.KVStore(k.storeKey) key := types.KeyFeeInEscrow(packetId) - if !store.Has(key) { - return false - } - - return true + return store.Has(key) } // MustMarshalFee attempts to encode a Fee object and returns the From 0587a3c8f9aea9d20816c2f4fec165a993c2bc46 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:09:12 +0100 Subject: [PATCH 37/50] Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: Aditya --- modules/apps/29-fee/keeper/msg_server.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 2b2cf0736f5..58c0cf1a369 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -17,10 +17,6 @@ var _ types.MsgServer = Keeper{} func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - counterpartyAddress, err := sdk.AccAddressFromBech32(msg.CounterpartyAddress) - if err != nil { - return &types.MsgRegisterCounterpartyAddressResponse{}, err - } k.SetCounterpartyAddress( ctx, msg.Address, counterpartyAddress.String(), From 63e7a1a401d67b161788cd6d8deda958ad1a2e77 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:09:31 +0100 Subject: [PATCH 38/50] Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: Aditya --- 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 58c0cf1a369..17012f47374 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -19,7 +19,7 @@ func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.Ms k.SetCounterpartyAddress( - ctx, msg.Address, counterpartyAddress.String(), + ctx, msg.Address, msg.CounterpartyAddress, ) k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress) From a40159ff4c6427389f1a03655981923bd64c88d9 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:10:00 +0100 Subject: [PATCH 39/50] Update modules/apps/29-fee/types/msgs.go Co-authored-by: Aditya --- 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 32dcf4c566d..cc88ba56239 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -126,7 +126,7 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error { return ErrRelayersNotNil } - // enforce relayer is nil + // ensure sequence is not 0 if msg.IdentifiedPacketFee.PacketId.Sequence == 0 { return sdkerrors.ErrInvalidSequence } From f379aaf4ee06968863a5993d16e75c782b8a54a1 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 4 Nov 2021 17:15:14 +0100 Subject: [PATCH 40/50] nit: proto doc & error fix --- docs/ibc/proto-docs.md | 2 +- modules/apps/29-fee/keeper/escrow.go | 6 +++--- modules/apps/29-fee/types/tx.pb.go | 2 +- proto/ibc/applications/fee/v1/tx.proto | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 5d0b2255aa1..52f2a145f8f 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -889,7 +889,7 @@ Query provides defines the gRPC querier service. ### MsgPayPacketFee -MsgPayPacketFee defines the request type EscrowPacketFee RPC +MsgPayPacketFee defines the request type PayPacketFee RPC This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be paid for diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 417566e53f4..6ffac5c3f99 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -82,13 +82,13 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, timeoutRelayer feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) // refund the receive fee - err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee) + err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee) if err != nil { return sdkerrors.Wrap(err, "error refunding receive fee") } - + // refund the ack fee - err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) + err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) if err != nil { return sdkerrors.Wrap(err, "error refunding ack fee") } diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index 4b73f291954..7e27acc666a 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -107,7 +107,7 @@ func (m *MsgRegisterCounterpartyAddressResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterCounterpartyAddressResponse proto.InternalMessageInfo -// MsgPayPacketFee defines the request type EscrowPacketFee RPC +// MsgPayPacketFee defines the request type PayPacketFee RPC // This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be // paid for type MsgPayPacketFee struct { diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index fd9a338fb04..31163483d4d 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -37,7 +37,7 @@ message MsgRegisterCounterpartyAddress { // MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type message MsgRegisterCounterpartyAddressResponse {} -// MsgPayPacketFee defines the request type EscrowPacketFee RPC +// MsgPayPacketFee defines the request type PayPacketFee RPC // This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be // paid for message MsgPayPacketFee { From 2f649a8d9053770a2a28e16c07a6f3c1d204cb06 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 10:38:15 +0100 Subject: [PATCH 41/50] fix: escrow test --- modules/apps/29-fee/keeper/escrow_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 25f24641cc9..c162ca60077 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -170,7 +170,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), forwardRelayer, validCoins[0]) suite.Require().True(hasBalance) // check the module acc wallet is now empty - hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) suite.Require().True(hasBalance) suite.Require().NoError(err) @@ -246,11 +246,11 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetId) // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) - // check if the refund acc has been refunded + // check if the timeoutRelayer has been paid hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), timeoutRelayer, validCoins[0]) suite.Require().True(hasBalance) // check the module acc wallet is now empty - hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) suite.Require().True(hasBalance) } else { From b100ee08d0395cf2264d6f0200dfe415e05f698a Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 11:10:07 +0100 Subject: [PATCH 42/50] test: updating distribute fee tests --- modules/apps/29-fee/keeper/escrow_test.go | 43 ++++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index c162ca60077..2d390079bc2 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -9,6 +9,8 @@ import ( var ( validCoins = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} + validCoins2 = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(200)}} + validCoins3 = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}} invalidCoins = sdk.Coins{sdk.Coin{Denom: "invalidDenom", Amount: sdk.NewInt(100)}} ) @@ -64,8 +66,8 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { // setup refundAcc = suite.chainA.SenderAccount.GetAddress() ackFee = validCoins - receiveFee = validCoins - timeoutFee = validCoins + receiveFee = validCoins2 + timeoutFee = validCoins3 packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} tc.malleate() @@ -85,9 +87,9 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { suite.Require().True(feeInEscrow.Fee.ReceiveFee.IsEqual(fee.ReceiveFee)) suite.Require().True(feeInEscrow.Fee.TimeoutFee.IsEqual(fee.TimeoutFee)) // check if the fee is escrowed correctly - hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(300)}) + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(600)}) suite.Require().True(hasBalance) - expectedBal := originalBal.Amount.Sub(sdk.NewInt(300)) + expectedBal := originalBal.Amount.Sub(sdk.NewInt(600)) // check if the refund acc has sent the fee hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: expectedBal}) suite.Require().True(hasBalance) @@ -143,10 +145,10 @@ func (suite *KeeperTestSuite) TestDistributeFee() { forwardRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) ackFee = validCoins - receiveFee = validCoins - timeoutFee = validCoins + receiveFee = validCoins2 + timeoutFee = validCoins3 packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} - fee := types.Fee{ackFee, receiveFee, timeoutFee} + fee := types.Fee{receiveFee, ackFee, timeoutFee} // escrow the packet fee & store the fee in state identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} @@ -156,6 +158,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() { tc.malleate() + // refundAcc balance after escrow + refundAccBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom) + err = suite.chainA.GetSimApp().IBCFeeKeeper.DistributeFee(suite.chainA.GetContext(), refundAcc, forwardRelayer, reverseRelayer, packetId) if tc.expPass { @@ -164,10 +169,14 @@ func (suite *KeeperTestSuite) TestDistributeFee() { // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) // check if the reverse relayer is paid - hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), reverseRelayer, validCoins[0]) + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), reverseRelayer, ackFee[0]) suite.Require().True(hasBalance) // check if the forward relayer is paid - hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), forwardRelayer, validCoins[0]) + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), forwardRelayer, receiveFee[0]) + suite.Require().True(hasBalance) + // check if the refund acc has been refunded the timeoutFee + expectedRefundAccBal := refundAccBal.Add(timeoutFee[0]) + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, expectedRefundAccBal) suite.Require().True(hasBalance) // check the module acc wallet is now empty hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) @@ -227,10 +236,10 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { timeoutRelayer := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) ackFee = validCoins - receiveFee = validCoins - timeoutFee = validCoins + receiveFee = validCoins2 + timeoutFee = validCoins3 packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} - fee := types.Fee{ackFee, receiveFee, timeoutFee} + fee := types.Fee{receiveFee, ackFee, timeoutFee} // escrow the packet fee & store the fee in state identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}} @@ -239,6 +248,9 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { tc.malleate() + // refundAcc balance after escrow + refundAccBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom) + err = suite.chainA.GetSimApp().IBCFeeKeeper.DistributeFeeTimeout(suite.chainA.GetContext(), refundAcc, timeoutRelayer, packetId) if tc.expPass { @@ -247,7 +259,12 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { // there should no longer be a fee in escrow for this packet suite.Require().False(hasFeeInEscrow) // check if the timeoutRelayer has been paid - hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), timeoutRelayer, validCoins[0]) + hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), timeoutRelayer, timeoutFee[0]) + suite.Require().True(hasBalance) + // check if the refund acc has been refunded the recv & ack fees + expectedRefundAccBal := refundAccBal.Add(ackFee[0]) + expectedRefundAccBal = refundAccBal.Add(receiveFee[0]) + hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), refundAcc, expectedRefundAccBal) suite.Require().True(hasBalance) // check the module acc wallet is now empty hasBalance = suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress(), sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(0)}) From b19ebd26f0226cc826294c039b85be916cac773e Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 12:07:14 +0100 Subject: [PATCH 43/50] test: adding validation check for fee and updating tests --- modules/apps/29-fee/keeper/msg_server.go | 1 - modules/apps/29-fee/types/msgs.go | 26 ++++++++ modules/apps/29-fee/types/msgs_test.go | 81 ++++++++++++++++++++---- 3 files changed, 94 insertions(+), 14 deletions(-) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 17012f47374..4b81a870eea 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -17,7 +17,6 @@ var _ types.MsgServer = Keeper{} func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - k.SetCounterpartyAddress( ctx, msg.Address, msg.CounterpartyAddress, ) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index cc88ba56239..2f9a0d557d2 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -81,6 +81,19 @@ func (msg MsgPayPacketFee) ValidateBasic() error { return ErrRelayersNotNil } + // ensure fee's are valid amounts + if !msg.Fee.AckFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + if !msg.Fee.ReceiveFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + if !msg.Fee.TimeoutFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + return nil } @@ -131,6 +144,19 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error { return sdkerrors.ErrInvalidSequence } + // ensure fee's are valid amounts + if !msg.IdentifiedPacketFee.Fee.AckFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + if !msg.IdentifiedPacketFee.Fee.ReceiveFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + if !msg.IdentifiedPacketFee.Fee.TimeoutFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + return nil } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index df9d5e57911..84abb42ed31 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -14,6 +14,7 @@ var ( 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" ) @@ -55,11 +56,14 @@ func TestRegisterCountepartyAddressGetSigners(t *testing.T) { // TestMsgPayPacketFeeValidation tests ValidateBasic func TestMsgPayPacketFeeValidation(t *testing.T) { var ( - signer string - channelID string - portID string - fee Fee - relayers []string + signer string + channelID string + portID string + fee Fee + relayers []string + ackFee sdk.Coins + receiveFee sdk.Coins + timeoutFee sdk.Coins ) testCases := []struct { @@ -100,6 +104,27 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { }, false, }, + { + "invalid ack fee", + func() { + ackFee = invalidCoins + }, + false, + }, + { + "invalid recieve fee", + func() { + receiveFee = invalidCoins + }, + false, + }, + { + "invalid timeout fee", + func() { + timeoutFee = invalidCoins + }, + false, + }, } for _, tc := range testCases { @@ -107,11 +132,14 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { signer = validAddr channelID = validChannelID portID = validPortID - fee = Fee{validCoins, validCoins, validCoins} + ackFee = validCoins + receiveFee = validCoins + timeoutFee = validCoins relayers = nil // malleate tc.malleate() + fee = Fee{receiveFee, ackFee, timeoutFee} msg := NewMsgPayPacketFee(fee, portID, channelID, signer, relayers) err := msg.ValidateBasic() @@ -143,12 +171,15 @@ func TestPayPacketFeeGetSigners(t *testing.T) { // TestMsgPayPacketFeeAsyncValidation tests ValidateBasic func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { var ( - signer string - channelID string - portID string - fee Fee - relayers []string - seq uint64 + signer string + channelID string + portID string + fee Fee + relayers []string + seq uint64 + ackFee sdk.Coins + receiveFee sdk.Coins + timeoutFee sdk.Coins ) testCases := []struct { @@ -196,6 +227,27 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { }, false, }, + { + "invalid ack fee", + func() { + ackFee = invalidCoins + }, + false, + }, + { + "invalid recieve fee", + func() { + receiveFee = invalidCoins + }, + false, + }, + { + "invalid timeout fee", + func() { + timeoutFee = invalidCoins + }, + false, + }, } for _, tc := range testCases { @@ -203,12 +255,15 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { signer = validAddr channelID = validChannelID portID = validPortID - fee = Fee{validCoins, validCoins, validCoins} + ackFee = validCoins + receiveFee = validCoins + timeoutFee = validCoins relayers = nil seq = 1 // malleate tc.malleate() + fee = Fee{receiveFee, ackFee, timeoutFee} packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: portID, Sequence: seq} identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: relayers} From a51e2ff1fe40dcf00f57ad6d877b2e760abc4882 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 12:24:16 +0100 Subject: [PATCH 44/50] test: allow counterparty address to be arbitrary string --- modules/apps/29-fee/keeper/msg_server_test.go | 7 ++++++- modules/apps/29-fee/types/errors.go | 11 ++++++----- modules/apps/29-fee/types/msgs.go | 5 ++--- modules/apps/29-fee/types/msgs_test.go | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 3766f4f9105..face4c4c905 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -21,6 +21,11 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { true, func() {}, }, + { + "success", + true, + func() { counterparty = "arbitrary-string" }, + }, } for _, tc := range testCases { @@ -29,8 +34,8 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() { sender = suite.chainA.SenderAccount.GetAddress().String() counterparty = suite.chainB.SenderAccount.GetAddress().String() - msg := types.NewMsgRegisterCounterpartyAddress(sender, counterparty) tc.malleate() + msg := types.NewMsgRegisterCounterpartyAddress(sender, counterparty) _, err := suite.chainA.SendMsgs(msg) diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 07a5ef985f2..b5e8203ec9f 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -6,9 +6,10 @@ import ( // 29-fee sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") - ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 3, "no account found for given refund address") - ErrBalanceNotFound = sdkerrors.Register(ModuleName, 4, "balance not found for given account address") - ErrFeeNotFound = sdkerrors.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") - ErrRelayersNotNil = sdkerrors.Register(ModuleName, 6, "relayers must be nil. This feature is not supported") + ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") + ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 3, "no account found for given refund address") + ErrBalanceNotFound = sdkerrors.Register(ModuleName, 4, "balance not found for given account address") + ErrFeeNotFound = sdkerrors.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") + ErrRelayersNotNil = sdkerrors.Register(ModuleName, 6, "relayers must be nil. This feature is not supported") + ErrCounterpartyAddressEmpty = sdkerrors.Register(ModuleName, 7, "counterparty address must not be empty") ) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 2f9a0d557d2..f35ad8e1259 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -28,9 +28,8 @@ func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") } - _, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress) - if err != nil { - return sdkerrors.Wrap(err, "failed to convert msg.CounterpartyAddress into sdk.AccAddress") + if msg.CounterpartyAddress == "" { + return ErrCounterpartyAddressEmpty } return nil diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 84abb42ed31..fb0deae1b2c 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -28,7 +28,7 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { }{ {"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}, + {"invalid counterparty address", NewMsgRegisterCounterpartyAddress(validAddr, ""), false}, } for i, tc := range testCases { @@ -45,7 +45,7 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { func TestRegisterCountepartyAddressGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) // build message - msg := NewMsgRegisterCounterpartyAddress(addr.String(), addr.String()) + msg := NewMsgRegisterCounterpartyAddress(addr.String(), "counterparty") // GetSigners res := msg.GetSigners() From bbfd8d7d7aeb2a5764f4d53bad5345b556f952af Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 16:09:21 +0100 Subject: [PATCH 45/50] fix: message validation should pass if one fee is valid --- modules/apps/29-fee/types/msgs.go | 24 ++++------------------ modules/apps/29-fee/types/msgs_test.go | 28 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index f35ad8e1259..64a5db18a76 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -80,16 +80,8 @@ func (msg MsgPayPacketFee) ValidateBasic() error { return ErrRelayersNotNil } - // ensure fee's are valid amounts - if !msg.Fee.AckFee.IsValid() { - return sdkerrors.ErrInvalidCoins - } - - if !msg.Fee.ReceiveFee.IsValid() { - return sdkerrors.ErrInvalidCoins - } - - if !msg.Fee.TimeoutFee.IsValid() { + // if all three fee's are invalid return an error + if !msg.Fee.AckFee.IsValid() && !msg.Fee.ReceiveFee.IsValid() && !msg.Fee.TimeoutFee.IsValid() { return sdkerrors.ErrInvalidCoins } @@ -143,16 +135,8 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error { return sdkerrors.ErrInvalidSequence } - // ensure fee's are valid amounts - if !msg.IdentifiedPacketFee.Fee.AckFee.IsValid() { - return sdkerrors.ErrInvalidCoins - } - - if !msg.IdentifiedPacketFee.Fee.ReceiveFee.IsValid() { - return sdkerrors.ErrInvalidCoins - } - - if !msg.IdentifiedPacketFee.Fee.TimeoutFee.IsValid() { + // if all three fee's are invalid return an error + if !msg.IdentifiedPacketFee.Fee.AckFee.IsValid() && !msg.IdentifiedPacketFee.Fee.ReceiveFee.IsValid() && !msg.IdentifiedPacketFee.Fee.TimeoutFee.IsValid() { return sdkerrors.ErrInvalidCoins } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index fb0deae1b2c..bcd3eddab55 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -105,25 +105,28 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { false, }, { - "invalid ack fee", + "should fail when all fees are invalid", func() { ackFee = invalidCoins + receiveFee = invalidCoins + timeoutFee = invalidCoins }, false, }, { - "invalid recieve fee", + "should pass with single invalid fee", func() { - receiveFee = invalidCoins + ackFee = invalidCoins }, - false, + true, }, { - "invalid timeout fee", + "should pass with two invalid fees", func() { timeoutFee = invalidCoins + ackFee = invalidCoins }, - false, + true, }, } @@ -228,25 +231,28 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { false, }, { - "invalid ack fee", + "should fail with three invalid fees", func() { ackFee = invalidCoins + receiveFee = invalidCoins + timeoutFee = invalidCoins }, false, }, { - "invalid recieve fee", + "should pass with two invalid fees", func() { receiveFee = invalidCoins + timeoutFee = invalidCoins }, - false, + true, }, { - "invalid timeout fee", + "should pass with single invalid fee", func() { timeoutFee = invalidCoins }, - false, + true, }, } From 6640660633fc45289401477ac6f44d6ac5610461 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 16:11:11 +0100 Subject: [PATCH 46/50] Update modules/apps/29-fee/keeper/escrow.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/escrow.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 6ffac5c3f99..9e194b1d6db 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -40,7 +40,7 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers // check if there is a Fee in escrow for the given packetId feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) if !found { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("with channelID: %s, sequenceId %d", packetID.ChannelId, packetID.Sequence)) + return sdkerrors.Wrapf(types.ErrFeeNotFound, "with channelID %s, sequence %d", packetID.ChannelId, packetID.Sequence) } // get module accAddr From 4610c993198d2d4a445cc75daeebe2be4ad76953 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 16:19:26 +0100 Subject: [PATCH 47/50] Update modules/apps/29-fee/keeper/escrow.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/escrow.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 9e194b1d6db..d4c24b63a43 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -73,9 +73,9 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers // DistributeFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, timeoutRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { // check if there is a Fee in escrow for the given packetId - feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID) - if !hasFee { - return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String())) + feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) + if !found { + return sdkerrors.Wrap(types.ErrFeeNotFound, refundAcc) } // get module accAddr From bec52c0b0409aa63eead9b6701f49a6038db455c Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 16:21:46 +0100 Subject: [PATCH 48/50] fix: nits --- modules/apps/29-fee/keeper/escrow.go | 2 +- modules/apps/29-fee/keeper/escrow_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index d4c24b63a43..97767986880 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -75,7 +75,7 @@ func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, timeoutRelayer // check if there is a Fee in escrow for the given packetId feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) if !found { - return sdkerrors.Wrap(types.ErrFeeNotFound, refundAcc) + return sdkerrors.Wrap(types.ErrFeeNotFound, refundAcc.String()) } // get module accAddr diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 2d390079bc2..d5600c964e3 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -1,10 +1,12 @@ package keeper_test import ( + "github.com/tendermint/tendermint/crypto/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" - "github.com/tendermint/tendermint/crypto/secp256k1" ) var ( From 2c9185cff0bbf39d6da1f5f799b392637cd1f56d Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 16:23:44 +0100 Subject: [PATCH 49/50] Update modules/apps/29-fee/keeper/escrow.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/escrow.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 97767986880..cddb3be047a 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -49,7 +49,7 @@ func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, revers // send receive fee to forward relayer err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, feeInEscrow.Fee.ReceiveFee) if err != nil { - return sdkerrors.Wrap(err, "error sending fee to forward relayer") + return sdkerrors.Wrap(err, "failed to send fee to forward relayer") } // send ack fee to reverse relayer From f4de334f22ef9a26a3ee0e7153408aa149dc5fae Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 5 Nov 2021 16:55:48 +0100 Subject: [PATCH 50/50] test: adding isZero check for msgs --- modules/apps/29-fee/keeper/keeper.go | 1 - modules/apps/29-fee/types/msgs.go | 18 ++++++-- modules/apps/29-fee/types/msgs_test.go | 64 ++++++++++++++++++++++---- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index b7e8e0db91a..3691204d2a6 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/ibc-go/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/modules/core/exported" ) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 64a5db18a76..ef9e49901fd 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -80,8 +80,13 @@ func (msg MsgPayPacketFee) ValidateBasic() error { return ErrRelayersNotNil } - // if all three fee's are invalid return an error - if !msg.Fee.AckFee.IsValid() && !msg.Fee.ReceiveFee.IsValid() && !msg.Fee.TimeoutFee.IsValid() { + // if any of the fee's are invalid return an error + if !msg.Fee.AckFee.IsValid() || !msg.Fee.ReceiveFee.IsValid() || !msg.Fee.TimeoutFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + // if all three fee's are zero or empty return an error + if msg.Fee.AckFee.IsZero() && msg.Fee.ReceiveFee.IsZero() && msg.Fee.TimeoutFee.IsZero() { return sdkerrors.ErrInvalidCoins } @@ -135,8 +140,13 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error { return sdkerrors.ErrInvalidSequence } - // if all three fee's are invalid return an error - if !msg.IdentifiedPacketFee.Fee.AckFee.IsValid() && !msg.IdentifiedPacketFee.Fee.ReceiveFee.IsValid() && !msg.IdentifiedPacketFee.Fee.TimeoutFee.IsValid() { + // if any of the fee's are invalid return an error + if !msg.IdentifiedPacketFee.Fee.AckFee.IsValid() || !msg.IdentifiedPacketFee.Fee.ReceiveFee.IsValid() || !msg.IdentifiedPacketFee.Fee.TimeoutFee.IsValid() { + return sdkerrors.ErrInvalidCoins + } + + // if all three fee's are zero or empty return an error + if msg.IdentifiedPacketFee.Fee.AckFee.IsZero() && msg.IdentifiedPacketFee.Fee.ReceiveFee.IsZero() && msg.IdentifiedPacketFee.Fee.TimeoutFee.IsZero() { return sdkerrors.ErrInvalidCoins } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index bcd3eddab55..480eedcc403 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -114,20 +114,44 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { false, }, { - "should pass with single invalid fee", + "should fail with single invalid fee", func() { ackFee = invalidCoins }, - true, + false, }, { - "should pass with two invalid fees", + "should fail with two invalid fees", func() { timeoutFee = invalidCoins ackFee = invalidCoins }, + false, + }, + { + "should pass with two empty fees", + func() { + timeoutFee = sdk.Coins{} + ackFee = sdk.Coins{} + }, true, }, + { + "should pass with one empty fee", + func() { + timeoutFee = sdk.Coins{} + }, + true, + }, + { + "should fail if all fees are empty", + func() { + ackFee = sdk.Coins{} + receiveFee = sdk.Coins{} + timeoutFee = sdk.Coins{} + }, + false, + }, } for _, tc := range testCases { @@ -231,7 +255,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { false, }, { - "should fail with three invalid fees", + "should fail when all fees are invalid", func() { ackFee = invalidCoins receiveFee = invalidCoins @@ -240,20 +264,44 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { false, }, { - "should pass with two invalid fees", + "should fail with single invalid fee", + func() { + ackFee = invalidCoins + }, + false, + }, + { + "should fail with two invalid fees", func() { - receiveFee = invalidCoins timeoutFee = invalidCoins + ackFee = invalidCoins + }, + false, + }, + { + "should pass with two empty fees", + func() { + timeoutFee = sdk.Coins{} + ackFee = sdk.Coins{} }, true, }, { - "should pass with single invalid fee", + "should pass with one empty fee", func() { - timeoutFee = invalidCoins + timeoutFee = sdk.Coins{} }, true, }, + { + "should fail if all fees are empty", + func() { + ackFee = sdk.Coins{} + receiveFee = sdk.Coins{} + timeoutFee = sdk.Coins{} + }, + false, + }, } for _, tc := range testCases {