| 4946 | } |
| 4947 | |
| 4948 | bool CChainState::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size) |
| 4949 | { |
| 4950 | AssertLockHeld(::cs_main); |
| 4951 | if (coinstip_size == m_coinstip_cache_size_bytes && |
| 4952 | coinsdb_size == m_coinsdb_cache_size_bytes) { |
| 4953 | // Cache sizes are unchanged, no need to continue. |
| 4954 | return true; |
| 4955 | } |
| 4956 | size_t old_coinstip_size = m_coinstip_cache_size_bytes; |
| 4957 | m_coinstip_cache_size_bytes = coinstip_size; |
| 4958 | m_coinsdb_cache_size_bytes = coinsdb_size; |
| 4959 | CoinsDB().ResizeCache(coinsdb_size); |
| 4960 | |
| 4961 | LogPrintf("[%s] resized coinsdb cache to %.1f MiB\n", |
| 4962 | this->ToString(), coinsdb_size * (1.0 / 1024 / 1024)); |
| 4963 | LogPrintf("[%s] resized coinstip cache to %.1f MiB\n", |
| 4964 | this->ToString(), coinstip_size * (1.0 / 1024 / 1024)); |
| 4965 | |
| 4966 | BlockValidationState state; |
| 4967 | bool ret; |
| 4968 | |
| 4969 | if (coinstip_size > old_coinstip_size) { |
| 4970 | // Likely no need to flush if cache sizes have grown. |
| 4971 | ret = FlushStateToDisk(state, FlushStateMode::IF_NEEDED); |
| 4972 | } else { |
| 4973 | // Otherwise, flush state to disk and deallocate the in-memory coins map. |
| 4974 | ret = FlushStateToDisk(state, FlushStateMode::ALWAYS); |
| 4975 | CoinsTip().ReallocateCache(); |
| 4976 | } |
| 4977 | return ret; |
| 4978 | } |
| 4979 | |
| 4980 | static const uint64_t MEMPOOL_DUMP_VERSION = 1; |
| 4981 | |