mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 05:23:01 +01:00
fix all kind of lock issues
This commit is contained in:
parent
3f4727716a
commit
afd715286a
@ -90,6 +90,7 @@ void CActiveMasternode::ManageStatus()
|
||||
return;
|
||||
}
|
||||
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
pwalletMain->LockCoin(vin.prevout);
|
||||
|
||||
// send to all nodes
|
||||
@ -342,6 +343,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()
|
||||
vector<COutput> filteredCoins;
|
||||
vector<COutPoint> confLockedCoins;
|
||||
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
// Temporary unlock MN coins from masternode.conf
|
||||
if(GetBoolArg("-mnconflock", true)) {
|
||||
uint256 mnTxHash;
|
||||
|
@ -259,6 +259,8 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)) {
|
||||
LogPrintf("dsi -- transaction not valid! \n");
|
||||
errorID = ERR_INVALID_TX;
|
||||
@ -266,6 +268,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(AddEntry(in, nAmount, txCollateral, out, 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
|
||||
//
|
||||
void CDarksendPool::UnlockCoins(){
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
BOOST_FOREACH(CTxIn v, lockedCoins)
|
||||
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());
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CValidationState state;
|
||||
if(!AcceptableInputs(mempool, state, txCollateral, true, NULL)){
|
||||
if(fDebug) LogPrintf ("CDarksendPool::IsCollateralValid - didn't pass IsAcceptable\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1147,6 +1154,8 @@ void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<
|
||||
|
||||
LogPrintf("Submitting tx %s\n", tx.ToString().c_str());
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)){
|
||||
LogPrintf("dsi -- transaction not valid! %s \n", tx.ToString().c_str());
|
||||
UnlockCoins();
|
||||
@ -1154,6 +1163,7 @@ void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// store our entry for later use
|
||||
CDarkSendEntry e;
|
||||
|
@ -1499,6 +1499,7 @@ bool AppInit2(boost::thread_group& threadGroup)
|
||||
strBudgetMode = GetArg("-budgetvotemode", "auto");
|
||||
|
||||
if(GetBoolArg("-mnconflock", true)) {
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
LogPrintf("Locking Masternodes:\n");
|
||||
uint256 mnTxHash;
|
||||
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
|
||||
|
@ -70,7 +70,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
|
||||
bool fMissingInputs = false;
|
||||
CValidationState state;
|
||||
|
||||
|
||||
LOCK(cs_main);
|
||||
if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
|
||||
{
|
||||
vector<CInv> vInv;
|
||||
|
@ -157,7 +157,9 @@ void CMasternodeSync::ProcessMessage(CNode* pfrom, std::string& strCommand, CDat
|
||||
|
||||
void CMasternodeSync::ClearFulfilledRequest()
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
TRY_LOCK(cs_vNodes, lockRecv);
|
||||
if(!lockRecv) return;
|
||||
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
pnode->ClearFulfilledRequest("getspork");
|
||||
@ -198,7 +200,9 @@ void CMasternodeSync::Process()
|
||||
|
||||
if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset();
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
TRY_LOCK(cs_vNodes, lockRecv);
|
||||
if(!lockRecv) return;
|
||||
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
if(Params().NetworkID() == CBaseChainParams::REGTEST){
|
||||
@ -230,7 +234,12 @@ void CMasternodeSync::Process()
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
TRY_LOCK(cs_main, lockMain);
|
||||
if(!lockMain) return;
|
||||
|
||||
if(IsInitialBlockDownload()) return;
|
||||
}
|
||||
|
||||
//don't begin syncing until we're almost at a recent block
|
||||
if(pindexPrev->nTime + 600 < GetTime()) return;
|
||||
|
@ -177,10 +177,6 @@ void CMasternode::Check()
|
||||
{
|
||||
if(ShutdownRequested()) return;
|
||||
|
||||
//TODO: Random segfault with this line removed
|
||||
TRY_LOCK(cs_main, lockRecv);
|
||||
if(!lockRecv) return;
|
||||
|
||||
//once spent, stop doing the checks
|
||||
if(activeState == MASTERNODE_VIN_SPENT) return;
|
||||
|
||||
@ -202,9 +198,15 @@ void CMasternode::Check()
|
||||
tx.vin.push_back(vin);
|
||||
tx.vout.push_back(vout);
|
||||
|
||||
{
|
||||
TRY_LOCK(cs_main, lockMain);
|
||||
if(!lockMain) return;
|
||||
|
||||
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)){
|
||||
activeState = MASTERNODE_VIN_SPENT;
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,7 +427,18 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS)
|
||||
CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey);
|
||||
tx.vin.push_back(vin);
|
||||
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(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){
|
||||
@ -466,12 +479,6 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS)
|
||||
if(!isLocal) Relay();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
//set nDos
|
||||
state.IsInvalid(nDoS);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMasternodeBroadcast::Relay()
|
||||
|
@ -224,10 +224,10 @@ void CMasternodeMan::Check()
|
||||
|
||||
void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
Check();
|
||||
|
||||
LOCK(cs);
|
||||
|
||||
//remove inactive and outdated
|
||||
vector<CMasternode>::iterator it = vMasternodes.begin();
|
||||
while(it != vMasternodes.end()){
|
||||
@ -604,17 +604,17 @@ void CMasternodeMan::ProcessMasternodeConnections()
|
||||
//we don't care about this for regtest
|
||||
if(Params().NetworkID() == CBaseChainParams::REGTEST) return;
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
|
||||
if(!darkSendPool.pSubmittedToMasternode) return;
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
if(darkSendPool.pSubmittedToMasternode->addr == pnode->addr) continue;
|
||||
|
||||
if(pnode->fDarkSendMaster){
|
||||
LogPrintf("Closing Masternode connection %s \n", pnode->addr.ToString().c_str());
|
||||
pnode->CloseSocketDisconnect();
|
||||
pnode->fDisconnect = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2434,6 +2434,7 @@ string CWallet::PrepareDarksendDenominate(int minRounds, int maxRounds)
|
||||
|
||||
LogPrintf("PrepareDarksendDenominate - preparing darksend denominate . Got: %d \n", nValueIn);
|
||||
|
||||
LOCK(cs_wallet);
|
||||
BOOST_FOREACH(CTxIn v, vCoins)
|
||||
LockCoin(v.prevout);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user