| 5476 | } |
| 5477 | |
| 5478 | bool Chainstate::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size) |
| 5479 | { |
| 5480 | AssertLockHeld(::cs_main); |
| 5481 | if (coinstip_size == m_coinstip_cache_size_bytes && |
| 5482 | coinsdb_size == m_coinsdb_cache_size_bytes) { |
| 5483 | // Cache sizes are unchanged, no need to continue. |
| 5484 | return true; |
| 5485 | } |
| 5486 | size_t old_coinstip_size = m_coinstip_cache_size_bytes; |
| 5487 | m_coinstip_cache_size_bytes = coinstip_size; |
| 5488 | m_coinsdb_cache_size_bytes = coinsdb_size; |
| 5489 | CoinsDB().ResizeCache(coinsdb_size); |
| 5490 | |
| 5491 | LogInfo("[%s] resized coinsdb cache to %.1f MiB", |
| 5492 | this->ToString(), coinsdb_size / double(1_MiB)); |
| 5493 | LogInfo("[%s] resized coinstip cache to %.1f MiB", |
| 5494 | this->ToString(), coinstip_size / double(1_MiB)); |
| 5495 | |
| 5496 | BlockValidationState state; |
| 5497 | bool ret; |
| 5498 | |
| 5499 | if (coinstip_size > old_coinstip_size) { |
| 5500 | // Likely no need to flush if cache sizes have grown. |
| 5501 | ret = FlushStateToDisk(state, FlushStateMode::IF_NEEDED); |
| 5502 | } else { |
| 5503 | // Otherwise, flush state to disk and deallocate the in-memory coins map. |
| 5504 | ret = FlushStateToDisk(state, FlushStateMode::FORCE_FLUSH); |
| 5505 | } |
| 5506 | return ret; |
| 5507 | } |
| 5508 | |
| 5509 | double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) const |
| 5510 | { |