From 96faa8155e261b5468248f6652bc608956863dcf Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Tue, 21 Apr 2020 16:44:18 +0200 Subject: [PATCH] Don't disconnect masternode probes for a few seconds (#3449) * Refactor CMasternodeUtils::ProcessMasternodeConnections to be more readable * Don't disconnect masternode probes for a few seconds --- src/masternode/masternode-utils.cpp | 37 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/masternode/masternode-utils.cpp b/src/masternode/masternode-utils.cpp index 42221556df..ae3ae41c9d 100644 --- a/src/masternode/masternode-utils.cpp +++ b/src/masternode/masternode-utils.cpp @@ -39,24 +39,31 @@ void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman) } connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) { - if (!pnode->fInbound && pnode->fMasternode && !connman.IsMasternodeQuorumNode(pnode)) { + // we're only disconnecting fMasternode connections + if (!pnode->fMasternode) return; + // we're only disconnecting outbound connections + if (pnode->fInbound) return; + // we're not disconnecting LLMQ connections + if (connman.IsMasternodeQuorumNode(pnode)) return; + // we're not disconnecting masternode probes for at least a few seconds + if (pnode->fMasternodeProbe && GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) return; + #ifdef ENABLE_WALLET - bool fFound = false; - for (const auto& dmn : vecDmns) { - if (pnode->addr == dmn->pdmnState->addr) { - fFound = true; - break; - } + bool fFound = false; + for (const auto& dmn : vecDmns) { + if (pnode->addr == dmn->pdmnState->addr) { + fFound = true; + break; } - if (fFound) return; // do NOT disconnect mixing masternodes -#endif // ENABLE_WALLET - if (fLogIPs) { - LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString()); - } else { - LogPrintf("Closing Masternode connection: peer=%d\n", pnode->GetId()); - } - pnode->fDisconnect = true; } + if (fFound) return; // do NOT disconnect mixing masternodes +#endif // ENABLE_WALLET + if (fLogIPs) { + LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString()); + } else { + LogPrintf("Closing Masternode connection: peer=%d\n", pnode->GetId()); + } + pnode->fDisconnect = true; }); }