Skip to content

Commit 9c01c54

Browse files
committed
minor fixes
1 parent 5c5ae91 commit 9c01c54

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

internal/committer/reorg.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func InitReorg() {
1616
}
1717

1818
func RunReorgValidator() {
19+
lastBlockCheck := int64(0)
1920
for {
2021
startBlock, endBlock, err := getReorgRange()
2122
if err != nil {
@@ -24,13 +25,20 @@ func RunReorgValidator() {
2425
continue
2526
}
2627

28+
if endBlock == lastBlockCheck || endBlock-startBlock < 5 {
29+
log.Debug().Msg("Not enough new blocks to check. Sleeping for 1 minute.")
30+
time.Sleep(1 * time.Minute)
31+
continue
32+
}
33+
2734
// Detect reorgs and handle them
2835
err = detectAndHandleReorgs(startBlock, endBlock)
2936
if err != nil {
3037
log.Error().Err(err).Msg("Failed to detect and handle reorgs")
3138
time.Sleep(2 * time.Second)
3239
continue
3340
}
41+
lastBlockCheck = endBlock
3442
}
3543
}
3644

@@ -40,7 +48,7 @@ func getReorgRange() (int64, int64, error) {
4048
return 0, 0, fmt.Errorf("failed to get last valid block: %w", err)
4149
}
4250

43-
startBlock := min(lastValidBlock-1, 1)
51+
startBlock := max(lastValidBlock-1, 1)
4452
endBlock, err := libs.GetMaxBlockNumberFromClickHouseV2(libs.ChainId)
4553
if err != nil {
4654
return 0, 0, fmt.Errorf("failed to get max block number: %w", err)

internal/libs/libblockdata/getblockdata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func GetValidBlockDataInBatch(latestBlock uint64, nextCommitBlockNumber uint64)
2121
maxBlocksPerFetch := rpcBatchSize * rpcNumParallelCalls
2222

2323
// Calculate the range of blocks to fetch
24-
blocksToFetch := latestBlock - nextCommitBlockNumber
24+
blocksToFetch := latestBlock - nextCommitBlockNumber + 1
2525
if blocksToFetch > maxBlocksPerFetch {
2626
blocksToFetch = maxBlocksPerFetch
2727
}

0 commit comments

Comments
 (0)