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 Core Block Storage: blk Files, Block Index, and Disk Layout

permalink THAMER
#bitcoin#bitcoin-core#block-index#block-storage

Bitcoin Core separates the historical block data from the indexes and databases used to validate the active chain. This separation matters when operating a node, diagnosing disk problems, or designing software that needs historical transactions. A block file is not a wallet database, and its presence does not prove that every block inside it belongs to the active chain.

Serialized block files

The blocks directory normally contains numbered files such as blk00000.dat and blk00001.dat. These files contain serialized blocks with record framing. Their numbering describes local storage allocation rather than a consensus-defined range of block heights. Blocks can arrive out of order, and competing branches may also be stored. A parser must not infer the active chain from the order of records in a file.

The exact disk representation is implementation-dependent. For example, newer Bitcoin Core releases can apply an XOR transformation to block and undo files using a local key. External parsers must account for the installed release and storage configuration rather than assume that every file begins with recognizable plaintext network magic.

Block index and active chain

The block index records metadata about known blocks, including their ancestry, validation status, accumulated chainwork and, when available, disk positions. The blocks/index database is distinct from the chainstate database. A block header can remain indexed even when its full serialized body has been pruned.

For applications, getblockhash maps an active-chain height to a block hash. getblockheader returns header information, while getblock retrieves block data when available. A block hash identifies a specific block even if a reorganization changes the active block at that height. Applications should preserve both height and hash when recording checkpoints.

Operational inspection

Use bitcoin-cli getblockchaininfo to inspect synchronization and pruning status. Use bitcoin-cli getblockhash 100000 to resolve a historical height, then query getblockheader with the returned hash. A subsequent getblock request may fail on a pruned node even though the header query succeeds. That difference is expected and does not establish corruption.

A transaction index is another separate facility. It does not replace historical block storage or the wallet's own transaction records. Consult the installed version's restrictions before combining optional indexes with pruning.

Safe storage management

Do not manually remove individual block files from a running node to reclaim space. Bitcoin Core coordinates pruning with index metadata and validation requirements. Use supported pruning configuration and monitor disk capacity, including space for databases, indexes and temporary operations. For backups, preserve wallet material independently and use a consistent stopped-node copy if a full data-directory backup is required.

Primary references

Bitcoin Core block storage implementation: https://github.com/bitcoin/bitcoin/blob/master/src/node/blockstorage.cpp

Bitcoin Core RPC documentation: https://bitcoincore.org/en/doc/

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