@@ -515,6 +515,9 @@ struct Peer {
515515 /* * Set of txids to reconsider once their parent transactions have been accepted **/
516516 std::set<uint256> m_orphan_work_set GUARDED_BY (g_cs_orphans);
517517
518+ /* * Work queue of items requested by this peer **/
519+ std::deque<CInv> vRecvGetData;
520+
518521 Peer (NodeId id) : m_id(id) {}
519522};
520523
@@ -1754,7 +1757,10 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17541757{
17551758 AssertLockNotHeld (cs_main);
17561759
1757- std::deque<CInv>::iterator it = pfrom.vRecvGetData .begin ();
1760+ PeerRef peer = GetPeerRef (pfrom.GetId ());
1761+ if (peer == nullptr ) return ;
1762+
1763+ std::deque<CInv>::iterator it = peer->vRecvGetData .begin ();
17581764 std::vector<CInv> vNotFound;
17591765 const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
17601766
@@ -1766,7 +1772,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17661772 // Process as many TX items from the front of the getdata queue as
17671773 // possible, since they're common and it's efficient to batch process
17681774 // them.
1769- while (it != pfrom. vRecvGetData .end () && it->IsGenTxMsg ()) {
1775+ while (it != peer-> vRecvGetData .end () && it->IsGenTxMsg ()) {
17701776 if (interruptMsgProc) return ;
17711777 // The send buffer provides backpressure. If there's no space in
17721778 // the buffer, pause processing until the next call.
@@ -1814,7 +1820,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
18141820
18151821 // Only process one BLOCK item per call, since they're uncommon and can be
18161822 // expensive to process.
1817- if (it != pfrom. vRecvGetData .end () && !pfrom.fPauseSend ) {
1823+ if (it != peer-> vRecvGetData .end () && !pfrom.fPauseSend ) {
18181824 const CInv &inv = *it++;
18191825 if (inv.IsGenBlkMsg ()) {
18201826 ProcessGetBlockData (pfrom, chainparams, inv, connman);
@@ -1823,7 +1829,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
18231829 // and continue processing the queue on the next call.
18241830 }
18251831
1826- pfrom. vRecvGetData .erase (pfrom. vRecvGetData .begin (), it);
1832+ peer-> vRecvGetData .erase (peer-> vRecvGetData .begin (), it);
18271833
18281834 if (!vNotFound.empty ()) {
18291835 // 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
28052811 LogPrint (BCLog::NET, " received getdata for: %s peer=%d\n " , vInv[0 ].ToString (), pfrom.GetId ());
28062812 }
28072813
2808- pfrom. vRecvGetData .insert (pfrom. vRecvGetData .end (), vInv.begin (), vInv.end ());
2814+ peer-> vRecvGetData .insert (peer-> vRecvGetData .end (), vInv.begin (), vInv.end ());
28092815 ProcessGetData (pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc);
28102816 return ;
28112817 }
@@ -2914,7 +2920,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
29142920 CInv inv;
29152921 inv.type = State (pfrom.GetId ())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK;
29162922 inv.hash = req.blockhash ;
2917- pfrom. vRecvGetData .push_back (inv);
2923+ peer-> vRecvGetData .push_back (inv);
29182924 // The message processing loop will go around again (without pausing) and we'll respond then (without cs_main)
29192925 return ;
29202926 }
@@ -3873,8 +3879,9 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
38733879 PeerRef peer = GetPeerRef (pfrom->GetId ());
38743880 if (peer == nullptr ) return false ;
38753881
3876- if (!pfrom ->vRecvGetData .empty ())
3882+ if (!peer ->vRecvGetData .empty ()) {
38773883 ProcessGetData (*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc);
3884+ }
38783885
38793886 {
38803887 LOCK2 (cs_main, g_cs_orphans);
@@ -3888,7 +3895,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
38883895
38893896 // this maintains the order of responses
38903897 // and prevents vRecvGetData to grow unbounded
3891- if (!pfrom ->vRecvGetData .empty ()) return true ;
3898+ if (!peer ->vRecvGetData .empty ()) return true ;
38923899 {
38933900 LOCK (g_cs_orphans);
38943901 if (!peer->m_orphan_work_set .empty ()) return true ;
@@ -3921,7 +3928,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
39213928 ProcessMessage (*pfrom, msg_type, msg.m_recv , msg.m_time , interruptMsgProc);
39223929 if (interruptMsgProc)
39233930 return false ;
3924- if (!pfrom ->vRecvGetData .empty ())
3931+ if (!peer ->vRecvGetData .empty ())
39253932 fMoreWork = true ;
39263933 } catch (const std::exception& e) {
39273934 LogPrint (BCLog::NET, " %s(%s, %u bytes): Exception '%s' (%s) caught\n " , __func__, SanitizeString (msg_type), nMessageSize, e.what (), typeid (e).name ());
0 commit comments