aboutsummaryrefslogtreecommitdiff
path: root/src/txmempool.h
diff options
context:
space:
mode:
authorElle Mouton <elle.mouton@gmail.com>2020-10-20 20:42:47 +0200
committerElle Mouton <elle.mouton@gmail.com>2020-10-23 14:41:30 +0200
commite3310692d0e9720e960b9785274ce1f0b58b4cd7 (patch)
treeb110b230110db9e2a9616a83cb8c3b545dbdb01d /src/txmempool.h
parent9d4b4b2c2c49774523de740d6492ee5b1ee15e74 (diff)
downloadbitcoin-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.h')
-rw-r--r--src/txmempool.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/txmempool.h b/src/txmempool.h
index 38abc65c5d..da071576ac 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -488,7 +488,7 @@ public:
class CTxMemPool
{
private:
- uint32_t m_check_ratio GUARDED_BY(cs); //!< Value n means that 1 times in n we check.
+ const int m_check_ratio; //!< Value n means that 1 times in n we check.
std::atomic<unsigned int> nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
CBlockPolicyEstimator* minerPolicyEstimator;
@@ -601,8 +601,14 @@ public:
std::map<uint256, CAmount> mapDeltas;
/** Create a new CTxMemPool.
+ * Sanity checks will be off by default for performance, because otherwise
+ * accepting transactions becomes O(N^2) where N is the number of transactions
+ * in the pool.
+ *
+ * @param[in] estimator is used to estimate appropriate transaction fees.
+ * @param[in] check_ratio is the ratio used to determine how often sanity checks will run.
*/
- explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr);
+ explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr, int check_ratio = 0);
/**
* If sanity-checking is turned on, check makes sure the pool is
@@ -611,7 +617,6 @@ public:
* check does nothing.
*/
void check(const CCoinsViewCache *pcoins) const;
- void setSanityCheck(int check_ratio = 0) { LOCK(cs); m_check_ratio = check_ratio; }
// addUnchecked must updated state for all ancestors of a given transaction,
// to track size/count of descendant transactions. First version of