From 23940d4effd9d25101172de0b19517463d87ec28 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 21 Feb 2022 13:05:12 +0000 Subject: [PATCH 1/7] 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/7] 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/7] 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 b658b0f7916e8d2b2611508e4be77ba6e805639f Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 21 Feb 2022 16:18:58 +0000 Subject: [PATCH 4/7] updating protos and existing queries --- docs/ibc/proto-docs.md | 4 +- modules/apps/29-fee/keeper/grpc_query.go | 29 ++++-- modules/apps/29-fee/types/fee.go | 9 ++ modules/apps/29-fee/types/query.pb.go | 109 ++++++++++------------ proto/ibc/applications/fee/v1/query.proto | 4 +- 5 files changed, 85 insertions(+), 70 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 3da59f9038c..7e67458862e 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -944,7 +944,7 @@ QueryIncentivizedPacketsResponse is the response type for the incentivized packe | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `incentivized_packet` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | Incentivized_packet | +| `incentivized_packet` | [IdentifiedPacketFees](#ibc.applications.fee.v1.IdentifiedPacketFees) | | Incentivized_packet | @@ -975,7 +975,7 @@ QueryIncentivizedPacketsResponse is the response type for the incentivized packe | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `incentivized_packets` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | Map of all incentivized_packets | +| `incentivized_packets` | [IdentifiedPacketFees](#ibc.applications.fee.v1.IdentifiedPacketFees) | repeated | Map of all incentivized_packets | diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index 1dae09d9265..f5381474d2a 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -2,6 +2,8 @@ package keeper import ( "context" + "strconv" + "strings" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -12,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) var _ types.QueryServer = Keeper{} @@ -24,11 +27,21 @@ func (k Keeper) IncentivizedPackets(c context.Context, req *types.QueryIncentivi ctx := sdk.UnwrapSDKContext(c).WithBlockHeight(int64(req.QueryHeight)) - var packets []*types.IdentifiedPacketFee - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeeInEscrowPrefix)) - _, err := query.Paginate(store, req.Pagination, func(_, value []byte) error { - result := k.MustUnmarshalFee(value) - packets = append(packets, &result) + var identifiedPackets []types.IdentifiedPacketFees + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeesInEscrowPrefix)) + _, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { + keySplit := strings.Split(string(key), "/") + + channelID, portID := keySplit[2], keySplit[1] + seq, err := strconv.ParseUint(keySplit[3], 10, 64) + if err != nil { + panic(err) + } + + packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetFees := k.MustUnmarshalFees(value) + + identifiedPackets = append(identifiedPackets, types.NewIdentifiedPacketFees(packetID, packetFees.PacketFees)) return nil }) @@ -39,7 +52,7 @@ func (k Keeper) IncentivizedPackets(c context.Context, req *types.QueryIncentivi } return &types.QueryIncentivizedPacketsResponse{ - IncentivizedPackets: packets, + IncentivizedPackets: identifiedPackets, }, nil } @@ -51,7 +64,7 @@ func (k Keeper) IncentivizedPacket(c context.Context, req *types.QueryIncentiviz ctx := sdk.UnwrapSDKContext(c).WithBlockHeight(int64(req.QueryHeight)) - fee, exists := k.GetFeeInEscrow(ctx, req.PacketId) + feesInEscrow, exists := k.GetFeesInEscrow(ctx, req.PacketId) if !exists { return nil, status.Error( codes.NotFound, @@ -60,6 +73,6 @@ func (k Keeper) IncentivizedPacket(c context.Context, req *types.QueryIncentiviz } return &types.QueryIncentivizedPacketResponse{ - IncentivizedPacket: &fee, + IncentivizedPacket: types.NewIdentifiedPacketFees(req.PacketId, feesInEscrow.PacketFees), }, nil } diff --git a/modules/apps/29-fee/types/fee.go b/modules/apps/29-fee/types/fee.go index 54dd9ee1435..de4fd944511 100644 --- a/modules/apps/29-fee/types/fee.go +++ b/modules/apps/29-fee/types/fee.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) // NewPacketFee creates and returns a new PacketFee struct including the incentivization fees, refund addres and relayers @@ -23,6 +24,14 @@ func NewPacketFees(packetFees []PacketFee) PacketFees { } } +// NewIdentifiedPacketFees creates and returns a new IdentifiedPacketFees struct containing a packet ID and packet fees +func NewIdentifiedPacketFees(packetID channeltypes.PacketId, packetFees []PacketFee) IdentifiedPacketFees { + return IdentifiedPacketFees{ + PacketId: packetID, + 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{ diff --git a/modules/apps/29-fee/types/query.pb.go b/modules/apps/29-fee/types/query.pb.go index 3bbbbee7b17..ef1b0512d25 100644 --- a/modules/apps/29-fee/types/query.pb.go +++ b/modules/apps/29-fee/types/query.pb.go @@ -89,7 +89,7 @@ func (m *QueryIncentivizedPacketsRequest) GetQueryHeight() uint64 { // QueryIncentivizedPacketsResponse is the response type for the incentivized packets RPC type QueryIncentivizedPacketsResponse struct { // Map of all incentivized_packets - IncentivizedPackets []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=incentivized_packets,json=incentivizedPackets,proto3" json:"incentivized_packets,omitempty"` + IncentivizedPackets []IdentifiedPacketFees `protobuf:"bytes,1,rep,name=incentivized_packets,json=incentivizedPackets,proto3" json:"incentivized_packets"` } func (m *QueryIncentivizedPacketsResponse) Reset() { *m = QueryIncentivizedPacketsResponse{} } @@ -125,7 +125,7 @@ func (m *QueryIncentivizedPacketsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryIncentivizedPacketsResponse proto.InternalMessageInfo -func (m *QueryIncentivizedPacketsResponse) GetIncentivizedPackets() []*IdentifiedPacketFee { +func (m *QueryIncentivizedPacketsResponse) GetIncentivizedPackets() []IdentifiedPacketFees { if m != nil { return m.IncentivizedPackets } @@ -190,7 +190,7 @@ func (m *QueryIncentivizedPacketRequest) GetQueryHeight() uint64 { // QueryIncentivizedPacketsResponse is the response type for the incentivized packet RPC type QueryIncentivizedPacketResponse struct { // Incentivized_packet - IncentivizedPacket *IdentifiedPacketFee `protobuf:"bytes,1,opt,name=incentivized_packet,json=incentivizedPacket,proto3" json:"incentivized_packet,omitempty"` + IncentivizedPacket IdentifiedPacketFees `protobuf:"bytes,1,opt,name=incentivized_packet,json=incentivizedPacket,proto3" json:"incentivized_packet"` } func (m *QueryIncentivizedPacketResponse) Reset() { *m = QueryIncentivizedPacketResponse{} } @@ -226,11 +226,11 @@ func (m *QueryIncentivizedPacketResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryIncentivizedPacketResponse proto.InternalMessageInfo -func (m *QueryIncentivizedPacketResponse) GetIncentivizedPacket() *IdentifiedPacketFee { +func (m *QueryIncentivizedPacketResponse) GetIncentivizedPacket() IdentifiedPacketFees { if m != nil { return m.IncentivizedPacket } - return nil + return IdentifiedPacketFees{} } func init() { @@ -246,41 +246,41 @@ func init() { var fileDescriptor_0638a8a78ca2503c = []byte{ // 554 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xc1, 0x6b, 0x13, 0x4f, - 0x14, 0xce, 0xa4, 0xfd, 0xfd, 0xd0, 0x89, 0xa7, 0x49, 0xc1, 0x10, 0x74, 0x9b, 0x46, 0xd4, 0x20, - 0x66, 0x86, 0xa4, 0x88, 0xed, 0x4d, 0x7a, 0x28, 0xe6, 0x64, 0xcd, 0x51, 0x90, 0xb0, 0x3b, 0xfb, - 0xb2, 0x19, 0x4c, 0x76, 0xb6, 0x99, 0xc9, 0x42, 0xab, 0x05, 0xa9, 0x78, 0xeb, 0x41, 0xf0, 0xaf, - 0xf1, 0x3f, 0xe8, 0xb1, 0xe8, 0xc5, 0x93, 0x48, 0xe2, 0x1f, 0x22, 0xb3, 0x3b, 0x89, 0x0b, 0xc9, - 0x62, 0xe3, 0x6d, 0xf7, 0xbd, 0xef, 0x7b, 0xdf, 0xb7, 0xdf, 0x9b, 0x59, 0x7c, 0x4f, 0x78, 0x9c, - 0xb9, 0x51, 0x34, 0x14, 0xdc, 0xd5, 0x42, 0x86, 0x8a, 0xf5, 0x01, 0x58, 0xdc, 0x62, 0xc7, 0x13, - 0x18, 0x9f, 0xd0, 0x68, 0x2c, 0xb5, 0x24, 0xb7, 0x85, 0xc7, 0x69, 0x16, 0x44, 0xfb, 0x00, 0x34, - 0x6e, 0x55, 0xb7, 0x02, 0x19, 0xc8, 0x04, 0xc3, 0xcc, 0x53, 0x0a, 0xaf, 0xee, 0xe4, 0xcd, 0x34, - 0xac, 0x14, 0x72, 0x27, 0x90, 0x32, 0x18, 0x02, 0x73, 0x23, 0xc1, 0xdc, 0x30, 0x94, 0xda, 0xce, - 0xcd, 0x0c, 0xe0, 0x72, 0x0c, 0x8c, 0x0f, 0xdc, 0x30, 0x84, 0xa1, 0x21, 0xdb, 0x47, 0x0b, 0x79, - 0xc4, 0xa5, 0x1a, 0x49, 0xc5, 0x3c, 0x57, 0x41, 0xea, 0x95, 0xc5, 0x2d, 0x0f, 0xb4, 0xdb, 0x62, - 0x91, 0x1b, 0x88, 0x30, 0x99, 0x97, 0x62, 0xeb, 0x17, 0x08, 0x6f, 0xbf, 0x34, 0x90, 0x4e, 0xc8, - 0x21, 0xd4, 0x22, 0x16, 0xa7, 0xe0, 0x1f, 0xb9, 0xfc, 0x0d, 0x68, 0xd5, 0x85, 0xe3, 0x09, 0x28, - 0x4d, 0x0e, 0x31, 0xfe, 0xc3, 0xab, 0xa0, 0x1a, 0x6a, 0x94, 0xda, 0x0f, 0x68, 0x2a, 0x42, 0x8d, - 0x08, 0x4d, 0x03, 0xb1, 0x22, 0xf4, 0xc8, 0x0d, 0xc0, 0x72, 0xbb, 0x19, 0x26, 0xd9, 0xc1, 0xb7, - 0x12, 0x60, 0x6f, 0x00, 0x22, 0x18, 0xe8, 0x4a, 0xb1, 0x86, 0x1a, 0x9b, 0xdd, 0x52, 0x52, 0x7b, - 0x9e, 0x94, 0xea, 0x1f, 0x10, 0xae, 0xe5, 0xdb, 0x51, 0x91, 0x0c, 0x15, 0x90, 0x1e, 0xde, 0x12, - 0x99, 0x76, 0x2f, 0x4a, 0xfb, 0x15, 0x54, 0xdb, 0x68, 0x94, 0xda, 0x8f, 0x69, 0xce, 0x46, 0x68, - 0xc7, 0x37, 0x9c, 0xbe, 0x98, 0x4f, 0x3c, 0x04, 0xe8, 0x96, 0xc5, 0xb2, 0x50, 0xfd, 0x23, 0xc2, - 0x4e, 0x8e, 0x8b, 0x79, 0x26, 0xcf, 0xf0, 0xcd, 0x54, 0xb6, 0x27, 0x7c, 0x1b, 0xc9, 0xdd, 0x44, - 0xd8, 0xac, 0x86, 0xce, 0xf7, 0x11, 0x9b, 0x30, 0x0c, 0xaa, 0xe3, 0x1f, 0x6c, 0x5e, 0xfe, 0xd8, - 0x2e, 0x74, 0x6f, 0x44, 0xf6, 0xfd, 0x3a, 0x69, 0xbc, 0xcf, 0x5f, 0xce, 0x22, 0x8c, 0xd7, 0xb8, - 0xbc, 0x22, 0x0c, 0x6b, 0x69, 0xbd, 0x2c, 0xc8, 0x72, 0x16, 0xed, 0xaf, 0x1b, 0xf8, 0xbf, 0xc4, - 0x02, 0xf9, 0x82, 0x70, 0x79, 0xc5, 0x56, 0xc8, 0x5e, 0xae, 0xc6, 0x5f, 0xce, 0x55, 0x75, 0xff, - 0x1f, 0x98, 0xe9, 0x57, 0xd7, 0x9b, 0xe7, 0xdf, 0x7e, 0x7d, 0x2e, 0x3e, 0x24, 0xf7, 0x99, 0xbd, - 0x4f, 0x8b, 0x7b, 0xb4, 0xea, 0x64, 0x90, 0x8b, 0x22, 0x26, 0xcb, 0xe3, 0xc8, 0xd3, 0x75, 0x0d, - 0xcc, 0x9d, 0xef, 0xad, 0x4f, 0xb4, 0xc6, 0xcf, 0x51, 0xe2, 0xfc, 0x1d, 0x39, 0xbd, 0x8e, 0x73, - 0x16, 0xc9, 0xb1, 0x66, 0x6f, 0x17, 0x27, 0x8d, 0x9a, 0xf7, 0x9e, 0xf0, 0xcf, 0x16, 0x97, 0x3f, - 0xd3, 0xb3, 0xa5, 0xa4, 0xad, 0x8c, 0xd1, 0x90, 0x43, 0xb6, 0x3f, 0xaf, 0x9d, 0x1d, 0xbc, 0xb8, - 0x9c, 0x3a, 0xe8, 0x6a, 0xea, 0xa0, 0x9f, 0x53, 0x07, 0x7d, 0x9a, 0x39, 0x85, 0xab, 0x99, 0x53, - 0xf8, 0x3e, 0x73, 0x0a, 0xaf, 0x9e, 0x04, 0x42, 0x0f, 0x26, 0x1e, 0xe5, 0x72, 0xc4, 0xec, 0x5f, - 0x44, 0x78, 0xbc, 0x19, 0x48, 0x16, 0xef, 0xb2, 0x91, 0xf4, 0x27, 0x43, 0x50, 0xa9, 0xe9, 0xf6, - 0x7e, 0xd3, 0xf8, 0xd6, 0x27, 0x11, 0x28, 0xef, 0xff, 0xe4, 0x67, 0xb2, 0xfb, 0x3b, 0x00, 0x00, - 0xff, 0xff, 0xd3, 0xea, 0xdd, 0xe2, 0x32, 0x05, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xce, 0xb4, 0x55, 0x74, 0xe2, 0x69, 0x52, 0x30, 0x04, 0xdd, 0xa6, 0x11, 0x35, 0x08, 0x99, + 0x21, 0x29, 0x62, 0x7b, 0x93, 0x1e, 0x8a, 0x39, 0x59, 0x73, 0xf4, 0x12, 0x76, 0x67, 0x5f, 0x36, + 0x83, 0xc9, 0xce, 0x36, 0x33, 0x59, 0x68, 0xb5, 0x97, 0x82, 0x08, 0xd2, 0x83, 0xe0, 0xaf, 0xf1, + 0x1f, 0xf4, 0x58, 0xf4, 0xe2, 0x49, 0x24, 0xf1, 0x87, 0xc8, 0xec, 0xce, 0xc6, 0x85, 0x64, 0xb1, + 0xed, 0x6d, 0xf7, 0xbd, 0xef, 0x7b, 0xdf, 0xb7, 0xdf, 0x9b, 0x1d, 0xfc, 0x48, 0x78, 0x9c, 0xb9, + 0x51, 0x34, 0x12, 0xdc, 0xd5, 0x42, 0x86, 0x8a, 0x0d, 0x00, 0x58, 0xdc, 0x66, 0x47, 0x53, 0x98, + 0x1c, 0xd3, 0x68, 0x22, 0xb5, 0x24, 0xf7, 0x85, 0xc7, 0x69, 0x1e, 0x44, 0x07, 0x00, 0x34, 0x6e, + 0xd7, 0x36, 0x03, 0x19, 0xc8, 0x04, 0xc3, 0xcc, 0x53, 0x0a, 0xaf, 0x6d, 0x17, 0xcd, 0x34, 0xac, + 0x14, 0xf2, 0x20, 0x90, 0x32, 0x18, 0x01, 0x73, 0x23, 0xc1, 0xdc, 0x30, 0x94, 0xda, 0xce, 0xcd, + 0x0d, 0xe0, 0x72, 0x02, 0x8c, 0x0f, 0xdd, 0x30, 0x84, 0x91, 0x21, 0xdb, 0x47, 0x0b, 0x79, 0xc6, + 0xa5, 0x1a, 0x4b, 0xc5, 0x3c, 0x57, 0x41, 0xea, 0x95, 0xc5, 0x6d, 0x0f, 0xb4, 0xdb, 0x66, 0x91, + 0x1b, 0x88, 0x30, 0x99, 0x97, 0x62, 0x1b, 0xe7, 0x08, 0x6f, 0xbd, 0x31, 0x90, 0x6e, 0xc8, 0x21, + 0xd4, 0x22, 0x16, 0x27, 0xe0, 0x1f, 0xba, 0xfc, 0x1d, 0x68, 0xd5, 0x83, 0xa3, 0x29, 0x28, 0x4d, + 0x0e, 0x30, 0xfe, 0xc7, 0xab, 0xa2, 0x3a, 0x6a, 0x96, 0x3b, 0x4f, 0x68, 0x2a, 0x42, 0x8d, 0x08, + 0x4d, 0x03, 0xb1, 0x22, 0xf4, 0xd0, 0x0d, 0xc0, 0x72, 0x7b, 0x39, 0x26, 0xd9, 0xc6, 0xf7, 0x12, + 0x60, 0x7f, 0x08, 0x22, 0x18, 0xea, 0xea, 0x5a, 0x1d, 0x35, 0x37, 0x7a, 0xe5, 0xa4, 0xf6, 0x2a, + 0x29, 0x35, 0x3e, 0x23, 0x5c, 0x2f, 0xb6, 0xa3, 0x22, 0x19, 0x2a, 0x20, 0x03, 0xbc, 0x29, 0x72, + 0xed, 0x7e, 0x94, 0xf6, 0xab, 0xa8, 0xbe, 0xde, 0x2c, 0x77, 0x5a, 0xb4, 0x60, 0x23, 0xb4, 0xeb, + 0x1b, 0xce, 0x40, 0x64, 0x13, 0x0f, 0x00, 0xd4, 0xfe, 0xc6, 0xc5, 0xaf, 0xad, 0x52, 0xaf, 0x22, + 0x96, 0xf5, 0x1a, 0x1f, 0x11, 0x76, 0x0a, 0xcc, 0x64, 0xd1, 0xbc, 0xc4, 0x77, 0x53, 0xf5, 0xbe, + 0xf0, 0x6d, 0x32, 0x0f, 0x13, 0x7d, 0xb3, 0x21, 0x9a, 0xad, 0x25, 0x36, 0x99, 0x18, 0x54, 0xd7, + 0xb7, 0x7a, 0x77, 0x22, 0xfb, 0x7e, 0x95, 0x50, 0x3e, 0x15, 0xef, 0x68, 0x91, 0x89, 0x8f, 0x2b, + 0x2b, 0x32, 0xb1, 0x96, 0x6e, 0x14, 0x09, 0x59, 0x8e, 0xa4, 0xf3, 0x7d, 0x1d, 0xdf, 0x4a, 0x9c, + 0x90, 0x6f, 0x08, 0x57, 0x56, 0xec, 0x88, 0xec, 0x16, 0x4a, 0xfd, 0xe7, 0x94, 0xd5, 0xf6, 0x6e, + 0xc0, 0x4c, 0x3f, 0xbe, 0xd1, 0x3a, 0xfb, 0xf1, 0xe7, 0xeb, 0xda, 0x53, 0xf2, 0x98, 0xd9, 0xbf, + 0x6b, 0xf1, 0x57, 0xad, 0x3a, 0x27, 0xe4, 0x7c, 0x0d, 0x93, 0xe5, 0x71, 0xe4, 0xc5, 0x75, 0x0d, + 0x64, 0xce, 0x77, 0xaf, 0x4f, 0xb4, 0xc6, 0xcf, 0x50, 0xe2, 0xfc, 0x03, 0x39, 0xb9, 0x8a, 0x73, + 0x16, 0xc9, 0x89, 0x66, 0xef, 0x17, 0x07, 0x8e, 0x9a, 0xf7, 0xbe, 0xf0, 0x4f, 0x17, 0x57, 0x41, + 0xae, 0x67, 0x4b, 0x49, 0x5b, 0x19, 0xa3, 0x21, 0x87, 0x7c, 0x3f, 0xab, 0x9d, 0xee, 0xbf, 0xbe, + 0x98, 0x39, 0xe8, 0x72, 0xe6, 0xa0, 0xdf, 0x33, 0x07, 0x7d, 0x99, 0x3b, 0xa5, 0xcb, 0xb9, 0x53, + 0xfa, 0x39, 0x77, 0x4a, 0x6f, 0x9f, 0x07, 0x42, 0x0f, 0xa7, 0x1e, 0xe5, 0x72, 0xcc, 0xec, 0x9d, + 0x22, 0x3c, 0xde, 0x0a, 0x24, 0x8b, 0x77, 0xd8, 0x58, 0xfa, 0xd3, 0x11, 0xa8, 0xd4, 0x74, 0x67, + 0xaf, 0x65, 0x7c, 0xeb, 0xe3, 0x08, 0x94, 0x77, 0x3b, 0xb9, 0x5a, 0x76, 0xfe, 0x06, 0x00, 0x00, + 0xff, 0xff, 0xcd, 0x07, 0x8a, 0x55, 0x40, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -540,18 +540,16 @@ func (m *QueryIncentivizedPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int _ = i var l int _ = l - if m.IncentivizedPacket != nil { - { - size, err := m.IncentivizedPacket.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + { + size, err := m.IncentivizedPacket.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -617,10 +615,8 @@ func (m *QueryIncentivizedPacketResponse) Size() (n int) { } var l int _ = l - if m.IncentivizedPacket != nil { - l = m.IncentivizedPacket.Size() - n += 1 + l + sovQuery(uint64(l)) - } + l = m.IncentivizedPacket.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -793,7 +789,7 @@ func (m *QueryIncentivizedPacketsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.IncentivizedPackets = append(m.IncentivizedPackets, &IdentifiedPacketFee{}) + m.IncentivizedPackets = append(m.IncentivizedPackets, IdentifiedPacketFees{}) if err := m.IncentivizedPackets[len(m.IncentivizedPackets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -979,9 +975,6 @@ func (m *QueryIncentivizedPacketResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.IncentivizedPacket == nil { - m.IncentivizedPacket = &IdentifiedPacketFee{} - } if err := m.IncentivizedPacket.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/proto/ibc/applications/fee/v1/query.proto b/proto/ibc/applications/fee/v1/query.proto index 47db939a512..a588240a285 100644 --- a/proto/ibc/applications/fee/v1/query.proto +++ b/proto/ibc/applications/fee/v1/query.proto @@ -37,7 +37,7 @@ message QueryIncentivizedPacketsRequest { // QueryIncentivizedPacketsResponse is the response type for the incentivized packets RPC message QueryIncentivizedPacketsResponse { // Map of all incentivized_packets - repeated ibc.applications.fee.v1.IdentifiedPacketFee incentivized_packets = 1; + repeated ibc.applications.fee.v1.IdentifiedPacketFees incentivized_packets = 1 [(gogoproto.nullable) = false]; } // QueryIncentivizedPacketRequest is the request type for querying for all incentivized packets @@ -51,5 +51,5 @@ message QueryIncentivizedPacketRequest { // QueryIncentivizedPacketsResponse is the response type for the incentivized packet RPC message QueryIncentivizedPacketResponse { // Incentivized_packet - ibc.applications.fee.v1.IdentifiedPacketFee incentivized_packet = 1; + ibc.applications.fee.v1.IdentifiedPacketFees incentivized_packet = 1 [(gogoproto.nullable) = false]; } From d853b94165e3411a91fd38709c3990fc6b61d93d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 22 Feb 2022 10:47:02 +0000 Subject: [PATCH 5/7] updating grpc queries and refactoring tests --- modules/apps/29-fee/keeper/grpc_query.go | 9 +- modules/apps/29-fee/keeper/grpc_query_test.go | 138 ++++++++---------- 2 files changed, 62 insertions(+), 85 deletions(-) diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index f5381474d2a..1f976159585 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -46,9 +46,7 @@ func (k Keeper) IncentivizedPackets(c context.Context, req *types.QueryIncentivi }) if err != nil { - return nil, status.Error( - codes.NotFound, err.Error(), - ) + return nil, status.Error(codes.NotFound, err.Error()) } return &types.QueryIncentivizedPacketsResponse{ @@ -66,10 +64,7 @@ func (k Keeper) IncentivizedPacket(c context.Context, req *types.QueryIncentiviz feesInEscrow, exists := k.GetFeesInEscrow(ctx, req.PacketId) if !exists { - return nil, status.Error( - codes.NotFound, - sdkerrors.Wrap(types.ErrFeeNotFound, req.PacketId.String()).Error(), - ) + return nil, status.Error(codes.NotFound, sdkerrors.Wrap(types.ErrFeeNotFound, req.PacketId.String()).Error()) } return &types.QueryIncentivizedPacketResponse{ diff --git a/modules/apps/29-fee/keeper/grpc_query_test.go b/modules/apps/29-fee/keeper/grpc_query_test.go index 649ff89e6b9..37626b40bac 100644 --- a/modules/apps/29-fee/keeper/grpc_query_test.go +++ b/modules/apps/29-fee/keeper/grpc_query_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" @@ -11,25 +9,10 @@ import ( ibctesting "github.com/cosmos/ibc-go/v3/testing" ) -func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() { - +func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { var ( - req *types.QueryIncentivizedPacketRequest - ) - - // setup - suite.coordinator.Setup(suite.path) // setup channel - validPacketId := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1) - invalidPacketId := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 2) - identifiedPacketFee := types.NewIdentifiedPacketFee( - validPacketId, - types.Fee{ - AckFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), - RecvFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), - TimeoutFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), - }, - "", // leave empty here and then populate on each testcase since suite resets - []string(nil), + req *types.QueryIncentivizedPacketsRequest + expectedPackets []types.IdentifiedPacketFees ) testCases := []struct { @@ -40,22 +23,36 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() { { "success", func() { - req = &types.QueryIncentivizedPacketRequest{ - PacketId: validPacketId, + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) + + fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) + packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) + + for i := 0; i < 3; i++ { + // escrow packet fees for three different packets + packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, uint64(i+1)) + suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) + + expectedPackets = append(expectedPackets, types.NewIdentifiedPacketFees(packetID, []types.PacketFee{packetFee})) + } + + req = &types.QueryIncentivizedPacketsRequest{ + Pagination: &query.PageRequest{ + Limit: 5, + CountTotal: false, + }, QueryHeight: 0, } }, true, }, { - "packetId not found", + "empty pagination", func() { - req = &types.QueryIncentivizedPacketRequest{ - PacketId: invalidPacketId, - QueryHeight: 0, - } + expectedPackets = nil + req = &types.QueryIncentivizedPacketsRequest{} }, - false, + true, }, } @@ -63,22 +60,15 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() { suite.Run(tc.name, func() { suite.SetupTest() // reset - refundAcc := suite.chainA.SenderAccount.GetAddress() - // populate RefundAddress field - identifiedPacketFee.RefundAddress = refundAcc.String() - - tc.malleate() - - suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), validPacketId.PortId, validPacketId.ChannelId) - suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeInEscrow(suite.chainA.GetContext(), identifiedPacketFee) + tc.malleate() // malleate mutates test data ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) - res, err := suite.queryClient.IncentivizedPacket(ctx, req) + res, err := suite.queryClient.IncentivizedPackets(ctx, req) if tc.expPass { suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().Equal(&identifiedPacketFee, res.IncentivizedPacket) + suite.Require().Equal(expectedPackets, res.IncentivizedPackets) } else { suite.Require().Error(err) } @@ -86,71 +76,63 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() { } } -func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { +func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { var ( - req *types.QueryIncentivizedPacketsRequest - expPackets []*types.IdentifiedPacketFee + req *types.QueryIncentivizedPacketRequest ) - fee := types.Fee{ - AckFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}}, - RecvFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}}, - TimeoutFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}}, - } - testCases := []struct { - msg string + name string malleate func() expPass bool }{ { - "empty pagination", - func() { - req = &types.QueryIncentivizedPacketsRequest{} - }, + "success", + func() {}, true, }, { - "success", + "fees not found for packet id", func() { - refundAcc := suite.chainA.SenderAccount.GetAddress() - - fee1 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1), fee, refundAcc.String(), []string(nil)) - fee2 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 2), fee, refundAcc.String(), []string(nil)) - fee3 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 3), fee, refundAcc.String(), []string(nil)) - - expPackets = []*types.IdentifiedPacketFee{} - expPackets = append(expPackets, &fee1, &fee2, &fee3) - - suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) - for _, packetFee := range expPackets { - suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeInEscrow(suite.chainA.GetContext(), *packetFee) - } - - req = &types.QueryIncentivizedPacketsRequest{ - Pagination: &query.PageRequest{ - Limit: 5, - CountTotal: false, - }, + req = &types.QueryIncentivizedPacketRequest{ + PacketId: channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100), QueryHeight: 0, } }, - true, + false, }, } for _, tc := range testCases { - suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.Run(tc.name, func() { suite.SetupTest() // reset - tc.malleate() - ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) - res, err := suite.queryClient.IncentivizedPackets(ctx, req) + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) + + packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) + packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) + + for i := 0; i < 3; i++ { + // escrow three packet fees for the same packet + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) + suite.Require().NoError(err) + } + + req = &types.QueryIncentivizedPacketRequest{ + PacketId: packetID, + QueryHeight: 0, + } + + tc.malleate() // malleate mutates test data + + ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) + res, err := suite.queryClient.IncentivizedPacket(ctx, req) if tc.expPass { suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().Equal(expPackets, res.IncentivizedPackets) + suite.Require().Equal(types.NewIdentifiedPacketFees(packetID, []types.PacketFee{packetFee, packetFee, packetFee}), res.IncentivizedPacket) } else { suite.Require().Error(err) } From dda4039ce088f86e3cf5c93e6bedafee2506984d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 22 Feb 2022 10:53:55 +0000 Subject: [PATCH 6/7] format error correct in favour of proto string() method --- modules/apps/29-fee/keeper/grpc_query.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index 1f976159585..1d0d2a7d6c3 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -64,7 +64,9 @@ func (k Keeper) IncentivizedPacket(c context.Context, req *types.QueryIncentiviz feesInEscrow, exists := k.GetFeesInEscrow(ctx, req.PacketId) if !exists { - return nil, status.Error(codes.NotFound, sdkerrors.Wrap(types.ErrFeeNotFound, req.PacketId.String()).Error()) + return nil, status.Error( + codes.NotFound, + sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error()) } return &types.QueryIncentivizedPacketResponse{ From 24185461449fce9d6fde31cebbd7b8dde76db8c1 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 24 Feb 2022 13:16:19 +0000 Subject: [PATCH 7/7] leveraging ParseKeyFeesInEscrow to obtain packet id in query --- modules/apps/29-fee/keeper/grpc_query.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index 1d0d2a7d6c3..3d4852831ad 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -2,8 +2,6 @@ package keeper import ( "context" - "strconv" - "strings" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -14,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) var _ types.QueryServer = Keeper{} @@ -30,17 +27,12 @@ func (k Keeper) IncentivizedPackets(c context.Context, req *types.QueryIncentivi var identifiedPackets []types.IdentifiedPacketFees store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeesInEscrowPrefix)) _, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { - keySplit := strings.Split(string(key), "/") - - channelID, portID := keySplit[2], keySplit[1] - seq, err := strconv.ParseUint(keySplit[3], 10, 64) + packetID, err := types.ParseKeyFeesInEscrow(types.FeesInEscrowPrefix + string(key)) if err != nil { - panic(err) + return err } - packetID := channeltypes.NewPacketId(channelID, portID, seq) packetFees := k.MustUnmarshalFees(value) - identifiedPackets = append(identifiedPackets, types.NewIdentifiedPacketFees(packetID, packetFees.PacketFees)) return nil })