From 62a68aa8647a81fa62dcd6da1d132a7956ede389 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Thu, 11 Apr 2024 16:05:08 -0500 Subject: [PATCH] Remove Overkill Flushing --- ethereum/listener.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ethereum/listener.go b/ethereum/listener.go index e43b227..0999d3a 100644 --- a/ethereum/listener.go +++ b/ethereum/listener.go @@ -279,16 +279,20 @@ func (e *Ethereum) flushMechanism( case <-timer.C: latestBlock := e.LatestBlock() + // initialize first lastFlushedBlock if not set if e.lastFlushedBlock == 0 { - e.lastFlushedBlock = latestBlock + e.lastFlushedBlock = latestBlock - e.lookbackPeriod } - start := e.lastFlushedBlock - e.lookbackPeriod + // start from lastFlushedBlock + start := e.lastFlushedBlock logger.Info(fmt.Sprintf("Flush started from %d to %d", start, latestBlock)) + // consume from lastFlushedBlock to the latestBlock e.getAndConsumeHistory(ctx, logger, processingQueue, messageSent, messageTransmitterAddress, messageTransmitterABI, start, latestBlock) + // update lastFlushedBlock to the last block it flushed e.lastFlushedBlock = latestBlock logger.Info("Flush complete")