Summary:
This PR fixes two related issues with address discovery when using explicit bind addresses in Bitcoin Core:
- #31293: Discover() will not run if listening on any address with an explicit bind=0.0.0.0
- #31336: Functional tests: feature_bind_port_discover.py is failing
Problem
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.py
would fail, as it expects local addresses to be discovered in these cases.
The Fix
This PR:
- Checks both
bind_on_any
and 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 ofbind_on_any
is 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 testfeature_bind_port_discover.py
is 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()
.