blockstorage: fix partial-mask assertions and genesis availability checks

bitcoin/bitcoin: PR #36971

1 suggestion

Optional improvements

Link

[suggestion] · Empty-mask availability behavior has no test coverage

The unit tests omit both paths that now accept an empty mask; both index-startup callers currently use nonempty masks.

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

Details and suggested fix

The previous any-bit guard rejected an empty mask, but the new implementation accepts it through the equal-endpoint return or a GetFirstBlock walk. Every existing availability assertion uses a nonempty mask, so an explicit if (!block_status) return false; would go undetected. After the pruning checks, add these assertions to cover both paths and show that missing block data is irrelevant when no bits are requested:

BOOST_CHECK(blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BlockStatus{}));
BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *last_pruned_block, BlockStatus{}));

Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The API originated as an index-startup pruning guard, not as a documented general-purpose status predicate. The original startup refactor sought to avoid repeating availability checks for each index, move verification off the main thread, and perform it even with reindexing enabled.

This establishes the original operational purpose: determining whether indexes can sync from locally available block data while reducing startup work. It does not establish semantics for arbitrary status bits or an empty request.

Source 1 · Source 2

Multiple-status support was introduced because checking BLOCK_HAVE_DATA alone allowed coinstatsindex and blockfilterindex to begin syncing without required undo data and fail later. The stated goal was to check every index's necessary data before starting synchronization.

For the historically motivated combined mask, block data and undo data are both requirements, not alternatives. Requiring all requested availability bits preserves that stated purpose. The inspected proposal does not extend its rationale to non-availability flags or zero masks.

Source 1 · Source 2

The multiple-status change deliberately exempted genesis from undo availability. Its comments distinguish expected missing genesis undo from genuinely missing data and say that all other required block data must still be available through genesis.

The current change retains this historical exception while checking the remaining requested bits separately. Genesis was not intended to waive block-data requirements merely because undo was requested.

Source 1

Ralph's inferences

The best-supported reading is an availability-specific API implemented using a general mask mechanism, rather than an established promise to answer every possible BlockStatus query. The base documentation says availability is defined by the status mask, and the underlying walker requires all mask bits, but the inspected historical tests exercise only BLOCK_HAVE_DATA and BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO.

The all-requested-bits interpretation has support in the existing walker contract and availability requirements. Support for arbitrary non-availability flags is suggested by the interface's generality, but is not explicitly justified by the inspected history.

Source 1

The change preserves the documented startup purpose and genesis-undo exception, while broadening the behavior implemented for edge inputs. In particular, the base rejects an empty mask immediately, whereas the head accepts it for a valid range; the head also applies full-bit checks to non-availability flags and permits undo-only genesis requests.

It is therefore more precise to describe this as preserving the historically motivated availability contract while extending or regularizing previously unsupported edge semantics—not as merely restoring a historically explicit general-query contract. The inspected history does not establish deliberate author intent concerning those broader inputs.

Source 1 · Source 2