From 30dd46d8124bffdf2219919f5db8d4cf8e2b909d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 11 Oct 2012 02:50:04 -0700 Subject: [PATCH] Improve SHAMapMissingNode --- src/SHAMap.cpp | 18 ++++++++++++------ src/SHAMap.h | 14 ++++++++++++-- src/SHAMapSync.cpp | 7 ++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 5dd31f5651..533b9d6710 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -93,7 +93,8 @@ std::stack SHAMap::getStack(const uint256& id, bool inc { if (partialOk) return stack; - throw mn; + mn.setTargetNode(id); + throw; } } @@ -153,10 +154,15 @@ SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify) return inNode; uint256 childHash = inNode->getChildHash(branch); - SHAMapTreeNode::pointer nextNode = getNode(inNode->getChildNodeID(branch), childHash, false); - if (!nextNode) - throw SHAMapMissingNode(inNode->getChildNodeID(branch), childHash); - inNode = nextNode; + try + { + inNode = getNode(inNode->getChildNodeID(branch), childHash, false); + } + catch (SHAMapMissingNode& mn) + { + mn.setTargetNode(id); + throw; + } } if (inNode->getTag() != id) return SHAMapTreeNode::pointer(); @@ -175,7 +181,7 @@ SHAMapTreeNode* SHAMap::walkToPointer(const uint256& id) if (nextHash.isZero()) return NULL; inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash); if (!inNode) - throw SHAMapMissingNode(inNode->getChildNodeID(branch), nextHash); + throw SHAMapMissingNode(inNode->getChildNodeID(branch), nextHash, id); } return (inNode->getTag() == id) ? inNode : NULL; } diff --git a/src/SHAMap.h b/src/SHAMap.h index c239bad307..a942943b1a 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -241,16 +241,26 @@ class SHAMapMissingNode : public std::runtime_error protected: SHAMapNode mNodeID; uint256 mNodeHash; + uint256 mTargetIndex; public: SHAMapMissingNode(const SHAMapNode& nodeID, const uint256& nodeHash) : std::runtime_error(nodeID.getString()), mNodeID(nodeID), mNodeHash(nodeHash) { ; } + + SHAMapMissingNode(const SHAMapNode& nodeID, const uint256& nodeHash, const uint256& targetIndex) : + std::runtime_error(nodeID.getString()), mNodeID(nodeID), mNodeHash(nodeHash), mTargetIndex(targetIndex) + { ; } + virtual ~SHAMapMissingNode() throw() { ; } - const SHAMapNode& getNodeID() const { return mNodeID; } - const uint256& getNodeHash() const { return mNodeHash; } + void setTargetNode(const uint256& tn) { mTargetIndex = tn; } + + const SHAMapNode& getNodeID() const { return mNodeID; } + const uint256& getNodeHash() const { return mNodeHash; } + const uint256& getTargetIndex() const { return mTargetIndex; } + bool hasTargetIndex() const { return !mTargetIndex.isZero(); } }; class SHAMap diff --git a/src/SHAMapSync.cpp b/src/SHAMapSync.cpp index fef3cf04ad..baf7de9501 100644 --- a/src/SHAMapSync.cpp +++ b/src/SHAMapSync.cpp @@ -53,7 +53,7 @@ void SHAMap::getMissingNodes(std::vector& nodeIDs, std::vectorisInner() && !nextNode->isFullBelow()) return true; } - catch (SHAMapMissingNode) + catch (SHAMapMissingNode&) { return true; } } iNode->setFullBelow(); } while (!stack.empty()); - if (root->isFullBelow()) clearSynching(); + if (root->isFullBelow()) + clearSynching(); return true; }