Don't put a leaf node in a fetch pack just because it moved.

This commit is contained in:
JoelKatz
2013-05-17 01:46:39 -07:00
parent 249d5575cd
commit c0e046a721
2 changed files with 19 additions and 5 deletions

View File

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

View File

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