From d261575b4f69a9e723f623ad0afcaaba2f1ad2c3 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 9 Jan 2018 12:17:54 +0300 Subject: [PATCH] Skip existing masternode conections on mixing (#1833) --- src/privatesend-client.cpp | 41 ++++++++++++-------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/privatesend-client.cpp b/src/privatesend-client.cpp index f044a310a1..a629c53161 100644 --- a/src/privatesend-client.cpp +++ b/src/privatesend-client.cpp @@ -873,23 +873,19 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon vecMasternodesUsed.push_back(dsq.vin.prevout); - CNode* pnodeFound = NULL; - bool fDisconnect = false; - connman.ForNode(infoMn.addr, CConnman::AllNodes, [&pnodeFound, &fDisconnect](CNode* pnode) { - pnodeFound = pnode; - if(pnodeFound->fDisconnect) { - fDisconnect = true; - } else { - pnodeFound->AddRef(); - } + bool fSkip = false; + connman.ForNode(infoMn.addr, CConnman::AllNodes, [&fSkip](CNode* pnode) { + fSkip = pnode->fDisconnect || pnode->fMasternode; return true; }); - if (fDisconnect) + if (fSkip) { + LogPrintf("CPrivateSendClient::JoinExistingQueue -- skipping masternode connection, addr=%s\n", infoMn.addr.ToString()); continue; + } LogPrintf("CPrivateSendClient::JoinExistingQueue -- attempt to connect to masternode from queue, addr=%s\n", infoMn.addr.ToString()); // connect to Masternode and submit the queue request - CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, true); + CNode* pnode = connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, true); if(pnode) { infoMixingMasternode = infoMn; nSessionDenom = dsq.nDenom; @@ -900,9 +896,6 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon strAutoDenomResult = _("Mixing in progress..."); SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTimeMillis(); - if(pnodeFound) { - pnodeFound->Release(); - } return true; } else { LogPrintf("CPrivateSendClient::JoinExistingQueue -- can't connect, addr=%s\n", infoMn.addr.ToString()); @@ -947,24 +940,19 @@ bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsA continue; } - CNode* pnodeFound = NULL; - bool fDisconnect = false; - connman.ForNode(infoMn.addr, CConnman::AllNodes, [&pnodeFound, &fDisconnect](CNode* pnode) { - pnodeFound = pnode; - if(pnodeFound->fDisconnect) { - fDisconnect = true; - } else { - pnodeFound->AddRef(); - } + bool fSkip = false; + connman.ForNode(infoMn.addr, CConnman::AllNodes, [&fSkip](CNode* pnode) { + fSkip = pnode->fDisconnect || pnode->fMasternode; return true; }); - if (fDisconnect) { + if (fSkip) { + LogPrintf("CPrivateSendClient::StartNewQueue -- skipping masternode connection, addr=%s\n", infoMn.addr.ToString()); nTries++; continue; } LogPrintf("CPrivateSendClient::StartNewQueue -- attempt %d connection to Masternode %s\n", nTries, infoMn.addr.ToString()); - CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, true); + CNode* pnode = connman.ConnectNode(CAddress(infoMn.addr, NODE_NETWORK), NULL, true); if(pnode) { LogPrintf("CPrivateSendClient::StartNewQueue -- connected, addr=%s\n", infoMn.addr.ToString()); infoMixingMasternode = infoMn; @@ -982,9 +970,6 @@ bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsA strAutoDenomResult = _("Mixing in progress..."); SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTimeMillis(); - if(pnodeFound) { - pnodeFound->Release(); - } return true; } else { LogPrintf("CPrivateSendClient::StartNewQueue -- can't connect, addr=%s\n", infoMn.addr.ToString());