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

Open
w0xlt wants to merge 4 commits from feature/addnode-bip152-hb into master AGit
w0xlt commented 2026-08-10 05:57:49 +00:00 (Migrated from github.com)

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 (https://github.com/bitcoin/bitcoin/pull/35940#issuecomment-6811490029).

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 (https://github.com/bitcoin/bitcoin/pull/35940#issuecomment-6811490029).
DrahtBot commented 2026-08-10 05:57: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
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.

<!--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/35940 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35940.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35940#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 | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/35940#pullrequestreview-4941909584), [Bicaru20](https://github.com/bitcoin/bitcoin/pull/35940#pullrequestreview-5531083661), [davidgumberg](https://github.com/bitcoin/bitcoin/pull/35940#issuecomment-6811490029) | 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: * [#36819](https://github.com/bitcoin/bitcoin/pull/36819) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36819.svg"></sub> ([RFC] enable `clang-tidy` `optin.performance.Padding` by fanquake) * [#36033](https://github.com/bitcoin/bitcoin/pull/36033) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36033.svg"></sub> ([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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
jeanpablojp (Migrated from github.com) reviewed 2026-08-14 23:32:52 +00:00
jeanpablojp (Migrated from github.com) left a comment

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.

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.
jeanpablojp (Migrated from github.com) commented 2026-08-14 23:32:52 +00:00

shouldn't this be renamed to release-notes-35940.md before merge?

shouldn't this be renamed to `release-notes-35940.md` before merge?
w0xlt (Migrated from github.com) reviewed 2026-09-16 22:34:48 +00:00
w0xlt (Migrated from github.com) commented 2026-09-16 22:34:48 +00:00

Done. Thanks.

Done. Thanks.
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

🟠 Minor · PR description advertises an unimplemented addnode suffix

The description advertises an addnode-only suffix, but the implementation exposes an address/listener permission that can also select explicitly permissioned inbound, RPC-created, and -connect peers.

Location: src/net_permissions.cpp:59 (head).

Review coverage was incomplete.


Reviewed: c29c91f5f254 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:464886e574fc96b3587e582688c29b6bd7a73bba755cfc1d2f031cc648c7ec97:a99dfe27a5d9c587aaf93be1a4842812699d6122d1d9babba7210869336cc02c --> <!-- ralph-base:9183edd25e60aa410bc3e4728989a1d75c309a09 --> <!-- ralph-head:c29c91f5f25491b7323a67edc40764241b0c59cf --> <!-- ralph-case:b6ed821de97f8b16f930fd524955ace1caf071c77846328b5682ce32b8214389 --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🟠 Minor · PR description advertises an unimplemented addnode suffix** The description advertises an addnode-only suffix, but the implementation exposes an address/listener permission that can also select explicitly permissioned inbound, RPC-created, and `-connect` peers. Location: [`src/net_permissions.cpp:59`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/c29c91f5f25491b7323a67edc40764241b0c59cf/src/net_permissions.cpp#L59>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`c29c91f5f254`](<https://git.fish.foo/bitcoin/bitcoin/commit/c29c91f5f25491b7323a67edc40764241b0c59cf>) · [Review report](<https://review.fish.foo/report/35940-c29c91f5f25491b7323a67edc40764241b0c59cf-2616-5.html>) · [Previous reports](<https://review.fish.foo/traces/35940/>) [permalink](<https://review.fish.foo/report/35940-c29c91f5f25491b7323a67edc40764241b0c59cf-2616-5.html>)
Bicaru20 (Migrated from github.com) reviewed 2026-10-15 13:55:00 +00:00
Bicaru20 (Migrated from github.com) left a comment

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.

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.
Bicaru20 (Migrated from github.com) commented 2026-10-15 13:40:44 +00:00

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`).

        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(), [])
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 -addnode` is empty but carries the suffix `bip152-hb` (`-addnode==bip152-hb`). ```suggestion 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(), []) ```
Bicaru20 (Migrated from github.com) commented 2026-10-15 13:42:49 +00:00

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

        self.restart_node(2)
        self.wait_until(configured_peer_connected)
        assert_equal(self.relay_block_through(3), [True, True, True, True])
We could add the test case where a configured peer disconnects and reconnects again on its own is granted the high-bandwidth mode again. ```suggestion self.restart_node(2) self.wait_until(configured_peer_connected) assert_equal(self.relay_block_through(3), [True, True, True, True]) ```
w0xlt (Migrated from github.com) reviewed 2026-11-12 00:43:20 +00:00
w0xlt (Migrated from github.com) commented 2026-11-12 00:43:20 +00:00

Thanks! Added in 0b54bdbfeb,

Thanks! Added in 0b54bdbfeb,
w0xlt (Migrated from github.com) reviewed 2026-11-12 00:43:49 +00:00
w0xlt (Migrated from github.com) commented 2026-11-12 00:43:49 +00:00

Thanks, good idea! Added in 0b54bdbfeb, 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.

Thanks, good idea! Added in 0b54bdbfeb, 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 commented 2026-11-12 01:17:19 +00:00 (Migrated from github.com)

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

Concept ACK, but I think it might make more sense to do this as a whitelist permission.
fanquake (Migrated from github.com) reviewed 2026-11-12 11:49:04 +00:00
fanquake (Migrated from github.com) commented 2026-11-12 11:49:05 +00:00
  connections opened for that added node. (#35940)
```suggestion connections opened for that added node. (#35940) ```
w0xlt (Migrated from github.com) reviewed 2026-11-12 19:09:15 +00:00
w0xlt (Migrated from github.com) commented 2026-11-12 19:09:15 +00:00

Done. Thanks.

Done. Thanks.
DrahtBot commented 2026-11-12 21:17:02 +00:00 (Migrated from github.com)

🚧 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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `macOS native, fuzz`: https://github.com/bitcoin/bitcoin/actions/runs/43301840898/job/131474760807</sub> <sub>LLM reason (✨ experimental): The CI failed because the `cmpctblock` fuzz target hit an assertion (`num_hb <= 3`) while processing corpus input `46958d…`.</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>
w0xlt commented 2026-11-12 22:56:34 +00:00 (Migrated from github.com)

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.

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 commented 2026-11-12 23:00:27 +00:00 (Migrated from github.com)

PR description updated.

PR description updated.
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!35940
No description provided.