From d43fd0ad3236928b782e143437e4f4f69c514b31 Mon Sep 17 00:00:00 2001 From: Sean King Date: Mon, 11 Apr 2022 14:46:28 +0200 Subject: [PATCH] refactor: moving fn definition to bottom of file and switching params (#1232) ## Description closes: #868 #997 --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x//spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes --- CHANGELOG.md | 2 +- modules/apps/29-fee/client/cli/query.go | 6 ++--- modules/apps/29-fee/client/cli/tx.go | 2 +- modules/apps/29-fee/ibc_module.go | 6 ++--- modules/apps/29-fee/ibc_module_test.go | 22 ++++++++--------- modules/apps/29-fee/keeper/escrow_test.go | 12 +++++----- modules/apps/29-fee/keeper/genesis_test.go | 4 ++-- modules/apps/29-fee/keeper/grpc_query_test.go | 24 +++++++++---------- modules/apps/29-fee/keeper/keeper_test.go | 4 ++-- modules/apps/29-fee/keeper/msg_server.go | 2 +- modules/apps/29-fee/keeper/msg_server_test.go | 2 +- modules/apps/29-fee/keeper/relay.go | 2 +- modules/apps/29-fee/keeper/relay_test.go | 4 ++-- modules/apps/29-fee/types/genesis_test.go | 8 +++---- modules/apps/29-fee/types/keys.go | 4 ++-- modules/apps/29-fee/types/keys_test.go | 2 +- modules/apps/29-fee/types/msgs_test.go | 6 ++--- modules/core/04-channel/types/packet.go | 10 ++++---- 18 files changed, 61 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b1f9271632..88886e3254e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,8 +43,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking ### Improvements - * (modules/core/04-channel) [\#1160](https://github.com/cosmos/ibc-go/pull/1160) Improve `uint64 -> string` performance in `Logger`. +* (modules/core/04-channel) [\#1232](https://github.com/cosmos/ibc-go/pull/1232) Updating params on `NewPacketId` and moving to bottom of file. ### Features * (modules/apps/29-fee) [\#1230](https://github.com/cosmos/ibc-go/pull/1230) Adding CLI command for getting incentivized packets for a specific channel-id. diff --git a/modules/apps/29-fee/client/cli/query.go b/modules/apps/29-fee/client/cli/query.go index 22ad1378309..a183c8f89d3 100644 --- a/modules/apps/29-fee/client/cli/query.go +++ b/modules/apps/29-fee/client/cli/query.go @@ -120,7 +120,7 @@ func GetCmdTotalRecvFees() *cobra.Command { return err } - packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetID := channeltypes.NewPacketId(portID, channelID, seq) if err := packetID.Validate(); err != nil { return err @@ -166,7 +166,7 @@ func GetCmdTotalAckFees() *cobra.Command { return err } - packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetID := channeltypes.NewPacketId(portID, channelID, seq) if err := packetID.Validate(); err != nil { return err @@ -212,7 +212,7 @@ func GetCmdTotalTimeoutFees() *cobra.Command { return err } - packetID := channeltypes.NewPacketId(channelID, portID, seq) + packetID := channeltypes.NewPacketId(portID, channelID, seq) if err := packetID.Validate(); err != nil { return err diff --git a/modules/apps/29-fee/client/cli/tx.go b/modules/apps/29-fee/client/cli/tx.go index 0a4436b0bc4..f1f858b60cd 100644 --- a/modules/apps/29-fee/client/cli/tx.go +++ b/modules/apps/29-fee/client/cli/tx.go @@ -45,7 +45,7 @@ func NewPayPacketFeeAsyncTxCmd() *cobra.Command { return err } - packetID := channeltypes.NewPacketId(args[1], args[0], seq) + packetID := channeltypes.NewPacketId(args[0], args[1], seq) recvFeeStr, err := cmd.Flags().GetString(flagRecvFee) if err != nil { diff --git a/modules/apps/29-fee/ibc_module.go b/modules/apps/29-fee/ibc_module.go index e4dab034b04..192193e07cc 100644 --- a/modules/apps/29-fee/ibc_module.go +++ b/modules/apps/29-fee/ibc_module.go @@ -204,7 +204,7 @@ func (im IBCModule) OnRecvPacket( // incase of async aknowledgement (ack == nil) store the relayer address for use later during async WriteAcknowledgement if ack == nil { - im.keeper.SetRelayerAddressForAsyncAck(ctx, channeltypes.NewPacketId(packet.GetDestChannel(), packet.GetDestPort(), packet.GetSequence()), relayer.String()) + im.keeper.SetRelayerAddressForAsyncAck(ctx, channeltypes.NewPacketId(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()), relayer.String()) return nil } @@ -231,7 +231,7 @@ func (im IBCModule) OnAcknowledgementPacket( return sdkerrors.Wrapf(err, "cannot unmarshal ICS-29 incentivized packet acknowledgement: %v", ack) } - packetID := channeltypes.NewPacketId(packet.SourceChannel, packet.SourcePort, packet.Sequence) + packetID := channeltypes.NewPacketId(packet.SourcePort, packet.SourceChannel, packet.Sequence) feesInEscrow, found := im.keeper.GetFeesInEscrow(ctx, packetID) if found { im.keeper.DistributePacketFees(ctx, ack.ForwardRelayerAddress, relayer, feesInEscrow.PacketFees) @@ -255,7 +255,7 @@ func (im IBCModule) OnTimeoutPacket( return im.app.OnTimeoutPacket(ctx, packet, relayer) } - packetID := channeltypes.NewPacketId(packet.SourceChannel, packet.SourcePort, packet.Sequence) + packetID := channeltypes.NewPacketId(packet.SourcePort, packet.SourceChannel, packet.Sequence) feesInEscrow, found := im.keeper.GetFeesInEscrow(ctx, packetID) if found { im.keeper.DistributePacketFeesOnTimeout(ctx, relayer, feesInEscrow.PacketFees) diff --git a/modules/apps/29-fee/ibc_module_test.go b/modules/apps/29-fee/ibc_module_test.go index fb2bd8ecf01..f2c56576a79 100644 --- a/modules/apps/29-fee/ibc_module_test.go +++ b/modules/apps/29-fee/ibc_module_test.go @@ -302,8 +302,8 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() { "success", func(suite *FeeTestSuite) { packetID := channeltypes.NewPacketId( - suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, + suite.path.EndpointA.ChannelID, 1, ) refundAcc := suite.chainA.SenderAccount.GetAddress() @@ -316,11 +316,11 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() { { "module account balance insufficient", func(suite *FeeTestSuite) { - packetID := channeltypes.PacketId{ - PortId: suite.path.EndpointA.ChannelConfig.PortID, - ChannelId: suite.path.EndpointA.ChannelID, - Sequence: 1, - } + packetID := channeltypes.NewPacketId( + suite.path.EndpointA.ChannelConfig.PortID, + suite.path.EndpointA.ChannelID, + 1, + ) refundAcc := suite.chainA.SenderAccount.GetAddress() packetFee := types.NewPacketFee(types.Fee{validCoins, validCoins2, validCoins3}, refundAcc.String(), []string{}) err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) @@ -537,7 +537,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() { case tc.forwardRelayer && result == nil: suite.Require().Equal(nil, result) - packetID := channeltypes.NewPacketId(packet.GetDestChannel(), packet.GetDestPort(), packet.GetSequence()) + packetID := channeltypes.NewPacketId(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) // retrieve the forward relayer that was stored in `onRecvPacket` relayer, _ := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), packetID) @@ -580,7 +580,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { { "no op success without a packet fee", func() { - packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, suite.chainA.SenderAccount.GetSequence()) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, suite.chainA.SenderAccount.GetSequence()) suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeesInEscrow(suite.chainA.GetContext(), packetID) ack = types.IncentivizedAcknowledgement{ @@ -645,7 +645,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() { suite.Require().True(ok) // escrow the packet fee - packetID := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()) + packetID := channeltypes.NewPacketId(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) packetFee = types.NewPacketFee( types.Fee{ RecvFee: validCoins, @@ -728,7 +728,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { "no op if identified packet fee doesn't exist", func() { // delete packet fee - packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, suite.chainA.SenderAccount.GetSequence()) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, suite.chainA.SenderAccount.GetSequence()) suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeesInEscrow(suite.chainA.GetContext(), packetID) expectedBalance = originalBalance @@ -762,7 +762,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module) suite.Require().True(ok) - packetID := channeltypes.NewPacketId(packet.GetSourceChannel(), packet.GetSourcePort(), packet.GetSequence()) + packetID := channeltypes.NewPacketId(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) // must be explicitly changed relayerAddr = suite.chainB.SenderAccount.GetAddress() diff --git a/modules/apps/29-fee/keeper/escrow_test.go b/modules/apps/29-fee/keeper/escrow_test.go index 2f6b2fe62b1..0b9e3045542 100644 --- a/modules/apps/29-fee/keeper/escrow_test.go +++ b/modules/apps/29-fee/keeper/escrow_test.go @@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() { receiveFee = defaultReceiveFee ackFee = defaultAckFee timeoutFee = defaultTimeoutFee - packetID = channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, uint64(1)) + packetID = channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, uint64(1)) tc.malleate() fee := types.Fee{ @@ -161,7 +161,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() { reverseRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) forwardRelayer = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() - packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, validSeq) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, validSeq) fee := types.Fee{ RecvFee: defaultReceiveFee, AckFee: defaultAckFee, @@ -221,8 +221,8 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { timeoutRelayer := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) packetID := channeltypes.NewPacketId( - suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, + suite.path.EndpointA.ChannelID, 1, ) @@ -271,7 +271,7 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() { prevBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), refundAcc) for i := 0; i < 5; i++ { - packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, uint64(i)) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, uint64(i)) fee := types.Fee{ RecvFee: defaultReceiveFee, AckFee: defaultAckFee, @@ -285,7 +285,7 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() { } // send a packet over a different channel to ensure this fee is not refunded - packetID := channeltypes.NewPacketId("channel-1", ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, "channel-1", 1) fee := types.Fee{ RecvFee: defaultReceiveFee, AckFee: defaultAckFee, @@ -306,7 +306,7 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() { suite.Require().Equal(prevBal, afterBal.Add(fee.RecvFee...).Add(fee.AckFee...).Add(fee.TimeoutFee...), "refund account not back to original balance after refunding all tokens") // create escrow and then change module account balance to cause error on refund - packetID = channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, uint64(6)) + packetID = channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, uint64(6)) packetFee = types.NewPacketFee(fee, refundAcc.String(), []string{}) err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) diff --git a/modules/apps/29-fee/keeper/genesis_test.go b/modules/apps/29-fee/keeper/genesis_test.go index f2824120a82..ec9602d3a4f 100644 --- a/modules/apps/29-fee/keeper/genesis_test.go +++ b/modules/apps/29-fee/keeper/genesis_test.go @@ -9,7 +9,7 @@ import ( func (suite *KeeperTestSuite) TestInitGenesis() { // build PacketId & Fee refundAcc := suite.chainA.SenderAccount.GetAddress() - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.Fee{ RecvFee: defaultReceiveFee, AckFee: defaultAckFee, @@ -71,7 +71,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { // setup & escrow the packet fee refundAcc := suite.chainA.SenderAccount.GetAddress() - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.Fee{ RecvFee: defaultReceiveFee, AckFee: defaultAckFee, diff --git a/modules/apps/29-fee/keeper/grpc_query_test.go b/modules/apps/29-fee/keeper/grpc_query_test.go index 516a31e87b2..446616ab176 100644 --- a/modules/apps/29-fee/keeper/grpc_query_test.go +++ b/modules/apps/29-fee/keeper/grpc_query_test.go @@ -33,7 +33,7 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { for i := 0; i < 3; i++ { // escrow packet fees for three different packets - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, uint64(i+1)) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, uint64(i+1)) suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) expectedPackets = append(expectedPackets, types.NewIdentifiedPacketFees(packetID, []types.PacketFee{packetFee})) @@ -98,7 +98,7 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { "fees not found for packet id", func() { req = &types.QueryIncentivizedPacketRequest{ - PacketId: channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100), + PacketId: channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 100), QueryHeight: 0, } }, @@ -112,7 +112,7 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) @@ -210,9 +210,9 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketsForChannel() { packetFee := types.NewPacketFee(fee, refundAcc.String(), nil) packetFees := types.NewPacketFees([]types.PacketFee{packetFee, packetFee, packetFee}) - identifiedFees1 := types.NewIdentifiedPacketFees(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1), packetFees.PacketFees) - identifiedFees2 := types.NewIdentifiedPacketFees(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 2), packetFees.PacketFees) - identifiedFees3 := types.NewIdentifiedPacketFees(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 3), packetFees.PacketFees) + identifiedFees1 := types.NewIdentifiedPacketFees(channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1), packetFees.PacketFees) + identifiedFees2 := types.NewIdentifiedPacketFees(channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 2), packetFees.PacketFees) + identifiedFees3 := types.NewIdentifiedPacketFees(channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 3), packetFees.PacketFees) expIdentifiedPacketFees = append(expIdentifiedPacketFees, &identifiedFees1, &identifiedFees2, &identifiedFees3) @@ -255,7 +255,7 @@ func (suite *KeeperTestSuite) TestQueryTotalRecvFees() { { "packet not found", func() { - req.PacketId = channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100) + req.PacketId = channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 100) }, false, }, @@ -267,7 +267,7 @@ func (suite *KeeperTestSuite) TestQueryTotalRecvFees() { suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) @@ -319,7 +319,7 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() { { "packet not found", func() { - req.PacketId = channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100) + req.PacketId = channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 100) }, false, }, @@ -331,7 +331,7 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() { suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) @@ -383,7 +383,7 @@ func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() { { "packet not found", func() { - req.PacketId = channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100) + req.PacketId = channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 100) }, false, }, @@ -395,7 +395,7 @@ func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() { suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) diff --git a/modules/apps/29-fee/keeper/keeper_test.go b/modules/apps/29-fee/keeper/keeper_test.go index 1f29a8872d5..29cb19fb8f5 100644 --- a/modules/apps/29-fee/keeper/keeper_test.go +++ b/modules/apps/29-fee/keeper/keeper_test.go @@ -92,7 +92,7 @@ func (suite *KeeperTestSuite) TestFeesInEscrow() { suite.coordinator.Setup(suite.path) // escrow five fees for packet sequence 1 - packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 1) fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) for i := 1; i < 6; i++ { @@ -131,7 +131,7 @@ func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() { // escrow a fee refundAcc := suite.chainA.SenderAccount.GetAddress() - packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 1) fee := types.Fee{ AckFee: defaultAckFee, RecvFee: defaultReceiveFee, diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index fdac1d27874..c9100f9c73e 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -38,8 +38,8 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) } packetID := channeltypes.NewPacketId( - msg.SourceChannelId, msg.SourcePortId, + msg.SourceChannelId, sequence, ) diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 26ce387b60e..7a06af6e30b 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -119,7 +119,7 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() { seq, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(ctxA, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) // build fee - packetID := channeltypes.NewPacketId(channelID, suite.path.EndpointA.ChannelConfig.PortID, seq) + packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, channelID, seq) packetFee := types.NewPacketFee(fee, refundAcc.String(), nil) tc.malleate() diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index a2ef8a7ca11..34c473e2e83 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -23,7 +23,7 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, acknowledgement) } - packetID := channeltypes.NewPacketId(packet.GetDestChannel(), packet.GetDestPort(), packet.GetSequence()) + packetID := channeltypes.NewPacketId(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) // retrieve the forward relayer that was stored in `onRecvPacket` relayer, found := k.GetRelayerAddressForAsyncAck(ctx, packetID) diff --git a/modules/apps/29-fee/keeper/relay_test.go b/modules/apps/29-fee/keeper/relay_test.go index 3cfd627b520..c853babd527 100644 --- a/modules/apps/29-fee/keeper/relay_test.go +++ b/modules/apps/29-fee/keeper/relay_test.go @@ -15,7 +15,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { { "success", func() { - suite.chainB.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointB.ChannelID, suite.path.EndpointB.ChannelConfig.PortID, 1), suite.chainA.SenderAccount.GetAddress().String()) + suite.chainB.GetSimApp().IBCFeeKeeper.SetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, 1), suite.chainA.SenderAccount.GetAddress().String()) suite.chainB.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainB.GetContext(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.path.EndpointB.ChannelID) }, true, @@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { if tc.expPass { suite.Require().NoError(err) - _, found := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1)) + _, found := suite.chainB.GetSimApp().IBCFeeKeeper.GetRelayerAddressForAsyncAck(suite.chainB.GetContext(), channeltypes.NewPacketId(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 1)) suite.Require().False(found) expectedAck := types.NewIncentivizedAcknowledgement(suite.chainB.SenderAccount.GetAddress().String(), ack.Acknowledgement(), ack.Success()) diff --git a/modules/apps/29-fee/types/genesis_test.go b/modules/apps/29-fee/types/genesis_test.go index edcd91c6f9d..d574257e706 100644 --- a/modules/apps/29-fee/types/genesis_test.go +++ b/modules/apps/29-fee/types/genesis_test.go @@ -49,8 +49,8 @@ func TestValidateGenesis(t *testing.T) { "invalid packetID: invalid channel", func() { packetID = channeltypes.NewPacketId( - "", portID, + "", seq, ) }, @@ -60,8 +60,8 @@ func TestValidateGenesis(t *testing.T) { "invalid packetID: invalid port", func() { packetID = channeltypes.NewPacketId( - channelID, "", + channelID, seq, ) }, @@ -71,8 +71,8 @@ func TestValidateGenesis(t *testing.T) { "invalid packetID: invalid sequence", func() { packetID = channeltypes.NewPacketId( - channelID, portID, + channelID, 0, ) }, @@ -195,7 +195,7 @@ func TestValidateGenesis(t *testing.T) { ForwardRelayers: []types.ForwardRelayerAddress{ { Address: forwardAddr, - PacketId: channeltypes.NewPacketId(packetChannelID, portID, 1), + PacketId: channeltypes.NewPacketId(portID, packetChannelID, 1), }, }, } diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index f2dd3458e20..d98dbcdf5a1 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -100,7 +100,7 @@ func ParseKeyForwardRelayerAddress(key string) (channeltypes.PacketId, error) { return channeltypes.PacketId{}, err } - packetID := channeltypes.NewPacketId(keySplit[2], keySplit[1], seq) + packetID := channeltypes.NewPacketId(keySplit[1], keySplit[2], seq) return packetID, nil } @@ -123,7 +123,7 @@ func ParseKeyFeesInEscrow(key string) (channeltypes.PacketId, error) { return channeltypes.PacketId{}, err } - packetID := channeltypes.NewPacketId(keySplit[2], keySplit[1], seq) + packetID := channeltypes.NewPacketId(keySplit[1], keySplit[2], seq) return packetID, nil } diff --git a/modules/apps/29-fee/types/keys_test.go b/modules/apps/29-fee/types/keys_test.go index 518b2d65604..22dc91b6a57 100644 --- a/modules/apps/29-fee/types/keys_test.go +++ b/modules/apps/29-fee/types/keys_test.go @@ -12,7 +12,7 @@ import ( ) var ( - validPacketID = channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + validPacketID = channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) ) func TestKeyCounterpartyRelayer(t *testing.T) { diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 8a7ec915a31..d314a4f4193 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -267,7 +267,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { } for _, tc := range testCases { - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, defaultAccAddress, nil) @@ -287,7 +287,7 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { func TestPayPacketFeeAsyncGetSigners(t *testing.T) { refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, refundAddr.String(), nil) @@ -307,7 +307,7 @@ func TestMsgPayPacketFeeAsyncType(t *testing.T) { } func TestMsgPayPacketFeeAsyncGetSignBytes(t *testing.T) { - packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) + packetID := channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1) fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) packetFee := types.NewPacketFee(fee, defaultAccAddress, nil) diff --git a/modules/core/04-channel/types/packet.go b/modules/core/04-channel/types/packet.go index 1b69dafa758..dd59c8bfde9 100644 --- a/modules/core/04-channel/types/packet.go +++ b/modules/core/04-channel/types/packet.go @@ -12,11 +12,6 @@ import ( "github.com/cosmos/ibc-go/v3/modules/core/exported" ) -// NewPacketId returns a new instance of PacketId -func NewPacketId(channelId, portId string, seq uint64) PacketId { - return PacketId{ChannelId: channelId, PortId: portId, Sequence: seq} -} - // CommitPacket returns the packet commitment bytes. The commitment consists of: // sha256_hash(timeout_timestamp + timeout_height.RevisionNumber + timeout_height.RevisionHeight + sha256_hash(data)) // from a given packet. This results in a fixed length preimage. @@ -133,3 +128,8 @@ func (p PacketId) Validate() error { return nil } + +// NewPacketId returns a new instance of PacketId +func NewPacketId(portId, channelId string, seq uint64) PacketId { + return PacketId{PortId: portId, ChannelId: channelId, Sequence: seq} +}