Skip to content

Commit

Permalink
Check bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed May 1, 2024
1 parent ff1375f commit ea7a7d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ethereum/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions noble/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea7a7d4

Please sign in to comment.