mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
p2p: cap maxconnections at 2,000 to reduce crash risk #35919
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!35919
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/p2p-handle-zero-orphanage-latency-share"
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?
Problem: The orphanage can abort when more than 3,000 peers have orphan announcements.
The
-maxconnectionssetting currently has no explicit upper bound.Fix: Cap
-maxconnectionsat 2,000 with a warning before reserving file descriptors, while retaining the default of 200.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
No conflicts as of last run.
ACK 1ac1f10e7b0e06e8d01a35cabf5bef49ea43c69a
Reproduced the abort on master
128456b62dwith three peers against a global limit of 2. The two halves of the fix depend on each other: with only the clamp and the old>filter, every peer sits at exactly its floored share, the heap comes out empty and the loop pops from it, which segfaults here. So>=is not cleanup. Full unit suite andp2p_orphan_handling.pypass on the merge.nit: the comment on
MaxPeerLatencyScore()(txorphanage.cpp:210) still says the number of peers times that value adds up toMaxGlobalLatencyScore(), and that keeping every peer below 1 keeps the global limit.LimitOrphans()now enforces a floor of 1 instead, so that stops matching what runs once there are more peers than slots.nit: the new test passes whichever peer gets trimmed.
BOOST_CHECK(!orphanage->HaveTxFromPeer(txns.at(2)->GetWitnessHash(), 2))pins it, and passes as written.nit:
#include <util/check.h>inorphanage_tests.cppis added by de6342cd45 and nothing uses it after 1ac1f10e7b.test_bitcoinbuilds with the line removed.Thanks @jeanpablojp, rebased and took all three suggestions (code comment, include and new test) - added you as co-author for the first commit.
re-ACK
5f4429c20cThanks for the co-author credit.
It's worthing changing the fuzz targets to reach the zero-share path. See:
code review ACK
5f4429c20clight ACK
5f4429c20cI'm light ACKing because it's my first time looking into the orphanage. Code looks good, I left a couple of non-blocking ideas.
(comment placed in random location), in
src/node/txorphanage.h, we say:github.com/bitcoin/bitcoin@51ddab532c/src/node/txorphanage.h (L35)"as long as they don't exceed their limits" is no longer accurate: a peer exactly at his limit isn't protected anymore if the number of peers holding orphans is higher than the global limit. You could rephrase this as "as long as they stay strictly below their limits"
Might be worth it to clarify why it might be equal? Something like:
Note that the per-peer latency limit is floored at 1, so if there are more peers with orphans than the global latency limit, the global limit is exceeded even if every peer's DoS score is exactly 1.
nit: extra whitespace here
nit: (Found with Fable 5): every other block in the test ends with a
orphanage->SanityCheck();, you should add it there too. It will initially fail, because the orphanage is not properly trimmed.In the first commit:
Then you change it to
orphanage->SanityCheck();in the second one.Rebased, adjusted the commit structure, the PR description and pushed a version incorporating the review feedback:
SanityCheck()after trimming.txorphanage_simnow exercises global latency scores below the peer count and models the minimum share and score-one eligibility.GetDosScore()resource preconditions now useAssert().Thanks @brunoerg and @danielabrozzoni for the suggestions.
Good point, fixed, thanks!
Added a whole new commit with doc adjustments, thanks!
Thanks, widened the simulation's limits and matched its trimming model to the minimum share of one, added you as coauthor.
It's not extra, in the next commit it're replaced by a
!, this way the diff is simpler :)Thanks, added the sanity check after trimming back to the limit (was originally skipped since the characterization test couldn't include it yet).
Base:
4303f3b7f0775cdbbe77faddf142e1e44fa590caHead:
b30f750de56c4e510f8af5a4dbba4e821b71a9b1Design and approach
The peer bound omits
-connectpeers (src/node/txorphanage.h:26, head)The assertion does not bound peers opened through
-connect. Startup copies each configured target intom_specified_outgoing, andThreadOpenConnectionsopens each asConnectionType::MANUALwith no outbound grant. This path has no-maxconnectionsor addnode-semaphore limit, and manual peers can enter the transaction-download path that adds orphan announcements. More than 3,000 such peers could therefore still makeMaxPeerLatencyScore()zero, leaving this configuration exposed to the reported risk. Include transaction-relaying-connectpeers in the bound or ensure the orphanage handles higher peer counts. Although the checkout permits this configuration, no production configuration with more than 3,000 successful-connectpeers was identified, so production impact is unconfirmed.Review coverage was incomplete.
Review limitations
Full review report
Rebased on master and simplified this to cap
-maxconnectionsat 2,000 with a warning instead of changing orphanage trimming - seems simpler, thanks @instagibbs.concept ACK, we really shouldn't let users configure a number where a deterministic crash is possible
crACK
ec01169832LGTM!
Nonblocking nit: There is also another parsing of "-maxconnections" in line 804, there it could be also changed to
GetIntArg<int>.We could do that for consistency, but here I changed it to avoid premature 32 bit casts. Given that we're checking the bounds here, whoever requests the param after this should be able to use
GetIntArg.ACK
ec01169832The residual risk is the client adding 1000 more connections manually, which seems vanishingly small
do we want to document this more? e.g., somewhere have
ACK
ec01169832Show Signature
vasild's public key is on openpgp.org
I thinks this would be worthwhile to add.
Thanks for the reviews, added a
static_assertto explain why capping was necessary.reACK https://github.com/bitcoin/bitcoin/pull/35919/commits/b30f750de56c4e510f8af5a4dbba4e821b71a9b1
reACK
b30f750de5ACK
b30f750de5Seems fine, don't think I know of anybody actually hitting 2000 peers.
Backported to
32.xin #36596.ralph referenced this pull request2026-10-22 12:14:19 +00:00
ralph referenced this pull request2026-10-26 16:39:15 +00:00