Skip to content

Commit 5dde8e7

Browse files
committed
merge bitcoin#25109: Strengthen AssertLockNotHeld assertions
1 parent a1f005e commit 5dde8e7

15 files changed

+148
-112
lines changed

src/checkqueue.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CCheckQueue
6565
bool m_request_stop GUARDED_BY(m_mutex){false};
6666

6767
/** Internal function that does bulk of the verification work. */
68-
bool Loop(bool fMaster)
68+
bool Loop(bool fMaster) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
6969
{
7070
std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
7171
std::vector<T> vChecks;
@@ -139,7 +139,7 @@ class CCheckQueue
139139
}
140140

141141
//! Create a pool of new worker threads.
142-
void StartWorkerThreads(const int threads_num)
142+
void StartWorkerThreads(const int threads_num) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
143143
{
144144
{
145145
LOCK(m_mutex);
@@ -157,13 +157,13 @@ class CCheckQueue
157157
}
158158

159159
//! Wait until execution finishes, and return whether all evaluations were successful.
160-
bool Wait()
160+
bool Wait() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
161161
{
162162
return Loop(true /* master thread */);
163163
}
164164

165165
//! Add a batch of checks to the queue
166-
void Add(std::vector<T>& vChecks)
166+
void Add(std::vector<T>& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
167167
{
168168
if (vChecks.empty()) {
169169
return;
@@ -186,7 +186,7 @@ class CCheckQueue
186186
}
187187

188188
//! Stop all of the worker threads.
189-
void StopWorkerThreads()
189+
void StopWorkerThreads() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
190190
{
191191
WITH_LOCK(m_mutex, m_request_stop = true);
192192
m_worker_cv.notify_all();

src/coinjoin/coinjoin.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,22 @@ class CDSTXManager
368368
void AddDSTX(const CCoinJoinBroadcastTx& dstx) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
369369
CCoinJoinBroadcastTx GetDSTX(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
370370

371-
void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync);
372-
void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync);
371+
void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler,
372+
const CMasternodeSync& mn_sync)
373+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
374+
void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler,
375+
const CMasternodeSync& mn_sync)
376+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
373377

374378
void TransactionAddedToMempool(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
375-
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
376-
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex*) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
379+
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
380+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
381+
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex*)
382+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
377383

378384
private:
379-
void CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler);
385+
void CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler)
386+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
380387
void UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::optional<int> nHeight);
381388

382389
};

src/httpserver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class WorkQueue
8383
{
8484
}
8585
/** Enqueue a work item */
86-
bool Enqueue(WorkItem* item)
86+
bool Enqueue(WorkItem* item) EXCLUSIVE_LOCKS_REQUIRED(!cs)
8787
{
8888
LOCK(cs);
8989
if (!running || queue.size() >= maxDepth) {
@@ -94,7 +94,7 @@ class WorkQueue
9494
return true;
9595
}
9696
/** Thread function */
97-
void Run()
97+
void Run() EXCLUSIVE_LOCKS_REQUIRED(!cs)
9898
{
9999
while (true) {
100100
std::unique_ptr<WorkItem> i;
@@ -111,7 +111,7 @@ class WorkQueue
111111
}
112112
}
113113
/** Interrupt and exit loops */
114-
void Interrupt()
114+
void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!cs)
115115
{
116116
LOCK(cs);
117117
running = false;

src/i2p.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Session
8484
* to the listening socket and address.
8585
* @return true on success
8686
*/
87-
bool Listen(Connection& conn);
87+
bool Listen(Connection& conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
8888

8989
/**
9090
* Wait for and accept a new incoming connection.
@@ -103,7 +103,7 @@ class Session
103103
* it is set to `false`. Only set if `false` is returned.
104104
* @return true on success
105105
*/
106-
bool Connect(const CService& to, Connection& conn, bool& proxy_error);
106+
bool Connect(const CService& to, Connection& conn, bool& proxy_error) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
107107

108108
private:
109109
/**
@@ -172,7 +172,7 @@ class Session
172172
/**
173173
* Check the control socket for errors and possibly disconnect.
174174
*/
175-
void CheckControlSock();
175+
void CheckControlSock() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
176176

177177
/**
178178
* Generate a new destination with the SAM proxy and set `m_private_key` to it.

src/index/blockfilterindex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BlockFilterIndex final : public BaseIndex
6363
bool LookupFilter(const CBlockIndex* block_index, BlockFilter& filter_out) const;
6464

6565
/** Get a single filter header by block. */
66-
bool LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out);
66+
bool LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_headers_cache);
6767

6868
/** Get a range of filters between two heights on a chain. */
6969
bool LookupFilterRange(int start_height, const CBlockIndex* stop_index,

src/net.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,6 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
29862986
}
29872987

29882988
void CConnman::OpenMasternodeConnection(const CAddress &addrConnect, MasternodeProbeConn probe) {
2989-
29902989
OpenNetworkConnection(addrConnect, false, nullptr, nullptr, ConnectionType::OUTBOUND_FULL_RELAY, MasternodeConn::IsConnection, probe);
29912990
}
29922991

src/net.h

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ class CNode
652652
* @return True if the peer should stay connected,
653653
* False if the peer should be disconnected from.
654654
*/
655-
bool ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete);
655+
bool ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete) EXCLUSIVE_LOCKS_REQUIRED(!cs_vRecv);
656656

657657
void SetCommonVersion(int greatest_common_version)
658658
{
@@ -664,9 +664,9 @@ class CNode
664664
return m_greatest_common_version;
665665
}
666666

667-
CService GetAddrLocal() const LOCKS_EXCLUDED(m_addr_local_mutex);
667+
CService GetAddrLocal() const EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
668668
//! May not be called more than once
669-
void SetAddrLocal(const CService& addrLocalIn) LOCKS_EXCLUDED(m_addr_local_mutex);
669+
void SetAddrLocal(const CService& addrLocalIn) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
670670

671671
CNode* AddRef()
672672
{
@@ -679,9 +679,9 @@ class CNode
679679
nRefCount--;
680680
}
681681

682-
void CloseSocketDisconnect(CConnman* connman);
682+
void CloseSocketDisconnect(CConnman* connman) EXCLUSIVE_LOCKS_REQUIRED(!cs_hSocket);
683683

684-
void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
684+
void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap) EXCLUSIVE_LOCKS_REQUIRED(!m_subver_mutex, !m_addr_local_mutex, !cs_vSend, !cs_vRecv);
685685

686686
ServiceFlags GetLocalServices() const
687687
{
@@ -857,7 +857,7 @@ friend class CNode;
857857
bool m_i2p_accept_incoming;
858858
};
859859

860-
void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
860+
void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
861861
{
862862
AssertLockNotHeld(m_total_bytes_sent_mutex);
863863

@@ -891,7 +891,8 @@ friend class CNode;
891891
CConnman(uint64_t seed0, uint64_t seed1, CAddrMan& addrman, bool network_active = true);
892892
~CConnman();
893893
bool Start(CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CMasternodeSync& mn_sync,
894-
CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
894+
CScheduler& scheduler, const Options& options)
895+
EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc);
895896

896897
void StopThreads();
897898
void StopNodes();
@@ -901,7 +902,7 @@ friend class CNode;
901902
StopNodes();
902903
};
903904

904-
void Interrupt();
905+
void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
905906
bool GetNetworkActive() const { return fNetworkActive; };
906907
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
907908
void SetNetworkActive(bool active, CMasternodeSync* const mn_sync);
@@ -917,8 +918,13 @@ friend class CNode;
917918
IsConnection,
918919
};
919920

920-
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant* grantOutbound, const char* strDest, ConnectionType conn_type, MasternodeConn masternode_connection = MasternodeConn::IsNotConnection, MasternodeProbeConn masternode_probe_connection = MasternodeProbeConn::IsNotConnection);
921-
void OpenMasternodeConnection(const CAddress& addrConnect, MasternodeProbeConn probe = MasternodeProbeConn::IsConnection);
921+
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant* grantOutbound,
922+
const char* strDest, ConnectionType conn_type,
923+
MasternodeConn masternode_connection = MasternodeConn::IsNotConnection,
924+
MasternodeProbeConn masternode_probe_connection = MasternodeProbeConn::IsNotConnection)
925+
EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
926+
void OpenMasternodeConnection(const CAddress& addrConnect, MasternodeProbeConn probe = MasternodeProbeConn::IsConnection)
927+
EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
922928
bool CheckIncomingNonce(uint64_t nonce);
923929

924930
struct CFullyConnectedOnly {
@@ -959,7 +965,8 @@ friend class CNode;
959965

960966
bool IsMasternodeOrDisconnectRequested(const CService& addr);
961967

962-
void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
968+
void PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
969+
EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc, !m_total_bytes_sent_mutex);
963970

964971
template<typename Condition, typename Callable>
965972
bool ForEachNodeContinueIf(const Condition& cond, Callable&& func)
@@ -1099,9 +1106,9 @@ friend class CNode;
10991106
// Count the number of block-relay-only peers we have over our limit.
11001107
int GetExtraBlockRelayCount() const;
11011108

1102-
bool AddNode(const std::string& node);
1103-
bool RemoveAddedNode(const std::string& node);
1104-
std::vector<AddedNodeInfo> GetAddedNodeInfo() const;
1109+
bool AddNode(const std::string& node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1110+
bool RemoveAddedNode(const std::string& node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1111+
std::vector<AddedNodeInfo> GetAddedNodeInfo() const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
11051112

11061113
/**
11071114
* Attempts to open a connection. Currently only used from tests.
@@ -1114,7 +1121,7 @@ friend class CNode;
11141121
* - Max total outbound connection capacity filled
11151122
* - Max connection capacity for type is filled
11161123
*/
1117-
bool AddConnection(const std::string& address, ConnectionType conn_type);
1124+
bool AddConnection(const std::string& address, ConnectionType conn_type) EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
11181125

11191126
bool AddPendingMasternode(const uint256& proTxHash);
11201127
void SetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash, const std::set<uint256>& proTxHashes);
@@ -1166,8 +1173,8 @@ friend class CNode;
11661173

11671174
unsigned int GetReceiveFloodSize() const;
11681175

1169-
void WakeMessageHandler();
1170-
void WakeSelect();
1176+
void WakeMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1177+
void WakeSelect() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
11711178

11721179
/** Attempts to obfuscate tx time through exponentially distributed emitting.
11731180
Works assuming that a single interval is used.
@@ -1221,13 +1228,15 @@ friend class CNode;
12211228
const std::vector<NetWhitebindPermissions>& whiteBinds,
12221229
const std::vector<CService>& onion_binds);
12231230

1224-
void ThreadOpenAddedConnections();
1225-
void AddAddrFetch(const std::string& strDest);
1226-
void ProcessAddrFetch();
1227-
void ThreadOpenConnections(const std::vector<std::string> connect, CDeterministicMNManager& dmnman);
1228-
void ThreadMessageHandler();
1229-
void ThreadI2PAcceptIncoming(CMasternodeSync& mn_sync);
1230-
void AcceptConnection(const ListenSocket& hListenSocket, CMasternodeSync& mn_sync);
1231+
void ThreadOpenAddedConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !mutexMsgProc);
1232+
void AddAddrFetch(const std::string& strDest) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex);
1233+
void ProcessAddrFetch() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !mutexMsgProc);
1234+
void ThreadOpenConnections(const std::vector<std::string> connect, CDeterministicMNManager& dmnman)
1235+
EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_added_nodes_mutex, !m_nodes_mutex, !mutexMsgProc);
1236+
void ThreadMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1237+
void ThreadI2PAcceptIncoming(CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1238+
void AcceptConnection(const ListenSocket& hListenSocket, CMasternodeSync& mn_sync)
1239+
EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
12311240

12321241
/**
12331242
* Create a `CNode` object from a socket that has just been accepted and add the node to
@@ -1241,7 +1250,7 @@ friend class CNode;
12411250
NetPermissionFlags permissionFlags,
12421251
const CAddress& addr_bind,
12431252
const CAddress& addr,
1244-
CMasternodeSync& mn_sync);
1253+
CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
12451254

12461255
void DisconnectNodes();
12471256
void NotifyNumConnectionsChanged(CMasternodeSync& mn_sync);
@@ -1305,7 +1314,7 @@ friend class CNode;
13051314
/**
13061315
* Check connected and listening sockets for IO readiness and process them accordingly.
13071316
*/
1308-
void SocketHandler(CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1317+
void SocketHandler(CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
13091318

13101319
/**
13111320
* Do the read/write for connected sockets that are ready for IO.
@@ -1316,18 +1325,20 @@ friend class CNode;
13161325
void SocketHandlerConnected(const std::set<SOCKET>& recv_set,
13171326
const std::set<SOCKET>& send_set,
13181327
const std::set<SOCKET>& error_set)
1319-
EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1328+
EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
13201329

13211330
/**
13221331
* Accept incoming connections, one from each read-ready listening socket.
13231332
* @param[in] recv_set Sockets that are ready for read.
13241333
*/
1325-
void SocketHandlerListening(const std::set<SOCKET>& recv_set, CMasternodeSync& mn_sync);
1334+
void SocketHandlerListening(const std::set<SOCKET>& recv_set, CMasternodeSync& mn_sync)
1335+
EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
13261336

1327-
void ThreadSocketHandler(CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1328-
void ThreadDNSAddressSeed();
1337+
void ThreadSocketHandler(CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1338+
void ThreadDNSAddressSeed() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_nodes_mutex);
13291339
void ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
1330-
CMasternodeSync& mn_sync);
1340+
CMasternodeSync& mn_sync)
1341+
EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_nodes_mutex, !mutexMsgProc);
13311342

13321343
uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
13331344

@@ -1351,7 +1362,7 @@ friend class CNode;
13511362
NodeId GetNewNodeId();
13521363

13531364
size_t SocketSendData(CNode& node) EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1354-
size_t SocketRecvData(CNode* pnode);
1365+
size_t SocketRecvData(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
13551366
void DumpAddresses();
13561367

13571368
// Network stats

0 commit comments

Comments
 (0)