Tried cherrypicking
0diff --git a/src/net.h b/src/net.h
1index d806b42a1e..f997bbe820 100644
2--- a/src/net.h
3+++ b/src/net.h
4@@ -1519,7 +1519,7 @@ private:
5 mutable Mutex m_added_nodes_mutex;
6 std::vector<CNode*> m_nodes GUARDED_BY(m_nodes_mutex);
7 std::list<CNode*> m_nodes_disconnected;
8- mutable RecursiveMutex m_nodes_mutex;
9+ mutable Mutex m_nodes_mutex;
10 std::atomic<NodeId> nLastNodeId{0};
11 unsigned int nPrevNodeCount{0};
12
13diff --git a/src/net_processing.cpp b/src/net_processing.cpp
14index 3777832215..20dcca2ca7 100644
15--- a/src/net_processing.cpp
16+++ b/src/net_processing.cpp
17@@ -1285,23 +1285,23 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
18 }
19 m_connman.ForNode(nodeid, [this](CNode* pfrom) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
20 AssertLockHeld(::cs_main);
21- if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
22- // As per BIP152, we only get 3 of our peers to announce
23- // blocks using compact encodings.
24- m_connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [this](CNode* pnodeStop){
25- MakeAndPushMessage(*pnodeStop, NetMsgType::SENDCMPCT, /*high_bandwidth=*/false, /*version=*/CMPCTBLOCKS_VERSION);
26- // save BIP152 bandwidth state: we select peer to be low-bandwidth
27- pnodeStop->m_bip152_highbandwidth_to = false;
28- return true;
29- });
30- lNodesAnnouncingHeaderAndIDs.pop_front();
31- }
32 MakeAndPushMessage(*pfrom, NetMsgType::SENDCMPCT, /*high_bandwidth=*/true, /*version=*/CMPCTBLOCKS_VERSION);
33 // save BIP152 bandwidth state: we select peer to be high-bandwidth
34 pfrom->m_bip152_highbandwidth_to = true;
35 lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
36 return true;
37 });
38+ if (lNodesAnnouncingHeaderAndIDs.size() > 3) {
39+ // As per BIP152, we only get 3 of our peers to announce
40+ // blocks using compact encodings.
41+ m_connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [this](CNode* pnodeStop){
42+ MakeAndPushMessage(*pnodeStop, NetMsgType::SENDCMPCT, /*high_bandwidth=*/false, /*version=*/CMPCTBLOCKS_VERSION);
43+ // save BIP152 bandwidth state: we select peer to be low-bandwidth
44+ pnodeStop->m_bip152_highbandwidth_to = false;
45+ return true;
46+ });
47+ lNodesAnnouncingHeaderAndIDs.pop_front();
48+ }
49 }
50
51 bool PeerManagerImpl::TipMayBeStale()
…and building with Clang 19.1.7 on Linux results in a lot of warnings spam:
0In file included from ../src/node/peerman_args.cpp:5:
1In file included from ../src/node/peerman_args.h:8:
2In file included from ../src/net_processing.h:10:
3../src/net.h:1186:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
4 1186 | LOCK(m_nodes_mutex);
5 | ^
6../src/sync.h:259:56: note: expanded from macro 'LOCK'
7 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
8 | ^
9In file included from ../src/node/peerman_args.cpp:5:
10In file included from ../src/node/peerman_args.h:8:
11In file included from ../src/net_processing.h:10:
12../src/net.h:1195:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
13 1195 | LOCK(m_nodes_mutex);
14 | ^
15../src/sync.h:259:56: note: expanded from macro 'LOCK'
16 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
17 | ^
182 warnings generated.
19[3/26] Building CXX object src/CMakeFiles/bitcoin_node.dir/node/txreconciliation.cpp.o
20In file included from ../src/node/txreconciliation.cpp:5:
21In file included from ../src/node/txreconciliation.h:8:
22../src/net.h:1186:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
23 1186 | LOCK(m_nodes_mutex);
24 | ^
25../src/sync.h:259:56: note: expanded from macro 'LOCK'
26 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
27 | ^
28In file included from ../src/node/txreconciliation.cpp:5:
29In file included from ../src/node/txreconciliation.h:8:
30../src/net.h:1195:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
31 1195 | LOCK(m_nodes_mutex);
32 | ^
33../src/sync.h:259:56: note: expanded from macro 'LOCK'
34 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
35 | ^
362 warnings generated.
37[4/26] Building CXX object src/CMakeFiles/bitcoin_node.dir/mapport.cpp.o
38In file included from ../src/mapport.cpp:12:
39../src/net.h:1186:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
40 1186 | LOCK(m_nodes_mutex);
41 | ^
42../src/sync.h:259:56: note: expanded from macro 'LOCK'
43 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
44 | ^
45In file included from ../src/mapport.cpp:12:
46../src/net.h:1195:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
47 1195 | LOCK(m_nodes_mutex);
48 | ^
49../src/sync.h:259:56: note: expanded from macro 'LOCK'
50 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
51 | ^
522 warnings generated.
53[5/26] Building CXX object src/CMakeFiles/bitcoin_node.dir/headerssync.cpp.o
54In file included from ../src/headerssync.cpp:5:
55In file included from ../src/headerssync.h:11:
56../src/net.h:1186:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
57 1186 | LOCK(m_nodes_mutex);
58 | ^
59../src/sync.h:259:56: note: expanded from macro 'LOCK'
60 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
61 | ^
62In file included from ../src/headerssync.cpp:5:
63In file included from ../src/headerssync.h:11:
64../src/net.h:1195:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
65 1195 | LOCK(m_nodes_mutex);
66 | ^
67../src/sync.h:259:56: note: expanded from macro 'LOCK'
68 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
69 | ^
702 warnings generated.
71[6/26] Building CXX object src/CMakeFiles/bitcoin_node.dir/node/context.cpp.o
72In file included from ../src/node/context.cpp:13:
73../src/net.h:1186:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
74 1186 | LOCK(m_nodes_mutex);
75 | ^
76../src/sync.h:259:56: note: expanded from macro 'LOCK'
77 259 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
78 | ^
79In file included from ../src/node/context.cpp:13:
80../src/net.h:1195:9: warning: calling function 'MaybeCheckNotHeld' requires negative capability '!m_nodes_mutex' [-Wthread-safety-analysis]
81 1195 | LOCK(m_nodes_mutex);
82 | ^
83...
So I think it’s quite natural to want to add all the annotations to silence the warnings within the same commit.