@@ -596,8 +596,9 @@ class PeerManagerImpl final : public PeerManager
596
596
* orphan will be reconsidered on each call of this function. This set
597
597
* may be added to if accepting an orphan causes its children to be
598
598
* reconsidered.
599
+ * @return True if there are still orphans in this peer's work set.
599
600
*/
600
- void ProcessOrphanTx (Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans)
601
+ bool ProcessOrphanTx (Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans)
601
602
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex);
602
603
/* * Process a single headers message from a peer.
603
604
*
@@ -2883,12 +2884,14 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
2883
2884
return ;
2884
2885
}
2885
2886
2886
- void PeerManagerImpl::ProcessOrphanTx (Peer& peer)
2887
+ bool PeerManagerImpl::ProcessOrphanTx (Peer& peer)
2887
2888
{
2888
2889
AssertLockHeld (g_msgproc_mutex);
2889
2890
AssertLockHeld (cs_main);
2890
2891
AssertLockHeld (g_cs_orphans);
2891
2892
2893
+ if (peer.m_orphan_work_set .empty ()) return false ;
2894
+
2892
2895
while (!peer.m_orphan_work_set .empty ()) {
2893
2896
const uint256 orphanHash = *peer.m_orphan_work_set .begin ();
2894
2897
peer.m_orphan_work_set .erase (peer.m_orphan_work_set .begin ());
@@ -2953,6 +2956,8 @@ void PeerManagerImpl::ProcessOrphanTx(Peer& peer)
2953
2956
break ;
2954
2957
}
2955
2958
}
2959
+
2960
+ return !peer.m_orphan_work_set .empty ();
2956
2961
}
2957
2962
2958
2963
bool PeerManagerImpl::PrepareBlockFilterRequest (CNode& node, Peer& peer,
@@ -4768,28 +4773,24 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
4768
4773
}
4769
4774
}
4770
4775
4776
+ bool has_more_orphans;
4771
4777
{
4772
4778
LOCK2 (cs_main, g_cs_orphans);
4773
- if (!peer->m_orphan_work_set .empty ()) {
4774
- ProcessOrphanTx (*peer);
4775
- }
4779
+ has_more_orphans = ProcessOrphanTx (*peer);
4776
4780
}
4777
4781
4778
4782
if (pfrom->fDisconnect )
4779
4783
return false ;
4780
4784
4785
+ if (has_more_orphans) return true ;
4786
+
4781
4787
// this maintains the order of responses
4782
4788
// and prevents m_getdata_requests to grow unbounded
4783
4789
{
4784
4790
LOCK (peer->m_getdata_requests_mutex );
4785
4791
if (!peer->m_getdata_requests .empty ()) return true ;
4786
4792
}
4787
4793
4788
- {
4789
- LOCK (g_cs_orphans);
4790
- if (!peer->m_orphan_work_set .empty ()) return true ;
4791
- }
4792
-
4793
4794
// Don't bother if send buffer is too full to respond anyway
4794
4795
if (pfrom->fPauseSend ) return false ;
4795
4796
0 commit comments