diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp index 325789572..a82f5bce6 100644 --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -212,4 +212,14 @@ BOOST_AUTO_TEST_CASE(RemoveWithoutBranchId) { BOOST_CHECK_EQUAL(pool.size(), 0); } +// Test that nCheckFrequency is set correctly when calling setSanityCheck(). +// https://github.com/zcash/zcash/issues/3134 +BOOST_AUTO_TEST_CASE(SetSanityCheck) { + CTxMemPool pool(CFeeRate(0)); + pool.setSanityCheck(1.0); + BOOST_CHECK_EQUAL(pool.GetCheckFrequency(), 4294967295); + pool.setSanityCheck(0); + BOOST_CHECK_EQUAL(pool.GetCheckFrequency(), 0); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/txmempool.h b/src/txmempool.h index 6b6434f1e..fd8758741 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -161,7 +161,7 @@ public: * check does nothing. */ void check(const CCoinsViewCache *pcoins) const; - void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967296.0; } + void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = static_cast(dFrequency * 4294967295.0); } bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true); void remove(const CTransaction &tx, std::list& removed, bool fRecursive = false); @@ -219,6 +219,11 @@ public: bool ReadFeeEstimates(CAutoFile& filein); size_t DynamicMemoryUsage() const; + + /** Return nCheckFrequency */ + uint32_t GetCheckFrequency() const { + return nCheckFrequency; + } }; /**