From 2e16054a66b0576ec93d4032d6b74f0930a44fef Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 30 Jan 2023 11:45:14 -0500 Subject: [PATCH] Add assertions that BatchWrite(erase=true) erases --- src/coins.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coins.cpp b/src/coins.cpp index e2401365760..31ac67674a4 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -250,7 +250,10 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn bool CCoinsViewCache::Flush() { bool fOk = base->BatchWrite(cacheCoins, hashBlock, /*erase=*/true); - cacheCoins.clear(); + if (fOk && !cacheCoins.empty()) { + /* BatchWrite must erase all cacheCoins elements when erase=true. */ + throw std::logic_error("Not all cached coins were erased"); + } cachedCoinsUsage = 0; return fOk; }