| 6102 | } |
| 6103 | |
| 6104 | void 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 | |
| 6136 | void ChainstateManager::ResetChainstates() |
| 6137 | { |