@@ -93,7 +93,7 @@ void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possi
93
93
//
94
94
// If the coin doesn't exist in the current cache, or is spent but not
95
95
// DIRTY, then it can be marked FRESH.
96
- fresh = !( it->second .flags & CCoinsCacheEntry::DIRTY );
96
+ fresh = !it->second .IsDirty ( );
97
97
}
98
98
it->second .coin = std::move (coin);
99
99
it->second .flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0 );
@@ -138,7 +138,7 @@ bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
138
138
if (moveout) {
139
139
*moveout = std::move (it->second .coin );
140
140
}
141
- if (it->second .flags & CCoinsCacheEntry::FRESH ) {
141
+ if (it->second .IsFresh () ) {
142
142
cacheCoins.erase (it);
143
143
} else {
144
144
it->second .flags |= CCoinsCacheEntry::DIRTY;
@@ -183,14 +183,14 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn
183
183
it != mapCoins.end ();
184
184
it = erase ? mapCoins.erase (it) : std::next (it)) {
185
185
// Ignore non-dirty entries (optimization).
186
- if (!( it->second .flags & CCoinsCacheEntry::DIRTY )) {
186
+ if (!it->second .IsDirty ( )) {
187
187
continue ;
188
188
}
189
189
CCoinsMap::iterator itUs = cacheCoins.find (it->first );
190
190
if (itUs == cacheCoins.end ()) {
191
191
// The parent cache does not have an entry, while the child cache does.
192
192
// We can ignore it if it's both spent and FRESH in the child
193
- if (!(it->second .flags & CCoinsCacheEntry::FRESH && it->second .coin .IsSpent ())) {
193
+ if (!(it->second .IsFresh () && it->second .coin .IsSpent ())) {
194
194
// Create the coin in the parent cache, move the data up
195
195
// and mark it as dirty.
196
196
CCoinsCacheEntry& entry = cacheCoins[it->first ];
@@ -207,21 +207,21 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn
207
207
// We can mark it FRESH in the parent if it was FRESH in the child
208
208
// Otherwise it might have just been flushed from the parent's cache
209
209
// and already exist in the grandparent
210
- if (it->second .flags & CCoinsCacheEntry::FRESH ) {
210
+ if (it->second .IsFresh () ) {
211
211
entry.flags |= CCoinsCacheEntry::FRESH;
212
212
}
213
213
}
214
214
} else {
215
215
// Found the entry in the parent cache
216
- if (( it->second .flags & CCoinsCacheEntry::FRESH ) && !itUs->second .coin .IsSpent ()) {
216
+ if (it->second .IsFresh ( ) && !itUs->second .coin .IsSpent ()) {
217
217
// The coin was marked FRESH in the child cache, but the coin
218
218
// exists in the parent cache. If this ever happens, it means
219
219
// the FRESH flag was misapplied and there is a logic error in
220
220
// the calling code.
221
221
throw std::logic_error (" FRESH flag misapplied to coin that exists in parent cache" );
222
222
}
223
223
224
- if (( itUs->second .flags & CCoinsCacheEntry::FRESH ) && it->second .coin .IsSpent ()) {
224
+ if (itUs->second .IsFresh ( ) && it->second .coin .IsSpent ()) {
225
225
// The grandparent cache does not have an entry, and the coin
226
226
// has been spent. We can just delete it from the parent cache.
227
227
cachedCoinsUsage -= itUs->second .coin .DynamicMemoryUsage ();
@@ -283,7 +283,7 @@ bool CCoinsViewCache::Sync()
283
283
void CCoinsViewCache::Uncache (const COutPoint& hash)
284
284
{
285
285
CCoinsMap::iterator it = cacheCoins.find (hash);
286
- if (it != cacheCoins.end () && it->second .flags == 0 ) {
286
+ if (it != cacheCoins.end () && ! it->second .IsDirty () && !it-> second . IsFresh () ) {
287
287
cachedCoinsUsage -= it->second .coin .DynamicMemoryUsage ();
288
288
TRACE5 (utxocache, uncache,
289
289
hash.hash .data (),
@@ -326,8 +326,8 @@ void CCoinsViewCache::SanityCheck() const
326
326
size_t recomputed_usage = 0 ;
327
327
for (const auto & [_, entry] : cacheCoins) {
328
328
unsigned attr = 0 ;
329
- if (entry.flags & CCoinsCacheEntry::DIRTY ) attr |= 1 ;
330
- if (entry.flags & CCoinsCacheEntry::FRESH ) attr |= 2 ;
329
+ if (entry.IsDirty () ) attr |= 1 ;
330
+ if (entry.IsFresh () ) attr |= 2 ;
331
331
if (entry.coin .IsSpent ()) attr |= 4 ;
332
332
// Only 5 combinations are possible.
333
333
assert (attr != 2 && attr != 4 && attr != 7 );
0 commit comments