Remove a lot of unneeded hashing.

This commit is contained in:
JoelKatz
2013-01-08 15:33:13 -08:00
parent 9c9530b50f
commit 3712f0f2cb
4 changed files with 21 additions and 18 deletions

View File

@@ -714,7 +714,8 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui
try try
{ {
SHAMapTreeNode::pointer ret = boost::make_shared<SHAMapTreeNode>(id, obj->getData(), mSeq - 1, snfPREFIX); SHAMapTreeNode::pointer ret =
boost::make_shared<SHAMapTreeNode>(id, obj->getData(), mSeq - 1, snfPREFIX, hash);
if (id != *ret) if (id != *ret)
{ {
cLog(lsFATAL) << "id:" << id << ", got:" << *ret; cLog(lsFATAL) << "id:" << id << ", got:" << *ret;

View File

@@ -176,7 +176,8 @@ public:
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::ref item, TNType type, uint32 seq); SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::ref item, TNType type, uint32 seq);
// raw node functions // raw node functions
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq, SHANodeFormat format); SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq,
SHANodeFormat format, const uint256& hash);
void addRaw(Serializer &, SHANodeFormat format); void addRaw(Serializer &, SHANodeFormat format);
virtual bool isPopulated() const { return true; } virtual bool isPopulated() const { return true; }

View File

@@ -197,7 +197,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::ref item, TNT
} }
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& rawNode, uint32 seq, SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& rawNode, uint32 seq,
SHANodeFormat format) : SHAMapNode(id), mSeq(seq), mType(tnERROR), mFullBelow(false) SHANodeFormat format, const uint256& hash) : SHAMapNode(id), mSeq(seq), mType(tnERROR), mFullBelow(false)
{ {
if (format == snfWIRE) if (format == snfWIRE)
{ {
@@ -326,7 +326,16 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
throw std::runtime_error("Unknown format"); throw std::runtime_error("Unknown format");
} }
updateHash(); if (hash.isZero())
updateHash();
else
{
mHash = hash;
#ifdef PARANOID
updateHash();
assert(mHash == hash);
#endif
}
} }
bool SHAMapTreeNode::updateHash() bool SHAMapTreeNode::updateHash()

View File

@@ -61,17 +61,9 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
std::vector<unsigned char> nodeData; std::vector<unsigned char> nodeData;
if (filter->haveNode(childID, childHash, nodeData)) if (filter->haveNode(childID, childHash, nodeData))
{ {
d = boost::make_shared<SHAMapTreeNode>(childID, nodeData, mSeq, snfPREFIX); d = boost::make_shared<SHAMapTreeNode>(childID, nodeData, mSeq, snfPREFIX, childHash);
if (childHash != d->getNodeHash()) cLog(lsTRACE) << "Got sync node from cache: " << *d;
{ mTNByID[*d] = d;
cLog(lsERROR) << "Wrong hash from cached object";
d.reset();
}
else
{
cLog(lsTRACE) << "Got sync node from cache: " << *d;
mTNByID[*d] = d;
}
} }
} }
} }
@@ -200,7 +192,7 @@ SMAddNode SHAMap::addRootNode(const std::vector<unsigned char>& rootNode, SHANod
return SMAddNode::okay(); return SMAddNode::okay();
} }
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format); SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format, uint256());
if (!node) if (!node)
return SMAddNode::invalid(); return SMAddNode::invalid();
@@ -240,7 +232,7 @@ SMAddNode SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned ch
return SMAddNode::okay(); return SMAddNode::okay();
} }
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format); SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format, uint256());
if (!node || node->getNodeHash() != hash) if (!node || node->getNodeHash() != hash)
return SMAddNode::invalid(); return SMAddNode::invalid();
@@ -318,7 +310,7 @@ SMAddNode SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigne
return SMAddNode::invalid(); return SMAddNode::invalid();
} }
SHAMapTreeNode::pointer newNode = boost::make_shared<SHAMapTreeNode>(node, rawNode, mSeq, snfWIRE); SHAMapTreeNode::pointer newNode = boost::make_shared<SHAMapTreeNode>(node, rawNode, mSeq, snfWIRE, uint256());
if (hash != newNode->getNodeHash()) // these aren't the droids we're looking for if (hash != newNode->getNodeHash()) // these aren't the droids we're looking for
return SMAddNode::invalid(); return SMAddNode::invalid();