From fb84a6c7153e771a02f1d61b85d24607c6926c98 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 22 Nov 2021 15:52:11 +0100 Subject: [PATCH 01/10] proto: adding genesis state --- docs/ibc/proto-docs.md | 5 ++ modules/apps/29-fee/keeper/escrow.go | 1 - modules/apps/29-fee/types/genesis.pb.go | 83 +++++++++++++++++++-- proto/ibc/applications/fee/v1/genesis.proto | 2 +- 4 files changed, 81 insertions(+), 10 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 11f3ab0479b..c906989b4f8 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -676,6 +676,11 @@ and an optional list of relayers that are permitted to receive the fee. GenesisState defines the fee middleware genesis state +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `identified_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | | + + diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 1f46d16bbf9..ce7c73db8ce 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -4,7 +4,6 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index b07a497011f..406c5f824f0 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -25,6 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fee middleware genesis state type GenesisState struct { + IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -60,6 +61,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetIdentifiedFees() []*IdentifiedPacketFee { + if m != nil { + return m.IdentifiedFees + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.fee.v1.GenesisState") } @@ -69,19 +77,24 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 192 bytes of a gzipped FileDescriptorProto + // 260 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x4f, 0x4b, 0x4d, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xa6, 0x97, 0x96, 0x9a, 0xaa, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0x29, 0xe2, - 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0x89, 0x8f, 0x8b, 0xc7, 0x1d, 0x62, 0x45, 0x70, 0x49, 0x62, - 0x49, 0xaa, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, - 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, - 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, - 0xeb, 0x67, 0x26, 0x25, 0xeb, 0xa6, 0xe7, 0xeb, 0xe7, 0xe6, 0xa7, 0x94, 0xe6, 0xa4, 0x16, 0x83, - 0x6c, 0x2a, 0xd6, 0x37, 0xb2, 0xd4, 0x05, 0x59, 0x52, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, - 0xb6, 0xc4, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x90, 0xf8, 0xaf, 0x33, 0xdf, 0x00, 0x00, 0x00, + 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0xa9, 0x91, 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x47, 0x70, 0x49, + 0x62, 0x49, 0xaa, 0x50, 0x21, 0x17, 0x7f, 0x66, 0x4a, 0x6a, 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, + 0x4a, 0x7c, 0x5a, 0x6a, 0x6a, 0xb1, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x8e, 0x1e, 0x0e, + 0xcb, 0xf5, 0x3c, 0xe1, 0xea, 0x03, 0x12, 0x93, 0xb3, 0x53, 0x4b, 0xdc, 0x52, 0x53, 0x9d, 0xa4, + 0x3e, 0xdd, 0x93, 0x17, 0xab, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, 0x33, 0x4e, 0x29, 0x88, 0x0f, + 0x21, 0xe2, 0x96, 0x9a, 0x5a, 0xec, 0xe4, 0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, + 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, + 0x0c, 0x51, 0x46, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0xf9, + 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x99, 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, + 0x39, 0xa9, 0xc5, 0x20, 0xdf, 0x15, 0xeb, 0x1b, 0x59, 0xea, 0x82, 0x3c, 0x56, 0x52, 0x59, 0x90, + 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x10, 0xa7, 0xc1, 0xb3, + 0x53, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -104,6 +117,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.IdentifiedFees) > 0 { + for iNdEx := len(m.IdentifiedFees) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IdentifiedFees[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } return len(dAtA) - i, nil } @@ -124,6 +151,12 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + if len(m.IdentifiedFees) > 0 { + for _, e := range m.IdentifiedFees { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -162,6 +195,40 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IdentifiedFees", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IdentifiedFees = append(m.IdentifiedFees, &IdentifiedPacketFee{}) + if err := m.IdentifiedFees[len(m.IdentifiedFees)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index 4006b5fdc9d..a4be8bea993 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -7,5 +7,5 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // GenesisState defines the fee middleware genesis state message GenesisState { - // TODO + repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; } From e82b3abc1c3bb652c864439dc752b459d8237109 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 22 Nov 2021 16:17:31 +0100 Subject: [PATCH 02/10] feat: add GetAllIdentifiedPacketFees --- modules/apps/29-fee/keeper/keeper.go | 15 ++++++++++++ modules/apps/29-fee/keeper/keeper_test.go | 28 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 3691204d2a6..dafcbc0529f 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -159,6 +159,21 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId *channeltypes.PacketId) return store.Has(key) } +// GetAllIdentifiedPacketFees returns a list of all IdentifiedPacketFees that are stored in state +func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []*types.IdentifiedPacketFee { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeeInEscrowPrefix)) + defer iterator.Close() + + var identifiedFees []*types.IdentifiedPacketFee + for ; iterator.Valid(); iterator.Next() { + fee := k.MustUnmarshalFee(iterator.Value()) + identifiedFees = append(identifiedFees, &fee) + } + + return identifiedFees +} + // MustMarshalFee attempts to encode a Fee object and returns the // raw encoded bytes. It panics on error. func (k Keeper) MustMarshalFee(fee *types.IdentifiedPacketFee) []byte { diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 476a14698b0..5d643b767b3 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -66,3 +66,31 @@ func SetupFeePath(path *ibctesting.Path) error { func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } + +func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() { + // escrow a fee + refundAcc := suite.chainA.SenderAccount.GetAddress() + ackFee := validCoins + receiveFee := validCoins2 + timeoutFee := validCoins3 + packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortKey, Sequence: uint64(1)} + fee := types.Fee{ackFee, receiveFee, timeoutFee} + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} + + // escrow the packet fee + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee) + suite.Require().NoError(err) + + expectedFees := []*types.IdentifiedPacketFee{ + { + PacketId: packetId, + Fee: fee, + RefundAddress: refundAcc.String(), + Relayers: nil, + }, + } + + fees := suite.chainA.GetSimApp().IBCFeeKeeper.GetAllIdentifiedPacketFees(suite.chainA.GetContext()) + suite.Require().Len(fees, len(expectedFees)) + suite.Require().Equal(fees, expectedFees) +} From 45bfeae09927fb380819b777ca277e290f4dffc5 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 22 Nov 2021 17:13:48 +0100 Subject: [PATCH 03/10] feat: adding genesis.go & updating proto + app.go --- docs/ibc/proto-docs.md | 1 + modules/apps/29-fee/keeper/escrow_test.go | 14 ++-- modules/apps/29-fee/keeper/genesis.go | 26 ++++++- modules/apps/29-fee/keeper/keeper.go | 23 +++++- modules/apps/29-fee/keeper/keeper_test.go | 2 +- modules/apps/29-fee/types/genesis.go | 9 ++- modules/apps/29-fee/types/genesis.pb.go | 83 +++++++++++++++++---- modules/apps/29-fee/types/keys.go | 7 +- modules/apps/29-fee/types/msgs.go | 2 +- proto/ibc/applications/fee/v1/genesis.proto | 3 +- testing/simapp/app.go | 5 +- 11 files changed, 140 insertions(+), 35 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index c906989b4f8..c6df5f226bf 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -678,6 +678,7 @@ GenesisState defines the fee middleware genesis state | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | +| `port_id` | [string](#string) | | | | `identified_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | | diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 91cd66a2a14..f9622bc3259 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -70,7 +70,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { ackFee = validCoins receiveFee = validCoins2 timeoutFee = validCoins3 - packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(1)} + packetId := &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: uint64(1)} tc.malleate() fee := types.Fee{ackFee, receiveFee, timeoutFee} @@ -130,7 +130,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { { "fee not found for packet", func() { // setting packetId with an invalid sequence of 2 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: uint64(2)} }, false, }, } @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { ackFee = validCoins receiveFee = validCoins2 timeoutFee = validCoins3 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: validSeq} fee := types.Fee{receiveFee, ackFee, timeoutFee} // escrow the packet fee & store the fee in state @@ -188,7 +188,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { } else { suite.Require().Error(err) - invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} + invalidPacketID := &channeltypes.PacketId{PortId: types.PortID, ChannelId: validChannelId, Sequence: 1} hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), invalidPacketID) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) @@ -222,7 +222,7 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { { "fee not found for packet", func() { // setting packetId with an invalid sequence of 2 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: uint64(2)} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: uint64(2)} }, false, }, } @@ -240,7 +240,7 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { ackFee = validCoins receiveFee = validCoins2 timeoutFee = validCoins3 - packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortKey, Sequence: validSeq} + packetId = &channeltypes.PacketId{ChannelId: validChannelId, PortId: types.PortID, Sequence: validSeq} fee := types.Fee{receiveFee, ackFee, timeoutFee} // escrow the packet fee & store the fee in state @@ -274,7 +274,7 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { } else { suite.Require().Error(err) - invalidPacketID := &channeltypes.PacketId{PortId: types.PortKey, ChannelId: validChannelId, Sequence: 1} + invalidPacketID := &channeltypes.PacketId{PortId: types.PortID, ChannelId: validChannelId, Sequence: 1} hasFeeInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), invalidPacketID) // there should still be a fee in escrow for this packet suite.Require().True(hasFeeInEscrow) diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index cb500443231..f8214759f9d 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -1,16 +1,36 @@ package keeper -/* import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" ) // InitGenesis func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { + k.SetPort(ctx, state.PortId) + + // Only try to bind to port if it is not already bound, since we may already own + // port capability from capability InitGenesis + if !k.IsBound(ctx, state.PortId) { + // fee29 module binds to the feetransfer port on InitChain + // and claims the returned capability + err := k.BindPort(ctx, state.PortId) + if err != nil { + panic(fmt.Sprintf("could not claim port capability: %v", err)) + } + } + + for _, fee := range state.IdentifiedFees { + k.SetFeeInEscrow(ctx, fee) + } } // ExportGenesis func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - return &types.GenesisState{} + return &types.GenesisState{ + PortId: k.GetPort(ctx), + IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), + } } -*/ diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index dafcbc0529f..735935439b2 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -30,12 +31,13 @@ type Keeper struct { channelKeeper types.ChannelKeeper portKeeper types.PortKeeper bankKeeper types.BankKeeper + scopedKeeper capabilitykeeper.ScopedKeeper } // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, + channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { return Keeper{ @@ -45,6 +47,7 @@ func NewKeeper( portKeeper: portKeeper, authKeeper: authKeeper, bankKeeper: bankKeeper, + scopedKeeper: scopedKeeper, } } @@ -59,6 +62,24 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } +// IsBound checks if the fee29 module is already bound to the desired port +func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) + return ok +} + +// GetPort returns the portID for the fee29 module. Used in ExportGenesis +func (k Keeper) GetPort(ctx sdk.Context) string { + store := ctx.KVStore(k.storeKey) + return string(store.Get(types.PortKey)) +} + +// SetPort sets the portID for the fee29 module. Used in InitGenesis +func (k Keeper) SetPort(ctx sdk.Context, portID string) { + store := ctx.KVStore(k.storeKey) + store.Set(types.PortKey, []byte(portID)) +} + // ChanCloseInit wraps the channel keeper's function in order to expose it to underlying app. func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 5d643b767b3..53b98a52e0c 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() { ackFee := validCoins receiveFee := validCoins2 timeoutFee := validCoins3 - packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortKey, Sequence: uint64(1)} + packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} fee := types.Fee{ackFee, receiveFee, timeoutFee} identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index 4086325bebb..1ba5b47d1e6 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -1,20 +1,22 @@ package types -/* import ( host "github.com/cosmos/ibc-go/modules/core/24-host" ) // NewGenesisState creates a 29-fee GenesisState instance. -func NewGenesisState(portID string, denomTraces Traces, params Params) *GenesisState { +func NewGenesisState(identifiedFees []*IdentifiedPacketFee) *GenesisState { return &GenesisState{ - Params: params, + PortId: PortID, + IdentifiedFees: identifiedFees, } } // DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. func DefaultGenesisState() *GenesisState { return &GenesisState{ + PortId: PortID, + IdentifiedFees: []*IdentifiedPacketFee{}, } } @@ -26,4 +28,3 @@ func (gs GenesisState) Validate() error { } return nil } -*/ diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index 406c5f824f0..d2287f27827 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -25,7 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fee middleware genesis state type GenesisState struct { - IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,2,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -61,6 +62,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + func (m *GenesisState) GetIdentifiedFees() []*IdentifiedPacketFee { if m != nil { return m.IdentifiedFees @@ -77,24 +85,26 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 260 bytes of a gzipped FileDescriptorProto + // 295 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x4f, 0x4b, 0x4d, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xa6, 0x97, 0x96, 0x9a, 0xaa, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0x29, 0xe2, - 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0xa9, 0x91, 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x47, 0x70, 0x49, - 0x62, 0x49, 0xaa, 0x50, 0x21, 0x17, 0x7f, 0x66, 0x4a, 0x6a, 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, - 0x4a, 0x7c, 0x5a, 0x6a, 0x6a, 0xb1, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x8e, 0x1e, 0x0e, - 0xcb, 0xf5, 0x3c, 0xe1, 0xea, 0x03, 0x12, 0x93, 0xb3, 0x53, 0x4b, 0xdc, 0x52, 0x53, 0x9d, 0xa4, - 0x3e, 0xdd, 0x93, 0x17, 0xab, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, 0x33, 0x4e, 0x29, 0x88, 0x0f, - 0x21, 0xe2, 0x96, 0x9a, 0x5a, 0xec, 0xe4, 0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, - 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, - 0x0c, 0x51, 0x46, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0xf9, - 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x99, 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, - 0x39, 0xa9, 0xc5, 0x20, 0xdf, 0x15, 0xeb, 0x1b, 0x59, 0xea, 0x82, 0x3c, 0x56, 0x52, 0x59, 0x90, - 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x10, 0xa7, 0xc1, 0xb3, - 0x53, 0x01, 0x00, 0x00, + 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0x69, 0x1d, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0x8e, 0xe0, 0x92, + 0xc4, 0x92, 0x54, 0x21, 0x6d, 0x2e, 0xf6, 0x82, 0xfc, 0xa2, 0x92, 0xf8, 0xcc, 0x14, 0x09, 0x46, + 0x05, 0x46, 0x0d, 0x4e, 0x27, 0xa1, 0x4f, 0xf7, 0xe4, 0xf9, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, + 0xa0, 0x12, 0x4a, 0x41, 0x6c, 0x20, 0x96, 0x67, 0x8a, 0x50, 0x21, 0x17, 0x7f, 0x66, 0x4a, 0x6a, + 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, 0x4a, 0x7c, 0x5a, 0x6a, 0x6a, 0xb1, 0x04, 0x93, 0x02, 0xb3, + 0x06, 0xb7, 0x91, 0x8e, 0x1e, 0x0e, 0x97, 0xea, 0x79, 0xc2, 0xd5, 0x07, 0x24, 0x26, 0x67, 0xa7, + 0x96, 0xb8, 0xa5, 0xa6, 0x3a, 0x49, 0x7d, 0xba, 0x27, 0x2f, 0x06, 0xb1, 0x02, 0xcd, 0x38, 0xa5, + 0x20, 0x3e, 0x84, 0x88, 0x5b, 0x6a, 0x6a, 0xb1, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, + 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, + 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, + 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, 0xeb, 0x67, 0x26, 0x25, 0xeb, 0xa6, 0xe7, 0xeb, 0xe7, 0xe6, + 0xa7, 0x94, 0xe6, 0xa4, 0x16, 0x83, 0x82, 0xa2, 0x58, 0xdf, 0xc8, 0x52, 0x17, 0x14, 0x0a, 0x25, + 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x50, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x0a, + 0x35, 0x98, 0xd6, 0x80, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -128,9 +138,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0xa + dAtA[i] = 0x12 } } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -151,6 +168,10 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } if len(m.IdentifiedFees) > 0 { for _, e := range m.IdentifiedFees { l = e.Size() @@ -196,6 +217,38 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field IdentifiedFees", wireType) } diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 3df1f637a6c..028ca9130dc 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -14,7 +14,7 @@ const ( StoreKey = ModuleName // PortKey is the port id that is wrapped by fee middleware - PortKey = "feetransfer" + PortID = "feetransfer" // RouterKey is the message route for IBC fee module RouterKey = ModuleName @@ -34,6 +34,11 @@ const ( FeeInEscrowPrefix = "feeInEscrow" ) +var ( + // PortKey defines the key to store the port ID in store + PortKey = []byte{0x01} +) + // FeeEnabledKey returns the key that stores a flag to determine if fee logic should // be enabled for the given port and channel identifiers. func FeeEnabledKey(portID, channelID string) []byte { diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 53bcc0b5b74..8dc7f2371eb 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -172,5 +172,5 @@ func NewIdentifiedPacketFee(packetId *channeltypes.PacketId, fee Fee, refundAddr } func NewPacketId(channelId string, id uint64) *channeltypes.PacketId { - return &channeltypes.PacketId{ChannelId: channelId, PortId: PortKey, Sequence: id} + return &channeltypes.PacketId{ChannelId: channelId, PortId: PortID, Sequence: id} } diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index a4be8bea993..760a31803a9 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -7,5 +7,6 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // GenesisState defines the fee middleware genesis state message GenesisState { - repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; + string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; + repeated IdentifiedPacketFee identified_fees = 2 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; } diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 58b2a79006d..066eb3f84cd 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -262,6 +262,8 @@ func NewSimApp( app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedIBCFeeKeeper := app.CapabilityKeeper.ScopeToModule(ibcfeetypes.ModuleName) + // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do // note replicate if you do not need to test core IBC or light clients. scopedIBCMockKeeper := app.CapabilityKeeper.ScopeToModule(ibcmock.ModuleName) @@ -323,7 +325,7 @@ func NewSimApp( ) app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(appCodec, keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedIBCFeeKeeper, ) // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper @@ -481,6 +483,7 @@ func NewSimApp( app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper + app.ScopedIBCFeeKeeper = scopedIBCFeeKeeper // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do // note replicate if you do not need to test core IBC or light clients. From e89d2e9c06b906a3769131a7bfae1eab934922be Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 23 Nov 2021 12:48:11 +0100 Subject: [PATCH 04/10] fix: removing PortId from genesis --- docs/ibc/proto-docs.md | 1 - modules/apps/29-fee/keeper/genesis.go | 16 ---- modules/apps/29-fee/keeper/genesis_test.go | 56 ++++++++++++++ modules/apps/29-fee/keeper/keeper.go | 28 ++----- modules/apps/29-fee/types/genesis.go | 9 --- modules/apps/29-fee/types/genesis.pb.go | 83 ++++----------------- proto/ibc/applications/fee/v1/genesis.proto | 3 +- 7 files changed, 77 insertions(+), 119 deletions(-) create mode 100644 modules/apps/29-fee/keeper/genesis_test.go diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index c6df5f226bf..c906989b4f8 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -678,7 +678,6 @@ GenesisState defines the fee middleware genesis state | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `port_id` | [string](#string) | | | | `identified_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | | diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index f8214759f9d..4652679a1a9 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -1,27 +1,12 @@ package keeper import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" ) // InitGenesis func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { - k.SetPort(ctx, state.PortId) - - // Only try to bind to port if it is not already bound, since we may already own - // port capability from capability InitGenesis - if !k.IsBound(ctx, state.PortId) { - // fee29 module binds to the feetransfer port on InitChain - // and claims the returned capability - err := k.BindPort(ctx, state.PortId) - if err != nil { - panic(fmt.Sprintf("could not claim port capability: %v", err)) - } - } - for _, fee := range state.IdentifiedFees { k.SetFeeInEscrow(ctx, fee) } @@ -30,7 +15,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { // ExportGenesis func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return &types.GenesisState{ - PortId: k.GetPort(ctx), IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), } } diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go new file mode 100644 index 00000000000..179862b88dd --- /dev/null +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/testing" +) + +func (suite *KeeperTestSuite) TestInitGenesis() { + suite.SetupTest() + + refundAcc := suite.chainA.SenderAccount.GetAddress() + ackFee := validCoins + receiveFee := validCoins2 + timeoutFee := validCoins3 + packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} + fee := types.Fee{ackFee, receiveFee, timeoutFee} + + genesisState := types.GenesisState{ + IdentifiedFees: []*types.IdentifiedPacketFee{ + { + PacketId: packetId, + Fee: fee, + RefundAddress: refundAcc.String(), + Relayers: nil, + }, + }, + } + + suite.chainA.GetSimApp().IBCFeeKeeper.InitGenesis(suite.chainA.GetContext(), genesisState) + + identifiedFee, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId) + suite.Require().True(found) + suite.Require().Equal(genesisState.IdentifiedFees[0], &identifiedFee) +} + +/* +func (suite *InterchainAccountsTestSuite) TestExportGenesis() { + suite.SetupTest() + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + genesisState := ica.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAKeeper) + + suite.Require().Equal([]string{types.PortID, TestPortID}, genesisState.GetPorts()) + + suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId) + suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId) + + suite.Require().Equal(TestAccAddress.String(), genesisState.InterchainAccounts[0].AccountAddress) + suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId) +} +*/ diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 735935439b2..05ac26a6d30 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -56,35 +56,17 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName) } +// ChanCloseInit wraps the channel keeper's function in order to expose it to underlying app. +func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { + return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) +} + // BindPort defines a wrapper function for the port Keeper's function in // order to expose it to module's InitGenesis function func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { return k.portKeeper.BindPort(ctx, portID) } -// IsBound checks if the fee29 module is already bound to the desired port -func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) - return ok -} - -// GetPort returns the portID for the fee29 module. Used in ExportGenesis -func (k Keeper) GetPort(ctx sdk.Context) string { - store := ctx.KVStore(k.storeKey) - return string(store.Get(types.PortKey)) -} - -// SetPort sets the portID for the fee29 module. Used in InitGenesis -func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) - store.Set(types.PortKey, []byte(portID)) -} - -// ChanCloseInit wraps the channel keeper's function in order to expose it to underlying app. -func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { - return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) -} - // GetChannel wraps IBC ChannelKeeper's GetChannel function func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool) { return k.channelKeeper.GetChannel(ctx, portID, channelID) diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index 1ba5b47d1e6..a096d8c8ab4 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -1,13 +1,8 @@ package types -import ( - host "github.com/cosmos/ibc-go/modules/core/24-host" -) - // NewGenesisState creates a 29-fee GenesisState instance. func NewGenesisState(identifiedFees []*IdentifiedPacketFee) *GenesisState { return &GenesisState{ - PortId: PortID, IdentifiedFees: identifiedFees, } } @@ -15,7 +10,6 @@ func NewGenesisState(identifiedFees []*IdentifiedPacketFee) *GenesisState { // DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. func DefaultGenesisState() *GenesisState { return &GenesisState{ - PortId: PortID, IdentifiedFees: []*IdentifiedPacketFee{}, } } @@ -23,8 +17,5 @@ func DefaultGenesisState() *GenesisState { // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - if err := host.PortIdentifierValidator(gs.PortId); err != nil { - return err - } return nil } diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index d2287f27827..406c5f824f0 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -25,8 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fee middleware genesis state type GenesisState struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` - IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,2,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` + IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -62,13 +61,6 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetPortId() string { - if m != nil { - return m.PortId - } - return "" -} - func (m *GenesisState) GetIdentifiedFees() []*IdentifiedPacketFee { if m != nil { return m.IdentifiedFees @@ -85,26 +77,24 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 295 bytes of a gzipped FileDescriptorProto + // 260 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x4f, 0x4b, 0x4d, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xa6, 0x97, 0x96, 0x9a, 0xaa, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0x29, 0xe2, - 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0x69, 0x1d, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0x8e, 0xe0, 0x92, - 0xc4, 0x92, 0x54, 0x21, 0x6d, 0x2e, 0xf6, 0x82, 0xfc, 0xa2, 0x92, 0xf8, 0xcc, 0x14, 0x09, 0x46, - 0x05, 0x46, 0x0d, 0x4e, 0x27, 0xa1, 0x4f, 0xf7, 0xe4, 0xf9, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, - 0xa0, 0x12, 0x4a, 0x41, 0x6c, 0x20, 0x96, 0x67, 0x8a, 0x50, 0x21, 0x17, 0x7f, 0x66, 0x4a, 0x6a, - 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, 0x4a, 0x7c, 0x5a, 0x6a, 0x6a, 0xb1, 0x04, 0x93, 0x02, 0xb3, - 0x06, 0xb7, 0x91, 0x8e, 0x1e, 0x0e, 0x97, 0xea, 0x79, 0xc2, 0xd5, 0x07, 0x24, 0x26, 0x67, 0xa7, - 0x96, 0xb8, 0xa5, 0xa6, 0x3a, 0x49, 0x7d, 0xba, 0x27, 0x2f, 0x06, 0xb1, 0x02, 0xcd, 0x38, 0xa5, - 0x20, 0x3e, 0x84, 0x88, 0x5b, 0x6a, 0x6a, 0xb1, 0x93, 0xcf, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, - 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, - 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, - 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, 0xeb, 0x67, 0x26, 0x25, 0xeb, 0xa6, 0xe7, 0xeb, 0xe7, 0xe6, - 0xa7, 0x94, 0xe6, 0xa4, 0x16, 0x83, 0x82, 0xa2, 0x58, 0xdf, 0xc8, 0x52, 0x17, 0x14, 0x0a, 0x25, - 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x50, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x0a, - 0x35, 0x98, 0xd6, 0x80, 0x01, 0x00, 0x00, + 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0xa9, 0x91, 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x47, 0x70, 0x49, + 0x62, 0x49, 0xaa, 0x50, 0x21, 0x17, 0x7f, 0x66, 0x4a, 0x6a, 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, + 0x4a, 0x7c, 0x5a, 0x6a, 0x6a, 0xb1, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x8e, 0x1e, 0x0e, + 0xcb, 0xf5, 0x3c, 0xe1, 0xea, 0x03, 0x12, 0x93, 0xb3, 0x53, 0x4b, 0xdc, 0x52, 0x53, 0x9d, 0xa4, + 0x3e, 0xdd, 0x93, 0x17, 0xab, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, 0x33, 0x4e, 0x29, 0x88, 0x0f, + 0x21, 0xe2, 0x96, 0x9a, 0x5a, 0xec, 0xe4, 0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, + 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, + 0x0c, 0x51, 0x46, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0xf9, + 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x99, 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, + 0x39, 0xa9, 0xc5, 0x20, 0xdf, 0x15, 0xeb, 0x1b, 0x59, 0xea, 0x82, 0x3c, 0x56, 0x52, 0x59, 0x90, + 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x10, 0xa7, 0xc1, 0xb3, + 0x53, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -138,16 +128,9 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0xa } } - if len(m.PortId) > 0 { - i -= len(m.PortId) - copy(dAtA[i:], m.PortId) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } @@ -168,10 +151,6 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - l = len(m.PortId) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } if len(m.IdentifiedFees) > 0 { for _, e := range m.IdentifiedFees { l = e.Size() @@ -217,38 +196,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PortId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field IdentifiedFees", wireType) } diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index 760a31803a9..a4be8bea993 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -7,6 +7,5 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // GenesisState defines the fee middleware genesis state message GenesisState { - string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; - repeated IdentifiedPacketFee identified_fees = 2 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; + repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; } From 01f442d45b7e403b1136b16a718fc21207c5c0ed Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 23 Nov 2021 14:11:45 +0100 Subject: [PATCH 05/10] feat: adding GetAll for relayer addr/fee enabled chan + update genesis --- docs/ibc/proto-docs.md | 36 ++ modules/apps/29-fee/keeper/genesis.go | 12 +- modules/apps/29-fee/keeper/keeper.go | 43 ++ modules/apps/29-fee/keeper/keeper_test.go | 50 ++ modules/apps/29-fee/types/genesis.pb.go | 619 +++++++++++++++++++- proto/ibc/applications/fee/v1/genesis.proto | 16 +- 6 files changed, 755 insertions(+), 21 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index c906989b4f8..4b05a167c58 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -30,7 +30,9 @@ - [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) - [ibc/applications/fee/v1/genesis.proto](#ibc/applications/fee/v1/genesis.proto) + - [FeeEnabledChannel](#ibc.applications.fee.v1.FeeEnabledChannel) - [GenesisState](#ibc.applications.fee.v1.GenesisState) + - [RegisteredRelayerAddress](#ibc.applications.fee.v1.RegisteredRelayerAddress) - [ibc/applications/fee/v1/query.proto](#ibc/applications/fee/v1/query.proto) - [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest) @@ -670,6 +672,22 @@ and an optional list of relayers that are permitted to receive the fee. + + +### FeeEnabledChannel +Contains the PortID & ChannelID for a fee enabled channel + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `port_id` | [string](#string) | | | +| `channel_id` | [string](#string) | | | + + + + + + ### GenesisState @@ -679,6 +697,24 @@ GenesisState defines the fee middleware genesis state | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `identified_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | | +| `fee_enabled_channels` | [FeeEnabledChannel](#ibc.applications.fee.v1.FeeEnabledChannel) | repeated | | +| `registered_relayers` | [RegisteredRelayerAddress](#ibc.applications.fee.v1.RegisteredRelayerAddress) | repeated | | + + + + + + + + +### RegisteredRelayerAddress +Contains the address and counterparty address for a specific relayer (for distributing fees) + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | | +| `counterparty_address` | [string](#string) | | | diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index 4652679a1a9..90512825aa6 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -10,11 +10,21 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { for _, fee := range state.IdentifiedFees { k.SetFeeInEscrow(ctx, fee) } + + for _, addr := range state.RegisteredRelayers { + k.SetCounterpartyAddress(ctx, addr.Address, addr.CounterpartyAddress) + } + + for _, enabledChan := range state.FeeEnabledChannels { + k.SetFeeEnabled(ctx, enabledChan.PortId, enabledChan.ChannelId) + } } // ExportGenesis func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return &types.GenesisState{ - IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), + IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), + FeeEnabledChannels: k.GetAllFeeEnabledChannels(ctx), + RegisteredRelayers: k.GetAllRelayerAddresses(ctx), } } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 05ac26a6d30..f1871d2adb6 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -1,6 +1,8 @@ package keeper import ( + "strings" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" @@ -107,6 +109,27 @@ func (k Keeper) IsFeeEnabled(ctx sdk.Context, portID, channelID string) bool { return store.Get(types.FeeEnabledKey(portID, channelID)) != nil } +// GetAllFeeEnabledChannels returns a list of all ics29 enabled channels containing portID & channelID that are stored in state +func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []*types.FeeEnabledChannel { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeeEnabledKeyPrefix)) + defer iterator.Close() + + var enabledChArr []*types.FeeEnabledChannel + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + + ch := &types.FeeEnabledChannel{ + PortId: keySplit[1], + ChannelId: keySplit[2], + } + + enabledChArr = append(enabledChArr, ch) + } + + return enabledChArr +} + // SetCounterpartyAddress maps the destination chain relayer address to the source relayer address // The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) { @@ -127,6 +150,26 @@ func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address string) (string, return addr, true } +func (k Keeper) GetAllRelayerAddresses(ctx sdk.Context) []*types.RegisteredRelayerAddress { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.RelayerAddressKeyPrefix)) + defer iterator.Close() + + var registeredAddrArr []*types.RegisteredRelayerAddress + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + + addr := &types.RegisteredRelayerAddress{ + Address: keySplit[1], + CounterpartyAddress: string(iterator.Value()), + } + + registeredAddrArr = append(registeredAddrArr, addr) + } + + return registeredAddrArr +} + // Stores a Fee for a given packet in state func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee *types.IdentifiedPacketFee) { store := ctx.KVStore(k.storeKey) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 53b98a52e0c..6157c29d353 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -94,3 +94,53 @@ func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() { suite.Require().Len(fees, len(expectedFees)) suite.Require().Equal(fees, expectedFees) } + +func (suite *KeeperTestSuite) TestGetAllFeeEnabledChannels() { + suite.SetupTest() // reset + + validPortId := "ibcmoduleport" + // set two channels enabled + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), validPortId, ibctesting.FirstChannelID) + + expectedCh := []*types.FeeEnabledChannel{ + { + PortId: validPortId, + ChannelId: ibctesting.FirstChannelID, + }, + { + PortId: transfertypes.PortID, + ChannelId: ibctesting.FirstChannelID, + }, + } + + ch := suite.chainA.GetSimApp().IBCFeeKeeper.GetAllFeeEnabledChannels(suite.chainA.GetContext()) + suite.Require().Len(ch, len(expectedCh)) + suite.Require().Equal(ch, expectedCh) +} + +func (suite *KeeperTestSuite) TestGetAllRelayerAddresses() { + suite.SetupTest() // reset + + sender := suite.chainA.SenderAccount.GetAddress().String() + counterparty := suite.chainB.SenderAccount.GetAddress().String() + + // register two address/counterparty address + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), counterparty, sender) + + expectedAddr := []*types.RegisteredRelayerAddress{ + { + Address: counterparty, + CounterpartyAddress: sender, + }, + { + Address: sender, + CounterpartyAddress: counterparty, + }, + } + + addr := suite.chainA.GetSimApp().IBCFeeKeeper.GetAllRelayerAddresses(suite.chainA.GetContext()) + suite.Require().Len(addr, len(expectedAddr)) + suite.Require().Equal(addr, expectedAddr) +} diff --git a/modules/apps/29-fee/types/genesis.pb.go b/modules/apps/29-fee/types/genesis.pb.go index 406c5f824f0..80a2e44d3df 100644 --- a/modules/apps/29-fee/types/genesis.pb.go +++ b/modules/apps/29-fee/types/genesis.pb.go @@ -25,7 +25,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fee middleware genesis state type GenesisState struct { - IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` + IdentifiedFees []*IdentifiedPacketFee `protobuf:"bytes,1,rep,name=identified_fees,json=identifiedFees,proto3" json:"identified_fees,omitempty" yaml:"identified_fees"` + FeeEnabledChannels []*FeeEnabledChannel `protobuf:"bytes,2,rep,name=fee_enabled_channels,json=feeEnabledChannels,proto3" json:"fee_enabled_channels,omitempty" yaml:"fee_enabled_channels"` + RegisteredRelayers []*RegisteredRelayerAddress `protobuf:"bytes,3,rep,name=registered_relayers,json=registeredRelayers,proto3" json:"registered_relayers,omitempty" yaml:"registered_relayers"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -68,8 +70,130 @@ func (m *GenesisState) GetIdentifiedFees() []*IdentifiedPacketFee { return nil } +func (m *GenesisState) GetFeeEnabledChannels() []*FeeEnabledChannel { + if m != nil { + return m.FeeEnabledChannels + } + return nil +} + +func (m *GenesisState) GetRegisteredRelayers() []*RegisteredRelayerAddress { + if m != nil { + return m.RegisteredRelayers + } + return nil +} + +// Contains the PortID & ChannelID for a fee enabled channel +type FeeEnabledChannel struct { + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` +} + +func (m *FeeEnabledChannel) Reset() { *m = FeeEnabledChannel{} } +func (m *FeeEnabledChannel) String() string { return proto.CompactTextString(m) } +func (*FeeEnabledChannel) ProtoMessage() {} +func (*FeeEnabledChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_7191992e856dff95, []int{1} +} +func (m *FeeEnabledChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeeEnabledChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeeEnabledChannel.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 *FeeEnabledChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeeEnabledChannel.Merge(m, src) +} +func (m *FeeEnabledChannel) XXX_Size() int { + return m.Size() +} +func (m *FeeEnabledChannel) XXX_DiscardUnknown() { + xxx_messageInfo_FeeEnabledChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_FeeEnabledChannel proto.InternalMessageInfo + +func (m *FeeEnabledChannel) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *FeeEnabledChannel) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +// Contains the address and counterparty address for a specific relayer (for distributing fees) +type RegisteredRelayerAddress struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + CounterpartyAddress string `protobuf:"bytes,2,opt,name=counterparty_address,json=counterpartyAddress,proto3" json:"counterparty_address,omitempty" yaml:"counterparty_address"` +} + +func (m *RegisteredRelayerAddress) Reset() { *m = RegisteredRelayerAddress{} } +func (m *RegisteredRelayerAddress) String() string { return proto.CompactTextString(m) } +func (*RegisteredRelayerAddress) ProtoMessage() {} +func (*RegisteredRelayerAddress) Descriptor() ([]byte, []int) { + return fileDescriptor_7191992e856dff95, []int{2} +} +func (m *RegisteredRelayerAddress) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RegisteredRelayerAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RegisteredRelayerAddress.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 *RegisteredRelayerAddress) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisteredRelayerAddress.Merge(m, src) +} +func (m *RegisteredRelayerAddress) XXX_Size() int { + return m.Size() +} +func (m *RegisteredRelayerAddress) XXX_DiscardUnknown() { + xxx_messageInfo_RegisteredRelayerAddress.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisteredRelayerAddress proto.InternalMessageInfo + +func (m *RegisteredRelayerAddress) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *RegisteredRelayerAddress) GetCounterpartyAddress() string { + if m != nil { + return m.CounterpartyAddress + } + return "" +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.fee.v1.GenesisState") + proto.RegisterType((*FeeEnabledChannel)(nil), "ibc.applications.fee.v1.FeeEnabledChannel") + proto.RegisterType((*RegisteredRelayerAddress)(nil), "ibc.applications.fee.v1.RegisteredRelayerAddress") } func init() { @@ -77,24 +201,37 @@ func init() { } var fileDescriptor_7191992e856dff95 = []byte{ - // 260 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4c, 0x4a, 0xd6, - 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x4f, 0x4b, 0x4d, - 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x12, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xa6, 0x97, 0x96, 0x9a, 0xaa, 0x57, 0x66, - 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0x29, 0xe2, - 0x32, 0x15, 0xa4, 0x0b, 0xac, 0x44, 0xa9, 0x91, 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x47, 0x70, 0x49, - 0x62, 0x49, 0xaa, 0x50, 0x21, 0x17, 0x7f, 0x66, 0x4a, 0x6a, 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, - 0x4a, 0x7c, 0x5a, 0x6a, 0x6a, 0xb1, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x8e, 0x1e, 0x0e, - 0xcb, 0xf5, 0x3c, 0xe1, 0xea, 0x03, 0x12, 0x93, 0xb3, 0x53, 0x4b, 0xdc, 0x52, 0x53, 0x9d, 0xa4, - 0x3e, 0xdd, 0x93, 0x17, 0xab, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, 0x33, 0x4e, 0x29, 0x88, 0x0f, - 0x21, 0xe2, 0x96, 0x9a, 0x5a, 0xec, 0xe4, 0x73, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, - 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, - 0x0c, 0x51, 0x46, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0xf9, - 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x99, 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, - 0x39, 0xa9, 0xc5, 0x20, 0xdf, 0x15, 0xeb, 0x1b, 0x59, 0xea, 0x82, 0x3c, 0x56, 0x52, 0x59, 0x90, - 0x5a, 0x9c, 0xc4, 0x06, 0xf6, 0x98, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x10, 0xa7, 0xc1, 0xb3, - 0x53, 0x01, 0x00, 0x00, + // 470 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x9b, 0x2d, 0xec, 0xb2, 0xa3, 0xac, 0xec, 0x6c, 0xd5, 0x50, 0x21, 0x59, 0x07, 0x84, + 0x45, 0xdd, 0x84, 0x56, 0x2f, 0x7a, 0xb3, 0x62, 0xa5, 0xe0, 0x41, 0xc6, 0x9b, 0x97, 0x30, 0xc9, + 0xbc, 0x64, 0x07, 0xd3, 0x4c, 0x9c, 0x99, 0x16, 0x7a, 0xf0, 0x22, 0x08, 0x1e, 0xfd, 0x58, 0x1e, + 0xf7, 0xe8, 0xa9, 0x48, 0xfb, 0x0d, 0xfa, 0x09, 0x24, 0x99, 0x76, 0xb7, 0xd4, 0xe6, 0xf6, 0x66, + 0xde, 0xef, 0xff, 0xff, 0xe7, 0x65, 0x1e, 0x7a, 0x22, 0xe2, 0x24, 0x64, 0x65, 0x99, 0x8b, 0x84, + 0x19, 0x21, 0x0b, 0x1d, 0xa6, 0x00, 0xe1, 0xb4, 0x17, 0x66, 0x50, 0x80, 0x16, 0x3a, 0x28, 0x95, + 0x34, 0x12, 0x3f, 0x14, 0x71, 0x12, 0x6c, 0x63, 0x41, 0x0a, 0x10, 0x4c, 0x7b, 0xdd, 0x4e, 0x26, + 0x33, 0x59, 0x33, 0x61, 0x55, 0x59, 0xbc, 0xfb, 0xb8, 0xc9, 0xb5, 0x52, 0xd5, 0x08, 0xf9, 0xd1, + 0x46, 0x77, 0xdf, 0xdb, 0x8c, 0x4f, 0x86, 0x19, 0xc0, 0x5f, 0xd1, 0x3d, 0xc1, 0xa1, 0x30, 0x22, + 0x15, 0xc0, 0xa3, 0x14, 0x40, 0xbb, 0xce, 0x79, 0xfb, 0xe2, 0x4e, 0xff, 0x79, 0xd0, 0x10, 0x1e, + 0x8c, 0x6e, 0xf8, 0x8f, 0x2c, 0xf9, 0x02, 0x66, 0x08, 0x30, 0xe8, 0xae, 0xe6, 0xfe, 0x83, 0x19, + 0x1b, 0xe7, 0xaf, 0xc9, 0x8e, 0x1d, 0xa1, 0x27, 0xb7, 0x37, 0x43, 0x00, 0x8d, 0xbf, 0xa1, 0x4e, + 0x0a, 0x10, 0x41, 0xc1, 0xe2, 0x1c, 0x78, 0x94, 0x5c, 0xb1, 0xa2, 0x80, 0x5c, 0xbb, 0x07, 0x75, + 0xee, 0xd3, 0xc6, 0xdc, 0x21, 0xc0, 0x3b, 0xab, 0x79, 0x6b, 0x25, 0x03, 0x7f, 0x35, 0xf7, 0x1f, + 0xd9, 0xd4, 0x7d, 0x8e, 0x84, 0xe2, 0x74, 0x57, 0xa3, 0xf1, 0x77, 0x07, 0x9d, 0x29, 0xc8, 0x84, + 0x36, 0xa0, 0x80, 0x47, 0x0a, 0x72, 0x36, 0x03, 0xa5, 0xdd, 0x76, 0x1d, 0xdf, 0x6b, 0x8c, 0xa7, + 0x37, 0x1a, 0x6a, 0x25, 0x6f, 0x38, 0x57, 0xa0, 0xf5, 0xc0, 0x5b, 0xcd, 0xfd, 0xae, 0xfd, 0x8a, + 0x3d, 0xbe, 0x84, 0x62, 0xb5, 0xab, 0xd4, 0x64, 0x8a, 0x4e, 0xff, 0x1b, 0x07, 0x3f, 0x43, 0x47, + 0xa5, 0x54, 0x26, 0x12, 0xdc, 0x75, 0xce, 0x9d, 0x8b, 0xe3, 0x01, 0x5e, 0xcd, 0xfd, 0x13, 0xeb, + 0xbc, 0x6e, 0x10, 0x7a, 0x58, 0x55, 0x23, 0x8e, 0x5f, 0x22, 0xb4, 0x9e, 0xb3, 0xe2, 0x0f, 0x6a, + 0xfe, 0xfe, 0x6a, 0xee, 0x9f, 0x5a, 0xfe, 0xb6, 0x47, 0xe8, 0xf1, 0xfa, 0x30, 0xe2, 0xe4, 0xa7, + 0x83, 0xdc, 0xa6, 0x41, 0xb0, 0x8b, 0x8e, 0x98, 0x2d, 0x6d, 0x3e, 0xdd, 0x1c, 0x31, 0x45, 0x9d, + 0x44, 0x4e, 0x0a, 0x03, 0xaa, 0x64, 0xca, 0xcc, 0xa2, 0x0d, 0x66, 0x63, 0xb7, 0x9e, 0x61, 0x1f, + 0x45, 0xe8, 0xd9, 0xf6, 0xf5, 0xe6, 0xb7, 0x7d, 0xf8, 0xbd, 0xf0, 0x9c, 0xeb, 0x85, 0xe7, 0xfc, + 0x5d, 0x78, 0xce, 0xaf, 0xa5, 0xd7, 0xba, 0x5e, 0x7a, 0xad, 0x3f, 0x4b, 0xaf, 0xf5, 0xb9, 0x9f, + 0x09, 0x73, 0x35, 0x89, 0x83, 0x44, 0x8e, 0xc3, 0x44, 0xea, 0xb1, 0xd4, 0xa1, 0x88, 0x93, 0xcb, + 0x4c, 0x86, 0x63, 0xc9, 0x27, 0x39, 0xe8, 0x6a, 0xc9, 0x75, 0xd8, 0x7f, 0x75, 0x59, 0xed, 0xb7, + 0x99, 0x95, 0xa0, 0xe3, 0xc3, 0x7a, 0xbf, 0x5f, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x14, 0xf8, + 0xcc, 0x98, 0x5a, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -117,6 +254,34 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.RegisteredRelayers) > 0 { + for iNdEx := len(m.RegisteredRelayers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RegisteredRelayers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.FeeEnabledChannels) > 0 { + for iNdEx := len(m.FeeEnabledChannels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FeeEnabledChannels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } if len(m.IdentifiedFees) > 0 { for iNdEx := len(m.IdentifiedFees) - 1; iNdEx >= 0; iNdEx-- { { @@ -134,6 +299,80 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *FeeEnabledChannel) 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 *FeeEnabledChannel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeeEnabledChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x12 + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RegisteredRelayerAddress) 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 *RegisteredRelayerAddress) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RegisteredRelayerAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CounterpartyAddress) > 0 { + i -= len(m.CounterpartyAddress) + copy(dAtA[i:], m.CounterpartyAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.CounterpartyAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -157,6 +396,52 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.FeeEnabledChannels) > 0 { + for _, e := range m.FeeEnabledChannels { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.RegisteredRelayers) > 0 { + for _, e := range m.RegisteredRelayers { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *FeeEnabledChannel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *RegisteredRelayerAddress) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.CounterpartyAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -229,6 +514,302 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeeEnabledChannels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FeeEnabledChannels = append(m.FeeEnabledChannels, &FeeEnabledChannel{}) + if err := m.FeeEnabledChannels[len(m.FeeEnabledChannels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisteredRelayers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RegisteredRelayers = append(m.RegisteredRelayers, &RegisteredRelayerAddress{}) + if err := m.RegisteredRelayers[len(m.RegisteredRelayers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *FeeEnabledChannel) 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 ErrIntOverflowGenesis + } + 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: FeeEnabledChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeeEnabledChannel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RegisteredRelayerAddress) 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 ErrIntOverflowGenesis + } + 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: RegisteredRelayerAddress: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RegisteredRelayerAddress: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CounterpartyAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/fee/v1/genesis.proto b/proto/ibc/applications/fee/v1/genesis.proto index a4be8bea993..cef33b501a0 100644 --- a/proto/ibc/applications/fee/v1/genesis.proto +++ b/proto/ibc/applications/fee/v1/genesis.proto @@ -7,5 +7,19 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/29-fee/types"; // GenesisState defines the fee middleware genesis state message GenesisState { - repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; + repeated IdentifiedPacketFee identified_fees = 1 [(gogoproto.moretags) = "yaml:\"identified_fees\""]; + repeated FeeEnabledChannel fee_enabled_channels = 2 [(gogoproto.moretags) = "yaml:\"fee_enabled_channels\""]; + repeated RegisteredRelayerAddress registered_relayers = 3 [(gogoproto.moretags) = "yaml:\"registered_relayers\""]; +} + +// Contains the PortID & ChannelID for a fee enabled channel +message FeeEnabledChannel { + string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""]; +} + +// Contains the address and counterparty address for a specific relayer (for distributing fees) +message RegisteredRelayerAddress { + string address = 1; + string counterparty_address = 2 [(gogoproto.moretags) = "yaml:\"counterparty_address\""]; } From 0694910e4967f365d7685dc9a2bca84538c566ac Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 23 Nov 2021 14:52:06 +0100 Subject: [PATCH 06/10] test: TestExportGenesis --- modules/apps/29-fee/keeper/genesis_test.go | 72 ++++++++++++++++++---- modules/apps/29-fee/keeper/keeper_test.go | 6 -- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index 179862b88dd..66e8ed6db6c 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -2,6 +2,8 @@ package keeper_test import ( "github.com/cosmos/ibc-go/modules/apps/29-fee/types" + + transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/testing" ) @@ -9,6 +11,7 @@ import ( func (suite *KeeperTestSuite) TestInitGenesis() { suite.SetupTest() + // build PacketId & Fee refundAcc := suite.chainA.SenderAccount.GetAddress() ackFee := validCoins receiveFee := validCoins2 @@ -16,6 +19,10 @@ func (suite *KeeperTestSuite) TestInitGenesis() { packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} fee := types.Fee{ackFee, receiveFee, timeoutFee} + // relayer addresses + sender := suite.chainA.SenderAccount.GetAddress().String() + counterparty := suite.chainB.SenderAccount.GetAddress().String() + genesisState := types.GenesisState{ IdentifiedFees: []*types.IdentifiedPacketFee{ { @@ -25,32 +32,73 @@ func (suite *KeeperTestSuite) TestInitGenesis() { Relayers: nil, }, }, + FeeEnabledChannels: []*types.FeeEnabledChannel{ + { + PortId: transfertypes.PortID, + ChannelId: ibctesting.FirstChannelID, + }, + }, + RegisteredRelayers: []*types.RegisteredRelayerAddress{ + { + Address: sender, + CounterpartyAddress: counterparty, + }, + }, } suite.chainA.GetSimApp().IBCFeeKeeper.InitGenesis(suite.chainA.GetContext(), genesisState) + // check fee identifiedFee, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId) suite.Require().True(found) suite.Require().Equal(genesisState.IdentifiedFees[0], &identifiedFee) + + // check fee is enabled + isEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) + suite.Require().True(isEnabled) + + // check relayers + addr, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(suite.chainA.GetContext(), sender) + suite.Require().True(found) + suite.Require().Equal(genesisState.RegisteredRelayers[0].CounterpartyAddress, addr) } -/* -func (suite *InterchainAccountsTestSuite) TestExportGenesis() { +func (suite *KeeperTestSuite) TestExportGenesis() { suite.SetupTest() - path := NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) + // set fee enabled + suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) - err := SetupICAPath(path, TestOwnerAddress) + // setup & escrow the packet fee + refundAcc := suite.chainA.SenderAccount.GetAddress() + ackFee := validCoins + receiveFee := validCoins2 + timeoutFee := validCoins3 + packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} + fee := types.Fee{ackFee, receiveFee, timeoutFee} + identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} + err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee) suite.Require().NoError(err) - genesisState := ica.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAKeeper) + // relayer addresses + sender := suite.chainA.SenderAccount.GetAddress().String() + counterparty := suite.chainB.SenderAccount.GetAddress().String() + // set counterparty address + suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) + + // export genesis + genesisState := suite.chainA.GetSimApp().IBCFeeKeeper.ExportGenesis(suite.chainA.GetContext()) - suite.Require().Equal([]string{types.PortID, TestPortID}, genesisState.GetPorts()) + // check fee enabled + suite.Require().Equal(ibctesting.FirstChannelID, genesisState.FeeEnabledChannels[0].ChannelId) + suite.Require().Equal(transfertypes.PortID, genesisState.FeeEnabledChannels[0].PortId) - suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId) - suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId) + // check fee + suite.Require().Equal(packetId, genesisState.IdentifiedFees[0].PacketId) + suite.Require().Equal(fee, genesisState.IdentifiedFees[0].Fee) + suite.Require().Equal(refundAcc.String(), genesisState.IdentifiedFees[0].RefundAddress) + suite.Require().Equal([]string(nil), genesisState.IdentifiedFees[0].Relayers) - suite.Require().Equal(TestAccAddress.String(), genesisState.InterchainAccounts[0].AccountAddress) - suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId) + // check registered relayer addresses + suite.Require().Equal(sender, genesisState.RegisteredRelayers[0].Address) + suite.Require().Equal(counterparty, genesisState.RegisteredRelayers[0].CounterpartyAddress) } -*/ diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 6157c29d353..f4315baa3b6 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -125,15 +125,9 @@ func (suite *KeeperTestSuite) TestGetAllRelayerAddresses() { sender := suite.chainA.SenderAccount.GetAddress().String() counterparty := suite.chainB.SenderAccount.GetAddress().String() - // register two address/counterparty address suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) - suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), counterparty, sender) expectedAddr := []*types.RegisteredRelayerAddress{ - { - Address: counterparty, - CounterpartyAddress: sender, - }, { Address: sender, CounterpartyAddress: counterparty, From b4e1f9a373715338ff0542af56141352d8bfa174 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 23 Nov 2021 15:04:13 +0100 Subject: [PATCH 07/10] feat: update type + hook up to module.go --- modules/apps/29-fee/module.go | 25 ++++++++++++------------- modules/apps/29-fee/types/genesis.go | 10 +++++++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/apps/29-fee/module.go b/modules/apps/29-fee/module.go index 61e39846584..78b9dc6d091 100644 --- a/modules/apps/29-fee/module.go +++ b/modules/apps/29-fee/module.go @@ -3,6 +3,7 @@ package fee import ( "context" "encoding/json" + "fmt" "math/rand" "github.com/cosmos/cosmos-sdk/client" @@ -51,19 +52,18 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) // DefaultGenesis returns default genesis state as raw bytes for the ibc // 29-fee module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - // return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) return nil } // ValidateGenesis performs genesis state validation for the 29-fee module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - // var gs types.GenesisState - // if err := cdc.UnmarshalJSON(bz, &gs); err != nil { - // return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - // } + var gs types.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } - // return gs.Validate() - return nil + return gs.Validate() } // RegisterRESTRoutes implements AppModuleBasic interface @@ -127,18 +127,17 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the ibc-29-fee module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - // var genesisState types.GenesisState - // cdc.MustUnmarshalJSON(data, &genesisState) - // am.keeper.InitGenesis(ctx, genesisState) + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the ibc-29-fee // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - // gs := am.keeper.ExportGenesis(ctx) - // return cdc.MustMarshalJSON(gs) - return nil + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index a096d8c8ab4..3f85192d930 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -1,16 +1,20 @@ package types // NewGenesisState creates a 29-fee GenesisState instance. -func NewGenesisState(identifiedFees []*IdentifiedPacketFee) *GenesisState { +func NewGenesisState(identifiedFees []*IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress) *GenesisState { return &GenesisState{ - IdentifiedFees: identifiedFees, + IdentifiedFees: identifiedFees, + FeeEnabledChannels: feeEnabledChannels, + RegisteredRelayers: registeredRelayers, } } // DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. func DefaultGenesisState() *GenesisState { return &GenesisState{ - IdentifiedFees: []*IdentifiedPacketFee{}, + IdentifiedFees: []*IdentifiedPacketFee{}, + FeeEnabledChannels: []*FeeEnabledChannel{}, + RegisteredRelayers: []*RegisteredRelayerAddress{}, } } From 6ba0387ab40283ffa7e961d59f1b9f5f06482412 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 23 Nov 2021 15:04:52 +0100 Subject: [PATCH 08/10] fix: remove PortKey --- modules/apps/29-fee/types/keys.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 028ca9130dc..5b2f1589f87 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -34,11 +34,6 @@ const ( FeeInEscrowPrefix = "feeInEscrow" ) -var ( - // PortKey defines the key to store the port ID in store - PortKey = []byte{0x01} -) - // FeeEnabledKey returns the key that stores a flag to determine if fee logic should // be enabled for the given port and channel identifiers. func FeeEnabledKey(portID, channelID string) []byte { From 7581a7ce4dceed0a2b8972035273d85fd232efab Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 23 Nov 2021 15:15:21 +0100 Subject: [PATCH 09/10] fix: imports + remove scoped keeper --- modules/apps/29-fee/keeper/genesis.go | 1 + modules/apps/29-fee/keeper/genesis_test.go | 1 - modules/apps/29-fee/keeper/keeper.go | 6 +----- modules/apps/29-fee/types/keys.go | 2 +- testing/simapp/app.go | 5 +---- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/modules/apps/29-fee/keeper/genesis.go b/modules/apps/29-fee/keeper/genesis.go index 90512825aa6..7ce7f11970f 100644 --- a/modules/apps/29-fee/keeper/genesis.go +++ b/modules/apps/29-fee/keeper/genesis.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/apps/29-fee/types" ) diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index 66e8ed6db6c..8daa67a669d 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "github.com/cosmos/ibc-go/modules/apps/29-fee/types" - transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/testing" diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index f1871d2adb6..1fda4910bc2 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -5,10 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/ibc-go/modules/apps/29-fee/types" @@ -33,13 +31,12 @@ type Keeper struct { channelKeeper types.ChannelKeeper portKeeper types.PortKeeper bankKeeper types.BankKeeper - scopedKeeper capabilitykeeper.ScopedKeeper } // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, + channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ) Keeper { return Keeper{ @@ -49,7 +46,6 @@ func NewKeeper( portKeeper: portKeeper, authKeeper: authKeeper, bankKeeper: bankKeeper, - scopedKeeper: scopedKeeper, } } diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 5b2f1589f87..522177c9aff 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -13,7 +13,7 @@ const ( // StoreKey is the store key string for IBC fee module StoreKey = ModuleName - // PortKey is the port id that is wrapped by fee middleware + // PortID is the port id that is wrapped by fee middleware PortID = "feetransfer" // RouterKey is the message route for IBC fee module diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 066eb3f84cd..58b2a79006d 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -262,8 +262,6 @@ func NewSimApp( app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) - scopedIBCFeeKeeper := app.CapabilityKeeper.ScopeToModule(ibcfeetypes.ModuleName) - // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do // note replicate if you do not need to test core IBC or light clients. scopedIBCMockKeeper := app.CapabilityKeeper.ScopeToModule(ibcmock.ModuleName) @@ -325,7 +323,7 @@ func NewSimApp( ) app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(appCodec, keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedIBCFeeKeeper, + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, ) // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper @@ -483,7 +481,6 @@ func NewSimApp( app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper - app.ScopedIBCFeeKeeper = scopedIBCFeeKeeper // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do // note replicate if you do not need to test core IBC or light clients. From 0421fd9cc9e834a4ff1ca7a102c9c5459454e394 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 24 Nov 2021 13:51:15 +0100 Subject: [PATCH 10/10] nit: using NewPacketId helper and updating helper def to have correct params --- modules/apps/29-fee/keeper/genesis_test.go | 31 ++++++++++++------- modules/apps/29-fee/keeper/grpc_query_test.go | 10 +++--- modules/apps/29-fee/types/msgs.go | 6 ++-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index 8daa67a669d..4119891d380 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "github.com/cosmos/ibc-go/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" - channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/testing" ) @@ -12,11 +11,16 @@ func (suite *KeeperTestSuite) TestInitGenesis() { // build PacketId & Fee refundAcc := suite.chainA.SenderAccount.GetAddress() - ackFee := validCoins - receiveFee := validCoins2 - timeoutFee := validCoins3 - packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} - fee := types.Fee{ackFee, receiveFee, timeoutFee} + packetId := types.NewPacketId( + ibctesting.FirstChannelID, + types.PortID, + uint64(1), + ) + fee := types.Fee{ + validCoins, + validCoins2, + validCoins3, + } // relayer addresses sender := suite.chainA.SenderAccount.GetAddress().String() @@ -69,11 +73,16 @@ func (suite *KeeperTestSuite) TestExportGenesis() { // setup & escrow the packet fee refundAcc := suite.chainA.SenderAccount.GetAddress() - ackFee := validCoins - receiveFee := validCoins2 - timeoutFee := validCoins3 - packetId := &channeltypes.PacketId{ChannelId: ibctesting.FirstChannelID, PortId: types.PortID, Sequence: uint64(1)} - fee := types.Fee{ackFee, receiveFee, timeoutFee} + packetId := types.NewPacketId( + ibctesting.FirstChannelID, + types.PortID, + uint64(1), + ) + fee := types.Fee{ + validCoins, + validCoins2, + validCoins3, + } identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee) suite.Require().NoError(err) diff --git a/modules/apps/29-fee/keeper/grpc_query_test.go b/modules/apps/29-fee/keeper/grpc_query_test.go index 899df77d5bd..1403326837a 100644 --- a/modules/apps/29-fee/keeper/grpc_query_test.go +++ b/modules/apps/29-fee/keeper/grpc_query_test.go @@ -17,8 +17,8 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { ) // setup - validPacketId := types.NewPacketId(ibctesting.FirstChannelID, 1) - invalidPacketId := types.NewPacketId(ibctesting.FirstChannelID, 2) + validPacketId := types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 1) + invalidPacketId := types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 2) identifiedPacketFee := types.NewIdentifiedPacketFee( validPacketId, types.Fee{ @@ -110,9 +110,9 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { func() { refundAcc := suite.chainA.SenderAccount.GetAddress() - fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 1), fee, refundAcc.String(), []string(nil)) - fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 2), fee, refundAcc.String(), []string(nil)) - fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 3), fee, refundAcc.String(), []string(nil)) + fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 1), fee, refundAcc.String(), []string(nil)) + fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 2), fee, refundAcc.String(), []string(nil)) + fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, types.PortID, 3), fee, refundAcc.String(), []string(nil)) expPackets = []*types.IdentifiedPacketFee{} expPackets = append(expPackets, fee1, fee2, fee3) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 8dc7f2371eb..bd04c041bb5 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -171,6 +171,8 @@ func NewIdentifiedPacketFee(packetId *channeltypes.PacketId, fee Fee, refundAddr } } -func NewPacketId(channelId string, id uint64) *channeltypes.PacketId { - return &channeltypes.PacketId{ChannelId: channelId, PortId: PortID, Sequence: id} +// NewPacketId returns a new instance of PacketId +// TODO: move to channeltypes +func NewPacketId(channelId, portId string, seq uint64) *channeltypes.PacketId { + return &channeltypes.PacketId{ChannelId: channelId, PortId: portId, Sequence: seq} }