diff options
| author | James O'Beirne <[email protected]> | 2019-09-16 13:37:29 -0400 |
|---|---|---|
| committer | James O'Beirne <[email protected]> | 2020-07-01 14:44:28 -0400 |
| commit | 8ac3ef46999ed676ca3775f7b2f461d92f09a542 (patch) | |
| tree | 3bace2a0a4de841a555e04052de69e7cae6ba1de /src/validation.cpp | |
| parent | Add CChainState::ResizeCoinsCaches (diff) | |
| download | discoin-8ac3ef46999ed676ca3775f7b2f461d92f09a542.tar.xz discoin-8ac3ef46999ed676ca3775f7b2f461d92f09a542.zip | |
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.
Diffstat (limited to 'src/validation.cpp')
| -rw-r--r-- | src/validation.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 1d7d85b75..906ed943b 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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); + } + } +} |