feat: reorg handling

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
rust

Research direction

The issue points to tidx's sync/engine.rs and find_fork_point as a reference; start there, then locate Atlas's batch indexing, sinks, indexer_state, HeadTracker, and SSE paths. Done means canonical-chain reorgs are detected, orphaned and derived data are reconciled, indexing resumes correctly, and affected clients are handled.

Written by the indexing model from the issue text.

Description

Summary

Atlas currently has no chain reorganization handling. If the chain reorgs, previously indexed blocks may become orphaned and the explorer will serve inconsistent data (e.g., transactions that no longer exist on the canonical chain).

Motivation

Any EVM chain can experience reorgs. Without handling them, Atlas may:

  • Show transactions/blocks that were reverted
  • Miss the canonical replacement blocks
  • Have inconsistent state in derived tables (ERC-20 balances, NFT ownership)

This is a correctness issue, not just a performance one.

Design

Detection
  1. On each new batch, validate the parent hash of the first block against the stored hash of the previous block
  2. If mismatch detected, walk back up to N blocks (e.g., 128) to find the fork point
Rollback
  1. Delete orphaned blocks and all associated data (transactions, logs, transfers, etc.) from the fork point onward
  2. For partitioned tables, deletion needs to target the correct partitions
  3. Update derived tables (ERC-20 balances, NFT ownership) — either recompute or reverse the orphaned changes
  4. Update indexer_state watermark to the fork point
  5. Resume indexing from the fork point
Considerations
  • Derived tables (erc20_balances, nft_tokens) make rollback more complex than raw-data-only indexers — may need to replay transfers from the fork point
  • The HeadTracker in-memory buffer needs to be pruned of orphaned blocks
  • SSE clients should be notified of the reorg (new event type or resync signal)
  • Configurable max reorg depth (default 128, matching tidx)
  • Optional trust_rpc flag to skip parent hash validation for trusted RPCs

References

  • tidx implementation: sync/engine.rsfind_fork_point walks back, deletes orphans from all sinks
Dominant language
Rust
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from evstack/atlas

All issues in evstack/atlas

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.