@@ -2876,16 +2876,12 @@ bool Chainstate::FlushStateToDisk(
2876
2876
}
2877
2877
}
2878
2878
const auto nNow{NodeClock::now ()};
2879
- // Avoid writing/flushing immediately after startup.
2880
- if (m_last_write == decltype (m_last_write){}) {
2881
- m_last_write = nNow;
2882
- }
2883
2879
// 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).
2884
2880
bool fCacheLarge = mode == FlushStateMode::PERIODIC && cache_state >= CoinsCacheSizeState::LARGE;
2885
2881
// The cache is over the limit, we have to write now.
2886
2882
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cache_state >= CoinsCacheSizeState::CRITICAL;
2887
2883
// 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 redownload or reindex after a crash.
2888
- bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > m_last_write + DATABASE_WRITE_INTERVAL ;
2884
+ bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow >= m_next_write ;
2889
2885
// Combine all conditions that result in a write to disk.
2890
2886
bool should_write = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicWrite || fFlushForPrune ;
2891
2887
// Write blocks, block index and best chain related state to disk.
@@ -2946,7 +2942,10 @@ bool Chainstate::FlushStateToDisk(
2946
2942
(uint64_t )coins_mem_usage,
2947
2943
(bool )fFlushForPrune );
2948
2944
}
2949
- m_last_write = NodeClock::now ();
2945
+ }
2946
+
2947
+ if (should_write || m_next_write == NodeClock::time_point::max ()) {
2948
+ m_next_write = NodeClock::now () + DATABASE_WRITE_INTERVAL;
2950
2949
}
2951
2950
}
2952
2951
if (full_flush_completed && m_chainman.m_options .signals ) {
0 commit comments