@@ -16,7 +16,6 @@ import (
1616 "github.com/cosmos/cosmos-sdk/codec"
1717 "github.com/cosmos/cosmos-sdk/telemetry"
1818 sdk "github.com/cosmos/cosmos-sdk/types"
19- "github.com/cosmos/cosmos-sdk/types/bech32"
2019 sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
2120
2221 "github.com/cosmos/ibc-go/v11/modules/apps/packet-forward-middleware/types"
@@ -94,69 +93,6 @@ func (*Keeper) Logger(ctx sdk.Context) log.Logger {
9493 return ctx .Logger ().With ("module" , "x/" + ibcexported .ModuleName + "-" + types .ModuleName )
9594}
9695
97- // moveFundsToUserRecoverableAccount will move the funds from the escrow account to the user recoverable account
98- // this is only used when the maximum timeouts have been reached or there is an acknowledgement error and the packet is nonrefundable,
99- // i.e. an operation has occurred to make the original packet funds inaccessible to the user, e.g. a swap.
100- // We cannot refund the funds back to the original chain, so we move them to an account on this chain that the user can access.
101- func (k * Keeper ) moveFundsToUserRecoverableAccount (ctx sdk.Context , packet channeltypes.Packet , token transfertypes.Token , inFlightPacket * types.InFlightPacket ) error {
102- amount , ok := sdkmath .NewIntFromString (token .GetAmount ())
103- if ! ok {
104- return fmt .Errorf ("failed to parse amount from packet data for forward recovery: %s" , token .GetAmount ())
105- }
106- denom := token .GetDenom ()
107- coin := sdk .NewCoin (denom .IBCDenom (), amount )
108-
109- userAccount , err := k .userRecoverableAccount (inFlightPacket )
110- if err != nil {
111- return fmt .Errorf ("failed to get user recoverable account: %w" , err )
112- }
113-
114- if ! denom .HasPrefix (packet .SourcePort , packet .SourceChannel ) {
115- // mint vouchers back to sender
116- if err := k .bankKeeper .MintCoins (ctx , transfertypes .ModuleName , sdk .NewCoins (coin )); err != nil {
117- return err
118- }
119-
120- if err := k .bankKeeper .SendCoinsFromModuleToAccount (ctx , transfertypes .ModuleName , userAccount , sdk .NewCoins (coin )); err != nil {
121- panic (fmt .Sprintf ("unable to send coins from module to account despite previously minting coins to module account: %v" , err ))
122- }
123- return nil
124- }
125-
126- escrowAddress := transfertypes .GetEscrowAddress (packet .SourcePort , packet .SourceChannel )
127-
128- if err := k .bankKeeper .SendCoins (ctx , escrowAddress , userAccount , sdk .NewCoins (coin )); err != nil {
129- return fmt .Errorf ("failed to send coins from escrow account to user recoverable account: %w" , err )
130- }
131-
132- // update the total escrow amount for the denom.
133- k .unescrowToken (ctx , coin )
134-
135- return nil
136- }
137-
138- // userRecoverableAccount finds an account on this chain that the original sender of the packet can recover funds from.
139- // If the destination receiver of the original packet is a valid bech32 address for this chain, we use that address.
140- // Otherwise, if the sender of the original packet is a valid bech32 address for another chain, we translate that address to this chain.
141- // Note that for the fallback, the coin type of the source chain sender account must be compatible with this chain.
142- func (k * Keeper ) userRecoverableAccount (inFlightPacket * types.InFlightPacket ) (sdk.AccAddress , error ) {
143- var originalData transfertypes.FungibleTokenPacketData
144- err := transfertypes .ModuleCdc .UnmarshalJSON (inFlightPacket .PacketData , & originalData )
145- if err == nil { // if NO error
146- sender , err := k .addressCodec .StringToBytes (originalData .Receiver )
147- if err == nil { // if NO error
148- return sender , nil
149- }
150- }
151-
152- _ , sender , fallbackErr := bech32 .DecodeAndConvert (inFlightPacket .OriginalSenderAddress )
153- if fallbackErr == nil { // if NO error
154- return sender , nil
155- }
156-
157- return nil , fmt .Errorf ("failed to decode bech32 addresses: %w" , errors .Join (err , fallbackErr ))
158- }
159-
16096func (k * Keeper ) WriteAcknowledgementForForwardedPacket (ctx sdk.Context , packet channeltypes.Packet , transferDetail transfertypes.InternalTransferRepresentation , inFlightPacket * types.InFlightPacket , ack channeltypes.Acknowledgement ) error {
16197 // Lookup module by channel capability
16298 _ , found := k .channelKeeper .GetChannel (ctx , inFlightPacket .RefundPortId , inFlightPacket .RefundChannelId )
@@ -172,21 +108,6 @@ func (k *Keeper) WriteAcknowledgementForForwardedPacket(ctx sdk.Context, packet
172108 // On an ack error or timeout on a forwarded packet, the funds in the escrow account
173109 // should be moved to the other escrow account on the other side or burned.
174110
175- // If this packet is non-refundable due to some action that took place between the initial ibc transfer and the forward
176- // we write a successful ack containing details on what happened regardless of ack error or timeout
177- if inFlightPacket .Nonrefundable {
178- // We are not allowed to refund back to the source chain.
179- // attempt to move funds to user recoverable account on this chain.
180- if err := k .moveFundsToUserRecoverableAccount (ctx , packet , transferDetail .Token , inFlightPacket ); err != nil {
181- return err
182- }
183-
184- ackResult := fmt .Sprintf ("packet forward failed after point of no return: %s" , ack .GetError ())
185- newAck := channeltypes .NewResultAcknowledgement ([]byte (ackResult ))
186-
187- return k .ics4Wrapper .WriteAcknowledgement (ctx , inFlightPacket .ChannelPacket (), newAck )
188- }
189-
190111 amount , ok := sdkmath .NewIntFromString (transferDetail .Token .GetAmount ())
191112 if ! ok {
192113 return fmt .Errorf ("failed to parse amount from packet data for forward refund: %s" , transferDetail .Token .GetAmount ())
@@ -252,7 +173,7 @@ func (k *Keeper) unescrowToken(ctx sdk.Context, token sdk.Coin) {
252173 k .transferKeeper .SetTotalEscrowForDenom (ctx , newTotalEscrow )
253174}
254175
255- func (k * Keeper ) ForwardTransferPacket (ctx sdk.Context , inFlightPacket * types.InFlightPacket , srcPacket channeltypes.Packet , srcPacketSender , receiver string , metadata types.ForwardMetadata , token sdk.Coin , maxRetries uint8 , timeoutDelta time.Duration , labels []metrics.Label , nonrefundable bool ) error {
176+ func (k * Keeper ) ForwardTransferPacket (ctx sdk.Context , inFlightPacket * types.InFlightPacket , srcPacket channeltypes.Packet , srcPacketSender , receiver string , metadata types.ForwardMetadata , token sdk.Coin , maxRetries uint8 , timeoutDelta time.Duration , labels []metrics.Label ) error {
256177 memo := ""
257178
258179 // set memo for next transfer with next from this transfer.
@@ -308,7 +229,6 @@ func (k *Keeper) ForwardTransferPacket(ctx sdk.Context, inFlightPacket *types.In
308229
309230 RetriesRemaining : int32 (maxRetries ),
310231 Timeout : uint64 (timeoutDelta .Nanoseconds ()),
311- Nonrefundable : nonrefundable ,
312232 }
313233 } else {
314234 inFlightPacket .RetriesRemaining --
@@ -390,7 +310,7 @@ func (k *Keeper) RetryTimeout(ctx sdk.Context, channel, port string, transferDet
390310 token := sdk .NewCoin (ibcDenom , amount )
391311
392312 // srcPacket and srcPacketSender are empty because inFlightPacket is non-nil.
393- return k .ForwardTransferPacket (ctx , inFlightPacket , channeltypes.Packet {}, "" , transferDetail .Sender , metadata , token , uint8 (inFlightPacket .RetriesRemaining ), time .Duration (inFlightPacket .Timeout )* time .Nanosecond , nil , inFlightPacket . Nonrefundable )
313+ return k .ForwardTransferPacket (ctx , inFlightPacket , channeltypes.Packet {}, "" , transferDetail .Sender , metadata , token , uint8 (inFlightPacket .RetriesRemaining ), time .Duration (inFlightPacket .Timeout )* time .Nanosecond , nil )
394314}
395315
396316func (k * Keeper ) SetInflightPacket (ctx sdk.Context , channel , port string , sequence uint64 , packet * types.InFlightPacket ) error {
0 commit comments