mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Add CCoinsViewCache::SanityCheck() and use it in fuzz test
This commit is contained in:
@@ -314,6 +314,23 @@ void CCoinsViewCache::ReallocateCache()
|
||||
::new (&cacheCoins) CCoinsMap();
|
||||
}
|
||||
|
||||
void CCoinsViewCache::SanityCheck() const
|
||||
{
|
||||
size_t recomputed_usage = 0;
|
||||
for (const auto& [_, entry] : cacheCoins) {
|
||||
unsigned attr = 0;
|
||||
if (entry.flags & CCoinsCacheEntry::DIRTY) attr |= 1;
|
||||
if (entry.flags & CCoinsCacheEntry::FRESH) attr |= 2;
|
||||
if (entry.coin.IsSpent()) attr |= 4;
|
||||
// Only 5 combinations are possible.
|
||||
assert(attr != 2 && attr != 4 && attr != 7);
|
||||
|
||||
// Recompute cachedCoinsUsage.
|
||||
recomputed_usage += entry.coin.DynamicMemoryUsage();
|
||||
}
|
||||
assert(recomputed_usage == cachedCoinsUsage);
|
||||
}
|
||||
|
||||
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut(), PROTOCOL_VERSION);
|
||||
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user