net: don’t self advertise tor exit node ip addresses in outbound connections

bitcoin/bitcoin: PR #35578

2 suggestions

Optional improvements

Link

[suggestion] · A fatal assertion can leave the IPv4 proxy set for later net_tests cases

A failed BOOST_REQUIRE after SetProxy would skip proxy cleanup and cause secondary failures in later advertisement tests.

Location: src/test/net_tests.cpp:781 (head).

Details and suggested fix

get_local_addr_for_peer_port installs a process-global IPv4 proxy, then executes three fatal BOOST_REQUIRE assertions before reaching ResetProxy(NET_IPV4). If one fails, the proxy survives into subsequent cases. Fixture cleanup clears local addresses and arguments, but not proxyInfo. For example, initial_advertise_from_version_message expects an outbound IPv4 peer's reported address to be advertised; the leftover proxy would suppress that address and make BOOST_CHECK(sent) fail as well. Create an RAII cleanup guard immediately after SetProxy succeeds so its destructor calls ResetProxy(NET_IPV4) even when the case exits early.


Link

[suggestion] · Proxy coverage misses unrelated-network configurations

Although production checks the peer's network correctly, the test would also pass a predicate that suppresses peer-observed IPv4 addresses whenever any network has a proxy.

Location: src/test/net_tests.cpp:759 (head).

Details and suggested fix

The pre-proxy assertions run without any proxy, and the new block installs only a NET_IPV4 proxy. Neither distinguishes the current predicate from an over-broad check for any configured proxy. With -onion alone, ordinary outbound IPv4 connections remain direct, so their peer-observed address must remain usable. Before the existing IPv4-proxy block, temporarily configure only NET_ONION and assert that GetLocalAddrForPeer(peer_out) equals CService{peer_us_addr, bind_port}, then reset the onion proxy. There are no local addresses at that point, so the peer-view branch is deterministic.


Coverage details

Background

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

Documented decisions

Historical self-advertisement policy distinguished useful reachability from disclosure of network identities. PR #27411 explicitly described retaining peer-observed clearnet advertisement while preventing a node's onion address from being advertised to clearnet peers when clearnet discovery failed.

The historical objective was to advertise a usable inbound address without unnecessarily linking identities—not to advertise every address that a peer reports. Its motivating example explicitly excluded using Tor as a proxy for clearnet connections, so it does not establish that an exit address was intended to qualify as the node's reachable address.

Source 1