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
- On each new batch, validate the parent hash of the first block against the stored hash of the previous block
- If mismatch detected, walk back up to N blocks (e.g., 128) to find the fork point
Rollback
- Delete orphaned blocks and all associated data (transactions, logs, transfers, etc.) from the fork point onward
- For partitioned tables, deletion needs to target the correct partitions
- Update derived tables (ERC-20 balances, NFT ownership) — either recompute or reverse the orphaned changes
- Update
indexer_state watermark to the fork point
- 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.rs — find_fork_point walks back, deletes orphans from all sinks
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:
This is a correctness issue, not just a performance one.
Design
Detection
Rollback
indexer_statewatermark to the fork pointConsiderations
HeadTrackerin-memory buffer needs to be pruned of orphaned blockstrust_rpcflag to skip parent hash validation for trusted RPCsReferences
sync/engine.rs—find_fork_pointwalks back, deletes orphans from all sinks