Improve SHAMapMissingNode

This commit is contained in:
JoelKatz
2012-10-11 02:50:04 -07:00
parent f81a3c623a
commit 30dd46d812
3 changed files with 28 additions and 11 deletions

View File

@@ -93,7 +93,8 @@ std::stack<SHAMapTreeNode::pointer> 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;
}

View File

@@ -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

View File

@@ -53,7 +53,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
{
d = getNode(childID, childHash, false);
}
catch (SHAMapMissingNode& )
catch (SHAMapMissingNode&)
{ // node is not in the map
if (filter != NULL)
{
@@ -269,14 +269,15 @@ bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigned cha
if (nextNode->isInner() && !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;
}