mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:26:38 +00:00
refactor: pass BlockManager to ChainstateManager #36739
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!36739
Loading…
Reference in a new issue
No description provided.
Delete branch "blockstorage-chainstate-separation"
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?
ChainstateManagercreates and owns itsBlockManager, which means block storage can't exist without chainstate management. #35627 discussed moving that ownership out ofChainstateManager, and the kernel needs it to configure, read and prune block storage on its own.NodeContextand the kernel now create theBlockManagerfirst, pass it toChainstateManagerby reference and destroyChainstateManagerfirst.The first commit makes the kernel's
ChainMandestroy itsChainstateManagerexplicitly. On masterChainMandeclares its context last, which destroys the context before theChainstateManagerthat refers into it. Nothing reads through those references during teardown, so this changes no behavior, but the order no longer depends on how the members are declared.The last commit removes
ChainstateLoadOptions::prune. It duplicated theBlockManager's prune mode, and the kernel never set it. Once the kernel can prune (#36856), that would make it refuse to reopen a data directory it had pruned.The only behavior change to my knowledge is startup log order, because the block tree database opens before the script verification threads start.
An earlier version of this PR also moved
ImportBlocksand replacedBlockManager's friend declarations. I've taken them out as they're not relevant to this, but I think together better suited for a change that removes thenode/blockstorage -> validationcircular dependency (#36858)The kernel side is #36854.
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:
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.
🔵 Suggestion · Constructor permits inconsistent startup interrupts
No current caller supplies different interrupts, but the new constructor permits a mismatch that can delay cancellation inside block-index loading or report an interruption as a database-load failure.
Location:
src/validation.cpp:6226(head).🔵 Suggestion · Description promises encapsulation changes absent from this revision
The description promises accessor and
ImportBlockschanges absent from this revision, misrepresenting the scope of the ownership refactor.Location:
src/validation.h:1049(head).🔵 Suggestion · Kernel tests leave the final-owner Context lifetime uncovered
Existing kernel tests retain an external
Contextuntil afterChainMandestruction, so they do not exercise the final-owner lifetime affected by this refactor; internal context retention itself predates the PR.Location:
src/kernel/bitcoinkernel.cpp:488(head).🔵 Suggestion · Pruning tests miss the pruned-to-unpruned startup guard
Although this rewrite preserves node startup behavior, the existing manual-pruning test would not detect accidental acceptance of a pruned database with
-prune=0.Location:
src/node/chainstate.cpp:57(head).Review coverage was incomplete.
Reviewed:
bfb52b50f5b7· Review report · Previous reportspermalink
Concept ACK.
This follows the ownership split we discussed in #35627: the caller owns
BlockManager, andChainstateManagerborrows it. I think this is a useful first step toward separating storage from validation.Could we cover this in
feature_pruning.py, at the end ofmanual_test?Could we drop the separate interrupt argument and use
blockman.m_interrupt? Current callers already share the same signal, but the constructor allows different ones.For example, if only storage’s signal is interrupted, block-index loading can return
falsebecause it was asked to stop. The chainstate loader then checkschainman.m_interrupt. If that separate signal is still clear, it reports “Error loading block database”, even though the database is healthy.Taking the signal from
blockmanwould prevent this mismatch.The declaration and callers would also need the interrupt argument removed.
Concept ACK
b9a83c74bd: refactor: pass BlockManager to ChainstateManagerConsider annotating this.
b9a83c74bd: refactor: pass BlockManager to ChainstateManagerConsider making ordering concerns clear here too
tACK
bfb52b50f5Agree that this is a nice first step towards decoupling storage and validation. Aside from logging order changes noted by OP, I did not find that this intended refactoring led to any behavior changes.
Left minor suggestions that are non-blocking.