mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
Add CChainState::ResizeCoinsCaches
Also adds CCoinsViewCache::ReallocateCache() to attempt to free
memory that the cacheCoins's allocator may be hanging onto when
downsizing the cache.
Adds `CChainState::m_coins{tip,db}_cache_size_bytes` data members
so that we can reference cache size on a per-chainstate basis for
flushing.
This commit is contained in:
committed by
James O'Beirne
parent
b223111da2
commit
f36aaa6392
@@ -139,7 +139,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
|
||||
::ChainstateActive().InitCoinsDB(
|
||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
|
||||
assert(!::ChainstateActive().CanFlushToDisk());
|
||||
::ChainstateActive().InitCoinsCache();
|
||||
::ChainstateActive().InitCoinsCache(1 << 23);
|
||||
assert(::ChainstateActive().CanFlushToDisk());
|
||||
if (!LoadGenesisBlock(chainparams)) {
|
||||
throw std::runtime_error("LoadGenesisBlock failed.");
|
||||
|
||||
@@ -28,13 +28,11 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
|
||||
// Create a legacy (IBD) chainstate.
|
||||
//
|
||||
ENTER_CRITICAL_SECTION(cs_main);
|
||||
CChainState& c1 = manager.InitializeChainstate();
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
CChainState& c1 = *WITH_LOCK(::cs_main, return &manager.InitializeChainstate());
|
||||
chainstates.push_back(&c1);
|
||||
c1.InitCoinsDB(
|
||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
|
||||
WITH_LOCK(::cs_main, c1.InitCoinsCache());
|
||||
WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23));
|
||||
|
||||
BOOST_CHECK(!manager.IsSnapshotActive());
|
||||
BOOST_CHECK(!manager.IsSnapshotValidated());
|
||||
@@ -57,12 +55,13 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
// Create a snapshot-based chainstate.
|
||||
//
|
||||
ENTER_CRITICAL_SECTION(cs_main);
|
||||
CChainState& c2 = manager.InitializeChainstate(GetRandHash());
|
||||
CChainState& c2 = *WITH_LOCK(::cs_main,
|
||||
return &manager.InitializeChainstate(GetRandHash()));
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
chainstates.push_back(&c2);
|
||||
c2.InitCoinsDB(
|
||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
|
||||
WITH_LOCK(::cs_main, c2.InitCoinsCache());
|
||||
WITH_LOCK(::cs_main, c2.InitCoinsCache(1 << 23));
|
||||
// Unlike c1, which doesn't have any blocks. Gets us different tip, height.
|
||||
c2.LoadGenesisBlock(chainparams);
|
||||
BlockValidationState _;
|
||||
|
||||
@@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
|
||||
BlockManager blockman{};
|
||||
CChainState chainstate{blockman};
|
||||
chainstate.InitCoinsDB(/*cache_size_bytes*/ 1 << 10, /*in_memory*/ true, /*should_wipe*/ false);
|
||||
WITH_LOCK(::cs_main, chainstate.InitCoinsCache());
|
||||
WITH_LOCK(::cs_main, chainstate.InitCoinsCache(1 << 10));
|
||||
CTxMemPool tx_pool{};
|
||||
|
||||
constexpr bool is_64_bit = sizeof(void*) == 8;
|
||||
|
||||
Reference in New Issue
Block a user