diff --git a/src/ripple_app/shamap/SHAMap.cpp b/src/ripple_app/shamap/SHAMap.cpp index b7f271ca1..1c0d97462 100644 --- a/src/ripple_app/shamap/SHAMap.cpp +++ b/src/ripple_app/shamap/SHAMap.cpp @@ -61,7 +61,7 @@ SHAMap::SHAMap (SHAMapType t, uint256 const& hash, FullBelowCache& fullBelowCach mTNByID.replace(*root, root); } -TaggedCache< SHAMap::TNIndex, SHAMapTreeNode> +TaggedCache SHAMap::treeNodeCache ("TreeNodeCache", 65536, 60, get_seconds_clock (), LogPartition::getJournal ()); @@ -1263,15 +1263,29 @@ void SHAMap::dump (bool hash) SHAMapTreeNode::pointer SHAMap::getCache (uint256 const& hash, SHAMapNode const& id) { - SHAMapTreeNode::pointer ret = treeNodeCache.fetch (TNIndex (hash, id)); + SHAMapTreeNode::pointer ret = treeNodeCache.fetch (hash); assert (!ret || !ret->getSeq()); + + if (ret && (*ret != id)) + { + // We have the data, but with a different node ID + WriteLog (lsTRACE, SHAMap) << "ID mismatch: " << id << " != " << *ret; + ret = boost::make_shared (*ret, 0); + ret->set(id); + + // Future fetches are likely to use the "new" ID + treeNodeCache.canonicalize (hash, ret, true); + assert (*ret == id); + assert (ret->getNodeHash() == hash); + } + return ret; } void SHAMap::canonicalize (uint256 const& hash, SHAMapTreeNode::pointer& node) { assert (node->getSeq() == 0); - treeNodeCache.canonicalize (TNIndex (hash, *node), node); + treeNodeCache.canonicalize (hash, node); } //------------------------------------------------------------------------------ diff --git a/src/ripple_app/shamap/SHAMap.h b/src/ripple_app/shamap/SHAMap.h index 15c6f94ff..bb817aad8 100644 --- a/src/ripple_app/shamap/SHAMap.h +++ b/src/ripple_app/shamap/SHAMap.h @@ -270,10 +270,8 @@ public: treeNodeCache.setTargetAge (age); } - typedef std::pair TNIndex; - private: - static TaggedCache treeNodeCache; + static TaggedCache treeNodeCache; void dirtyUp (std::stack& stack, uint256 const & target, uint256 prevHash); std::stack getStack (uint256 const & id, bool include_nonmatching_leaf); diff --git a/src/ripple_app/shamap/SHAMapNode.h b/src/ripple_app/shamap/SHAMapNode.h index 39cd8e273..ef4fa7a01 100644 --- a/src/ripple_app/shamap/SHAMapNode.h +++ b/src/ripple_app/shamap/SHAMapNode.h @@ -92,6 +92,12 @@ public: { return n != mNodeID; } + void set (SHAMapNode const& from) + { + mNodeID = from.mNodeID; + mDepth = from.mDepth; + mHash = from.mHash; + } virtual std::string getString () const; void dump () const;