Repository navigation
Read only block headers in the -reindex scan (#916) - #927
Merged
Merged
Conversation
The flat-file reindex plans its chain from the block headers, but its scan read every blk*.dat whole to get them: on mainnet the whole chain, about 700 GB, before the first block connected, and again on every start that continued an interrupted reindex (#906). FlatFileManager::for_each_block_header walks the same records as for_each_block, ending a file on the same padding and length checks, but reads each record's framing and the start of its payload and seeks to the next record: one 4 KiB read for a block larger than that, shared reads for smaller ones. The reindex scan uses it, and logs the bytes it read. The resume check compares the stored entries against the scan's map in memory, so it reads nothing more. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
bkeroack
added a commit
that referenced
this pull request
Oct 7, 2026
The flat-file reindex plans its chain from the block headers, but its scan read every blk*.dat whole to get them: on mainnet the whole chain, about 700 GB, before the first block connected, and again on every start that continued an interrupted reindex (#906). FlatFileManager::for_each_block_header walks the same records as for_each_block, ending a file on the same padding and length checks, but reads each record's framing and the start of its payload and seeks to the next record: one 4 KiB read for a block larger than that, shared reads for smaller ones. The reindex scan uses it, and logs the bytes it read. The resume check compares the stored entries against the scan's map in memory, so it reads nothing more. (cherry picked from commit 1ada7eb) Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #916.
A flat-file
-reindexplans its chain from the block headers alone. Its phase 1 scan still read everyblk*.datwhole (std::fs::read) to get them. On mainnet that is the whole chain, about 700 GB, before the first block connects. Since #915 a continued reindex paid that again on every start.Change
FlatFileManager::for_each_block_headerwalks the same records asfor_each_block, and ends a file on the same zero-padding and length checks. It reads each record's 8-byte framing and up to 80 header bytes, then seeks to the next record.xor.datblocks dir works as before.bytes_read. The plan comes from the same records as before.check_resumable_prefixcompares the stored entries with the scan's map in memory, so a continued reindex reads no more than a fresh one.fs::readdropped the whole file without a word.Why headers only, not skipping the files below the stored tip
The issue offered both. Skipping the early files still means checking each stored entry against them. The issue proposes doing that by reading the header at each recorded position, which is the same one small read per block the header scan makes. Skipping would also need:
The header scan makes the same reads without any of that. Its plan matches a full scan's by construction, and it speeds up a fresh reindex too.
Not measured: the issue's caveat that on a hard drive, one seek per large block may cost about as much as reading the files sequentially.
Tests
the_header_scan_yields_the_records_the_full_scan_doesbuilds a plaintext dir and an XOR-obfuscated one. Each holds records that straddle the 4 KiB reads, records shorter than a header, raw zero padding, and a record that runs past the end of its file. The header scan must yield the same headers, file numbers and positions asfor_each_block, with at most one read per record plus one per file.a_reindex_scan_reads_the_block_headers_not_the_blocksuses 12 blocks with 32 KB of unspendable output each. A fresh reindex's scan and a continued reindex's scan must each read less than a fifth of the block files. The continued run must end on the uninterrupted run's UTXO set.for_each_blockin the replay fails the reindex test;Release notes
CHANGELOG.mdbullet.docs/release-notes/0.6.1-pre.md.Verified locally
cargo clippy --all-targets --all-features --locked -- -D warningscargo test --test e2e --no-run --locked --features e2enodelib suite: 2150 passedsatdbin tests: 307 passedThis targets
release/0.6for 0.6.1. Once it merges, it needs a forward-port tomaster. The forward-port of #914 and #915 is open separately as #926.🤖 Generated with Claude Code