@@ -780,10 +780,8 @@ class PeerManagerImpl final : public PeerManager
780780 * - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_rejects_reconsiderable.
781781 * - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_confirmed_transactions.
782782 * - Each data structure's limits hold (m_orphanage max size, m_txrequest per-peer limits, etc).
783- *
784- * m_tx_download_mutex must be acquired before mempool.cs
785783 */
786- Mutex m_tx_download_mutex;
784+ Mutex m_tx_download_mutex ACQUIRED_BEFORE (m_mempool.cs) ;
787785 TxRequestTracker m_txrequest GUARDED_BY (m_tx_download_mutex);
788786 std::unique_ptr<TxReconciliationTracker> m_txreconciliation;
789787
@@ -2072,6 +2070,8 @@ void PeerManagerImpl::StartScheduledTasks(CScheduler& scheduler)
20722070
20732071void PeerManagerImpl::ActiveTipChange (const CBlockIndex& new_tip, bool is_ibd)
20742072{
2073+ // Ensure mempool mutex was released, otherwise deadlock may occur if another thread holding
2074+ // m_tx_download_mutex waits on the mempool mutex.
20752075 AssertLockNotHeld (m_mempool.cs );
20762076 AssertLockNotHeld (m_tx_download_mutex);
20772077
@@ -5334,6 +5334,7 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
53345334
53355335bool PeerManagerImpl::ProcessMessages (CNode* pfrom, std::atomic<bool >& interruptMsgProc)
53365336{
5337+ AssertLockNotHeld (m_tx_download_mutex);
53375338 AssertLockHeld (g_msgproc_mutex);
53385339
53395340 PeerRef peer = GetPeerRef (pfrom->GetId ());
@@ -5825,6 +5826,7 @@ bool PeerManagerImpl::SetupAddressRelay(const CNode& node, Peer& peer)
58255826
58265827bool PeerManagerImpl::SendMessages (CNode* pto)
58275828{
5829+ AssertLockNotHeld (m_tx_download_mutex);
58285830 AssertLockHeld (g_msgproc_mutex);
58295831
58305832 PeerRef peer = GetPeerRef (pto->GetId ());
0 commit comments