From 9c47cb29f9f525ee58acc629825a97075156d764 Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Sun, 13 Sep 2020 19:07:49 -0400 Subject: [PATCH 1/6] [Rename only] Rename orphan_work_set to m_orphan_work_set. This helps distinguish the member from any local variables. --- src/net.h | 2 +- src/net_processing.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/net.h b/src/net.h index 7c63516394..c357d33165 100644 --- a/src/net.h +++ b/src/net.h @@ -1042,7 +1042,7 @@ class CNode // Whether a ping is requested. std::atomic fPingQueued{false}; - std::set orphan_work_set; + std::set m_orphan_work_set; CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion = false); ~CNode(); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 9ad3f5d6f4..7b5805c93e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3052,7 +3052,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(txid, i)); if (it_by_prev != mapOrphanTransactionsByPrev.end()) { for (const auto& elem : it_by_prev->second) { - pfrom.orphan_work_set.insert(elem->first); + pfrom.m_orphan_work_set.insert(elem->first); } } } @@ -3069,7 +3069,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat } // Recursively process any orphan transactions that depended on this one - ProcessOrphanTx(pfrom.orphan_work_set); + ProcessOrphanTx(pfrom.m_orphan_work_set); } else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { @@ -3868,9 +3868,9 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP if (!pfrom->vRecvGetData.empty()) ProcessGetData(*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); - if (!pfrom->orphan_work_set.empty()) { + if (!pfrom->m_orphan_work_set.empty()) { LOCK2(cs_main, g_cs_orphans); - ProcessOrphanTx(pfrom->orphan_work_set); + ProcessOrphanTx(pfrom->m_orphan_work_set); } if (pfrom->fDisconnect) @@ -3879,7 +3879,7 @@ 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 (!pfrom->orphan_work_set.empty()) return true; + if (!pfrom->m_orphan_work_set.empty()) return true; // Don't bother if send buffer is too full to respond anyway if (pfrom->fPauseSend) From 8803aee66813d27ddbdfce937ab9c35f8f7c35bc Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Sun, 13 Sep 2020 19:29:50 -0400 Subject: [PATCH 2/6] Move m_orphan_work_set to net_processing --- src/net.h | 2 -- src/net_processing.cpp | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/net.h b/src/net.h index c357d33165..da82fe9a2e 100644 --- a/src/net.h +++ b/src/net.h @@ -1042,8 +1042,6 @@ class CNode // Whether a ping is requested. std::atomic fPingQueued{false}; - std::set m_orphan_work_set; - CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion = false); ~CNode(); CNode(const CNode&) = delete; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 7b5805c93e..ab3c323b0f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -512,6 +512,9 @@ struct Peer { /** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */ 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; + Peer(NodeId id) : m_id(id) {} }; @@ -2363,6 +2366,8 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat return; } + PeerRef peer = GetPeerRef(pfrom.GetId()); + if (peer == nullptr) return; if (msg_type == NetMsgType::VERSION) { // Each connection can only send one version message @@ -3052,7 +3057,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(txid, i)); if (it_by_prev != mapOrphanTransactionsByPrev.end()) { for (const auto& elem : it_by_prev->second) { - pfrom.m_orphan_work_set.insert(elem->first); + peer->m_orphan_work_set.insert(elem->first); } } } @@ -3069,7 +3074,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat } // Recursively process any orphan transactions that depended on this one - ProcessOrphanTx(pfrom.m_orphan_work_set); + ProcessOrphanTx(peer->m_orphan_work_set); } else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { @@ -3865,12 +3870,15 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP { bool fMoreWork = false; + PeerRef peer = GetPeerRef(pfrom->GetId()); + if (peer == nullptr) return false; + if (!pfrom->vRecvGetData.empty()) ProcessGetData(*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); - if (!pfrom->m_orphan_work_set.empty()) { + if (!peer->m_orphan_work_set.empty()) { LOCK2(cs_main, g_cs_orphans); - ProcessOrphanTx(pfrom->m_orphan_work_set); + ProcessOrphanTx(peer->m_orphan_work_set); } if (pfrom->fDisconnect) @@ -3879,7 +3887,7 @@ 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 (!pfrom->m_orphan_work_set.empty()) return true; + if (!peer->m_orphan_work_set.empty()) return true; // Don't bother if send buffer is too full to respond anyway if (pfrom->fPauseSend) From 673247b58cd1252ab7e99f7d63ead05cc100cef2 Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Sun, 13 Sep 2020 19:34:52 -0400 Subject: [PATCH 3/6] 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) From 2d9f2fca43aadcdda4d644cddab36dca88b40b97 Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Sun, 13 Sep 2020 20:11:24 -0400 Subject: [PATCH 4/6] Move vRecvGetData to net processing --- src/net.h | 1 - src/net_processing.cpp | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/net.h b/src/net.h index da82fe9a2e..cd7a7c7c73 100644 --- a/src/net.h +++ b/src/net.h @@ -848,7 +848,6 @@ class CNode RecursiveMutex cs_sendProcessing; - std::deque vRecvGetData; uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0}; std::atomic nLastSend{0}; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 1a50c68a26..3b632cf20b 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -515,6 +515,9 @@ struct Peer { /** Set of txids to reconsider once their parent transactions have been accepted **/ std::set m_orphan_work_set GUARDED_BY(g_cs_orphans); + /** Work queue of items requested by this peer **/ + std::deque vRecvGetData; + Peer(NodeId id) : m_id(id) {} }; @@ -1754,7 +1757,10 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm { AssertLockNotHeld(cs_main); - std::deque::iterator it = pfrom.vRecvGetData.begin(); + PeerRef peer = GetPeerRef(pfrom.GetId()); + if (peer == nullptr) return; + + std::deque::iterator it = peer->vRecvGetData.begin(); std::vector vNotFound; const CNetMsgMaker msgMaker(pfrom.GetCommonVersion()); @@ -1766,7 +1772,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm // Process as many TX items from the front of the getdata queue as // possible, since they're common and it's efficient to batch process // them. - while (it != pfrom.vRecvGetData.end() && it->IsGenTxMsg()) { + while (it != peer->vRecvGetData.end() && it->IsGenTxMsg()) { if (interruptMsgProc) return; // The send buffer provides backpressure. If there's no space in // the buffer, pause processing until the next call. @@ -1814,7 +1820,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm // Only process one BLOCK item per call, since they're uncommon and can be // expensive to process. - if (it != pfrom.vRecvGetData.end() && !pfrom.fPauseSend) { + if (it != peer->vRecvGetData.end() && !pfrom.fPauseSend) { const CInv &inv = *it++; if (inv.IsGenBlkMsg()) { ProcessGetBlockData(pfrom, chainparams, inv, connman); @@ -1823,7 +1829,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm // and continue processing the queue on the next call. } - pfrom.vRecvGetData.erase(pfrom.vRecvGetData.begin(), it); + peer->vRecvGetData.erase(peer->vRecvGetData.begin(), it); if (!vNotFound.empty()) { // Let the peer know that we didn't find what it asked for, so it doesn't @@ -2805,7 +2811,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom.GetId()); } - pfrom.vRecvGetData.insert(pfrom.vRecvGetData.end(), vInv.begin(), vInv.end()); + peer->vRecvGetData.insert(peer->vRecvGetData.end(), vInv.begin(), vInv.end()); ProcessGetData(pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); return; } @@ -2914,7 +2920,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat CInv inv; inv.type = State(pfrom.GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK; inv.hash = req.blockhash; - pfrom.vRecvGetData.push_back(inv); + peer->vRecvGetData.push_back(inv); // The message processing loop will go around again (without pausing) and we'll respond then (without cs_main) return; } @@ -3873,8 +3879,9 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP PeerRef peer = GetPeerRef(pfrom->GetId()); if (peer == nullptr) return false; - if (!pfrom->vRecvGetData.empty()) + if (!peer->vRecvGetData.empty()) { ProcessGetData(*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); + } { LOCK2(cs_main, g_cs_orphans); @@ -3888,7 +3895,7 @@ 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->vRecvGetData.empty()) return true; { LOCK(g_cs_orphans); if (!peer->m_orphan_work_set.empty()) return true; @@ -3921,7 +3928,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP ProcessMessage(*pfrom, msg_type, msg.m_recv, msg.m_time, interruptMsgProc); if (interruptMsgProc) return false; - if (!pfrom->vRecvGetData.empty()) + if (!peer->vRecvGetData.empty()) fMoreWork = true; } catch (const std::exception& e) { LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(msg_type), nMessageSize, e.what(), typeid(e).name()); From ba951812ec0cc8ebee5911a582f188525b76ff0a Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Sun, 13 Sep 2020 20:34:41 -0400 Subject: [PATCH 5/6] Guard vRecvGetData (now in net processing) with its own mutex This requires slightly reorganizing the logic in GETBLOCKTXN to maintain locking order. --- src/net_processing.cpp | 101 +++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 3b632cf20b..162d484566 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -515,8 +515,10 @@ struct Peer { /** Set of txids to reconsider once their parent transactions have been accepted **/ std::set m_orphan_work_set GUARDED_BY(g_cs_orphans); + /** Protects vRecvGetData **/ + Mutex m_getdata_requests_mutex; /** Work queue of items requested by this peer **/ - std::deque vRecvGetData; + std::deque vRecvGetData GUARDED_BY(m_getdata_requests_mutex); Peer(NodeId id) : m_id(id) {} }; @@ -1753,14 +1755,11 @@ static CTransactionRef FindTxForGetData(const CTxMemPool& mempool, const CNode& return {}; } -void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnman& connman, CTxMemPool& mempool, const std::atomic& interruptMsgProc) LOCKS_EXCLUDED(cs_main) +void static ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainparams, CConnman& connman, CTxMemPool& mempool, const std::atomic& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(!cs_main, peer.m_getdata_requests_mutex) { AssertLockNotHeld(cs_main); - PeerRef peer = GetPeerRef(pfrom.GetId()); - if (peer == nullptr) return; - - std::deque::iterator it = peer->vRecvGetData.begin(); + std::deque::iterator it = peer.vRecvGetData.begin(); std::vector vNotFound; const CNetMsgMaker msgMaker(pfrom.GetCommonVersion()); @@ -1772,7 +1771,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm // Process as many TX items from the front of the getdata queue as // possible, since they're common and it's efficient to batch process // them. - while (it != peer->vRecvGetData.end() && it->IsGenTxMsg()) { + while (it != peer.vRecvGetData.end() && it->IsGenTxMsg()) { if (interruptMsgProc) return; // The send buffer provides backpressure. If there's no space in // the buffer, pause processing until the next call. @@ -1820,7 +1819,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm // Only process one BLOCK item per call, since they're uncommon and can be // expensive to process. - if (it != peer->vRecvGetData.end() && !pfrom.fPauseSend) { + if (it != peer.vRecvGetData.end() && !pfrom.fPauseSend) { const CInv &inv = *it++; if (inv.IsGenBlkMsg()) { ProcessGetBlockData(pfrom, chainparams, inv, connman); @@ -1829,7 +1828,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm // and continue processing the queue on the next call. } - peer->vRecvGetData.erase(peer->vRecvGetData.begin(), it); + peer.vRecvGetData.erase(peer.vRecvGetData.begin(), it); if (!vNotFound.empty()) { // Let the peer know that we didn't find what it asked for, so it doesn't @@ -2811,8 +2810,12 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom.GetId()); } - peer->vRecvGetData.insert(peer->vRecvGetData.end(), vInv.begin(), vInv.end()); - ProcessGetData(pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); + { + LOCK(peer->m_getdata_requests_mutex); + peer->vRecvGetData.insert(peer->vRecvGetData.end(), vInv.begin(), vInv.end()); + ProcessGetData(pfrom, *peer, m_chainparams, m_connman, m_mempool, interruptMsgProc); + } + return; } @@ -2900,36 +2903,38 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat return; } - LOCK(cs_main); + { + LOCK(cs_main); - const CBlockIndex* pindex = LookupBlockIndex(req.blockhash); - if (!pindex || !(pindex->nStatus & BLOCK_HAVE_DATA)) { - LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block we don't have\n", pfrom.GetId()); - return; - } + const CBlockIndex* pindex = LookupBlockIndex(req.blockhash); + if (!pindex || !(pindex->nStatus & BLOCK_HAVE_DATA)) { + LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block we don't have\n", pfrom.GetId()); + return; + } - if (pindex->nHeight < ::ChainActive().Height() - MAX_BLOCKTXN_DEPTH) { - // If an older block is requested (should never happen in practice, - // but can happen in tests) send a block response instead of a - // blocktxn response. Sending a full block response instead of a - // small blocktxn response is preferable in the case where a peer - // might maliciously send lots of getblocktxn requests to trigger - // expensive disk reads, because it will require the peer to - // actually receive all the data read from disk over the network. - LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block > %i deep\n", pfrom.GetId(), MAX_BLOCKTXN_DEPTH); - CInv inv; - inv.type = State(pfrom.GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK; - inv.hash = req.blockhash; - peer->vRecvGetData.push_back(inv); - // The message processing loop will go around again (without pausing) and we'll respond then (without cs_main) - return; - } + if (pindex->nHeight >= ::ChainActive().Height() - MAX_BLOCKTXN_DEPTH) { + CBlock block; + bool ret = ReadBlockFromDisk(block, pindex, m_chainparams.GetConsensus()); + assert(ret); - CBlock block; - bool ret = ReadBlockFromDisk(block, pindex, m_chainparams.GetConsensus()); - assert(ret); + SendBlockTransactions(pfrom, block, req); + return; + } + } - SendBlockTransactions(pfrom, block, req); + // If an older block is requested (should never happen in practice, + // but can happen in tests) send a block response instead of a + // blocktxn response. Sending a full block response instead of a + // small blocktxn response is preferable in the case where a peer + // might maliciously send lots of getblocktxn requests to trigger + // expensive disk reads, because it will require the peer to + // actually receive all the data read from disk over the network. + LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block > %i deep\n", pfrom.GetId(), MAX_BLOCKTXN_DEPTH); + CInv inv; + WITH_LOCK(cs_main, inv.type = State(pfrom.GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK); + inv.hash = req.blockhash; + WITH_LOCK(peer->m_getdata_requests_mutex, peer->vRecvGetData.push_back(inv)); + // The message processing loop will go around again (without pausing) and we'll respond then return; } @@ -3879,8 +3884,11 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP PeerRef peer = GetPeerRef(pfrom->GetId()); if (peer == nullptr) return false; - if (!peer->vRecvGetData.empty()) { - ProcessGetData(*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); + { + LOCK(peer->m_getdata_requests_mutex); + if (!peer->vRecvGetData.empty()) { + ProcessGetData(*pfrom, *peer, m_chainparams, m_connman, m_mempool, interruptMsgProc); + } } { @@ -3895,7 +3903,11 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP // this maintains the order of responses // and prevents vRecvGetData to grow unbounded - if (!peer->vRecvGetData.empty()) return true; + { + LOCK(peer->m_getdata_requests_mutex); + if (!peer->vRecvGetData.empty()) return true; + } + { LOCK(g_cs_orphans); if (!peer->m_orphan_work_set.empty()) return true; @@ -3926,10 +3938,11 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP try { ProcessMessage(*pfrom, msg_type, msg.m_recv, msg.m_time, interruptMsgProc); - if (interruptMsgProc) - return false; - if (!peer->vRecvGetData.empty()) - fMoreWork = true; + if (interruptMsgProc) return false; + { + LOCK(peer->m_getdata_requests_mutex); + if (!peer->vRecvGetData.empty()) fMoreWork = true; + } } catch (const std::exception& e) { LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(msg_type), nMessageSize, e.what(), typeid(e).name()); } catch (...) { From da0988daf1d665a4644ad3f1ddf3f8a8bdd88cde Mon Sep 17 00:00:00 2001 From: Neha Narula Date: Wed, 30 Sep 2020 14:23:28 -0400 Subject: [PATCH 6/6] scripted-diff: rename vRecvGetData -BEGIN VERIFY SCRIPT- sed -i 's/vRecvGetData/m_getdata_requests/g' src/net_processing.cpp -END VERIFY SCRIPT- --- src/net_processing.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 162d484566..83bea58fe9 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -515,10 +515,10 @@ struct Peer { /** Set of txids to reconsider once their parent transactions have been accepted **/ std::set m_orphan_work_set GUARDED_BY(g_cs_orphans); - /** Protects vRecvGetData **/ + /** Protects m_getdata_requests **/ Mutex m_getdata_requests_mutex; /** Work queue of items requested by this peer **/ - std::deque vRecvGetData GUARDED_BY(m_getdata_requests_mutex); + std::deque m_getdata_requests GUARDED_BY(m_getdata_requests_mutex); Peer(NodeId id) : m_id(id) {} }; @@ -1759,7 +1759,7 @@ void static ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainpa { AssertLockNotHeld(cs_main); - std::deque::iterator it = peer.vRecvGetData.begin(); + std::deque::iterator it = peer.m_getdata_requests.begin(); std::vector vNotFound; const CNetMsgMaker msgMaker(pfrom.GetCommonVersion()); @@ -1771,7 +1771,7 @@ void static ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainpa // Process as many TX items from the front of the getdata queue as // possible, since they're common and it's efficient to batch process // them. - while (it != peer.vRecvGetData.end() && it->IsGenTxMsg()) { + while (it != peer.m_getdata_requests.end() && it->IsGenTxMsg()) { if (interruptMsgProc) return; // The send buffer provides backpressure. If there's no space in // the buffer, pause processing until the next call. @@ -1819,7 +1819,7 @@ void static ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainpa // Only process one BLOCK item per call, since they're uncommon and can be // expensive to process. - if (it != peer.vRecvGetData.end() && !pfrom.fPauseSend) { + if (it != peer.m_getdata_requests.end() && !pfrom.fPauseSend) { const CInv &inv = *it++; if (inv.IsGenBlkMsg()) { ProcessGetBlockData(pfrom, chainparams, inv, connman); @@ -1828,7 +1828,7 @@ void static ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainpa // and continue processing the queue on the next call. } - peer.vRecvGetData.erase(peer.vRecvGetData.begin(), it); + peer.m_getdata_requests.erase(peer.m_getdata_requests.begin(), it); if (!vNotFound.empty()) { // Let the peer know that we didn't find what it asked for, so it doesn't @@ -2812,7 +2812,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat { LOCK(peer->m_getdata_requests_mutex); - peer->vRecvGetData.insert(peer->vRecvGetData.end(), vInv.begin(), vInv.end()); + peer->m_getdata_requests.insert(peer->m_getdata_requests.end(), vInv.begin(), vInv.end()); ProcessGetData(pfrom, *peer, m_chainparams, m_connman, m_mempool, interruptMsgProc); } @@ -2933,7 +2933,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat CInv inv; WITH_LOCK(cs_main, inv.type = State(pfrom.GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK); inv.hash = req.blockhash; - WITH_LOCK(peer->m_getdata_requests_mutex, peer->vRecvGetData.push_back(inv)); + WITH_LOCK(peer->m_getdata_requests_mutex, peer->m_getdata_requests.push_back(inv)); // The message processing loop will go around again (without pausing) and we'll respond then return; } @@ -3886,7 +3886,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP { LOCK(peer->m_getdata_requests_mutex); - if (!peer->vRecvGetData.empty()) { + if (!peer->m_getdata_requests.empty()) { ProcessGetData(*pfrom, *peer, m_chainparams, m_connman, m_mempool, interruptMsgProc); } } @@ -3902,10 +3902,10 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP return false; // this maintains the order of responses - // and prevents vRecvGetData to grow unbounded + // and prevents m_getdata_requests to grow unbounded { LOCK(peer->m_getdata_requests_mutex); - if (!peer->vRecvGetData.empty()) return true; + if (!peer->m_getdata_requests.empty()) return true; } { @@ -3941,7 +3941,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP if (interruptMsgProc) return false; { LOCK(peer->m_getdata_requests_mutex); - if (!peer->vRecvGetData.empty()) fMoreWork = true; + if (!peer->m_getdata_requests.empty()) fMoreWork = true; } } catch (const std::exception& e) { LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(msg_type), nMessageSize, e.what(), typeid(e).name());