From 202385cbe47b7c11ebe46762499a78fadaefafdf Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 2 Sep 2026 15:32:48 +0300 Subject: [PATCH] fix: restore the intended cs_main scope in FinalizeNode 40906b2bbb ("partial bitcoin#20228: Make addrman a top-level component", PR #5163) transposed two lines when backporting upstream 3fc06d3d7b. Upstream opens a scope and takes cs_main inside it: int misbehavior{0}; { LOCK(cs_main); { while the backport landed the LOCK before the scope: int misbehavior{0}; LOCK(cs_main); { { The braces still balance, so this compiled and went unnoticed, but cs_main ended up held for the whole function instead of just that block. The `} // cs_main` marker has been wrong ever since. It stayed harmless because the only code below the marker is CAddrMan::Connected() and a LogPrint, neither of which contends for anything meaningful. It stops being harmless as soon as someone adds work below the marker that takes a contended lock, since the comment says they are outside cs_main when they are not. Restore the upstream shape. No behavior change: nothing below the marker requires cs_main, and misbehavior and nodeid are declared above the scope. Co-Authored-By: Claude Opus 5 --- src/net_processing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 740a4e966d27..e90381eff780 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1739,8 +1739,8 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler) void PeerManagerImpl::FinalizeNode(const CNode& node) { NodeId nodeid = node.GetId(); int misbehavior{0}; - LOCK(cs_main); { + LOCK(cs_main); { // We remove the PeerRef from g_peer_map here, but we don't always // destruct the Peer. Sometimes another thread is still holding a