Skip to content

net: add bip152hb permission to select BIP152 high-bandwidth peers - #35940

Open
w0xlt wants to merge 4 commits into
bitcoin:masterfrom
w0xlt:feature/addnode-bip152-hb
Open

w0xlt wants to merge 4 commits into
bitcoin:masterfrom
w0xlt:feature/addnode-bip152-hb

Conversation

@w0xlt

@w0xlt w0xlt commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Bitcoin Core automatically selects up to three BIP152 high-bandwidth peers after they deliver new blocks. This works well for ordinary connections, but it cannot use topology information known to the operator.

For example, an operator may run nodes in multiple locations, or maintain a stable, low-latency link to another node, and want that peer to announce compact blocks immediately and consistently, including after reconnects, instead of waiting for automatic selection.

This PR adds a bip152hb net permission:

-addnode=203.0.113.5 -whitelist=bip152hb,[email protected]

For a peer with this permission, the node requests high-bandwidth mode in the existing SENDCMPCT message sent at VERACK, so it applies to every connection to that peer and requires no new P2P messages. It works with the existing -whitelist/-whitebind semantics: out applies to manual connections (-addnode, -connect, addnode RPC), in (the default) to inbound connections, and subnets are supported. Matching is by IP address or subnet, so hostnames are not supported.

Peers with the permission are additional to the three automatically selected high-bandwidth peers and never take one of their slots. This intentionally allows explicit configuration to exceed BIP152's current three-peer recommendation and may increase redundant bandwidth. If accepted, BIP152 can be updated separately.

Notes:

  • bip152hb is not included in all: unlike the other flags it grants the peer nothing and only costs bandwidth, so existing all@ configurations are unaffected.
  • The permission is rejected at startup with -blocksonly, where high-bandwidth mode is never requested.

Earlier versions of this PR used an -addnode=<host>=bip152-hb suffix; it was reworked into a permission following review (#35940 (comment)).

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

DrahtBot commented Aug 10, 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
Concept ACK jeanpablojp, Bicaru20, davidgumberg

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:

  • #36819 ([RFC] enable clang-tidy optin.performance.Padding by fanquake)
  • #36033 ([wip,nomerge,rfc] build: Require C++23 compiler 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.

@jeanpablojp jeanpablojp 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

The opt-in override of the BIP152 three-peer cap seems fine to me, since it's an explicit operator choice, not a default, and it's disclosed upfront.
Reusing -addnode also made more sense to me than creating a dedicated option.

Comment thread doc/release-notes-35940.md Resolved

@Bicaru20 Bicaru20 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 think it’s a good addition to let users add their own high-bandwidth peers, as it gives them more control. I was initially worried about there being no cap on the number of user-selected high-bandwidth peers. However, since this will mostly be used by advanced users, it only affects the operator's own node, and the release notes already warn about the extra bandwidth, I think it's okay to leave it as is.

Comment thread test/functional/feature_config_args.py Outdated
extra_args=["-blocksonly", "-addnode=127.0.0.1:18444=bip152-hb"],
expected_msg="Error: Invalid -addnode value '127.0.0.1:18444=bip152-hb': the bip152-hb suffix is incompatible with -blocksonly",
)

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.

Following the same pattern as in the test_empty_addnode in line 268 of the same file, I think we could also check the case where an -addnodeis empty but carries the suffixbip152-hb (-addnode==bip152-hb`).

Suggested change
with node.assert_debug_log(expected_msgs=["Ignoring empty -addnode value"]):
self.start_node(0, extra_args=["-blocksonly", "-addnode==bip152-hb"])
util.assert_equal(node.getaddednodeinfo(), [])

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.

Thanks! Added in 0b54bdb,

# Receiving another block from the configured peer must not insert it
# into the automatic list or displace one of those three peers.
assert_equal(self.relay_block_through(2), [True, True, True, True])

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.

We could add the test case where a configured peer disconnects and reconnects again on its own is granted the high-bandwidth mode again.

Suggested change
self.restart_node(2)
self.wait_until(configured_peer_connected)
assert_equal(self.relay_block_through(3), [True, True, True, True])

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.

Thanks, good idea! Added in 0b54bdb, with a small change: rather than restarting node 2, the test disconnects it and reconnects with addnode ... onetry. Otherwise the addnode thread can take up to 60s to retry.

@davidgumberg

Copy link
Copy Markdown
Contributor

Concept ACK, but I think it might make more sense to do this as a whitelist permission.

Comment thread doc/release-notes-35940.md Outdated
- Added persistent BIP152 high-bandwidth compact block announcement requests
for selected outbound added-node connections. Append `=bip152-hb` to an
`-addnode=<host>[:<port>]` value to request high-bandwidth announcements from
connections opened for that added node.

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.

Suggested change
connections opened for that added node.
connections opened for that added node. (#35940)

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.

Done. Thanks.

@w0xlt
w0xlt force-pushed the feature/addnode-bip152-hb branch from 499495a to 5bf17f2 Compare November 12, 2026 19:08
Add a "bip152hb" permission that can be granted with -whitelist and
-whitebind, and that is reported by getpeerinfo. The next commit uses it
to request BIP152 high-bandwidth compact block announcements from such
peers, so operators can apply topology knowledge (for example a
low-latency link to another node they run) that the automatic
high-bandwidth peer selection cannot have.

Unlike the existing flags, this one grants the peer nothing and only
makes us request extra announcements. It is therefore not part of
"all", which would otherwise increase bandwidth usage for existing
configurations.

The flag has no effect yet.
@w0xlt
w0xlt force-pushed the feature/addnode-bip152-hb branch from 5bf17f2 to 7549b41 Compare November 12, 2026 20:35
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task macOS native, fuzz: https://github.com/bitcoin/bitcoin/actions/runs/43301840898/job/131474760807
LLM reason (✨ experimental): The CI failed because the cmpctblock fuzz target hit an assertion (num_hb <= 3) while processing corpus input 46958d….

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.

Bitcoin Core automatically selects up to three BIP152 high-bandwidth
peers after they deliver new blocks. That selection cannot use topology
information known to the operator, e.g. a stable low-latency link to
another node they run, which should announce compact blocks immediately
and consistently, including after reconnects.

For peers with the bip152hb permission, request high-bandwidth mode in
the SENDCMPCT message sent at VERACK, so that this applies to every
connection to such a peer. Keep these peers out of
lNodesAnnouncingHeaderAndIDs: they are additional to the three
automatically selected peers and must not displace them. As for the
automatic selection, never request high-bandwidth mode in -blocksonly
mode.

Combined with the existing "out" whitelist direction, this lets an
operator configure an added node as high-bandwidth, e.g.
-addnode=203.0.113.5 -whitelist=bip152hb,[email protected]

The cmpctblock fuzz target asserted that there are at most three
high-bandwidth peers. Only count automatically selected ones there, and
check that peers with the permission are high-bandwidth once the
handshake completes.
High-bandwidth compact block announcements are never requested in
-blocksonly mode, because our mempool would not contain the transactions
needed to reconstruct the blocks. Fail at startup when -whitelist or
-whitebind grants the bip152hb permission in that mode, rather than
silently ignoring the operator's configuration.
@w0xlt
w0xlt force-pushed the feature/addnode-bip152-hb branch from 7549b41 to c29c91f Compare November 12, 2026 22:30
@w0xlt

w0xlt commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @davidgumberg for the suggestion! I've reworked the PR to add a bip152hb permission instead of the -addnode suffix:

-addnode=203.0.113.5 -whitelist=bip152hb,[email protected]

The diff is a lot smaller now: there's no extra -addnode parsing and no code to match connections against added nodes.

As a bonus, it now also works with the addnode RPC and -connect, can cover several nodes with one subnet entry (e.g. bip152hb,[email protected]/24), and can apply to inbound connections from those addresses.

Two trade-offs:

  • Whitelist entries only match IPs and subnets, so an addnode given as a hostname, or a connection made through a name proxy, can no longer get high-bandwidth mode.
  • bip152hb isn't included in all: unlike the other flags it grants the peer nothing and only costs us bandwidth. It's also rejected with -blocksonly, where high-bandwidth mode is never requested.

I think losing hostnames is acceptable so I pushed a new version.

@w0xlt

w0xlt commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

PR description updated.

@w0xlt w0xlt changed the title net: allow selecting BIP152 high-bandwidth peers with -addnode net: add bip152hb permission to select BIP152 high-bandwidth peers Nov 12, 2026
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