blockstorage: fix partial-mask assertions and genesis availability checks #36971

Open
l0rinc wants to merge 5 commits from l0rinc/block-data-availability-mask into master AGit
l0rinc commented 2026-11-24 20:26:40 +00:00 (Migrated from github.com)

Problem: CheckBlockDataAvailability checks whether the upper block has any requested bit. GetFirstBlock requires every requested bit, so a partial match can reach its assertion. At genesis, the existing undo exception can reject an undo-only request or accept a request with missing block data. It also misses ranges containing only genesis.

Fix: Require every requested bit on each block in the range, except that genesis needs no undo data. An empty mask now succeeds for a valid range because it requests no bits. Both index-startup calls supply nonempty masks.

**Problem:** `CheckBlockDataAvailability` checks whether the upper block has any requested bit. `GetFirstBlock` requires every requested bit, so a partial match can reach its assertion. At genesis, the existing undo exception can reject an undo-only request or accept a request with missing block data. It also misses ranges containing only genesis. **Fix:** Require every requested bit on each block in the range, except that genesis needs no undo data. An empty mask now succeeds for a valid range because it requests no bits. Both index-startup calls supply nonempty masks.
DrahtBot commented 2026-11-24 20:26:50 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK jeanpablojp

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #35731 (Indexes: Harden the flush-error notification invariant by arejula27)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36971 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36971.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36971#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36971#pullrequestreview-6079586836) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36946](https://github.com/bitcoin/bitcoin/pull/36946) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36946.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko) * [#35731](https://github.com/bitcoin/bitcoin/pull/35731) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35731.svg"></sub> (Indexes: Harden the flush-error notification invariant by arejula27) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 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).


Reviewed: 41851dc3c325 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:5cfea17ba7610fa178d67839cc6796a49c08c7f7be4d932c06b37a8bd66e2a40:3329223fb40bbbe44124b0523f0fa08f23650d06836368f60e45a38d2db02971 --> <!-- ralph-base:74f3ed9021e853aa14a402ed0ceef78544c5b4a7 --> <!-- ralph-head:41851dc3c325d656e33d72b79f3770a801f923e7 --> <!-- ralph-case:da572d7c867de4d42e80e137fcc512403999c2826228e46d51f23f0e9e461ea2 --> **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/41851dc3c325d656e33d72b79f3770a801f923e7/src/test/blockmanager_tests.cpp#L164>) (head). <!-- Review tier: sensitive --> --- Reviewed: [`41851dc3c325`](<https://git.fish.foo/bitcoin/bitcoin/commit/41851dc3c325d656e33d72b79f3770a801f923e7>) · [Review report](<https://review.fish.foo/report/36971-41851dc3c325d656e33d72b79f3770a801f923e7-3079-1.html>) · [Previous reports](<https://review.fish.foo/traces/36971/>) [permalink](<https://review.fish.foo/report/36971-41851dc3c325d656e33d72b79f3770a801f923e7-3079-1.html>)
jeanpablojp (Migrated from github.com) reviewed 2026-11-26 19:33:45 +00:00
jeanpablojp (Migrated from github.com) left a comment

tACK 41851dc3c3

Left 2 small nits.

tACK 41851dc3c325d656e33d72b79f3770a801f923e7 Left 2 small nits.
Lines 417-418
jeanpablojp (Migrated from github.com) commented 2026-11-26 19:33:45 +00:00

nit: could the comment say every flag is required, like the PR description does?

    //! Check if all blocks in the [upper_block, lower_block] range have all
    //! block_status flags set.
nit: could the comment say every flag is required, like the PR description does? ```suggestion //! Check if all blocks in the [upper_block, lower_block] range have all //! block_status flags set. ```
jeanpablojp (Migrated from github.com) commented 2026-11-26 19:33:45 +00:00

I think the two empty-mask checks Ralph suggested make sense here. Feel free to ignore, though.

    BOOST_CHECK(!blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BLOCK_HAVE_MASK));
    BOOST_CHECK(blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BlockStatus{}));
    BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *last_pruned_block, BlockStatus{}));
I think the two empty-mask checks Ralph suggested make sense here. Feel free to ignore, though. ```suggestion BOOST_CHECK(!blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BLOCK_HAVE_MASK)); BOOST_CHECK(blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BlockStatus{})); BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *last_pruned_block, BlockStatus{})); ```
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36971
No description provided.