mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
net: prevent duplication manual connections (take 2) #35600
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!35600
Loading…
Reference in a new issue
No description provided.
Delete branch "duplicate-connections-2"
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?
Fixes #5299.
-connectand-addnodecan attempt the same manual connection concurrently during startup. The existing duplicate checks cannot see a peer until it has been added tom_nodes, so both attempts can pass and open connections.Reserve the destination in
OpenNetworkConnection()before checking connected peers or starting the connection. The reservation stays in place until the attempt fails or the new peer has been added tom_nodes.This applies to
ConnectionType::MANUAL, including-connect,-addnode, manual reconnections, andaddnode onetry. Automatic outbound connections are outside this change.The functional test checks the original two-node startup case. It also holds a manual connection in a local proxy handshake and verifies that an overlapping attempt is rejected, that a failed attempt releases its reservation, and that equivalent numeric addresses share a reservation.
Unlike #27804, this handles attempts in the connection manager rather than deduplicating configuration arguments. Hostnames use their original string as the reservation key, so different names that resolve to the same endpoint may still overlap. This avoids an extra DNS lookup.
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.
Concept ACK
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
ACK
081ba2b98cBuilt and ran the new test, the functional suite and the net unit tests. The new test fails with the duplicate check disabled, and also when the key normalization or the release after a failed attempt is broken.
The test still passes if the reservation covers every connection type (net.cpp:3139). An
addconnectionto the same destination while a manual attempt is in progress would catch that. Non-blocking.Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🔵 Suggestion · Equivalent hostname spellings get separate reservations
The documented raw-hostname scope leaves a pre-existing duplicate-dial case for names with omitted versus explicit default ports or different case, although normalizing those forms requires no DNS lookup.
Location:
src/net.cpp:376(head).🔵 Suggestion · In-progress rejection discards queued manual fallbacks
Overlapping manual dials can discard a queued v1 fallback or return early from
onetry; production impact is unconfirmed, and no in-tree caller relying ononetrycompletion was found.Location:
src/net.cpp:3187(head).🔵 Suggestion · Proxy and Future waits ignore the timeout factor
The new functional test uses unscaled ten-second socket and Future waits, making slow CI runs more timing-sensitive; no flaky run has been demonstrated.
Location:
test/functional/p2p_duplicate_manual_connections.py:104(head).Review coverage was incomplete.
Reviewed:
120d45ecac6b· Review report · Previous reportspermalink
ralph says to drop them, which seems right? #35600
Good bot. Taken.
ACK
590947d783I think this also partially fixes https://github.com/bitcoin/bitcoin/issues/22559. In there, there is another bug that it is related and I think it may make sense to address it in this PR. I left my suggestions in the comments of the issue so feel free to check it out or ignore it if you think it deserve its own pr.
That being said, I tested the code by passing the test and also in I2P. In I2P it is very easy to reproduce this bug. You can do so by connecting to the same address multiple times at the same time:
With this you can create duplicated connections to your node (as many as you want in theory, I've just tried with 3 duplicated connections).
If you run the comand above after the fix of this pr, the duplicates connections are gone.
🐙 This pull request conflicts with the target branch and needs rebase.
Thanks for reviewing @Bicaru20.
I agree that this PR only partially fixes #22559, but I think in this case I'm going to leave the fix for that up to a separate PR as IMO the nonce tie-breaker probably wants some decent independent scrutiny.
I'd encourage you (or anyone) to perhaps followup this PR with a complete fix for it though!