Review report

bitcoin/bitcoin: PR #36621

2 suggestions

Optional improvements

Link

[suggestion] · PruneBlockFiles documents the wrong upper bound

The new precondition excludes MaxBlockfileNum(), but the helper accepts that endpoint and migrated wallet tests rely on it.

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

Details and suggested fix

MaxBlockfileNum() returns the largest cursor file number, not a file count. The bitmap has MaxBlockfileNum() + 1 entries, and scan_for_wallet_transactions forces a rollover then directly prunes newTip's file, which is that maximum. Tightening the bitmap to match the comment would make this existing test throw std::out_of_range. The production selectors intentionally stop below the maximum, but that selection policy is not a restriction in this helper. Document the initialized file range as [0, MaxBlockfileNum()], state that numbers outside it throw before any block-index entry changes, and leave pruning eligibility to callers.


Link

[suggestion] · Out-of-range test cannot detect partial pruning before the throw

The {-1} unit-test case would still pass if invalid file numbers were rejected only after pruning valid members of a mixed batch.

Location: src/test/blockmanager_tests.cpp:194 (head).

Details and suggested fix

The current implementation validates the entire set before changing the index, but {-1} does not protect that ordering. If bitmap construction instead skipped invalid numbers, the final m_blockfile_info.at(-1) would still throw without selecting any live entry, leaving these assertions satisfied. Keep this case and add BOOST_CHECK_THROW(blockman.PruneBlockFiles({file2, file2 + 1}), std::out_of_range). After the two forced rollovers, file2 is the newest initialized file and file2 + 1 is out of range. The ordered set places the valid file first, exposing an implementation that prunes each member before validating the rest. After the exception, check that tip2 retains its data flag, file number and positions, its file-info size remains nonzero, and the dirty block-index set remains empty.


Coverage details