@@ -780,10 +780,8 @@ class PeerManagerImpl final : public PeerManager
780
780
* - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_rejects_reconsiderable.
781
781
* - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_confirmed_transactions.
782
782
* - 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
785
783
*/
786
- Mutex m_tx_download_mutex;
784
+ Mutex m_tx_download_mutex ACQUIRED_BEFORE (m_mempool.cs) ;
787
785
TxRequestTracker m_txrequest GUARDED_BY (m_tx_download_mutex);
788
786
std::unique_ptr<TxReconciliationTracker> m_txreconciliation;
789
787
@@ -2072,6 +2070,8 @@ void PeerManagerImpl::StartScheduledTasks(CScheduler& scheduler)
2072
2070
2073
2071
void PeerManagerImpl::ActiveTipChange (const CBlockIndex& new_tip, bool is_ibd)
2074
2072
{
2073
+ // Ensure mempool mutex was released, otherwise deadlock may occur if another thread holding
2074
+ // m_tx_download_mutex waits on the mempool mutex.
2075
2075
AssertLockNotHeld (m_mempool.cs );
2076
2076
AssertLockNotHeld (m_tx_download_mutex);
2077
2077
@@ -5334,6 +5334,7 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
5334
5334
5335
5335
bool PeerManagerImpl::ProcessMessages (CNode* pfrom, std::atomic<bool >& interruptMsgProc)
5336
5336
{
5337
+ AssertLockNotHeld (m_tx_download_mutex);
5337
5338
AssertLockHeld (g_msgproc_mutex);
5338
5339
5339
5340
PeerRef peer = GetPeerRef (pfrom->GetId ());
@@ -5825,6 +5826,7 @@ bool PeerManagerImpl::SetupAddressRelay(const CNode& node, Peer& peer)
5825
5826
5826
5827
bool PeerManagerImpl::SendMessages (CNode* pto)
5827
5828
{
5829
+ AssertLockNotHeld (m_tx_download_mutex);
5828
5830
AssertLockHeld (g_msgproc_mutex);
5829
5831
5830
5832
PeerRef peer = GetPeerRef (pto->GetId ());
0 commit comments