From a8e7133c65c65f61fae792c299cec8230a8236a8 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Wed, 1 Jan 2020 15:13:14 +0100 Subject: [PATCH] Don't disconnect masternode connections when we have less then the desired amount of outbound nodes (#3255) --- src/masternode/masternode-utils.cpp | 11 +++++++++++ src/net.cpp | 5 +++++ src/net.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/masternode/masternode-utils.cpp b/src/masternode/masternode-utils.cpp index e72d730b40..1c10385eda 100644 --- a/src/masternode/masternode-utils.cpp +++ b/src/masternode/masternode-utils.cpp @@ -27,6 +27,17 @@ void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman) privateSendClient.GetMixingMasternodesInfo(vecDmns); #endif // ENABLE_WALLET + // Don't disconnect masternode connections when we have less then the desired amount of outbound nodes + int nonMasternodeCount = 0; + connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) { + if (!pnode->fInbound && !pnode->fFeeler && !pnode->m_manual_connection && !pnode->fMasternode) { + nonMasternodeCount++; + } + }); + if (nonMasternodeCount < connman.GetMaxOutboundNodeCount()) { + return; + } + connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) { if (pnode->fMasternode && !connman.IsMasternodeQuorumNode(pnode)) { #ifdef ENABLE_WALLET diff --git a/src/net.cpp b/src/net.cpp index 03aee76255..9e82a2a455 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2924,6 +2924,11 @@ size_t CConnman::GetNodeCount(NumConnections flags) return nNum; } +size_t CConnman::GetMaxOutboundNodeCount() +{ + return nMaxOutbound; +} + void CConnman::GetNodeStats(std::vector& vstats) { vstats.clear(); diff --git a/src/net.h b/src/net.h index 3a405d0f77..f4d6879034 100644 --- a/src/net.h +++ b/src/net.h @@ -407,6 +407,7 @@ public: bool IsMasternodeQuorumNode(const CNode* pnode); size_t GetNodeCount(NumConnections num); + size_t GetMaxOutboundNodeCount(); void GetNodeStats(std::vector& vstats); bool DisconnectNode(const std::string& node); bool DisconnectNode(NodeId id);