txorphanage: bound orphan memory by storing transactions serialized #36015

Closed
brunoerg wants to merge 7 commits from 2026-08-orphanage-mem-bug into master AGit
brunoerg commented 2026-08-18 21:11:30 +00:00 (Migrated from github.com)

The orphanage limits the "usage" of the orphans it stores, per peer and globally, to bound the amount of memory an attacker can make us hold on to. It uses weight as a proxy for that memory, on the assumption that weight is "often higher than the actual memory usage of the transaction".

That assumption does not hold for a deserialized transaction. Every witness stack element is an individually heap-allocated vector, costing its 24-byte slot in the stack vector plus a 32-byte minimum allocation, while only weighing 2WU. A transaction of 199,000 1-byte witness elements weighs 398,247WU (i.e. it is of standard weight, and witness standardness cannot be checked while the inputs are missing), but uses 11.1MB of memory: 28 times what is accounted for it, and one such orphan can be retained per peer.

Rather than change the accounting metric, keep orphans in serialized form, deserializing them again on the paths that hand them back out. Serialized, a transaction's memory usage is bounded by its weight, so the existing weight-based accounting becomes a true upper bound on memory and the worst case is the peers' combined allowances.

Admission, eviction and accounting behavior are unchanged: no transaction that was previously accepted is refused, so orphan resolution (and thus 1p1c package relay) keeps working for standard-weight transactions whose witnesses consist of many small elements, such as BitVM-style transactions.

The orphanage limits the "usage" of the orphans it stores, per peer and globally, to bound the amount of memory an attacker can make us hold on to. It uses weight as a proxy for that memory, on the assumption that weight is "often higher than the actual memory usage of the transaction". That assumption does not hold for a deserialized transaction. Every witness stack element is an individually heap-allocated vector, costing its 24-byte slot in the stack vector plus a 32-byte minimum allocation, while only weighing 2WU. A transaction of 199,000 1-byte witness elements weighs 398,247WU (i.e. it is of standard weight, and witness standardness cannot be checked while the inputs are missing), but uses 11.1MB of memory: 28 times what is accounted for it, and one such orphan can be retained per peer. Rather than change the accounting metric, keep orphans in serialized form, deserializing them again on the paths that hand them back out. Serialized, a transaction's memory usage is bounded by its weight, so the existing weight-based accounting becomes a true upper bound on memory and the worst case is the peers' combined allowances. Admission, eviction and accounting behavior are unchanged: no transaction that was previously accepted is refused, so orphan resolution (and thus 1p1c package relay) keeps working for standard-weight transactions whose witnesses consist of many small elements, such as BitVM-style transactions.
DrahtBot commented 2026-08-18 21:11:36 +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
Concept ACK w0xlt, l0rinc, Crypt-iQ
Stale ACK jeanpablojp, nervana21

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:

  • #36904 (log: Remove trailing and embedded newlines from log messages by maflcko)
  • #36884 (p2p: skip parent lookups for orphan announcements that cannot add a candidate by kah-ja)
  • #36506 (p2p: plug "tier 1" 1p1c liveness holes by instagibbs)

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/36015 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36015.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36015#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 | | ---- | --------- | | Concept ACK | [w0xlt](https://github.com/bitcoin/bitcoin/pull/36015#issuecomment-5334161944), [l0rinc](https://github.com/bitcoin/bitcoin/pull/36015#issuecomment-5335302033), [Crypt-iQ](https://github.com/bitcoin/bitcoin/pull/36015#issuecomment-5461045168) | | Stale ACK | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36015#pullrequestreview-4994649322), [nervana21](https://github.com/bitcoin/bitcoin/pull/36015#issuecomment-5819207882) | 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: * [#36904](https://github.com/bitcoin/bitcoin/pull/36904) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36904.svg"></sub> (log: Remove trailing and embedded newlines from log messages by maflcko) * [#36884](https://github.com/bitcoin/bitcoin/pull/36884) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36884.svg"></sub> (p2p: skip parent lookups for orphan announcements that cannot add a candidate by kah-ja) * [#36506](https://github.com/bitcoin/bitcoin/pull/36506) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36506.svg"></sub> (p2p: plug "tier 1" 1p1c liveness holes by instagibbs) 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-->
w0xlt commented 2026-08-18 21:15:49 +00:00 (Migrated from github.com)

Concept ACK.

Concept ACK.
DrahtBot commented 2026-08-18 22:42:09 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32186423022/job/95870987922
LLM reason (✨ experimental): CI failed due to an assertion failure in the fuzz test txorphan (txorphan.cpp:182), causing the fuzzer to exit with code 1.

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 `Windows native, fuzz, VS`: https://github.com/bitcoin/bitcoin/actions/runs/32186423022/job/95870987922</sub> <sub>LLM reason (✨ experimental): CI failed due to an assertion failure in the fuzz test `txorphan` (`txorphan.cpp:182`), causing the fuzzer to exit with code 1.</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>
l0rinc commented 2026-08-18 23:08:32 +00:00 (Migrated from github.com)

Concept ACK
The failing orphanage tests seem related (the musl one is the new test, the fuzz ones need a rebase, iwyu is the bench) and the change mixes refactors and hardening - can you check if it's possible to simplify and do refactors that aren't strictly related in follow-ups instead?
Especially since #35923 is related and complements this change, and #35919 is also touching the same area.

Concept ACK The failing orphanage tests seem related (the musl one is the new test, the fuzz ones need a rebase, iwyu is the bench) and the change mixes refactors and hardening - can you check if it's possible to simplify and do refactors that aren't strictly related in follow-ups instead? Especially since #35923 is related and complements this change, and #35919 is also touching the same area.
brunoerg commented 2026-08-18 23:22:05 +00:00 (Migrated from github.com)

The failing orphanage tests seem related (the musl one is the new test, the fuzz ones need a rebase, iwyu is the bench) and the change mixes refactors and hardening - can you check if it's possible to simplify and do refactors that aren't strictly related in follow-ups instead?

My bad on that, forgot to push since my latest local change. Just did it.

> The failing orphanage tests seem related (the musl one is the new test, the fuzz ones need a rebase, iwyu is the bench) and the change mixes refactors and hardening - can you check if it's possible to simplify and do refactors that aren't strictly related in follow-ups instead? My bad on that, forgot to push since my latest local change. Just did it.
brunoerg commented 2026-08-19 11:33:51 +00:00 (Migrated from github.com)

Ready for review.

Ready for review.
jeanpablojp (Migrated from github.com) reviewed 2026-08-21 15:03:30 +00:00
jeanpablojp (Migrated from github.com) left a comment

tACK d48b8afcaee6d08cc5e0c00262d0b7defdc6009f

Reverted txorphanage back to master and the new functional test fails like it should, "no orphan was evicted". With 10 peers sending one memory-heavy orphan each, master keeps all 10 and the head none.

I also checked the two numbers in the MAX_ORPHAN_TX_USAGE comment and got 1.24x and 1.47x, matching.

Left a comment on send_orphan() in the new test, nothing blocking.

tACK d48b8afcaee6d08cc5e0c00262d0b7defdc6009f Reverted `txorphanage` back to master and the new functional test fails like it should, "no orphan was evicted". With 10 peers sending one memory-heavy orphan each, master keeps all 10 and the head none. I also checked the two numbers in the `MAX_ORPHAN_TX_USAGE` comment and got 1.24x and 1.47x, matching. Left a comment on `send_orphan()` in the new test, nothing blocking.
jeanpablojp (Migrated from github.com) commented 2026-08-21 15:03:30 +00:00

This wait_until matches the getdata from the previous call, since last_message isn't cleared. From the second send_orphan() on, the getdata doesn't hold the current tx's wtxid, so the tx goes out unrequested and the inv/getdata path is only exercised on the first call.

wait_for_getdata([int(tx.wtxid_hex, 16)]) fixes it, which is what p2p_orphan_handling.py does. Swapped it here and it still passes.

This `wait_until` matches the getdata from the previous call, since `last_message` isn't cleared. From the second `send_orphan()` on, the getdata doesn't hold the current tx's wtxid, so the tx goes out unrequested and the inv/getdata path is only exercised on the first call. `wait_for_getdata([int(tx.wtxid_hex, 16)])` fixes it, which is what `p2p_orphan_handling.py` does. Swapped it here and it still passes.
instagibbs commented 2026-08-24 09:28:11 +00:00 (Migrated from github.com)

I'm pretty worried that the new behavior would cause subtle user breakage, epsecially considering something BitVM-like (with lots of 20b and 1b elements in witness data i.e. winternitz sigs).

Rather than change the metrics entirely, could you consider an alternative where the stored transactions are in serialized form, and deserialized only when required? https://github.com/instagibbs/bitcoin/tree/2026-08-orphanage-serialized-weight

It's significantly less code, doesn't require the weight metric to be swapped out (it would truly be an overestimation now modulo small constant), limiting the scope of the change. The one cost is the serialize<->deserialize that would be added on round-tripping. From my benchmarks it looks like a non-adversarial large tx would take ~1.5ms on ReconsiderTx, and a BitVM-like one ~3ms. The other costs look negligible.

Let me know what you think. I'm happy for you to take the code, or to open my own PR.

I'm pretty worried that the new behavior would cause subtle user breakage, epsecially considering something BitVM-like (with lots of 20b and 1b elements in witness data i.e. winternitz sigs). Rather than change the metrics entirely, could you consider an alternative where the stored transactions are in serialized form, and deserialized only when required? https://github.com/instagibbs/bitcoin/tree/2026-08-orphanage-serialized-weight It's significantly less code, doesn't require the weight metric to be swapped out (it would truly be an overestimation now modulo small constant), limiting the scope of the change. The one cost is the serialize<->deserialize that would be added on round-tripping. From my benchmarks it looks like a non-adversarial large tx would take ~1.5ms on `ReconsiderTx`, and a BitVM-like one ~3ms. The other costs look negligible. Let me know what you think. I'm happy for you to take the code, or to open my own PR.
jeanpablojp commented 2026-08-24 21:05:07 +00:00 (Migrated from github.com)

@instagibbs I was curious so I built your branch, and I'm sharing some numbers I got in my tests.

The timing below is for rebuilding the transaction, one input with N items of k bytes.

witness stack         weight    deserialize   with teardown
100 x 80B              8,343        0.07 ms         0.08 ms
1 x 380,000B         380,248         2.4 ms          2.4 ms
8,000 x 20B          168,245         2.2 ms          2.8 ms
199,000 x 1B         398,247          28 ms           42 ms

Your ~3ms checks out. It's the item count driving this and not the bytes, and it's paid once, both of the paths a peer can trigger consume the orphan.

The limit here is 600,000 bytes of memory, not weight. Varying the item size, this is the weight at which it's reached.

item size    stored up to    % of the range to 400,000 WU lost
  1 byte       21,661 WU                  94.6%
 20 bytes     175,133 WU                  56.2%
 64 bytes     375,035 WU                   6.2%
 65 bytes     330,047 WU                  17.5%

64 to 65 is a MallocUsage step, so the threshold tracks the allocator's buckets and not the transaction.

I tested on x86-64, best case of several runs.

@instagibbs I was curious so I built your branch, and I'm sharing some numbers I got in my tests. The timing below is for rebuilding the transaction, one input with N items of k bytes. ``` witness stack weight deserialize with teardown 100 x 80B 8,343 0.07 ms 0.08 ms 1 x 380,000B 380,248 2.4 ms 2.4 ms 8,000 x 20B 168,245 2.2 ms 2.8 ms 199,000 x 1B 398,247 28 ms 42 ms ``` Your ~3ms checks out. It's the item count driving this and not the bytes, and it's paid once, both of the paths a peer can trigger consume the orphan. The limit here is 600,000 bytes of memory, not weight. Varying the item size, this is the weight at which it's reached. ``` item size stored up to % of the range to 400,000 WU lost 1 byte 21,661 WU 94.6% 20 bytes 175,133 WU 56.2% 64 bytes 375,035 WU 6.2% 65 bytes 330,047 WU 17.5% ``` 64 to 65 is a MallocUsage step, so the threshold tracks the allocator's buckets and not the transaction. I tested on x86-64, best case of several runs.
instagibbs commented 2026-08-25 11:01:25 +00:00 (Migrated from github.com)

Note that it's a pretty expensive "attack" in that to cause deserialization in the orphanage you'd have to enter in a valid parent tx into the mempool.

Note that it's a pretty expensive "attack" in that to cause deserialization in the orphanage you'd have to enter in a valid parent tx into the mempool.
brunoerg commented 2026-08-25 12:11:24 +00:00 (Migrated from github.com)

I'm pretty worried that the new behavior would cause subtle user breakage, epsecially considering something BitVM-like (with lots of 20b and 1b elements in witness data i.e. winternitz sigs).

Rather than change the metrics entirely, could you consider an alternative where the stored transactions are in serialized form, and deserialized only when required? https://github.com/instagibbs/bitcoin/tree/2026-08-orphanage-serialized-weight

It's significantly less code, doesn't require the weight metric to be swapped out (it would truly be an overestimation now modulo small constant), limiting the scope of the change. The one cost is the serialize<->deserialize that would be added on round-tripping. From my benchmarks it looks like a non-adversarial large tx would take ~1.5ms on ReconsiderTx, and a BitVM-like one ~3ms. The other costs look negligible.

Let me know what you think. I'm happy for you to take the code, or to open my own PR.

Good point. I haven't tried that approach, but it seems simpler and achieves the same. I'll take a look at your branch, but you can open the PR and move on, no problem. Happy to review.

> I'm pretty worried that the new behavior would cause subtle user breakage, epsecially considering something BitVM-like (with lots of 20b and 1b elements in witness data i.e. winternitz sigs). > > Rather than change the metrics entirely, could you consider an alternative where the stored transactions are in serialized form, and deserialized only when required? https://github.com/instagibbs/bitcoin/tree/2026-08-orphanage-serialized-weight > > It's significantly less code, doesn't require the weight metric to be swapped out (it would truly be an overestimation now modulo small constant), limiting the scope of the change. The one cost is the serialize<->deserialize that would be added on round-tripping. From my benchmarks it looks like a non-adversarial large tx would take ~1.5ms on `ReconsiderTx`, and a BitVM-like one ~3ms. The other costs look negligible. > > Let me know what you think. I'm happy for you to take the code, or to open my own PR. Good point. I haven't tried that approach, but it seems simpler and achieves the same. I'll take a look at your branch, but you can open the PR and move on, no problem. Happy to review.
instagibbs commented 2026-08-25 12:12:32 +00:00 (Migrated from github.com)

@brunoerg I'm a little busy, please take it on

@brunoerg I'm a little busy, please take it on
brunoerg commented 2026-08-25 17:24:31 +00:00 (Migrated from github.com)

Force-pushed addressing @instagibbs' approach.

Force-pushed addressing @instagibbs' approach.
instagibbs commented 2026-08-25 19:45:59 +00:00 (Migrated from github.com)

title and OP will need updating 👍

title and OP will need updating :+1:
brunoerg commented 2026-08-25 20:15:45 +00:00 (Migrated from github.com)

title and OP will need updating 👍

Done.

> title and OP will need updating 👍 Done.
jeanpablojp (Migrated from github.com) reviewed 2026-08-26 11:00:32 +00:00
jeanpablojp (Migrated from github.com) left a comment

Built the merge with master and tested again.

Built the merge with master and tested again.
jeanpablojp (Migrated from github.com) commented 2026-08-26 11:00:32 +00:00

Every matching child is rebuilt before Find1P1CPackage looks at the first one. With 94 orphans of 199,000 1-byte items, one per peer, all announced by a single peer, that's 1,047.6 MB live against the 37.4 MB accounted for it, where one at a time would be 11.1 MB.

The trigger costs no fee, min relay fee not met already returns TX_RECONSIDERABLE.

Every matching child is rebuilt before `Find1P1CPackage` looks at the first one. With 94 orphans of 199,000 1-byte items, one per peer, all announced by a single peer, that's 1,047.6 MB live against the 37.4 MB accounted for it, where one at a time would be 11.1 MB. The trigger costs no fee, `min relay fee not met` already returns `TX_RECONSIDERABLE`.
jeanpablojp (Migrated from github.com) commented 2026-08-26 11:00:32 +00:00

This test passes without the change. Reverting just src/node/txorphanage.cpp to before 493561a34285, the whole suite still passes, since the only difference the API exposes is the identity of the returned object.

    BOOST_CHECK(ptx_out != ptx);
    BOOST_CHECK(ptx_out->GetWitnessHash() == ptx->GetWitnessHash());

Fails without the change and passes with it.

This test passes without the change. Reverting just `src/node/txorphanage.cpp` to before 493561a34285, the whole suite still passes, since the only difference the API exposes is the identity of the returned object. ```suggestion BOOST_CHECK(ptx_out != ptx); BOOST_CHECK(ptx_out->GetWitnessHash() == ptx->GetWitnessHash()); ``` Fails without the change and passes with it.
Crypt-iQ commented 2026-08-29 07:24:30 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
instagibbs commented 2026-09-08 21:43:25 +00:00 (Migrated from github.com)

When finding potential 1P1C packages, we're now deserializing potentially many orphans, which on my machine can cause ~1s of cpu time at ~1GB of memory usage on top of normal. astra slop for your consideration:

github.com/instagibbs/bitcoin@847d2dc2a0

When finding potential 1P1C packages, we're now deserializing potentially many orphans, which on my machine can cause ~1s of cpu time at ~1GB of memory usage on top of normal. astra slop for your consideration: https://github.com/instagibbs/bitcoin/commit/847d2dc2a0dc76340e269f3f60977b8a5d6bab2a
brunoerg commented 2026-09-09 14:19:24 +00:00 (Migrated from github.com)

When finding potential 1P1C packages, we're now deserializing potentially many orphans, which on my machine can cause ~1s of cpu time at ~1GB of memory usage on top of normal. astra slop for your consideration:

instagibbs@847d2dc

Interesting, I benchmarked it (with and without your suggestion) and got +700 MB of peak (I think around 40MB of stored orphans) without and basically zero with. Will review the code and address it here.

> When finding potential 1P1C packages, we're now deserializing potentially many orphans, which on my machine can cause ~1s of cpu time at ~1GB of memory usage on top of normal. astra slop for your consideration: > > [instagibbs@847d2dc](https://github.com/instagibbs/bitcoin/commit/847d2dc2a0dc76340e269f3f60977b8a5d6bab2a) Interesting, I benchmarked it (with and without your suggestion) and got +700 MB of peak (I think around 40MB of stored orphans) without and basically zero with. Will review the code and address it here.
brunoerg (Migrated from github.com) reviewed 2026-09-09 17:46:44 +00:00
brunoerg (Migrated from github.com) commented 2026-09-09 17:46:44 +00:00

Good point, I could add a BOOST_CHECK(ptx_out != ptx) right after it.

Good point, I could add a `BOOST_CHECK(ptx_out != ptx)` right after it.
brunoerg commented 2026-09-09 18:48:28 +00:00 (Migrated from github.com)

Force-pushed:

Force-pushed: - Addressed suggestion from @instagibbs - fixing `Find1P1CPackage`. I got [instagibbs@847d2dc](https://github.com/instagibbs/bitcoin/commit/847d2dc2a0dc76340e269f3f60977b8a5d6bab2a) but changed some things; most nits that I found and test improvements. I also changed `Find1P1CPackage` to store the `GetTx `result and skips the candidate under `Assume` if it is null. - Addressed https://github.com/bitcoin/bitcoin/pull/36015#discussion_r3862075438
brunoerg commented 2026-09-09 19:19:16 +00:00 (Migrated from github.com)

Missing rebase, doing it now.

Missing rebase, doing it now.
brunoerg commented 2026-09-10 03:17:14 +00:00 (Migrated from github.com)

CI failure is unrelated

CI failure is unrelated
nervana21 commented 2026-09-23 13:59:16 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
nervana21 (Migrated from github.com) reviewed 2026-09-24 17:42:40 +00:00
nervana21 (Migrated from github.com) commented 2026-09-24 02:39:42 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

nit.

    // All of the tiny transactions are attributed the same usage.
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement nit. ```suggestion // All of the tiny transactions are attributed the same usage. ``` ```
nervana21 (Migrated from github.com) commented 2026-09-24 02:40:35 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

nit.

    // All of the shared transactions are attributed the same usage.
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement nit. ```suggestion // All of the shared transactions are attributed the same usage. ```
nervana21 (Migrated from github.com) commented 2026-09-24 03:16:28 +00:00

933a9f95af: txorphanage: store orphans serialized, making weight bound their memory

nit.

    /** Usage attributed to this orphan (see GetOrphanUsage), cached at construction. Caching guarantees that the
933a9f95af2ec52e0804dd8f66d229e49e53c426: txorphanage: store orphans serialized, making weight bound their memory nit. ```suggestion /** Usage attributed to this orphan (see GetOrphanUsage), cached at construction. Caching guarantees that the ```
nervana21 (Migrated from github.com) commented 2026-09-24 02:48:29 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

nit.

     * announcers, its usage will be accounted for in each PeerOrphanInfo, so the total of all
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement nit. ```suggestion * announcers, its usage will be accounted for in each PeerOrphanInfo, so the total of all ```
nervana21 (Migrated from github.com) commented 2026-09-24 02:48:58 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

nit. Match the usage API this comment documents.

/** Get the usage TxOrphanage attributes to this transaction, i.e. its contribution to
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement nit. Match the usage API this comment documents. ```suggestion /** Get the usage TxOrphanage attributes to this transaction, i.e. its contribution to ```
nervana21 (Migrated from github.com) commented 2026-09-24 02:50:05 +00:00

0557bc81d5: txorphanage: return orphan ids from GetChildrenFromSamePeer

nit. Mirror GetPackageHash above

/** Get the hash of the concatenated wtxids, with wtxids
 * treated as little-endian numbers and sorted in ascending numeric order.
 * Same as GetPackageHash(), but takes wtxids directly without needing the transactions. */
0557bc81d577ab3ed4354e79dfa6bf5b5a2f0c6c: txorphanage: return orphan ids from GetChildrenFromSamePeer nit. Mirror GetPackageHash above ```suggestion /** Get the hash of the concatenated wtxids, with wtxids * treated as little-endian numbers and sorted in ascending numeric order. * Same as GetPackageHash(), but takes wtxids directly without needing the transactions. */ ```
nervana21 (Migrated from github.com) commented 2026-09-24 02:51:48 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

Can add the usage metric

            const auto tx_weight{GetTransactionWeight(*tx)};
            const auto tx_usage{node::GetOrphanUsage(tx)};
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement Can add the usage metric ```suggestion const auto tx_weight{GetTransactionWeight(*tx)}; const auto tx_usage{node::GetOrphanUsage(tx)}; ```
nervana21 (Migrated from github.com) commented 2026-09-24 03:30:00 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

Can use usage instead of weight.

                            Assert(orphanage->UsageByPeer(peer_id) <= bytes_from_peer_before - tx_usage);
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement Can use usage instead of weight. ```suggestion Assert(orphanage->UsageByPeer(peer_id) <= bytes_from_peer_before - tx_usage); ```
nervana21 (Migrated from github.com) commented 2026-09-24 03:17:36 +00:00

f4d43b530a: txorphanage: add GetOrphanUsage() and cache it per announcement

nit.

    // The orphanage attributes the same usage to each orphan transaction. Don't hardcode the value, as it is
f4d43b530a142fea0db9488028c5e510bf78d1ee: txorphanage: add GetOrphanUsage() and cache it per announcement nit. ```suggestion // The orphanage attributes the same usage to each orphan transaction. Don't hardcode the value, as it is ```
nervana21 (Migrated from github.com) commented 2026-09-24 03:04:31 +00:00

e9381aac15: test: cover storing a witness-heavy orphan at its serialized cost

nit.

    // are stored in serialized form, its memory usage is bounded by the usage attributed to it.
e9381aac1570875f395c1f8f9169179726534e06: test: cover storing a witness-heavy orphan at its serialized cost nit. ```suggestion // are stored in serialized form, its memory usage is bounded by the usage attributed to it. ```
nervana21 (Migrated from github.com) commented 2026-09-24 03:04:59 +00:00

e9381aac15: test: cover storing a witness-heavy orphan at its serialized cost

nit.

    // The serialized transaction, which is what the orphanage keeps, is smaller than the usage attributed to it.
e9381aac1570875f395c1f8f9169179726534e06: test: cover storing a witness-heavy orphan at its serialized cost nit. ```suggestion // The serialized transaction, which is what the orphanage keeps, is smaller than the usage attributed to it. ```
nervana21 (Migrated from github.com) commented 2026-09-24 03:05:25 +00:00

e9381aac15: test: cover storing a witness-heavy orphan at its serialized cost

nit.

    // It is stored and its usage is accounted for.
e9381aac1570875f395c1f8f9169179726534e06: test: cover storing a witness-heavy orphan at its serialized cost nit. ```suggestion // It is stored and its usage is accounted for. ```
nervana21 commented 2026-09-24 17:45:54 +00:00 (Migrated from github.com)

Nits for the commit message themselves

87a2791f54: txorphanage: add GetParentTxids() and use it for orphan resolution candidates
Says "The following commit"
Should read "In a later commit"

9d6e93f5c7: iwyu: fix includes in node/txorphanage.h
Says "the following commits modify this header"
Should read "later commits modify this header"

e9381aac15: test: cover storing a witness-heavy orphan at its serialized cost
Says "stored (accounted its weight, which now bounds its memory)"
Should read "stored (its usage is accounted for, which now bounds its memory)"

Nits for the commit message themselves 87a2791f5438672cba63de2c10b5da1d82425d51: txorphanage: add GetParentTxids() and use it for orphan resolution candidates Says "The following commit" Should read "In a later commit" 9d6e93f5c7dc5afd08e872d9c7e39623c487a9c8: iwyu: fix includes in node/txorphanage.h Says "the following commits modify this header" Should read "later commits modify this header" e9381aac1570875f395c1f8f9169179726534e06: test: cover storing a witness-heavy orphan at its serialized cost Says "stored (accounted its weight, which now bounds its memory)" Should read "stored (its usage is accounted for, which now bounds its memory)"
nervana21 commented 2026-09-24 17:47:04 +00:00 (Migrated from github.com)

tACK e9381aac15

left a slew of non blocking nits, mostly about wording
the logic is sound based on my review and testing

tACK e9381aac1570875f395c1f8f9169179726534e06 left a slew of non blocking nits, mostly about wording the logic is sound based on my review and testing
First-time contributor

3 additional verified findings in the full report.

🟠 Minor · Missing-input children can be repeatedly deserialized before cheap rejection

Distinct low-fee parent witness variants can repeatedly rebuild a retained witness-heavy child under cs_main and m_tx_download_mutex without requiring valid signatures.

Location: src/node/txdownloadman_impl.cpp:328 (head).

🟠 Minor · getorphantxs decodes every orphan under the download mutex

An authorized getorphantxs call reconstructs every unique orphan while holding m_tx_download_mutex, even when the default response only needs cached txids.

Location: src/node/txorphanage.cpp:783 (head).

🟠 Minor · Candidate cleanup can invalidate the later Assume(child_tx)

Cleaning up an in-mempool child can evict a later candidate from the ID snapshot, causing Assume-enforcing builds to abort; ordinary release builds skip it.

Location: src/node/txdownloadman_impl.cpp:329 (head).

🔵 Suggestion · The witness-heavy test misses retention of the incoming transaction

Pointer inequality proves that GetTx returns a fresh object, but would not detect the orphanage retaining the original deserialized transaction as well.

Location: src/test/orphanage_tests.cpp:759 (head).

🔵 Suggestion · EraseTx fuzz accounting still depends directly on weight

The txorphan accounting assertion bypasses GetOrphanUsage, leaving one usage expectation coupled to weight after the other targets adopt the new helper.

Location: src/test/fuzz/txorphan.cpp:183 (head).

🔵 Suggestion · The usage comment incorrectly suggests platform-dependent accounting

GetOrphanUsage currently returns platform-independent transaction weight, contrary to the test comment's rationale for computing TX_USAGE.

Location: src/test/orphanage_tests.cpp:113 (head).

Review coverage was incomplete.


Reviewed: 771bc5311c7b · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:94181c18e25436d5e4a2de2ff71714413b4552a2 --> <!-- ralph-head:771bc5311c7b6a3656687cd2a91625e18fb4686e --> <!-- ralph-case:f9d29a36b7607f34f26ace1d4841cabdc65d446953d485167e784f310c015c83 --> [3 additional verified findings in the full report](<https://review.fish.foo/traces/36015-771bc5311c7b6a3656687cd2a91625e18fb4686e-2148-3.html>). **🟠 Minor · Missing-input children can be repeatedly deserialized before cheap rejection** Distinct low-fee parent witness variants can repeatedly rebuild a retained witness-heavy child under cs_main and m_tx_download_mutex without requiring valid signatures. Location: [`src/node/txdownloadman_impl.cpp:328`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e/src/node/txdownloadman_impl.cpp#L328>) (head). **🟠 Minor · getorphantxs decodes every orphan under the download mutex** An authorized getorphantxs call reconstructs every unique orphan while holding m_tx_download_mutex, even when the default response only needs cached txids. Location: [`src/node/txorphanage.cpp:783`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e/src/node/txorphanage.cpp#L783>) (head). **🟠 Minor · Candidate cleanup can invalidate the later Assume(child_tx)** Cleaning up an in-mempool child can evict a later candidate from the ID snapshot, causing Assume-enforcing builds to abort; ordinary release builds skip it. Location: [`src/node/txdownloadman_impl.cpp:329`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e/src/node/txdownloadman_impl.cpp#L329>) (head). **🔵 Suggestion · The witness-heavy test misses retention of the incoming transaction** Pointer inequality proves that GetTx returns a fresh object, but would not detect the orphanage retaining the original deserialized transaction as well. Location: [`src/test/orphanage_tests.cpp:759`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e/src/test/orphanage_tests.cpp#L759>) (head). **🔵 Suggestion · EraseTx fuzz accounting still depends directly on weight** The txorphan accounting assertion bypasses GetOrphanUsage, leaving one usage expectation coupled to weight after the other targets adopt the new helper. Location: [`src/test/fuzz/txorphan.cpp:183`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e/src/test/fuzz/txorphan.cpp#L183>) (head). **🔵 Suggestion · The usage comment incorrectly suggests platform-dependent accounting** GetOrphanUsage currently returns platform-independent transaction weight, contrary to the test comment's rationale for computing TX_USAGE. Location: [`src/test/orphanage_tests.cpp:113`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e/src/test/orphanage_tests.cpp#L113>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`771bc5311c7b`](<https://git.fish.foo/bitcoin/bitcoin/commit/771bc5311c7b6a3656687cd2a91625e18fb4686e>) · [Full review report](<https://review.fish.foo/traces/36015-771bc5311c7b6a3656687cd2a91625e18fb4686e-2148-3.html>) · [Previous reports](<https://review.fish.foo/traces/36015/>) [permalink](<https://review.fish.foo/traces/36015-771bc5311c7b6a3656687cd2a91625e18fb4686e-2148-3.html>)
instagibbs commented 2026-10-15 00:14:26 +00:00 (Migrated from github.com)

I think I approach nack this overall, if #36521 is viable

I think I approach nack this overall, if #36521 is viable
brunoerg commented 2026-10-15 00:59:32 +00:00 (Migrated from github.com)

I think I approach nack this overall, if #36521 is viable

I did really a quick look at #36521, looks to solve the issue. If that is viable, happy to close this.

> I think I approach nack this overall, if #36521 is viable I did really a quick look at #36521, looks to solve the issue. If that is viable, happy to close this.
instagibbs commented 2026-10-15 02:16:39 +00:00 (Migrated from github.com)

Don't close until we get consensus on it 👍

Don't close until we get consensus on it :+1:
DrahtBot commented 2026-11-04 15:40:37 +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).
nervana21 commented 2026-11-27 12:47:39 +00:00 (Migrated from github.com)

@brunoerg
#36895 (successor to #36521) has been merged. Can this be closed?

@brunoerg #36895 (successor to #36521) has been merged. Can this be closed?
instagibbs commented 2026-11-30 14:06:27 +00:00 (Migrated from github.com)

this should be closed 👍

this should be closed :+1:
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!36015
No description provided.