txpool: Make nTransactionsUpdated atomic

This commit is contained in:
MarcoFalke 2019-05-23 19:17:09 +02:00
parent d0f81a96d9
commit fa0c9dbf91
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
3 changed files with 8 additions and 8 deletions

View file

@ -480,6 +480,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout) if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout)
{ {
// Timeout: Check transactions for update // Timeout: Check transactions for update
// without holding ::mempool.cs to avoid deadlocks
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP) if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
break; break;
checktxtime += std::chrono::seconds(10); checktxtime += std::chrono::seconds(10);

View file

@ -322,8 +322,8 @@ void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee,
assert(int(nSigOpCostWithAncestors) >= 0); assert(int(nSigOpCostWithAncestors) >= 0);
} }
CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) : CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator)
nTransactionsUpdated(0), minerPolicyEstimator(estimator) : nTransactionsUpdated(0), minerPolicyEstimator(estimator)
{ {
_clear(); //lock free clear _clear(); //lock free clear
@ -341,13 +341,11 @@ bool CTxMemPool::isSpent(const COutPoint& outpoint) const
unsigned int CTxMemPool::GetTransactionsUpdated() const unsigned int CTxMemPool::GetTransactionsUpdated() const
{ {
LOCK(cs);
return nTransactionsUpdated; return nTransactionsUpdated;
} }
void CTxMemPool::AddTransactionsUpdated(unsigned int n) void CTxMemPool::AddTransactionsUpdated(unsigned int n)
{ {
LOCK(cs);
nTransactionsUpdated += n; nTransactionsUpdated += n;
} }

View file

@ -6,12 +6,13 @@
#ifndef BITCOIN_TXMEMPOOL_H #ifndef BITCOIN_TXMEMPOOL_H
#define BITCOIN_TXMEMPOOL_H #define BITCOIN_TXMEMPOOL_H
#include <atomic>
#include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <map>
#include <vector>
#include <utility>
#include <string> #include <string>
#include <utility>
#include <vector>
#include <amount.h> #include <amount.h>
#include <coins.h> #include <coins.h>
@ -443,7 +444,7 @@ class CTxMemPool
{ {
private: private:
uint32_t nCheckFrequency GUARDED_BY(cs); //!< Value n means that n times in 2^32 we check. uint32_t nCheckFrequency GUARDED_BY(cs); //!< Value n means that n times in 2^32 we check.
unsigned int nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation std::atomic<unsigned int> nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
CBlockPolicyEstimator* minerPolicyEstimator; CBlockPolicyEstimator* minerPolicyEstimator;
uint64_t totalTxSize; //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141. uint64_t totalTxSize; //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.