From ebd9aa11b108071795c53a8abaf5fe8043dcc6db Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Mon, 5 Dec 2016 13:42:30 -0700 Subject: [PATCH] Ensure cache contains valid entry when anchor is popped. --- src/coins.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index c861bb81e..65c25f131 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -176,11 +176,20 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) { // case restoring the "old" anchor during a reorg must // have no effect. if (currentRoot != newrt) { - CAnchorsMap::iterator ret = cacheAnchors.insert(std::make_pair(currentRoot, CAnchorsCacheEntry())).first; + // Bring the current best anchor into our local cache + // so that its tree exists in memory. + { + ZCIncrementalMerkleTree tree; + assert(GetAnchorAt(currentRoot, tree)); + } - ret->second.entered = false; - ret->second.flags = CAnchorsCacheEntry::DIRTY; + // Mark the anchor as unentered, removing it from view + cacheAnchors[currentRoot].entered = false; + // Mark the cache entry as dirty so it's propagated + cacheAnchors[currentRoot].flags = CAnchorsCacheEntry::DIRTY; + + // Mark the new root as the best anchor hashAnchor = newrt; } }