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 Chain Reorganizations Explained: Active Chain, Chainwork, and Fork Choice

permalink THAMER
#bitcoin#blockchain#chainwork#consensus#reorganization

Bitcoin nodes do not select a chain by counting votes, choosing the longest visible branch, or trusting the first block they see. They independently validate blocks and follow the valid chain with the greatest accumulated proof of work. A chain reorganization, often shortened to reorg, occurs when a node changes which valid branch it treats as active.

Competing branches and accumulated work

Two miners can discover different valid blocks extending the same parent before learning about each other. Both blocks can be valid, but they cannot both occupy the same height in one active chain. Nodes may temporarily disagree about which tip is active, depending on which blocks have reached them.

A block header commits to the previous block hash and includes a proof-of-work target encoded in nBits. Nodes evaluate the work represented by each valid block and accumulate that work across the branch. A branch with more blocks is not automatically better: the selection criterion is accumulated chainwork, subject to full consensus validation. Header work alone is not permission to accept an invalid transaction or block.

How a reorganization happens

Suppose a node considers branch A active through height H. It later receives and validates a competing branch B that diverges at height H-2 and eventually has greater accumulated work. The node finds the common ancestor, disconnects the former active blocks above that ancestor, and connects the new branch's blocks in order.

Disconnecting blocks reverses their effects on the active UTXO set. Connecting replacement blocks spends and creates outputs according to the newly active history. The original blocks remain known historical candidates, but they are no longer active-chain confirmations. A reorg does not rewrite their bytes or invalidate the cryptographic signatures they contained; it changes which history is currently accepted.

What happens to transactions?

A transaction confirmed only in disconnected blocks loses those confirmations. It may appear in the replacement branch, be reconsidered for the mempool, conflict with a transaction in the new branch, or be absent from a node's current mempool. These outcomes depend on validity, conflicts, policy, and node state; reentry into the mempool is not guaranteed.

A wallet must therefore distinguish transaction identity from active-chain inclusion. A txid can remain unchanged even while its confirmation status changes. A block height or block hash previously attached to a payment must be checked against the active chain before being treated as current.

Why reorg depth matters

One confirmation means inclusion in the currently active tip, not irrevocable settlement. Each additional block increases the amount of competing proof of work needed to replace that history, but no fixed confirmation count makes a reorg mathematically impossible. The appropriate risk tolerance depends on payment value, threat model, and business requirements.

Practical node checks

Bitcoin Core exposes the active tip with getbestblockhash and getblockchaininfo, while getblockheader can identify a block and its chainwork. Applications can track block hashes, not just heights, to detect a changed history. Reorg-aware services should make block connection and disconnection updates reversible and idempotent.

Primary references

Bitcoin Developer Guide — Block Chain: https://developer.bitcoin.org/devguide/block_chain.html

Bitcoin Core RPC — getblockchaininfo: https://bitcoincore.org/en/doc/

Bitcoin whitepaper — Section 5: https://bitcoin.org/bitcoin.pdf

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