diff --git a/src/test/validation_flush_tests.cpp b/src/test/validation_flush_tests.cpp --- a/src/test/validation_flush_tests.cpp +++ b/src/test/validation_flush_tests.cpp @@ -23,7 +23,6 @@ chainstate.InitCoinsDB(/*cache_size_bytes*/ 1 << 10, /*in_memory*/ true, /*should_wipe*/ false); WITH_LOCK(::cs_main, chainstate.InitCoinsCache(1 << 10)); - CTxMemPool tx_pool{}; constexpr bool is_64_bit = sizeof(void *) == 8; @@ -58,10 +57,9 @@ constexpr size_t MAX_COINS_CACHE_BYTES = 1024; // Without any coins in the cache, we shouldn't need to flush. - BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, - /*max_mempool_size_bytes*/ 0), - CoinsCacheSizeState::OK); + BOOST_CHECK_EQUAL(chainstate.GetCoinsCacheSizeState( + MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0), + CoinsCacheSizeState::OK); // If the initial memory allocations of cacheCoins don't match these common // cases, we can't really continue to make assertions about memory usage. @@ -76,7 +74,7 @@ } BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, + chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0), CoinsCacheSizeState::CRITICAL); @@ -99,7 +97,7 @@ print_view_mem_usage(view); BOOST_CHECK_EQUAL(view.AccessCoin(res).DynamicMemoryUsage(), COIN_SIZE); BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, + chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0), CoinsCacheSizeState::OK); } @@ -108,31 +106,30 @@ for (int i{0}; i < 4; ++i) { add_coin(view); print_view_mem_usage(view); - if (chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, + if (chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0) == CoinsCacheSizeState::CRITICAL) { break; } } - BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, - /*max_mempool_size_bytes*/ 0), - CoinsCacheSizeState::CRITICAL); + BOOST_CHECK_EQUAL(chainstate.GetCoinsCacheSizeState( + MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0), + CoinsCacheSizeState::CRITICAL); // Passing non-zero max mempool usage should allow us more headroom. BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, + chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 1 << 10), CoinsCacheSizeState::OK); for (int i{0}; i < 3; ++i) { add_coin(view); print_view_mem_usage(view); - BOOST_CHECK_EQUAL(chainstate.GetCoinsCacheSizeState( - &tx_pool, MAX_COINS_CACHE_BYTES, - /*max_mempool_size_bytes*/ 1 << 10), - CoinsCacheSizeState::OK); + BOOST_CHECK_EQUAL( + chainstate.GetCoinsCacheSizeState( + MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 1 << 10), + CoinsCacheSizeState::OK); } // Adding another coin with the additional mempool room will put us >90% @@ -148,15 +145,15 @@ BOOST_TEST_MESSAGE("CoinsTip usage percentage: " << usage_percentage); BOOST_CHECK(usage_percentage >= 0.9); BOOST_CHECK(usage_percentage < 1); - BOOST_CHECK_EQUAL(chainstate.GetCoinsCacheSizeState( - &tx_pool, MAX_COINS_CACHE_BYTES, 1 << 10), - CoinsCacheSizeState::LARGE); + BOOST_CHECK_EQUAL( + chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10), + CoinsCacheSizeState::LARGE); } // Using the default max_* values permits way more coins to be added. for (int i{0}; i < 1000; ++i) { add_coin(view); - BOOST_CHECK_EQUAL(chainstate.GetCoinsCacheSizeState(&tx_pool), + BOOST_CHECK_EQUAL(chainstate.GetCoinsCacheSizeState(), CoinsCacheSizeState::OK); } @@ -164,7 +161,7 @@ // preallocated memory that doesn't get reclaimed even after flush. BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, 0), + chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0), CoinsCacheSizeState::CRITICAL); view.SetBestBlock(BlockHash(InsecureRand256())); @@ -172,7 +169,7 @@ print_view_mem_usage(view); BOOST_CHECK_EQUAL( - chainstate.GetCoinsCacheSizeState(&tx_pool, MAX_COINS_CACHE_BYTES, 0), + chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0), CoinsCacheSizeState::CRITICAL); } diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -1100,12 +1100,13 @@ //! Dictates whether we need to flush the cache to disk or not. //! //! @return the state of the size of the coins cache. - CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool *tx_pool) + CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); - CoinsCacheSizeState GetCoinsCacheSizeState( - const CTxMemPool *tx_pool, size_t max_coins_cache_size_bytes, - size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + CoinsCacheSizeState + GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, + size_t max_mempool_size_bytes) + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1968,18 +1968,16 @@ return true; } -CoinsCacheSizeState -CChainState::GetCoinsCacheSizeState(const CTxMemPool *tx_pool) { +CoinsCacheSizeState CChainState::GetCoinsCacheSizeState() { return this->GetCoinsCacheSizeState( - tx_pool, m_coinstip_cache_size_bytes, + m_coinstip_cache_size_bytes, gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000); } CoinsCacheSizeState -CChainState::GetCoinsCacheSizeState(const CTxMemPool *tx_pool, - size_t max_coins_cache_size_bytes, +CChainState::GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, size_t max_mempool_size_bytes) { - int64_t nMempoolUsage = tx_pool ? tx_pool->DynamicMemoryUsage() : 0; + int64_t nMempoolUsage = m_mempool ? m_mempool->DynamicMemoryUsage() : 0; int64_t cacheSize = CoinsTip().DynamicMemoryUsage(); int64_t nTotalSpace = max_coins_cache_size_bytes + @@ -2019,7 +2017,7 @@ bool fFlushForPrune = false; bool fDoFullFlush = false; - CoinsCacheSizeState cache_state = GetCoinsCacheSizeState(m_mempool); + CoinsCacheSizeState cache_state = GetCoinsCacheSizeState(); LOCK(cs_LastBlockFile); if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) { @@ -6015,8 +6013,7 @@ } const auto snapshot_cache_state = WITH_LOCK( - ::cs_main, return snapshot_chainstate.GetCoinsCacheSizeState( - snapshot_chainstate.m_mempool)); + ::cs_main, return snapshot_chainstate.GetCoinsCacheSizeState()); if (snapshot_cache_state >= CoinsCacheSizeState::CRITICAL) { LogPrintfToBeContinued(