WIP: refactor: pass BlockManager to ChainstateManager

bitcoin/bitcoin: PR #36739

4 suggestions

Optional improvements

Link

[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).

Details and suggested fix

BlockManager::LoadBlockIndex() polls blockman.m_interrupt, whereas CompleteChainstateInitialization() classifies a failed load using chainman.m_interrupt. With distinct objects, signalling only the former during loading can return FAILURE with "Error loading block database" instead of INTERRUPTED; signalling only the latter does not cancel those inner BlockManager loops. The old constructor supplied one interrupt to both managers. Remove the separate interrupt argument and initialize m_interrupt from blockman.m_interrupt to preserve that invariant and eliminate the duplicated choice at call sites.


Link

[suggestion] · Description promises encapsulation changes absent from this revision

The description promises accessor and ImportBlocks changes absent from this revision, misrepresenting the scope of the ownership refactor.

Location: src/validation.h:1049 (head).

Details and suggested fix

BlockManager still declares both friends, validation still writes m_check_for_pruning directly, and ImportBlocks remains in node/blockstorage.cpp with a direct assignment to m_blockfiles_indexed. None of RequestPrune(), MarkBlockIndexDirty() or SetBlockfilesIndexed() exists here. The ownership change does not require those encapsulation changes, which may belong to another stacked revision. Update the description to match the three commits in this revision rather than describing interfaces and relocation that are not included.


Link

[suggestion] · Kernel tests leave the final-owner Context lifetime uncovered

Existing kernel tests retain an external Context until after ChainMan destruction, 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).

Details and suggested fix

m_context is last-declared, so the explicit resets must run before its last reference is released. create_chainman() already destroys its local options, but its callers keep their Context handles alive, masking removal of internal context ownership. Add a regtest case that returns a ChainMan from a scope containing the context, options and only external notification-observer owner. Keep a weak_ptr to the observer and assert it survives that scope. Process REGTEST_BLOCK_DATA[0], check new_block and the resulting chain height, then destroy ChainMan and assert the observer expires. This deterministically tests retention; sanitizers may catch destruction-order regressions too, but the case will not detect every incorrect ordering deterministically.


Link

[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).

Details and suggested fix

feature_pruning.py::manual_test already deletes blk00000.dat through blk00003.dat, which sets the persisted prunedblockfiles flag. Its next start uses -prune=550, so removing this rejection guard would leave the fixture's assertions unchanged. After the file-deletion assertions, stop the node and use assert_start_raises_init_error with -prune=0, expecting the "You need to rebuild the database using -reindex to go back to unpruned mode" rejection and its normal recovery suffix. Then continue with the existing pruning-enabled start. Without -reindex, the failed attempt preserves the flag and reuses the existing chain.


Coverage details