diff options
author | Elle Mouton <elle.mouton@gmail.com> | 2020-10-20 20:09:55 +0200 |
---|---|---|
committer | Elle Mouton <elle.mouton@gmail.com> | 2020-10-23 14:14:57 +0200 |
commit | 9d4b4b2c2c49774523de740d6492ee5b1ee15e74 (patch) | |
tree | 017771d3a7b54af87ceccc1003234f3b940f889d /src/txmempool.cpp | |
parent | 88271184e82222f556d67511cc64230b0532f40d (diff) |
refactor: Avoid double to int cast for nCheckFrequency
Use a ratio instead of a frequency that requires a double to int cast
for determining how often a mempool sanity check should run.
Diffstat (limited to 'src/txmempool.cpp')
-rw-r--r-- | src/txmempool.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 0c2b731967..78af3bf833 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -339,7 +339,7 @@ CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) // 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 - nCheckFrequency = 0; + m_check_ratio = 0; } bool CTxMemPool::isSpent(const COutPoint& outpoint) const @@ -523,7 +523,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem if (it2 != mapTx.end()) continue; const Coin &coin = pcoins->AccessCoin(txin.prevout); - if (nCheckFrequency != 0) assert(!coin.IsSpent()); + if (m_check_ratio != 0) assert(!coin.IsSpent()); if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) { txToRemove.insert(it); break; @@ -620,11 +620,9 @@ static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& m void CTxMemPool::check(const CCoinsViewCache *pcoins) const { LOCK(cs); - if (nCheckFrequency == 0) - return; + if (m_check_ratio == 0) return; - if (GetRand(std::numeric_limits<uint32_t>::max()) >= nCheckFrequency) - return; + if (GetRand(m_check_ratio) >= 1) return; LogPrint(BCLog::MEMPOOL, "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); |