Skip to content

Commit

Permalink
Merge pull request #477 from UdjinM6/v0.12.0.x_locks
Browse files Browse the repository at this point in the history
V0.12.0.x more locks fixes
  • Loading branch information
evan82 committed Aug 5, 2015
2 parents 8f1c0e1 + 7d78c98 commit e056220
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 94 deletions.
12 changes: 4 additions & 8 deletions src/darksend-relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,11 @@ void CDarkSendRelay::RelayThroughNode(int nRank)

if(pmn != NULL){
//printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str());
if(ConnectNode((CAddress)pmn->addr, NULL, true)){
CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true);
if(pnode){
//printf("Connected\n");
CNode* pNode = FindNode(pmn->addr);
if(pNode)
{
//printf("Found\n");
pNode->PushMessage("dsr", (*this));
return;
}
pnode->PushMessage("dsr", (*this));
return;
}
} else {
//printf("RelayThroughNode NULL\n");
Expand Down
89 changes: 35 additions & 54 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,26 +1527,24 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
}

// connect to Masternode and submit the queue request
if(ConnectNode((CAddress)addr, NULL, true)){
CNode* pnode = FindNode(addr);
if(pnode)
CNode* pnode = ConnectNode((CAddress)addr, NULL, true);
if(pnode != NULL)
{
CMasternode* pmn = mnodeman.Find(dsq.vin);
if(pmn == NULL)
{
CMasternode* pmn = mnodeman.Find(dsq.vin);
if(pmn == NULL)
{
LogPrintf("DoAutomaticDenominating --- dsq vin %s is not in masternode list!", dsq.vin.ToString());
continue;
}
pSubmittedToMasternode = pmn;
vecMasternodesUsed.push_back(dsq.vin);
sessionDenom = dsq.nDenom;

pnode->PushMessage("dsa", sessionDenom, txCollateral);
LogPrintf("DoAutomaticDenominating --- connected (from queue), sending dsa for %d - %s\n", sessionDenom, pnode->addr.ToString());
strAutoDenomResult = _("Mixing in progress...");
dsq.time = 0; //remove node
return true;
LogPrintf("DoAutomaticDenominating --- dsq vin %s is not in masternode list!", dsq.vin.ToString());
continue;
}
pSubmittedToMasternode = pmn;
vecMasternodesUsed.push_back(dsq.vin);
sessionDenom = dsq.nDenom;

pnode->PushMessage("dsa", sessionDenom, txCollateral);
LogPrintf("DoAutomaticDenominating --- connected (from queue), sending dsa for %d - %s\n", sessionDenom, pnode->addr.ToString());
strAutoDenomResult = _("Mixing in progress...");
dsq.time = 0; //remove node
return true;
} else {
LogPrintf("DoAutomaticDenominating --- error connecting \n");
strAutoDenomResult = _("Error connecting to Masternode.");
Expand Down Expand Up @@ -1577,27 +1575,21 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)

lastTimeChanged = GetTimeMillis();
LogPrintf("DoAutomaticDenominating -- attempt %d connection to Masternode %s\n", i, pmn->addr.ToString());
if(ConnectNode((CAddress)pmn->addr, NULL, true)){

LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if((CNetAddr)pnode->addr != (CNetAddr)pmn->addr) continue;

pSubmittedToMasternode = pmn;
vecMasternodesUsed.push_back(pmn->vin);

std::vector<CAmount> vecAmounts;
pwalletMain->ConvertList(vCoins, vecAmounts);
// try to get random denoms out of vecAmounts
while(sessionDenom == 0)
sessionDenom = GetDenominationsByAmounts(vecAmounts, true);

pnode->PushMessage("dsa", sessionDenom, txCollateral);
LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom);
strAutoDenomResult = _("Mixing in progress...");
return true;
}
CNode* pnode = ConnectNode((CAddress)pmn->addr, NULL, true);
if(pnode != NULL){
pSubmittedToMasternode = pmn;
vecMasternodesUsed.push_back(pmn->vin);

std::vector<CAmount> vecAmounts;
pwalletMain->ConvertList(vCoins, vecAmounts);
// try to get random denoms out of vecAmounts
while(sessionDenom == 0)
sessionDenom = GetDenominationsByAmounts(vecAmounts, true);

pnode->PushMessage("dsa", sessionDenom, txCollateral);
LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom);
strAutoDenomResult = _("Mixing in progress...");
return true;
} else {
i++;
continue;
Expand Down Expand Up @@ -2167,6 +2159,7 @@ void CDarksendPool::RelayFinalTransaction(const int sessionID, const CTransactio

void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout)
{
if(!pSubmittedToMasternode) return;

std::vector<CTxIn> vin2;
std::vector<CTxOut> vout2;
Expand All @@ -2177,11 +2170,8 @@ void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmo
BOOST_FOREACH(CTxDSOut out, vout)
vout2.push_back(out);

LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if(!pSubmittedToMasternode) return;
if((CNetAddr)pSubmittedToMasternode->addr != (CNetAddr)pnode->addr) continue;
CNode* pnode = FindNode(pSubmittedToMasternode->addr);
if(pnode != NULL) {
LogPrintf("RelayIn - found master, relaying message - %s \n", pnode->addr.ToString());
pnode->PushMessage("dsi", vin2, nAmount, txCollateral, vout2);
}
Expand Down Expand Up @@ -2229,16 +2219,7 @@ void ThreadCheckDarkSendPool()

if(c % 60 == 0)
{
{
LOCK(cs_main);
/*
cs_main is required for doing CMasternode.Check because something
is modifying the coins view without a mempool lock. It causes
segfaults from this code without the cs_main lock.
*/
mnodeman.CheckAndRemove();
}

mnodeman.CheckAndRemove();
mnodeman.ProcessMasternodeConnections();
masternodePayments.CleanPaymentList();
CleanTransactionLocksList();
Expand Down
21 changes: 8 additions & 13 deletions src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
bool fMissingInputs = false;
CValidationState state;

LOCK(cs_main);
if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
bool fAccepted = false;
{
vector<CInv> vInv;
vInv.push_back(inv);
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
pnode->PushMessage("inv", vInv);
LOCK(cs_main);
fAccepted = AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs);
}
if (fAccepted)
{
RelayInv(inv);

DoConsensusVote(tx, nBlockHeight);

Expand Down Expand Up @@ -161,12 +161,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
mapUnknownVotes[ctx.vinMasternode.prevout.hash] = GetTime()+(60*10);
}
}
vector<CInv> vInv;
vInv.push_back(inv);
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
pnode->PushMessage("inv", vInv);

RelayInv(inv);
}

return;
Expand Down
13 changes: 0 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3284,22 +3284,9 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis

if(!fLiteMode){
if (masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_LIST) {
CScript payee;
CTxIn vin;
darkSendPool.NewBlock();
masternodePayments.ProcessBlock(GetHeight()+10);
budget.NewBlock();

//allow clients to ask for syncing again if they need it
if(GetHeight() % 100 == 0) {
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) {
pnode->ClearFulfilledRequest("getspork");
pnode->ClearFulfilledRequest("mnsync");
pnode->ClearFulfilledRequest("mnwsync");
pnode->ClearFulfilledRequest("busync");
}
}
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,8 @@ void CMasternodeMan::ProcessMasternodeConnections()

if(!darkSendPool.pSubmittedToMasternode) return;

LOCK(cs_vNodes);

BOOST_FOREACH(CNode* pnode, vNodes)
{
if(darkSendPool.pSubmittedToMasternode->addr == pnode->addr) continue;

CNode* pnode = FindNode(darkSendPool.pSubmittedToMasternode->addr);
if(pnode != NULL) {
if(pnode->fDarkSendMaster){
LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString());
pnode->fDisconnect = true;
Expand Down

0 comments on commit e056220

Please sign in to comment.