diff --git a/src/net.cpp b/src/net.cpp index 0158f61f6c..4fe2ec2752 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2436,11 +2436,20 @@ void CConnman::OpenMasternodeConnection(const CAddress &addrConnect, bool probe) void CConnman::ThreadMessageHandler() { + int64_t nLastForceSendMessages = 0; + while (!flagInterruptMsgProc) { std::vector vNodesCopy = CopyNodeVector(); + int64_t nNow = GetTimeMillis(); + bool fMoreWork = false; + bool fForceSendMessages = false; + if (nNow - nLastForceSendMessages >= 100) { + fForceSendMessages = true; + nLastForceSendMessages = nNow; + } for (CNode* pnode : vNodesCopy) { @@ -2448,12 +2457,13 @@ void CConnman::ThreadMessageHandler() continue; // Receive messages - bool fMoreNodeWork = m_msgproc->ProcessMessages(pnode, flagInterruptMsgProc); + bool fDidWork = false; + bool fMoreNodeWork = m_msgproc->ProcessMessages(pnode, flagInterruptMsgProc, fDidWork); fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend); if (flagInterruptMsgProc) return; // Send messages - { + if (fDidWork || fForceSendMessages) { LOCK(pnode->cs_sendProcessing); m_msgproc->SendMessages(pnode, flagInterruptMsgProc); } diff --git a/src/net.h b/src/net.h index 38863f94c1..de30147b56 100644 --- a/src/net.h +++ b/src/net.h @@ -633,7 +633,7 @@ struct CombinerAll class NetEventsInterface { public: - virtual bool ProcessMessages(CNode* pnode, std::atomic& interrupt) = 0; + virtual bool ProcessMessages(CNode* pnode, std::atomic& interrupt, bool &fRetDidWork) = 0; virtual bool SendMessages(CNode* pnode, std::atomic& interrupt) = 0; virtual void InitializeNode(CNode* pnode) = 0; virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d17ec13310..a0e446f924 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3529,7 +3529,7 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman) return false; } -bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgProc) +bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgProc, bool &fRetDidWork) { const CChainParams& chainparams = Params(); // @@ -3541,13 +3541,17 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& inter // (x) data // bool fMoreWork = false; + fRetDidWork = false; - if (!pfrom->vRecvGetData.empty()) + if (!pfrom->vRecvGetData.empty()) { ProcessGetData(pfrom, chainparams.GetConsensus(), connman, interruptMsgProc); + fRetDidWork = true; + } if (!pfrom->orphan_work_set.empty()) { LOCK2(cs_main, g_cs_orphans); ProcessOrphanTx(connman, pfrom->orphan_work_set); + fRetDidWork = true; } if (pfrom->fDisconnect) @@ -3571,6 +3575,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic& inter pfrom->nProcessQueueSize -= msgs.front().vRecv.size() + CMessageHeader::HEADER_SIZE; pfrom->fPauseRecv = pfrom->nProcessQueueSize > connman->GetReceiveFloodSize(); fMoreWork = !pfrom->vProcessMsg.empty(); + fRetDidWork = true; } CNetMessage& msg(msgs.front()); diff --git a/src/net_processing.h b/src/net_processing.h index 1c070160a3..1688158e1b 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -53,7 +53,7 @@ public: void InitializeNode(CNode* pnode) override; void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override; /** Process protocol messages received from a given node */ - bool ProcessMessages(CNode* pfrom, std::atomic& interrupt) override; + bool ProcessMessages(CNode* pfrom, std::atomic& interrupt, bool &fRetDidWork) override; /** * Send queued protocol messages to be sent to a give node. *