From d6de708786e90f667e2a59996ba388f29a1c4747 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Mon, 10 Jun 2024 19:04:19 +0300 Subject: [PATCH] Use Transfer instead of sendTransfer when forwarding. Pass nil as the next forwarding path if at final hop. Use consistent timeout for all hops. --- modules/apps/transfer/keeper/relay.go | 28 ++++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index ec27e395b92..711f2221391 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "strings" - "time" "github.com/hashicorp/go-metrics" @@ -277,40 +276,37 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // Adding forwarding logic if data.ForwardingPath != nil && len(data.ForwardingPath.Hops) > 0 { memo := "" - var nextForwardingPath types.ForwardingInfo + + var nextForwardingPath *types.ForwardingInfo if len(data.ForwardingPath.Hops) == 1 { memo = data.ForwardingPath.Memo - nextForwardingPath = types.ForwardingInfo{ - Hops: nil, - Memo: data.ForwardingPath.Memo, - } + nextForwardingPath = nil } else { - nextForwardingPath = types.ForwardingInfo{ + nextForwardingPath = &types.ForwardingInfo{ Hops: data.ForwardingPath.Hops[1:], Memo: data.ForwardingPath.Memo, } } - // Assign to timestamp --> current + 1 h - timeoutTimestamp := uint64(ctx.BlockTime().Add(time.Hour).UnixNano()) - sequence, err := k.sendTransfer( - ctx, + msg := types.NewMsgTransfer( data.ForwardingPath.Hops[0].PortId, data.ForwardingPath.Hops[0].ChannelId, receivedCoins, - receiver, + receiver.String(), finalReceiver.String(), - clienttypes.Height{}, - timeoutTimestamp, + packet.TimeoutHeight, + packet.TimeoutTimestamp, memo, - &nextForwardingPath, + nextForwardingPath, ) + + resp, err := k.Transfer(ctx, msg) if err != nil { return false, err } - k.SetForwardedPacket(ctx, data.ForwardingPath.Hops[0].PortId, data.ForwardingPath.Hops[0].ChannelId, sequence, packet) + k.SetForwardedPacket(ctx, data.ForwardingPath.Hops[0].PortId, data.ForwardingPath.Hops[0].ChannelId, resp.Sequence, packet) return true, nil }