Skip to content

Commit

Permalink
do not poll more than the configured amount when filling gaps (#123)
Browse files Browse the repository at this point in the history
### TL;DR
Added a limit to the number of blocks that can be polled when handling gaps in block sequences.

### What changed?
- Added a check to limit the number of missing blocks to poll based on the poller's `blocksPerPoll` configuration
- Reordered logging statements for better clarity
- Added debug logging to indicate when block polling is limited due to configuration

### How to test?
1. Configure a low `blocksPerPoll` value
2. Create a scenario with a large gap between expected and actual block numbers
3. Verify that the number of polled blocks is capped at the configured `blocksPerPoll` value
4. Check debug logs to confirm the limitation message appears

### Why make this change?
To prevent potential performance issues and resource exhaustion when handling large gaps in block sequences. This change ensures the system maintains stability by limiting the number of blocks that can be polled in a single operation.
  • Loading branch information
iuwqyir authored Dec 6, 2024
2 parents c5c27eb + 69139c0 commit cdb050b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/orchestrator/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,20 @@ func (c *Committer) handleGap(expectedStartBlockNumber *big.Int, actualFirstBloc
// record the first missed block number in prometheus
metrics.MissedBlockNumbers.Set(float64(expectedStartBlockNumber.Int64()))

poller := NewBoundlessPoller(c.rpc, c.storage)

missingBlockCount := new(big.Int).Sub(actualFirstBlock.Number, expectedStartBlockNumber).Int64()
log.Debug().Msgf("Detected %d missing blocks between blocks %s and %s", missingBlockCount, expectedStartBlockNumber.String(), actualFirstBlock.Number.String())
if missingBlockCount > poller.blocksPerPoll {
log.Debug().Msgf("Limiting polling missing blocks to %d blocks due to config", poller.blocksPerPoll)
missingBlockCount = poller.blocksPerPoll
}
missingBlockNumbers := make([]*big.Int, missingBlockCount)
for i := int64(0); i < missingBlockCount; i++ {
missingBlockNumber := new(big.Int).Add(expectedStartBlockNumber, big.NewInt(i))
missingBlockNumbers[i] = missingBlockNumber
}
log.Debug().Msgf("Detected %d missing blocks between blocks %s and %s", missingBlockCount, expectedStartBlockNumber.String(), actualFirstBlock.Number.String())

poller := NewBoundlessPoller(c.rpc, c.storage)
log.Debug().Msgf("Polling %d blocks while handling gap: %v", len(missingBlockNumbers), missingBlockNumbers)
poller.Poll(missingBlockNumbers)
return fmt.Errorf("first block number (%s) in commit batch does not match expected (%s)", actualFirstBlock.Number.String(), expectedStartBlockNumber.String())
Expand Down

0 comments on commit cdb050b

Please sign in to comment.