mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Don't put a leaf node in a fetch pack just because it moved.
This commit is contained in:
@@ -377,7 +377,8 @@ protected:
|
||||
SHAMapItem::pointer onlyBelow(SHAMapTreeNode*);
|
||||
void eraseChildren(SHAMapTreeNode::pointer);
|
||||
void dropBelow(SHAMapTreeNode*);
|
||||
bool hasNode(const SHAMapNode& id, const uint256& hash);
|
||||
bool hasInnerNode(const SHAMapNode& nodeID, const uint256& hash);
|
||||
bool hasLeafNode(const uint256& tag, const uint256& hash);
|
||||
|
||||
bool walkBranch(SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, bool isFirstMap,
|
||||
SHAMapDiff& differences, int& maxCount);
|
||||
|
||||
@@ -410,7 +410,7 @@ bool SHAMap::deepCompare(SHAMap& other)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::hasNode(const SHAMapNode& nodeID, const uint256& nodeHash)
|
||||
bool SHAMap::hasInnerNode(const SHAMapNode& nodeID, const uint256& nodeHash)
|
||||
{
|
||||
SHAMapTreeNode* node = root.get();
|
||||
while (node->isInner() && (node->getDepth() < nodeID.getDepth()))
|
||||
@@ -423,6 +423,19 @@ bool SHAMap::hasNode(const SHAMapNode& nodeID, const uint256& nodeHash)
|
||||
return node->getNodeHash() == nodeHash;
|
||||
}
|
||||
|
||||
bool SHAMap::hasLeafNode(const uint256& tag, const uint256& nodeHash)
|
||||
{
|
||||
SHAMapTreeNode* node = root.get();
|
||||
while (node->isInner())
|
||||
{
|
||||
int branch = node->selectBranch(tag);
|
||||
if (node->isEmptyBranch(branch))
|
||||
return false;
|
||||
node = getNodePointer(node->getChildNodeID(branch), node->getChildHash(branch));
|
||||
}
|
||||
return node->getNodeHash() == nodeHash;
|
||||
}
|
||||
|
||||
std::list<SHAMap::fetchPackEntry_t> SHAMap::getFetchPack(SHAMap* have, bool includeLeaves, int max)
|
||||
{
|
||||
std::list<fetchPackEntry_t> ret;
|
||||
@@ -446,7 +459,7 @@ std::list<SHAMap::fetchPackEntry_t> SHAMap::getFetchPack(SHAMap* have, bool incl
|
||||
if (root->isLeaf())
|
||||
{
|
||||
if (includeLeaves && !root->getNodeHash().isZero() &&
|
||||
(!have || !have->hasNode(*root, root->getNodeHash())))
|
||||
(!have || !have->hasLeafNode(root->getTag(), root->getNodeHash())))
|
||||
{
|
||||
Serializer s;
|
||||
root->addRaw(s, snfPREFIX);
|
||||
@@ -486,10 +499,10 @@ std::list<SHAMap::fetchPackEntry_t> SHAMap::getFetchPack(SHAMap* have, bool incl
|
||||
SHAMapTreeNode *next = getNodePointer(childID, childHash);
|
||||
if (next->isInner())
|
||||
{
|
||||
if (!have || !have->hasNode(*next, childHash))
|
||||
if (!have || !have->hasInnerNode(*next, childHash))
|
||||
stack.push(next);
|
||||
}
|
||||
else if (includeLeaves && (!have || !have->hasNode(childID, childHash)))
|
||||
if (includeLeaves && (!have || !have->hasLeafNode(next->getTag(), childHash)))
|
||||
{
|
||||
Serializer s;
|
||||
node->addRaw(s, snfPREFIX);
|
||||
|
||||
Reference in New Issue
Block a user