1 minor finding · 5 suggestions
Findings
[minor] · Discarding a wiping block manager loses the pending chainstate wipe
Discarding a disk-backed wiping block manager before attachment makes a populated datadir fail to reopen with defaults; no current in-tree caller producing this sequence was found.
Location: src/kernel/bitcoinkernel.cpp:1361 (head).
Details and suggested fix
On a cleanly closed, populated datadir, btck_block_manager_create wipes the block index immediately, but the matching chainstate wipe depends on the transient m_wipe_block_tree_db flag. Destroying that manager before attachment leaves the coins DB intact. A default reopen restores only m_blockfiles_indexed = false, so LoadChainTip cannot resolve the coins best block and creation fails before btck_chainstate_manager_import_blocks can run. An active assumeutxo snapshot with a recognized base instead reaches the pre-existing unchecked lookup of that now-missing base.
Base already had a failure or interruption window within combined creation; this API exposes the state across successful create/destroy calls. A context-mismatch rejection alone does not lose the request because the original handle remains reusable. Document that callers must attach a wiping manager or explicitly request btck_chainstate_manager_options_update_wipe_chainstate_db on reopening, and add a destroy-and-reopen test for that recovery.
Optional improvements
[suggestion] · One-use tests can pass through unrelated DB-lock failures
The new lifecycle assertions do not distinguish the documented consumption rules from context rejection or a live coins-database lock.
Location: src/test/kernel/test_kernel.cpp:912 (head).
Details and suggested fix
The mismatch case destroys the rejected block manager immediately, so consuming it before the context check would still satisfy the assertion. The reuse check keeps the first ChainMan alive. Without m_used, another creation can fail opening the same disk-backed coins DB, and the wrapper converts that null result into the expected std::runtime_error. Add a successful matching-context retry after mismatch and a rejected retry after destroying the first chainstate manager. Also test consumption after a same-context load failure: independent in-memory block trees can isolate a deliberately held coins-DB lock, then releasing the lock before retrying removes the original failure cause. Check that the consumed manager remains rejected while a fresh one succeeds.
[suggestion] · Independent data directories lack a persisted-state compatibility contract
The split options permit incompatible index and chainstate pairings without documenting the requirement; no current in-tree caller was found doing this, and the loader's unchecked snapshot assumption predates this PR.
Location: src/kernel/bitcoinkernel.h:1392 (head).
Details and suggested fix
Previously one data_dir supplied both the chainstate and blocks/index; now each options object selects its own root, and btck_chainstate_manager_create checks only context identity. Pairing existing coins with a fresh or stale index can fail in LoadChainTip. With an active assumeutxo snapshot, a recognized base hash missing from that index, and no wipe requested, loading instead dereferences the null base lookup in BlockManager::LoadBlockIndex. Document in the creation and options contracts that the persisted chainstate must be compatible with the supplied index, including its snapshot base, and that pairing an existing chainstate with a new index requires a chainstate wipe.
[suggestion] · Independent cache setters do not enforce a shared total
Setting only the chainstate total to 4 MiB leaves 5.5 MiB of combined configured caches, despite the header describing shares of the same total.
Location: src/kernel/bitcoinkernel.cpp:1256 (head).
Details and suggested fix
The block-manager setter stores only CacheSizes{total}.block_tree_db, while the chainstate setter independently determines the coins shares. An untouched block manager retains its default 2 MiB allocation; a 4 MiB chainstate total therefore adds 3.5 MiB rather than coordinating a combined 4 MiB budget. The discrepancy is limited: min(total / 8, 2 MiB) makes every block-manager total of at least 16 MiB equivalent. Document that the two values are independent and that callers must coordinate both setters to obtain the intended combined cache allocation, rather than implying that the API maintains a shared total.
[suggestion] · Lifetime reads retain an extra context owner
Neither lifetime test leaves BlockMan as the sole context owner, so the new post-chainstate read coverage does not isolate BlockMan's context ownership.
Location: src/test/kernel/test_kernel.cpp:1246 (head).
Details and suggested fix
btck_block_manager_tests keeps its Context handle alive during the reads. The reverse-destruction test releases that handle but keeps ChainMan, including its separate m_context, alive. Block reads access context-owned chain parameters for block magic and proof-of-work checks. Hold the first test's context in a std::optional and reset it after the chainstate-manager scope ends, before the existing block and spent-output assertions. The helper-created options have already been destroyed then, so this exercises BlockMan's own ownership and would allow ASan to detect a dangling-reference regression.
[suggestion] · Pruning restarts do not cover rejection with pruning disabled
The rewritten prune-mode guard retains a pre-existing coverage gap: pruning tests restart with pruning enabled, so they do not verify rejection of a pruned datadir reopened without pruning.
Location: src/node/chainstate.cpp:57 (head).
Details and suggested fix
feature_pruning.py::manual_test confirms that block files were removed, then restarts successfully with -prune=550. Before that restart, stop the node and use assert_start_raises_init_error with -prune=0, matching the specific 'go back to unpruned mode' diagnostic with partial matching if needed. Keep the successful pruning-enabled restart afterward. This adds the missing rejecting case for the guard now reading BlockManager::IsPruneMode() directly, while retaining the accepting case.