Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 2,549 Lines • ▼ Show 20 Lines | bool Chainstate::FlushStateToDisk(BlockValidationState &state, | ||||
| bool full_flush_completed = false; | bool full_flush_completed = false; | ||||
| const size_t coins_count = CoinsTip().GetCacheSize(); | const size_t coins_count = CoinsTip().GetCacheSize(); | ||||
| const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage(); | const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage(); | ||||
| try { | try { | ||||
| { | { | ||||
| bool fFlushForPrune = false; | bool fFlushForPrune = false; | ||||
| bool fDoFullFlush = false; | |||||
| CoinsCacheSizeState cache_state = GetCoinsCacheSizeState(); | CoinsCacheSizeState cache_state = GetCoinsCacheSizeState(); | ||||
| LOCK(m_blockman.cs_LastBlockFile); | LOCK(m_blockman.cs_LastBlockFile); | ||||
| if (m_blockman.IsPruneMode() && | if (m_blockman.IsPruneMode() && | ||||
| (m_blockman.m_check_for_pruning || nManualPruneHeight > 0) && | (m_blockman.m_check_for_pruning || nManualPruneHeight > 0) && | ||||
| !fReindex) { | !fReindex) { | ||||
| // Make sure we don't prune any of the prune locks bestblocks. | // Make sure we don't prune any of the prune locks bestblocks. | ||||
| // Pruning is height-based. | // Pruning is height-based. | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | try { | ||||
| // The cache is over the limit, we have to write now. | // The cache is over the limit, we have to write now. | ||||
| bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && | bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && | ||||
| cache_state >= CoinsCacheSizeState::CRITICAL; | cache_state >= CoinsCacheSizeState::CRITICAL; | ||||
| // It's been a while since we wrote the block index and chain | // It's been a while since we wrote the block index and chain | ||||
| // state to disk. Do this frequently, so we don't need to | // state to disk. Do this frequently, so we don't need to | ||||
| // redownload or reindex after a crash. | // redownload or reindex after a crash. | ||||
| bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && | bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && | ||||
| nNow > m_last_write + DATABASE_WRITE_INTERVAL; | nNow > m_last_write + DATABASE_WRITE_INTERVAL; | ||||
| // Combine all conditions that result in a full cache flush. | // Combine all conditions that result in a write to disk. | ||||
| fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || | bool should_write = (mode == FlushStateMode::ALWAYS) || | ||||
| fCacheCritical || fPeriodicWrite || fFlushForPrune; | fCacheLarge || fCacheCritical || | ||||
| fPeriodicWrite || fFlushForPrune; | |||||
| // Write blocks, block index and best chain related state to disk. | // Write blocks, block index and best chain related state to disk. | ||||
| if (fDoFullFlush) { | if (should_write) { | ||||
| // Ensure we can write block index | // Ensure we can write block index | ||||
| if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) { | if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) { | ||||
| return AbortNode(state, "Disk space is too low!", | return AbortNode(state, "Disk space is too low!", | ||||
| _("Disk space is too low!")); | _("Disk space is too low!")); | ||||
| } | } | ||||
| { | { | ||||
| LOG_TIME_MILLIS_WITH_CATEGORY( | LOG_TIME_MILLIS_WITH_CATEGORY( | ||||
| ▲ Show 20 Lines • Show All 4,807 Lines • Show Last 20 Lines | |||||