THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Chainstate and Reorganizations: UTXO Consistency Across Forks

permalink THAMER
#bitcoin-chainstate#chainwork#reorg#utxo-undo-data

Bitcoin nodes maintain an active chain and a corresponding UTXO state. A chain reorganization occurs when the node switches to a different valid branch with more accumulated proof of work. The node must update its spendable-output state to match the selected branch.

Competing branches are normal

Two miners can discover different valid blocks at nearly the same height. Nodes may initially accept different tips. Once one valid branch accumulates more work, nodes can reorganize to it. A reorganization does not imply that either competing block was invalid.

Disconnecting blocks

To leave the old branch, a node reverses its effects on chainstate. Outputs created by disconnected transactions cease to be confirmed on the active chain; previously spent outputs can be restored using undo information. Coinbase outputs from disconnected blocks also cease to be active-chain rewards.

Connecting the replacement branch

The node validates and connects blocks from the selected branch in order, updating UTXOs again. A transaction confirmed on the old branch might be included in the new branch, return to the mempool if eligible, or conflict with a transaction in the new branch. Applications must not assume all disconnected transactions are automatically rebroadcast or accepted.

Confirmations are conditional on the active chain

A transaction's confirmation count reflects its position in the current active chain. Reorganizations can reduce or remove confirmations. More confirmations generally make replacement increasingly costly, but no finite confirmation count provides a mathematical guarantee against every possible reorganization.

Implications for wallets and indexers

Wallets should track block hashes and chain positions, not only heights. Indexers need reversible updates or a reconciliation strategy. Payment systems should handle duplicate notifications, reorganizations, and mempool replacement independently from their display of confirmed balances.

Pruned-node considerations

Pruned nodes retain data required for their supported reorganization and validation behavior, but they do not promise indefinite access to every historical block. Historical application queries may require separate indexes or an archival source.

Primary references

Bitcoin Core source: https://github.com/bitcoin/bitcoin
Bitcoin developer reference: https://developer.bitcoin.org/reference/

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects