Merge bitcoin/bitcoin#33866: refactor: Let CCoinsViewCache::BatchWrite return void

6da6f503a6 refactor: Let CCoinsViewCache::BatchWrite return void (TheCharlatan)

Pull request description:

  CCoinsViewCache::BatchWrite always returns true if called from a backed cache, so just return void instead. Also return void from ::Sync and ::Flush.

  This allows for dropping a FatalError condition and simplifying some dead error handling code a bit.

  Since we now no longer exercise the "error path" when returning from `CCoinsView::BatchWrite`, make the method clear the cache instead. This should only be exercised by tests and not change production behaviour. This might slightly improve the coins_view fuzz test's ability to generate better coverage.

ACKs for top commit:
  l0rinc:
    ACK 6da6f503a6
  andrewtoth:
    re-ACK 6da6f503a6
  achow101:
    ACK 6da6f503a6
  w0xlt:
    ACK 6da6f503a6

Tree-SHA512: dfaa325b0cf8108910aebf1b27434aaddb639d10d860e96797c77ea42eca9035a54a7dc1d6a5d4eae2b75fcc9356206d3d5672243d2c906e80d19024c8b95408
This commit is contained in:
Ava Chow
2026-01-02 16:49:23 -08:00
9 changed files with 41 additions and 50 deletions

View File

@@ -2845,9 +2845,7 @@ bool Chainstate::FlushStateToDisk(
}
// Flush the chainstate (which may refer to block index entries).
const auto empty_cache{(mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical};
if (empty_cache ? !CoinsTip().Flush() : !CoinsTip().Sync()) {
return FatalError(m_chainman.GetNotifications(), state, _("Failed to write to coin database."));
}
empty_cache ? CoinsTip().Flush() : CoinsTip().Sync();
full_flush_completed = true;
TRACEPOINT(utxocache, flush,
int64_t{Ticks<std::chrono::microseconds>(NodeClock::now() - nNow)},
@@ -2984,8 +2982,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
LogError("DisconnectTip(): DisconnectBlock %s failed\n", pindexDelete->GetBlockHash().ToString());
return false;
}
bool flushed = view.Flush(/*will_reuse_cache=*/false); // local CCoinsViewCache goes out of scope
assert(flushed);
view.Flush(/*will_reuse_cache=*/false); // local CCoinsViewCache goes out of scope
}
LogDebug(BCLog::BENCH, "- Disconnect block: %.2fms\n",
Ticks<MillisecondsDouble>(SteadyClock::now() - time_start));
@@ -3119,8 +3116,7 @@ bool Chainstate::ConnectTip(
Ticks<MillisecondsDouble>(time_3 - time_2),
Ticks<SecondsDouble>(m_chainman.time_connect_total),
Ticks<MillisecondsDouble>(m_chainman.time_connect_total) / m_chainman.num_blocks_total);
bool flushed = view.Flush(/*will_reuse_cache=*/false); // local CCoinsViewCache goes out of scope
assert(flushed);
view.Flush(/*will_reuse_cache=*/false); // local CCoinsViewCache goes out of scope
}
const auto time_4{SteadyClock::now()};
m_chainman.time_flush += time_4 - time_3;