net: advertise -externalip addresses #34538

pull willcl-ark wants to merge 2 commits into bitcoin:master from willcl-ark:onlynet-advertisments changing 2 files +28 −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

  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. 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.
    383763f9ee
  4. DrahtBot added the label P2P on Feb 9, 2026
  5. 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. A summary of reviews will appear here.

  6. 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 :)


willcl-ark DrahtBot

Labels
P2P


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-02-17 06:13 UTC

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