diff --git a/src/darksend.cpp b/src/darksend.cpp index db1faa890..d9bc9b58e 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -1543,9 +1543,22 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) vecMasternodesUsed.push_back(dsq.vin); + CNode* pnodeFound = NULL; + { + LOCK(cs_vNodes); + pnodeFound = FindNode(pmn->addr); + if(pnodeFound) { + if(pnodeFound->fDisconnect) { + continue; + } else { + pnodeFound->AddRef(); + } + } + } + LogPrintf("CDarksendPool::DoAutomaticDenominating -- attempt to connect to masternode from queue, addr=%s\n", pmn->addr.ToString()); // connect to Masternode and submit the queue request - CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true); + CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : ConnectNode((CAddress)pmn->addr, NULL, true); if(pnode) { pSubmittedToMasternode = pmn; nSessionDenom = dsq.nDenom; @@ -1556,6 +1569,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) strAutoDenomResult = _("Mixing in progress..."); SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTimeMillis(); + if(pnodeFound) { + pnodeFound->Release(); + } return true; } else { LogPrintf("CDarksendPool::DoAutomaticDenominating -- can't connect, addr=%s\n", pmn->addr.ToString()); @@ -1589,8 +1605,22 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) continue; } + CNode* pnodeFound = NULL; + { + LOCK(cs_vNodes); + pnodeFound = FindNode(pmn->addr); + if(pnodeFound) { + if(pnodeFound->fDisconnect) { + nTries++; + continue; + } else { + pnodeFound->AddRef(); + } + } + } + LogPrintf("CDarksendPool::DoAutomaticDenominating -- attempt %d connection to Masternode %s\n", nTries, pmn->addr.ToString()); - CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true); + CNode* pnode = (pnodeFound && pnodeFound->fMasternode) ? pnodeFound : ConnectNode((CAddress)pmn->addr, NULL, true); if(pnode) { LogPrintf("CDarksendPool::DoAutomaticDenominating -- connected, addr=%s\n", pmn->addr.ToString()); pSubmittedToMasternode = pmn; @@ -1608,6 +1638,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun) strAutoDenomResult = _("Mixing in progress..."); SetState(POOL_STATE_QUEUE); nTimeLastSuccessfulStep = GetTimeMillis(); + if(pnodeFound) { + pnodeFound->Release(); + } return true; } else { LogPrintf("CDarksendPool::DoAutomaticDenominating -- can't connect, addr=%s\n", pmn->addr.ToString());