mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
add ChainstateManager::MaybeRebalanceCaches()
Aside from in unittests, this method is unused at the moment. It will be used in upcoming commits that enable utxo snapshot activation.
This commit is contained in:
parent
f36aaa6392
commit
8ac3ef4699
4 changed files with 99 additions and 0 deletions
|
|
@ -5297,3 +5297,33 @@ void ChainstateManager::Reset()
|
|||
m_active_chainstate = nullptr;
|
||||
m_snapshot_validated = false;
|
||||
}
|
||||
|
||||
void ChainstateManager::MaybeRebalanceCaches()
|
||||
{
|
||||
if (m_ibd_chainstate && !m_snapshot_chainstate) {
|
||||
LogPrintf("[snapshot] allocating all cache to the IBD chainstate\n");
|
||||
// Allocate everything to the IBD chainstate.
|
||||
m_ibd_chainstate->ResizeCoinsCaches(m_total_coinstip_cache, m_total_coinsdb_cache);
|
||||
}
|
||||
else if (m_snapshot_chainstate && !m_ibd_chainstate) {
|
||||
LogPrintf("[snapshot] allocating all cache to the snapshot chainstate\n");
|
||||
// Allocate everything to the snapshot chainstate.
|
||||
m_snapshot_chainstate->ResizeCoinsCaches(m_total_coinstip_cache, m_total_coinsdb_cache);
|
||||
}
|
||||
else if (m_ibd_chainstate && m_snapshot_chainstate) {
|
||||
// If both chainstates exist, determine who needs more cache based on IBD status.
|
||||
//
|
||||
// Note: shrink caches first so that we don't inadvertently overwhelm available memory.
|
||||
if (m_snapshot_chainstate->IsInitialBlockDownload()) {
|
||||
m_ibd_chainstate->ResizeCoinsCaches(
|
||||
m_total_coinstip_cache * 0.05, m_total_coinsdb_cache * 0.05);
|
||||
m_snapshot_chainstate->ResizeCoinsCaches(
|
||||
m_total_coinstip_cache * 0.95, m_total_coinsdb_cache * 0.95);
|
||||
} else {
|
||||
m_snapshot_chainstate->ResizeCoinsCaches(
|
||||
m_total_coinstip_cache * 0.05, m_total_coinsdb_cache * 0.05);
|
||||
m_ibd_chainstate->ResizeCoinsCaches(
|
||||
m_total_coinstip_cache * 0.95, m_total_coinsdb_cache * 0.95);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue