From 35d75b19e6235460d7f3ab18acf082f6dde47066 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 19 Mar 2020 14:21:02 +0100 Subject: [PATCH] Make pending masternode queue proTxHash based Instead of CService --- src/net.cpp | 31 +++++++++++++------------- src/net.h | 4 ++-- src/privatesend/privatesend-client.cpp | 4 ++-- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 59565ba5ca..3b08781408 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2126,20 +2126,20 @@ void CConnman::ThreadOpenMasternodeConnections() // NOTE: Process only one pending masternode at a time - CService addr; + CDeterministicMNCPtr connectToDmn; { // don't hold lock while calling OpenMasternodeConnection as cs_main is locked deep inside LOCK2(cs_vNodes, cs_vPendingMasternodes); if (!vPendingMasternodes.empty()) { - auto addr2 = vPendingMasternodes.front(); + auto dmn = mnList.GetValidMN(vPendingMasternodes.front()); vPendingMasternodes.erase(vPendingMasternodes.begin()); - if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2)) { - addr = addr2; + if (dmn && !connectedNodes.count(dmn->pdmnState->addr) && !IsMasternodeOrDisconnectRequested(dmn->pdmnState->addr)) { + connectToDmn = dmn; } } - if (addr == CService()) { - std::vector pending; + if (!connectToDmn) { + std::vector pending; for (const auto& group : masternodeQuorumNodes) { for (const auto& proRegTxHash : group.second) { auto dmn = mnList.GetMN(proRegTxHash); @@ -2153,24 +2153,24 @@ void CConnman::ThreadOpenMasternodeConnections() if (addrInfo.IsValid() && nANow - addrInfo.nLastTry < 60) { continue; } - pending.emplace_back(addr2); + pending.emplace_back(dmn); } } } if (!pending.empty()) { - addr = pending[GetRandInt(pending.size())]; + connectToDmn = pending[GetRandInt(pending.size())]; } } } - if (addr == CService()) { + if (!connectToDmn) { continue; } - OpenMasternodeConnection(CAddress(addr, NODE_NETWORK)); + OpenMasternodeConnection(CAddress(connectToDmn->pdmnState->addr, NODE_NETWORK)); // should be in the list now if connection was opened - ForNode(addr, CConnman::AllNodes, [&](CNode* pnode) { + ForNode(connectToDmn->pdmnState->addr, CConnman::AllNodes, [&](CNode* pnode) { if (pnode->fDisconnect) { return false; } @@ -2782,15 +2782,14 @@ bool CConnman::RemoveAddedNode(const std::string& strNode) return false; } -bool CConnman::AddPendingMasternode(const CService& service) +bool CConnman::AddPendingMasternode(const uint256& proTxHash) { LOCK(cs_vPendingMasternodes); - for(const auto& s : vPendingMasternodes) { - if (service == s) - return false; + if (std::find(vPendingMasternodes.begin(), vPendingMasternodes.end(), proTxHash) != vPendingMasternodes.end()) { + return false; } - vPendingMasternodes.push_back(service); + vPendingMasternodes.push_back(proTxHash); return true; } diff --git a/src/net.h b/src/net.h index 5e05078589..b7b35a7ffb 100644 --- a/src/net.h +++ b/src/net.h @@ -407,7 +407,7 @@ public: bool RemoveAddedNode(const std::string& node); std::vector GetAddedNodeInfo(); - bool AddPendingMasternode(const CService& addr); + bool AddPendingMasternode(const uint256& proTxHash); bool AddMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash, const std::set& proTxHashes); bool HasMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash); std::set GetMasternodeQuorums(Consensus::LLMQType llmqType); @@ -543,7 +543,7 @@ private: CCriticalSection cs_vOneShots; std::vector vAddedNodes GUARDED_BY(cs_vAddedNodes); CCriticalSection cs_vAddedNodes; - std::vector vPendingMasternodes; + std::vector vPendingMasternodes; std::map, std::set> masternodeQuorumNodes; // protected by cs_vPendingMasternodes mutable CCriticalSection cs_vPendingMasternodes; std::vector vNodes; diff --git a/src/privatesend/privatesend-client.cpp b/src/privatesend/privatesend-client.cpp index fa38003257..5356e3196a 100644 --- a/src/privatesend/privatesend-client.cpp +++ b/src/privatesend/privatesend-client.cpp @@ -1081,7 +1081,7 @@ bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymize nSessionDenom = dsq.nDenom; mixingMasternode = dmn; pendingDsaRequest = CPendingDsaRequest(dmn->pdmnState->addr, CPrivateSendAccept(nSessionDenom, txMyCollateral)); - connman.AddPendingMasternode(dmn->pdmnState->addr); + connman.AddPendingMasternode(dmn->proTxHash); // TODO: add new state POOL_STATE_CONNECTING and bump MIN_PRIVATESEND_PEER_PROTO_VERSION SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTime(); @@ -1158,7 +1158,7 @@ bool CPrivateSendClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, C } mixingMasternode = dmn; - connman.AddPendingMasternode(dmn->pdmnState->addr); + connman.AddPendingMasternode(dmn->proTxHash); pendingDsaRequest = CPendingDsaRequest(dmn->pdmnState->addr, CPrivateSendAccept(nSessionDenom, txMyCollateral)); // TODO: add new state POOL_STATE_CONNECTING and bump MIN_PRIVATESEND_PEER_PROTO_VERSION SetState(POOL_STATE_QUEUE);