Fix crash on initial mixing step: (#1331)

* Fix crash on initial mixing step:
- skip nodes marked to be disconnected
- add/release ref to make sure pnode is not deleted in the middle of the process

* - fix copy/paste mistake (nTries)
- let ConnectNode manage ref for non-mn pnodeFound
This commit is contained in:
UdjinM6 2017-02-11 06:57:09 +04:00 committed by Holger Schinzel
parent 817fd9c860
commit f08ae49904

View File

@ -1543,9 +1543,22 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun)
vecMasternodesUsed.push_back(dsq.vin); 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()); LogPrintf("CDarksendPool::DoAutomaticDenominating -- attempt to connect to masternode from queue, addr=%s\n", pmn->addr.ToString());
// connect to Masternode and submit the queue request // 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) { if(pnode) {
pSubmittedToMasternode = pmn; pSubmittedToMasternode = pmn;
nSessionDenom = dsq.nDenom; nSessionDenom = dsq.nDenom;
@ -1556,6 +1569,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun)
strAutoDenomResult = _("Mixing in progress..."); strAutoDenomResult = _("Mixing in progress...");
SetState(POOL_STATE_QUEUE); SetState(POOL_STATE_QUEUE);
nTimeLastSuccessfulStep = GetTimeMillis(); nTimeLastSuccessfulStep = GetTimeMillis();
if(pnodeFound) {
pnodeFound->Release();
}
return true; return true;
} else { } else {
LogPrintf("CDarksendPool::DoAutomaticDenominating -- can't connect, addr=%s\n", pmn->addr.ToString()); LogPrintf("CDarksendPool::DoAutomaticDenominating -- can't connect, addr=%s\n", pmn->addr.ToString());
@ -1589,8 +1605,22 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun)
continue; 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()); 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) { if(pnode) {
LogPrintf("CDarksendPool::DoAutomaticDenominating -- connected, addr=%s\n", pmn->addr.ToString()); LogPrintf("CDarksendPool::DoAutomaticDenominating -- connected, addr=%s\n", pmn->addr.ToString());
pSubmittedToMasternode = pmn; pSubmittedToMasternode = pmn;
@ -1608,6 +1638,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun)
strAutoDenomResult = _("Mixing in progress..."); strAutoDenomResult = _("Mixing in progress...");
SetState(POOL_STATE_QUEUE); SetState(POOL_STATE_QUEUE);
nTimeLastSuccessfulStep = GetTimeMillis(); nTimeLastSuccessfulStep = GetTimeMillis();
if(pnodeFound) {
pnodeFound->Release();
}
return true; return true;
} else { } else {
LogPrintf("CDarksendPool::DoAutomaticDenominating -- can't connect, addr=%s\n", pmn->addr.ToString()); LogPrintf("CDarksendPool::DoAutomaticDenominating -- can't connect, addr=%s\n", pmn->addr.ToString());