3 suggestions
Optional improvements
[suggestion] · Replacement requests cannot run with a saturated low connection limit
With an effective -maxconnections limit of at most ten and all persistent outbound slots filled, the replacement flag cannot lead to a connect-before-evict swap because no spare outbound grant exists.
Location: src/net.cpp:2856 (head).
Details and suggested fix
ThreadOpenConnections acquires a semOutbound grant before reaching this branch. The semaphore capacity is min(full-relay target + block-relay target + one feeler, effective connection limit), so established peers hold every grant at limits of at most ten once both persistent targets are filled. In the new -maxconnections=2 subtest, the two full-relay peers exhaust that capacity. The flag can become true, but replacement eviction requires an extra fully connected peer, so these peers remain unless another event disconnects them. This is an existing capacity restriction, not a regression; the default configuration has one spare grant beyond its eight full-relay and two block-relay peers. Document the spare-grant requirement beside this branch and clarify that the low-limit subtest checks only the request, not an eventual swap. A disconnect-first fallback would abandon the intended connect-before-evict behavior.
[suggestion] · The -blocksonly subtest cannot detect loss of the replacement exemption
The single-peer fixture suppresses replacement independently of -blocksonly, so removing the blocksonly guard from replace_no_tx_relay would leave its assertions passing.
Location: test/functional/p2p_blocksonly.py:104 (head).
Details and suggested fix
This subtest uses -blocksonly -maxconnections=1, adds one txrelay=False full-relay outbound peer, and checks only that it still answers a ping. MultipleManualOrFullOutboundConns is false for its network, so the replacement scan skips it regardless of the blocksonly guard. There is also no extra full-relay peer to evict, so the fixture cannot exercise eviction priority either. Use -blocksonly -maxconnections=2 with two same-network txrelay=False peers and assert that the log never contains "setting replace no-tx-relay peer=true" when the scheduled check runs. Keep the preceding non-blocksonly case as the positive control. This would distinguish the replacement-request exemption without requiring an actual replacement connection.
[suggestion] · Eviction comments still describe announcement-only ordering
The comparator now prioritizes eligible peers that do not relay transactions, but three comments still describe selection solely by the oldest block announcement.
Location: src/net_processing.cpp:5644 (head).
Details and suggested fix
Outside IBD and -blocksonly mode, an eligible full-relay outbound peer that does not relay transactions takes priority over every tx-relaying candidate, regardless of announcement time. This applies to all extra full-relay connections, including stale-tip and network-specific extras. Update the ChainSyncTimeoutState documentation, the EvictExtraOutboundPeers declaration comment, and the selection comment above WorstPeer to describe this priority, followed by oldest block announcement within each group and higher node ID as the tie-breaker. Preserve the existing qualifications: protected peers and sole connections to a network are excluded, while minimum connection time and blocks in flight still gate disconnection.