mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Improve SHAMapMissingNode
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
14
src/SHAMap.h
14
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user