From daa415326bb00c502fa9029140592759f9740e31 Mon Sep 17 00:00:00 2001 From: j75689 Date: Mon, 15 Jan 2024 12:58:05 +0800 Subject: [PATCH] chore: add logs to refund tokens --- plugins/tokens/plugin.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/tokens/plugin.go b/plugins/tokens/plugin.go index 1a41bf3ab..fd9c14398 100644 --- a/plugins/tokens/plugin.go +++ b/plugins/tokens/plugin.go @@ -65,31 +65,33 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap iterator := timelockKeeper.GetTimeLockRecordIterator(ctx) defer iterator.Close() i := 0 + failedCount := 0 for ; iterator.Valid(); iterator.Next() { - if i >= MaxUnlockItems { - break - } addr, id, err := timelock.ParseKeyRecord(iterator.Key()) if err != nil { logger.Error("failed to parse timelock record", "error", err) + failedCount++ continue } err = timelockKeeper.TimeUnlock(ctx, addr, id, true) if err != nil { logger.Error("failed to unlock the time locks", "error", err) + failedCount++ continue } logger.Info("succeed to unlock the time locks", "addr", addr, "id", id) i++ + if i >= MaxUnlockItems { + break + } } + logger.Info("unlock the time locks done", "blockHeight", ctx.BlockHeight(), "succeed", i, "failed", failedCount) swapIterator := swapKeeper.GetSwapIterator(ctx) defer swapIterator.Close() i = 0 + failedCount = 0 for ; swapIterator.Valid(); swapIterator.Next() { - if i >= MaxUnlockItems { - break - } var automaticSwap swap.AtomicSwap swapKeeper.CDC().MustUnmarshalBinaryBare(swapIterator.Value(), &automaticSwap) swapID := swapIterator.Key()[len(swap.HashKey):] @@ -106,12 +108,17 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap }) if !result.IsOK() { logger.Error("failed to refund swap", "swapId", swapID, "result", fmt.Sprintf("%+v", result)) + failedCount++ continue } logger.Info("succeed to refund swap", "swapId", swapID, "swap", fmt.Sprintf("%+v", swapItem)) i++ + if i >= MaxUnlockItems { + break + } } + logger.Info("refund the swaps done", "blockHeight", ctx.BlockHeight(), "succeed", i, "failed", failedCount) } // EndBreatheBlock processes the breathe block lifecycle event.