diff options
author | Elle Mouton <elle.mouton@gmail.com> | 2020-10-20 20:42:47 +0200 |
---|---|---|
committer | Elle Mouton <elle.mouton@gmail.com> | 2020-10-23 14:41:30 +0200 |
commit | e3310692d0e9720e960b9785274ce1f0b58b4cd7 (patch) | |
tree | b110b230110db9e2a9616a83cb8c3b545dbdb01d /src/txmempool.cpp | |
parent | 9d4b4b2c2c49774523de740d6492ee5b1ee15e74 (diff) | |
download | bitcoin-e3310692d0e9720e960b9785274ce1f0b58b4cd7.tar.xz |
refactor: Make CTxMemPool::m_check_ratio a const and a constructor argument
Since m_check_ratio is only set once and since the CTxMemPool object is
no longer a global variable, m_check_ratio can be passed into the
constructor of CTxMemPool. Since it is only read from after
initialization, m_check_ratio can also be made a const and hence no
longer needs to be guarded by the cs mutex.
Diffstat (limited to 'src/txmempool.cpp')
-rw-r--r-- | src/txmempool.cpp | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 78af3bf833..ca7021443e 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -331,15 +331,10 @@ void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee, assert(int(nSigOpCostWithAncestors) >= 0); } -CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) - : nTransactionsUpdated(0), minerPolicyEstimator(estimator), m_epoch(0), m_has_epoch_guard(false) +CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator, int check_ratio) + : m_check_ratio(check_ratio), nTransactionsUpdated(0), minerPolicyEstimator(estimator), m_epoch(0), m_has_epoch_guard(false) { _clear(); //lock free clear - - // Sanity checks off by default for performance, because otherwise - // accepting transactions becomes O(N^2) where N is the number - // of transactions in the pool - m_check_ratio = 0; } bool CTxMemPool::isSpent(const COutPoint& outpoint) const @@ -619,11 +614,11 @@ static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& m void CTxMemPool::check(const CCoinsViewCache *pcoins) const { - LOCK(cs); if (m_check_ratio == 0) return; if (GetRand(m_check_ratio) >= 1) return; + LOCK(cs); LogPrint(BCLog::MEMPOOL, "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); uint64_t checkTotal = 0; |