p2p: Reconsider package transactions that are immediately trimmed #36328

Open
instagibbs wants to merge 3 commits from package-trim-reconsiderable into master AGit
instagibbs commented 2026-09-24 16:26:50 +00:00 (Migrated from github.com)

In-master, if a package is entered into mempool at the lowerst chunk feerate, pushing the mempool oversize, this causes that transaction (package) to be trimmed immediately. This is fine and expected, but the returned validation result TX_MEMPOOL_POLICY precludes the now-evicted parent from being considered again (i.e. fetched / processed as package) until after another block is found.

This is not a major issue, but would result in unneeded censorship of someone low-balling package feerates.

The already-in-mempool case needs a bit more logic due to the FeeFailure's requirement of package feerate knowledge, so I opted to defer it for now.

Related to finding made by Loupe, and subsequently Red Team.

In-master, if a package is entered into mempool at the lowerst chunk feerate, pushing the mempool oversize, this causes that transaction (package) to be trimmed immediately. This is fine and expected, but the returned validation result `TX_MEMPOOL_POLICY` precludes the now-evicted parent from being considered again (i.e. fetched / processed as package) until after another block is found. This is not a major issue, but would result in unneeded censorship of someone low-balling package feerates. The already-in-mempool case needs a bit more logic due to the `FeeFailure`'s requirement of package feerate knowledge, so I opted to defer it for now. Related to finding made by Loupe, and subsequently Red Team.
DrahtBot commented 2026-09-24 16:26:58 +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 mzumsande, ismaelsadeeq

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

Conflicts

No conflicts as of last run.

<!--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/36328 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36328.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36328#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 | [mzumsande](https://github.com/bitcoin/bitcoin/pull/36328#pullrequestreview-5799883633), [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/36328#pullrequestreview-5825981337) | 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 No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
DrahtBot commented 2026-09-24 16:40:01 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/36027432164/job/107727417441
LLM reason (✨ experimental): CI failed to compile test_bitcoin because Clang -Wthread-safety (treated as -Werror) reported an exclusive cs_main lock is missing when calling ProcessNewPackage in txpackage_tests.cpp.

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 `ASan + LSan + UBSan + integer`: https://github.com/bitcoin/bitcoin/actions/runs/36027432164/job/107727417441</sub> <sub>LLM reason (✨ experimental): CI failed to compile `test_bitcoin` because Clang `-Wthread-safety` (treated as `-Werror`) reported an exclusive `cs_main` lock is missing when calling `ProcessNewPackage` in `txpackage_tests.cpp`.</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>
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: f19e4bfc9be5 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:94181c18e25436d5e4a2de2ff71714413b4552a2 --> <!-- ralph-head:f19e4bfc9be59d32502215e9624a5a18600e26f6 --> <!-- ralph-case:4a87ba49a98e9e9d56891327052de431020c88de773605168a7ed9bb3f53b052 --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`f19e4bfc9be5`](<https://git.fish.foo/bitcoin/bitcoin/commit/f19e4bfc9be59d32502215e9624a5a18600e26f6>) · [Full review report](<https://review.fish.foo/traces/36328-f19e4bfc9be59d32502215e9624a5a18600e26f6-2150-2.html>) · [Previous reports](<https://review.fish.foo/traces/36328/>) [permalink](<https://review.fish.foo/traces/36328-f19e4bfc9be59d32502215e9624a5a18600e26f6-2150-2.html>)
instagibbs commented 2026-09-28 16:12:19 +00:00 (Migrated from github.com)
This PR closes out R10: https://gist.github.com/instagibbs/880a76535fd802fced9f9a5253cdbb40
mzumsande (Migrated from github.com) reviewed 2026-11-04 17:37:06 +00:00
mzumsande (Migrated from github.com) left a comment

Concept ACK
Seems to me that the first part is much more important because it could be encountered via p2p 1p1c.
The second part seems less urgent, and I think it could wait until after removing the fee information from FeeFailure, as suggested in the OP.
As far as I understand, the second part would mostly be encountered via rpc anyway, where it makes no observable difference (same error string). By delaying it we wouldn't need to introduce deduplicated_feerates.

Concept ACK Seems to me that the first part is much more important because it could be encountered via p2p 1p1c. The second part seems less urgent, and I think it could wait until after removing the fee information from `FeeFailure`, as suggested in the OP. As far as I understand, the second part would mostly be encountered via rpc anyway, where it makes no observable difference (same error string). By delaying it we wouldn't need to introduce `deduplicated_feerates`.
instagibbs commented 2026-11-04 18:45:59 +00:00 (Migrated from github.com)

@mzumsande split it up, thanks

@mzumsande split it up, thanks
mzumsande (Migrated from github.com) reviewed 2026-11-06 12:11:36 +00:00
mzumsande (Migrated from github.com) left a comment

Code Review ACK f19e4bfc9b

Code Review ACK f19e4bfc9be59d32502215e9624a5a18600e26f6
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-09 13:04:18 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

ACK f19e4bfc9b

I also went through the other TX_MEMPOOL_POLICY reasons. The "max feerate exceeded" one is a local only guard that can't be triggered over p2p, others are legitimate except one left deliberately by the OP. For that, I think a user who hits it can workaround the rejection by e.g. running with a larger -maxmempool, or starting from an empty mempool and not accepting incoming txs (-blocksonly). larger -maxmempool is optimistic but better because a blocksonly node relays only its own transactions and accepts none from peers, so it could be a source leak.
This should be fixed too.

ACK f19e4bfc9be59d32502215e9624a5a18600e26f6 I also went through the other `TX_MEMPOOL_POLICY` reasons. The "max feerate exceeded" one is a local only guard that can't be triggered over p2p, others are legitimate except one left deliberately by the OP. For that, I think a user who hits it can workaround the rejection by e.g. running with a larger -maxmempool, or starting from an empty mempool and not accepting incoming txs (-blocksonly). larger -maxmempool is optimistic but better because a blocksonly node relays only its own transactions and accepts none from peers, so it could be a source leak. This should be fixed too.
ismaelsadeeq (Migrated from github.com) commented 2026-11-09 12:42:25 +00:00

nit: can be boost check equal

nit: can be boost check equal
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!36328
No description provided.