Fix ThreadOpenMasternodeConnections to not drop pending MN connections

The way it was implemented caused vPendingMasternodes entries to be popped
but not necessarily connected to when at the same time quorum connections
were pending.
This commit is contained in:
Alexander Block 2020-03-17 08:36:45 +01:00
parent 0fa2e14065
commit 0adef2cf7a

View File

@ -2130,6 +2130,15 @@ void CConnman::ThreadOpenMasternodeConnections()
{ // don't hold lock while calling OpenMasternodeConnection as cs_main is locked deep inside { // don't hold lock while calling OpenMasternodeConnection as cs_main is locked deep inside
LOCK2(cs_vNodes, cs_vPendingMasternodes); LOCK2(cs_vNodes, cs_vPendingMasternodes);
if (!vPendingMasternodes.empty()) {
auto addr2 = vPendingMasternodes.front();
vPendingMasternodes.erase(vPendingMasternodes.begin());
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2)) {
addr = addr2;
}
}
if (addr == CService()) {
std::vector<CService> pending; std::vector<CService> pending;
for (const auto& group : masternodeQuorumNodes) { for (const auto& group : masternodeQuorumNodes) {
for (const auto& proRegTxHash : group.second) { for (const auto& proRegTxHash : group.second) {
@ -2149,23 +2158,16 @@ void CConnman::ThreadOpenMasternodeConnections()
} }
} }
if (!vPendingMasternodes.empty()) { if (!pending.empty()) {
auto addr2 = vPendingMasternodes.front(); addr = pending[GetRandInt(pending.size())];
vPendingMasternodes.erase(vPendingMasternodes.begin()); }
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2)) {
pending.emplace_back(addr2);
} }
} }
if (pending.empty()) { if (addr == CService()) {
// nothing to do, keep waiting
continue; continue;
} }
std::random_shuffle(pending.begin(), pending.end());
addr = pending.front();
}
OpenMasternodeConnection(CAddress(addr, NODE_NETWORK)); OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
// should be in the list now if connection was opened // should be in the list now if connection was opened
ForNode(addr, CConnman::AllNodes, [&](CNode* pnode) { ForNode(addr, CConnman::AllNodes, [&](CNode* pnode) {