mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-17 01:13:41 +02:00
Merge bitcoin/bitcoin#33680: validation: do not wipe utxo cache for stats/scans/snapshots
c6ca2b85a3validation: do not wipe utxo cache for stats/scans/snapshots (Pieter Wuille)7099e93d0arefactor: rename `FlushStateMode::ALWAYS` to `FORCE_FLUSH` (Lőrinc) Pull request description: Revival of https://github.com/bitcoin/bitcoin/pull/30610#issuecomment-3432564955 with the remaining comments applied on top > 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. (slightly updated after #30214) ACKs for top commit: optout21: reACKc6ca2b85a3cedwies: reACKc6ca2b8(trivial) achow101: ACKc6ca2b85a3sedited: ACKc6ca2b85a3Tree-SHA512: f3525a85dc512db4a0a9c749ad47c0d3fa44085a121aa54cd77646260a719c71f754ec6570ae77779c0ed68a24799116f79c686e7a17ce57a26f6a598f7bf926
This commit is contained in:
@@ -2769,8 +2769,9 @@ bool Chainstate::FlushStateToDisk(
|
||||
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cache_state >= CoinsCacheSizeState::CRITICAL;
|
||||
// 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.
|
||||
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 = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || 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",
|
||||
@@ -2818,7 +2819,6 @@ bool Chainstate::FlushStateToDisk(
|
||||
return FatalError(m_chainman.GetNotifications(), state, _("Disk space is too low!"));
|
||||
}
|
||||
// Flush the chainstate (which may refer to block index entries).
|
||||
const auto empty_cache{(mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical};
|
||||
empty_cache ? CoinsTip().Flush() : CoinsTip().Sync();
|
||||
full_flush_completed = true;
|
||||
TRACEPOINT(utxocache, flush,
|
||||
@@ -2845,10 +2845,10 @@ bool Chainstate::FlushStateToDisk(
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chainstate::ForceFlushStateToDisk()
|
||||
void Chainstate::ForceFlushStateToDisk(bool wipe_cache)
|
||||
{
|
||||
BlockValidationState state;
|
||||
if (!this->FlushStateToDisk(state, FlushStateMode::ALWAYS)) {
|
||||
if (!this->FlushStateToDisk(state, wipe_cache ? FlushStateMode::FORCE_FLUSH : FlushStateMode::FORCE_SYNC)) {
|
||||
LogWarning("Failed to force flush state (%s)", state.ToString());
|
||||
}
|
||||
}
|
||||
@@ -5531,7 +5531,7 @@ bool Chainstate::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
|
||||
ret = FlushStateToDisk(state, FlushStateMode::IF_NEEDED);
|
||||
} else {
|
||||
// Otherwise, flush state to disk and deallocate the in-memory coins map.
|
||||
ret = FlushStateToDisk(state, FlushStateMode::ALWAYS);
|
||||
ret = FlushStateToDisk(state, FlushStateMode::FORCE_FLUSH);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -5977,7 +5977,7 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
|
||||
// returns in `ActivateSnapshot()`, when `MaybeRebalanceCaches()` is
|
||||
// called, since we've added a snapshot chainstate and therefore will
|
||||
// have to downsize the IBD chainstate, which will result in a call to
|
||||
// `FlushStateToDisk(ALWAYS)`.
|
||||
// `FlushStateToDisk(FORCE_FLUSH)`.
|
||||
}
|
||||
|
||||
assert(index);
|
||||
|
||||
Reference in New Issue
Block a user