Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. |
ChainMan declares m_context last, which destroys it before the ChainstateManager that refers into it. Reset the chainstate manager explicitly, making the order independent of member declaration order.
Create the BlockManager first and pass it in by reference. NodeContext and the kernel own both and destroy ChainstateManager first. The block tree database opens before the script verification threads start, which swaps their startup log lines.
The flag duplicated the BlockManager's prune mode. Init and the test setup copied it, and the kernel left it false. Check the BlockManager directly, keeping one source of truth before the kernel can enable pruning.
c43a937 to
bfb52b5
Compare
musaHaruna
left a comment
There was a problem hiding this comment.
Concept ACK.
This follows the ownership split we discussed in #35627: the caller owns BlockManager, and ChainstateManager borrows 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 of manual_test?
- # stop node, start back up with auto-prune at 550 MiB, make sure still runs
- self.restart_node(node_number, extra_args=["-prune=550"])
+ self.stop_node(node_number)
+ node.assert_start_raises_init_error(
+ extra_args=["-prune=0"],
+ expected_msg="You need to rebuild the database using -reindex to go back to unpruned mode."
+ f" This will redownload the entire blockchain.{os.linesep}"
+ "Please restart with -reindex or -reindex-chainstate to recover.",
+ )
+ self.start_node(node_number, extra_args=["-prune=550"])| @@ -6223,11 +6223,11 @@ static ChainstateManager::Options&& Flatten(ChainstateManager::Options&& opts) | |||
| return std::move(opts); | |||
| } | |||
|
|
|||
| ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options) | |||
| ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager& blockman) | |||
There was a problem hiding this comment.
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 false because it was asked to stop. The chainstate loader then checks chainman.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 blockman would prevent this mismatch.
-ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager& blockman)
+ChainstateManager::ChainstateManager(Options options, node::BlockManager& blockman)
: m_script_check_queue{/*batch_size=*/128, std::clamp(options.worker_threads_num, 0, MAX_SCRIPTCHECK_THREADS)},
- m_interrupt{interrupt},
+ m_interrupt{blockman.m_interrupt},The declaration and callers would also need the interrupt argument removed.
|
Concept ACK |
| std::unique_ptr<FeeRateEstimatorManager> fee_estimator_man; | ||
| std::unique_ptr<PeerManager> peerman; | ||
| std::unique_ptr<TorController> tor_controller; | ||
| std::unique_ptr<BlockManager> blockman; |
There was a problem hiding this comment.
b9a83c7: refactor: pass BlockManager to ChainstateManager
Consider annotating this.
| std::unique_ptr<BlockManager> blockman; | |
| //! Caller owns BlockManager. It must outlive chainman, which holds a reference into it. | |
| std::unique_ptr<BlockManager> blockman; |
|
|
||
| ~ChainMan() | ||
| { | ||
| // Both hold references into m_context |
There was a problem hiding this comment.
b9a83c7: refactor: pass BlockManager to ChainstateManager
Consider making ordering concerns clear here too
| // Both hold references into m_context | |
| // Destroy chainman before blockman. ChainstateManager holds a | |
| // BlockManager reference, and both hold references into m_context. |
|
tACK bfb52b5 Agree 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. |

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.