Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: pass only hops to sendTransfer and events #6703

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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"),
}
Expand Down Expand Up @@ -373,15 +370,15 @@ 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{
sdk.NewAttribute(types.AttributeKeySender, packetData.Sender),
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"))
Expand Down
18 changes: 9 additions & 9 deletions modules/apps/transfer/internal/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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())),
}

Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -103,15 +103,15 @@ 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(
types.EventTypeTimeout,
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,
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ const (
AttributeKeyAck = "acknowledgement"
AttributeKeyAckError = "error"
AttributeKeyMemo = "memo"
AttributeKeyForwarding = "forwarding"
AttributeKeyForwardingHops = "forwarding_hops"
)
Loading