From 8a5d3a4fd549f8b725fa3b8599fa012454fa8db3 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Wed, 20 Sep 2023 13:06:26 +0100 Subject: [PATCH] 1658 Fix totalMemory calculation used for garbage collection --- libethereum/BlockChain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 8902b8ff0..29de6b27b 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -1263,7 +1263,8 @@ void BlockChain::garbageCollect( bool _force ) { m_lastCollection = chrono::system_clock::now(); - while ( m_lastStats.memTotal() >= c_maxCacheSize ) { + // We subtract memory that blockhashes occupy because it is treated sepaparately + while ( m_lastStats.memTotal() - m_lastStats.memBlockHashes >= c_maxCacheSize ) { Guard l( x_cacheUsage ); for ( CacheID const& id : m_cacheUsage.back() ) { m_inUse.erase( id ); @@ -1316,6 +1317,7 @@ void BlockChain::garbageCollect( bool _force ) { { WriteGuard l( x_blockHashes ); + // This is where block hash memory cleanup is treated // allow only 4096 blockhashes in the cache if ( m_blockHashes.size() > 4096 ) { auto last = m_blockHashes.begin();