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,606 Lines • ▼ Show 20 Lines | try { | ||||
| if (!m_blockman.m_have_pruned) { | if (!m_blockman.m_have_pruned) { | ||||
| m_blockman.m_block_tree_db->WriteFlag( | m_blockman.m_block_tree_db->WriteFlag( | ||||
| "prunedblockfiles", true); | "prunedblockfiles", true); | ||||
| m_blockman.m_have_pruned = true; | m_blockman.m_have_pruned = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| const auto nNow{NodeClock::now()}; | const auto nNow{NodeClock::now()}; | ||||
| // Avoid writing/flushing immediately after startup. | |||||
| if (m_last_write == decltype(m_last_write){}) { | |||||
| m_last_write = nNow; | |||||
| } | |||||
| // The cache is large and we're within 10% and 10 MiB of the limit, | // The cache is large and we're within 10% and 10 MiB of the limit, | ||||
| // but we have time now (not in the middle of a block processing). | // but we have time now (not in the middle of a block processing). | ||||
| bool fCacheLarge = mode == FlushStateMode::PERIODIC && | bool fCacheLarge = mode == FlushStateMode::PERIODIC && | ||||
| cache_state >= CoinsCacheSizeState::LARGE; | cache_state >= CoinsCacheSizeState::LARGE; | ||||
| // 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 = | ||||
| nNow > m_last_write + DATABASE_WRITE_INTERVAL; | mode == FlushStateMode::PERIODIC && nNow >= m_next_write; | ||||
| // Combine all conditions that result in a write to disk. | // Combine all conditions that result in a write to disk. | ||||
| bool should_write = (mode == FlushStateMode::ALWAYS) || | bool should_write = (mode == FlushStateMode::ALWAYS) || | ||||
| fCacheLarge || fCacheCritical || | fCacheLarge || fCacheCritical || | ||||
| fPeriodicWrite || fFlushForPrune; | 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 (should_write) { | if (should_write) { | ||||
| // Ensure we can write block index | // Ensure we can write block index | ||||
| if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) { | if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) { | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | try { | ||||
| } | } | ||||
| full_flush_completed = true; | full_flush_completed = true; | ||||
| TRACE5(utxocache, flush, | TRACE5(utxocache, flush, | ||||
| int64_t{Ticks<std::chrono::microseconds>( | int64_t{Ticks<std::chrono::microseconds>( | ||||
| SteadyClock::now() - nNow)}, | SteadyClock::now() - nNow)}, | ||||
| uint32_t(mode), coins_count, | uint32_t(mode), coins_count, | ||||
| uint64_t(coins_mem_usage), fFlushForPrune); | uint64_t(coins_mem_usage), fFlushForPrune); | ||||
| } | } | ||||
| m_last_write = NodeClock::now(); | } | ||||
| if (should_write || m_next_write == NodeClock::time_point::max()) { | |||||
| m_next_write = NodeClock::now() + DATABASE_WRITE_INTERVAL; | |||||
| } | } | ||||
| } | } | ||||
| if (full_flush_completed) { | if (full_flush_completed) { | ||||
| // Update best block in wallet (so we can detect restored wallets). | // Update best block in wallet (so we can detect restored wallets). | ||||
| GetMainSignals().ChainStateFlushed(this->GetRole(), | GetMainSignals().ChainStateFlushed(this->GetRole(), | ||||
| m_chain.GetLocator()); | m_chain.GetLocator()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 4,729 Lines • Show Last 20 Lines | |||||