Review report

bitcoin/bitcoin: PR #36735

4 suggestions

Optional improvements

Link

[suggestion] · Pending-unlink cancellation lacks regression coverage

The new retry test never writes into a pending file, so it would not catch removal of the cancellation that protects reused block files.

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

Details and suggested fix

prune_flush_failure finishes all mining before the failed prune flush and goes directly from restoring the tip file to FORCE_FLUSH. Its single cursor is always MaxBlockfileNum(), which pruning excludes, so it cannot exercise cancellation of a pending unlink. With two cursors after snapshot validation, an otherwise prune-eligible lower NORMAL cursor file can be selected and its size reset to zero, allowing a lower-height block write to reuse it. Without this erase, a later successful index write would still pass that file to UnlinkPrunedFiles(). Add a focused two-cursor regression that leaves the lower cursor file pending after an early flush failure, writes a block into it, then flushes without selecting that reused file for pruning again. Assert that the block file survives and the block reads back, while another pending, unused file is deleted.


Link

[suggestion] · Pending-unlink failure handling is split across classes

The ordering is correct today, but dropping pending deletions with a failed dirty batch relies on coordinated implementations in Chainstate and BlockManager.

Location: src/validation.cpp:2865 (head).

Details and suggested fix

FlushStateToDisk() exchanges the pending set immediately before calling WriteBlockIndexDB(), which clears the dirty sets before the potentially throwing WriteBatchSync(). A future change to retain dirty entries for retry must also update the caller's pending-set handling or risk losing deletions again. Move the exchange into WriteBlockIndexDB() beside the dirty-set drains and return the file numbers only after WriteBatchSync() succeeds, leaving the caller responsible for unlinking them. This localizes the coupled lifetime while preserving current behavior: early disk-space or block-file failures leave files pending, and an index-write exception returns no files for unlinking. Document that invariant on the member.


Link

[suggestion] · The retry test does not cover deferred deletion scheduling

The immediate forced retry leaves untested the rule that pending deletions must not trigger a write on their own.

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

Details and suggested fix

prune_flush_failure restores the tip file and immediately forces the next write. With this fixture's -prune=1 target and the default manual height of zero, a FlushStateMode::NONE call has no pruning, cache, periodic, or force reason to write, even though deletions remain pending. Insert that call after restoring the file and resetting state. Check that it succeeds, that the database still records file 0's size as pruned_size, and that both pruned files still exist. Keep the existing forced-retry assertions afterward. This would detect adding a nonempty pending set to should_write, which the current assertions would not distinguish.


Link

[suggestion] · The pending-unlink scheduling rationale is undocumented

The exchange comment explains index-write failure handling, but not why pending files intentionally wait for an independently triggered write.

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

Details and suggested fix

Add a member comment explaining that m_files_to_unlink contains pruned file numbers awaiting deletion after the block-index write that marks them pruned, and that retained entries deliberately do not force another write. This scheduling rule matters after early disk-space or block-file failures: using the nonempty set as a write trigger would make subsequent per-block flush calls retry that work rather than wait for another write reason. The current exchange-site comment documents only why pending entries are discarded with a failed index batch.


Coverage details