This PR fixes two related issues with address discovery when using explicit bind addresses in Bitcoin Core:
When using -bind=0.0.0.0:port (or -bind=::), the Discover() function was not being executed because the code only checked the bind_on_any flag. This led to two problems:
- The node would not discover its own local addresses if an explicit “any” bind was used.
- The functional test
feature_bind_port_discover.pywould fail, as it expects local addresses to be discovered in these cases.
This PR:
- Checks both
bind_on_anyand any bind addresses usingIsBindAny()EnsuresDiscover()runs when binding to 0.0.0.0 or ::, even if specified explicitly. - Ensures correct address discovery The node will now discover its own addresses when using explicit “any” binds, matching user expectations and fixing the test.
- Maintains backward compatibility
The semantic meaning of
bind_on_anyis preserved as defined innet.h:“True if the user did not specify -bind= or -whitebind= and thus we should bind on 0.0.0.0 (IPv4) and :: (IPv6)”
- Updates the test to use dynamic ports
The functional test
feature_bind_port_discover.pyis updated to use dynamic ports instead of hardcoded ones, improving reliability.
How this PR Differs from #31492
- Preserves the semantic meaning of
bind_on_any(seenet.h). - Uses a simpler approach: checks
IsBindAny()on bind addresses, without modifyingGetListenPort(). - Avoids code duplication with
DefaultOnionServiceTarget().
References
- Implementation follows the approach proposed in my [review comment on #31492](/bitcoin-bitcoin/31492/#issuecomment-2941773645).
Closes #31293
The #31336 has the overall test failure and requires both this PR and #33362 to be fully resolved.