net: stop sharing P2P listeners with automatic Tor services

bitcoin/bitcoin: PR #36170

1 minor finding · 5 suggestions

Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · Wildcard recovery advice omits the static-service whitelist caveat

The new error offers -listenonion=0 without explaining that a static Tor service forwarding to the wildcard listener can retain pre-existing address-based whitelist inheritance.

Location: src/init.cpp:2311 (head).

Details and suggested fix

With -bind=0.0.0.0:P=onion, following this advice disables automatic service creation but leaves the listener open. Accepted sockets report a concrete local address through getsockname, so they do not match the wildcard entry in m_onion_binds. If a static service in torrc forwards to that port and a whitelist covers the Tor daemon's source, such as -whitelist=noban@127.0.0.1, remote Tor peers receive those permissions. The release note discloses the classification limitation, but the startup remedy does not. Add this caveat to the error or emit an InitWarning when accepting a wildcard onion bind with -listenonion=0; preserving that listener need not imply that it safely identifies Tor peers.


Optional improvements

Link

[suggestion] · Explicit -listenonion=1 gets no startup warning when service creation is skipped

With a normal -bind and no onion bind, even explicitly requested automatic service creation is skipped without a startup/GUI warning; the notice is logged only after successful Tor authentication.

Location: src/torcontrol.cpp:573 (head).

Details and suggested fix

Previously this configuration created a service targeting the first normal bind. Init now leaves onion_service_target empty, but only auth_cb reports the skipped service through LogWarning, which reaches the log and configured console rather than the InitWarning UI path. If Tor control is unreachable, that notice never appears. Emit an InitWarning naming -bind=<addr>:<port>=onion when args.IsArgSet("-listenonion"), listenonion is true, and no target was selected. This makes the upgrade's loss of incoming Tor reachability visible to users who explicitly requested the service, without warning default non-Tor configurations or changing outbound proxy discovery.


Link

[suggestion] · Default ADD_ONION targets lack no-bind and whitebind-only coverage

Existing tests check the default onion listener with -listenonion=0, but do not verify the automatic service's default forwarding target for no-bind or whitebind-only nodes.

Location: src/init.cpp:2304 (head).

Details and suggested fix

feature_torcontrol.py inherits bind=127.0.0.1 in bitcoin.conf; its successful service cases additionally supply explicit onion binds. Consequently, the mock never exercises the changed vBinds.empty() branch that selects the default target. Add mock-controller cases with no configuration bind, suppress TestNode.start's injected binds using has_explicit_bind=True, and enable -listenonion=1. Run once without -bind or -whitebind, and once with only -whitebind=noban@127.0.0.1:X. Assert that the default listener opens and ADD_ONION targets 127.0.0.1 at -port + 1. This pins the automatic-service behavior promised by the release note rather than duplicating the existing listener-only assertions.


Link

[suggestion] · Wildcard onion-bind rejection waits until after chainstate loading

A wildcard onion bind with -listenonion=1 now fails only after InitAndLoadChainstate, although the rejection depends solely on configuration arguments.

Location: src/init.cpp:2310 (head).

Details and suggested fix

The bind parsing and new IsBindAny() check run in Step 12, after block-index and chainstate initialization. An upgraded node using this previously accepted configuration therefore performs that initialization before learning that it must change its arguments. Validate the restriction before chainstate loading, preferably by sharing bind parsing rather than duplicating it. Existing bind-resolution and duplicate-binding errors also occur late, so keeping validation together explains the current placement; the concrete benefit of moving this check is avoiding a wasted chainstate load on each misconfigured restart.


Link

[suggestion] · The [::] rejection test unnecessarily requires local IPv6 connectivity

The guard skips IPv6 wildcard-rejection coverage when ::1 is unavailable, even though the rejection needs only numeric parsing and occurs before P2P binding.

Location: test/functional/feature_bind_extra.py:120 (head).

Details and suggested fix

test_ipv6_local() checks whether an IPv6 socket can reach ::1. In contrast, -bind=[::]:P=onion uses Lookup(..., false), which selects AI_NUMERICHOST rather than AI_ADDRCONFIG. IsBindAny() then examines the decoded address bytes and returns the configuration error before connman->Start. Remove the guard and its import so both wildcard forms are checked regardless of local IPv6 connectivity. This preserves the expected result while retaining the assertion on CI hosts where ::1 is not configured.


Link

[suggestion] · Behavior commits precede their matching -listenonion contract updates

The final tree is consistent, but the behavior commits retain obsolete help and an unconditional-service TorController description until the final documentation commit.

Location: src/init.cpp:575 at ac8e9e34180b (commit) (commit).

Details and suggested fix

8189f2fe9a393ccc6a438e5c8318a21b58d15641 introduces wildcard rejection without updating the help. b8d7371d8695c2db573cc4c7af6f83bf57368a57 then introduces the optional target and skipped-service behavior while its class comment still says the controller creates and maintains a service unconditionally. Both contract updates arrive in ac8e9e34180b2c68f0a7a6937e54303a128132ef. Move the wildcard-only help clause into the first commit, and the dedicated-bind requirement, outbound-discovery clause, and corrected class comment into the second. The earlier clause must not yet claim that normal binds require a dedicated target. Keep doc/tor.md and the release note in the documentation commit. These text-only moves let reviewers check each behavior against its contract without changing the final tree, build dependencies, or characterization-test boundaries.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Unresolved disagreements

The historical remote-Tor discussion left a capability tension between using the local bind as the forwarding target and supporting a distinct daemon-visible address or hostname. One participant proposed the same endpoint to avoid another option; the container-use-case author accepted it as workable but less straightforward.

A concrete dedicated bind supports remote Tor only when Tor can reach that same address and port. The inspected closure of the separate-target proposal establishes the chosen interface, but does not demonstrate that translated-address or runtime-hostname deployment needs disappeared.

Source 1 · Source 2 · Source 3