feat: multidownloader reorg + integration l1infotree#1462
feat: multidownloader reorg + integration l1infotree#1462joanestebanr wants to merge 75 commits intodevelopfrom
Conversation
507d2fe to
a4578b3
Compare
There was a problem hiding this comment.
Pull request overview
This pull request implements comprehensive reorganization handling and unsafe sync capabilities for the multidownloader component. The PR introduces new data structures and logic for detecting and processing blockchain reorganizations, separates synced data into finalized (safe) and non-finalized (unsafe) categories, and adds state management to track sync progress.
Changes:
- Introduces reorg detection and processing infrastructure with new types (ReorgError, ReorgData, ReorgProcessor)
- Implements unsafe sync mode that downloads non-finalized blocks with reorg checking
- Adds comprehensive state management to separate synced and pending segments
- Refactors storage layer with new tables for tracking reorged blocks and logs
Reviewed changes
Copilot reviewed 48 out of 48 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| types/map_block_header.go | New type for mapping block numbers to headers |
| types/list_block_header.go | New type for list of block headers with helper methods |
| types/block_header.go | Added Empty() method to check if block header is empty |
| multidownloader/types/sync_segment.go | Added Empty() and IsEmpty() methods for segment management |
| multidownloader/types/storager.go | Extended interface with reorg and finalization support |
| multidownloader/types/reorg_*.go | New types for reorg error handling and data structures |
| multidownloader/storage/storage_*.go | Refactored storage layer with separate files for blocks, reorgs, and sync |
| multidownloader/storage/migrations/0002.sql | New migration adding reorg tracking tables |
| multidownloader/state.go | New state management for tracking synced vs pending segments |
| multidownloader/reorg_processor*.go | New reorg detection and processing logic |
| multidownloader/evm_multidownloader.go | Major refactoring with unsafe sync support and reorg handling |
| multidownloader/config.go | Added PeriodToCheckReorgs configuration |
| Test files | Updated and added tests for new functionality |
fd74186 to
4b119d1
Compare
2bd29e1 to
1d04650
Compare
479e298 to
6110fba
Compare
- Rename SyncerConfig.ContractsAddr to ContractAddresses for better naming consistency
- Updated all references across multidownloader, l1infotreesync, and types packages
- Updated all unit tests to use new field name
Improvements:
- Add auto-initialization in EVMMultidownloader.Start() when not already initialized
- Adds safety check to call Initialize() if IsInitialized() returns false
- Logs initialization attempt for better observability
- Fix typo in log_query.go panic message: "unsuppoerted" → "unsupported"
- Add nil check for query.ToBlock in NewLogQueryFromEthereumFilter to prevent nil pointer panics
- Fix typo in evm_multidownloader.go log message: "relauncing" → "relaunching"
Database:
- Fix SQL migration 0002.sql:
- Add missing DROP statements for blocks_reorged and reorgs tables in Down migration
- Fix typo in comment: "extran" → "extra"
Types:
- Update BlockHeader.Empty() to only check for nil (removed Number == 0 check)
- Update NewListBlockHeadersEmpty to pre-allocate slice with nil elements
- Add nil checks in ListBlockHeaders.ToMap() and BlockNumbers() methods
- Add clarifying comment to ReorgError about OffendingBlockNumber behavior
Testing:
- Add unit test for Start() auto-initialization error handling
- Re-enable TestEVMMultidownloader_Start with simplified test case
- Update test contracts compilation scripts (logemitter)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enhancements to multidownloader: - Add graceful Stop() method with context cancellation and WaitGroup - Improve Start() with better error handling and continuous reorg processing - Replace panic with warnings and automatic retry on errors - Add updateTargetBlockNumber() and checkReorgsUnsafeZone() methods - Refactor StartStep() with improved sync logic Reorg processor improvements: - Change GetLatestBlockNumberInRPC to GetBlockNumberInRPC with finality parameter - Fetch both latest and finalized block numbers from RPC during reorg processing - Improve reorg detection logging and metadata Storage enhancements: - Add GetBlockReorgedChainID() method to query reorged blocks - Update GetBlockHeadersNotFinalized() to accept nullable finalized block number - Improve block and reorg storage operations Common utilities: - Add BlockRange.SplitByBlockNumber() method with comprehensive tests - Add warning log when L1 MultiDownloader is disabled Test coverage: - Add extensive unit tests for state, storage, and set_sync_segment - Update etherman client tests - Add tests for new BlockRange split functionality Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add new multidownloader/sync package with Download and EVMDriver components - Introduce MultiDownloaderLegacy interface for backward compatibility - Rename ReorgError to DetectedReorgError for clarity - Add NewMultidownloadBased() implementation for l1infotreesync - Extend Storager interface with LogQuery, GetReorgedDataByChainID methods - Add IsPartiallyAvailable and ContainsBlockNumber utility methods - Update cmd/run.go to support both legacy and multidownloader-based flows - Regenerate all mocks with mockery v2.53.5 - Improve logging for block waiting states Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement completion percentage reporting in l1infotreesync RPC status endpoint to provide sync progress visibility. - Add GetCompletionPercentage() to DriverInterface and L1InfoTreeSync - Add completionPercentage field to StatusInfo RPC response - Rename PercentComplete to CompletionPercentage across multidownloader for consistency - Legacy syncer returns nil for completion percentage (not supported) - Update local_config_helper script with --skip-committee-override option
100e5c4 to
ca6527e
Compare
|
Claude finished @joanestebanr's task in 2m 13s —— View job Code Review CompleteReviewing PR #1462: feat: multidownloader reorg + integration l1infotree 🚀 What's New
🐛 Bug Fixes
📋 Config UpdatesDefault Value Changes:
New Configuration Parameters: [L1Multidownloader]
DeveloperMode = false # Enable forced reorgs for testing
PeriodToCheckReorgs = "5s" # How often to check for reorgs
[L2Multidownloader]
DeveloperMode = false
PeriodToCheckReorgs = "5s"
|
| if query.ToBlock == nil { | ||
| panic("NewLogQueryFromEthereumFilter: unsupported nil ToBlock") | ||
| } | ||
| return NewLogQuery(query.FromBlock.Uint64(), query.ToBlock.Uint64(), query.Addresses) |
There was a problem hiding this comment.
ethereum.FilterQuery.ToBlock is commonly left nil to indicate "latest" in go-ethereum conventions; panicking here makes NewLogQueryFromEthereumFilter unsafe for typical callers and can crash the process on valid inputs. Prefer handling nil (e.g., treat it as FromBlock, treat it as an open-ended range resolved elsewhere, or change the API to return (LogQuery, error) instead of panicking).
| if query.ToBlock == nil { | |
| panic("NewLogQueryFromEthereumFilter: unsupported nil ToBlock") | |
| } | |
| return NewLogQuery(query.FromBlock.Uint64(), query.ToBlock.Uint64(), query.Addresses) | |
| from := uint64(0) | |
| if query.FromBlock != nil { | |
| from = query.FromBlock.Uint64() | |
| } | |
| to := from | |
| if query.ToBlock != nil { | |
| to = query.ToBlock.Uint64() | |
| } | |
| return NewLogQuery(from, to, query.Addresses) |
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds per-contract and global completion percentage tracking to monitor sync progress: - Implements CompletionPercentage() method in State for per-contract progress calculation - Extends RPC Status endpoint with completionPercentage and completionPercentageDetailed fields - Adds GetContracts() helper to SetSyncSegment for contract iteration - Improves Add() logic to handle empty BlockRange initialization correctly - Adds documentation comments to all exported State functions - Adds test coverage for merging segments from empty BlockRange Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Better BlockRange empty case (add a flag to set it), in that way we support range{0,0}
- Multidownloader take care to avoid using range {0,0} because is the way of set an empty range in DB
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 107 out of 129 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
multidownloader/storage/storage_block.go:1
- Debug log statement is being executed unconditionally. Consider checking if debug logging is enabled before constructing the log message to avoid unnecessary string formatting overhead.
package storage
| syncedBlocks := synced.BlockRange.CountBlocks() | ||
| pendingBlocks := pending.BlockRange.CountBlocks() | ||
| totalBlocks := syncedBlocks + pendingBlocks | ||
| log.Infof("CompletionPercentage for contract %s: syncedBlocks=%d, pendingBlocks=%d, totalBlocks=%d", |
There was a problem hiding this comment.
Using the global log package instead of the instance logger (if available). This log statement appears to be debugging code that should either use a proper logger instance or be removed/changed to debug level.
| log.Infof("CompletionPercentage for contract %s: syncedBlocks=%d, pendingBlocks=%d, totalBlocks=%d", | |
| log.Debugf("CompletionPercentage for contract %s: syncedBlocks=%d, pendingBlocks=%d, totalBlocks=%d", |
|





🔄 Changes Summary
Changes in Multidownloader
downloader,processoranddriver) for syncer that require adaption:None
🔌 CLI / API Updates
RPC endpoint l1infotreesync
l1infotreesync_statushave added the completation percentage:RPC endpoint
multidownloader-l1_statuscompletionPercentageandcompletionPercentageDetailedscript/local_config_*
There is a new param (
-s | --skip-comittee-override) that prevents fetching the committee information fromaggkit-001. Retrieving this information requires the container to be running, so if there is any error that prevents it from starting you will still to be able to generate a local configuration.📋 Config Updates
The configuration reflects the increase of functionality of Multidownloader
Changes in default values:
New config params for Multidownloader :
It applies to
L1MultidownloaderandL2MultidownloaderDeveloperMode: Iftrueallow to force Reorg from RPCbooleanPeriodToCheckReorgs: Time to periodictypes.DurationExample
✅ Testing
🐞 Issues
🔗 Related PRs
📝 Notes