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 Reorganization Monitoring: Block Hashes, Chainstate, and Bitcoin Core RPC

permalink THAMER
#bitcoin#bitcoin-core#chainstate#monitoring#reorg#rpc

Applications that process Bitcoin blocks must expect the active tip to change. A service that assumes every new height is permanent may miss transactions, double-count outputs, or continue treating stale blocks as confirmed. Reorganization monitoring requires following block identities and their parent relationships, not simply incrementing a height counter.

Height is not a unique block identifier

A height tells you a block's position within a particular chain, but two competing blocks can share that height. The block hash identifies the actual block, and the previousblockhash field links it to its parent. To verify continuity, compare the new block's parent with the previously processed active tip.

If they differ, the service may have missed blocks, received notifications out of order, or encountered a reorg. It should query the node's current active chain rather than guessing which event occurred.

Useful Bitcoin Core interfaces

getblockchaininfo reports active-chain information such as blocks and bestblockhash. getblockhash maps a height on the node's current active chain to a block hash. getblockheader supplies a header and, when requested in decoded form, contextual fields including previousblockhash. getchaintips can reveal competing known tips and their status.

getrawtransaction is not a universal historical wallet index: its availability depends on transaction index settings, wallet context, and supplied block hash. gettxout reports whether an output is currently unspent under the node's selected view; it is not a substitute for complete wallet transaction history.

Polling and event notifications

Polling the current tip is simple and robust when combined with a persisted last-processed block hash. Bitcoin Core also supports ZeroMQ notifications in suitable deployments. Notifications are triggers to re-query authoritative node state, not durable proof that a block will remain active forever.

A service may receive multiple events for the same tip or miss events during downtime. It should therefore reconcile from its persisted checkpoint to the node's active chain on every restart and after detected discontinuities.

Atomic state transitions

Process block disconnections and connections in a deterministic order. Commit the processed tip and its wallet-derived effects together when possible. If the process crashes between updating balances and recording the checkpoint, recovery should replay or roll back safely rather than creating duplicate credits.

For complex systems, a reversible journal of output creations, spends, and transaction status changes can make reorg processing auditable. Alternatively, a bounded rescan from a known-good ancestor can rebuild derived state. Both approaches need careful handling of pending mempool activity.

Operational alerts

Useful metrics include active tip hash and height, processed checkpoint hash, reorg depth, time since the last successful reconciliation, and whether the wallet's derived state is caught up. A health endpoint should distinguish a node that is syncing from a wallet that has fully reconciled its own transaction history.

Never infer safety from a monotonically increasing height alone: a node can advance to a new branch while earlier block hashes change.

Primary references

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

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

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

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