@@ -515,6 +515,9 @@ struct Peer {
515
515
/* * Set of txids to reconsider once their parent transactions have been accepted **/
516
516
std::set<uint256> m_orphan_work_set GUARDED_BY (g_cs_orphans);
517
517
518
+ /* * Work queue of items requested by this peer **/
519
+ std::deque<CInv> vRecvGetData;
520
+
518
521
Peer (NodeId id) : m_id(id) {}
519
522
};
520
523
@@ -1754,7 +1757,10 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1754
1757
{
1755
1758
AssertLockNotHeld (cs_main);
1756
1759
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 ();
1758
1764
std::vector<CInv> vNotFound;
1759
1765
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1760
1766
@@ -1766,7 +1772,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1766
1772
// Process as many TX items from the front of the getdata queue as
1767
1773
// possible, since they're common and it's efficient to batch process
1768
1774
// them.
1769
- while (it != pfrom. vRecvGetData .end () && it->IsGenTxMsg ()) {
1775
+ while (it != peer-> vRecvGetData .end () && it->IsGenTxMsg ()) {
1770
1776
if (interruptMsgProc) return ;
1771
1777
// The send buffer provides backpressure. If there's no space in
1772
1778
// the buffer, pause processing until the next call.
@@ -1814,7 +1820,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1814
1820
1815
1821
// Only process one BLOCK item per call, since they're uncommon and can be
1816
1822
// expensive to process.
1817
- if (it != pfrom. vRecvGetData .end () && !pfrom.fPauseSend ) {
1823
+ if (it != peer-> vRecvGetData .end () && !pfrom.fPauseSend ) {
1818
1824
const CInv &inv = *it++;
1819
1825
if (inv.IsGenBlkMsg ()) {
1820
1826
ProcessGetBlockData (pfrom, chainparams, inv, connman);
@@ -1823,7 +1829,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1823
1829
// and continue processing the queue on the next call.
1824
1830
}
1825
1831
1826
- pfrom. vRecvGetData .erase (pfrom. vRecvGetData .begin (), it);
1832
+ peer-> vRecvGetData .erase (peer-> vRecvGetData .begin (), it);
1827
1833
1828
1834
if (!vNotFound.empty ()) {
1829
1835
// 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
2805
2811
LogPrint (BCLog::NET, " received getdata for: %s peer=%d\n " , vInv[0 ].ToString (), pfrom.GetId ());
2806
2812
}
2807
2813
2808
- pfrom. vRecvGetData .insert (pfrom. vRecvGetData .end (), vInv.begin (), vInv.end ());
2814
+ peer-> vRecvGetData .insert (peer-> vRecvGetData .end (), vInv.begin (), vInv.end ());
2809
2815
ProcessGetData (pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc);
2810
2816
return ;
2811
2817
}
@@ -2914,7 +2920,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2914
2920
CInv inv;
2915
2921
inv.type = State (pfrom.GetId ())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK;
2916
2922
inv.hash = req.blockhash ;
2917
- pfrom. vRecvGetData .push_back (inv);
2923
+ peer-> vRecvGetData .push_back (inv);
2918
2924
// The message processing loop will go around again (without pausing) and we'll respond then (without cs_main)
2919
2925
return ;
2920
2926
}
@@ -3873,8 +3879,9 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
3873
3879
PeerRef peer = GetPeerRef (pfrom->GetId ());
3874
3880
if (peer == nullptr ) return false ;
3875
3881
3876
- if (!pfrom ->vRecvGetData .empty ())
3882
+ if (!peer ->vRecvGetData .empty ()) {
3877
3883
ProcessGetData (*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc);
3884
+ }
3878
3885
3879
3886
{
3880
3887
LOCK2 (cs_main, g_cs_orphans);
@@ -3888,7 +3895,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
3888
3895
3889
3896
// this maintains the order of responses
3890
3897
// and prevents vRecvGetData to grow unbounded
3891
- if (!pfrom ->vRecvGetData .empty ()) return true ;
3898
+ if (!peer ->vRecvGetData .empty ()) return true ;
3892
3899
{
3893
3900
LOCK (g_cs_orphans);
3894
3901
if (!peer->m_orphan_work_set .empty ()) return true ;
@@ -3921,7 +3928,7 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgP
3921
3928
ProcessMessage (*pfrom, msg_type, msg.m_recv , msg.m_time , interruptMsgProc);
3922
3929
if (interruptMsgProc)
3923
3930
return false ;
3924
- if (!pfrom ->vRecvGetData .empty ())
3931
+ if (!peer ->vRecvGetData .empty ())
3925
3932
fMoreWork = true ;
3926
3933
} catch (const std::exception& e) {
3927
3934
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