mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-10 06:39:15 +02:00
validation: do not wipe utxo cache for stats/scans/snapshots
Since #28280, the cost of a non-wiping sync of the UTXO cache is only proportional to the number of dirty entries, rather than proportional to the size of the entire cache. Because of that, there is no reason to perform a wiping flush in case the contents of the cache is still useful. Split the FlushStateMode::ALWAYS mode into a FORCE_SYNC (non-wiping) and a FORCE_FLUSH (wiping), and then use the former in scantxoutset, gettxoutsetinfo, snapshot creation. Co-authored-by: l0rinc <pap.lorinc@gmail.com> Co-authored-by: cedwies <141683552+cedwies@users.noreply.github.com>
This commit is contained in:
@@ -2797,7 +2797,7 @@ bool Chainstate::FlushStateToDisk(
|
||||
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow >= m_next_write;
|
||||
const auto empty_cache{(mode == FlushStateMode::FORCE_FLUSH) || fCacheLarge || fCacheCritical};
|
||||
// Combine all conditions that result in a write to disk.
|
||||
bool should_write = empty_cache || fPeriodicWrite || fFlushForPrune;
|
||||
bool should_write = (mode == FlushStateMode::FORCE_SYNC) || empty_cache || fPeriodicWrite || fFlushForPrune;
|
||||
// Write blocks, block index and best chain related state to disk.
|
||||
if (should_write) {
|
||||
LogDebug(BCLog::COINDB, "Writing chainstate to disk: flush mode=%s, prune=%d, large=%d, critical=%d, periodic=%d",
|
||||
@@ -2871,10 +2871,10 @@ bool Chainstate::FlushStateToDisk(
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chainstate::ForceFlushStateToDisk()
|
||||
void Chainstate::ForceFlushStateToDisk(bool wipe_cache)
|
||||
{
|
||||
BlockValidationState state;
|
||||
if (!this->FlushStateToDisk(state, FlushStateMode::FORCE_FLUSH)) {
|
||||
if (!this->FlushStateToDisk(state, wipe_cache ? FlushStateMode::FORCE_FLUSH : FlushStateMode::FORCE_SYNC)) {
|
||||
LogWarning("Failed to force flush state (%s)", state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user