From dd44ea39bb6e1e2a244630909647ea7fbb052941 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Fri, 9 Dec 2016 12:28:22 -0500 Subject: Check FRESH validity in CCoinsViewCache::BatchWrite --- src/coins.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/coins.cpp') diff --git a/src/coins.cpp b/src/coins.cpp index 68f32a9da..4d0e4bc0a 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -207,6 +207,13 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn entry.flags |= CCoinsCacheEntry::FRESH; } } else { + // Assert that the child cache entry was not marked FRESH if the + // parent cache entry has unspent outputs. If this ever happens, + // it means the FRESH flag was misapplied and there is a logic + // error in the calling code. + if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coins.IsPruned()) + throw std::logic_error("FRESH flag misapplied to cache entry for base transaction with spendable outputs"); + // Found the entry in the parent cache if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coins.IsPruned()) { // The grandparent does not have an entry, and the child is -- cgit v1.2.3