From 23940d4effd9d25101172de0b19517463d87ec28 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 21 Feb 2022 13:05:12 +0000 Subject: [PATCH 1/6] adding new proto types and codegen --- docs/ibc/proto-docs.md | 40 +- modules/apps/29-fee/types/fee.pb.go | 597 ++++++++++++++++++-- proto/ibc/applications/fee/v1/fee.proto | 22 +- proto/ibc/applications/fee/v1/genesis.proto | 9 +- 4 files changed, 619 insertions(+), 49 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 84127283e32..3da59f9038c 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -32,6 +32,8 @@ - [Fee](#ibc.applications.fee.v1.Fee) - [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) - [IdentifiedPacketFees](#ibc.applications.fee.v1.IdentifiedPacketFees) + - [PacketFee](#ibc.applications.fee.v1.PacketFee) + - [PacketFees](#ibc.applications.fee.v1.PacketFees) - [ibc/applications/fee/v1/genesis.proto](#ibc/applications/fee/v1/genesis.proto) - [FeeEnabledChannel](#ibc.applications.fee.v1.FeeEnabledChannel) @@ -741,12 +743,46 @@ and an optional list of relayers that are permitted to receive the fee. ### IdentifiedPacketFees -IdentifiedPacketFees contains a list of packet fees +IdentifiedPacketFees contains a PacketFree and associated PacketId | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `packet_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | | +| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | | +| `packet_fees` | [PacketFee](#ibc.applications.fee.v1.PacketFee) | repeated | | + + + + + + + + +### PacketFee +PacketFee contains the relayer fee, refund address and an optional list of relayers that are permitted to receive the +fee + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | | +| `refund_address` | [string](#string) | | | +| `relayers` | [string](#string) | repeated | | + + + + + + + + +### PacketFees +PacketFees contains a list of type PacketFee + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `packet_fees` | [PacketFee](#ibc.applications.fee.v1.PacketFee) | repeated | | diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index 8be56939659..e3e41810f96 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -161,16 +161,124 @@ func (m *IdentifiedPacketFee) GetRelayers() []string { return nil } -// IdentifiedPacketFees contains a list of packet fees +// PacketFee contains the relayer fee, refund address and an optional list of relayers that are permitted to receive the +// fee +type PacketFee struct { + Fee Fee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee"` + RefundAddress string `protobuf:"bytes,2,opt,name=refund_address,json=refundAddress,proto3" json:"refund_address,omitempty" yaml:"refund_address"` + Relayers []string `protobuf:"bytes,3,rep,name=relayers,proto3" json:"relayers,omitempty"` +} + +func (m *PacketFee) Reset() { *m = PacketFee{} } +func (m *PacketFee) String() string { return proto.CompactTextString(m) } +func (*PacketFee) ProtoMessage() {} +func (*PacketFee) Descriptor() ([]byte, []int) { + return fileDescriptor_cb3319f1af2a53e5, []int{2} +} +func (m *PacketFee) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketFee.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 *PacketFee) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketFee.Merge(m, src) +} +func (m *PacketFee) XXX_Size() int { + return m.Size() +} +func (m *PacketFee) XXX_DiscardUnknown() { + xxx_messageInfo_PacketFee.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketFee proto.InternalMessageInfo + +func (m *PacketFee) GetFee() Fee { + if m != nil { + return m.Fee + } + return Fee{} +} + +func (m *PacketFee) GetRefundAddress() string { + if m != nil { + return m.RefundAddress + } + return "" +} + +func (m *PacketFee) GetRelayers() []string { + if m != nil { + return m.Relayers + } + return nil +} + +// PacketFees contains a list of type PacketFee +type PacketFees struct { + PacketFees []PacketFee `protobuf:"bytes,1,rep,name=packet_fees,json=packetFees,proto3" json:"packet_fees" yaml:"packet_fees"` +} + +func (m *PacketFees) Reset() { *m = PacketFees{} } +func (m *PacketFees) String() string { return proto.CompactTextString(m) } +func (*PacketFees) ProtoMessage() {} +func (*PacketFees) Descriptor() ([]byte, []int) { + return fileDescriptor_cb3319f1af2a53e5, []int{3} +} +func (m *PacketFees) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketFees) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketFees.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 *PacketFees) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketFees.Merge(m, src) +} +func (m *PacketFees) XXX_Size() int { + return m.Size() +} +func (m *PacketFees) XXX_DiscardUnknown() { + xxx_messageInfo_PacketFees.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketFees proto.InternalMessageInfo + +func (m *PacketFees) GetPacketFees() []PacketFee { + if m != nil { + return m.PacketFees + } + return nil +} + +// IdentifiedPacketFees contains a PacketFree and associated PacketId type IdentifiedPacketFees struct { - PacketFees []IdentifiedPacketFee `protobuf:"bytes,1,rep,name=packet_fees,json=packetFees,proto3" json:"packet_fees" yaml:"packet_fees"` + PacketId types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id" yaml:"packet_id"` + PacketFees []PacketFee `protobuf:"bytes,2,rep,name=packet_fees,json=packetFees,proto3" json:"packet_fees" yaml:"packet_fees"` } func (m *IdentifiedPacketFees) Reset() { *m = IdentifiedPacketFees{} } func (m *IdentifiedPacketFees) String() string { return proto.CompactTextString(m) } func (*IdentifiedPacketFees) ProtoMessage() {} func (*IdentifiedPacketFees) Descriptor() ([]byte, []int) { - return fileDescriptor_cb3319f1af2a53e5, []int{2} + return fileDescriptor_cb3319f1af2a53e5, []int{4} } func (m *IdentifiedPacketFees) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -199,7 +307,14 @@ func (m *IdentifiedPacketFees) XXX_DiscardUnknown() { var xxx_messageInfo_IdentifiedPacketFees proto.InternalMessageInfo -func (m *IdentifiedPacketFees) GetPacketFees() []IdentifiedPacketFee { +func (m *IdentifiedPacketFees) GetPacketId() types1.PacketId { + if m != nil { + return m.PacketId + } + return types1.PacketId{} +} + +func (m *IdentifiedPacketFees) GetPacketFees() []PacketFee { if m != nil { return m.PacketFees } @@ -209,46 +324,50 @@ func (m *IdentifiedPacketFees) GetPacketFees() []IdentifiedPacketFee { func init() { proto.RegisterType((*Fee)(nil), "ibc.applications.fee.v1.Fee") proto.RegisterType((*IdentifiedPacketFee)(nil), "ibc.applications.fee.v1.IdentifiedPacketFee") + proto.RegisterType((*PacketFee)(nil), "ibc.applications.fee.v1.PacketFee") + proto.RegisterType((*PacketFees)(nil), "ibc.applications.fee.v1.PacketFees") proto.RegisterType((*IdentifiedPacketFees)(nil), "ibc.applications.fee.v1.IdentifiedPacketFees") } func init() { proto.RegisterFile("ibc/applications/fee/v1/fee.proto", fileDescriptor_cb3319f1af2a53e5) } var fileDescriptor_cb3319f1af2a53e5 = []byte{ - // 523 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x6b, 0x32, 0x6d, 0xab, 0x2b, 0x26, 0x14, 0x86, 0xe8, 0x2a, 0x48, 0x4b, 0x4e, 0x3d, - 0x50, 0x5b, 0xed, 0xe0, 0x00, 0x27, 0x08, 0x52, 0xa5, 0x9d, 0x40, 0x11, 0x27, 0x2e, 0x95, 0xe3, - 0xbc, 0x76, 0x56, 0x9b, 0x38, 0x8a, 0xd3, 0x48, 0x95, 0x38, 0x00, 0x9f, 0x80, 0xcf, 0xc1, 0x27, - 0xd9, 0x71, 0x47, 0x4e, 0x05, 0xb5, 0xdf, 0x60, 0x5f, 0x00, 0xe4, 0xd8, 0xab, 0x8a, 0xd8, 0x34, - 0xf5, 0x64, 0xfb, 0xf9, 0xfd, 0xdf, 0xef, 0xd9, 0xef, 0x3d, 0xfc, 0x4c, 0x44, 0x9c, 0xb2, 0x2c, - 0x9b, 0x09, 0xce, 0x0a, 0x21, 0x53, 0x45, 0xc7, 0x00, 0xb4, 0xec, 0xeb, 0x85, 0x64, 0xb9, 0x2c, - 0xa4, 0xfb, 0x58, 0x44, 0x9c, 0x6c, 0xbb, 0x10, 0x7d, 0x57, 0xf6, 0x5b, 0x1e, 0x97, 0x2a, 0x91, - 0x8a, 0x46, 0x4c, 0x69, 0x49, 0x04, 0x05, 0xeb, 0x53, 0x2e, 0x45, 0x6a, 0x84, 0xad, 0xe3, 0x89, - 0x9c, 0xc8, 0x6a, 0x4b, 0xf5, 0xce, 0x5a, 0x2b, 0x22, 0x97, 0x39, 0x50, 0x7e, 0xce, 0xd2, 0x14, - 0x66, 0x9a, 0x66, 0xb7, 0xc6, 0xc5, 0xff, 0xe2, 0x60, 0x67, 0x08, 0xe0, 0x7e, 0xc6, 0x87, 0x39, - 0xf0, 0x72, 0x34, 0x06, 0x68, 0xa2, 0x8e, 0xd3, 0x6d, 0x0c, 0x4e, 0x88, 0x61, 0x12, 0xcd, 0x24, - 0x96, 0x49, 0xde, 0x49, 0x91, 0x06, 0xc3, 0x8b, 0x65, 0xbb, 0x76, 0xb5, 0x6c, 0xbb, 0x0b, 0x96, - 0xcc, 0x5e, 0xfb, 0x39, 0x70, 0x10, 0x25, 0x68, 0xad, 0xff, 0xe3, 0x57, 0xbb, 0x3b, 0x11, 0xc5, - 0xf9, 0x3c, 0x22, 0x5c, 0x26, 0xd4, 0xa6, 0x6d, 0x96, 0x9e, 0x8a, 0xa7, 0xb4, 0x58, 0x64, 0xa0, - 0xaa, 0x30, 0x2a, 0x3c, 0xd0, 0x48, 0x4d, 0x2f, 0xf1, 0x01, 0xe3, 0xd3, 0x0a, 0x7e, 0xef, 0x2e, - 0x78, 0x60, 0xe1, 0x47, 0x06, 0x6e, 0x75, 0xbb, 0x81, 0xf7, 0x19, 0x9f, 0x6a, 0xee, 0x37, 0x84, - 0x1b, 0x85, 0x48, 0x40, 0xce, 0x8b, 0x0a, 0xee, 0xec, 0xf8, 0xf2, 0x2d, 0xed, 0x6e, 0x09, 0x60, - 0xab, 0x1c, 0x02, 0xf8, 0x7f, 0x10, 0x7e, 0x78, 0x16, 0x43, 0x5a, 0x88, 0xb1, 0x80, 0xf8, 0x03, - 0xe3, 0x53, 0xd0, 0x76, 0xf7, 0x23, 0xae, 0x67, 0xd5, 0x61, 0x24, 0xe2, 0x26, 0xea, 0xa0, 0x6e, - 0x63, 0xf0, 0x94, 0xe8, 0x06, 0xd1, 0x15, 0x25, 0xd7, 0x65, 0x2c, 0xfb, 0xc4, 0x48, 0xce, 0xe2, - 0xa0, 0x69, 0xb3, 0x7b, 0x60, 0xb2, 0xdb, 0xa8, 0xfd, 0xf0, 0x30, 0xb3, 0x3e, 0xee, 0x0b, 0xec, - 0x98, 0x6f, 0xd6, 0xf1, 0x9e, 0x90, 0x5b, 0x1a, 0x8e, 0x0c, 0x01, 0x82, 0x3d, 0x1d, 0x2e, 0xd4, - 0xee, 0xee, 0x1b, 0x7c, 0x94, 0xc3, 0x78, 0x9e, 0xc6, 0x23, 0x16, 0xc7, 0x39, 0x28, 0xd5, 0x74, - 0x3a, 0xa8, 0x5b, 0x0f, 0x4e, 0xae, 0x96, 0xed, 0x47, 0xd7, 0x5d, 0xb0, 0x7d, 0xef, 0x87, 0xf7, - 0x8d, 0xe1, 0xad, 0x39, 0xbb, 0x2d, 0xdd, 0x60, 0x33, 0xb6, 0x80, 0x5c, 0x35, 0xf7, 0x3a, 0x4e, - 0xb7, 0x1e, 0x6e, 0xce, 0xfe, 0x57, 0x84, 0x8f, 0x6f, 0xf8, 0x01, 0xe5, 0x0a, 0xdc, 0xb0, 0x8f, - 0x18, 0x03, 0x28, 0xdb, 0x98, 0xcf, 0x6f, 0x4d, 0xfa, 0x86, 0x18, 0x41, 0xeb, 0xdf, 0x8a, 0x6d, - 0x85, 0xf3, 0x43, 0x9c, 0x6d, 0x50, 0xc1, 0xfb, 0x8b, 0x95, 0x87, 0x2e, 0x57, 0x1e, 0xfa, 0xbd, - 0xf2, 0xd0, 0xf7, 0xb5, 0x57, 0xbb, 0x5c, 0x7b, 0xb5, 0x9f, 0x6b, 0xaf, 0xf6, 0xe9, 0xe5, 0xff, - 0x55, 0x15, 0x11, 0xef, 0x4d, 0x24, 0x2d, 0x4f, 0x69, 0x22, 0xe3, 0xf9, 0x0c, 0x94, 0x9e, 0x6b, - 0x45, 0x07, 0xaf, 0x7a, 0x7a, 0xa4, 0xab, 0x42, 0x47, 0xfb, 0xd5, 0x80, 0x9d, 0xfe, 0x0d, 0x00, - 0x00, 0xff, 0xff, 0x0e, 0xeb, 0xd3, 0x29, 0xf7, 0x03, 0x00, 0x00, + // 560 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0xeb, 0x66, 0xda, 0x56, 0x57, 0x4c, 0x28, 0x0c, 0xd1, 0x55, 0x90, 0x96, 0x9c, 0x7a, + 0xa9, 0xad, 0x76, 0x70, 0x80, 0x13, 0x04, 0xa9, 0xd2, 0x4e, 0xa0, 0x88, 0x13, 0x97, 0xca, 0x71, + 0xbe, 0x76, 0x56, 0x9b, 0x38, 0x8a, 0xd3, 0x48, 0x95, 0x38, 0x20, 0x9e, 0x80, 0x37, 0xe0, 0xce, + 0x93, 0xec, 0x82, 0xb4, 0x23, 0xa7, 0x82, 0xda, 0x37, 0xd8, 0x0b, 0x80, 0x9c, 0x78, 0xa5, 0x0c, + 0x26, 0x54, 0x0d, 0x4e, 0xb1, 0x9d, 0xef, 0xff, 0xfd, 0xfe, 0x9f, 0xfd, 0xd9, 0xf8, 0xa1, 0x08, + 0x38, 0x65, 0x49, 0x32, 0x15, 0x9c, 0x65, 0x42, 0xc6, 0x8a, 0x8e, 0x00, 0x68, 0xde, 0xd3, 0x1f, + 0x92, 0xa4, 0x32, 0x93, 0xf6, 0x3d, 0x11, 0x70, 0xb2, 0x19, 0x42, 0xf4, 0xbf, 0xbc, 0xd7, 0x74, + 0xb8, 0x54, 0x91, 0x54, 0x34, 0x60, 0x4a, 0x4b, 0x02, 0xc8, 0x58, 0x8f, 0x72, 0x29, 0xe2, 0x52, + 0xd8, 0x3c, 0x1c, 0xcb, 0xb1, 0x2c, 0x86, 0x54, 0x8f, 0xcc, 0x6a, 0x41, 0xe4, 0x32, 0x05, 0xca, + 0x4f, 0x59, 0x1c, 0xc3, 0x54, 0xd3, 0xcc, 0xb0, 0x0c, 0x71, 0xdf, 0x59, 0xd8, 0x1a, 0x00, 0xd8, + 0x6f, 0xf1, 0x7e, 0x0a, 0x3c, 0x1f, 0x8e, 0x00, 0x1a, 0xa8, 0x6d, 0x75, 0xea, 0xfd, 0x23, 0x52, + 0x32, 0x89, 0x66, 0x12, 0xc3, 0x24, 0x2f, 0xa4, 0x88, 0xbd, 0xc1, 0xd9, 0xa2, 0x55, 0xb9, 0x58, + 0xb4, 0xec, 0x39, 0x8b, 0xa6, 0x4f, 0xdd, 0x14, 0x38, 0x88, 0x1c, 0xb4, 0xd6, 0xfd, 0xf4, 0xb5, + 0xd5, 0x19, 0x8b, 0xec, 0x74, 0x16, 0x10, 0x2e, 0x23, 0x6a, 0x6c, 0x97, 0x9f, 0xae, 0x0a, 0x27, + 0x34, 0x9b, 0x27, 0xa0, 0x8a, 0x34, 0xca, 0xdf, 0xd3, 0x48, 0x4d, 0xcf, 0xf1, 0x1e, 0xe3, 0x93, + 0x02, 0x5e, 0xfd, 0x1b, 0xdc, 0x33, 0xf0, 0x83, 0x12, 0x6e, 0x74, 0xdb, 0x81, 0x77, 0x19, 0x9f, + 0x68, 0xee, 0x7b, 0x84, 0xeb, 0x99, 0x88, 0x40, 0xce, 0xb2, 0x02, 0x6e, 0x6d, 0x59, 0xf9, 0x86, + 0x76, 0x3b, 0x03, 0xd8, 0x28, 0x07, 0x00, 0xee, 0x77, 0x84, 0xef, 0x9c, 0x84, 0x10, 0x67, 0x62, + 0x24, 0x20, 0x7c, 0xc5, 0xf8, 0x04, 0xf4, 0xba, 0xfd, 0x1a, 0xd7, 0x92, 0x62, 0x32, 0x14, 0x61, + 0x03, 0xb5, 0x51, 0xa7, 0xde, 0x7f, 0x40, 0x74, 0x83, 0xe8, 0x13, 0x25, 0x97, 0xc7, 0x98, 0xf7, + 0x48, 0x29, 0x39, 0x09, 0xbd, 0x86, 0x71, 0x77, 0xbb, 0x74, 0xb7, 0x56, 0xbb, 0xfe, 0x7e, 0x62, + 0x62, 0xec, 0x47, 0xd8, 0x2a, 0xb7, 0x59, 0xe7, 0xbb, 0x4f, 0xae, 0x69, 0x38, 0x32, 0x00, 0xf0, + 0x76, 0x74, 0x3a, 0x5f, 0x87, 0xdb, 0xcf, 0xf0, 0x41, 0x0a, 0xa3, 0x59, 0x1c, 0x0e, 0x59, 0x18, + 0xa6, 0xa0, 0x54, 0xc3, 0x6a, 0xa3, 0x4e, 0xcd, 0x3b, 0xba, 0x58, 0xb4, 0xee, 0x5e, 0x76, 0xc1, + 0xe6, 0x7f, 0xd7, 0xbf, 0x55, 0x2e, 0x3c, 0x2f, 0xe7, 0x76, 0x53, 0x37, 0xd8, 0x94, 0xcd, 0x21, + 0x55, 0x8d, 0x9d, 0xb6, 0xd5, 0xa9, 0xf9, 0xeb, 0xb9, 0xfb, 0x11, 0xe1, 0xda, 0xcf, 0xba, 0x8d, + 0x43, 0x74, 0x53, 0x87, 0xd5, 0x1b, 0x38, 0xb4, 0xae, 0x38, 0x8c, 0x30, 0x5e, 0x1b, 0x54, 0xf6, + 0x10, 0xd7, 0xcd, 0xde, 0x8e, 0x00, 0x94, 0xb9, 0x2f, 0xee, 0xb5, 0x4e, 0xd7, 0x4a, 0xaf, 0xf9, + 0x6b, 0xfb, 0x6c, 0x24, 0x71, 0x7d, 0x9c, 0xac, 0x01, 0xee, 0x67, 0x84, 0x0f, 0xff, 0xd0, 0x12, + 0xea, 0x3f, 0xf5, 0xc4, 0x95, 0x7a, 0xaa, 0xff, 0xba, 0x1e, 0xef, 0xe5, 0xd9, 0xd2, 0x41, 0xe7, + 0x4b, 0x07, 0x7d, 0x5b, 0x3a, 0xe8, 0xc3, 0xca, 0xa9, 0x9c, 0xaf, 0x9c, 0xca, 0x97, 0x95, 0x53, + 0x79, 0xf3, 0xf8, 0xf7, 0x2b, 0x23, 0x02, 0xde, 0x1d, 0x4b, 0x9a, 0x1f, 0xd3, 0x48, 0x86, 0xb3, + 0x29, 0x28, 0xfd, 0x68, 0x2a, 0xda, 0x7f, 0xd2, 0xd5, 0xef, 0x65, 0x71, 0x8b, 0x82, 0xdd, 0xe2, + 0xf5, 0x3a, 0xfe, 0x11, 0x00, 0x00, 0xff, 0xff, 0x6b, 0xd4, 0x49, 0x04, 0x54, 0x05, 0x00, 0x00, } func (m *Fee) Marshal() (dAtA []byte, err error) { @@ -375,6 +494,92 @@ func (m *IdentifiedPacketFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *PacketFee) 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 *PacketFee) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketFee) 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 = encodeVarintFee(dAtA, i, uint64(len(m.Relayers[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.RefundAddress) > 0 { + i -= len(m.RefundAddress) + copy(dAtA[i:], m.RefundAddress) + i = encodeVarintFee(dAtA, i, uint64(len(m.RefundAddress))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *PacketFees) 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 *PacketFees) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketFees) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PacketFees) > 0 { + for iNdEx := len(m.PacketFees) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PacketFees[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *IdentifiedPacketFees) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -406,9 +611,19 @@ func (m *IdentifiedPacketFees) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintFee(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0xa + dAtA[i] = 0x12 + } + } + { + size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -473,12 +688,50 @@ func (m *IdentifiedPacketFee) Size() (n int) { return n } +func (m *PacketFee) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Fee.Size() + n += 1 + l + sovFee(uint64(l)) + l = len(m.RefundAddress) + if l > 0 { + 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 +} + +func (m *PacketFees) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PacketFees) > 0 { + for _, e := range m.PacketFees { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } + } + return n +} + func (m *IdentifiedPacketFees) Size() (n int) { if m == nil { return 0 } var l int _ = l + l = m.PacketId.Size() + n += 1 + l + sovFee(uint64(l)) if len(m.PacketFees) > 0 { for _, e := range m.PacketFees { l = e.Size() @@ -826,6 +1079,237 @@ func (m *IdentifiedPacketFee) Unmarshal(dAtA []byte) error { } return nil } +func (m *PacketFee) 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: PacketFee: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketFee: 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 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 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + 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 RefundAddress", 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.RefundAddress = string(dAtA[iNdEx:postIndex]) + 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:]) + 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 *PacketFees) 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: PacketFees: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketFees: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketFees", 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 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PacketFees = append(m.PacketFees, PacketFee{}) + if err := m.PacketFees[len(m.PacketFees)-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 *IdentifiedPacketFees) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -856,6 +1340,39 @@ func (m *IdentifiedPacketFees) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + 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 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 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PacketFees", wireType) } @@ -884,7 +1401,7 @@ func (m *IdentifiedPacketFees) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PacketFees = append(m.PacketFees, IdentifiedPacketFee{}) + m.PacketFees = append(m.PacketFees, PacketFee{}) if err := m.PacketFees[len(m.PacketFees)-1].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 3a58f093e06..09fdd6d1a7d 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -41,8 +41,22 @@ message IdentifiedPacketFee { repeated string relayers = 4; } -// IdentifiedPacketFees contains a list of packet fees +// PacketFee contains the relayer fee, refund address and an optional list of relayers that are permitted to receive the +// fee +message PacketFee { + Fee fee = 1 [(gogoproto.nullable) = false]; + string refund_address = 2 [(gogoproto.moretags) = "yaml:\"refund_address\""]; + repeated string relayers = 3; +} + +// PacketFees contains a list of type PacketFee +message PacketFees { + repeated PacketFee packet_fees = 1 [(gogoproto.moretags) = "yaml:\"packet_fees\"", (gogoproto.nullable) = false]; +} + +// IdentifiedPacketFees contains a PacketFree and associated PacketId message IdentifiedPacketFees { - repeated IdentifiedPacketFee packet_fees = 1 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"packet_fees\""]; -} \ No newline at end of file + ibc.core.channel.v1.PacketId packet_id = 1 + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"packet_id\""]; + repeated PacketFee packet_fees = 2 [(gogoproto.moretags) = "yaml:\"packet_fees\"", (gogoproto.nullable) = false]; +} diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index 4780a68f72e..470e5b54a47 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -12,9 +12,12 @@ import "ibc/core/channel/v1/channel.proto"; message GenesisState { repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\"", (gogoproto.nullable) = false]; - repeated FeeEnabledChannel fee_enabled_channels = 2 [(gogoproto.moretags) = "yaml:\"fee_enabled_channels\"", (gogoproto.nullable) = false]; - repeated RegisteredRelayerAddress registered_relayers = 3 [(gogoproto.moretags) = "yaml:\"registered_relayers\"", (gogoproto.nullable) = false]; - repeated ForwardRelayerAddress forward_relayers = 4 [(gogoproto.moretags) = "yaml:\"forward_relayers\"", (gogoproto.nullable) = false]; + repeated FeeEnabledChannel fee_enabled_channels = 2 + [(gogoproto.moretags) = "yaml:\"fee_enabled_channels\"", (gogoproto.nullable) = false]; + repeated RegisteredRelayerAddress registered_relayers = 3 + [(gogoproto.moretags) = "yaml:\"registered_relayers\"", (gogoproto.nullable) = false]; + repeated ForwardRelayerAddress forward_relayers = 4 + [(gogoproto.moretags) = "yaml:\"forward_relayers\"", (gogoproto.nullable) = false]; } // FeeEnabledChannel contains the PortID & ChannelID for a fee enabled channel From 615200bf42cb17286928168a79a1484b2e06ece1 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 21 Feb 2022 13:12:02 +0000 Subject: [PATCH 2/6] refactoring ics29 fees for more efficient storage --- modules/apps/29-fee/ibc_module.go | 8 +++---- modules/apps/29-fee/keeper/escrow.go | 24 ++++++++++----------- modules/apps/29-fee/keeper/events.go | 14 ++++++------ modules/apps/29-fee/keeper/keeper.go | 32 ++++++++++++++-------------- modules/apps/29-fee/types/fee.go | 24 ++++++++++++++++++--- 5 files changed, 60 insertions(+), 42 deletions(-) diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index 66e40d5d8d8..421900807a6 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -225,13 +225,13 @@ func (im IBCModule) OnAcknowledgementPacket( } packetID := channeltypes.NewPacketId(packet.SourceChannel, packet.SourcePort, packet.Sequence) - identifiedPacketFees, found := im.keeper.GetFeesInEscrow(ctx, packetID) + feesInEscrow, found := im.keeper.GetFeesInEscrow(ctx, packetID) if !found { // return underlying callback if no fee found for given packetID return im.app.OnAcknowledgementPacket(ctx, packet, ack.Result, relayer) } - im.keeper.DistributePacketFees(ctx, ack.ForwardRelayerAddress, relayer, identifiedPacketFees.PacketFees) + im.keeper.DistributePacketFees(ctx, ack.ForwardRelayerAddress, relayer, feesInEscrow.PacketFees) // removes the fees from the store as fees are now paid im.keeper.DeleteFeesInEscrow(ctx, packetID) @@ -252,13 +252,13 @@ func (im IBCModule) OnTimeoutPacket( } packetID := channeltypes.NewPacketId(packet.SourceChannel, packet.SourcePort, packet.Sequence) - identifiedPacketFees, found := im.keeper.GetFeesInEscrow(ctx, packetID) + feesInEscrow, found := im.keeper.GetFeesInEscrow(ctx, packetID) if !found { // return underlying callback if fee not found for given packetID return im.app.OnTimeoutPacket(ctx, packet, relayer) } - im.keeper.DistributePacketFeesOnTimeout(ctx, relayer, identifiedPacketFees.PacketFees) + im.keeper.DistributePacketFeesOnTimeout(ctx, relayer, feesInEscrow.PacketFees) // removes the fee from the store as fee is now paid im.keeper.DeleteFeesInEscrow(ctx, packetID) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index ec62156855b..d3e96bad312 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -11,13 +11,13 @@ import ( ) // EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow -func (k Keeper) EscrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, identifiedFee types.IdentifiedPacketFee) error { +func (k Keeper) EscrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, packetFee types.PacketFee) error { if !k.IsFeeEnabled(ctx, packetID.PortId, packetID.ChannelId) { // users may not escrow fees on this channel. Must send packets without a fee message return sdkerrors.Wrap(types.ErrFeeNotEnabled, "cannot escrow fee for packet") } // check if the refund account exists - refundAcc, err := sdk.AccAddressFromBech32(identifiedFee.RefundAddress) + refundAcc, err := sdk.AccAddressFromBech32(packetFee.RefundAddress) if err != nil { return err } @@ -27,26 +27,26 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, return sdkerrors.Wrapf(types.ErrRefundAccNotFound, "account with address: %s not found", refundAcc) } - coins := identifiedFee.Fee.Total() + coins := packetFee.Fee.Total() if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, refundAcc, types.ModuleName, coins); err != nil { return err } - packetFees := []types.IdentifiedPacketFee{identifiedFee} + fees := []types.PacketFee{packetFee} if feesInEscrow, found := k.GetFeesInEscrow(ctx, packetID); found { - packetFees = append(packetFees, feesInEscrow.PacketFees...) + fees = append(fees, feesInEscrow.PacketFees...) } - identifiedFees := types.NewIdentifiedPacketFees(packetFees) - k.SetFeesInEscrow(ctx, packetID, identifiedFees) + packetFees := types.NewPacketFees(fees) + k.SetFeesInEscrow(ctx, packetID, packetFees) - EmitIncentivizedPacket(ctx, identifiedFee) + EmitIncentivizedPacket(ctx, packetID, packetFee) return nil } // DistributePacketFees 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) DistributePacketFees(ctx sdk.Context, forwardRelayer string, reverseRelayer sdk.AccAddress, feesInEscrow []types.IdentifiedPacketFee) { +func (k Keeper) DistributePacketFees(ctx sdk.Context, forwardRelayer string, reverseRelayer sdk.AccAddress, feesInEscrow []types.PacketFee) { forwardAddr, _ := sdk.AccAddressFromBech32(forwardRelayer) for _, packetFee := range feesInEscrow { @@ -73,7 +73,7 @@ func (k Keeper) DistributePacketFees(ctx sdk.Context, forwardRelayer string, rev } // DistributePacketsFeesTimeout 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) DistributePacketFeesOnTimeout(ctx sdk.Context, timeoutRelayer sdk.AccAddress, feesInEscrow []types.IdentifiedPacketFee) { +func (k Keeper) DistributePacketFeesOnTimeout(ctx sdk.Context, timeoutRelayer sdk.AccAddress, feesInEscrow []types.PacketFee) { for _, feeInEscrow := range feesInEscrow { // check if refundAcc address works refundAddr, err := sdk.AccAddressFromBech32(feeInEscrow.RefundAddress) @@ -113,8 +113,8 @@ func (k Keeper) RefundFeesOnChannel(ctx sdk.Context, portID, channelID string) e var refundErr error - k.IterateIdentifiedChannelFeesInEscrow(ctx, portID, channelID, func(identifiedFees types.IdentifiedPacketFees) (stop bool) { - for _, identifiedFee := range identifiedFees.PacketFees { + k.IteratePacketFeesInEscrow(ctx, portID, channelID, func(packetFees types.PacketFees) (stop bool) { + for _, identifiedFee := range packetFees.PacketFees { refundAccAddr, err := sdk.AccAddressFromBech32(identifiedFee.RefundAddress) if err != nil { refundErr = err diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index 64c44a34ea0..9ff6f320ffc 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -10,16 +10,16 @@ import ( ) // EmitIncentivizedPacket emits an event so that relayers know an incentivized packet is ready to be relayed -func EmitIncentivizedPacket(ctx sdk.Context, identifiedFee types.IdentifiedPacketFee) { +func EmitIncentivizedPacket(ctx sdk.Context, packetID channeltypes.PacketId, packetFee types.PacketFee) { ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeIncentivizedPacket, - sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), - sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), - sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), - sdk.NewAttribute(types.AttributeKeyRecvFee, identifiedFee.Fee.RecvFee.String()), - sdk.NewAttribute(types.AttributeKeyAckFee, identifiedFee.Fee.AckFee.String()), - sdk.NewAttribute(types.AttributeKeyTimeoutFee, identifiedFee.Fee.TimeoutFee.String()), + sdk.NewAttribute(channeltypes.AttributeKeyPortID, packetID.PortId), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, packetID.ChannelId), + sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(packetID.Sequence)), + sdk.NewAttribute(types.AttributeKeyRecvFee, packetFee.Fee.RecvFee.String()), + sdk.NewAttribute(types.AttributeKeyAckFee, packetFee.Fee.AckFee.String()), + sdk.NewAttribute(types.AttributeKeyTimeoutFee, packetFee.Fee.TimeoutFee.String()), ), ) } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 2d7fb3e5135..4694ac51b6d 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -248,12 +248,12 @@ func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId channeltypes.PacketId) } // GetFeesInEscrow returns all escrowed packet fees for a given packetID -func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) (types.IdentifiedPacketFees, bool) { +func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) (types.PacketFees, bool) { store := ctx.KVStore(k.storeKey) key := types.KeyFeesInEscrow(packetID) bz := store.Get(key) if bz == nil { - return types.IdentifiedPacketFees{}, false + return types.PacketFees{}, false } return k.MustUnmarshalFees(bz), true @@ -268,7 +268,7 @@ func (k Keeper) HasFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) } // SetFeesInEscrow sets the given packet fees in escrow keyed by the packet identifier -func (k Keeper) SetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId, fees types.IdentifiedPacketFees) { +func (k Keeper) SetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId, fees types.PacketFees) { store := ctx.KVStore(k.storeKey) bz := k.MustMarshalFees(fees) store.Set(types.KeyFeesInEscrow(packetID), bz) @@ -281,31 +281,31 @@ func (k Keeper) DeleteFeesInEscrow(ctx sdk.Context, packetID channeltypes.Packet store.Delete(key) } -// IterateChannelFeesInEscrow iterates over all the fees on the given channel currently escrowed and calls the provided callback +// IteratePacketFeesInEscrow iterates over all the fees on the given channel currently escrowed and calls the provided callback // if the callback returns true, then iteration is stopped. -func (k Keeper) IterateChannelFeesInEscrow(ctx sdk.Context, portID, channelID string, cb func(identifiedFee types.IdentifiedPacketFee) (stop bool)) { +func (k Keeper) IteratePacketFeesInEscrow(ctx sdk.Context, portID, channelID string, cb func(packetFees types.PacketFees) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.KeyFeeInEscrowChannelPrefix(portID, channelID)) + iterator := sdk.KVStorePrefixIterator(store, types.KeyFeesInEscrowChannelPrefix(portID, channelID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - identifiedFee := k.MustUnmarshalFee(iterator.Value()) - if cb(identifiedFee) { + packetFees := k.MustUnmarshalFees(iterator.Value()) + if cb(packetFees) { break } } } -// IterateIdentifiedChannelFeesInEscrow iterates over all the fees on the given channel currently escrowed and calls the provided callback +// IterateChannelFeesInEscrow iterates over all the fees on the given channel currently escrowed and calls the provided callback // if the callback returns true, then iteration is stopped. -func (k Keeper) IterateIdentifiedChannelFeesInEscrow(ctx sdk.Context, portID, channelID string, cb func(identifiedFees types.IdentifiedPacketFees) (stop bool)) { +func (k Keeper) IterateChannelFeesInEscrow(ctx sdk.Context, portID, channelID string, cb func(identifiedFee types.IdentifiedPacketFee) (stop bool)) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.KeyFeesInEscrowChannelPrefix(portID, channelID)) + iterator := sdk.KVStorePrefixIterator(store, types.KeyFeeInEscrowChannelPrefix(portID, channelID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - identifiedFees := k.MustUnmarshalFees(iterator.Value()) - if cb(identifiedFees) { + identifiedFee := k.MustUnmarshalFee(iterator.Value()) + if cb(identifiedFee) { break } } @@ -357,14 +357,14 @@ func (k Keeper) MustUnmarshalFee(bz []byte) types.IdentifiedPacketFee { // MustMarshalFees attempts to encode a Fee object and returns the // raw encoded bytes. It panics on error. -func (k Keeper) MustMarshalFees(fees types.IdentifiedPacketFees) []byte { +func (k Keeper) MustMarshalFees(fees types.PacketFees) []byte { return k.cdc.MustMarshal(&fees) } // MustUnmarshalFees attempts to decode and return a Fee object from // raw encoded bytes. It panics on error. -func (k Keeper) MustUnmarshalFees(bz []byte) types.IdentifiedPacketFees { - var fees types.IdentifiedPacketFees +func (k Keeper) MustUnmarshalFees(bz []byte) types.PacketFees { + var fees types.PacketFees k.cdc.MustUnmarshal(bz, &fees) return fees } diff --git a/modules/apps/29-fee/types/fee.go b/modules/apps/29-fee/types/fee.go index 7453c88e50e..54dd9ee1435 100644 --- a/modules/apps/29-fee/types/fee.go +++ b/modules/apps/29-fee/types/fee.go @@ -7,13 +7,31 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// NewIdentifiedPacketFees creates and returns a new IdentifiedPacketFees struct -func NewIdentifiedPacketFees(packetFees []IdentifiedPacketFee) IdentifiedPacketFees { - return IdentifiedPacketFees{ +// NewPacketFee creates and returns a new PacketFee struct including the incentivization fees, refund addres and relayers +func NewPacketFee(fee Fee, refundAddr string, relayers []string) PacketFee { + return PacketFee{ + Fee: fee, + RefundAddress: refundAddr, + Relayers: relayers, + } +} + +// NewPacketFees creates and returns a new PacketFees struct including a list of type PacketFee +func NewPacketFees(packetFees []PacketFee) PacketFees { + return PacketFees{ PacketFees: packetFees, } } +// NewFee creates and returns a new Fee struct encapsulating the receive, acknowledgement and timeout fees as sdk.Coins +func NewFee(recvFee, ackFee, timeoutFee sdk.Coins) Fee { + return Fee{ + RecvFee: recvFee, + AckFee: ackFee, + TimeoutFee: timeoutFee, + } +} + // Total returns the total amount for a given Fee func (f Fee) Total() sdk.Coins { return f.RecvFee.Add(f.AckFee...).Add(f.TimeoutFee...) From c5178be872a3349ea70775a50acff8066c55a0cb Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 21 Feb 2022 13:12:11 +0000 Subject: [PATCH 3/6] updating tests --- modules/apps/29-fee/ibc_module_test.go | 46 +++++++++++------------ modules/apps/29-fee/keeper/escrow_test.go | 44 +++++++++------------- modules/apps/29-fee/keeper/msg_server.go | 8 ++-- 3 files changed, 45 insertions(+), 53 deletions(-) diff --git a/modules/apps/29-fee/ibc_module_test.go b/modules/apps/29-fee/ibc_module_test.go index b556f057d7e..8ffbdd5466b 100644 --- a/modules/apps/29-fee/ibc_module_test.go +++ b/modules/apps/29-fee/ibc_module_test.go @@ -306,8 +306,8 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() { 1, ) refundAcc := suite.chainA.SenderAccount.GetAddress() - identifiedFee := types.NewIdentifiedPacketFee(packetID, types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedFee) + packetFee := types.NewPacketFee(types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) }, false, @@ -321,8 +321,8 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() { Sequence: 1, } refundAcc := suite.chainA.SenderAccount.GetAddress() - identifiedFee := types.NewIdentifiedPacketFee(packetID, types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedFee) + packetFee := types.NewPacketFee(types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) suite.chainA.GetSimApp().BankKeeper.SendCoinsFromModuleToAccount(suite.chainA.GetContext(), types.ModuleName, refundAcc, validCoins3) @@ -384,8 +384,8 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { Sequence: 1, } refundAcc := suite.chainA.SenderAccount.GetAddress() - identifiedFee := types.NewIdentifiedPacketFee(packetID, types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedFee) + packetFee := types.NewPacketFee(types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) }, false, @@ -399,8 +399,8 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() { Sequence: 1, } refundAcc := suite.chainA.SenderAccount.GetAddress() - identifiedFee := types.NewIdentifiedPacketFee(packetID, types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedFee) + packetFee := types.NewPacketFee(types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) suite.chainA.GetSimApp().BankKeeper.SendCoinsFromModuleToAccount(suite.chainA.GetContext(), types.ModuleName, refundAcc, validCoins3) @@ -531,7 +531,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { var ( ack []byte - identifiedFee types.IdentifiedPacketFee + packetFee types.PacketFee originalBalance sdk.Coins expectedBalance sdk.Coins expectedRelayerBalance sdk.Coins @@ -545,7 +545,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { { "success", func() { - expectedRelayerBalance = identifiedFee.Fee.RecvFee.Add(identifiedFee.Fee.AckFee[0]) + expectedRelayerBalance = packetFee.Fee.RecvFee.Add(packetFee.Fee.AckFee[0]) }, true, }, @@ -593,7 +593,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { ForwardRelayerAddress: blockedAddr.String(), }.Acknowledgement() - expectedRelayerBalance = identifiedFee.Fee.AckFee + expectedRelayerBalance = packetFee.Fee.AckFee }, true, }, @@ -617,8 +617,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { // escrow the packet fee packetID := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()) - identifiedFee = types.NewIdentifiedPacketFee( - packetID, + packetFee = types.NewPacketFee( types.Fee{ RecvFee: validCoins, AckFee: validCoins2, @@ -627,7 +626,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { suite.chainA.SenderAccount.GetAddress().String(), []string{}, ) - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedFee) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) relayerAddr := suite.chainB.SenderAccount.GetAddress() @@ -643,7 +642,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { originalBalance = sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom)) // default to success case - expectedBalance = originalBalance.Add(identifiedFee.Fee.TimeoutFee[0]) + expectedBalance = originalBalance.Add(packetFee.Fee.TimeoutFee[0]) // malleate test case tc.malleate() @@ -674,7 +673,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { func (suite *FeeTestSuite) TestOnTimeoutPacket() { var ( relayerAddr sdk.AccAddress - identifiedFee types.IdentifiedPacketFee + packetFee types.PacketFee originalBalance sdk.Coins expectedBalance sdk.Coins ) @@ -714,8 +713,8 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { relayerAddr = suite.chainA.GetSimApp().AccountKeeper.GetModuleAccount(suite.chainA.GetContext(), transfertypes.ModuleName).GetAddress() expectedBalance = originalBalance. - Add(identifiedFee.Fee.RecvFee[0]). - Add(identifiedFee.Fee.AckFee[0]) + Add(packetFee.Fee.RecvFee[0]). + Add(packetFee.Fee.AckFee[0]) }, false, }, @@ -740,8 +739,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { // must be explicitly changed relayerAddr = suite.chainB.SenderAccount.GetAddress() - identifiedFee = types.NewIdentifiedPacketFee( - packetID, + packetFee = types.NewPacketFee( types.Fee{ RecvFee: validCoins, AckFee: validCoins2, @@ -751,7 +749,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { []string{}, ) - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedFee) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) // log original sender balance @@ -760,8 +758,8 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { // default to success case expectedBalance = originalBalance. - Add(identifiedFee.Fee.RecvFee[0]). - Add(identifiedFee.Fee.AckFee[0]) + Add(packetFee.Fee.RecvFee[0]). + Add(packetFee.Fee.AckFee[0]) // malleate test case tc.malleate() @@ -780,7 +778,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { found := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeesInEscrow(suite.chainA.GetContext(), packetID) suite.Require().False(found) - suite.Require().Equal(identifiedFee.Fee.TimeoutFee, relayerBalance) + suite.Require().Equal(packetFee.Fee.TimeoutFee, relayerBalance) } else { suite.Require().Empty(relayerBalance) } diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index fe582aa4335..81103197aa5 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -35,11 +35,8 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { TimeoutFee: timeoutFee, } - identifiedPacketFee := types.NewIdentifiedPacketFee(packetID, fee, refundAcc.String(), []string{}) - - feesInEscrow := types.IdentifiedPacketFees{ - PacketFees: []types.IdentifiedPacketFee{identifiedPacketFee}, - } + packetFee := types.NewPacketFee(fee, refundAcc.String(), []string{}) + feesInEscrow := types.NewPacketFees([]types.PacketFee{packetFee}) suite.chainA.GetSimApp().IBCFeeKeeper.SetFeesInEscrow(suite.chainA.GetContext(), packetID, feesInEscrow) }, true, @@ -92,13 +89,13 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { AckFee: ackFee, TimeoutFee: timeoutFee, } - identifiedPacketFee := types.NewIdentifiedPacketFee(packetID, fee, refundAcc.String(), []string{}) + packetFee := types.NewPacketFee(fee, refundAcc.String(), []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(), packetID, identifiedPacketFee) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) if tc.expPass { feesInEscrow, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeesInEscrow(suite.chainA.GetContext(), packetID) @@ -166,12 +163,12 @@ func (suite *KeeperTestSuite) TestDistributeFee() { } // escrow the packet fee & store the fee in state - identifiedPacketFee := types.NewIdentifiedPacketFee(packetID, fee, refundAcc.String(), []string{}) + packetFee := types.NewPacketFee(fee, refundAcc.String(), []string{}) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) // escrow a second packet fee to test with multiple fees distributed - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) tc.malleate() @@ -179,7 +176,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { // refundAcc balance after escrow refundAccBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom) - suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFees(suite.chainA.GetContext(), forwardRelayer, reverseRelayer, []types.IdentifiedPacketFee{identifiedPacketFee, identifiedPacketFee}) + suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFees(suite.chainA.GetContext(), forwardRelayer, reverseRelayer, []types.PacketFee{packetFee, packetFee}) if tc.expPass { // there should no longer be a fee in escrow for this packet @@ -234,23 +231,18 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { } // escrow the packet fee & store the fee in state - identifiedPacketFee := types.NewIdentifiedPacketFee( - packetID, - fee, - refundAcc.String(), - []string{}, - ) + packetFee := types.NewPacketFee(fee, refundAcc.String(), []string{}) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) // escrow a second packet fee to test with multiple fees distributed - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) // refundAcc balance after escrow refundAccBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom) - suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFeesOnTimeout(suite.chainA.GetContext(), timeoutRelayer, []types.IdentifiedPacketFee{identifiedPacketFee, identifiedPacketFee}) + suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFeesOnTimeout(suite.chainA.GetContext(), timeoutRelayer, []types.PacketFee{packetFee, packetFee}) // check if the timeoutRelayer has been paid hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), timeoutRelayer, fee.TimeoutFee[0]) @@ -284,9 +276,9 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() { TimeoutFee: defaultTimeoutFee, } - identifiedPacketFee := types.NewIdentifiedPacketFee(packetID, fee, refundAcc.String(), []string{}) + packetFee := types.NewPacketFee(fee, refundAcc.String(), []string{}) suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) } @@ -298,9 +290,9 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() { TimeoutFee: defaultTimeoutFee, } - identifiedPacketFee := types.NewIdentifiedPacketFee(packetID, fee, refundAcc.String(), []string{}) + packetFee := types.NewPacketFee(fee, refundAcc.String(), []string{}) suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, "channel-1") - err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) // check that refunding all fees on channel-0 refunds all fees except for fee on channel-1 @@ -314,8 +306,8 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() { // create escrow and then change module account balance to cause error on refund packetID = channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, uint64(6)) - identifiedPacketFee = types.NewIdentifiedPacketFee(packetID, fee, refundAcc.String(), []string{}) - err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, identifiedPacketFee) + packetFee = types.NewPacketFee(fee, refundAcc.String(), []string{}) + err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) suite.Require().NoError(err) suite.chainA.GetSimApp().BankKeeper.SendCoinsFromModuleToAccount(suite.chainA.GetContext(), types.ModuleName, refundAcc, fee.TimeoutFee) diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index a87962c518b..678a8b6c08c 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -43,8 +43,8 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) sequence, ) - identifiedPacket := types.NewIdentifiedPacketFee(packetID, msg.Fee, msg.Signer, msg.Relayers) - if err := k.EscrowPacketFee(ctx, packetID, identifiedPacket); err != nil { + packetFee := types.NewPacketFee(msg.Fee, msg.Signer, msg.Relayers) + if err := k.EscrowPacketFee(ctx, packetID, packetFee); err != nil { return nil, err } @@ -57,7 +57,9 @@ 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) - if err := k.EscrowPacketFee(ctx, msg.IdentifiedPacketFee.PacketId, msg.IdentifiedPacketFee); err != nil { + // TODO: Update MsgPayPacketFeeAsync to include PacketFee in favour of IdentifiedPacketFee + packetFee := types.NewPacketFee(msg.IdentifiedPacketFee.Fee, msg.IdentifiedPacketFee.RefundAddress, msg.IdentifiedPacketFee.Relayers) + if err := k.EscrowPacketFee(ctx, msg.IdentifiedPacketFee.PacketId, packetFee); err != nil { return nil, err } From e3bd5c5c04cc27481b80ac1cf7e373e3d92fed21 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 21 Feb 2022 16:24:27 +0000 Subject: [PATCH 4/6] fixing typo in protodoc comments --- docs/ibc/proto-docs.md | 2 +- modules/apps/29-fee/types/fee.pb.go | 2 +- proto/ibc/applications/fee/v1/fee.proto | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 3da59f9038c..40e9dff81d8 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -743,7 +743,7 @@ and an optional list of relayers that are permitted to receive the fee. ### IdentifiedPacketFees -IdentifiedPacketFees contains a PacketFree and associated PacketId +IdentifiedPacketFees contains a list of type PacketFee and associated PacketId | Field | Type | Label | Description | diff --git a/modules/apps/29-fee/types/fee.pb.go b/modules/apps/29-fee/types/fee.pb.go index e3e41810f96..ad74e0b2d86 100644 --- a/modules/apps/29-fee/types/fee.pb.go +++ b/modules/apps/29-fee/types/fee.pb.go @@ -268,7 +268,7 @@ func (m *PacketFees) GetPacketFees() []PacketFee { return nil } -// IdentifiedPacketFees contains a PacketFree and associated PacketId +// IdentifiedPacketFees contains a list of type PacketFee and associated PacketId type IdentifiedPacketFees struct { PacketId types1.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id" yaml:"packet_id"` PacketFees []PacketFee `protobuf:"bytes,2,rep,name=packet_fees,json=packetFees,proto3" json:"packet_fees" yaml:"packet_fees"` diff --git a/proto/ibc/applications/fee/v1/fee.proto b/proto/ibc/applications/fee/v1/fee.proto index 09fdd6d1a7d..4d39ad3786c 100644 --- a/proto/ibc/applications/fee/v1/fee.proto +++ b/proto/ibc/applications/fee/v1/fee.proto @@ -54,7 +54,7 @@ message PacketFees { repeated PacketFee packet_fees = 1 [(gogoproto.moretags) = "yaml:\"packet_fees\"", (gogoproto.nullable) = false]; } -// IdentifiedPacketFees contains a PacketFree and associated PacketId +// IdentifiedPacketFees contains a list of type PacketFee and associated PacketId message IdentifiedPacketFees { ibc.core.channel.v1.PacketId packet_id = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"packet_id\""]; From aedd3597e15c5edcb42b726e4eec7612e7db32e3 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 23 Feb 2022 10:43:19 +0000 Subject: [PATCH 5/6] updating protos and codegen --- docs/ibc/proto-docs.md | 3 +- modules/apps/29-fee/types/tx.pb.go | 141 +++++++++++++------- proto/ibc/applications/fee/v1/ack.proto | 2 +- proto/ibc/applications/fee/v1/genesis.proto | 2 +- proto/ibc/applications/fee/v1/tx.proto | 12 +- 5 files changed, 106 insertions(+), 54 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 9bf131b1b56..12fe22e2ee9 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -1041,7 +1041,8 @@ This Msg can be used to pay for a packet at a specified sequence (instead of the | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `identified_packet_fee` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | identified packet to pay fee for identified fee must contain the refund address which is also signer of this message | +| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | unique packet identifier | +| `packet_fee` | [PacketFee](#ibc.applications.fee.v1.PacketFee) | | packet fee for incentivization | diff --git a/modules/apps/29-fee/types/tx.pb.go b/modules/apps/29-fee/types/tx.pb.go index a7f8e1d3bee..c30331992dd 100644 --- a/modules/apps/29-fee/types/tx.pb.go +++ b/modules/apps/29-fee/types/tx.pb.go @@ -6,6 +6,7 @@ package types import ( context "context" fmt "fmt" + types "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -194,9 +195,10 @@ 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 { - // identified packet to pay fee for - // identified fee must contain the refund address which is also signer of this message - IdentifiedPacketFee IdentifiedPacketFee `protobuf:"bytes,1,opt,name=identified_packet_fee,json=identifiedPacketFee,proto3" json:"identified_packet_fee" yaml:"identified_packet_fee"` + // unique packet identifier + PacketId types.PacketId `protobuf:"bytes,1,opt,name=packet_id,json=packetId,proto3" json:"packet_id" yaml:"packet_id"` + // packet fee for incentivization + PacketFee PacketFee `protobuf:"bytes,2,opt,name=packet_fee,json=packetFee,proto3" json:"packet_fee" yaml:"packet_fee"` } func (m *MsgPayPacketFeeAsync) Reset() { *m = MsgPayPacketFeeAsync{} } @@ -281,45 +283,47 @@ func init() { func init() { proto.RegisterFile("ibc/applications/fee/v1/tx.proto", fileDescriptor_05c93128649f1b96) } var fileDescriptor_05c93128649f1b96 = []byte{ - // 594 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4d, 0x4f, 0xdb, 0x4c, - 0x10, 0xc7, 0x6d, 0xc2, 0xc3, 0x03, 0x5b, 0x54, 0x84, 0x81, 0x62, 0x4c, 0x64, 0x53, 0xab, 0xaa, - 0x72, 0x28, 0x76, 0x79, 0x53, 0x55, 0x2e, 0x88, 0x20, 0xa1, 0x72, 0x40, 0x8d, 0x7c, 0xec, 0x25, - 0x72, 0xd6, 0x13, 0xb3, 0x6d, 0xe2, 0xb5, 0xbc, 0x9b, 0xa8, 0xfe, 0x02, 0xa8, 0x47, 0x6e, 0xbd, - 0x72, 0xed, 0x37, 0xe1, 0x54, 0x71, 0xec, 0xc9, 0xaa, 0x92, 0x4b, 0xcf, 0xf9, 0x04, 0x95, 0xed, - 0xd8, 0x75, 0xc8, 0x8b, 0x68, 0x6f, 0x3b, 0x3b, 0xbf, 0xf9, 0xef, 0xcc, 0x7f, 0x57, 0x8b, 0x76, - 0x48, 0x03, 0x9b, 0xb6, 0xef, 0xb7, 0x08, 0xb6, 0x39, 0xa1, 0x1e, 0x33, 0x9b, 0x00, 0x66, 0x77, - 0xcf, 0xe4, 0x9f, 0x0d, 0x3f, 0xa0, 0x9c, 0x4a, 0x9b, 0xa4, 0x81, 0x8d, 0x22, 0x61, 0x34, 0x01, - 0x8c, 0xee, 0x9e, 0xb2, 0xee, 0x52, 0x97, 0x26, 0x8c, 0x19, 0xaf, 0x52, 0x5c, 0x79, 0x3e, 0x4d, - 0x30, 0xae, 0x4a, 0x10, 0xfd, 0xbb, 0x88, 0xd4, 0x4b, 0xe6, 0x5a, 0xe0, 0x12, 0xc6, 0x21, 0x38, - 0xa3, 0x1d, 0x8f, 0x43, 0xe0, 0xdb, 0x01, 0x0f, 0x4f, 0x1d, 0x27, 0x00, 0xc6, 0x24, 0x19, 0xfd, - 0x6f, 0xa7, 0x4b, 0x59, 0xdc, 0x11, 0x2b, 0x4b, 0x56, 0x16, 0x4a, 0x16, 0x5a, 0xc7, 0x85, 0x82, - 0x7a, 0x86, 0xcd, 0xc5, 0x58, 0x55, 0x1b, 0x44, 0xda, 0x76, 0x68, 0xb7, 0x5b, 0xc7, 0xfa, 0x24, - 0x4a, 0xb7, 0xd6, 0xf0, 0x84, 0xd3, 0x0e, 0x11, 0xc2, 0x57, 0xb6, 0xe7, 0x41, 0xab, 0x4e, 0x1c, - 0xb9, 0x94, 0x28, 0x6d, 0x0c, 0x22, 0x6d, 0x75, 0xa8, 0x94, 0xe7, 0x74, 0x6b, 0x69, 0x18, 0x5c, - 0x38, 0xc7, 0x8b, 0x5f, 0x6e, 0x35, 0xe1, 0xd7, 0xad, 0x26, 0xe8, 0x15, 0xf4, 0x72, 0xf6, 0x3c, - 0x16, 0x30, 0x9f, 0x7a, 0x0c, 0xf4, 0x9b, 0x39, 0xb4, 0x72, 0xc9, 0xdc, 0x9a, 0x1d, 0xd6, 0x6c, - 0xfc, 0x09, 0xf8, 0x39, 0x80, 0x74, 0x88, 0x4a, 0x4d, 0x80, 0x64, 0xce, 0x27, 0xfb, 0x65, 0x63, - 0x8a, 0xdd, 0xc6, 0x39, 0x40, 0x75, 0xfe, 0x2e, 0xd2, 0x04, 0x2b, 0xc6, 0xa5, 0x13, 0xf4, 0x94, - 0xd1, 0x4e, 0x80, 0xa1, 0xee, 0xd3, 0x80, 0xc7, 0x7d, 0xa7, 0x0e, 0x6c, 0x0d, 0x22, 0x6d, 0x23, - 0xed, 0x7b, 0x34, 0xaf, 0x5b, 0xcb, 0xe9, 0x46, 0x8d, 0x06, 0xfc, 0xc2, 0x91, 0xde, 0xa1, 0xd5, - 0x21, 0x30, 0x36, 0x7b, 0x79, 0x10, 0x69, 0xf2, 0x88, 0x46, 0xd1, 0x82, 0x95, 0x74, 0xef, 0x2c, - 0x33, 0x42, 0x7a, 0x86, 0x16, 0x18, 0x71, 0x3d, 0x08, 0xe4, 0xf9, 0xe4, 0xae, 0x86, 0x91, 0xa4, - 0xa0, 0xc5, 0x00, 0x5a, 0x76, 0x08, 0x01, 0x93, 0xff, 0xdb, 0x29, 0x55, 0x96, 0xac, 0x3c, 0x2e, - 0x98, 0xb7, 0x85, 0x36, 0x1f, 0x38, 0x92, 0xbb, 0xf5, 0x4d, 0x44, 0xeb, 0x0f, 0x72, 0xa7, 0x2c, - 0xf4, 0xb0, 0x74, 0x2d, 0xa2, 0x0d, 0xe2, 0x80, 0xc7, 0x49, 0x93, 0x80, 0x53, 0xf7, 0x93, 0x6c, - 0xfd, 0x8f, 0x8b, 0xaf, 0xa6, 0xba, 0x78, 0x91, 0x57, 0xe5, 0x92, 0xd5, 0x17, 0xb1, 0xab, 0x83, - 0x48, 0x2b, 0xa7, 0x23, 0x4f, 0x14, 0xd6, 0xad, 0x35, 0x32, 0x5e, 0x5a, 0x18, 0x43, 0x45, 0xe5, - 0x49, 0xad, 0x66, 0xb3, 0xec, 0x5f, 0x97, 0x50, 0xe9, 0x92, 0xb9, 0xd2, 0x57, 0x11, 0x6d, 0xcf, - 0x7a, 0xf9, 0x6f, 0xa6, 0xb6, 0x3e, 0xfb, 0x89, 0x29, 0x27, 0xff, 0x58, 0x98, 0x75, 0x28, 0x7d, - 0x44, 0xcb, 0x23, 0xef, 0xb2, 0x32, 0x4b, 0xb0, 0x48, 0x2a, 0xaf, 0x1f, 0x4b, 0xe6, 0x67, 0x85, - 0x68, 0x75, 0xfc, 0x56, 0x77, 0x1f, 0x2b, 0x93, 0xe0, 0xca, 0xd1, 0x5f, 0xe1, 0xd9, 0xd1, 0xd5, - 0xf7, 0x77, 0x3d, 0x55, 0xbc, 0xef, 0xa9, 0xe2, 0xcf, 0x9e, 0x2a, 0xde, 0xf4, 0x55, 0xe1, 0xbe, - 0xaf, 0x0a, 0x3f, 0xfa, 0xaa, 0xf0, 0xe1, 0xc8, 0x25, 0xfc, 0xaa, 0xd3, 0x30, 0x30, 0x6d, 0x9b, - 0x98, 0xb2, 0x36, 0x65, 0x26, 0x69, 0xe0, 0x5d, 0x97, 0x9a, 0xdd, 0x03, 0xb3, 0x4d, 0x9d, 0x4e, - 0x0b, 0x58, 0xfc, 0xb5, 0x31, 0x73, 0xff, 0xed, 0x6e, 0xfc, 0xab, 0xf1, 0xd0, 0x07, 0xd6, 0x58, - 0x48, 0x7e, 0xb5, 0x83, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcf, 0x27, 0xb3, 0x4f, 0x4b, 0x05, - 0x00, 0x00, + // 630 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4d, 0x4f, 0xdb, 0x40, + 0x10, 0x8d, 0x09, 0xa5, 0x64, 0x8b, 0x4a, 0xb3, 0x85, 0x62, 0x0c, 0xb5, 0xa9, 0x0f, 0x55, 0x2e, + 0xd8, 0xe5, 0x4b, 0x55, 0xb9, 0x20, 0x82, 0x84, 0xca, 0x01, 0x15, 0x59, 0x3d, 0x55, 0x95, 0x90, + 0xb3, 0x9e, 0x18, 0xb7, 0x89, 0xd7, 0xda, 0x75, 0xa2, 0xfa, 0x0f, 0x54, 0x3d, 0x72, 0xeb, 0x95, + 0x9f, 0xc3, 0xa9, 0xe2, 0xd0, 0x43, 0x4f, 0x56, 0x05, 0x97, 0x9e, 0xf3, 0x0b, 0xaa, 0xf5, 0x97, + 0x1c, 0x48, 0x22, 0xda, 0x9b, 0x77, 0xe6, 0xcd, 0xdb, 0x37, 0x6f, 0xc6, 0x8b, 0xd6, 0xbc, 0x16, + 0x31, 0xed, 0x20, 0xe8, 0x78, 0xc4, 0x0e, 0x3d, 0xea, 0x73, 0xb3, 0x0d, 0x60, 0xf6, 0x37, 0xcc, + 0xf0, 0x8b, 0x11, 0x30, 0x1a, 0x52, 0xbc, 0xe4, 0xb5, 0x88, 0x51, 0x46, 0x18, 0x6d, 0x00, 0xa3, + 0xbf, 0xa1, 0x2c, 0xb8, 0xd4, 0xa5, 0x09, 0xc6, 0x14, 0x5f, 0x29, 0x5c, 0x79, 0x31, 0x8e, 0x50, + 0x54, 0x95, 0x20, 0x84, 0x32, 0x30, 0xc9, 0x99, 0xed, 0xfb, 0xd0, 0x11, 0xe9, 0xec, 0x33, 0x85, + 0xe8, 0x3f, 0x24, 0xa4, 0x1e, 0x73, 0xd7, 0x02, 0xd7, 0xe3, 0x21, 0xb0, 0x03, 0xda, 0xf3, 0x43, + 0x60, 0x81, 0xcd, 0xc2, 0x68, 0xdf, 0x71, 0x18, 0x70, 0x8e, 0x65, 0xf4, 0xd0, 0x4e, 0x3f, 0x65, + 0x69, 0x4d, 0x6a, 0xd4, 0xac, 0xfc, 0x88, 0x2d, 0xb4, 0x40, 0x4a, 0x05, 0xa7, 0x39, 0x6c, 0x4a, + 0xc0, 0x9a, 0xda, 0x20, 0xd6, 0x56, 0x22, 0xbb, 0xdb, 0xd9, 0xd5, 0x47, 0xa1, 0x74, 0xeb, 0x29, + 0x19, 0x71, 0xdb, 0x36, 0x42, 0x99, 0xc2, 0x53, 0xcf, 0x91, 0xab, 0x09, 0xd3, 0xe2, 0x20, 0xd6, + 0xea, 0x19, 0x53, 0x91, 0xd3, 0xad, 0x5a, 0x76, 0x38, 0x72, 0x76, 0x67, 0xbf, 0x5d, 0x68, 0x95, + 0x3f, 0x17, 0x5a, 0x45, 0x6f, 0xa0, 0x97, 0x93, 0xfb, 0xb1, 0x80, 0x07, 0xd4, 0xe7, 0xa0, 0x9f, + 0x4f, 0xa1, 0xf9, 0x63, 0xee, 0x9e, 0xd8, 0xd1, 0x89, 0x4d, 0x3e, 0x43, 0x78, 0x08, 0x80, 0xb7, + 0x51, 0xb5, 0x0d, 0x90, 0xf4, 0xf9, 0x68, 0x73, 0xd5, 0x18, 0x33, 0x11, 0xe3, 0x10, 0xa0, 0x39, + 0x7d, 0x19, 0x6b, 0x15, 0x4b, 0xc0, 0xf1, 0x1e, 0x7a, 0xcc, 0x69, 0x8f, 0x11, 0x38, 0x0d, 0x28, + 0x0b, 0x85, 0xee, 0xd4, 0x81, 0xe5, 0x41, 0xac, 0x2d, 0xa6, 0xba, 0x87, 0xf3, 0xba, 0x35, 0x97, + 0x06, 0x4e, 0x28, 0x0b, 0x8f, 0x1c, 0xfc, 0x16, 0xd5, 0x33, 0xc0, 0x9d, 0xde, 0x57, 0x07, 0xb1, + 0x26, 0x0f, 0x71, 0x94, 0x2d, 0x98, 0x4f, 0x63, 0x07, 0xb9, 0x11, 0xf8, 0x19, 0x9a, 0xe1, 0x9e, + 0xeb, 0x03, 0x93, 0xa7, 0x93, 0x59, 0x65, 0x27, 0xac, 0xa0, 0x59, 0x06, 0x1d, 0x3b, 0x02, 0xc6, + 0xe5, 0x07, 0x6b, 0xd5, 0x46, 0xcd, 0x2a, 0xce, 0x25, 0xf3, 0x96, 0xd1, 0xd2, 0x2d, 0x47, 0x0a, + 0xb7, 0x7e, 0x4a, 0x68, 0xe1, 0x56, 0x6e, 0x9f, 0x47, 0x3e, 0xc1, 0xef, 0x51, 0x2d, 0x48, 0x22, + 0x42, 0x73, 0x6a, 0xdc, 0xf3, 0xc4, 0x38, 0xb1, 0x78, 0x46, 0xbe, 0x6d, 0xfd, 0x0d, 0x23, 0xad, + 0x3b, 0x72, 0x9a, 0xb2, 0x70, 0x6e, 0x10, 0x6b, 0x4f, 0xd2, 0xb6, 0x8a, 0x6a, 0xdd, 0x9a, 0x0d, + 0x32, 0x0c, 0xfe, 0x88, 0x50, 0x16, 0x17, 0xf3, 0x98, 0x4a, 0x68, 0xf5, 0xb1, 0xf3, 0x28, 0x24, + 0x35, 0x97, 0x33, 0xee, 0xfa, 0x10, 0x77, 0x1b, 0x40, 0xb7, 0x32, 0x99, 0x87, 0x00, 0xa5, 0x8e, + 0x55, 0xb4, 0x3a, 0xaa, 0xab, 0xbc, 0xed, 0xcd, 0xaf, 0x55, 0x54, 0x3d, 0xe6, 0x2e, 0xfe, 0x2e, + 0xa1, 0x95, 0x49, 0x3f, 0xc9, 0xeb, 0xb1, 0xda, 0x26, 0x6f, 0xa3, 0xb2, 0xf7, 0x9f, 0x85, 0xb9, + 0x42, 0xfc, 0x09, 0xcd, 0x0d, 0xad, 0x70, 0x63, 0x12, 0x61, 0x19, 0xa9, 0xbc, 0xba, 0x2f, 0xb2, + 0xb8, 0x2b, 0x42, 0xf5, 0xbb, 0x0b, 0xb0, 0x7e, 0x5f, 0x9a, 0x04, 0xae, 0xec, 0xfc, 0x13, 0x3c, + 0xbf, 0xba, 0xf9, 0xee, 0xf2, 0x5a, 0x95, 0xae, 0xae, 0x55, 0xe9, 0xf7, 0xb5, 0x2a, 0x9d, 0xdf, + 0xa8, 0x95, 0xab, 0x1b, 0xb5, 0xf2, 0xeb, 0x46, 0xad, 0x7c, 0xd8, 0x71, 0xbd, 0xf0, 0xac, 0xd7, + 0x32, 0x08, 0xed, 0x9a, 0x84, 0xf2, 0x2e, 0xe5, 0xa6, 0xd7, 0x22, 0xeb, 0x2e, 0x35, 0xfb, 0x5b, + 0x66, 0x97, 0x3a, 0xbd, 0x0e, 0x70, 0xf1, 0x50, 0x72, 0x73, 0xf3, 0xcd, 0xba, 0x78, 0x23, 0xc3, + 0x28, 0x00, 0xde, 0x9a, 0x49, 0x1e, 0xc0, 0xad, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcc, 0xf7, + 0x58, 0xab, 0x99, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -670,7 +674,17 @@ func (m *MsgPayPacketFeeAsync) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.IdentifiedPacketFee.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.PacketFee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -790,7 +804,9 @@ func (m *MsgPayPacketFeeAsync) Size() (n int) { } var l int _ = l - l = m.IdentifiedPacketFee.Size() + l = m.PacketId.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.PacketFee.Size() n += 1 + l + sovTx(uint64(l)) return n } @@ -1298,7 +1314,40 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field IdentifiedPacketFee", wireType) + 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 err := m.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketFee", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1325,7 +1374,7 @@ func (m *MsgPayPacketFeeAsync) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.IdentifiedPacketFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.PacketFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/proto/ibc/applications/fee/v1/ack.proto b/proto/ibc/applications/fee/v1/ack.proto index 1a0c5e3f404..6a77e4fce45 100644 --- a/proto/ibc/applications/fee/v1/ack.proto +++ b/proto/ibc/applications/fee/v1/ack.proto @@ -11,5 +11,5 @@ import "gogoproto/gogo.proto"; message IncentivizedAcknowledgement { bytes result = 1; string forward_relayer_address = 2 [(gogoproto.moretags) = "yaml:\"forward_relayer_address\""]; - bool underlying_app_success = 3 [(gogoproto.moretags) = "yaml:\"underlying_app_successl\""]; + bool underlying_app_success = 3 [(gogoproto.moretags) = "yaml:\"underlying_app_successl\""]; } diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index b832a4bcd4a..07bde848a37 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -30,7 +30,7 @@ message FeeEnabledChannel { message RegisteredRelayerAddress { string address = 1; string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; - string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; + string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; } // ForwardRelayerAddress contains the forward relayer address and packetId used for async acknowledgements diff --git a/proto/ibc/applications/fee/v1/tx.proto b/proto/ibc/applications/fee/v1/tx.proto index 532524cd4b2..ec2f2cc4f38 100644 --- a/proto/ibc/applications/fee/v1/tx.proto +++ b/proto/ibc/applications/fee/v1/tx.proto @@ -6,6 +6,7 @@ option go_package = "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"; import "gogoproto/gogo.proto"; import "ibc/applications/fee/v1/fee.proto"; +import "ibc/core/channel/v1/channel.proto"; // Msg defines the ibc/fee Msg service. service Msg { @@ -32,7 +33,7 @@ message MsgRegisterCounterpartyAddress { string address = 1; string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; - string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; + string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; } // MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type @@ -64,10 +65,11 @@ message MsgPayPacketFeeAsync { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - // identified packet to pay fee for - // identified fee must contain the refund address which is also signer of this message - ibc.applications.fee.v1.IdentifiedPacketFee identified_packet_fee = 1 - [(gogoproto.moretags) = "yaml:\"identified_packet_fee\"", (gogoproto.nullable) = false]; + // unique packet identifier + ibc.core.channel.v1.PacketId packet_id = 1 + [(gogoproto.moretags) = "yaml:\"packet_id\"", (gogoproto.nullable) = false]; + // packet fee for incentivization + PacketFee packet_fee = 2 [(gogoproto.moretags) = "yaml:\"packet_fee\"", (gogoproto.nullable) = false]; } // MsgPayPacketFeeAsyncResponse defines the response type for Msg/PayPacketFeeAsync From 02a063eb82ec08815769385c2551d119cb766561 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 23 Feb 2022 10:43:48 +0000 Subject: [PATCH 6/6] updating MsgPayPacketFeeAsync handler and tests --- modules/apps/29-fee/client/cli/tx.go | 4 +- modules/apps/29-fee/keeper/msg_server.go | 4 +- modules/apps/29-fee/keeper/msg_server_test.go | 6 +-- modules/apps/29-fee/types/fee.go | 19 ++++++++ modules/apps/29-fee/types/msgs.go | 17 ++++--- modules/apps/29-fee/types/msgs_test.go | 47 +++++++++---------- 6 files changed, 56 insertions(+), 41 deletions(-) diff --git a/modules/apps/29-fee/client/cli/tx.go b/modules/apps/29-fee/client/cli/tx.go index a9f66a71007..d14c8313dca 100644 --- a/modules/apps/29-fee/client/cli/tx.go +++ b/modules/apps/29-fee/client/cli/tx.go @@ -83,9 +83,9 @@ func NewPayPacketFeeAsyncTxCmd() *cobra.Command { TimeoutFee: timeoutFee, } - identifiedPacketFee := types.NewIdentifiedPacketFee(packetID, fee, sender, relayers) + packetFee := types.NewPacketFee(fee, sender, relayers) + msg := types.NewMsgPayPacketFeeAsync(packetID, packetFee) - msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 2f0004be150..fdac1d27874 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -57,9 +57,7 @@ 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) - // TODO: Update MsgPayPacketFeeAsync to include PacketFee in favour of IdentifiedPacketFee - packetFee := types.NewPacketFee(msg.IdentifiedPacketFee.Fee, msg.IdentifiedPacketFee.RefundAddress, msg.IdentifiedPacketFee.Relayers) - if err := k.EscrowPacketFee(ctx, msg.IdentifiedPacketFee.PacketId, packetFee); err != nil { + if err := k.EscrowPacketFee(ctx, msg.PacketId, msg.PacketFee); 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 0a8ad4b7d06..c6dc2f90856 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -119,12 +119,12 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { seq, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(ctxA, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) // build fee - packetId := channeltypes.NewPacketId(channelID, suite.path.EndpointA.ChannelConfig.PortID, seq) - identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} + packetID := channeltypes.NewPacketId(channelID, suite.path.EndpointA.ChannelConfig.PortID, seq) + packetFee := types.NewPacketFee(fee, refundAcc.String(), nil) tc.malleate() - msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee) + msg := types.NewMsgPayPacketFeeAsync(packetID, packetFee) _, err := suite.chainA.SendMsgs(msg) if tc.expPass { diff --git a/modules/apps/29-fee/types/fee.go b/modules/apps/29-fee/types/fee.go index 54dd9ee1435..4dd73893888 100644 --- a/modules/apps/29-fee/types/fee.go +++ b/modules/apps/29-fee/types/fee.go @@ -16,6 +16,25 @@ func NewPacketFee(fee Fee, refundAddr string, relayers []string) PacketFee { } } +// Validate performs basic stateless validation of the associated PacketFee +func (p PacketFee) Validate() error { + _, err := sdk.AccAddressFromBech32(p.RefundAddress) + if err != nil { + return sdkerrors.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress") + } + + // enforce relayer is nil + if p.Relayers != nil { + return ErrRelayersNotNil + } + + if err := p.Fee.Validate(); err != nil { + return err + } + + return nil +} + // NewPacketFees creates and returns a new PacketFees struct including a list of type PacketFee func NewPacketFees(packetFees []PacketFee) PacketFees { return PacketFees{ diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 50e6584e26b..2c0d8a52e32 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -118,22 +118,21 @@ func (msg MsgPayPacketFee) GetSignBytes() []byte { } // NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee -func NewMsgPayPacketFeeAsync(identifiedPacketFee IdentifiedPacketFee) *MsgPayPacketFeeAsync { +func NewMsgPayPacketFeeAsync(packetID channeltypes.PacketId, packetFee PacketFee) *MsgPayPacketFeeAsync { return &MsgPayPacketFeeAsync{ - IdentifiedPacketFee: identifiedPacketFee, + PacketId: packetID, + PacketFee: packetFee, } } // ValidateBasic performs a basic check of the MsgPayPacketFeeAsync fields func (msg MsgPayPacketFeeAsync) ValidateBasic() error { - // signer check - _, err := sdk.AccAddressFromBech32(msg.IdentifiedPacketFee.RefundAddress) - if err != nil { - return sdkerrors.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") + if err := msg.PacketId.Validate(); err != nil { + return err } - if err = msg.IdentifiedPacketFee.Validate(); err != nil { - return sdkerrors.Wrap(err, "Invalid IdentifiedPacketFee") + if err := msg.PacketFee.Validate(); err != nil { + return err } return nil @@ -142,7 +141,7 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error { // GetSigners implements sdk.Msg // The signer of the fee message must be the refund address func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.IdentifiedPacketFee.RefundAddress) + signer, err := sdk.AccAddressFromBech32(msg.PacketFee.RefundAddress) 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 c4ee1a477f1..6ded61d407f 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -319,9 +319,10 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { tc.malleate() fee = Fee{receiveFee, ackFee, timeoutFee} - packetId := channeltypes.NewPacketId(channelID, portID, seq) - identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: signer, Relayers: relayers} - msg := NewMsgPayPacketFeeAsync(identifiedPacketFee) + packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetFee := NewPacketFee(fee, signer, relayers) + + msg := NewMsgPayPacketFeeAsync(packetID, packetFee) err := msg.ValidateBasic() @@ -335,20 +336,15 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { // TestRegisterCounterpartyAddressGetSigners tests GetSigners func TestPayPacketFeeAsyncGetSigners(t *testing.T) { - addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - // build message - channelID := validChannelID - portID := validPortID - fee := Fee{validCoins, validCoins, validCoins} - seq := uint64(1) - packetId := channeltypes.NewPacketId(channelID, portID, seq) - identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil} - msg := NewMsgPayPacketFeeAsync(identifiedPacketFee) + refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + fee := NewFee(validCoins, validCoins, validCoins) - // GetSigners - res := msg.GetSigners() + packetID := channeltypes.NewPacketId(validChannelID, validPortID, 1) + packetFee := NewPacketFee(fee, refundAddr.String(), nil) - require.Equal(t, []sdk.AccAddress{addr}, res) + msg := NewMsgPayPacketFeeAsync(packetID, packetFee) + + require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners()) } // TestMsgPayPacketFeeAsyncRoute tests Route for MsgPayPacketFeeAsync @@ -360,9 +356,10 @@ func TestMsgPayPacketFeeAsyncRoute(t *testing.T) { portID := validPortID fee := Fee{validCoins, validCoins, validCoins} seq := uint64(1) - packetId := channeltypes.NewPacketId(channelID, portID, seq) - identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil} - msg := NewMsgPayPacketFeeAsync(identifiedPacketFee) + packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetFee := NewPacketFee(fee, addr.String(), nil) + + msg := NewMsgPayPacketFeeAsync(packetID, packetFee) require.Equal(t, RouterKey, msg.Route()) } @@ -376,9 +373,10 @@ func TestMsgPayPacketFeeAsyncType(t *testing.T) { portID := validPortID fee := Fee{validCoins, validCoins, validCoins} seq := uint64(1) - packetId := channeltypes.NewPacketId(channelID, portID, seq) - identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil} - msg := NewMsgPayPacketFeeAsync(identifiedPacketFee) + packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetFee := NewPacketFee(fee, addr.String(), nil) + + msg := NewMsgPayPacketFeeAsync(packetID, packetFee) require.Equal(t, "payPacketFeeAsync", msg.Type()) } @@ -392,9 +390,10 @@ func TestMsgPayPacketFeeAsyncGetSignBytes(t *testing.T) { portID := validPortID fee := Fee{validCoins, validCoins, validCoins} seq := uint64(1) - packetId := channeltypes.NewPacketId(channelID, portID, seq) - identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil} - msg := NewMsgPayPacketFeeAsync(identifiedPacketFee) + packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetFee := NewPacketFee(fee, addr.String(), nil) + + msg := NewMsgPayPacketFeeAsync(packetID, packetFee) require.NotPanics(t, func() { _ = msg.GetSignBytes()