mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 19:44:37 +00:00
index: prevent block filter loss and restart failures after reorgs #37044
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!37044
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/blockfilter-restore-header-by-hash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: A reorg can put a different block at the same height while an index still has the old block saved as its last committed tip.
The database preserves the old entries by block hash.
The block filter index looks up headers by height during startup and rewind, so it can fail to start or abort during a rewind.
CoinStats can also fail to start when a rewind tries to decode the parent's hash entry as a height entry.
The block filter index can save a new filter entry before it saves the next write position.
After an unclean shutdown, the index can resume writing at the old position and overwrite a filter still referenced by a stale branch.
getblockfilterreports index corruption for that block, and peers that request its compact filter get no response.The block filter index can also start with a tip entry that points to a missing filter file. A later
getblockfiltercall then reports index corruption.Fix: Use
index_util::LookUpOne()when the block filter index starts or rewinds and when CoinStats rewinds.If the height entry belongs to a different block, the helper reads the preserved hash entry in its stored format.
Save the next block filter position in the same database batch as the new height entry, so writes after a restart append past the filters the index still references.
Read the committed tip's filter at startup and verify its payload checksum before accepting the tip.
Fixes #34261
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion · Crash replay leaves duplicate filter payloads unreclaimed
Replaying persisted entries after an unclean restart can leave duplicate filter payloads unreclaimed, even without a reorg, because the saved append position now advances beyond the committed locator.
Location:
src/index/blockfilterindex.cpp:265(head).🔵 Suggestion · Fatal tip-filter failures lack
InitError()and rebuild guidanceMissing or corrupt committed-tip filters now stop startup without
InitError()or rebuild advice, chiefly affecting daemon and GUI use because foregroundbitcoindprints the log line.Location:
src/index/blockfilterindex.cpp:125(head).🔵 Suggestion ·
rpc_getblockfilter.pymisses checksum-invalid startup recordsA startup check reduced to file existence would still pass the new regression test, leaving readable tip-record corruption uncovered.
Location:
test/functional/rpc_getblockfilter.py:90(head).🔵 Suggestion · Post-restart range checks never traverse the recovered hash entries
Only single-block calls follow restart, so the test never checks a range whose tip matches the height index but whose recovered ancestors require hash fallback.
Location:
src/test/blockfilter_index_tests.cpp:257(head).Review coverage was incomplete.
Reviewed:
fb1c51158ce5· Review report · Previous reportspermalink
nit: could be a
constfunction (not related to this diff)CoinStatsIndex::RevertBlock has almost the same code. It likely has the same bug.
I was thinking of upstreaming these separately, but you're right, they're basically the same bug, so I added the
CoinStatsequivalent here too.I also checked the other indexes, and block filters and
CoinStatsseem to be the only ones using this height/hash key scheme.Concept ACK
This fixes index corruptions from unclean shutdowns while a reorg happens before restart.
There's a minor issue flagged by ralph as well, which is basically
The following test characterizes the behavior:
This patch fixes it:
Rebased and added a functional test for the abort that can happen when the block filter index rewinds after an unclean restart. The unit test continues through the same rewind, mines another block, and verifies that its filter header builds on the correct parent. I also took @andrewtoth’s suggestion, extending the fix to save the next write position with every filter entry and simplifying the test that reproduces filter data being overwritten after restart.
Edit: The node now also reads the committed tip’s filter at startup and refuses to start if the record is missing or its payload checksum doesn’t match.