Skip to content

p2p: plug "tier 1" 1p1c liveness holes - #36506

Open
instagibbs wants to merge 4 commits into
bitcoin:masterfrom
instagibbs:2026-10-1p1c-liveness-fixes
Open

instagibbs wants to merge 4 commits into
bitcoin:masterfrom
instagibbs:2026-10-1p1c-liveness-fixes

Conversation

@instagibbs

@instagibbs instagibbs commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

@DrahtBot DrahtBot added the P2P label Oct 12, 2026
@DrahtBot

DrahtBot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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
Concept ACK ismaelsadeeq
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)

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.

LLM Linter (✨ experimental)

Possible places where comparison-specific test macros should replace generic comparisons:

  • test/functional/p2p_opportunistic_1p1c.py: assert package_fee / honest_vsize * 1000 > mempoolminfee → Prefer assert_greater_than(package_fee / honest_vsize * 1000, mempoolminfee).

2026-11-30 20:30:50

@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from 077fd92 to 9972cd9 Compare October 14, 2026 01:58
@instagibbs
instagibbs marked this pull request as ready for review October 14, 2026 01:59
@instagibbs instagibbs changed the title p2p: plug various 1p1c liveness holes p2p: plug "tier 1" 1p1c liveness holes Oct 14, 2026
@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from 9972cd9 to 8746d5a Compare October 14, 2026 02:05
@instagibbs

Copy link
Copy Markdown
Member Author

@marcofleon @mzumsande this will be the ultimate target PR to fuzz

@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from 8746d5a to c8abd9e Compare October 14, 2026 04:36
@fametrano

Copy link
Copy Markdown

Tested c8abd9e: each of the four fixes is caught by a test this PR adds or extends. I reverted each fix on its own, keeping the tests, and each revert made txdownload_tests, orphanage_tests or p2p_opportunistic_1p1c.py fail, while the unchanged branch passes them all. I did not review the C++ changes. Details on request.

@fametrano

Copy link
Copy Markdown

ACK c8abd9e. I have now reviewed the four fixes commit by commit and found nothing blocking. One gap remains for a follow-up: in the 1p1c package path, a DIFFERENT_WITNESS result still goes through ProcessInvalidTx, so a witness-stripped copy of a mempool parent puts the parent's txid in the reject filter, as TX_CONFLICT did before 3a2b553. A functional test shows it end to end: an attacker peer re-sends the stripped copy with an orphan of its own, and after the parent leaves the mempool, an honest child is dropped as having a rejected parent. Test on request.

@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from c8abd9e to 8d44ac8 Compare October 15, 2026 02:33
@fametrano

Copy link
Copy Markdown

reACK 8d44ac8. The new DIFFERENT_WITNESS case closes the 1p1c gap I noted at c8abd9e, and the only other code change is its test, known_parent_in_package_does_not_poison_after_eviction. I built test_bitcoin and ran txdownload_tests, orphanage_tests and txpackage_tests: the new test passes, and fails with that case moved back next to INVALID.

@instagibbs

Copy link
Copy Markdown
Member Author

@fametrano fuzzer hit it, which is a good sign

@mzumsande mzumsande left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

I reviewed the production code fixes/non-fuzz test changes and they are all quite small and reviewable, and they all look good to me.

Personally, it would help me to ACK quicker if the large p2p_1p1c_liveness fuzz target was added in a separate PR, especially since all the changes covered by other tests as well, and a lot of code gets added first and then removed again in later commits - but up to you of course.

@instagibbs

Copy link
Copy Markdown
Member Author

Personally, it would help me to ACK quicker if the large p2p_1p1c_liveness fuzz target was added in a separate PR, especially since all the changes covered by other tests as well, and a lot of code gets added first and then removed again in later commits - but up to you of course.

If that makes it easier, can do. Would you prefer just to have me close #36437 , split out the fuzz target commits, and get this one merged ASAP?

@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from 8d44ac8 to a30665c Compare November 25, 2026 15:39
@instagibbs

Copy link
Copy Markdown
Member Author

@fanquake fanquake added this to the 33.0 milestone Nov 25, 2026

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review ACK a30665c

I reviewed the entire code changes after the new fuzz test was deferred, the comments are minor.

Comment thread src/txrequest.h Outdated
* announcement is a request for the transaction with any witness, so a verdict about one witness (recorded
* under a wtxid that equals the txid because that copy had no witness) should not cancel it.
*/
void ForgetTxHash(const GenTxid& gtxid);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer a different name, such as ForgetTxHashOfType or similar to avoid confusion with the existing method (e.g. ForgetTxHash(ptx->GetHash()) used to be a compile error, now it compiles and has different behavior from ForgetTxHash(ptx->GetHash().ToUint256())) which may not be intended by future callers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion taken

Comment thread src/txrequest.h Outdated

/** Like GetCandidatePeers(txhash, result_peers), but only for announcements whose type (txid or wtxid)
* matches that of gtxid. */
void GetCandidatePeers(const GenTxid& gtxid, std::vector<NodeId>& result_peers) const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe we don't really need this? It's only called from tests, and it seems that existing checks already covers the behavior pretty well, so not sure if its adds enough additional coverage.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from a30665c to 44842fc Compare November 30, 2026 20:05
A child that arrives before its parent is kept as an orphan. Once the
parent is accepted on its own, the orphan is put in one randomly chosen
announcer's work set to be retried. If that announcer disconnects or is
evicted first, the orphan is never retried, and re-announcements by the
other announcers don't fetch it again since it is already held. This
keeps e.g. a CPFP child of a parent that pays for itself out of the
mempool until the orphan is evicted, and an announcer can cause it on
purpose.

Hand reconsideration over to the remaining announcer with the lowest
NodeId instead.
TX_CONFLICT means the transaction is already known, in the mempool or
confirmed, not that it is invalid. Its wtxid still went into the reject
filter. For a witnessless copy that is also the txid, so if the known
parent then left the mempool before the next block, a child arriving
afterwards was dropped as having a rejected parent. For the honest
version of a parent whose other-witness version is in the mempool, the
honest parent itself was ignored once that version left.

Don't add TX_CONFLICT results to the reject filter. The entry only saved
re-downloading and re-checking a transaction we already have. Do the
same for a DIFFERENT_WITNESS result in 1p1c package evaluation, which
ProcessPackageResult passed to ProcessInvalidTx with a valid state and
so reached the filter by another path.

This also keeps a witnessless copy of a confirmed transaction out of
the filter, as it is rejected as already known when one of its outputs
is in the coins cache, so children spending that transaction are no
longer dropped. A copy of a coinbase is rejected as TX_CONSENSUS
instead, before any input lookup, and still poisons the coinbase's
txid.

Update the rejection-type table for TX_CONFLICT.
When a 1p1c package fails the package feerate check, the child gets a
TX_RECONSIDERABLE result, and ProcessPackageResult passed it to
ProcessInvalidTx, which erased the child from the orphanage for all of
its announcers.

The failure is a property of that pair of wtxids, which
MempoolRejectedPackage already caches, not of the child. The child can
still succeed with another version of the parent, such as the one an
honest announcer holds, so it should stay available.

Skip ProcessInvalidTx for package members with a TX_RECONSIDERABLE
result. A child that is too low feerate on its own is still rejected
when its parent's work set is processed.
A reconsiderable rejection of a witnessless copy of a transaction
forgot its wtxid in TxRequestTracker regardless of announcement type,
and since that wtxid equals the txid, it also cancelled every peer's
txid-typed request for the transaction, including orphan resolution
requests for a missing parent.

Now only wtxid-typed announcements of that hash are forgotten, so
witnessless parents are treated like witnessed ones, which were never
affected since their wtxid differs from the txid.
@instagibbs
instagibbs force-pushed the 2026-10-1p1c-liveness-fixes branch from 44842fc to d8c1eb7 Compare November 30, 2026 20:30

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review ACK d8c1eb7

@ismaelsadeeq

Copy link
Copy Markdown
Member

Concept ACK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants