mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix bugs, typo in SHAMapNodeID
This commit is contained in:
committed by
Vinnie Falco
parent
63f099f2f6
commit
84c6622122
@@ -444,7 +444,7 @@ SHAMap::lastBelow (SHAMapTreeNode* node, SHAMapNodeID nodeID)
|
||||
if (node->hasItem ())
|
||||
return node;
|
||||
bool foundNode = false;
|
||||
for (int i = 15; i >= 0; ++i)
|
||||
for (int i = 15; i >= 0; --i)
|
||||
{
|
||||
uint256 nodeHash;
|
||||
if (node->descend (i, nodeID, nodeHash))
|
||||
@@ -467,14 +467,17 @@ SHAMap::onlyBelow (SHAMapTreeNode* node, SHAMapNodeID nodeID)
|
||||
while (!node->isLeaf ())
|
||||
{
|
||||
SHAMapTreeNode* nextNode = nullptr;
|
||||
SHAMapNodeID nextNodeID;
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
SHAMapNodeID tempNodeID = nodeID;
|
||||
uint256 nodeHash;
|
||||
if (node->descend (i, nodeID, nodeHash))
|
||||
if (node->descend (i, tempNodeID, nodeHash))
|
||||
{
|
||||
if (nextNode)
|
||||
return SHAMapItem::pointer (); // two leaves below
|
||||
nextNode = getNodePointer (nodeID, nodeHash);
|
||||
nextNode = getNodePointer (tempNodeID, nodeHash);
|
||||
nextNodeID = tempNodeID;
|
||||
}
|
||||
}
|
||||
if (!nextNode)
|
||||
@@ -485,6 +488,7 @@ SHAMap::onlyBelow (SHAMapTreeNode* node, SHAMapNodeID nodeID)
|
||||
}
|
||||
|
||||
node = nextNode;
|
||||
nodeID = nextNodeID;
|
||||
}
|
||||
|
||||
assert (node->hasItem ());
|
||||
@@ -600,14 +604,16 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT
|
||||
else
|
||||
{
|
||||
uint256 nodeHash;
|
||||
// breadth-first
|
||||
for (int i = nodeID.selectBranch (id) + 1; i < 16; ++i)
|
||||
{
|
||||
if (node->descend (i, nodeID, nodeHash))
|
||||
SHAMapNodeID childNodeID = nodeID;
|
||||
if (node->descend (i, childNodeID, nodeHash))
|
||||
{
|
||||
SHAMapTreeNode* firstNode = getNodePointer (nodeID,
|
||||
nodeHash);
|
||||
SHAMapTreeNode* firstNode = getNodePointer (
|
||||
childNodeID, nodeHash);
|
||||
assert (firstNode);
|
||||
firstNode = firstBelow (firstNode, nodeID);
|
||||
firstNode = firstBelow (firstNode, childNodeID);
|
||||
|
||||
if (!firstNode || firstNode->isInner ())
|
||||
throw (std::runtime_error ("missing/corrupt node"));
|
||||
|
||||
@@ -496,6 +496,7 @@ bool SHAMapTreeNode::setChildHash (int m, uint256 const& hash)
|
||||
bool
|
||||
SHAMapTreeNode::descend (int branch, SHAMapNodeID& nodeID, uint256& nodeHash)
|
||||
{
|
||||
assert (branch >= 0 && branch < 16);
|
||||
assert (isInnerNode ());
|
||||
|
||||
if (isEmptyBranch (branch))
|
||||
|
||||
@@ -175,15 +175,15 @@ public:
|
||||
virtual void dump (SHAMapNodeID const&);
|
||||
virtual std::string getString (SHAMapNodeID const&) const;
|
||||
|
||||
/** Descends along the specified branch
|
||||
* On invocation, nodeID must be the ID of this node
|
||||
* Returns false if there is no node down that branch
|
||||
* Otherwise, returns true and fills in the node's ID and hash
|
||||
*
|
||||
* @param branch the branch to descend [0, 15]
|
||||
* @param nodeID on entry the ID of the parent. On exit the ID of the child
|
||||
* @param nodeHash on exit the hash of the child node.
|
||||
* @return true if nodeID and nodeHash are altered.
|
||||
/** Descend along the specified branch
|
||||
On invocation, nodeID must be the ID of this node
|
||||
Returns `false` if there is no node down that branch
|
||||
Otherwise, returns `true` and fills in the node's ID and hash
|
||||
|
||||
@param branch The branch to descend [0, 15]
|
||||
@param nodeID On entry the ID of the parent. On exit the ID of the child
|
||||
@param nodeHash On exit the hash of the child node.
|
||||
@return `true` if nodeID and nodeHash are altered.
|
||||
*/
|
||||
bool descend (int branch, SHAMapNodeID& nodeID, uint256& nodeHash);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user