Reorgs
A reorg orphans blocks your tables already hold: delete your rows from the fork height, inclusive, then read forward again.
Keep rows from the orphaned range and your tables describe a chain that no longer exists. Every read envelope carries the same fork in its reorgs array: Cursors and Pages.
How you read decides how much rollback code you write.
| You read with | What happens on a reorg | You do |
|---|---|---|
| A consumer | It rewinds and calls onReorg | Delete from the fork height |
| A sink | It deletes the rows and rereads | Nothing |
| A subgraph | Rows are rewritten under new ids | Wait a few blocks before moving money |
| A webhook | chain.reorg.rollback lists what may have arrived | Undo each entry |
A plain list() | reorgs[] names what to undo | Do it by hand |
- Delivery after a rewind is at least once, so keep writes idempotent.
- The fork block itself is re-delivered, which is why the delete is inclusive.
A consumer rewinds under these rules:
| Rule | Detail |
|---|---|
| Scope | Only forks at or below your checkpoint roll back; a fork above it has nothing to undo |
| Depth | A rewind deeper than maxRollbackDepth (default 1000 blocks) is refused before anything is deleted |
| Idle | On empty pages the loop polls reorgs.list, so a fork that lands while idle at the tip is caught, at one extra request per idle poll |
| Genesis | A fork at genesis hands onReorg a null cursor |
By hand, roll back rows whose cursor falls inside orphaned_range, then re-fetch from new_canonical_tip. Both bounds are <block_height>:<event_index> cursors; on transaction-keyed feeds, compare by the block height. A consumer does all of this for you.
Check Your Mirror
Compare your stored hashes with the canonical chain any time, and re-sweep from the first block that diverged.
Rows at or below tip.finalized_height never reorg, so a consumer that reads only those has nothing to undo. The tradeoff is freshness: finalizedOnly holds delivery until each row is final, which can put you hundreds of blocks behind the tip.
Use it for accounting and reports, and keep the rollback path for anything a user watches live. The option is on the checkpointed consumer.
Edit on GitHub