diff options
author | Pieter Wuille <pieter@wuille.net> | 2023-02-01 18:28:08 -0500 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2023-02-01 23:14:12 -0500 |
commit | b0ff31084006ac7d4a7afba3190ca75f5f8441af (patch) | |
tree | 909dc06de479080bab43ca090efaa8ea2b359b9c /src/coins.cpp | |
parent | 3c9cea1340fd1358d6854209d782922864945eb0 (diff) | |
download | bitcoin-b0ff31084006ac7d4a7afba3190ca75f5f8441af.tar.xz |
Add CCoinsViewCache::SanityCheck() and use it in fuzz test
Diffstat (limited to 'src/coins.cpp')
-rw-r--r-- | src/coins.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/coins.cpp b/src/coins.cpp index e98bf816ab..8d99019bb0 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -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; |