From 63a24829c4ea3e149eb28d99492533d785ec7abb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Jul 2018 19:55:54 -1100 Subject: [PATCH] Tweak locks --- src/cc/faucet.cpp | 3 +++ src/main.cpp | 13 ++++++++----- src/miner.cpp | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 8dc70dab5..14f361ef7 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -62,12 +62,15 @@ bool FaucetExactAmounts(Eval* eval,const CTransaction &tx,int32_t minage,uint64_ numvouts = tx.vout.size(); for (i=0; iGetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin, but didnt"); else { + fprintf(stderr,"vini.%d check hash and vout\n"); if ( hashBlock == zerohash ) return eval->Invalid("cant faucet from mempool"); if ( (assetoshis= IsFaucetvout(vinTx,tx.vin[i].prevout.n)) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 54e77366f..e4d060fe0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1606,13 +1606,16 @@ bool GetAddressUnspent(uint160 addressHash, int type, bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) { // need a GetTransaction without lock so the validation code for assets can run without deadlock - //fprintf(stderr,"check mempool\n"); - if (mempool.lookup(hash, txOut)) { - //fprintf(stderr,"found in mempool\n"); - return true; + READLOCK(mempool.cs) + fprintf(stderr,"check mempool\n"); + if (mempool.lookup(hash, txOut)) + { + fprintf(stderr,"found in mempool\n"); + return true; + } } - //fprintf(stderr,"check disk\n"); + fprintf(stderr,"check disk\n"); if (fTxIndex) { CDiskTxPos postx; diff --git a/src/miner.cpp b/src/miner.cpp index 6dce2f9fa..f73e93d6c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -165,7 +165,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) CAmount nFees = 0; { - LOCK2(cs_main, mempool.cs); + //LOCK2(cs_main, mempool.cs); + LOCK(cs_main); CBlockIndex* pindexPrev = chainActive.LastTip(); const int nHeight = pindexPrev->nHeight + 1; uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus()); @@ -185,6 +186,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi) { + READLOCK(mempool.cs); const CTransaction& tx = mi->GetTx(); int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)