Understanding Data Storage Formats in Bitcoin Core

Understanding Data Storage Formats in Bitcoin Core

Bitcoin Core, since its inception, has evolved in the way it stores data about blocks and transactions. This article dives into the formats used for data storage in Bitcoin Core, providing insights for developers and enthusiasts alike.

Block Index and Chain State

Since version 0.8, Bitcoin Core uses two primary databases: the block index and the chain state.

  • The block index ($DATADIR/blocks/index) maintains information about each block and its location on disk.
  • The chain state ($DATADIR/chainstate) contains information about the state of validation resulting from the currently known best chain, storing all spendable transaction outputs (UTXOs) and relevant metadata.

Storage Formats in Block Index

The block index stores detailed information about each block, including:

  • Block header
  • Block height
  • Number of transactions
  • Validation status of the block
  • Location of block data and undo data in files

Storage Formats in Chain State

Chain state database stores records for transactions with unspent outputs, including:

  • Transaction version
  • Coinbase status
  • Block height containing the transaction
  • Unspent outputs and their details (scriptPubKey, amount)

Additional Files and Databases

Bitcoin Core uses various files and databases for additional data storage:

  • blocks/: Contains actual Bitcoin blocks in network format.
  • chainstate/: LevelDB database for blockchain state.
  • indexes/txindex/: Optional transaction index database.
  • wallets/: Stores wallets, which can be either Berkeley DB or SQLite databases.

File Formats

Key file formats include:

  • blkNNNNN.dat: Actual Bitcoin blocks.
  • revNNNNN.dat: Block undo data files.
  • wallet.dat: Personal wallet file.

Other Files

Bitcoin Core also uses various other files for storing data:

  • peers.dat: Peer IP address database.
  • mempool.dat: Mempool transactions dump.

Version Compatibility and Updates

With each new release of Bitcoin Core, changes to data storage formats may be introduced. It is advisable to refer to the latest sources for up-to-date information.