net: serve MSG_BLOCK by stripping witnesses in place #36548

Open
l0rinc wants to merge 4 commits from l0rinc/msg-block-serving into master AGit
l0rinc commented 2026-10-16 01:08:15 +00:00 (Migrated from github.com)

Problem: To send a MSG_BLOCK reply from disk, a node currently decodes the block and serializes it again without witnesses.
For MSG_WITNESS_BLOCK, it already sends the stored bytes directly.
Serving MSG_BLOCK efficiently also matters for the proposed witnessless initial block download. #36476

Fix: For MSG_BLOCK replies from disk on non-Signet chains, read the block into an owned byte buffer and check the header’s proof of work and expected hash.
Walk the serialized transactions directly and strip their witnesses in place.
Signet still uses ReadBlock to verify the Signet solution.
Header checks now run before transaction parsing, so if both the header and transaction data are corrupt, the node may log a different error.

Performance:

Block Before After Speedup
block413567 3.204 ms 0.369 ms 8.7×
Same block with synthetic witnesses 8.944 ms 1.026 ms 8.7×

The synthetic fixture adds a 512-byte witness item and an empty item to every input.

Related work: This extends the path that sends witness blocks directly from disk. #13151
Earlier work identified unnecessary transaction hashing when serving historical blocks. #13011 discussion · #13098
The implementation also builds on bulk block reads. #31551

**Problem:** To send a `MSG_BLOCK` reply from disk, a node currently decodes the block and serializes it again without witnesses. For `MSG_WITNESS_BLOCK`, it already sends the stored bytes directly. Serving `MSG_BLOCK` efficiently also matters for the proposed witnessless initial block download. [#36476](https://github.com/bitcoin/bitcoin/issues/36476) **Fix:** For `MSG_BLOCK` replies from disk on non-Signet chains, read the block into an owned byte buffer and check the header’s proof of work and expected hash. Walk the serialized transactions directly and strip their witnesses in place. Signet still uses `ReadBlock` to verify the Signet solution. Header checks now run before transaction parsing, so if both the header and transaction data are corrupt, the node may log a different error. **Performance:** | Block | Before | After | Speedup | | --- | ---: | ---: | ---: | | `block413567` | 3.204 ms | 0.369 ms | **8.7×** | | Same block with synthetic witnesses | 8.944 ms | 1.026 ms | **8.7×** | The synthetic fixture adds a 512-byte witness item and an empty item to every input. **Related work:** This extends the path that sends witness blocks directly from disk. [#13151](https://github.com/bitcoin/bitcoin/pull/13151) Earlier work identified unnecessary transaction hashing when serving historical blocks. [#13011 discussion](https://github.com/bitcoin/bitcoin/pull/13011#issuecomment-383145046) · [#13098](https://github.com/bitcoin/bitcoin/pull/13098) The implementation also builds on bulk block reads. [#31551](https://github.com/bitcoin/bitcoin/pull/31551)
DrahtBot commented 2026-10-16 01:08:23 +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 optout21
Stale ACK fametrano

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)
  • #36621 (node: batch block file pruning in a single pass over block index by mutatrum)
  • #36000 (validation: prefetch blocks while connecting by l0rinc)
  • #35731 (Indexes: Harden the flush-error notification invariant by arejula27)
  • #35003 (validation: improve block data I/O error handling in P2P paths by furszy)
  • #32554 (bench: replace embedded raw block with configurable block generator by l0rinc)

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/36548 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36548.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36548#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 | [optout21](https://github.com/bitcoin/bitcoin/pull/36548#issuecomment-7409892524) | | Stale ACK | [fametrano](https://github.com/bitcoin/bitcoin/pull/36548#pullrequestreview-5849889238) | 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) * [#36621](https://github.com/bitcoin/bitcoin/pull/36621) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36621.svg"></sub> (node: batch block file pruning in a single pass over block index by mutatrum) * [#36000](https://github.com/bitcoin/bitcoin/pull/36000) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36000.svg"></sub> (validation: prefetch blocks while connecting by l0rinc) * [#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) * [#35003](https://github.com/bitcoin/bitcoin/pull/35003) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35003.svg"></sub> (validation: improve block data I/O error handling in P2P paths by furszy) * [#32554](https://github.com/bitcoin/bitcoin/pull/32554) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32554.svg"></sub> (bench: replace embedded raw block with configurable block generator by l0rinc) 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 · The Signet restriction on ReadBlockWithoutWitness duplicates reader selection

ReadBlockWithoutWitness makes ProcessGetBlockData repeat the Signet restriction and reports unsupported use as ReadRawError::IO, although no current caller reaches that case.

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


Reviewed: 516378803669 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:e1a29e5e677c47d383756f0fcf8f3760725c91d1104dd3ccb2f333b6217eba26:47880f5569fd2047d249266f337c4f2a509adf7d96c3ccb1c7644c2c2a650bff --> <!-- ralph-base:2f3f6397bb92beccaccce16742f0574d1617fb3e --> <!-- ralph-head:516378803669d42e0dda9e1a29ef8cbc229dcdb0 --> <!-- ralph-case:d859137d9e1244fda827daa054676e909151f70e720609a1ff398c222b41f755 --> **🔵 Suggestion · The Signet restriction on `ReadBlockWithoutWitness` duplicates reader selection** `ReadBlockWithoutWitness` makes `ProcessGetBlockData` repeat the Signet restriction and reports unsupported use as `ReadRawError::IO`, although no current caller reaches that case. Location: [`src/node/blockstorage.cpp:1099`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/516378803669d42e0dda9e1a29ef8cbc229dcdb0/src/node/blockstorage.cpp#L1099>) (head). <!-- Review tier: sensitive --> --- Reviewed: [`516378803669`](<https://git.fish.foo/bitcoin/bitcoin/commit/516378803669d42e0dda9e1a29ef8cbc229dcdb0>) · [Review report](<https://review.fish.foo/report/36548-516378803669d42e0dda9e1a29ef8cbc229dcdb0-3510-13.html>) · [Previous reports](<https://review.fish.foo/traces/36548/>) [permalink](<https://review.fish.foo/report/36548-516378803669d42e0dda9e1a29ef8cbc229dcdb0-3510-13.html>)
DrahtBot commented 2026-10-16 02:21:15 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/38833479928/job/116757258223
LLM reason (✨ experimental): CI failed because IWYU modified includes in src/bench/readwriteblock.cpp, and the formatting check detected uncommitted changes.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/38833479928/job/116757258223</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU modified includes in `src/bench/readwriteblock.cpp`, and the formatting check detected uncommitted changes.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
fametrano commented 2026-10-25 11:41:24 +00:00 (Migrated from github.com)

tACK 0b01ce05e1

I checked that the new MSG_BLOCK reply is byte for byte the old one. On 214 blocks, the head's ReadBlockWithoutWitness matches its ReadBlock plus TX_NO_WITNESS, that old path matches the base's, and btclib, a library I maintain, agrees. The blocks are mainnet 481824, 709632, 774628, 920000 and the bench's 413567, plus 209 regtest blocks with segwit v0 and v1 spends, 1,000 witness items, empty stacks and items, a 3,990,000-byte annex, 300 inputs, 316 outputs, 260 transactions, or no witness. Over P2P, a head node and a base node give the same MSG_BLOCK and MSG_WITNESS_BLOCK payloads for all 209: 208 from disk, and the two successive tips from the recent-block cache.

Each of seven mutants of StripBlockWitness and ReadBlockWithoutWitness fails blockmanager_tests. They range from keeping the marker or the witnesses to skipping the proof-of-work or hash check. The new p2p_getdata case also passes against a base node, so it guards the payload format rather than the new path.

Building the reply got 7.2x to 9.0x faster than on the base for those five mainnet blocks and the two largest regtest blocks (median of three runs, Release, Apple M5). Peak heap fell from 2.9 to 2.0 MB for 481824 and from 7.9 to 4.0 MB for 774628. I measured with a Boost test that writes each block with WriteBlock and reads it back both ways, and a functional test running a head and a base node; I can share both as a gist.

tACK 0b01ce05e162ee61fb0e3c0d8413e0e1af4c1976 I checked that the new `MSG_BLOCK` reply is byte for byte the old one. On 214 blocks, the head's `ReadBlockWithoutWitness` matches its `ReadBlock` plus `TX_NO_WITNESS`, that old path matches the base's, and btclib, a library I maintain, agrees. The blocks are mainnet 481824, 709632, 774628, 920000 and the bench's 413567, plus 209 regtest blocks with segwit v0 and v1 spends, 1,000 witness items, empty stacks and items, a 3,990,000-byte annex, 300 inputs, 316 outputs, 260 transactions, or no witness. Over P2P, a head node and a base node give the same `MSG_BLOCK` and `MSG_WITNESS_BLOCK` payloads for all 209: 208 from disk, and the two successive tips from the recent-block cache. Each of seven mutants of `StripBlockWitness` and `ReadBlockWithoutWitness` fails `blockmanager_tests`. They range from keeping the marker or the witnesses to skipping the proof-of-work or hash check. The new `p2p_getdata` case also passes against a base node, so it guards the payload format rather than the new path. Building the reply got 7.2x to 9.0x faster than on the base for those five mainnet blocks and the two largest regtest blocks (median of three runs, Release, Apple M5). Peak heap fell from 2.9 to 2.0 MB for 481824 and from 7.9 to 4.0 MB for 774628. I measured with a Boost test that writes each block with `WriteBlock` and reads it back both ways, and a functional test running a head and a base node; I can share both as a gist.
DrahtBot commented 2026-10-28 23:18:15 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-10-31 15:25:22 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/41212933561/job/124571513411
LLM reason (✨ experimental): CI failed because IWYU modified src/bench/readwriteblock.cpp to add missing includes, and the subsequent diff check detected uncommitted changes.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/41212933561/job/124571513411</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU modified `src/bench/readwriteblock.cpp` to add missing includes, and the subsequent diff check detected uncommitted changes.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
fametrano (Migrated from github.com) reviewed 2026-11-01 18:25:24 +00:00
fametrano (Migrated from github.com) left a comment

tACK d36943b49c

The PR's own changes are the ones I tested on 0b01ce05: the range-diff only moves three bench includes into the earlier bench commits and places the new tests before master's new blockmanager_tests case, and the net diff is unchanged line for line. The new base widens block file positions to 64 bits, which the new read path goes through, so I re-ran the byte-for-byte check rather than carry the old result over.

On this head, ReadBlockWithoutWitness matches ReadBlock plus TX_NO_WITNESS for the same five mainnet blocks and for 263 new regtest blocks, and btclib agrees. The regtest blocks include taproot annexes of up to 3,990,001 bytes, witness stacks of 1,001 items, 260 transactions, 300 inputs and 316 outputs, and three blocks with no witness. Over P2P, MSG_BLOCK equals the test framework's non-witness serialization for all 263 blocks read from disk and for 22 of them while they were the tip. MSG_WITNESS_BLOCK equals getblock. blockmanager_tests, p2p_getdata, p2p_segwit and p2p_compactblocks pass. I did not re-run the mutants or the timings. Scripts and output: https://gist.github.com/fametrano/740bc1f88f3d5967023c920824bafd70/29865a5e048c740b1ac50fbc311e2f1607bfaa3d

tACK d36943b49ce321cd622a8ae5a885227c7b3189cf The PR's own changes are the ones I tested on 0b01ce05: the range-diff only moves three bench includes into the earlier bench commits and places the new tests before master's new `blockmanager_tests` case, and the net diff is unchanged line for line. The new base widens block file positions to 64 bits, which the new read path goes through, so I re-ran the byte-for-byte check rather than carry the old result over. On this head, `ReadBlockWithoutWitness` matches `ReadBlock` plus `TX_NO_WITNESS` for the same five mainnet blocks and for 263 new regtest blocks, and btclib agrees. The regtest blocks include taproot annexes of up to 3,990,001 bytes, witness stacks of 1,001 items, 260 transactions, 300 inputs and 316 outputs, and three blocks with no witness. Over P2P, `MSG_BLOCK` equals the test framework's non-witness serialization for all 263 blocks read from disk and for 22 of them while they were the tip. `MSG_WITNESS_BLOCK` equals `getblock`. `blockmanager_tests`, `p2p_getdata`, `p2p_segwit` and `p2p_compactblocks` pass. I did not re-run the mutants or the timings. Scripts and output: https://gist.github.com/fametrano/740bc1f88f3d5967023c920824bafd70/29865a5e048c740b1ac50fbc311e2f1607bfaa3d
l0rinc commented 2026-11-09 21:47:18 +00:00 (Migrated from github.com)

Rebased + applied some minor Fable 5.2 simplification suggestions.

Rebased + applied some minor Fable 5.2 simplification suggestions.
DrahtBot commented 2026-11-10 13:52:55 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
fametrano (Migrated from github.com) reviewed 2026-11-10 21:41:33 +00:00
fametrano (Migrated from github.com) left a comment

reACK 5208112736

Since d36943b4, the rebase and the simplifications l0rinc applied leave the non-test changes identical line for line; only the unit tests, the functional test and the bench changed. The new base widens the block file sizes and constants to 64 bits, with the same values.

I re-ran the earlier checks on this head with the same scripts (https://gist.github.com/fametrano/740bc1f88f3d5967023c920824bafd70/29865a5e048c740b1ac50fbc311e2f1607bfaa3d). ReadBlockWithoutWitness still matches ReadBlock plus TX_NO_WITNESS for the five mainnet and 263 regtest blocks, MSG_BLOCK still matches the non-witness serialization for all 263 regtest blocks, and blockmanager_tests, p2p_getdata, p2p_segwit and p2p_compactblocks pass.

reACK 52081127364481ed14249e38bd460e725e4b0a40 Since d36943b4, the rebase and the simplifications l0rinc applied leave the non-test changes identical line for line; only the unit tests, the functional test and the bench changed. The new base widens the block file sizes and constants to 64 bits, with the same values. I re-ran the earlier checks on this head with the same scripts (https://gist.github.com/fametrano/740bc1f88f3d5967023c920824bafd70/29865a5e048c740b1ac50fbc311e2f1607bfaa3d). `ReadBlockWithoutWitness` still matches `ReadBlock` plus `TX_NO_WITNESS` for the five mainnet and 263 regtest blocks, `MSG_BLOCK` still matches the non-witness serialization for all 263 regtest blocks, and `blockmanager_tests`, `p2p_getdata`, `p2p_segwit` and `p2p_compactblocks` pass.
DrahtBot commented 2026-11-26 17:40:29 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
optout21 (Migrated from github.com) reviewed 2026-11-30 08:32:51 +00:00
optout21 (Migrated from github.com) left a comment

Concept ACK (28a0c6a4ec)

Reviewed by reimplementing and comparing solutions.

Comments:

  • StripBlockWitness is pure serialization logic with no storage dependency, but it sits in node:: inside blockstorage. Putting it next to the block and transaction serialization code would make it reusable (for example by REST or a future compact-block path), and its tests wouldn't need node code.

  • The reason to exclude Signet could be explained in more detail.

  • Signet isn't covered. No test exercises the MSG_BLOCK-on-Signet branch, which still uses ReadBlock. It's cheap to leave untested since it's the old code path, but if the special case stays, a test would stop it from being lost in a later cleanup.

  • Is ReadBlockWithoutWitness more similar to ReadBlock or ReadRawBlock? It's a combinations; this could be explained.

  • Possible follow-up: CSerializedNetMsg::data is a std::vector<unsigned char>, so NetMsg::Make copies the 1–4 MB payload once more. If the message could take ownership of the buffer, that copy would go away for both the witness and non-witness paths.

Concept ACK (28a0c6a4ec09a1c56cb1c9685360bbb7ab37c58a) Reviewed by reimplementing and comparing solutions. Comments: - `StripBlockWitness` is pure serialization logic with no storage dependency, but it sits in `node::` inside `blockstorage`. Putting it next to the block and transaction serialization code would make it reusable (for example by `REST` or a future compact-block path), and its tests wouldn't need node code. - The reason to exclude Signet could be explained in more detail. - Signet isn't covered. No test exercises the `MSG_BLOCK`-on-Signet branch, which still uses `ReadBlock`. It's cheap to leave untested since it's the old code path, but if the special case stays, a test would stop it from being lost in a later cleanup. - Is `ReadBlockWithoutWitness` more similar to `ReadBlock` or `ReadRawBlock`? It's a combinations; this could be explained. - Possible follow-up: `CSerializedNetMsg::data` is a `std::vector<unsigned char>`, so `NetMsg::Make` copies the 1–4 MB payload once more. If the message could take ownership of the buffer, that copy would go away for both the witness and non-witness paths.
optout21 (Migrated from github.com) commented 2026-11-30 08:08:28 +00:00

28a0c6a net: serve MSG_BLOCK from serialized data:

Nit: This also handles MSG_BLOCK

> [28a0c6a](https://github.com/bitcoin/bitcoin/pull/36548/changes/28a0c6a4ec09a1c56cb1c9685360bbb7ab37c58a) _net: serve `MSG_BLOCK` from serialized data_: Nit: This also handles `MSG_BLOCK`
optout21 (Migrated from github.com) commented 2026-11-30 08:10:59 +00:00

28a0c6a net: serve MSG_BLOCK from serialized data:

Nit: as this alias is introduced, it could also be used 4 lines below, within the same code block.
(return m_chainman.m_blockman.IsBlockPruned(*pindex))

> [28a0c6a](https://github.com/bitcoin/bitcoin/pull/36548/changes/28a0c6a4ec09a1c56cb1c9685360bbb7ab37c58a) _net: serve `MSG_BLOCK` from serialized data_: Nit: as this alias is introduced, it could also be used 4 lines below, within the same code block. (`return m_chainman.m_blockman.IsBlockPruned(*pindex)`)
optout21 (Migrated from github.com) commented 2026-11-30 08:04:28 +00:00

be13ee8 test: cover block serving serialization:

This overwrite is not restored. Can later tests be distracted by this?

> [be13ee8](https://github.com/bitcoin/bitcoin/pull/36548/changes/be13ee89034c28afbf9b4a5bc15b669713583da3) _test: cover block serving serialization_: This overwrite is not restored. Can later tests be distracted by this?
l0rinc commented 2026-12-01 20:18:25 +00:00 (Migrated from github.com)

Thanks for the review, @optout21!
I rebased and moved the witness-stripping code and tests next to block serialization and made the P2P test restore MESSAGEMAP. I also added a test that checks that we serve a valid Signet block from disk and refuse it if its solution is damaged.

Thanks for the review, @optout21! I rebased and moved the witness-stripping code and tests next to block serialization and made the P2P test restore `MESSAGEMAP`. I also added a test that checks that we serve a valid Signet block from disk and refuse it if its solution is damaged.
optout21 (Migrated from github.com) reviewed 2026-12-02 09:12:08 +00:00
optout21 (Migrated from github.com) left a comment

ACK 8a827efb36

Thanks for addressing my review comments. Reviewed again, only non-blocking nits found.

ACK 8a827efb361aaef267f0ec3e31f7b17d2b88c251 Thanks for addressing my review comments. Reviewed again, only non-blocking nits found.
optout21 (Migrated from github.com) commented 2026-12-02 08:52:48 +00:00

1f1d86c node: read non-witness block payloads:

Nit: This can happen on incorrect usage, so maybe a proper error in this case would be more appropriate. Assume does nothing in release mode.

> [1f1d86c](https://github.com/bitcoin/bitcoin/pull/36548/changes/1f1d86c9f2c8bb0d106628a9b69b2304a8669bc6) _node: read non-witness block payloads_: Nit: This can happen on incorrect usage, so maybe a proper error in this case would be more appropriate. `Assume` does nothing in release mode.
optout21 (Migrated from github.com) commented 2026-12-02 09:11:09 +00:00

1f1d86c node: read non-witness block payloads:

Nit: Invalid data read from disk is arguably not an IO error, but data inconsistency. Could use a specialized error here.

> [1f1d86c](https://github.com/bitcoin/bitcoin/pull/36548/changes/1f1d86c9f2c8bb0d106628a9b69b2304a8669bc6) _node: read non-witness block payloads_: Nit: Invalid data read from disk is arguably not an `IO` error, but data inconsistency. Could use a specialized error here.
Lines 1113-1120
optout21 (Migrated from github.com) commented 2026-12-02 09:09:10 +00:00

1f1d86c node: read non-witness block payloads:

Nit: These checks are verbatim in ReadBlock as well, a common helper could reduce code duplication (it's fine to have CheckSignetBlockSolution in as well, as that's if'ed).

> [1f1d86c](https://github.com/bitcoin/bitcoin/pull/36548/changes/1f1d86c9f2c8bb0d106628a9b69b2304a8669bc6) _node: read non-witness block payloads_: Nit: These checks are verbatim in `ReadBlock` as well, a common helper could reduce code duplication (it's fine to have `CheckSignetBlockSolution` in as well, as that's if'ed).
l0rinc (Migrated from github.com) reviewed 2026-12-02 14:01:24 +00:00
Lines 1116-1123
l0rinc (Migrated from github.com) commented 2026-12-02 14:01:24 +00:00

Sharing that sequence would require passing the decoded block into the helper, I tried it, didn't like the results - you can suggest a version you like if you think we should do it here.

Sharing that sequence would require passing the decoded block into the helper, I tried it, didn't like the results - you can suggest a version you like if you think we should do it here.
l0rinc (Migrated from github.com) reviewed 2026-12-02 14:02:15 +00:00
l0rinc (Migrated from github.com) commented 2026-12-02 14:02:15 +00:00

InvalidData may be more precise, but the logs already distinguish the failures and the P2P caller handles them the same way - the diff seems simpler as-is.

`InvalidData` may be more precise, but the logs already distinguish the failures and the P2P caller handles them the same way - the diff seems simpler as-is.
l0rinc commented 2026-12-02 14:02:39 +00:00 (Migrated from github.com)

Rebased and made ReadBlockWithoutWitness return an error on Signet in all builds, thanks @optout21

Rebased and made `ReadBlockWithoutWitness` return an error on Signet in all builds, thanks @optout21
optout21 commented 2026-12-04 11:07:04 +00:00 (Migrated from github.com)

It looks like the fixup is missing for the last fixup commit.
I've reviewed it, LGTM, thanks for reacting. Happy to re-ack after fixup.

It looks like the fixup is missing for the last fixup commit. I've reviewed it, LGTM, thanks for reacting. Happy to re-ack after fixup.
l0rinc commented 2026-12-04 11:11:57 +00:00 (Migrated from github.com)

It looks like the fixup is missing for the last fixup commit.

That's how I usually review locally, forgot to fold back the fixup, thanks, rebased and folded it back, no other change was done in latest push.

> It looks like the fixup is missing for the last fixup commit. That's how I usually review locally, forgot to fold back the fixup, thanks, rebased and folded it back, no other change was done in latest push.
optout21 commented 2026-12-04 11:17:28 +00:00 (Migrated from github.com)

reACK 5163788036
(git range-diff 8a827ef...5163788)

reACK 516378803669d42e0dda9e1a29ef8cbc229dcdb0 (`git range-diff 8a827ef...5163788`)
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!36548
No description provided.