mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:29:40 +00:00
net: ignore repeated -addnode startup values #36014
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!36014
Loading…
Reference in a new issue
No description provided.
Delete branch "net-deduplicate-startup-addnodes"
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?
Startup
-addnodevalues are copied directly into the connection manager's added-node list. Unlike runtimeaddnode addcalls, this path does not reject repeated values.For example:
All three entries are currently stored, although on mainnet they refer to the same peer. While the destination is disconnected,
ThreadOpenAddedConnections()processes each entry during every retry cycle.This can cause redundant DNS lookups, connection attempts, and log messages.
getaddednodeinfoalso reports the repeated entries.This PR checks each startup value with the same lookup that
addnode adduses, keeps the first entry, and logs a warning for each ignored value naming the entry it matched.Two values refer to the same peer if they are the same string, the same numeric address (e.g.
[::1]and[0:0:0:0:0:0:0:1]), or the same host and effective port (e.g.example.comandexample.com:8333on mainnet). No DNS lookups are done.To keep the added-node handling consistent, it also:
addnode addreject a host that was already added with or without the default port;addnode removeandgetaddednodeinfo <node>accept any equivalent value, so they no longer report a value as not added afteraddnode addrejected it as already added;AddedNodesContain(), which keeps automatic outbound connections away from addnode peers, match numeric aliases. On master, an added node written as[2001:db8::1]or as an expanded IPv6 address is never matched, and deduplicating startup values could otherwise keep such a spelling instead of one that matches.A release note is included.
This change is complementary to, and independent of, #35600.
#35600 prevents overlapping manual connection attempts by tracking destinations while a connection attempt is in progress.
This PR instead removes repeated
-addnodevalues before the connection threads start, preventing duplicate stored entries and sequential redundant retries.It does not replace or broaden #35600's in-flight connection handling.
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.
Concept ACK
Comparing this patch to the validation performed in
CConnman::AddNode()(the RPC path), which resolves the target — full resolution is out of scope as clearly explained in the description and commit body. What about also checking the port (perhaps usingSplitHostPort), so e.g.node.exampleandnode.example:8333(mainnetdefault port) would be treated as the same target, and the second one excluded as a duplicate?Concept ACK on ignoring repeated values.
When looking at how addnode handles repeated values, I noticed that it uses
CConnMan::AddNode, which invokesLookupNumericto parse IP addresses and remove equivalent representations (it doesn't do any DNS resolution). For consistency, it may make sense for-addnodevalues to use the same check.One way would be to call
AddNodeinside ofCConnman::Init, but I'm not sure if it's okay to callLogWarningfrom there:Otherwise, you can duplicate the logic in
init.cpp.To be clear, I'm okay even with the code as-is, if it gets too complicated to add the
LookupNumericchecks.@pablomartin4btc @danielabrozzoni
Thanks for the suggestions. Great catches.
I split the change into two commits and credited each of you as a co-author on the respective commit.
ACK
4ebff1af2aThanks for taking my suggestion!
Left a couple of inline nits I noticed on a re-read — nothing blocking.
One more equivalence worth considering, in the same spirit as the host/port work here: hostname comparison is case-sensitive (
host == existing_host), so-addnode=Example.comand-addnode=example.comwouldn't be caught as duplicates, since DNS hostnames are case-insensitive. This isn't new — the original exact-string check had the same gap — and it's arguably out of scope for this PR. But since the whole point here is catching duplicate representations of the same target rather than just literal string matches, case-folding the hostname comparison feels like a natural extension of the same fix rather than a separate concern, so wanted to flag it while this code is already being touched. No test currently covers it either way, consistent with it not being handled. Happy to leave it out if you'd rather keep this PR narrowly scoped to the port-equivalence case.minor nit: this logs only the rejected value, not what it matched against. For a user staring at their config wondering why an entry got dropped, "Ignoring duplicate -addnode value: node.example:8333 (matches node.example)" would be more actionable — especially since the whole point of this PR is catching non-obvious duplicates (different port representations), where "this is a duplicate" alone doesn't explain why. Not blocking, just a nice-to-have.
tested ACK
4ebff1af2aBuilt and tested both commits separately. Also checked on regtest that
-addnode=first.node -addnode=first.node:18444keeps a single entry ingetaddednodeinfo.The only thing I found is the case-sensitive hostname comparison @pablomartin4btc already flagged, which seems fine as a follow-up.
🟠 Minor · Numeric equivalence merges link-local addnodes on different interfaces
When configured link-local peers differ only by IPv6 scope, startup now discards the second destination, and removal or lookup using that scope can affect the first entry.
Location:
src/net.cpp:3915(head).🔵 Suggestion · DNS case variants remain separate added nodes
DNS hostname case variants with the same effective port remain separate entries and can still cause redundant lookups and connection attempts while disconnected.
Location:
src/net.cpp:3920(head).Review coverage was incomplete.
Reviewed:
cc3246f6d83e· Full review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
Reviewed
55003ac5fbI want to mention this explicitly, but I don't think it's really problematic, and I'm fine if it doesn't get fixed - we are changing how add checks for duplicates, but remove still compares exact strings. It means that one could do:
This is a bit confusing for the user - has
abc.com:8333been added or not?This is also present in master, it's not unique to this PR, since in master
addalready rejects numeric equivalents.The fix would be to also check for equivalence in
RemoveAddedNode.nit: I found this function a bit hard to go through (although I'm very new to the net code :)), I think one comment explaining the three checks we're applying would be very helpful:
nit: I was a bit confused because
porthere is used as two different things: it's the default port that goes intoLookupNumeric, and then it gets overwritten bySplitHostPortwith the effective port. It might be clearer to use separate variables, although it might be a bit too verbose, feel free to ignore:You should include a "\n" at the end of this sentence, otherwise the line in the logs for
Ignoring duplicate -addnode value: first.node:18444will also match this one (assert_debug_logchecks the presence of a substring). Currently, if you remove the duplicate-addnode=first.nodeline, the test still passes.Thanks, good idea. Done in
b8e01b0354. Added you as a co-author on that commit.Thanks! I tried this, but it has edge cases, because not every host is a DNS name. IPv6 zone IDs are case-sensitive interface names, so
[fe80::1%ETH0]would be treated as a duplicate of[fe80::1%eth0], and the valid spelling could be dropped.I'd rather keep this PR focused and leave case-insensitive matching for a follow-up as suggested.
Thanks, added! The checks now live in a
FindAddedNodehelper (shared byaddnode add/remove,getaddednodeinfoand the startup-addnodehandling) so I put your comment on its declaration, with the wording adapted slightly to fit the helper. See59d428d730.Done, thanks! I split them into
default_port/portandexisting_default_port/existing_portas you suggested, inf2fcaeb72. I also added you as a co-author there.Good catch, thanks! Fixed in
b8e01b0354: the expected messages now end with\n, so each one has to match a whole log line.@danielabrozzoni Thanks for the thorough review. I fixed this in
59d428d730: add and remove now share the same lookup, soaddnode abc.com:8333remove removesabc.com. For consistency,getaddednodeinfo <node>uses the same lookup too (6d5a7119ee). I added you as co-author on the fix.re-ACK
cc3246f6d8Left a non-blocking nit on the release note.
Thanks for taking my suggestion.
Agree with leaving case-insensitive matching for a follow-up, and good point on IPv6 zone IDs. I think it could be scoped to names only, e.g. by only applying
CaseInsensitiveEqualin the host/port check when the host contains no ':' (IPv6 literals always do afterSplitHostPortstrips the brackets, and onion/ i2p are already handled byLookupNumericsince base32 decoding is case-insensitive). Happy to review or open that follow-up.Changes since my last ACK:
addnode removeandgetaddednodeinfo <node>(extended by w0xlt for consistency) now use the same equivalence asaddvia the sharedFindAddedNodehelper, plus the explanatory comment, thedefault_port/portsplit, and the\nfix in the functional test.AddedNodesContainnow matches numeric aliases (486e97266a), so expanded/ bracketed IPv6 spellings no longer let automatic outbound use a slot on an added peer.added_nodes_contain_numeric_aliases,remove_added_node_equivalence,get_added_node_info_equivalence)/ functional tests (rpc_net.pychecks foraddnode removeandgetaddednodeinfowith an equivalent address) and release note.nit:
AddedNodesContainmatching numeric aliases (486e97266a) also changes behaviour (automatic outbound now skips an added peer written as e.g.[2001:db8::1]or an expanded IPv6 address), maybe worth a line under "P2P and network changes"? Something like: