You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### TL;DR
Improved reorg detection and handling logic to identify and process all reorged blocks in the current range handled by ReorgHandler.
### What changed?
- Renamed and enhanced the reorg detection function to explicitly find the first hash mismatch
- Added validation for sequential block headers during reorg detection
- Implemented parallel block fetching with chunking for better performance
- Improved error messages and logging for better debugging
- Changed the reorg handling approach to work with specific reorged block numbers instead of a range
- Added sequential block number validation to prevent incorrect reorg detection
### How to test?
1. Run the system during a chain reorganization event
2. Verify that reorged blocks are correctly identified and processed
3. Check logs for detailed reorg detection information
4. Monitor metrics to confirm reorg counter increments appropriately
5. Verify parallel block fetching works with different chunk sizes
### Why make this change?
The previous implementation had potential gaps in reorg detection and could miss some edge cases. This update provides more robust and efficient reorg handling, with improved error detection and parallel processing capabilities. The changes also make the system more maintainable and easier to debug when issues occur.
log.Debug().Msgf("Reorg was detected, but no reorged block numbers found, most recent block number checked: %s", mostRecentBlockHeader.Number.String())
131
+
returnmostRecentBlockHeader.Number, nil
118
132
}
119
-
reorgEndBlock:=blockHeaders[reorgEndIndex].Number
120
-
err=rh.handleReorg(forkPoint, reorgEndBlock)
133
+
134
+
err=rh.handleReorg(reorgedBlockNumbers)
121
135
iferr!=nil {
122
136
returnnil, fmt.Errorf("error while handling reorg: %w", err)
return-1, fmt.Errorf("block headers are not sequential - cannot proceed with detecting reorgs. Comparing blocks: %s and %s", currentBlock.Number.String(), previousBlockInChain.Number.String())
nextHeadersBatch, err:=rh.storage.MainStorage.GetBlockHeadersDescending(rh.rpc.GetChainID(), fetchFromBlock, new(big.Int).Sub(fetchUntilBlock, big.NewInt(1))) // we sub 1 to not check the last block again
181
+
iferr!=nil {
182
+
returnfmt.Errorf("error getting next headers batch: %w", err)
0 commit comments