From ea7a7d474ac928ba04caa3d0602e9023080f4a62 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Wed, 1 May 2024 16:06:17 -0500 Subject: [PATCH] Check bounds --- ethereum/listener.go | 8 ++++++-- noble/listener.go | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ethereum/listener.go b/ethereum/listener.go index 759420a..346f3a8 100644 --- a/ethereum/listener.go +++ b/ethereum/listener.go @@ -291,7 +291,11 @@ func (e *Ethereum) flushMechanism( // initialize first lastFlushedBlock if not set if e.lastFlushedBlock == 0 { - e.lastFlushedBlock = latestBlock - (2 * e.lookbackPeriod) + e.lastFlushedBlock = latestBlock - 2*e.lookbackPeriod + + if latestBlock < e.lookbackPeriod { + e.lastFlushedBlock = 0 + } } // start from the last block it flushed @@ -307,7 +311,7 @@ func (e *Ethereum) flushMechanism( logger.Info(fmt.Sprintf("Flush started from %d to %d (current height: %d, lookback period: %d)", startBlock, finishBlock, latestBlock, e.lookbackPeriod)) - // consume from lastFlushedBlock to the latestBlock + // consume from lastFlushedBlock to the finishBlock e.getAndConsumeHistory(ctx, logger, processingQueue, messageSent, messageTransmitterAddress, messageTransmitterABI, startBlock, finishBlock) // update lastFlushedBlock to the last block it flushed diff --git a/noble/listener.go b/noble/listener.go index 6005d27..7c4830c 100644 --- a/noble/listener.go +++ b/noble/listener.go @@ -158,6 +158,10 @@ func (n *Noble) flushMechanism( // initialize first lastFlushedBlock if not set if n.lastFlushedBlock == 0 { n.lastFlushedBlock = latestBlock - (2 * n.lookbackPeriod) + + if latestBlock < n.lookbackPeriod { + n.lastFlushedBlock = 0 + } } // start from the last block it flushed