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().
This commit is contained in:
1 parent
ecb0a3e425
commit
c58c249a5b
3 files changed
+21
No files matched your search
@@ -4902,6 +4902,12 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
|||||||
LOCK(peer->m_getdata_requests_mutex);
|
LOCK(peer->m_getdata_requests_mutex);
|
||||||
if (!peer->m_getdata_requests.empty()) fMoreWork = true;
|
if (!peer->m_getdata_requests.empty()) fMoreWork = true;
|
||||||
}
|
}
|
||||||
|
// Does this peer has an orphan ready to reconsider?
|
||||||
|
// (Note: we may have provided a parent for an orphan provided
|
||||||
|
// by another peer that was already processed; in that case,
|
||||||
|
// the extra work may not be noticed, possibly resulting in an
|
||||||
|
// unnecessary 100ms delay)
|
||||||
|
if (m_orphanage.HaveTxToReconsider(peer->m_id)) fMoreWork = true;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
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());
|
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());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|||||||
@@ -194,6 +194,18 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TxOrphanage::HaveTxToReconsider(NodeId peer)
|
||||||
|
{
|
||||||
|
LOCK(m_mutex);
|
||||||
|
|
||||||
|
auto work_set_it = m_peer_work_set.find(peer);
|
||||||
|
if (work_set_it != m_peer_work_set.end()) {
|
||||||
|
auto& work_set = work_set_it->second;
|
||||||
|
return !work_set.empty();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void TxOrphanage::EraseForBlock(const CBlock& block)
|
void TxOrphanage::EraseForBlock(const CBlock& block)
|
||||||
{
|
{
|
||||||
LOCK(m_mutex);
|
LOCK(m_mutex);
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ public:
|
|||||||
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
|
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
|
||||||
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
|
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
|
||||||
|
|
||||||
|
/** Does this peer have any work to do? */
|
||||||
|
bool HaveTxToReconsider(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
|
||||||
|
|
||||||
/** Return how many entries exist in the orphange */
|
/** Return how many entries exist in the orphange */
|
||||||
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user