From ce33b4b3fd37c7a074fdaea8f0834d6dd7a26d84 Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Wed, 26 Jun 2024 16:38:50 +0200 Subject: [PATCH] chore: pass only hops to sendTransfer + events rename (#6703) Co-authored-by: Carlos Rodriguez --- modules/apps/transfer/ibc_module_test.go | 15 ++++++--------- .../apps/transfer/internal/events/events.go | 18 +++++++++--------- modules/apps/transfer/keeper/msg_server.go | 2 +- .../apps/transfer/keeper/msg_server_test.go | 4 ++-- modules/apps/transfer/keeper/relay.go | 8 ++++---- modules/apps/transfer/types/events.go | 2 +- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 327009b0ef4..c524bb42cc5 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -307,11 +307,11 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { ) packet.Data = packetData.GetBytes() - forwardingBz, err := json.Marshal(packetData.Forwarding) + forwardingHopsBz, err := json.Marshal(packetData.Forwarding.Hops) suite.Require().NoError(err) for i, attr := range expectedAttributes { - if attr.Key == types.AttributeKeyForwarding { - expectedAttributes[i].Value = string(forwardingBz) + if attr.Key == types.AttributeKeyForwardingHops { + expectedAttributes[i].Value = string(forwardingHopsBz) break } } @@ -325,15 +325,12 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { packet.Data = []byte("invalid data") // Override expected attributes because this fails on unmarshaling packet data (so can't get the attributes) - forwardingBz, err := json.Marshal(types.Forwarding{}) - suite.Require().NoError(err) - expectedAttributes = []sdk.Attribute{ sdk.NewAttribute(types.AttributeKeySender, ""), sdk.NewAttribute(types.AttributeKeyReceiver, ""), sdk.NewAttribute(types.AttributeKeyTokens, "null"), sdk.NewAttribute(types.AttributeKeyMemo, ""), - sdk.NewAttribute(types.AttributeKeyForwarding, string(forwardingBz)), + sdk.NewAttribute(types.AttributeKeyForwardingHops, "null"), sdk.NewAttribute(types.AttributeKeyAckSuccess, "false"), sdk.NewAttribute(types.AttributeKeyAckError, "cannot unmarshal ICS20-V2 transfer packet data: invalid character 'i' looking for beginning of value: invalid type: invalid type"), } @@ -373,7 +370,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { tokensBz, err := json.Marshal(packetData.Tokens) suite.Require().NoError(err) - forwardingBz, err := json.Marshal(packetData.Forwarding) + forwardingHopsBz, err := json.Marshal(packetData.Forwarding.Hops) suite.Require().NoError(err) expectedAttributes = []sdk.Attribute{ @@ -381,7 +378,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() { sdk.NewAttribute(types.AttributeKeyReceiver, packetData.Receiver), sdk.NewAttribute(types.AttributeKeyTokens, string(tokensBz)), sdk.NewAttribute(types.AttributeKeyMemo, packetData.Memo), - sdk.NewAttribute(types.AttributeKeyForwarding, string(forwardingBz)), + sdk.NewAttribute(types.AttributeKeyForwardingHops, string(forwardingHopsBz)), } if tc.expAck == nil || tc.expAck.Success() { expectedAttributes = append(expectedAttributes, sdk.NewAttribute(types.AttributeKeyAckSuccess, "true")) diff --git a/modules/apps/transfer/internal/events/events.go b/modules/apps/transfer/internal/events/events.go index 70556ab5c97..8bcbf49bb6d 100644 --- a/modules/apps/transfer/internal/events/events.go +++ b/modules/apps/transfer/internal/events/events.go @@ -11,9 +11,9 @@ import ( ) // EmitTransferEvent emits a ibc transfer event on successful transfers. -func EmitTransferEvent(ctx sdk.Context, sender, receiver string, tokens types.Tokens, memo string, forwarding types.Forwarding) { +func EmitTransferEvent(ctx sdk.Context, sender, receiver string, tokens types.Tokens, memo string, forwardingHops []types.Hop) { tokensStr := mustMarshalType[types.Tokens](tokens) - forwardingStr := mustMarshalType[types.Forwarding](forwarding) + forwardingHopsStr := mustMarshalType[[]types.Hop](forwardingHops) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -22,7 +22,7 @@ func EmitTransferEvent(ctx sdk.Context, sender, receiver string, tokens types.To sdk.NewAttribute(types.AttributeKeyReceiver, receiver), sdk.NewAttribute(types.AttributeKeyTokens, tokensStr), sdk.NewAttribute(types.AttributeKeyMemo, memo), - sdk.NewAttribute(types.AttributeKeyForwarding, forwardingStr), + sdk.NewAttribute(types.AttributeKeyForwardingHops, forwardingHopsStr), ), sdk.NewEvent( sdk.EventTypeMessage, @@ -34,14 +34,14 @@ func EmitTransferEvent(ctx sdk.Context, sender, receiver string, tokens types.To // EmitOnRecvPacketEvent emits a fungible token packet event in the OnRecvPacket callback func EmitOnRecvPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement, ackErr error) { tokensStr := mustMarshalType[types.Tokens](packetData.Tokens) - forwardingStr := mustMarshalType[types.ForwardingPacketData](packetData.Forwarding) + forwardingHopStr := mustMarshalType[[]types.Hop](packetData.Forwarding.Hops) eventAttributes := []sdk.Attribute{ sdk.NewAttribute(types.AttributeKeySender, packetData.Sender), sdk.NewAttribute(types.AttributeKeyReceiver, packetData.Receiver), sdk.NewAttribute(types.AttributeKeyTokens, tokensStr), sdk.NewAttribute(types.AttributeKeyMemo, packetData.Memo), - sdk.NewAttribute(types.AttributeKeyForwarding, forwardingStr), + sdk.NewAttribute(types.AttributeKeyForwardingHops, forwardingHopStr), sdk.NewAttribute(types.AttributeKeyAckSuccess, strconv.FormatBool(ack.Success())), } @@ -64,7 +64,7 @@ func EmitOnRecvPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacket // EmitOnAcknowledgementPacketEvent emits a fungible token packet event in the OnAcknowledgementPacket callback func EmitOnAcknowledgementPacketEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement) { tokensStr := mustMarshalType[types.Tokens](packetData.Tokens) - forwardingStr := mustMarshalType[types.ForwardingPacketData](packetData.Forwarding) + forwardingHopsStr := mustMarshalType[[]types.Hop](packetData.Forwarding.Hops) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -73,7 +73,7 @@ func EmitOnAcknowledgementPacketEvent(ctx sdk.Context, packetData types.Fungible sdk.NewAttribute(types.AttributeKeyReceiver, packetData.Receiver), sdk.NewAttribute(types.AttributeKeyTokens, tokensStr), sdk.NewAttribute(types.AttributeKeyMemo, packetData.Memo), - sdk.NewAttribute(types.AttributeKeyForwarding, forwardingStr), + sdk.NewAttribute(types.AttributeKeyForwardingHops, forwardingHopsStr), sdk.NewAttribute(types.AttributeKeyAck, ack.String()), ), sdk.NewEvent( @@ -103,7 +103,7 @@ func EmitOnAcknowledgementPacketEvent(ctx sdk.Context, packetData types.Fungible // EmitOnTimeoutEvent emits a fungible token packet event in the OnTimeoutPacket callback func EmitOnTimeoutEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDataV2) { tokensStr := mustMarshalType[types.Tokens](packetData.Tokens) - forwardingStr := mustMarshalType[types.ForwardingPacketData](packetData.Forwarding) + forwardingHopsStr := mustMarshalType[[]types.Hop](packetData.Forwarding.Hops) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -111,7 +111,7 @@ func EmitOnTimeoutEvent(ctx sdk.Context, packetData types.FungibleTokenPacketDat sdk.NewAttribute(types.AttributeKeyReceiver, packetData.Sender), sdk.NewAttribute(types.AttributeKeyRefundTokens, tokensStr), sdk.NewAttribute(types.AttributeKeyMemo, packetData.Memo), - sdk.NewAttribute(types.AttributeKeyForwarding, forwardingStr), + sdk.NewAttribute(types.AttributeKeyForwardingHops, forwardingHopsStr), ), sdk.NewEvent( sdk.EventTypeMessage, diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 55202574157..689b44084d5 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -45,7 +45,7 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. sequence, err := k.sendTransfer( ctx, msg.SourcePort, msg.SourceChannel, coins, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, - msg.Memo, msg.Forwarding) + msg.Memo, msg.Forwarding.Hops) if err != nil { return nil, err } diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 95e1734d209..0d17738263e 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -153,7 +153,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { tokensBz, err := json.Marshal(types.Tokens(tokens)) suite.Require().NoError(err) - forwardingBz, err := json.Marshal(msg.Forwarding) + forwardingHopsBz, err := json.Marshal(msg.Forwarding.Hops) suite.Require().NoError(err) res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(ctx, msg) @@ -168,7 +168,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { sdk.NewAttribute(types.AttributeKeyReceiver, msg.Receiver), sdk.NewAttribute(types.AttributeKeyTokens, string(tokensBz)), sdk.NewAttribute(types.AttributeKeyMemo, msg.Memo), - sdk.NewAttribute(types.AttributeKeyForwarding, string(forwardingBz)), + sdk.NewAttribute(types.AttributeKeyForwardingHops, string(forwardingHopsBz)), ), sdk.NewEvent( sdk.EventTypeMessage, diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 6c9d67c041b..a4712c12f58 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -64,7 +64,7 @@ func (k Keeper) sendTransfer( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, memo string, - forwarding types.Forwarding, + hops []types.Hop, ) (uint64, error) { channel, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { @@ -83,7 +83,7 @@ func (k Keeper) sendTransfer( } // ics20-1 does not support forwarding, so if that is the current version, we must reject the transfer. - if len(forwarding.Hops) > 0 { + if len(hops) > 0 { return 0, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "cannot forward coins with %s", types.V1) } } @@ -147,7 +147,7 @@ func (k Keeper) sendTransfer( tokens = append(tokens, token) } - packetDataBytes, err := createPacketDataBytesFromVersion(appVersion, sender.String(), receiver, memo, tokens, forwarding.Hops) + packetDataBytes, err := createPacketDataBytesFromVersion(appVersion, sender.String(), receiver, memo, tokens, hops) if err != nil { return 0, err } @@ -157,7 +157,7 @@ func (k Keeper) sendTransfer( return 0, err } - events.EmitTransferEvent(ctx, sender.String(), receiver, tokens, memo, forwarding) + events.EmitTransferEvent(ctx, sender.String(), receiver, tokens, memo, hops) defer internaltelemetry.ReportTransferTelemetry(tokens, labels) diff --git a/modules/apps/transfer/types/events.go b/modules/apps/transfer/types/events.go index 90f2137d11f..f5ad7210431 100644 --- a/modules/apps/transfer/types/events.go +++ b/modules/apps/transfer/types/events.go @@ -19,5 +19,5 @@ const ( AttributeKeyAck = "acknowledgement" AttributeKeyAckError = "error" AttributeKeyMemo = "memo" - AttributeKeyForwarding = "forwarding" + AttributeKeyForwardingHops = "forwarding_hops" )