From 707c330f2cb518f0d777ddc68ac0db74a16e4329 Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:35:57 -0700 Subject: [PATCH] Fix error handling logic --- core/chains/evm/logpoller/log_poller.go | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/core/chains/evm/logpoller/log_poller.go b/core/chains/evm/logpoller/log_poller.go index d2607b23e08..ad30429c195 100644 --- a/core/chains/evm/logpoller/log_poller.go +++ b/core/chains/evm/logpoller/log_poller.go @@ -659,17 +659,13 @@ func (lp *logPoller) backgroundWorkerRun() { case <-logPruneTick: lp.lggr.Infof("Pruning LogPoller logs...") logPruneTick = time.After(utils.WithJitter(lp.pollPeriod * 2401)) // = 7^5 avoids common factors with 1000 - allRemoved, err := lp.PruneExpiredLogs(ctx) - if allRemoved { + if lp.PruneExpiredLogs(ctx) { lp.lggr.Infof("Finished pruning LogPoller logs. Next pruning in ~ %s", lp.pollPeriod*2401) } else { // Tick faster when cleanup can't keep up with the pace of new logs logPruneTick = time.After(utils.WithJitter(lp.pollPeriod * 241)) lp.lggr.Warnf("Partially finished pruning LogPoller logs. Will resume in ~ %s", lp.pollPeriod*241) } - if err != nil { - lp.lggr.Errorw("Unable to prune expired logs", "err", err) - } } } } @@ -1096,14 +1092,26 @@ func (lp *logPoller) PruneOldBlocks(ctx context.Context) (bool, error) { } // PruneExpiredLogs logs that are older than their retention period defined in Filter. -// Returns whether all logs eligible for pruning were removed. If logPrunePageSize is set to 0, it will always return true. -func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (bool, error) { +// Returns whether all logs eligible for pruning were removed. If logPrunePageSize is set to 0, it can only +// return false if an actual error is encountered +func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (done bool) { + done = true + rowsRemoved, err := lp.orm.DeleteExpiredLogs(ctx, lp.logPrunePageSize) - if err != nil || rowsRemoved < lp.logPrunePageSize { - return true, err + if err != nil { + lp.lggr.Errorw("Unable to prune expired logs", "err", err) + done = false + } else if lp.logPrunePageSize != 0 && rowsRemoved < lp.logPrunePageSize { + done = false } + rowsRemoved, err = lp.orm.DeleteExcessLogs(ctx, lp.logPrunePageSize) - return lp.logPrunePageSize == 0 || err != nil || rowsRemoved < lp.logPrunePageSize, err + if err != nil { + lp.lggr.Errorw("Unable to prune excess logs", "err", err) + } else if lp.logPrunePageSize != 0 && rowsRemoved < lp.logPrunePageSize { + done = false + } + return done } // Logs returns logs matching topics and address (exactly) in the given block range,