First part of fetch acceleration changes. Includes a bugfix that I'll push to master.

This commit is contained in:
JoelKatz
2013-04-21 12:44:21 -07:00
parent b993c6ee32
commit 79ec8e6070
11 changed files with 272 additions and 28 deletions

View File

@@ -97,7 +97,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
node->setFullBelow();
if (mType == smtSTATE)
{
fullBelowCache.add(node->getHash());
fullBelowCache.add(node->getNodeHash());
dropBelow(node);
}
}
@@ -162,7 +162,7 @@ std::vector<uint256> SHAMap::getNeededHashes(int max)
node->setFullBelow();
if (mType == smtSTATE)
{
fullBelowCache.add(node->getHash());
fullBelowCache.add(node->getNodeHash());
dropBelow(node);
}
}
@@ -172,6 +172,38 @@ std::vector<uint256> SHAMap::getNeededHashes(int max)
return ret;
}
std::list< std::pair<uint256, std::vector<unsigned char> > >
getSyncInfo(SHAMap::pointer have, SHAMap::pointer want, int max)
{
std::list< std::pair< uint256, std::vector<unsigned char> > > ret;
SHAMapIterator haveI(*have, true, false);
SHAMapIterator wantI(*want, true, false);
SHAMapTreeNode *haveN = haveI.getNext();
SHAMapTreeNode *wantN = wantI.getNext();
while (wantN != NULL)
{
if (haveN && (haveN->getNodeHash() == wantN->getNodeHash()))
{ // they match, advance both
haveN = haveI.getNext();
wantN = wantI.getNext();
}
else if (haveN && (haveN->getNodeHash() < wantN->getNodeHash()))
{ // need to advance have pointer
haveN = haveI.getNext();
}
else
{ // unmatched inner node
Serializer s;
wantN->addRaw(s, snfPREFIX);
ret.push_back(std::make_pair(wantN->getNodeHash(), s.peekData()));
if (--max <= 0)
break;
wantN = wantI.getNext();
}
}
return ret;
}
bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector<SHAMapNode>& nodeIDs,
std::list<std::vector<unsigned char> >& rawNodes, bool fatRoot, bool fatLeaves)
{ // Gets a node and some of its children