net: Fix Discover() not running when using -bind=0.0.0.0:port #32757

pull b-l-u-e wants to merge 2 commits into bitcoin:master from b-l-u-e:net-fix-discover-bind-any changing 2 files +20 −8
  1. b-l-u-e commented at 4:28 am on June 16, 2025: none

    When using -bind=0.0.0.0:port, the Discover() function was not being executed because the condition only checked bind_on_any. This fix modifies the condition to also check for any bind addresses that use 0.0.0.0 or ::.

    The fix:

    1. Checks both bind_on_any and any bind addresses using IsBindAny()
    2. Ensures Discover() runs when binding to 0.0.0.0
    3. Maintains backward compatibility
    4. Updates test to use dynamic ports instead of hardcoded port

    This PR differs from #31492 by:

    • Preserving the semantic meaning of bind_on_any as defined in net.h: “True if the user did not specify -bind= or -whitebind= and thus we should bind on 0.0.0.0 (IPv4) and :: (IPv6)”
    • Using a simpler approach that checks IsBindAny() on bind addresses without modifying GetListenPort()
    • Avoiding code duplication with DefaultOnionServiceTarget()

    The implementation follows the approach I proposed in my review comment#31492:

    Closes #31293

  2. DrahtBot commented at 4:28 am on June 16, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32757.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK yuvicc

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label P2P on Jun 16, 2025
  4. in src/init.cpp:506 in 5d5bf98bdb outdated
    502@@ -503,7 +503,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
    503                    ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
    504     argsman.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
    505     argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex. "
    506-            "Warning: Reverting this setting requires re-downloading the entire blockchain. "
    507+                                           "Warning: Reverting this setting requires re-downloading the entire blockchain. "
    


    maflcko commented at 6:34 am on June 16, 2025:
    all the whitespace changes look unrelated. Please remove them again. Otherwise, it is unclear what you are really changing in this commit.
  5. b-l-u-e force-pushed on Jun 16, 2025
  6. b-l-u-e requested review from maflcko on Jun 16, 2025
  7. yuvicc commented at 3:40 pm on June 16, 2025: contributor

    Concept ACK

    Removing duplicate code from DefaultOnionServiceTarget() is better IMO

  8. net: Fix Discover() not running when using -bind=0.0.0.0:port
    When using -bind=0.0.0.0:port, the Discover() function was not being executed because the condition only checked bind_on_any. This fix modifies the condition to also check for any bind addresses that use 0.0.0.0 or ::.
    
    The fix: 1. Checks both bind_on_any and any bind addresses using IsBindAny() 2. Ensures Discover() runs when binding to 0.0.0.0 3. Maintains backward compatibility
    
    Closes #31293
    705fe35719
  9. test: Update feature_bind_port_discover.py to use dynamic ports
    Updates the test to use dynamic ports from the test framework instead of hardcoded ports. This makes the test more robust and prevents port conflicts.
    
    The test verifies that Discover() runs correctly when binding to 0.0.0.0
    776b7ee585
  10. b-l-u-e force-pushed on Jun 16, 2025

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: 2025-06-18 09:13 UTC

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