[31.x] Backports

bitcoin/bitcoin: PR #36901

1 suggestion

Optional improvements

Link

[suggestion] · peer_discouragement misses ordinary same-address sibling survival

The existing peer_discouragement assertions would still pass if address-wide teardown returned with the former private-broadcast exemption.

Location: src/net_processing.cpp:5230 (head).

Details and suggested fix

The ordinary inbound peers in peer_discouragement have different addresses. The only same-address pair is nodes[2] and its PRIVATE_BROADCAST sibling, which the base implementation already excluded from subnet disconnection. Its survival assertion therefore does not distinguish the old behavior from setting only the offender's fDisconnect. Register two ordinary INBOUND peers with the same non-local address before either misbehaves. Call UnitTestMisbehaving on one and then SendMessages; assert that the offender's fDisconnect is set, the sibling's is clear, and IsDiscouraged(shared_addr) is true. This would directly cover the shared-address case fixed by #36894 using the existing synthetic-node fixture. Upstream commit d63068c58ec9fcc94876bce30865d1a7266d64d4 adds no test either, so add this coverage upstream and backport it with or after the fix.


Backport verdict: Needs clarification

Fidelity could not be established from the available evidence.

Evidence:

Limitations:

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

Automatic misbehavior handling primarily aimed to keep scarce connection slots from being wasted on unhelpful peers, including peers running incompatible consensus rules—not to provide a strong identity-based security boundary.

The proposal preceding discouragement explicitly described eviction preferences as a better way to achieve this purpose for inbound peers. It also described repeated-abuse mitigation as secondary because attackers can obtain many addresses. This is the historical purpose against which the base's immediate address-wide disconnection should be understood.

Source 1

The historical policy deliberately allowed incoming connections from automatically penalized addresses when capacity permitted, while preferring those connections for eviction; renewed misbehavior would still cause disconnection.

Immediate exclusion of every connection from a penalized address was not the intended steady-state invariant. The historical proposal even allowed connections to remain when they qualified for protected eviction classes. This distinguishes disconnecting a misbehaving connection from requiring the address to have no live connections.

Source 1

Discouragement was separated from manual banning to preserve connection-management effects with lower resource costs: eviction preference, avoidance for outgoing connections, and suppression of address gossip. Its documented threat model says neither banning nor discouragement protects against denial of service by an attacker able to change addresses, and warns that automatic disconnection can split the network.

The pinned head retains address-wide Discourage(pnode.addr) while changing immediate teardown to pnode.fDisconnect. Historical documentation supports treating discouragement as a bounded compatibility and resource-management mechanism, rather than assuming address-wide teardown was an essential anti-DoS guarantee.

Source 1 · Source 2