MCPcopy Create free account
hub / github.com/ElementsProject/elements / ResizeCoinsCaches

Method ResizeCoinsCaches

src/validation.cpp:4948–4978  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4946}
4947
4948bool CChainState::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
4949{
4950 AssertLockHeld(::cs_main);
4951 if (coinstip_size == m_coinstip_cache_size_bytes &&
4952 coinsdb_size == m_coinsdb_cache_size_bytes) {
4953 // Cache sizes are unchanged, no need to continue.
4954 return true;
4955 }
4956 size_t old_coinstip_size = m_coinstip_cache_size_bytes;
4957 m_coinstip_cache_size_bytes = coinstip_size;
4958 m_coinsdb_cache_size_bytes = coinsdb_size;
4959 CoinsDB().ResizeCache(coinsdb_size);
4960
4961 LogPrintf("[%s] resized coinsdb cache to %.1f MiB\n",
4962 this->ToString(), coinsdb_size * (1.0 / 1024 / 1024));
4963 LogPrintf("[%s] resized coinstip cache to %.1f MiB\n",
4964 this->ToString(), coinstip_size * (1.0 / 1024 / 1024));
4965
4966 BlockValidationState state;
4967 bool ret;
4968
4969 if (coinstip_size > old_coinstip_size) {
4970 // Likely no need to flush if cache sizes have grown.
4971 ret = FlushStateToDisk(state, FlushStateMode::IF_NEEDED);
4972 } else {
4973 // Otherwise, flush state to disk and deallocate the in-memory coins map.
4974 ret = FlushStateToDisk(state, FlushStateMode::ALWAYS);
4975 CoinsTip().ReallocateCache();
4976 }
4977 return ret;
4978}
4979
4980static const uint64_t MEMPOOL_DUMP_VERSION = 1;
4981

Callers 3

ActivateSnapshotMethod · 0.80
MaybeRebalanceCachesMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 3

ToStringMethod · 0.95
ResizeCacheMethod · 0.80
ReallocateCacheMethod · 0.80

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64