fix: determine claim syncer starting block from earliest settled reference when DB is empty#1574
Conversation
…rence when DB is empty When the claim syncer DB is empty on startup, use the earliest block among the settled bridge exit sources (bridge exits, imported bridge exits, FEP L2 block) instead of the latest, falling back to RPC log scanning when the imported bridge exit block cannot be resolved from local storage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @joanestebanr's task in 2m 11s —— View job Code Review Complete ✅🚀 What's NewThis PR improves the claim syncer startup logic when the database is empty. The key change is using the earliest block (instead of latest) among the three settled references (bridge exit, imported bridge exit, FEP L2 block) as the starting point. This ensures all historical claims are properly synced from the earliest point forward. Additionally, when the imported bridge exit block cannot be resolved from local storage, the system now falls back to RPC log scanning with automatic chunking to handle RPC max-range limits. 🐛 Bug Fixes
📋 Config UpdatesNone
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts claim syncer bootstrapping when its DB is empty by deriving the starting block from the earliest available settled reference (instead of the latest), and adds supporting plumbing to query/derive those references more robustly (including an RPC log-scan fallback).
Changes:
- Introduces
SettledBlocks(+EarliestBlock/LatestBlock) andGetBlockNumbersFromCertHeaderto query three settlement sources independently with per-source errors. - Updates claim syncer startup logic to be idempotent and to use earliest-settled block; adds RPC fallback to resolve imported-bridge-exit block when local storage can’t.
- Adds an optional log hook to the EVM downloader and uses it to prefer
DetailedClaimEventoverClaimEvent, plus warns/drops an outdated detailed event variant.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sync/evmdownloader.go | Adds optional LogsHookFunc and plumbing to apply it after fetching logs. |
| sync/evmdownloader_test.go | Unit tests for the new logs hook behavior and delegation. |
| claimsync/types/claim_syncer.go | Extends ClaimSyncer interface with RPC fallback method. |
| claimsync/types/mocks/mock_claim_syncer.go | Updates generated mock for new ClaimSyncer method. |
| claimsync/mocks/mock_claim_syncer.go | Updates generated mock for new ClaimSyncer method. |
| claimsync/downloader.go | Adds outdated detailed-claim signature handling + prefer-detailed hook implementation. |
| claimsync/claimsync.go | Installs logs hook; caps SetNextRequiredBlock; adds RPC log-scan helper to resolve block by global index. |
| claimsync/claimsync_get_block_rpc_test.go | New unit tests covering chunked RPC scan and parsing across event variants. |
| aggsender/types/types.go | Adds SettledBlocks struct and helper methods for earliest/latest settled block selection. |
| aggsender/types/types_test.go | Unit tests for SettledBlocks string/earliest/latest behavior. |
| aggsender/types/interfaces.go | Extends CertificateQuerier interface with GetBlockNumbersFromCertHeader. |
| aggsender/query/initial_block_to_claimsync_setter.go | Makes claim syncer startup idempotent; derives starting block via earliest settled source + RPC fallback. |
| aggsender/query/initial_block_to_claimsync_setter_test.go | Updates/adds tests for new startup/idempotency and RPC fallback behaviors. |
| aggsender/query/certificate_query.go | Refactors settled-block derivation into GetBlockNumbersFromCertHeader; reuses it for GetLastSettledCertificateToBlock. |
| aggsender/query/certificate_query_test.go | Adds coverage for GetBlockNumbersFromCertHeader and updates existing expectations. |
| aggsender/mocks/mock_certificate_querier.go | Updates generated mock for new CertificateQuerier method. |
| aggsender/aggsender.go | Reorders startup stages so claim syncer next-required block is set before initial status checks. |
| AGENTS.md | Adds a GitHub PR template and guidance on BlockNumberFinality usage. |
…aimEvent Drop the ClaimQuerier interface and GetBoundaryBlockForClaimType method from storage, processor, and all related interfaces/mocks. The DB lookup performed during event handling to skip ClaimEvents already covered by a DetailedClaimEvent is no longer needed; deduplication is handled by the DetailedClaimEvent handler which removes the redundant ClaimEvent in-block. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|



🔄 Changes Summary
EarliestBlock()method toSettledBlocksthat excludesLastSettledL2BlockNumwhen it is 0 (not found).GetBlockNumbersFromCertHeader()tocertificateQuerierto query all three block sources independently, recording errors per source without aborting the others.GetLatestBlockNumByGlobalIndexFromRPC) using chunkedFilterLogsbackwards from the finalized block.SetClaimSyncerNextRequiredBlockwhen the claim syncer DB already has processed blocks (idempotent startup).ClaimQuerierinterface andGetBoundaryBlockForClaimTypemethod from storage, processor, and all related interfaces/mocks. Deduplication betweenClaimEventandDetailedClaimEventis now handled entirely by theDetailedClaimEventhandler in-block, removing the need for DB lookups during event processing.None
📋 Config Updates
None
✅ Testing
make test-unit🐞 Issues
🔗 Related PRs
None
📝 Notes
GetLatestBlockNumByGlobalIndexFromRPCauto-detects the RPC max-range limit from the first error message and retries in backward chunks until a matching claim log is found or the full range is exhausted.