TeachMeBitcoin

Linear Storage vs. Index

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Linear Storage vs. Random Access

A common misconception is that blk00000.dat contains Blocks 0 through 1,000 in perfect order. In reality, the blk.dat files are chronological logs, not ordered databases.

1. Out-of-Order Storage

When you sync a Bitcoin node (Initial Block Download), you often download blocks from many peers simultaneously.

Consequently, Block 100,005 might appear in the file before Block 100,001.

2. The Role of the Block Index (LevelDB)

Since the blk.dat files are unordered, the node needs a way to find a specific block without scanning terabytes of data. This is handled by the Block Index.

3. The Undo Files (rev.dat)

Alongside the blk.dat files, you will find rev.dat files. These contain "Undo Data."

4. Pruning

If you run a "Pruned Node," your software will delete old blk.dat files once they have been processed and validated.

File Type Purpose
blkXXXXX.dat Raw Block Data (The Chain)
revXXXXX.dat Undo Data (For Reorgs)
index/ (LevelDB) Map of Hash -> File Position

In the next section, we will perform a Byte-by-Byte Walkthrough of a raw blk.dat record.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!