From c60079b59413fdd84e67e79f278eb1c7331e92e3 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 26 May 2018 21:03:49 +0300 Subject: [PATCH] ThreadOpenMasternodeConnections should process only one mn at a time (#2080) --- src/net.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 31d78519b7..b1087939b1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1950,22 +1950,30 @@ void CConnman::ThreadOpenMasternodeConnections() if (interruptNet) return; + // NOTE: Process only one pending masternode at a time + LOCK(cs_vPendingMasternodes); - std::vector::iterator it = vPendingMasternodes.begin(); - while (it != vPendingMasternodes.end()) { - if (!IsMasternodeOrDisconnectRequested(*it)) { - OpenMasternodeConnection(CAddress(*it, NODE_NETWORK)); - // should be in the list now if connection was opened - ForNode(*it, CConnman::AllNodes, [&](CNode* pnode) { - if (pnode->fDisconnect) { - return false; - } - grant.MoveTo(pnode->grantMasternodeOutbound); - return true; - }); - } - it = vPendingMasternodes.erase(it); + if (vPendingMasternodes.empty()) { + // nothing to do, keep waiting + continue; } + + const CService addr = vPendingMasternodes.front(); + vPendingMasternodes.erase(vPendingMasternodes.begin()); + if (IsMasternodeOrDisconnectRequested(addr)) { + // nothing to do, try the next one + continue; + } + + OpenMasternodeConnection(CAddress(addr, NODE_NETWORK)); + // should be in the list now if connection was opened + ForNode(addr, CConnman::AllNodes, [&](CNode* pnode) { + if (pnode->fDisconnect) { + return false; + } + grant.MoveTo(pnode->grantMasternodeOutbound); + return true; + }); } }