Merge pull request #463 from UdjinM6/v0.12.0.x_fix_locks

V0.12.0.x fix all kind of lock issues
This commit is contained in:
evan82 2015-07-30 07:40:09 -07:00
commit 4455951bd0
8 changed files with 103 additions and 73 deletions

View File

@ -90,6 +90,7 @@ void CActiveMasternode::ManageStatus()
return; return;
} }
LOCK(pwalletMain->cs_wallet);
pwalletMain->LockCoin(vin.prevout); pwalletMain->LockCoin(vin.prevout);
// send to all nodes // send to all nodes
@ -342,6 +343,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()
vector<COutput> filteredCoins; vector<COutput> filteredCoins;
vector<COutPoint> confLockedCoins; vector<COutPoint> confLockedCoins;
LOCK(pwalletMain->cs_wallet);
// Temporary unlock MN coins from masternode.conf // Temporary unlock MN coins from masternode.conf
if(GetBoolArg("-mnconflock", true)) { if(GetBoolArg("-mnconflock", true)) {
uint256 mnTxHash; uint256 mnTxHash;

View File

@ -259,6 +259,8 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
return; return;
} }
{
LOCK(cs_main);
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)) { if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)) {
LogPrintf("dsi -- transaction not valid! \n"); LogPrintf("dsi -- transaction not valid! \n");
errorID = ERR_INVALID_TX; errorID = ERR_INVALID_TX;
@ -266,6 +268,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
return; return;
} }
} }
}
if(AddEntry(in, nAmount, txCollateral, out, errorID)){ if(AddEntry(in, nAmount, txCollateral, out, errorID)){
pfrom->PushMessage("dssu", sessionID, GetState(), GetEntriesCount(), MASTERNODE_ACCEPTED, errorID); pfrom->PushMessage("dssu", sessionID, GetState(), GetEntriesCount(), MASTERNODE_ACCEPTED, errorID);
@ -429,6 +432,7 @@ bool CDarksendPool::SetCollateralAddress(std::string strAddress){
// Unlock coins after Darksend fails or succeeds // Unlock coins after Darksend fails or succeeds
// //
void CDarksendPool::UnlockCoins(){ void CDarksendPool::UnlockCoins(){
LOCK(pwalletMain->cs_wallet);
BOOST_FOREACH(CTxIn v, lockedCoins) BOOST_FOREACH(CTxIn v, lockedCoins)
pwalletMain->UnlockCoin(v.prevout); pwalletMain->UnlockCoin(v.prevout);
@ -967,11 +971,14 @@ bool CDarksendPool::IsCollateralValid(const CTransaction& txCollateral){
if(fDebug) LogPrintf("CDarksendPool::IsCollateralValid %s\n", txCollateral.ToString().c_str()); if(fDebug) LogPrintf("CDarksendPool::IsCollateralValid %s\n", txCollateral.ToString().c_str());
{
LOCK(cs_main);
CValidationState state; CValidationState state;
if(!AcceptableInputs(mempool, state, txCollateral, true, NULL)){ if(!AcceptableInputs(mempool, state, txCollateral, true, NULL)){
if(fDebug) LogPrintf ("CDarksendPool::IsCollateralValid - didn't pass IsAcceptable\n"); if(fDebug) LogPrintf ("CDarksendPool::IsCollateralValid - didn't pass IsAcceptable\n");
return false; return false;
} }
}
return true; return true;
} }
@ -1147,6 +1154,8 @@ void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<
LogPrintf("Submitting tx %s\n", tx.ToString().c_str()); LogPrintf("Submitting tx %s\n", tx.ToString().c_str());
{
LOCK(cs_main);
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)){ if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)){
LogPrintf("dsi -- transaction not valid! %s \n", tx.ToString().c_str()); LogPrintf("dsi -- transaction not valid! %s \n", tx.ToString().c_str());
UnlockCoins(); UnlockCoins();
@ -1154,6 +1163,7 @@ void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<
return; return;
} }
} }
}
// store our entry for later use // store our entry for later use
CDarkSendEntry e; CDarkSendEntry e;

View File

@ -1499,6 +1499,7 @@ bool AppInit2(boost::thread_group& threadGroup)
strBudgetMode = GetArg("-budgetvotemode", "auto"); strBudgetMode = GetArg("-budgetvotemode", "auto");
if(GetBoolArg("-mnconflock", true)) { if(GetBoolArg("-mnconflock", true)) {
LOCK(pwalletMain->cs_wallet);
LogPrintf("Locking Masternodes:\n"); LogPrintf("Locking Masternodes:\n");
uint256 mnTxHash; uint256 mnTxHash;
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) { BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {

View File

@ -70,7 +70,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
bool fMissingInputs = false; bool fMissingInputs = false;
CValidationState state; CValidationState state;
LOCK(cs_main);
if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
{ {
vector<CInv> vInv; vector<CInv> vInv;

View File

@ -157,7 +157,9 @@ void CMasternodeSync::ProcessMessage(CNode* pfrom, std::string& strCommand, CDat
void CMasternodeSync::ClearFulfilledRequest() void CMasternodeSync::ClearFulfilledRequest()
{ {
LOCK(cs_vNodes); TRY_LOCK(cs_vNodes, lockRecv);
if(!lockRecv) return;
BOOST_FOREACH(CNode* pnode, vNodes) BOOST_FOREACH(CNode* pnode, vNodes)
{ {
pnode->ClearFulfilledRequest("getspork"); pnode->ClearFulfilledRequest("getspork");
@ -198,7 +200,9 @@ void CMasternodeSync::Process()
if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset(); if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset();
LOCK(cs_vNodes); TRY_LOCK(cs_vNodes, lockRecv);
if(!lockRecv) return;
BOOST_FOREACH(CNode* pnode, vNodes) BOOST_FOREACH(CNode* pnode, vNodes)
{ {
if(Params().NetworkID() == CBaseChainParams::REGTEST){ if(Params().NetworkID() == CBaseChainParams::REGTEST){
@ -230,7 +234,12 @@ void CMasternodeSync::Process()
return; return;
} }
{
TRY_LOCK(cs_main, lockMain);
if(!lockMain) return;
if(IsInitialBlockDownload()) return; if(IsInitialBlockDownload()) return;
}
//don't begin syncing until we're almost at a recent block //don't begin syncing until we're almost at a recent block
if(pindexPrev->nTime + 600 < GetTime()) return; if(pindexPrev->nTime + 600 < GetTime()) return;

View File

@ -177,10 +177,6 @@ void CMasternode::Check()
{ {
if(ShutdownRequested()) return; if(ShutdownRequested()) return;
//TODO: Random segfault with this line removed
TRY_LOCK(cs_main, lockRecv);
if(!lockRecv) return;
//once spent, stop doing the checks //once spent, stop doing the checks
if(activeState == MASTERNODE_VIN_SPENT) return; if(activeState == MASTERNODE_VIN_SPENT) return;
@ -202,9 +198,15 @@ void CMasternode::Check()
tx.vin.push_back(vin); tx.vin.push_back(vin);
tx.vout.push_back(vout); tx.vout.push_back(vout);
{
TRY_LOCK(cs_main, lockMain);
if(!lockMain) return;
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)){ if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)){
activeState = MASTERNODE_VIN_SPENT; activeState = MASTERNODE_VIN_SPENT;
return; return;
}
} }
} }
@ -425,7 +427,18 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS)
CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey); CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey);
tx.vin.push_back(vin); tx.vin.push_back(vin);
tx.vout.push_back(vout); tx.vout.push_back(vout);
if(AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)){
{
TRY_LOCK(cs_main, lockMain);
if(!lockMain) return false;
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) {
//set nDos
state.IsInvalid(nDoS);
return false;
}
}
if(fDebug) LogPrintf("mnb - Accepted Masternode entry\n"); if(fDebug) LogPrintf("mnb - Accepted Masternode entry\n");
if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){
@ -466,12 +479,6 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS)
if(!isLocal) Relay(); if(!isLocal) Relay();
return true; return true;
} else {
//set nDos
state.IsInvalid(nDoS);
}
return false;
} }
void CMasternodeBroadcast::Relay() void CMasternodeBroadcast::Relay()

View File

@ -224,10 +224,10 @@ void CMasternodeMan::Check()
void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval) void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval)
{ {
LOCK(cs);
Check(); Check();
LOCK(cs);
//remove inactive and outdated //remove inactive and outdated
vector<CMasternode>::iterator it = vMasternodes.begin(); vector<CMasternode>::iterator it = vMasternodes.begin();
while(it != vMasternodes.end()){ while(it != vMasternodes.end()){
@ -604,17 +604,17 @@ void CMasternodeMan::ProcessMasternodeConnections()
//we don't care about this for regtest //we don't care about this for regtest
if(Params().NetworkID() == CBaseChainParams::REGTEST) return; if(Params().NetworkID() == CBaseChainParams::REGTEST) return;
LOCK(cs_vNodes);
if(!darkSendPool.pSubmittedToMasternode) return; if(!darkSendPool.pSubmittedToMasternode) return;
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) BOOST_FOREACH(CNode* pnode, vNodes)
{ {
if(darkSendPool.pSubmittedToMasternode->addr == pnode->addr) continue; if(darkSendPool.pSubmittedToMasternode->addr == pnode->addr) continue;
if(pnode->fDarkSendMaster){ if(pnode->fDarkSendMaster){
LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString().c_str()); LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString().c_str());
pnode->CloseSocketDisconnect(); pnode->fDisconnect = true;
} }
} }
} }

View File

@ -2434,6 +2434,7 @@ string CWallet::PrepareDarksendDenominate(int minRounds, int maxRounds)
LogPrintf("PrepareDarksendDenominate - preparing darksend denominate . Got: %d \n", nValueIn); LogPrintf("PrepareDarksendDenominate - preparing darksend denominate . Got: %d \n", nValueIn);
LOCK(cs_wallet);
BOOST_FOREACH(CTxIn v, vCoins) BOOST_FOREACH(CTxIn v, vCoins)
LockCoin(v.prevout); LockCoin(v.prevout);