MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MaybeRebalanceCaches

Method MaybeRebalanceCaches

src/validation.cpp:6104–6134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6102}
6103
6104void ChainstateManager::MaybeRebalanceCaches()
6105{
6106 AssertLockHeld(::cs_main);
6107 Chainstate& current_cs{CurrentChainstate()};
6108 Chainstate* historical_cs{HistoricalChainstate()};
6109 if (!historical_cs && !current_cs.m_from_snapshot_blockhash) {
6110 // Allocate everything to the IBD chainstate. This will always happen
6111 // when we are not using a snapshot.
6112 current_cs.ResizeCoinsCaches(m_total_coinstip_cache, m_total_coinsdb_cache);
6113 } else if (!historical_cs) {
6114 // If background validation has completed and snapshot is our active chain...
6115 LogInfo("[snapshot] allocating all cache to the snapshot chainstate");
6116 // Allocate everything to the snapshot chainstate.
6117 current_cs.ResizeCoinsCaches(m_total_coinstip_cache, m_total_coinsdb_cache);
6118 } else {
6119 // If both chainstates exist, determine who needs more cache based on IBD status.
6120 //
6121 // Note: shrink caches first so that we don't inadvertently overwhelm available memory.
6122 if (IsInitialBlockDownload()) {
6123 historical_cs->ResizeCoinsCaches(
6124 m_total_coinstip_cache * 0.05, m_total_coinsdb_cache * 0.05);
6125 current_cs.ResizeCoinsCaches(
6126 m_total_coinstip_cache * 0.95, m_total_coinsdb_cache * 0.95);
6127 } else {
6128 current_cs.ResizeCoinsCaches(
6129 m_total_coinstip_cache * 0.05, m_total_coinsdb_cache * 0.05);
6130 historical_cs->ResizeCoinsCaches(
6131 m_total_coinstip_cache * 0.95, m_total_coinsdb_cache * 0.95);
6132 }
6133 }
6134}
6135
6136void ChainstateManager::ResetChainstates()
6137{

Callers 7

ActivateSnapshotMethod · 0.95
MaybeValidateSnapshotMethod · 0.95
ActivateBestChainMethod · 0.80
validation.cppFile · 0.80
BOOST_FIXTURE_TEST_CASEFunction · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.80

Calls 1

ResizeCoinsCachesMethod · 0.80

Tested by 2

BOOST_FIXTURE_TEST_CASEFunction · 0.64