mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
p2p: replace full outbound peers that don't support tx relay (take 2) #36372
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36372
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-09-pr28538-pickup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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).-maxconnections=1case (https://github.com/bitcoin/bitcoin/pull/28538#discussion_r1417178196).Nothing is changed in
-blocksonlymode or during IBD. The rename commit and the functional test are taken from the original PR with some changes to match the new behavior.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.
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:
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.
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 losem_protecteligibility 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
-maxconnectionsat 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 reportspermalink
Concept ACK, thanks for picking this up!
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?
The "not evicted" checks in the first and third cases of the new
p2p_blocksonly.pytest 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-blocksonlymode (dropping!m_opts.ignore_incoming_txsfromreplace_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=2and 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 on07e58de. Diff below.I only looked at the new tests; I have not reviewed the C++ change.
Diff
Conecpt ACK
07e58de168I 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_protectflag. 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?
nit:
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=falsecannot be evicted yet because it is younger than MINIMUM_CONNECT_TIMEThis is not needed anymore, we are dealing with the newline internally for a while now already.
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.
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.
@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.
@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.
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.
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:
relay=0So the share on Tor is even smaller than on clearnet and the KIT data matches the result closely.
ACK
5c8457a367I 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):That way I could see if node 1 to 3 would change their
blocksonlypeers for normal peers. This is what I got:(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
sendrawtransactionand 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 :)