test: add functional test for outbound connection management

bitcoin/bitcoin: PR #33954

The review is inconclusive; no findings were published.

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

Sole-network protection was intended as a categorical exclusion from extra full-relay eviction, not merely a preference in ranking eviction candidates. The original proposal explicitly says that outbound eviction “ensures that peers are protected if they are the only ones for their network.” This is a guarantee within that eviction policy, not a guarantee against every possible disconnection.

This directly addresses test_network_specific_peers(): after establishing an extra full-relay connection from a previously unrepresented network, the test expects that network to remain represented after eviction. Both pinned base and head implement the stated protection by excluding sole-network peers before comparing block-announcement recency.

Source 1 · Source 2

The motivation was to preserve diversity that address-frequency-based selection would otherwise rarely provide, improving eclipse resistance, partition resistance, and privacy. Connection acquisition was deliberately defensive: fill ordinary outbound slots first, then attempt additional connections to missing networks, so an unavailable or misconfigured alternate network cannot leave ordinary slots unfilled. Manual peers also satisfy network representation.

The historical design separates best-effort acquisition from protection once connected. The test follows that sequence by first establishing regular outbounds, adding Tor and CJDNS addresses, waiting for an extra connection, and then checking preservation during eviction. It does not establish a general guarantee that every reachable network can always be connected.

Source 1

Ralph's inferences

The precise contract is narrower than “retain the sole peer of every network visible in getpeerinfo.” For this eviction path, representation is assessed using full-relay outbound and manual connections; block-relay-only eviction follows separate rules. The network guard precedes block-announcement ranking, so it is not a diversity score that a sufficiently poor announcement history can outweigh.

The new test exercises the protected case with automatic full-relay connections. Its retention expectation reflects an existing local policy invariant, while successful acquisition, uninterrupted connectivity, and protection from other disconnection mechanisms remain outside that invariant. The relevant eviction code is unchanged between the pinned base and head.