mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-11 13:13:49 +01:00
Add linked-list test to CCoinsViewCache::SanityCheck
This commit is contained in:
committed by
Andrew Toth
parent
05cf4e1875
commit
0e8918755f
@@ -320,6 +320,7 @@ void CCoinsViewCache::ReallocateCache()
|
|||||||
void CCoinsViewCache::SanityCheck() const
|
void CCoinsViewCache::SanityCheck() const
|
||||||
{
|
{
|
||||||
size_t recomputed_usage = 0;
|
size_t recomputed_usage = 0;
|
||||||
|
size_t count_flagged = 0;
|
||||||
for (const auto& [_, entry] : cacheCoins) {
|
for (const auto& [_, entry] : cacheCoins) {
|
||||||
unsigned attr = 0;
|
unsigned attr = 0;
|
||||||
if (entry.IsDirty()) attr |= 1;
|
if (entry.IsDirty()) attr |= 1;
|
||||||
@@ -330,7 +331,22 @@ void CCoinsViewCache::SanityCheck() const
|
|||||||
|
|
||||||
// Recompute cachedCoinsUsage.
|
// Recompute cachedCoinsUsage.
|
||||||
recomputed_usage += entry.coin.DynamicMemoryUsage();
|
recomputed_usage += entry.coin.DynamicMemoryUsage();
|
||||||
|
|
||||||
|
// Count the number of entries we expect in the linked list.
|
||||||
|
if (entry.IsDirty() || entry.IsFresh()) ++count_flagged;
|
||||||
}
|
}
|
||||||
|
// Iterate over the linked list of flagged entries.
|
||||||
|
size_t count_linked = 0;
|
||||||
|
for (auto it = m_sentinel.second.Next(); it != &m_sentinel; it = it->second.Next()) {
|
||||||
|
// Verify linked list integrity.
|
||||||
|
assert(it->second.Next()->second.Prev() == it);
|
||||||
|
assert(it->second.Prev()->second.Next() == it);
|
||||||
|
// Verify they are actually flagged.
|
||||||
|
assert(it->second.IsDirty() || it->second.IsFresh());
|
||||||
|
// Count the number of entries actually in the list.
|
||||||
|
++count_linked;
|
||||||
|
}
|
||||||
|
assert(count_linked == count_flagged);
|
||||||
assert(recomputed_usage == cachedCoinsUsage);
|
assert(recomputed_usage == cachedCoinsUsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user