Skip to content

Commit 6f8e442

Browse files
committed
net_processing: Localise orphan_work_set handling to ProcessOrphanTx
1 parent 0027174 commit 6f8e442

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/net_processing.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,9 @@ class PeerManagerImpl final : public PeerManager
596596
* orphan will be reconsidered on each call of this function. This set
597597
* may be added to if accepting an orphan causes its children to be
598598
* reconsidered.
599+
* @return True if there are still orphans in this peer's work set.
599600
*/
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)
601602
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex);
602603
/** Process a single headers message from a peer.
603604
*
@@ -2883,12 +2884,14 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
28832884
return;
28842885
}
28852886

2886-
void PeerManagerImpl::ProcessOrphanTx(Peer& peer)
2887+
bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
28872888
{
28882889
AssertLockHeld(g_msgproc_mutex);
28892890
AssertLockHeld(cs_main);
28902891
AssertLockHeld(g_cs_orphans);
28912892

2893+
if (peer.m_orphan_work_set.empty()) return false;
2894+
28922895
while (!peer.m_orphan_work_set.empty()) {
28932896
const uint256 orphanHash = *peer.m_orphan_work_set.begin();
28942897
peer.m_orphan_work_set.erase(peer.m_orphan_work_set.begin());
@@ -2953,6 +2956,8 @@ void PeerManagerImpl::ProcessOrphanTx(Peer& peer)
29532956
break;
29542957
}
29552958
}
2959+
2960+
return !peer.m_orphan_work_set.empty();
29562961
}
29572962

29582963
bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
@@ -4768,28 +4773,24 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
47684773
}
47694774
}
47704775

4776+
bool has_more_orphans;
47714777
{
47724778
LOCK2(cs_main, g_cs_orphans);
4773-
if (!peer->m_orphan_work_set.empty()) {
4774-
ProcessOrphanTx(*peer);
4775-
}
4779+
has_more_orphans = ProcessOrphanTx(*peer);
47764780
}
47774781

47784782
if (pfrom->fDisconnect)
47794783
return false;
47804784

4785+
if (has_more_orphans) return true;
4786+
47814787
// this maintains the order of responses
47824788
// and prevents m_getdata_requests to grow unbounded
47834789
{
47844790
LOCK(peer->m_getdata_requests_mutex);
47854791
if (!peer->m_getdata_requests.empty()) return true;
47864792
}
47874793

4788-
{
4789-
LOCK(g_cs_orphans);
4790-
if (!peer->m_orphan_work_set.empty()) return true;
4791-
}
4792-
47934794
// Don't bother if send buffer is too full to respond anyway
47944795
if (pfrom->fPauseSend) return false;
47954796

0 commit comments

Comments
 (0)