Skip to content

Commit c58c249

Browse files
committed
net_processing: indicate more work to do when orphans are ready to reconsider
When PR#15644 made orphan processing interruptible, it also introduced a potential 100ms delay between processing of the first and second newly reconsiderable orphan, because it didn't check if the orphan work set was non-empty after invoking ProcessMessage(). This adds that check, so that ProcessMessages() will return true if there are orphans to process, usually avoiding the 100ms delay in CConnman::ThreadMessageHandler().
1 parent ecb0a3e commit c58c249

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/net_processing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4902,6 +4902,12 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
49024902
LOCK(peer->m_getdata_requests_mutex);
49034903
if (!peer->m_getdata_requests.empty()) fMoreWork = true;
49044904
}
4905+
// Does this peer has an orphan ready to reconsider?
4906+
// (Note: we may have provided a parent for an orphan provided
4907+
// by another peer that was already processed; in that case,
4908+
// the extra work may not be noticed, possibly resulting in an
4909+
// unnecessary 100ms delay)
4910+
if (m_orphanage.HaveTxToReconsider(peer->m_id)) fMoreWork = true;
49054911
} catch (const std::exception& e) {
49064912
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(msg.m_type), msg.m_message_size, e.what(), typeid(e).name());
49074913
} catch (...) {

src/txorphanage.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
194194
return nullptr;
195195
}
196196

197+
bool TxOrphanage::HaveTxToReconsider(NodeId peer)
198+
{
199+
LOCK(m_mutex);
200+
201+
auto work_set_it = m_peer_work_set.find(peer);
202+
if (work_set_it != m_peer_work_set.end()) {
203+
auto& work_set = work_set_it->second;
204+
return !work_set.empty();
205+
}
206+
return false;
207+
}
208+
197209
void TxOrphanage::EraseForBlock(const CBlock& block)
198210
{
199211
LOCK(m_mutex);

src/txorphanage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class TxOrphanage {
4848
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
4949
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
5050

51+
/** Does this peer have any work to do? */
52+
bool HaveTxToReconsider(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
53+
5154
/** Return how many entries exist in the orphange */
5255
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
5356
{

0 commit comments

Comments
 (0)