net: advertise -externalip addresses #34538

pull willcl-ark wants to merge 3 commits into bitcoin:master from willcl-ark:onlynet-advertisments changing 3 files +44 −1
  1. willcl-ark commented at 12:16 pm on February 9, 2026: member

    …regardless of -onlynet.

    -onlynet is documented to only affect automatic outbound connections (this naming is not ideal!), but it also currently prevents -externalip addresses from being advertised when their network isn’t in the -onlynet set, which will affect inbound behaviour/performance. This is because of the g_reachable_nets.Contains() check in AddLocal(), which rejects all addresses outside the reachable set, regardless of how they were specified.

    Previous attempts to fix this (#24835 and #25690) both tried removal of the g_reachable_nets check from AddLocal(). A concern raised was that IsPeerAddrLocalGood() would also need adjusting for consistency. I am not sure this applies though, because -externalip sets fDiscover=false, so IsPeerAddrLocalGood() is short-circuited before its g_reachable_nets check is reached. In the -listenonion path (where fDiscover may be true), g_reachable_nets.Contains() still returns false for the excluded network, but this is correct — IsPeerAddrLocalGood() is checking whether to replace our “known” address with a peer’s claim, and there doesn’t seem any reason to override an address that tor control already knows?

    In the approach in this changeset, instead of removing the check entirely, skip it only when nScore >= LOCAL_MANUAL. This limits the bypass to addresses explicitly provided by the user (-externalip, -torcontrol).

    This also means that we would not advertise non-onlynet discovered addresses, only those which are manually specified, which I believe addresses #25690 (comment):

    I think it might also be weird for a user to activate -onlynet and keep on advertising their clearnet address to the network

    Fixes: #25336 Fixes: #25669

  2. net: allow `AddLocal()` to bypass reachable nets
    ...for manual addresses.
    
    When -onlynet restricts reachable networks, `AddLocal()` rejects all
    addresses outside those networks, including ones explicitly provided via
    `-externalip`. This means a user who sets `-onlynet=ipv4` along with
    `-externalip=<onion_address>` will never advertise the onion address.
    
    Fix by skipping the `g_reachable_nets` check when `nScore >=
    LOCAL_MANUAL`, consistent with the existing `fDiscover` bypass on the
    preceding line.
    57b3f870ae
  3. DrahtBot added the label P2P on Feb 9, 2026
  4. DrahtBot commented at 12:17 pm on February 9, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK vasild
    Concept ACK chriszeng1010
    Stale ACK seduless

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  5. willcl-ark commented at 12:18 pm on February 9, 2026: member

    cc @mzumsande @vasild

    I’ve taken a very slightly different approach at fixing this, and would value your opinion(s) on :)

  6. chriszeng1010 commented at 6:48 pm on March 2, 2026: none

    Tested ACK

    Built and rantest_bitcoin --run_test=net_testson Windows/MSYS2. New addlocal_onlynet_externalip test passes.

  7. in src/test/net_tests.cpp:1569 in 383763f9ee
    1564+    CAddress addr_onion;
    1565+    BOOST_REQUIRE(addr_onion.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
    1566+    BOOST_REQUIRE(addr_onion.IsValid());
    1567+    BOOST_REQUIRE(addr_onion.IsTor());
    1568+
    1569+    // Simulate using -onlynet=ipv4
    


    seduless commented at 3:57 am on March 3, 2026:
    nit: This simulates -onlynet=ipv4 but doesn’t replicate -externalip’s side effect of setting fDiscover=false. With fDiscover left as true (the test default), only the g_reachable_nets gate is exercised. Adding fDiscover = false; here would catch a regression on the fDiscover gate too.

    willcl-ark commented at 10:03 am on March 3, 2026:
    Thanks for the review. I agree, and have taken this suggestion in 6e73dcf700796146b33f3788b2ff7f659244f909
  8. seduless commented at 4:03 am on March 3, 2026: contributor

    Tested ACK 383763f9ee3ca307c2b881f0fcf4de660073aa84

    Reproduced #25336 on regtest: started a node with -onlynet=ipv4 -externalip=<onion_address>, confirmed getnetworkinfo shows empty localaddresses on master. With the fix applied, the onion address appears at score 4.

    Traced all LOCAL_MANUAL callers and found no inconsistency with IsPeerAddrLocalGood.

  9. DrahtBot requested review from chriszeng1010 on Mar 3, 2026
  10. willcl-ark force-pushed on Mar 3, 2026
  11. seduless commented at 11:24 pm on March 3, 2026: contributor
    re-ACK 6e73dcf700796146b33f3788b2ff7f659244f909
  12. in src/test/net_tests.cpp:1584 in 6e73dcf700
    1579+    BOOST_CHECK(AddLocal(addr_onion, LOCAL_MANUAL));
    1580+    BOOST_CHECK(IsLocal(addr_onion));
    1581+
    1582+    RemoveLocal(addr_onion);
    1583+    g_reachable_nets.Add(NET_ONION);
    1584+    fDiscover = true;
    


    vasild commented at 11:09 am on March 5, 2026:

    I guess this is an attempt to restore the global state to what it was at the beginning of the test. Here are more robust ways to that:

    For g_reachable_nets:

    0... test ...
    1// Assumes that g_reachable_nets was in its default-constructed state at the start of the test.
    2g_reachable_nets.Reset();
    

    or (no assumptions)

    0const auto reachable_nets_at_start{g_reachable_nets.All()};
    1... test ...
    2g_reachable_nets.RemoveAll();
    3for (const auto& net : reachable_nets_at_start) {
    4    g_reachable_nets.Add(net);
    5}
    

    For fDiscover:

    0const bool discover_orig{fDiscover};
    1... test ...
    2fDiscover = discover_orig;
    

    willcl-ark commented at 12:18 pm on March 5, 2026:
    Good point, thanks, I agree. I changed the test to restore both global states as you suggested, in e459f651c89
  13. vasild approved
  14. vasild commented at 11:27 am on March 5, 2026: contributor

    ACK 6e73dcf700796146b33f3788b2ff7f659244f909

    Note that AddLocal(..., LOCAL_MANUAL) is called from 3 places:

    1. For addresses given to -externalip=..., the focus of this PR.
    2. For our listening Tor address that is automatically created with the Tor router when -listenonion=1. So this setup will be affected by this PR: -onlynet=ipv4 -listenonion=1. Before this PR we would not advertise the Tor address and now we will.
    3. For our listening I2P address that is created with the I2P SAM proxy when -i2psam=... -i2pacceptincoming=1 is used. Similarly to Tor this would affect -onlynet=ipv4 -i2psam=... -i2pacceptincoming=1.

    I think those 2. and 3. are welcomed changes. Maybe deserve a release note.

    Will resolve https://github.com/bitcoin/bitcoin/issues/25669

  15. test: `-externalip` addresses bypass `-onlynet` restriction
    Add a unit test for `AddLocal()` confirming that `LOCAL_MANUAL` score
    (used by `-externalip`) bypasses the `g_reachable_nets` filter, while
    lower scores are still rejected.
    e459f651c8
  16. doc: release note for 34538 3c63971454
  17. willcl-ark force-pushed on Mar 5, 2026
  18. willcl-ark commented at 12:19 pm on March 5, 2026: member

    I think those 2. and 3. are welcomed changes. Maybe deserve a release note.

    😃 Release note added in 3c63971454722a9ab399d49b1195fdd640867e31

  19. vasild approved
  20. vasild commented at 12:33 pm on March 5, 2026: contributor
    ACK 3c63971454722a9ab399d49b1195fdd640867e31
  21. DrahtBot requested review from seduless on Mar 5, 2026
  22. vasild commented at 12:36 pm on March 5, 2026: contributor
    Might want to add “Fixes: #25669” to the OP.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-03-09 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me