fix: start onchain events ingest from latest block by default - #745
fix: start onchain events ingest from latest block by default#745aditiharini wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adjusts the default onchain events ingestion start point so new validator nodes don’t backfill from the beginning of chain history when no explicit bounds are configured.
Changes:
- Introduces a default live-sync start offset from the chain head (
LIVE_SYNC_BLOCK_OFFSET). - Updates the
Subscriber::run()default start-block logic to use(latest_on_chain - offset)as the baseline.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
src/connectors/onchain_events/mod.rs |
Three issues raised in review: 1. Silent skip when DB is behind tip - offset (regression). The original default_start.max(latest_block_in_db) only protects when the DB is ahead of the offset window. After long downtime or restoring from a stale snapshot, latest_block_in_db < tip - offset, so the node would jump forward and permanently miss onchain events in the gap. Resume from the DB checkpoint whenever one exists; only use the offset for a truly fresh start. 2. default_start could fall below the contract-deployment block on chains where the tip is near genesis (testnets, future chains). Clamp to first_block(chain) so we don't issue invalid pre-deployment RPC log queries. 3. No unit coverage for the start-block selection. Extract the logic into a pure associated fn (live_sync_start_block) and cover: empty DB → tip - offset, empty DB near genesis → clamps to first_block, empty DB with tiny tip (saturating_sub edge) → clamps to first_block, DB ahead of default → resume from DB, DB behind default → resume from DB (the regression guard). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ddccb9f to
81257a0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 81257a0. Configure here.
| first_block: u64, | ||
| ) -> u64 { | ||
| if latest_block_in_db > 0 { | ||
| latest_block_in_db |
There was a problem hiding this comment.
Checkpoint not clamped to first
Medium Severity
The live_sync_start_block function can return a latest_block_in_db value that's earlier than first_block. If latest_block_in_db is non-zero but below the chain's actual first block, the system might attempt to query events from before contracts existed.
Reviewed by Cursor Bugbot for commit 81257a0. Configure here.
| latest_block_on_chain | ||
| .saturating_sub(LIVE_SYNC_BLOCK_OFFSET) | ||
| .max(first_block) | ||
| } |
There was a problem hiding this comment.
Storage read failure mimics empty
High Severity
live_sync_start_block treats latest_block_in_db == 0 as a fresh node and starts at tip - LIVE_SYNC_BLOCK_OFFSET. latest_block_in_db() also returns 0 when reading the checkpoint fails, so a transient storage error at startup can jump ahead of a real checkpoint and skip onchain events in the gap.
Reviewed by Cursor Bugbot for commit 81257a0. Configure here.


When starting a new validator node we end up picking up all blocks from beginning of history by default rather than starting at current. Fix this by starting at current if no explicit bounds are specified.
Note
Medium Risk
Alters default ingest scope for new nodes (recent blocks only unless configured), which is intentional but could surprise operators expecting full historical backfill without an explicit start block.
Overview
Changes the default live-sync start block when
start_block_numberis unset. Fresh nodes no longer begin at contract deployment (first_block); they start at chain tip minus 500 blocks, floored atfirst_block.If the local DB already has a block checkpoint, live sync still resumes from that checkpoint even when it lags far behind the tip, so restarts after downtime do not skip events in the gap.
Adds
live_sync_start_blockand unit tests for tip-offset, genesis clamping, and checkpoint resume behavior.Reviewed by Cursor Bugbot for commit 81257a0. Bugbot is set up for automated code reviews on this repo. Configure here.