net: ignore repeated -addnode startup values #36014

Open
w0xlt wants to merge 6 commits from net-deduplicate-startup-addnodes into master AGit
w0xlt commented 2026-08-18 20:28:51 +00:00 (Migrated from github.com)

Startup -addnode values are copied directly into the connection manager's added-node list. Unlike runtime addnode add calls, this path does not reject repeated values.

For example:

-addnode=example.com
-addnode=example.com
-addnode=example.com:8333

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. getaddednodeinfo also reports the repeated entries.

This PR checks each startup value with the same lookup that addnode add uses, 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.com and example.com:8333 on mainnet). No DNS lookups are done.

To keep the added-node handling consistent, it also:

  • makes addnode add reject a host that was already added with or without the default port;
  • makes addnode remove and getaddednodeinfo <node> accept any equivalent value, so they no longer report a value as not added after addnode add rejected it as already added;
  • makes 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 -addnode values 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.

Startup `-addnode` values are copied directly into the connection manager's added-node list. Unlike runtime `addnode add` calls, this path does not reject repeated values. For example: ``` -addnode=example.com -addnode=example.com -addnode=example.com:8333 ``` 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. `getaddednodeinfo` also reports the repeated entries. This PR checks each startup value with the same lookup that `addnode add` uses, 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.com` and `example.com:8333` on mainnet). No DNS lookups are done. To keep the added-node handling consistent, it also: - makes `addnode add` reject a host that was already added with or without the default port; - makes `addnode remove` and `getaddednodeinfo <node>` accept any equivalent value, so they no longer report a value as not added after `addnode add` rejected it as already added; - makes `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 `-addnode` values 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.
DrahtBot commented 2026-08-18 20:28:59 +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 pablomartin4btc
Concept ACK danielabrozzoni, RandyMcMillan
Stale ACK AndreaDiazCorreia

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:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)

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/36014 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36014.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36014#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 | [pablomartin4btc](https://github.com/bitcoin/bitcoin/pull/36014#pullrequestreview-6106192229) | | Concept ACK | [danielabrozzoni](https://github.com/bitcoin/bitcoin/pull/36014#pullrequestreview-5041831301), [RandyMcMillan](https://github.com/bitcoin/bitcoin/pull/36014#issuecomment-6071551925) | | Stale ACK | [AndreaDiazCorreia](https://github.com/bitcoin/bitcoin/pull/36014#issuecomment-5746181295) | 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: * [#36990](https://github.com/bitcoin/bitcoin/pull/36990) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36990.svg"></sub> (test: replace hard-coded RPC error codes by l0rinc) 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-->
pablomartin4btc (Migrated from github.com) reviewed 2026-08-19 18:30:37 +00:00
pablomartin4btc (Migrated from github.com) left a comment

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 using SplitHostPort), so e.g. node.example and node.example:8333 (mainnet default port) would be treated as the same target, and the second one excluded as a duplicate?

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 using `SplitHostPort`), so e.g. `node.example` and `node.example:8333` (`mainnet` default port) would be treated as the same target, and the second one excluded as a duplicate?
danielabrozzoni (Migrated from github.com) reviewed 2026-08-27 14:15:29 +00:00
danielabrozzoni (Migrated from github.com) left a comment

Concept ACK on ignoring repeated values.

When looking at how addnode handles repeated values, I noticed that it uses CConnMan::AddNode, which invokes LookupNumeric to parse IP addresses and remove equivalent representations (it doesn't do any DNS resolution). For consistency, it may make sense for -addnode values to use the same check.

One way would be to call AddNode inside of CConnman::Init, but I'm not sure if it's okay to call LogWarning from there:

diff --git a/src/net.h b/src/net.h
index ea0c651d11..d69b9a4df3 100644
--- a/src/net.h
+++ b/src/net.h
@@ -1140,12 +1140,13 @@ public:
         vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming;
         vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
         {
-            LOCK(m_added_nodes_mutex);
             // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
             // peer doesn't support it or immediately disconnects us for another reason.
             const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
             for (const std::string& added_node : connOptions.m_added_nodes) {
-                m_added_node_params.push_back({added_node, use_v2transport});
+                if (!AddNode({added_node, use_v2transport})) {
+                    LogWarning("Ignoring duplicate -addnode value: %s", added_node);
+                }
             }
         }

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 LookupNumeric checks.

Concept ACK on ignoring repeated values. When looking at how addnode handles repeated values, I noticed that it uses `CConnMan::AddNode`, which invokes `LookupNumeric` to parse IP addresses and remove equivalent representations (it doesn't do any DNS resolution). For consistency, it may make sense for `-addnode` values to use the same check. One way would be to call `AddNode` inside of `CConnman::Init`, but I'm not sure if it's okay to call `LogWarning` from there: ```diff diff --git a/src/net.h b/src/net.h index ea0c651d11..d69b9a4df3 100644 --- a/src/net.h +++ b/src/net.h @@ -1140,12 +1140,13 @@ public: vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming; vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing; { - LOCK(m_added_nodes_mutex); // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our // peer doesn't support it or immediately disconnects us for another reason. const bool use_v2transport(GetLocalServices() & NODE_P2P_V2); for (const std::string& added_node : connOptions.m_added_nodes) { - m_added_node_params.push_back({added_node, use_v2transport}); + if (!AddNode({added_node, use_v2transport})) { + LogWarning("Ignoring duplicate -addnode value: %s", added_node); + } } } ``` 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 `LookupNumeric` checks.
w0xlt commented 2026-09-01 23:34:28 +00:00 (Migrated from github.com)

@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.

@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.
pablomartin4btc (Migrated from github.com) reviewed 2026-09-11 01:39:24 +00:00
pablomartin4btc (Migrated from github.com) left a comment

ACK 4ebff1af2a

Thanks for taking my suggestion!

Left a couple of inline nits I noticed on a re-read — nothing blocking.

ACK 4ebff1af2acc6e846eb7932ff8ece03ffa3a9066 Thanks for taking my suggestion! Left a couple of inline nits I noticed on a re-read — nothing blocking.
pablomartin4btc (Migrated from github.com) commented 2026-09-11 01:37:58 +00:00

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.com and -addnode=example.com wouldn'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.

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.com` and `-addnode=example.com` wouldn'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.
pablomartin4btc (Migrated from github.com) commented 2026-09-11 01:30:48 +00:00

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.

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.
AndreaDiazCorreia commented 2026-09-19 23:43:03 +00:00 (Migrated from github.com)

tested ACK 4ebff1af2a

Built and tested both commits separately. Also checked on regtest that -addnode=first.node -addnode=first.node:18444 keeps a single entry in getaddednodeinfo.

The only thing I found is the case-sensitive hostname comparison @pablomartin4btc already flagged, which seems fine as a follow-up.

tested ACK 4ebff1af2acc6e846eb7932ff8ece03ffa3a9066 Built and tested both commits separately. Also checked on regtest that `-addnode=first.node -addnode=first.node:18444` keeps a single entry in `getaddednodeinfo`. The only thing I found is the case-sensitive hostname comparison @pablomartin4btc already flagged, which seems fine as a follow-up.
First-time contributor

🟠 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 reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:0e38ad26af922abdc0fc36c9379e17efd2a72b80 --> <!-- ralph-head:cc3246f6d83e8d027f294cdccfae7da8e53fae5f --> <!-- ralph-case:4e6dbe15be6e9515409cf413aaf15c19aacc67fade4e1b8eb2df6d36d113d9fc --> **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/cc3246f6d83e8d027f294cdccfae7da8e53fae5f/src/net.cpp#L3915>) (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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/cc3246f6d83e8d027f294cdccfae7da8e53fae5f/src/net.cpp#L3920>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`cc3246f6d83e`](<https://git.fish.foo/bitcoin/bitcoin/commit/cc3246f6d83e8d027f294cdccfae7da8e53fae5f>) · [Full review report](<https://review.fish.foo/traces/36014-cc3246f6d83e8d027f294cdccfae7da8e53fae5f-2178-3.html>) · [Previous reports](<https://review.fish.foo/traces/36014/>) [permalink](<https://review.fish.foo/traces/36014-cc3246f6d83e8d027f294cdccfae7da8e53fae5f-2178-3.html>)
DrahtBot commented 2026-10-07 12:29:50 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
RandyMcMillan commented 2026-10-09 00:10:36 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
danielabrozzoni (Migrated from github.com) reviewed 2026-11-03 16:21:07 +00:00
danielabrozzoni (Migrated from github.com) left a comment

Reviewed 55003ac5fb

I 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:

addnode abc.com add         # ok!
addnode abc.com:8333 add    # Error: Node already added
addnode abc.com:8333 remove # Error: Node could not be removed. It has not been added previously.

This is a bit confusing for the user - has abc.com:8333 been added or not?

This is also present in master, it's not unique to this PR, since in master add already rejects numeric equivalents.

The fix would be to also check for equivalence in RemoveAddedNode.

Reviewed 55003ac5fbbe4ef458f790cef4280092f203e471 I 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: ``` addnode abc.com add # ok! addnode abc.com:8333 add # Error: Node already added addnode abc.com:8333 remove # Error: Node could not be removed. It has not been added previously. ``` This is a bit confusing for the user - has `abc.com:8333` been added or not? This is also present in master, it's not unique to this PR, since in master `add` already rejects numeric equivalents. The fix would be to also check for equivalence in `RemoveAddedNode`.
danielabrozzoni (Migrated from github.com) commented 2026-11-02 14:00:29 +00:00

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:

// We want to avoid storing the same peer twice, so we check for duplicates in
// three different ways:
// 1. Exact string match.
// 2. Same address, compared as a CService. We use LookupNumeric to parse
//    addresses and fill in the default port if needed, so different spellings
//    of one address match (e.g. "[::1]" and "[0:0:0:0:0:0:0:1]"). This doesn't
//    apply to names, for which resolved_is_valid is false.
// 3. Same host text and effective port, using SplitHostPort. This one works
//    for names, so "node.example" and "node.example:8333" are one peer.
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: ``` // We want to avoid storing the same peer twice, so we check for duplicates in // three different ways: // 1. Exact string match. // 2. Same address, compared as a CService. We use LookupNumeric to parse // addresses and fill in the default port if needed, so different spellings // of one address match (e.g. "[::1]" and "[0:0:0:0:0:0:0:1]"). This doesn't // apply to names, for which resolved_is_valid is false. // 3. Same host text and effective port, using SplitHostPort. This one works // for names, so "node.example" and "node.example:8333" are one peer. ```
danielabrozzoni (Migrated from github.com) commented 2026-11-02 14:11:41 +00:00

nit: I was a bit confused because port here is used as two different things: it's the default port that goes into LookupNumeric, and then it gets overwritten by SplitHostPort with the effective port. It might be clearer to use separate variables, although it might be a bit too verbose, feel free to ignore:

diff --git a/src/net.cpp b/src/net.cpp
index 1b6f6263fe..1f9923b873 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -3871,20 +3871,22 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
 
 bool CConnman::AddNode(const AddedNodeParams& add)
 {
-    uint16_t port{GetDefaultPort(add.m_added_node)};
-    const CService resolved(LookupNumeric(add.m_added_node, port));
+    const uint16_t default_port{GetDefaultPort(add.m_added_node)};
+    const CService resolved(LookupNumeric(add.m_added_node, default_port));
     const bool resolved_is_valid{resolved.IsValid()};
     std::string host;
+    uint16_t port{default_port};
     const bool host_port_is_valid{SplitHostPort(add.m_added_node, port, host)};
 
     LOCK(m_added_nodes_mutex);
     for (const auto& it : m_added_node_params) {
         if (add.m_added_node == it.m_added_node) return false;
 
-        uint16_t existing_port{GetDefaultPort(it.m_added_node)};
-        if (resolved_is_valid && resolved == LookupNumeric(it.m_added_node, existing_port)) return false;
+        const uint16_t existing_default_port{GetDefaultPort(it.m_added_node)};
+        if (resolved_is_valid && resolved == LookupNumeric(it.m_added_node, existing_default_port)) return false;
 
         std::string existing_host;
+        uint16_t existing_port{existing_default_port};
         if (host_port_is_valid && SplitHostPort(it.m_added_node, existing_port, existing_host) &&
             host == existing_host && port == existing_port) {
             return false;
nit: I was a bit confused because `port` here is used as two different things: it's the default port that goes into `LookupNumeric`, and then it gets overwritten by `SplitHostPort` with the effective port. It might be clearer to use separate variables, although it might be a bit too verbose, feel free to ignore: ```diff diff --git a/src/net.cpp b/src/net.cpp index 1b6f6263fe..1f9923b873 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3871,20 +3871,22 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres bool CConnman::AddNode(const AddedNodeParams& add) { - uint16_t port{GetDefaultPort(add.m_added_node)}; - const CService resolved(LookupNumeric(add.m_added_node, port)); + const uint16_t default_port{GetDefaultPort(add.m_added_node)}; + const CService resolved(LookupNumeric(add.m_added_node, default_port)); const bool resolved_is_valid{resolved.IsValid()}; std::string host; + uint16_t port{default_port}; const bool host_port_is_valid{SplitHostPort(add.m_added_node, port, host)}; LOCK(m_added_nodes_mutex); for (const auto& it : m_added_node_params) { if (add.m_added_node == it.m_added_node) return false; - uint16_t existing_port{GetDefaultPort(it.m_added_node)}; - if (resolved_is_valid && resolved == LookupNumeric(it.m_added_node, existing_port)) return false; + const uint16_t existing_default_port{GetDefaultPort(it.m_added_node)}; + if (resolved_is_valid && resolved == LookupNumeric(it.m_added_node, existing_default_port)) return false; std::string existing_host; + uint16_t existing_port{existing_default_port}; if (host_port_is_valid && SplitHostPort(it.m_added_node, existing_port, existing_host) && host == existing_host && port == existing_port) { return false; ```
danielabrozzoni (Migrated from github.com) commented 2026-11-02 15:11:35 +00:00

You should include a "\n" at the end of this sentence, otherwise the line in the logs for Ignoring duplicate -addnode value: first.node:18444 will also match this one (assert_debug_log checks the presence of a substring). Currently, if you remove the duplicate -addnode=first.node line, the test still passes.

You should include a "\n" at the end of this sentence, otherwise the line in the logs for `Ignoring duplicate -addnode value: first.node:18444` will also match this one (`assert_debug_log` checks the presence of a substring). Currently, if you remove the duplicate `-addnode=first.node` line, the test still passes.
w0xlt (Migrated from github.com) reviewed 2026-11-04 23:17:30 +00:00
w0xlt (Migrated from github.com) commented 2026-11-04 23:17:30 +00:00

Thanks, good idea. Done in b8e01b0354. Added you as a co-author on that commit.

Thanks, good idea. Done in b8e01b0354. Added you as a co-author on that commit.
w0xlt (Migrated from github.com) reviewed 2026-11-04 23:20:28 +00:00
w0xlt (Migrated from github.com) commented 2026-11-04 23:20:28 +00:00

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! 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.
w0xlt (Migrated from github.com) reviewed 2026-11-04 23:25:00 +00:00
w0xlt (Migrated from github.com) commented 2026-11-04 23:25:00 +00:00

Thanks, added! The checks now live in a FindAddedNode helper (shared by addnode add/remove, getaddednodeinfo and the startup -addnode handling) so I put your comment on its declaration, with the wording adapted slightly to fit the helper. See 59d428d730.

Thanks, added! The checks now live in a `FindAddedNode` helper (shared by `addnode add/remove`, `getaddednodeinfo` and the startup `-addnode` handling) so I put your comment on its declaration, with the wording adapted slightly to fit the helper. See 59d428d730.
w0xlt (Migrated from github.com) reviewed 2026-11-04 23:26:42 +00:00
w0xlt (Migrated from github.com) commented 2026-11-04 23:26:42 +00:00

Done, thanks! I split them into default_port/port and existing_default_port/existing_port as you suggested, in f2fcaeb72. I also added you as a co-author there.

Done, thanks! I split them into `default_port`/`port` and `existing_default_port`/`existing_port` as you suggested, in f2fcaeb72. I also added you as a co-author there.
w0xlt (Migrated from github.com) reviewed 2026-11-04 23:27:34 +00:00
w0xlt (Migrated from github.com) commented 2026-11-04 23:27:34 +00:00

Good catch, thanks! Fixed in b8e01b0354: the expected messages now end with \n, so each one has to match a whole log line.

Good catch, thanks! Fixed in b8e01b0354: the expected messages now end with `\n`, so each one has to match a whole log line.
w0xlt commented 2026-11-04 23:30:00 +00:00 (Migrated from github.com)

This is a bit confusing for the user - has abc.com:8333 been added or not?
This is also present in master, it's not unique to this PR, since in master add already rejects numeric equivalents.

@danielabrozzoni Thanks for the thorough review. I fixed this in 59d428d730: add and remove now share the same lookup, so addnode abc.com:8333 remove removes abc.com. For consistency, getaddednodeinfo <node> uses the same lookup too (6d5a7119ee). I added you as co-author on the fix.

> This is a bit confusing for the user - has abc.com:8333 been added or not? This is also present in master, it's not unique to this PR, since in master add already rejects numeric equivalents. @danielabrozzoni Thanks for the thorough review. I fixed this in 59d428d730: add and remove now share the same lookup, so `addnode abc.com:8333` remove removes `abc.com`. For consistency, `getaddednodeinfo <node>` uses the same lookup too (6d5a7119ee). I added you as co-author on the fix.
pablomartin4btc (Migrated from github.com) reviewed 2026-11-30 02:25:33 +00:00
pablomartin4btc (Migrated from github.com) left a comment

re-ACK cc3246f6d8

Left 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 CaseInsensitiveEqual in the host/port check when the host contains no ':' (IPv6 literals always do after SplitHostPort strips the brackets, and onion/ i2p are already handled by LookupNumeric since base32 decoding is case-insensitive). Happy to review or open that follow-up.

Changes since my last ACK:

  • @danielabrozzoni's feedback addressed: addnode remove and getaddednodeinfo <node> (extended by w0xlt for consistency) now use the same equivalence as add via the shared FindAddedNode helper, plus the explanatory comment, the default_port/port split, and the \n fix in the functional test.
  • AddedNodesContain now matches numeric aliases (486e97266a), so expanded/ bracketed IPv6 spellings no longer let automatic outbound use a slot on an added peer.
  • New unit (added_nodes_contain_numeric_aliases, remove_added_node_equivalence, get_added_node_info_equivalence)/ functional tests (rpc_net.py checks for addnode remove and getaddednodeinfo with an equivalent address) and release note.
re-ACK cc3246f6d83e8d027f294cdccfae7da8e53fae5f Left a non-blocking nit on the release note. Thanks for taking my [suggestion](https://github.com/bitcoin/bitcoin/pull/36014#discussion_r4474566267). Agree with leaving [case-insensitive matching](https://github.com/bitcoin/bitcoin/pull/36014#discussion_r4474589807) 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 `CaseInsensitiveEqual` in the host/port check when the host contains no ':' (IPv6 literals always do after `SplitHostPort` strips the brackets, and onion/ i2p are already handled by `LookupNumeric` since base32 decoding is case-insensitive). Happy to review or open that follow-up. Changes since my last ACK: - @danielabrozzoni's feedback addressed: `addnode remove` and `getaddednodeinfo <node>` (extended by w0xlt for consistency) now use the same equivalence as `add` via the shared `FindAddedNode` helper, plus the explanatory comment, the `default_port`/`port` split, and the `\n` fix in the functional test. - `AddedNodesContain` now matches numeric aliases (486e97266af9dac33cf72082f8e7c35504bb5fdb), so expanded/ bracketed IPv6 spellings no longer let automatic outbound use a slot on an added peer. - New unit (`added_nodes_contain_numeric_aliases`, `remove_added_node_equivalence`, `get_added_node_info_equivalence`)/ functional tests (`rpc_net.py` checks for `addnode remove` and `getaddednodeinfo` with an equivalent address) and release note.
pablomartin4btc (Migrated from github.com) commented 2026-11-30 02:24:13 +00:00

nit: AddedNodesContain matching 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:

P2P and network changes
-----------------------

- Automatic outbound connections now skip a peer that was added with
  `-addnode` or `addnode add` using a different spelling of its numeric
  address, such as an expanded IPv6 address or a bracketed IPv6 address
  without a port. Previously, only the canonical spelling was recognised.
  (#36014)
nit: `AddedNodesContain` matching 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: ``` P2P and network changes ----------------------- - Automatic outbound connections now skip a peer that was added with `-addnode` or `addnode add` using a different spelling of its numeric address, such as an expanded IPv6 address or a bracketed IPv6 address without a port. Previously, only the canonical spelling was recognised. (#36014) ```
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!36014
No description provided.