From 5271a750ccfe6caa1a9e46d378474d4d68a047b9 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 17 Jul 2013 19:52:35 -0700 Subject: [PATCH] Cleanups. --- src/cpp/ripple/ripple_SHAMap.cpp | 26 ++++++++++++-------------- src/cpp/ripple/ripple_SHAMap.h | 2 +- src/cpp/ripple/ripple_SHAMapSync.cpp | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/cpp/ripple/ripple_SHAMap.cpp b/src/cpp/ripple/ripple_SHAMap.cpp index d60bc51cd8..3782e7a4a9 100644 --- a/src/cpp/ripple/ripple_SHAMap.cpp +++ b/src/cpp/ripple/ripple_SHAMap.cpp @@ -69,7 +69,7 @@ SHAMap::pointer SHAMap::snapShot (bool isMutable) return ret; } -std::stack SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf, bool partialOk) +std::stack SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf) { // Walk the tree as far as possible to the specified identifier // produce a stack of nodes along the way, with the terminal node at the top @@ -92,9 +92,6 @@ std::stack SHAMap::getStack (uint256 const& id, bool in } catch (SHAMapMissingNode& mn) { - if (partialOk) - return stack; - mn.setTargetNode (id); throw; } @@ -317,7 +314,8 @@ SHAMapTreeNode* SHAMap::firstBelow (SHAMapTreeNode* node) do { // Walk down the tree - if (node->hasItem ()) return node; + if (node->hasItem ()) + return node; bool foundNode = false; @@ -468,10 +466,10 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id) SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNType& type) { - // Get a pointer to the next item in the tree after a given item - item must be in tree + // Get a pointer to the next item in the tree after a given item - item need not be in tree boost::recursive_mutex::scoped_lock sl (mLock); - std::stack stack = getStack (id, true, false); + std::stack stack = getStack (id, true); while (!stack.empty ()) { @@ -494,8 +492,8 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT assert (firstNode); firstNode = firstBelow (firstNode); - if (!firstNode) - throw std::runtime_error ("missing node"); + if (!firstNode || firstNode->isInner ()) + throw std::runtime_error ("missing/corrupt node"); type = firstNode->getType (); return firstNode->peekItem (); @@ -506,12 +504,12 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT return no_item; } -// Get a pointer to the previous item in the tree after a given item - item must be in tree +// Get a pointer to the previous item in the tree after a given item - item need not be in tree SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id) { boost::recursive_mutex::scoped_lock sl (mLock); - std::stack stack = getStack (id, true, false); + std::stack stack = getStack (id, true); while (!stack.empty ()) { @@ -596,7 +594,7 @@ bool SHAMap::delItem (uint256 const& id) boost::recursive_mutex::scoped_lock sl (mLock); assert (mState != smsImmutable); - std::stack stack = getStack (id, true, false); + std::stack stack = getStack (id, true); if (stack.empty ()) throw std::runtime_error ("missing node"); @@ -677,7 +675,7 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta boost::recursive_mutex::scoped_lock sl (mLock); assert (mState != smsImmutable); - std::stack stack = getStack (tag, true, false); + std::stack stack = getStack (tag, true); if (stack.empty ()) throw std::runtime_error ("missing node"); @@ -775,7 +773,7 @@ bool SHAMap::updateGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasM boost::recursive_mutex::scoped_lock sl (mLock); assert (mState != smsImmutable); - std::stack stack = getStack (tag, true, false); + std::stack stack = getStack (tag, true); if (stack.empty ()) throw std::runtime_error ("missing node"); diff --git a/src/cpp/ripple/ripple_SHAMap.h b/src/cpp/ripple/ripple_SHAMap.h index d6d196c4be..b195dd4f20 100644 --- a/src/cpp/ripple/ripple_SHAMap.h +++ b/src/cpp/ripple/ripple_SHAMap.h @@ -193,7 +193,7 @@ private: static KeyCache fullBelowCache; void dirtyUp (std::stack& stack, uint256 const & target, uint256 prevHash); - std::stack getStack (uint256 const & id, bool include_nonmatching_leaf, bool partialOk); + std::stack getStack (uint256 const & id, bool include_nonmatching_leaf); SHAMapTreeNode::pointer walkTo (uint256 const & id, bool modify); SHAMapTreeNode* walkToPointer (uint256 const & id); SHAMapTreeNode::pointer checkCacheNode (const SHAMapNode&); diff --git a/src/cpp/ripple/ripple_SHAMapSync.cpp b/src/cpp/ripple/ripple_SHAMapSync.cpp index 438b83d4b6..2520dbd4ee 100644 --- a/src/cpp/ripple/ripple_SHAMapSync.cpp +++ b/src/cpp/ripple/ripple_SHAMapSync.cpp @@ -571,7 +571,7 @@ void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max, std::list SHAMap::getTrustedPath (uint256 const& index) { boost::recursive_mutex::scoped_lock sl (mLock); - std::stack stack = SHAMap::getStack (index, false, false); + std::stack stack = SHAMap::getStack (index, false); if (stack.empty () || !stack.top ()->isLeaf ()) throw std::runtime_error ("requested leaf not present");