p2p: replace full outbound peers that don't support tx relay (take 2) #36372

Open
fjahr wants to merge 4 commits from 2026-09-pr28538-pickup into master AGit
fjahr commented 2026-09-28 17:19:39 +00:00 (Migrated from github.com)

Picks up #28538

Outbound-full-relay slots should be used by peers that actually relay transactions, besides #28538 see #16418 and #28371 for the motivation. So try to replace peers that are not relaying txs with peers that do.

The approach differs from the original PR in a few details in response to some of the review comments there:

Nothing is changed in -blocksonly mode or during IBD. The rename commit and the functional test are taken from the original PR with some changes to match the new behavior.

Picks up #28538 Outbound-full-relay slots should be used by peers that actually relay transactions, besides #28538 see #16418 and #28371 for the motivation. So try to replace peers that are not relaying txs with peers that do. The approach differs from the original PR in a few details in response to some of the review comments there: - A replacement is connected before the peer is evicted. The original PR disconnected a non-tx-relaying peer once all full outbound slots were filled. Reviewers preferred having a replacement available first (https://github.com/bitcoin/bitcoin/pull/28538#issuecomment-1883481846). Now an extra outbound-full-relay connection is requested, like the extra network-specific peers, and the existing eviction of extra outbound peers prefers peers that don't relay txs. - Peers not relaying txs don't get `m_protect`. Otherwise they could stay forever (https://github.com/bitcoin/bitcoin/pull/28538#discussion_r1443336121), and ignoring the protection was rejected in the same thread (https://github.com/bitcoin/bitcoin/pull/28538#discussion_r1443312604). - An only peer on a network is not replaced. Otherwise the network-specific extra connections and this logic would keep replacing each other (https://github.com/bitcoin/bitcoin/pull/28538#issuecomment-1883481846). This also covers the `-maxconnections=1` case (https://github.com/bitcoin/bitcoin/pull/28538#discussion_r1417178196). Nothing is changed in `-blocksonly` mode or during IBD. The rename commit and the functional test are taken from the original PR with some changes to match the new behavior.
DrahtBot commented 2026-09-28 17:19:49 +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 Bicaru20
Concept ACK mzumsande

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:

  • #36955 (p2p: Use separate compact block nonce per network by mzumsande)
  • #36820 (refactor: remove more dead code by fanquake)
  • #36787 (cmpctblock: Cache serialized cmpctblock msg for relay [part of prefill series] by davidgumberg)
  • #35591 ([DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) by sr-gi)
  • #35558 (p2p: Prefill compact blocks by davidgumberg)

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/36372 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36372.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36372#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 | [Bicaru20](https://github.com/bitcoin/bitcoin/pull/36372#issuecomment-7217866150) | | Concept ACK | [mzumsande](https://github.com/bitcoin/bitcoin/pull/36372#pullrequestreview-5344753685) | 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: * [#36955](https://github.com/bitcoin/bitcoin/pull/36955) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36955.svg"></sub> (p2p: Use separate compact block nonce per network by mzumsande) * [#36820](https://github.com/bitcoin/bitcoin/pull/36820) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36820.svg"></sub> (refactor: remove more dead code by fanquake) * [#36787](https://github.com/bitcoin/bitcoin/pull/36787) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36787.svg"></sub> (cmpctblock: Cache serialized cmpctblock msg for relay [part of prefill series] by davidgumberg) * [#35591](https://github.com/bitcoin/bitcoin/pull/35591) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35591.svg"></sub> ([DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) by sr-gi) * [#35558](https://github.com/bitcoin/bitcoin/pull/35558) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35558.svg"></sub> (p2p: Prefill compact blocks by davidgumberg) 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-->
First-time contributor

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

🟠 Minor · Relay preference also evicts useful stale-tip recovery peers

After IBD and outside -blocksonly, a non-relaying stale-tip recovery peer can deliver a new block and then be evicted before non-announcing relaying peers, sacrificing that round's rotation without preventing block delivery.

Location: src/net_processing.cpp:5646 (head).

🔵 Suggestion · Protection exclusion also changes IBD behavior

Outside -blocksonly, non-relaying full outbounds lose m_protect eligibility during IBD too, contrary to the stated scope, although peers that keep up with our chain avoid chain-sync timeouts.

Location: src/net_processing.cpp:3209 (head).

🔵 Suggestion · Low connection limits leave no permit for replacement

With -maxconnections at most 10 and all outbound targets filled, the inherited semaphore limit prevents connect-before-evict replacement, even when the replacement request is set.

Location: src/net.cpp:2858 (head).

🔵 Suggestion · Added tests do not exercise the replacement-request consumer

The unit test inserts the replacement manually, and the functional test disables automatic connections, so deleting the new ThreadOpenConnections() selection branch would leave their assertions intact.

Location: test/functional/p2p_blocksonly.py:95 (head).

Review coverage was incomplete.


Reviewed: 5c8457a367e8 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3f89681de11a6729a084d29fd96adfa42e3f319bf8f5c8ad91552cdeb231adb4:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:d55f55eda79a98ddaad7f7bec9faca8beb097b99 --> <!-- ralph-head:5c8457a367e810a99d3784bec275f8cc0fe76cdb --> <!-- ralph-case:afb3110d71b4c0091ad0aca605d5142f6d89c166a5845850d362607591836072 --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🟠 Minor · Relay preference also evicts useful stale-tip recovery peers** After IBD and outside `-blocksonly`, a non-relaying stale-tip recovery peer can deliver a new block and then be evicted before non-announcing relaying peers, sacrificing that round's rotation without preventing block delivery. Location: [`src/net_processing.cpp:5646`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5c8457a367e810a99d3784bec275f8cc0fe76cdb/src/net_processing.cpp#L5646>) (head). **🔵 Suggestion · Protection exclusion also changes IBD behavior** Outside `-blocksonly`, non-relaying full outbounds lose `m_protect` eligibility during IBD too, contrary to the stated scope, although peers that keep up with our chain avoid chain-sync timeouts. Location: [`src/net_processing.cpp:3209`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5c8457a367e810a99d3784bec275f8cc0fe76cdb/src/net_processing.cpp#L3209>) (head). **🔵 Suggestion · Low connection limits leave no permit for replacement** With `-maxconnections` at most 10 and all outbound targets filled, the inherited semaphore limit prevents connect-before-evict replacement, even when the replacement request is set. Location: [`src/net.cpp:2858`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5c8457a367e810a99d3784bec275f8cc0fe76cdb/src/net.cpp#L2858>) (head). **🔵 Suggestion · Added tests do not exercise the replacement-request consumer** The unit test inserts the replacement manually, and the functional test disables automatic connections, so deleting the new `ThreadOpenConnections()` selection branch would leave their assertions intact. Location: [`test/functional/p2p_blocksonly.py:95`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/5c8457a367e810a99d3784bec275f8cc0fe76cdb/test/functional/p2p_blocksonly.py#L95>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`5c8457a367e8`](<https://git.fish.foo/bitcoin/bitcoin/commit/5c8457a367e810a99d3784bec275f8cc0fe76cdb>) · [Review report](<https://review.fish.foo/report/36372-5c8457a367e810a99d3784bec275f8cc0fe76cdb-2813-3.html>) · [Previous reports](<https://review.fish.foo/traces/36372/>) [permalink](<https://review.fish.foo/report/36372-5c8457a367e810a99d3784bec275f8cc0fe76cdb-2813-3.html>)
mzumsande (Migrated from github.com) reviewed 2026-09-28 21:16:20 +00:00
mzumsande (Migrated from github.com) left a comment

Concept ACK, thanks for picking this up!

Concept ACK, thanks for picking this up!
instagibbs commented 2026-09-30 19:46:55 +00:00 (Migrated from github.com)

Just a conceptual question IIUC: we could be evicting a peer that was giving us useful work for a peer that claims to do useful work. Would we want to do more validation of those claims before evicting someone?

edit: do we have evidence this is a real problem? Obviously it would be problematic if nodes quickly started converting to blocksonly, but I don't see that happening fast. Can we crawl the network to see evidence of this?

Just a conceptual question IIUC: we could be evicting a peer that was giving us useful work for a peer that *claims* to do useful work. Would we want to do more validation of those claims before evicting someone? edit: do we have evidence this is a real problem? Obviously it would be problematic if nodes quickly started converting to blocksonly, but I don't see that happening fast. Can we crawl the network to see evidence of this?
fametrano commented 2026-10-02 11:49:40 +00:00 (Migrated from github.com)

The "not evicted" checks in the first and third cases of the new p2p_blocksonly.py test can't fail. Each case connects one peer, and a node never evicts or replaces its only full-outbound peer on a network. So replacing peers in -blocksonly mode (dropping !m_opts.ignore_incoming_txs from replace_no_tx_relay) passes every test in the PR. Evicting below the outbound limit (GetExtraFullOutboundCount() >= 0) also passes this test, though the existing unit tests catch it. The second case works: disconnecting the peer instead of asking for a replacement fails it.

Two peers in each case fix this. In the first case, mocktime also has to pass MINIMUM_CONNECT_TIME (30 s), because a newer peer is never evicted. In the blocksonly case, use -maxconnections=2 and check that "setting replace no-tx-relay peer=true" is not logged. With that, both changes fail the test, and it passed 6 of 6 runs on 07e58de. Diff below.

I only looked at the new tests; I have not reviewed the C++ change.

Diff
--- a/test/functional/p2p_blocksonly.py
+++ b/test/functional/p2p_blocksonly.py
@@ -83,30 +83,41 @@
         self.log.info("Tests with outbound peers that set txrelay to false, as peers in blocksonly mode do")
         self.restart_node(0, ["-noblocksonly"])
         self.log.info("Check that we sustain full-relay outbound connections to blocksonly peers when not at the full outbound limit")
-        blocksonly_peer = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, txrelay=False)
-        # Trigger CheckForStaleTipAndEvictPeers, which is scheduled every 45s (EXTRA_PEER_CHECK_INTERVAL)
-        self.nodes[0].mockscheduler(46)
-        blocksonly_peer.sync_with_ping()
-        blocksonly_peer.peer_disconnect()
+        peers = self.add_blocksonly_peers()
+        self.trigger_eviction_check()
+        self.check_connected(peers)
 
         self.log.info("Check that we request a replacement instead of evicting full-relay outbound connections to blocksonly peers at the full outbound limit")
         # Simulate the situation of being at the max limit of full-outbound connections by setting -maxconnections to a low value
         self.restart_node(0, ["-noblocksonly", "-maxconnections=2"])
-        blocksonly_peer1 = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, txrelay=False)
-        blocksonly_peer2 = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=2, txrelay=False)
+        peers = self.add_blocksonly_peers()
         with self.nodes[0].assert_debug_log(["setting replace no-tx-relay peer=true"]):
-            self.nodes[0].mockscheduler(46)
-        blocksonly_peer1.sync_with_ping()
-        blocksonly_peer2.sync_with_ping()
-        self.nodes[0].disconnect_p2ps()
+            self.trigger_eviction_check()
+        self.check_connected(peers)
 
         self.log.info("Check that we don't evict full-relay outbound connections to blocksonly peers if we are blocksonly ourselves")
-        self.restart_node(0, ["-blocksonly", "-maxconnections=1"])
-        blocksonly_peer = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, txrelay=False)
+        self.restart_node(0, ["-blocksonly", "-maxconnections=2"])
+        peers = self.add_blocksonly_peers()
+        with self.nodes[0].assert_debug_log([], unexpected_msgs=["setting replace no-tx-relay peer=true"]):
+            self.trigger_eviction_check()
+        self.check_connected(peers)
+
+    def add_blocksonly_peers(self):
+        # Two peers, so that neither is kept only for being the sole peer on its network
+        return [self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i, txrelay=False) for i in (1, 2)]
+
+    def trigger_eviction_check(self):
+        # Pass MINIMUM_CONNECT_TIME (30s), so that a chosen peer is not kept for being new
+        self.nodes[0].setmocktime(int(time.time()) + 31)
+        # Trigger CheckForStaleTipAndEvictPeers, which is scheduled every 45s (EXTRA_PEER_CHECK_INTERVAL)
         self.nodes[0].mockscheduler(46)
-        blocksonly_peer.sync_with_ping()
-        blocksonly_peer.peer_disconnect()
 
+    def check_connected(self, peers):
+        for peer in peers:
+            peer.sync_with_ping()
+        self.nodes[0].disconnect_p2ps()
+        self.nodes[0].setmocktime(0)
+
     def blocks_relay_conn_tests(self):
         self.log.info('Tests with node in normal mode with block-relay-only connections')
         self.restart_node(0, ["-noblocksonly"])  # disables blocks only mode
The "not evicted" checks in the first and third cases of the new `p2p_blocksonly.py` test can't fail. Each case connects one peer, and a node never evicts or replaces its only full-outbound peer on a network. So replacing peers in `-blocksonly` mode (dropping `!m_opts.ignore_incoming_txs` from `replace_no_tx_relay`) passes every test in the PR. Evicting below the outbound limit (`GetExtraFullOutboundCount() >= 0`) also passes this test, though the existing unit tests catch it. The second case works: disconnecting the peer instead of asking for a replacement fails it. Two peers in each case fix this. In the first case, mocktime also has to pass MINIMUM_CONNECT_TIME (30 s), because a newer peer is never evicted. In the blocksonly case, use `-maxconnections=2` and check that "setting replace no-tx-relay peer=true" is not logged. With that, both changes fail the test, and it passed 6 of 6 runs on 07e58de. Diff below. I only looked at the new tests; I have not reviewed the C++ change. <details><summary>Diff</summary> ```diff --- a/test/functional/p2p_blocksonly.py +++ b/test/functional/p2p_blocksonly.py @@ -83,30 +83,41 @@ self.log.info("Tests with outbound peers that set txrelay to false, as peers in blocksonly mode do") self.restart_node(0, ["-noblocksonly"]) self.log.info("Check that we sustain full-relay outbound connections to blocksonly peers when not at the full outbound limit") - blocksonly_peer = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, txrelay=False) - # Trigger CheckForStaleTipAndEvictPeers, which is scheduled every 45s (EXTRA_PEER_CHECK_INTERVAL) - self.nodes[0].mockscheduler(46) - blocksonly_peer.sync_with_ping() - blocksonly_peer.peer_disconnect() + peers = self.add_blocksonly_peers() + self.trigger_eviction_check() + self.check_connected(peers) self.log.info("Check that we request a replacement instead of evicting full-relay outbound connections to blocksonly peers at the full outbound limit") # Simulate the situation of being at the max limit of full-outbound connections by setting -maxconnections to a low value self.restart_node(0, ["-noblocksonly", "-maxconnections=2"]) - blocksonly_peer1 = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, txrelay=False) - blocksonly_peer2 = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=2, txrelay=False) + peers = self.add_blocksonly_peers() with self.nodes[0].assert_debug_log(["setting replace no-tx-relay peer=true"]): - self.nodes[0].mockscheduler(46) - blocksonly_peer1.sync_with_ping() - blocksonly_peer2.sync_with_ping() - self.nodes[0].disconnect_p2ps() + self.trigger_eviction_check() + self.check_connected(peers) self.log.info("Check that we don't evict full-relay outbound connections to blocksonly peers if we are blocksonly ourselves") - self.restart_node(0, ["-blocksonly", "-maxconnections=1"]) - blocksonly_peer = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, txrelay=False) + self.restart_node(0, ["-blocksonly", "-maxconnections=2"]) + peers = self.add_blocksonly_peers() + with self.nodes[0].assert_debug_log([], unexpected_msgs=["setting replace no-tx-relay peer=true"]): + self.trigger_eviction_check() + self.check_connected(peers) + + def add_blocksonly_peers(self): + # Two peers, so that neither is kept only for being the sole peer on its network + return [self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i, txrelay=False) for i in (1, 2)] + + def trigger_eviction_check(self): + # Pass MINIMUM_CONNECT_TIME (30s), so that a chosen peer is not kept for being new + self.nodes[0].setmocktime(int(time.time()) + 31) + # Trigger CheckForStaleTipAndEvictPeers, which is scheduled every 45s (EXTRA_PEER_CHECK_INTERVAL) self.nodes[0].mockscheduler(46) - blocksonly_peer.sync_with_ping() - blocksonly_peer.peer_disconnect() + def check_connected(self, peers): + for peer in peers: + peer.sync_with_ping() + self.nodes[0].disconnect_p2ps() + self.nodes[0].setmocktime(0) + def blocks_relay_conn_tests(self): self.log.info('Tests with node in normal mode with block-relay-only connections') self.restart_node(0, ["-noblocksonly"]) # disables blocks only mode ``` </details>
Bicaru20 (Migrated from github.com) reviewed 2026-10-13 12:14:09 +00:00
Bicaru20 (Migrated from github.com) left a comment

Conecpt ACK 07e58de168
I left a suggestion to try to make the tests more robusts

With the new changes, if we are not in -blocksonly mode or in IBD, our node will be able to evict the nodes that do not relay transaction first. Also, these nodes will not be protected against eviction with the m_protect flag. Before evicting one of the nodes, it ensures a new peer has been found.

One question I have is what happens if we have a node that doesn't relay transactions and another one that does but has been silent for some time. In this case, if I have understood it correclty, it would evict first the peer that doesn't relay the tansactions. Shouldn't we chose the peer that is active over the one that has been silent for some time even if the active peer is not relaying transactions?

Conecpt ACK 07e58de16805e66fc2bccc842c1c2edc4ee1f897 I left a suggestion to try to make the tests more robusts With the new changes, if we are not in -blocksonly mode or in IBD, our node will be able to evict the nodes that do not relay transaction first. Also, these nodes will not be protected against eviction with the `m_protect` flag. Before evicting one of the nodes, it ensures a new peer has been found. One question I have is what happens if we have a node that doesn't relay transactions and another one that does but has been silent for some time. In this case, if I have understood it correclty, it would evict first the peer that doesn't relay the tansactions. Shouldn't we chose the peer that is active over the one that has been silent for some time even if the active peer is not relaying transactions?
Bicaru20 (Migrated from github.com) commented 2026-10-13 10:32:16 +00:00

nit:

        LogDebug(BCLog::NET, "setting replace no-tx-relay peer=%s\n", flag ? "true" : "false");
nit: ```suggestion LogDebug(BCLog::NET, "setting replace no-tx-relay peer=%s\n", flag ? "true" : "false"); ```
Bicaru20 (Migrated from github.com) commented 2026-10-13 11:10:35 +00:00

I think it would be good to add a new test case here to check that a replecemnt is requested even when the candidate with m_relays_txs=false cannot be evicted yet because it is younger than MINIMUM_CONNECT_TIME

    vNodes[1]->fDisconnect = false;
    AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
    vNodes.back()->m_relays_txs = false;
    AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
    vNodes.back()->m_relays_txs = true;
    clock += 1s;
    peerLogic->CheckForStaleTipAndEvictPeers();
    BOOST_CHECK(connman->GetReplaceNoTxRelayPeer());
    for (const CNode* node : vNodes) {
        BOOST_CHECK(!node->fDisconnect);
    }
I think it would be good to add a new test case here to check that a replecemnt is requested even when the candidate with `m_relays_txs=false` cannot be evicted yet because it is younger than MINIMUM_CONNECT_TIME ```cpp vNodes[1]->fDisconnect = false; AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY); vNodes.back()->m_relays_txs = false; AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY); vNodes.back()->m_relays_txs = true; clock += 1s; peerLogic->CheckForStaleTipAndEvictPeers(); BOOST_CHECK(connman->GetReplaceNoTxRelayPeer()); for (const CNode* node : vNodes) { BOOST_CHECK(!node->fDisconnect); } ```
fjahr (Migrated from github.com) reviewed 2026-11-18 16:47:34 +00:00
fjahr (Migrated from github.com) commented 2026-11-18 16:47:34 +00:00

This is not needed anymore, we are dealing with the newline internally for a while now already.

This is not needed anymore, we are dealing with the newline internally for a while now already.
fjahr (Migrated from github.com) reviewed 2026-11-18 16:47:47 +00:00
fjahr (Migrated from github.com) commented 2026-11-18 16:47:47 +00:00

I added a check for this but it could be done simpler than you suggested because the test already passes through this state so I added just the check in the right place.

I added a check for this but it could be done simpler than you suggested because the test already passes through this state so I added just the check in the right place.
fjahr commented 2026-11-18 16:51:57 +00:00 (Migrated from github.com)

Addressed code review from @fametrano and @Bicaru20, thanks! I took the suggested test changes mostly with a few edits. Aside from addressing the comments I also expanded the tests with additional checks in a few places.

Shouldn't we chose the peer that is active over the one that has been silent for some time even if the active peer is not relaying transactions?

@Bicaru20 Good question. The last block announcement only decides between peers of the same kind. A tx relaying peer that stays silent is still handled by the chain sync and stale tip logic, and we have the block-relay-only peers on top of that.

we could be evicting a peer that was giving us useful work for a peer that claims to do useful work. Would we want to do more validation of those claims before evicting someone?

@instagibbs The replacement peer makes the same claims as every other full outbound peer we connect to while the evicted peer has told us that it will drop our transactions. So I don't think we can end up doing worse in terms of tx relay and the four block relay peers are protected anyway.

If that still seems undesirable I could see two possible tweaks to the concept: 1. we could only evict once the replacement has sent us a transaction, but of course that is easy to do for an attacker that is lying to us. Or 2. we could tolerate one or two blocksonly peers and only replace the ones beyond that threshold, which was already mentioned as an option in #28538. I prefer the current approach and I don't think there are any harmful effects but I am open to adopt if reviewers prefer a different change.

do we have evidence this is a real problem?

For a more complete answer I will try to do a fresh crawl of the network since I didn't find a recent dataset that included the flags. But the KIT monitoring snapshots record block and tx announcements per reachable peer which should be a good approximation with the caveat that it only covers IPv4 and IPv6. Over the last year somewhere between 1% and 2% of the peers there announced blocks but no transactions, with a slight upward trend. That's about 100 to 150 nodes, not sure how inflated their total node counts may be from sybils etc. But anyway it indeed does not seem to be a big problem today and I see it more as a cheap precaution. Had the BIP110 campaign aimed at making node runners deactivate their mempool for example, this could have been relevant.

Addressed code review from @fametrano and @Bicaru20, thanks! I took the suggested test changes mostly with a few edits. Aside from addressing the comments I also expanded the tests with additional checks in a few places. > Shouldn't we chose the peer that is active over the one that has been silent for some time even if the active peer is not relaying transactions? @Bicaru20 Good question. The last block announcement only decides between peers of the same kind. A tx relaying peer that stays silent is still handled by the chain sync and stale tip logic, and we have the block-relay-only peers on top of that. > we could be evicting a peer that was giving us useful work for a peer that *claims* to do useful work. Would we want to do more validation of those claims before evicting someone? @instagibbs The replacement peer makes the same claims as every other full outbound peer we connect to while the evicted peer has told us that it will drop our transactions. So I don't think we can end up doing worse in terms of tx relay and the four block relay peers are protected anyway. If that still seems undesirable I could see two possible tweaks to the concept: 1. we could only evict once the replacement has sent us a transaction, but of course that is easy to do for an attacker that is lying to us. Or 2. we could tolerate one or two blocksonly peers and only replace the ones beyond that threshold, which was already mentioned as an option in #28538. I prefer the current approach and I don't think there are any harmful effects but I am open to adopt if reviewers prefer a different change. > do we have evidence this is a real problem? For a more complete answer I will try to do a fresh crawl of the network since I didn't find a recent dataset that included the flags. But the [KIT monitoring snapshots](https://www.dsn.kastel.kit.edu/bitcoin/data.html) record block and tx announcements per reachable peer which should be a good approximation with the caveat that it only covers IPv4 and IPv6. Over the last year somewhere between 1% and 2% of the peers there announced blocks but no transactions, with a slight upward trend. That's about 100 to 150 nodes, not sure how inflated their total node counts may be from sybils etc. But anyway it indeed does not seem to be a big problem today and I see it more as a cheap precaution. Had the BIP110 campaign aimed at making node runners deactivate their mempool for example, this could have been relevant.
fjahr commented 2026-11-18 17:49:42 +00:00 (Migrated from github.com)

I let a clanker write a small crawler that connected to all reachable nodes from the latest bitnod.es snapshot (2026-11-18) and recorded the relay flag from their version message:

Network Handshakes relay=0 Share P(≥1 of 8 full outbound peers)
IPv4 5,618 85 1.51% 11.5%
IPv6 549 11 2.00% 15.0%
Tor 10,277 58 0.56% 4.4%
I2P 4,671 12 0.26% 2.0%
All 21,115 166 0.79% 6.1%

So the share on Tor is even smaller than on clearnet and the KIT data matches the result closely.

I let a clanker write a small crawler that connected to all reachable nodes from the latest bitnod.es snapshot (2026-11-18) and recorded the relay flag from their version message: | Network | Handshakes | `relay=0` | Share | P(≥1 of 8 full outbound peers) | |---|---|---|---|---| | IPv4 | 5,618 | 85 | 1.51% | 11.5% | | IPv6 | 549 | 11 | 2.00% | 15.0% | | Tor | 10,277 | 58 | 0.56% | 4.4% | | I2P | 4,671 | 12 | 0.26% | 2.0% | | All | 21,115 | 166 | 0.79% | 6.1% | So the share on Tor is even smaller than on clearnet and the KIT data matches the result closely.
Bicaru20 commented 2026-11-27 12:07:25 +00:00 (Migrated from github.com)

ACK 5c8457a367

I was worried that this new behaviour could isolate the blocksonly node. Specifically I wonder what would happen if one of those nodes wanted to send a transaction. But after thinking a little bit I saw that it would propagate normally since the blocksonly nodes can also choose their peers, so as long as they have one peer that is not blocksonly there is no problem. Still, I ran a small experiment to see how the normal nodes now change look for peers that are not blocksonly and also to see if the propagation of transactions is afected.

Experiment:

The experiment consist on 6 nodes an a regtest. From nodes 1 to 3 are normal and nodes from 4 to 6 are blocksonly. Their initials connections where (I limited the outbound connection to 2):

  • Node 1 → 2, 4
  • Node 2 → 3, 5
  • Node 3 → 1, 6
  • Node 4 → 2, 5
  • Node 5 → 3, 6
  • Node 6 → 1, 4

That way I could see if node 1 to 3 would change their blocksonly peers for normal peers. This is what I got:

photo_2026-11-27_12-56-36

(The image has been generated with gemini. I directly passed the logs of the info I collected to the agent to generate this graph)

The first and second node where able to connect to normal nodes very quickly. For some reason for a short time they connected again to a blockonly node. I had some issues with node 3 during that time so probably that is the issue. The node 3 took longer to connect to just normal nodes but evetually it also got there. I also checked that before disconnecting from a blocksonly they always had already the new connection.

Since I already had build this setup, I also tried to brodcast a trasnaction from one of the blockonly nodes with sendrawtransaction and there was no problem with the transaction arriving to the others nodes.

This is a very small experiment but it was just to see that the pr works as expected :)

ACK 5c8457a367e810a99d3784bec275f8cc0fe76cdb I was worried that this new behaviour could isolate the blocksonly node. Specifically I wonder what would happen if one of those nodes wanted to send a transaction. But after thinking a little bit I saw that it would propagate normally since the blocksonly nodes can also choose their peers, so as long as they have one peer that is not blocksonly there is no problem. Still, I ran a small experiment to see how the normal nodes now change look for peers that are not blocksonly and also to see if the propagation of transactions is afected. <details> <summary> Experiment: </summary> The experiment consist on 6 nodes an a regtest. From nodes 1 to 3 are normal and nodes from 4 to 6 are `blocksonly`. Their initials connections where (I limited the outbound connection to 2): - Node 1 → 2, 4 - Node 2 → 3, 5 - Node 3 → 1, 6 - Node 4 → 2, 5 - Node 5 → 3, 6 - Node 6 → 1, 4 That way I could see if node 1 to 3 would change their `blocksonly` peers for normal peers. This is what I got: <img width="1280" height="527" alt="photo_2026-11-27_12-56-36" src="https://git.fish.foo/attachments/bcc81592-3b36-4e71-85a9-fcc959b6bccc" /> (_The image has been generated with gemini. I directly passed the logs of the info I collected to the agent to generate this graph_) The first and second node where able to connect to normal nodes very quickly. For some reason for a short time they connected again to a blockonly node. I had some issues with node 3 during that time so probably that is the issue. The node 3 took longer to connect to just normal nodes but evetually it also got there. I also checked that before disconnecting from a blocksonly they always had already the new connection. Since I already had build this setup, I also tried to brodcast a trasnaction from one of the blockonly nodes with `sendrawtransaction` and there was no problem with the transaction arriving to the others nodes. This is a very small experiment but it was just to see that the pr works as expected :) </details>
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!36372
No description provided.