mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
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:
parent
0fa2e14065
commit
0adef2cf7a
54
src/net.cpp
54
src/net.cpp
@ -2130,40 +2130,42 @@ 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);
|
||||||
|
|
||||||
std::vector<CService> pending;
|
|
||||||
for (const auto& group : masternodeQuorumNodes) {
|
|
||||||
for (const auto& proRegTxHash : group.second) {
|
|
||||||
auto dmn = mnList.GetMN(proRegTxHash);
|
|
||||||
if (!dmn) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto& addr2 = dmn->pdmnState->addr;
|
|
||||||
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
|
|
||||||
auto addrInfo = addrman.GetAddressInfo(addr2);
|
|
||||||
// back off trying connecting to an address if we already tried recently
|
|
||||||
if (addrInfo.IsValid() && nANow - addrInfo.nLastTry < 60) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
pending.emplace_back(addr2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vPendingMasternodes.empty()) {
|
if (!vPendingMasternodes.empty()) {
|
||||||
auto addr2 = vPendingMasternodes.front();
|
auto addr2 = vPendingMasternodes.front();
|
||||||
vPendingMasternodes.erase(vPendingMasternodes.begin());
|
vPendingMasternodes.erase(vPendingMasternodes.begin());
|
||||||
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2)) {
|
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2)) {
|
||||||
pending.emplace_back(addr2);
|
addr = addr2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pending.empty()) {
|
if (addr == CService()) {
|
||||||
// nothing to do, keep waiting
|
std::vector<CService> pending;
|
||||||
continue;
|
for (const auto& group : masternodeQuorumNodes) {
|
||||||
}
|
for (const auto& proRegTxHash : group.second) {
|
||||||
|
auto dmn = mnList.GetMN(proRegTxHash);
|
||||||
|
if (!dmn) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto& addr2 = dmn->pdmnState->addr;
|
||||||
|
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
|
||||||
|
auto addrInfo = addrman.GetAddressInfo(addr2);
|
||||||
|
// back off trying connecting to an address if we already tried recently
|
||||||
|
if (addrInfo.IsValid() && nANow - addrInfo.nLastTry < 60) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pending.emplace_back(addr2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::random_shuffle(pending.begin(), pending.end());
|
if (!pending.empty()) {
|
||||||
addr = pending.front();
|
addr = pending[GetRandInt(pending.size())];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr == CService()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
|
OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
|
||||||
|
Loading…
Reference in New Issue
Block a user