mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Remove a lot of unneeded hashing.
This commit is contained in:
@@ -714,7 +714,8 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui
|
||||
|
||||
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)
|
||||
{
|
||||
cLog(lsFATAL) << "id:" << id << ", got:" << *ret;
|
||||
|
||||
@@ -176,7 +176,8 @@ public:
|
||||
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::ref item, TNType type, uint32 seq);
|
||||
|
||||
// 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);
|
||||
|
||||
virtual bool isPopulated() const { return true; }
|
||||
|
||||
@@ -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,
|
||||
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)
|
||||
{
|
||||
@@ -326,7 +326,16 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
throw std::runtime_error("Unknown format");
|
||||
}
|
||||
|
||||
updateHash();
|
||||
if (hash.isZero())
|
||||
updateHash();
|
||||
else
|
||||
{
|
||||
mHash = hash;
|
||||
#ifdef PARANOID
|
||||
updateHash();
|
||||
assert(mHash == hash);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool SHAMapTreeNode::updateHash()
|
||||
|
||||
@@ -61,17 +61,9 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
|
||||
std::vector<unsigned char> nodeData;
|
||||
if (filter->haveNode(childID, childHash, nodeData))
|
||||
{
|
||||
d = boost::make_shared<SHAMapTreeNode>(childID, nodeData, mSeq, snfPREFIX);
|
||||
if (childHash != d->getNodeHash())
|
||||
{
|
||||
cLog(lsERROR) << "Wrong hash from cached object";
|
||||
d.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
cLog(lsTRACE) << "Got sync node from cache: " << *d;
|
||||
mTNByID[*d] = d;
|
||||
}
|
||||
d = boost::make_shared<SHAMapTreeNode>(childID, nodeData, mSeq, snfPREFIX, childHash);
|
||||
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();
|
||||
}
|
||||
|
||||
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)
|
||||
return SMAddNode::invalid();
|
||||
|
||||
@@ -240,7 +232,7 @@ SMAddNode SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned ch
|
||||
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)
|
||||
return SMAddNode::invalid();
|
||||
|
||||
@@ -318,7 +310,7 @@ SMAddNode SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigne
|
||||
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
|
||||
return SMAddNode::invalid();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user