From 673247b58cd1252ab7e99f7d63ead05cc100cef2 Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Sun, 13 Sep 2020 19:34:52 -0400 Subject: Lock before checking if orphan_work_set is empty; indicate it is guarded --- src/net_processing.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index ab3c323b0f..1a50c68a26 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -513,7 +513,7 @@ struct Peer { bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false}; /** Set of txids to reconsider once their parent transactions have been accepted **/ - std::set m_orphan_work_set; + std::set m_orphan_work_set GUARDED_BY(g_cs_orphans); Peer(NodeId id) : m_id(id) {} }; @@ -3876,9 +3876,11 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP if (!pfrom->vRecvGetData.empty()) ProcessGetData(*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); - if (!peer->m_orphan_work_set.empty()) { + { LOCK2(cs_main, g_cs_orphans); - ProcessOrphanTx(peer->m_orphan_work_set); + if (!peer->m_orphan_work_set.empty()) { + ProcessOrphanTx(peer->m_orphan_work_set); + } } if (pfrom->fDisconnect) @@ -3887,7 +3889,10 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP // this maintains the order of responses // and prevents vRecvGetData to grow unbounded if (!pfrom->vRecvGetData.empty()) return true; - if (!peer->m_orphan_work_set.empty()) return true; + { + LOCK(g_cs_orphans); + if (!peer->m_orphan_work_set.empty()) return true; + } // Don't bother if send buffer is too full to respond anyway if (pfrom->fPauseSend) -- cgit v1.2.3