2 suggestions
Optional improvements
[suggestion] · peer_discouragement misses ordinary same-address sibling coverage
Source inspection shows that restoring the old subnet-wide disconnect would leave the existing peer_discouragement assertions passing, so the test does not protect the connection-isolation behavior added here.
Location: src/net_processing.cpp:5404 (head).
Details and suggested fix
The ordinary IPv4 peers use different addresses. The only same-address sibling, nodes[3], is PRIVATE_BROADCAST, which the old call already excluded with disconnect_private_broadcast=false. Add a second ordinary INBOUND connection at an offender's non-local address, without NoBan, and initialize and register it with connman->AddTestNode before calling UnitTestMisbehaving on the offender. After SendMessages, assert that the offender's fDisconnect is set, the sibling's is not, and banman->IsDiscouraged(addr) remains true. Restoring the base call would then fail the sibling-preservation assertion while the intended address-wide discouragement remains covered.
[suggestion] · DisconnectNode retains an unused private-broadcast exemption
This removes the only caller passing disconnect_private_broadcast=false, leaving an unused API mode that can be removed without changing any current caller's behavior.
Location: src/net_processing.cpp:5404 (base).
Details and suggested fix
The remaining callers of the CSubNet overload, including setban, the CNetAddr forwarding overload, and the fuzz harness, all use the default true. Consequently, the private-broadcast exemption is always bypassed. Remove disconnect_private_broadcast from the declaration and definition and simplify the condition to subnet.Match(pnode->addr). Keep the subnet-wide scope: explicit bans must still disconnect all matching connections, including private-broadcast ones, as they do now. Misbehaving private-broadcast peers remain handled independently by the early IsPrivateBroadcastConn() branch in MaybeDiscourageAndDisconnect.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The stated main purpose of automatic misbehavior bans was to avoid wasting connections on unhelpful peers, including peers running incompatible consensus rules. Reducing resource waste from repeated abuse was a secondary purpose, explicitly limited by the assumption that virtually any attacker could obtain a nearly unlimited supply of addresses.
The description of historical PR #14929 directly explains the policy underlying the affected misbehavior handler. It argues that eviction preferences can better accomplish the main purpose for inbound connections and that disconnection is approximately the best available response to repeated abuse. This documents a resource-management rationale, not a strong address-based exclusion guarantee.
The move away from strict automatic bans deliberately allowed previously misbehaving addresses to connect when inbound capacity permitted. Such connections were preferred for eviction, could still receive eviction protection, and would be disconnected if they misbehaved again. Reducing harm from incorrect misbehavior bans was an explicit motivation.
The pinned change retains address-wide discouragement while narrowing immediate disconnection. This historical policy distinguishes admitting connections from retaining useful ones: an address's past misbehavior was not intended to categorically prohibit subsequent inbound connections. However, the inspected proposal does not explicitly discuss whether other already-established connections sharing that address should be disconnected immediately.
Ralph's inferences
Immediate address-wide disconnection has an additional operational effect beyond future discouragement: it removes existing same-address connections without waiting for them to misbehave or become eviction candidates. The inspected history does not establish that this additional effect was intended as a distinct anti-abuse guarantee.
This is the precise distinction between the pinned base's subnet-wide DisconnectNode call and the head's per-connection fDisconnect assignment. The historical acceptance of new connections from automatically banned addresses, together with the stated weakness of address-based abuse prevention, cautions against interpreting the older call's breadth as evidence of a promised security property. It does not prove that the breadth was accidental.