Skip to content

p2p: prevent BIP35 requesters from bypassing inbound tx-relay capacity - #35874

Open
l0rinc wants to merge 3 commits into
bitcoin:masterfrom
l0rinc:l0rinc/bip35-relay-capacity
Open

l0rinc wants to merge 3 commits into
bitcoin:masterfrom
l0rinc:l0rinc/bip35-relay-capacity

Conversation

@l0rinc

@l0rinc l0rinc commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem: When a node offers NODE_BLOOM, an inbound peer can advertise fRelay=false and request BIP35 mempool inventory while remaining outside the inbound transaction-relay capacity introduced in #28463.

Fix: Ignore mempool requests while the peer has transaction relay disabled, unless the connection has the mempool permission.
A BIP37 filterload message enables transaction relay and applies the existing capacity limit, preserving bitcoinj's SPV filterload-then-mempool sequence.
Targeted getdata requests remain unchanged.

@DrahtBot DrahtBot added the P2P label Aug 3, 2026
@DrahtBot

DrahtBot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35874.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34824 (net: encapsulate TxRelay state and replace recursive mutexes by w0xlt)

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.

@l0rinc
l0rinc marked this pull request as ready for review August 4, 2026 01:13
@l0rinc
l0rinc force-pushed the l0rinc/bip35-relay-capacity branch from c83a7c7 to 6726904 Compare August 4, 2026 05:14
@l0rinc l0rinc changed the title p2p: account BIP35 requests against relay capacity p2p: enforce relay limit for BIP35 requesters Aug 4, 2026
@l0rinc
l0rinc force-pushed the l0rinc/bip35-relay-capacity branch from 6726904 to dd1af38 Compare August 4, 2026 05:24
@DrahtBot

DrahtBot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task riscv32 bare metal, static libbitcoin_consensus: https://github.com/bitcoin/bitcoin/actions/runs/30880088557/job/91899376958
LLM reason (✨ experimental): CI failed because cloning the binutils-gdb submodule (sourceware.org/git/binutils-gdb.git) errored with “fatal: the remote end hung up unexpectedly” (exit code 2).

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.

@DrahtBot DrahtBot closed this Aug 4, 2026
@DrahtBot DrahtBot reopened this Aug 4, 2026
@DrahtBot DrahtBot removed the CI failed label Aug 4, 2026
Comment thread src/net_processing.cpp Outdated
if (auto tx_relay = peer.GetTxRelay(); tx_relay != nullptr) {
if (pfrom.IsInboundConn() && !pfrom.m_relays_txs) {
// BIP35 consumes tx-relay capacity while fRelay=false still disables ongoing announcements.
pfrom.m_relays_txs = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that's a protocol change? Prior to this we would not flood a peer that set BIP 37 fRelay to false with INV's until they set a filter. After this change, we would flood them with non-filtered INV's provided they previously sent a MEMPOOL message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid question. If I understood your objection correctly, it applies to TxRelay::m_relay_txs, while we're changing CNode::m_relays_txs. To make sure, I added a test that requests a BIP35 snapshot and verifies that a transaction added afterward is announced to a regular relay peer but not to the requester. It passes before and after the production change. Could you please check whether it satisfies your criterion? Thanks for the hint.

@l0rinc
l0rinc force-pushed the l0rinc/bip35-relay-capacity branch 2 times, most recently from c7460a2 to 760da86 Compare August 5, 2026 06:29
@l0rinc l0rinc changed the title p2p: enforce relay limit for BIP35 requesters p2p: prevent BIP35 requesters from bypassing inbound tx-relay capacity Aug 5, 2026
@l0rinc l0rinc closed this Aug 5, 2026
@l0rinc l0rinc reopened this Aug 5, 2026
@DrahtBot DrahtBot removed the CI failed label Aug 5, 2026
@gmaxwell

gmaxwell commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Should fRelay=false be able to request inventory at all? Do any existing pieces of software do this (outside of surveillance software, of course)?

I think it probably shouldn't be allowed. Historically fRelay=false peers have been treated as a reduced bandwidth and surveillance privacy risk, but I think that's mooted if they're doing mempool requests.

@l0rinc

l0rinc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gmaxwell.

Do any existing pieces of software do this?

I'm not sure about the details, my goal was to close a potential DoS angle.
A quick search (and some AI tutoring) turned up bitcoinj, it seems that in SPV mode with Bloom filtering, bitcoinj sets fRelay=false, then sends filterload before mempool. I'm not sure whether this is the case you had in mind.

This suggests ignoring non-permissioned mempool requests until the peer enables transaction relay, for example by sending filterload. @msgilligan, is that accurate? Does bitcoinj ever send mempool without first loading a filter?

@schildbach

Copy link
Copy Markdown
Contributor

Should fRelay=false be able to request inventory at all?

Historically, bitcoinj has walked the tx dependency chain for its risk analysis. It uses getdata messages for this.

Does bitcoinj ever send mempool without first loading a filter?

In the SPV case (which I assume is what you care about in this context), bitcoinj sets the filter first via filterload, then immediately follows up with mempool.

(Afaicr, we never used the ability to set a new filter for a connection, or add data to one. Rather, we drop the connection and build a new one.)

@l0rinc
l0rinc force-pushed the l0rinc/bip35-relay-capacity branch from 760da86 to fc657d8 Compare August 15, 2026 04:24
@l0rinc

l0rinc commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Rebased and reworked this based on the review feedback. The PR now ignores non-permissioned mempool requests while tx relay is disabled, preserving existing BIP37 and targeted getdata behavior.
Thanks @gmaxwell and @schildbach for helping clarify the intended behavior and guiding this toward a simpler solution.

An inbound peer with `fRelay=false` currently receives BIP35 inventory before enabling transaction relay, with or without the `mempool` permission.
The BIP37 test covers bitcoinj's SPV sequence by sending `filterload` before `mempool`.
An inbound peer with `fRelay=false` stays outside transaction-relay capacity accounting, yet BIP35 requests give it full mempool inventory.
Ignore these requests until transaction relay is enabled, except when the operator grants the `mempool` permission.

A BIP37 `filterload` message enables relay and applies the existing inbound capacity limit before bitcoinj's SPV flow sends `mempool`.
Targeted `getdata` requests remain unchanged.
@l0rinc
l0rinc force-pushed the l0rinc/bip35-relay-capacity branch from 14eee1f to 038e3c1 Compare November 4, 2026 17:57
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.

5 participants