mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:17:38 +00:00
validation: validate assumeutxo snapshots with a single chainstate #37094
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!37094
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-12-au-verifier"
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?
Assumeutxo currently needs two
Chainstateobjects, and validation code has to pay attention to that everywhere with chainstate roles, target blocks, a second set of block index candidates and role-aware notifications. This PR removes all of it and keeps the feature complete, including the background validation of the snapshot.The idea is simple. Validating a snapshot never really needed chain selection. It connects a fixed list of blocks and compares one hash at the end, so it needs neither a
Chainstatenor a place in validation.What this change does:
Chainstateagain.loadtxoutsetmoves the coins of the snapshot into it in place.node::HistoricalReplayVerifier, validates the snapshot on its own thread. It connects the blocks before the snapshot to the coins the chainstate had before and compares the UTXO set hash at the end.validation.cppshrinks by more than 500 lines and the kernel sources by about 50. Outside of tests the code gets smaller overall, and that includes the new verifier. With this, assumeutxo stops being something most validation changes have to take into account.The concerns people raised about the implementation, and how this answers them:
ConnectBlock()with its own coins, andConnectBlock()no longer knows anything about snapshots.cs_mainis held for minutes while the UTXO set is hashed. The verifier hashes without holding it.BlockConnectedwithout a role, and indexes follow a single accessor.A few things to note:
Chainstateobject. While a snapshot is validated there are still two coins databases on disk, in the same directories as on master, andgetchainstatesstill reports both. A datadir with a loaded snapshot needs no migration.loadtxoutsetstill fills a temporaryChainstatewith the coins of the snapshot and then moves them into the real one. The temporary object never leaves the loader.The following behavior changes compared to master are intentional:
loadtxoutsetno longer accepts a snapshot while the node's tip is on a stale branch. The snapshot's block has to be a descendant of the tip. Background validation then only ever connects blocks, so the cases where it first had to disconnect a stale branch are gone.ProcessNewBlock()advances the background validation.getindexinforeports them as not synced until they have reached the tip. The sync thread reads the verifier's progress fromChainstateManager, the same way the loop already reads the chain. If this sounds like a architectural regression, #24230 moves that loop out of index code into the node, and this wait would move with it.-prunetarget in half while a snapshot is validated. A prune lock protects the blocks the verifier still needs, and the pruning code has no snapshot rule left.Also, this is my fourth big iteration of this concept and the one that I think strikes the best balance but a lot of tweaks to the approach are possible depending on what people prefer. And there are lots of good follow-ups that I left out here like for example shrinking kernel awareness to almost none is possible at the cost of expanding the interface of the kernel. Or connecting the historical blocks with minimized holding of
cs_mainand keeping requests for those blocks from delaying blocks for the tip.I couldn't check everything yet, but for now fixes #37056, fixes #37064, fixes #37070, fixes #37071, fixes #37079, fixes #37050, fixes #37053, fixes #37072, fixes #37076, fixes #37078, fixes #36495, fixes #36562, fixes #36939, fixes #32029.
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.Conflicts
Reviewers, this pull request conflicts with the following ones:
loadtxoutsetRPC with a startup arg by l0rinc)-Wunusedby fanquake)m_blocks_unlinked, fix anothernSequenceIdissue by mzumsande)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
LLM Linter (✨ experimental)
Possible typos and grammar issues:
src/node/historical_verify.cpp:As below a chain tip→As with the chain tip[the original phrasing is unclear]Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):src/rpc/blockchain.cpp:chainman.ActivateSnapshot(afile, metadata, false)2026-12-03 15:59:34
3 additional verified findings in the Review report.
🟠 Minor · Replay completion leaves the snapshot base's undo unflushed
If replay writes the snapshot base's undo into the current
ASSUMEDfile, completion persists its index and coins without flushing that file, so a power loss can leave local state requiring a rebuild.Location:
src/validation.cpp:5989(head).🟠 Minor · The
loadtxoutsetindex restart can double-count coinstatsWith
-coinstatsindex, a timing-dependentloadtxoutsetrestart can reprocess blocks over an uncommitted in-memory MuHash, corrupting index statistics; production occurrence is unconfirmed.Location:
src/rpc/blockchain.cpp:3580(head).🟠 Minor · Validated snapshot promotion treats cleanup failure as fatal
A stray file in the old
chainstatedirectory now prevents startup after snapshot validation, whereas the base version could promote the snapshot and only warn about incomplete cleanup.Location:
src/node/chainstate.cpp:161(head).🔵 Suggestion · Index tests do not exercise intermediate replay flushes
The new index wait is not tested against both unflushed replay progress and persisted progress followed by an unclean restart.
Location:
src/index/base.cpp:250(head).🔵 Suggestion · Operator-visible assumeutxo changes lack a release note
The PR changes snapshot-loading preconditions, pruning storage expectations, and index sync reporting without a release note for operators.
Location:
doc/assumeutxo.md:23(head).🔵 Suggestion · The
loadtxoutsethelp omits its new preconditionsThe assumeutxo guide states the new startup and ancestry requirements, but
help loadtxoutsetomits them.Location:
src/rpc/blockchain.cpp:3510(head).Review coverage was incomplete.
Reviewed:
29ed3015f8dc· Review report · Previous reportspermalink
Nice Work,
I read through the description and skimmed the code, this addresses my concern in bitcoin#36598 about components not being able to hold a stable Chainstate handle.
@fjahr I think this is essentially a rewrite of AssumeUTXO's background validation, we first need to align on whether we want to keep the feature at all, I think it's otherwise, given the sentiment in (#36598).
If we do decide to keep AssumeUTXO, I'm Approach ACK on doing it this way rather than maintaining two Chainstate objects.
I'm open to this, but it would be good to compare it with dropping background validation (which is my current preference).