Review report

bitcoin/bitcoin: PR #36739

3 suggestions

Optional improvements

Link

[suggestion] · Prune retry coverage misses the block-index write failure boundary

The new test fails before the pending-deletion exchange, so it does not protect the ordering that prevents a later write from deleting files whose prune metadata was never persisted.

Location: src/node/blockstorage.cpp:843 (head).

Details and suggested fix

prune_flush_failure makes FlushChainstateBlockFile() fail, so WriteBlockStorage() returns before both the exchange and WriteBlockIndexDB(). The latter clears its dirty sets before writing the batch. Moving the exchange below it would leave pending deletions queued after a recoverable, unapplied batch failure. A later successful write, including the shutdown flush, could then unlink files still marked BLOCK_HAVE_DATA on disk and prevent the next startup from loading the block index. Add a focused test using block_tree_db_params.testing_env to fail the log append before the batch is applied, then clear the fault and retry without adding dirty entries. Check that the files remain and persisted file info is unchanged. Do not inject a Sync() failure, because LevelDB rejects subsequent writes in that case.


Link

[suggestion] · Pending-deletion scheduling is untested after the failed prune flush

The forced retry does not distinguish deferred cleanup from eager retries, or verify that an ordinary periodic write consumes pending deletions.

Location: src/test/chainstate_write_tests.cpp:210 (head).

Details and suggested fix

prune_flush_failure restores access before its only retry and explicitly uses FORCE_FLUSH. Making pending deletions force a write, or skipping their cleanup specifically on PERIODIC writes, would leave those assertions unchanged. This scheduling matters because ConnectTip() calls IF_NEEDED for each block. Before restoring the inaccessible file, call FlushStateToDisk(state, FlushStateMode::NONE) with a fresh state and require success, a valid state, and both pruned files still present. The fixture's -prune=1 selects the manual-pruning target, so automatic pruning does not independently force a write. In a separate retry case, restore access, advance m_clock beyond DATABASE_WRITE_INTERVAL_MAX, and call PERIODIC; require zero persisted size and deletion of both files. Keep the existing forced-retry case as well.


Link

[suggestion] · RequestPrune() leaves its locking contract unstated

RequestPrune() omits the cs_main annotation and assertion needed to diagnose unlocked use of its non-atomic flag.

Location: src/node/blockstorage.h:466 (head).

Details and suggested fix

BeginTargetPrune() reads and clears m_check_for_pruning under cs_main, but the new public setter has neither EXCLUSIVE_LOCKS_REQUIRED(::cs_main) nor AssertLockHeld(::cs_main). Add both to RequestPrune() and propagate the requirement to Chainstate::PruneAndFlush(), which calls the setter before FlushStateToDisk() acquires its internal lock. The sole current call path in init.cpp already holds cs_main, so this enforces the public API's synchronization requirement without changing that caller's behavior.


Coverage details