mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 21:42:47 +01:00
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:
commit
4455951bd0
@ -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;
|
||||||
|
@ -259,11 +259,14 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)) {
|
{
|
||||||
LogPrintf("dsi -- transaction not valid! \n");
|
LOCK(cs_main);
|
||||||
errorID = ERR_INVALID_TX;
|
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)) {
|
||||||
pfrom->PushMessage("dssu", sessionID, GetState(), GetEntriesCount(), MASTERNODE_REJECTED, errorID);
|
LogPrintf("dsi -- transaction not valid! \n");
|
||||||
return;
|
errorID = ERR_INVALID_TX;
|
||||||
|
pfrom->PushMessage("dssu", sessionID, GetState(), GetEntriesCount(), MASTERNODE_REJECTED, errorID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,10 +971,13 @@ 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());
|
||||||
|
|
||||||
CValidationState state;
|
{
|
||||||
if(!AcceptableInputs(mempool, state, txCollateral, true, NULL)){
|
LOCK(cs_main);
|
||||||
if(fDebug) LogPrintf ("CDarksendPool::IsCollateralValid - didn't pass IsAcceptable\n");
|
CValidationState state;
|
||||||
return false;
|
if(!AcceptableInputs(mempool, state, txCollateral, true, NULL)){
|
||||||
|
if(fDebug) LogPrintf ("CDarksendPool::IsCollateralValid - didn't pass IsAcceptable\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1147,11 +1154,14 @@ 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());
|
||||||
|
|
||||||
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)){
|
{
|
||||||
LogPrintf("dsi -- transaction not valid! %s \n", tx.ToString().c_str());
|
LOCK(cs_main);
|
||||||
UnlockCoins();
|
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)){
|
||||||
SetNull();
|
LogPrintf("dsi -- transaction not valid! %s \n", tx.ToString().c_str());
|
||||||
return;
|
UnlockCoins();
|
||||||
|
SetNull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()) {
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(IsInitialBlockDownload()) return;
|
{
|
||||||
|
TRY_LOCK(cs_main, lockMain);
|
||||||
|
if(!lockMain) 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;
|
||||||
|
@ -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);
|
||||||
|
|
||||||
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)){
|
{
|
||||||
activeState = MASTERNODE_VIN_SPENT;
|
TRY_LOCK(cs_main, lockMain);
|
||||||
return;
|
if(!lockMain) return;
|
||||||
|
|
||||||
|
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)){
|
||||||
|
activeState = MASTERNODE_VIN_SPENT;
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,53 +427,58 @@ 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)){
|
|
||||||
if(fDebug) LogPrintf("mnb - Accepted Masternode entry\n");
|
|
||||||
|
|
||||||
if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){
|
{
|
||||||
LogPrintf("mnb - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS);
|
TRY_LOCK(cs_main, lockMain);
|
||||||
|
if(!lockMain) return false;
|
||||||
|
|
||||||
|
if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) {
|
||||||
|
//set nDos
|
||||||
|
state.IsInvalid(nDoS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that sig time is legit in past
|
|
||||||
// should be at least not earlier than block when 1000 DASH tx got MASTERNODE_MIN_CONFIRMATIONS
|
|
||||||
uint256 hashBlock = 0;
|
|
||||||
CTransaction tx2;
|
|
||||||
GetTransaction(vin.prevout.hash, tx2, hashBlock, true);
|
|
||||||
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
|
|
||||||
if (mi != mapBlockIndex.end() && (*mi).second)
|
|
||||||
{
|
|
||||||
CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation
|
|
||||||
CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS
|
|
||||||
if(pConfIndex->GetBlockTime() > sigTime)
|
|
||||||
{
|
|
||||||
LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n",
|
|
||||||
sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LogPrintf("mnb - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime);
|
|
||||||
CMasternode mn(*this);
|
|
||||||
mnodeman.Add(mn);
|
|
||||||
|
|
||||||
// if it matches our Masternode privkey, then we've been remotely activated
|
|
||||||
if(pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION){
|
|
||||||
activeMasternode.EnableHotColdMasterNode(vin, addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isLocal = addr.IsRFC1918() || addr.IsLocal();
|
|
||||||
if(Params().NetworkID() == CBaseChainParams::REGTEST) isLocal = false;
|
|
||||||
|
|
||||||
if(!isLocal) Relay();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
//set nDos
|
|
||||||
state.IsInvalid(nDoS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if(fDebug) LogPrintf("mnb - Accepted Masternode entry\n");
|
||||||
|
|
||||||
|
if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){
|
||||||
|
LogPrintf("mnb - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// verify that sig time is legit in past
|
||||||
|
// should be at least not earlier than block when 1000 DASH tx got MASTERNODE_MIN_CONFIRMATIONS
|
||||||
|
uint256 hashBlock = 0;
|
||||||
|
CTransaction tx2;
|
||||||
|
GetTransaction(vin.prevout.hash, tx2, hashBlock, true);
|
||||||
|
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
|
||||||
|
if (mi != mapBlockIndex.end() && (*mi).second)
|
||||||
|
{
|
||||||
|
CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation
|
||||||
|
CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS
|
||||||
|
if(pConfIndex->GetBlockTime() > sigTime)
|
||||||
|
{
|
||||||
|
LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n",
|
||||||
|
sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogPrintf("mnb - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime);
|
||||||
|
CMasternode mn(*this);
|
||||||
|
mnodeman.Add(mn);
|
||||||
|
|
||||||
|
// if it matches our Masternode privkey, then we've been remotely activated
|
||||||
|
if(pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION){
|
||||||
|
activeMasternode.EnableHotColdMasterNode(vin, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLocal = addr.IsRFC1918() || addr.IsLocal();
|
||||||
|
if(Params().NetworkID() == CBaseChainParams::REGTEST) isLocal = false;
|
||||||
|
|
||||||
|
if(!isLocal) Relay();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMasternodeBroadcast::Relay()
|
void CMasternodeBroadcast::Relay()
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user