mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 19:53:27 +01:00
coins: move Sync logic to CoinsViewCacheCursor
Erase spent cache entries and clear flags of unspent entries inside the BatchWrite loop, instead of an additional loop after BatchWrite. Co-Authored-By: Pieter Wuille <pieter@wuille.net>
This commit is contained in:
@@ -267,15 +267,10 @@ bool CCoinsViewCache::Sync()
|
||||
{
|
||||
auto cursor{CoinsViewCacheCursor(cachedCoinsUsage, m_sentinel, cacheCoins, /*will_erase=*/false)};
|
||||
bool fOk = base->BatchWrite(cursor, hashBlock);
|
||||
// Instead of clearing `cacheCoins` as we would in Flush(), just clear the
|
||||
// FRESH/DIRTY flags of any coin that isn't spent.
|
||||
for (auto it = cacheCoins.begin(); it != cacheCoins.end(); ) {
|
||||
if (it->second.coin.IsSpent()) {
|
||||
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
|
||||
it = cacheCoins.erase(it);
|
||||
} else {
|
||||
it->second.ClearFlags();
|
||||
++it;
|
||||
if (fOk) {
|
||||
if (m_sentinel.second.Next() != &m_sentinel) {
|
||||
/* BatchWrite must clear flags of all entries */
|
||||
throw std::logic_error("Not all unspent flagged entries were cleared");
|
||||
}
|
||||
}
|
||||
return fOk;
|
||||
|
||||
Reference in New Issue
Block a user