Skip to content

fix: start onchain events ingest from latest block by default#745

Open
aditiharini wants to merge 4 commits into
mainfrom
start-onchain-events-from-current
Open

fix: start onchain events ingest from latest block by default#745
aditiharini wants to merge 4 commits into
mainfrom
start-onchain-events-from-current

Conversation

@aditiharini
Copy link
Copy Markdown
Contributor

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.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
snapchain-docs Ready Ready Preview, Comment Apr 28, 2026 0:22am

Request Review

@aditiharini aditiharini marked this pull request as ready for review January 9, 2026 03:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/connectors/onchain_events/mod.rs Outdated
Comment thread src/connectors/onchain_events/mod.rs Outdated
Comment thread src/connectors/onchain_events/mod.rs Outdated
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>
@github-actions
Copy link
Copy Markdown

Diff Coverage

Diff: origin/main...HEAD, staged and unstaged changes

  • src/connectors/onchain_events/mod.rs (87.2%): Missing lines 1293-1297

Summary

  • Total: 39 lines
  • Missing: 5 lines
  • Coverage: 87%

src/connectors/onchain_events/mod.rs

  1289         );
  1290         let live_sync_block;
  1291         match self.start_block_number {
  1292             None => {
! 1293                 live_sync_block = Some(Self::live_sync_start_block(
! 1294                     latest_block_on_chain,
! 1295                     latest_block_in_db,
! 1296                     Self::first_block(self.chain),
! 1297                 ));
  1298             }
  1299             Some(start_block_number) => {
  1300                 let historical_sync_start_block = latest_block_in_db.max(start_block_number);
  1301                 let historical_sync_stop_block = latest_block_on_chain

@topocount topocount self-assigned this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants