1 suggestion
Optional improvements
[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:
- #36869 b9a6b0c -> 72d6048: the memusage.h change is identical to upstream. It only removes
private:from stl_tree_node, list_node and unordered_node, so every field keeps the same access level and the struct layout does not change (head src/memusage.h:68-182). - #36889 460f877 -> c4547c4: the change is identical. At head, src/CMakeLists.txt:8-11 sets target_include_directories(core_interface INTERFACE ...). Every first-party target links core_interface: bitcoin_clientversion, bitcoin_consensus, bitcoin_common, bitcoin-wallet, bitcoin_node, bitcoin, bitcoind, bitcoin-node, bitcoin_cli, bitcoin-cli, bitcoin-tx, bitcoin-util and bitcoin-chainstate (src/CMakeLists.txt 54-412). The same holds for bitcoin_crypto (crypto/CMakeLists.txt:27), bitcoin_zmq (zmq:18), bitcoin_ipc and bitcoin_ipc_test (ipc:21,43), bitcoinkernel (kernel:103), the qt targets (qt:150,267,284), univalue, wallet, test, fuzz, bench, crc32c, leveldb and minisketch. libmultiprocess also links it, and cmake/libmultiprocess.cmake is identical to upstream.
- Left-out commit 4ef05d6f45620254417fe6be701bebbf1a42619a (#36889, 'Link bitcoin_ipc against core_interface') was correctly omitted. Upstream it adds target_link_libraries to the
else()branch that builds a stub bitcoin_ipc from ipc/stub.cpp. On 31.x that branch and that file do not exist (base path search for ipc/stub finds nothing; head src/CMakeLists.txt:60-62 has onlyif(ENABLE_IPC) add_subdirectory(ipc)). The only bitcoin_ipc target is in src/ipc/CMakeLists.txt, which already links core_interface. Every place that links bitcoin_ipc is guarded by ENABLE_IPC (src/CMakeLists.txt:325, qt/CMakeLists.txt:278). - #36889 435d5b2 -> 1a38585: the change is identical. No file at head still references WarnAboutGlobalProperties. The dev-mode preset in CMakePresets.json (
errors: {dev: true}) is the same on 31.x as upstream at 435d5b2, so the reason given in the commit message also holds on this branch. - #36894 d63068c -> 35f34a3: the logic is identical. Head net_processing.cpp:5189-5232 matches upstream 5363-5406, with pnode.fDisconnect replacing the subnet-wide DisconnectNode. The range-diff only shows differences from 31.x code: no EXCLUSIVE_LOCKS_REQUIRED/AssertLockNotHeld, and DisconnectMsg(fLogIPs) is kept. No code passes the removed disconnect_private_broadcast argument. The remaining callers (rpc/net.cpp:808 setban, the CNetAddr overload, fuzz/connman.cpp:126) used the default of true, so their behavior is unchanged.
- src/test/denialofservice_tests.cpp:301-436 (peer_discouragement) still matches the new behavior: the private-broadcast node[3], which shares addr[2] with node[2], must not be disconnected when node[2] misbehaves. Functional-test peers connect from localhost and take the IsLocal branch, which is unchanged. The historical context (PRs #14929, #19219) supports discouraging the whole address while disconnecting only the one connection.
- Release notes (1fed214): doc/release-notes.md now lists #36894, #36889 and #36869 with their authors. Replacing the v31.3 entries follows the branch's own pattern: commit 57f79f1 replaced the 31.2 notes with 31.3 in the same way. CMakeLists.txt still shows 31.3 as the released version (CLIENT_VERSION_IS_RELEASE true), and no archived release-notes-31.* files exist on this branch.
Limitations:
- No build, unit-test, functional-test or fuzz results were supplied, and none were run at this stage. All conclusions come from reading the source of the pinned base, head and upstream commits.
- I did not run CMake, so I have not confirmed that CMake 4.5's -Wnon-target-directive stays quiet for 31.x configurations. The secp256k1 subtree still has a directory-level include_directories for Valgrind, but upstream at 435d5b2 has the same line.
- The body of PR #36869 in the evidence packet was cut off. The commit patch itself was complete and matches upstream exactly.
- The historical rationale for #36894 is only partly covered: no inspected source shows a protection that depends on disconnecting every connection from an address at once, but that does not prove none exists.
- bitcoin/bitcoin#36869: truncated body
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.
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.
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.