From 9027b6ebf1d8645ba160eb118d6ed68c74076150 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Sun, 5 May 2024 23:23:25 +0200 Subject: [PATCH] fix logic --- modules/apps/29-fee/keeper/escrow.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index f1761d4e854..1ebbeb95caa 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -189,9 +189,8 @@ func (k Keeper) RefundFeesOnChannelClosure(ctx sdk.Context, portID, channelID st cacheCtx, writeFn := ctx.CacheContext() for _, identifiedPacketFee := range identifiedPacketFees { - var failedToSendCoins bool var unRefundedFees []types.PacketFee - for i, packetFee := range identifiedPacketFee.PacketFees { + for _, packetFee := range identifiedPacketFee.PacketFees { if !k.EscrowAccountHasBalance(cacheCtx, packetFee.Fee.Total()) { // if the escrow account does not have sufficient funds then there must exist a severe bug @@ -206,23 +205,20 @@ func (k Keeper) RefundFeesOnChannelClosure(ctx sdk.Context, portID, channelID st return nil } - // preemptively store the unrefunded fees in case of failure - unRefundedFees = identifiedPacketFee.PacketFees[i:] - refundAddr, err := sdk.AccAddressFromBech32(packetFee.RefundAddress) if err != nil { - failedToSendCoins = true + unRefundedFees = append(unRefundedFees, packetFee) continue } // refund all fees to refund address if err = k.bankKeeper.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, refundAddr, packetFee.Fee.Total()); err != nil { - failedToSendCoins = true + unRefundedFees = append(unRefundedFees, packetFee) continue } } - if failedToSendCoins { + if len(unRefundedFees) > 0 { // update packet fees to keep only the unrefunded fees packetFees := types.NewPacketFees(unRefundedFees) k.SetFeesInEscrow(cacheCtx, identifiedPacketFee.PacketId, packetFees)