Home / Notes

Reorgs, finality and idempotency in chain data pipelines

2026-10-30 · Web3 data · Edward Plata

Unlike most data sources, a blockchain can take rows back. Near the head of the chain, a different block at the same height can replace a block you already loaded. This is a chain reorganization, or reorg. Every transaction and log in the dropped blocks leaves the canonical chain. Some come back in new blocks, with a new block hash and often a new position.

If your pipeline reads recent blocks, it will meet reorgs. If your keys are wrong, a reorg leaves orphan rows or silently overwrites good ones. This note covers finality per chain, how tools signal an undo, and the keys and lanes that make a pipeline correct and safe to rerun. The decentralized data stack maps the layers around it. Decoding contracts at scale covers what to do with the logs once they are correct.

Finality differs per chain

Ethereum proof-of-stake divides time into "slots (12 seconds) and epochs (32 slots)" (ethereum.org, PoS, updated 2026-10-07). Checkpoints become justified, then finalized, when votes from at least two-thirds of staked ETH support them. Two epochs is about 13 minutes. The ethereum.org roadmap rounds it up: "It takes about 15 minutes for an Ethereum block to finalize" (single slot finality, updated 2026-07-23).

Finalized means expensive to revert, not impossible: "To revert a finalized block, an attacker would commit to losing at least one-third of the total supply of staked ETH."

JSON-RPC exposes this through block tags. latest is "the latest proposed block", safe is "the latest safe head block", and finalized is "the latest finalized block" (ethereum.org, JSON-RPC). On Ethereum, safe follows the justified checkpoint. It can still revert in rare cases. Only finalized carries the one-third stake cost.

Finality has no fixed schedule. If too much stake is offline, finalized stops moving. Monitor the gap between latest and finalized, and decide in advance what your pipeline does when that gap grows.

Use the finalized tag where the chain provides one. Many EVM chains do not, or give it a different meaning. For those, keep a confirmation depth per chain in config, write down why you chose it, and review it. Tools follow the same idea: cryo has a --reorg-buffer flag and Envio has a max_reorg_depth setting, both covered below.

Solana uses commitment levels: processed, confirmed and finalized. Under Tower BFT, confirmed needs "66%+ stake voted on block", and finalized also needs "31+ confirmed blocks built atop block" (Anza, commitments). The same page describes Alpenglow, a newer consensus where "the Confirmed and Finalized commitment statuses are equivalent". Check which consensus the cluster you read runs.

Rollups add a second clock. On the OP Stack, "The unsafe head is served as the latest block, and the safe and finalized heads back the safe and finalized block tags." Soft finality takes "About two seconds". Hard finality takes "About 15 to 30 minutes" (OP docs). Arbitrum soft finality comes from the sequencer feed and is "Sub-second". Parent-chain finality is "~2 epochs, roughly 12–15 minutes" (Arbitrum docs). A sequencer fault, or an L1 reorg before the batch is final, can replace the unsafe L2 head. Treat it like latest on Ethereum.

Do not confuse rollup finality with the withdrawal window. The OP docs say the bridge delay "affects only withdrawals through the Standard Bridge and does not impact transaction finality". Arbitrum withdrawals wait "on the order of days". Analytics do not need to wait for either.

ChainProvisionalFinal for a pipelineSource
Ethereumlatest, safefinalized, about 15 minethereum.org
Solanaprocessed, confirmedfinalizedAnza docs
OP Stackunsafe (latest), about 2 sfinalized, 15 to 30 minOP docs
Arbitrumsequencer feedL1-final batch, 12 to 15 minArbitrum docs

This table does not cover ZK rollups or validiums. Their finality follows proof posting, so read their own docs.

Deep reorgs are rare, but they occur. On 2022-05-25 the Ethereum beacon chain had a seven-block reorg, which a researcher analysis links to a partial rollout of a fork-choice change (Barnabé Monnot). I do not give a maximum depth for any chain. Fail loudly when a reorg is deeper than your window.

How the tools signal undo

Raw EVM RPC. Log objects have a removed field: "true when the log was removed, due to a chain reorganization" (ethereum.org, JSON-RPC). You only see true on log subscriptions and filter polling. eth_getLogs returns current logs, so removed is always false there. Provider support also varies. Do not build on removed alone. Pair it with the parent-hash check described later.

Two EIPs help you read one branch on purpose. EIP-234 adds a blockHash filter to eth_getLogs. If the block is unknown, the node returns an error. The EIP gives "Block not found." as the message, but the exact text varies by client (EIP-234). That error is itself a reorg signal. EIP-1898 does the same for state reads such as eth_call and eth_getBalance, so a client can "maintain a coherent picture of blockchain state ... even in the presence of reorgs" (EIP-1898).

Solana. RPC polling at processed has no undo signal. A slot you read can vanish without notice. Either read at finalized, or stream slot status. The Yellowstone gRPC protocol, a common Geyser stream, reports SLOT_PROCESSED, SLOT_CONFIRMED, SLOT_FINALIZED and SLOT_DEAD (Yellowstone proto). Treat a dead slot as an undo for every row from that slot.

Substreams. A sink handles blockScopedData and blockUndoSignal. The undo signal is "sent every time there is a fork in the blockchain ... you must rewind back to the latest valid block." It carries last_valid_block and last_valid_cursor. "You must persist the cursor" (Substreams docs). For backfill, the request option final_blocks_only sends only irreversible blocks, so "no 'undo_signal' will ever be sent" (Substreams proto). Handle undo only in the head lane.

Ponder. Ponder records "all changes (insert, update, delete) to each table ... using a trigger-based transaction log". On a reorg it will "Roll back the database to the common ancestor block height". reorgWindow "defaults to 180 (3 minutes)" and accepts up to 600 seconds. "If a reorg crosses this finalized boundary, Ponder errors rather than continue with inconsistent data" (Ponder docs).

Envio HyperIndex. Rollback covers "reorgs up to max_reorg_depth blocks below the chain head. That's 200 on most chains and 0 on Arbitrum and OP Mainnet". The docs add that 0 "means HyperIndex doesn't track reorgs on those chains", and you can set the value yourself (Envio docs). They also warn: "RPC queries aren't atomic, so if the logs come from a reorged block but the block header comes from the canonical block, the indexer may not see that the logs came from a reorged block."

Bulk extractors. cryo's --reorg-buffer <N_BLOCKS> means "save blocks only when this old", and the default is 0 (cryo README). Set it, or stop at the finalized block.

One rule applies everywhere: "Side effects outside the database, such as calls to external APIs, are not rolled back" (Envio docs). Send webhooks and payouts from final data only.

Idempotency keys

A rerun must produce the same table. A reorg must replace, not add. Both depend on the key. The keys below are for EVM chains.

Block number alone is the wrong key. After a reorg, block 1,000 still exists, but it is a different block. A key on (block_number, log_index) overwrites only when positions happen to match. Logs that moved or vanished stay as orphans.

Use the block hash:

  • Logs: (chain_id, block_hash, log_index), where log_index is the block-wide logIndex the node returns. Some tools number logs per transaction. Do not mix the two.
  • Transactions and receipts: (chain_id, block_hash, tx_hash). A transaction can be re-included in another block, with a new status, gas used and position. Build "latest canonical row per tx_hash" as a view.
  • Keep block_number and tx_index as ordinary columns for partitioning.

Then a row is valid if and only if its block_hash is on the canonical chain.

On Solana, the fork-sensitive coordinate is the slot, and skipped slots mean slot and block height differ. Key instruction-level rows on (slot, blockhash, signature, instruction_index, inner_index). Use -1 as inner_index for top-level instructions, because some engines reject NULL in a key.

An illustrative upsert in Delta Lake / Spark SQL:

-- illustrative, Delta/Spark dialect
-- staged_logs is deduplicated on the key first
MERGE INTO logs AS t
USING staged_logs AS s
  ON  t.chain_id     = s.chain_id
  AND t.block_number = s.block_number  -- lets the engine prune
  AND t.block_hash   = s.block_hash
  AND t.log_index    = s.log_index
WHEN NOT MATCHED THEN INSERT *;

Other engines need a column list, or ON CONFLICT DO NOTHING in Postgres. Deduplicate the staging table first. Providers can return the same log twice when request ranges overlap, and engines without unique constraints will insert both. Add a uniqueness test on the key.

Two lanes: head and backfill

Split the pipeline into two lanes. The split keeps reorg handling in the small head lane.

The backfill lane reads only up to finalized. It loads history in large chunks, and its rows do not change after load. Check completeness anyway. A lagging node behind a load balancer can return a short eth_getLogs result with no error. Compare log counts per block against receipts.

The head lane reads from finalized to latest. Its rows are provisional, carry is_final = false, and can be rolled back.

The lanes overlap near the boundary because finalized moves while both run. The key makes the overlap harmless. Pin one provider, or one sticky session, per batch, because load-balanced nodes can return different latest and finalized values per call.

A promotion job marks head rows as final. It must not use height alone. A row is final only when its height is at or below finalized and its block_hash equals the canonical hash at that height. Delete or flag orphans before you promote.

height:   100   101   102   103   104        (head)
chain A:  [a0]--[a1]--[a2]--[a3]
chain B:              \--[b2]--[b3]--[b4]    new canonical chain
                      ^
                      common ancestor = 101

action:  remove rows where block_hash in (a2, a3)
         insert rows for b2, b3, b4

lanes:   backfill: <= finalized    head: finalized .. latest
         upsert, immutable         provisional, can roll back

Reports, reconciliations and anything with money attached read only final rows.

Reorg tables and rollback

A head lane needs two small tables.

The block table holds (chain_id, height, block_hash, parent_hash) for every block in your window. On each new block, check that its parent_hash equals the stored hash at height - 1. If not, walk back until the hashes match. That height is the common ancestor. Envio does the same: it "fetches recent block hashes to pinpoint exactly where a reorg occurred."

The change log records every insert, update and delete, with the block that caused it. On a reorg, apply it in reverse down to the common ancestor. This is the Ponder approach. Prune entries once their block is final.

You can delete orphan rows or mark them is_canonical = false. A soft delete keeps an audit trail and makes orphan checks cheap.

Read logs by block hash where you can (EIP-234). This closes the gap Envio describes, where logs and header come from different branches.

The cursor needs one rule. Commit it atomically with the data, or make the sink idempotent so a repeat is harmless. Object-store sinks cannot share a transaction with a cursor table, so they depend on the second option.

Tests and monitoring

Build reorg tests. Do not wait for a real one.

  • Replay test. Feed blocks a0 to a3, then b2 to b4 with b2 as a child of a1. Assert no row with hash a2 or a3 remains canonical.
  • Dropped transaction. Make one transaction appear in a2 and in no block of chain B. Assert it has no canonical row.
  • Equal or shorter branch. Replace a2 and a3 with one block b2. Assert the head moves back.
  • Rerun test. Load the same range twice. Assert row counts do not change.
  • Orphan check. In the head lane, count rows whose block_hash is not in the block table. Older rows need a check against a full hash chain or a sample against RPC.
  • Depth alert. Alert when a reorg is deeper than your window.
  • Finality lag. Alert when finalized falls far behind latest, on L1 and on any rollup you read.

What to take away

  • Read history at finalized, or at a documented depth where no tag exists.
  • Key EVM facts on block hash. Key Solana facts on slot and blockhash.
  • Promote rows by canonical hash, not by height.
  • Persist cursors with the data, or make the sink idempotent.
  • Test reorgs on purpose.

Build or buy on-chain data compares managed indexers with your own. The on-chain analytics lakehouse uses these lanes in a full design. The on-chain analytics warehouse and Rust ingestion and indexers pages describe how I approach this work.

If your chain tables drift after reorgs or reruns, I can review the keys, lanes and rollback path with you.

Book a 30-minute call

Ask a question