Fix the disconnect between hashes of nodes in transport format and hashes of nodes in internal format.

This commit is contained in:
JoelKatz
2012-06-24 06:01:48 -07:00
parent 340f17e471
commit 08bfd8f1d0
2 changed files with 4 additions and 34 deletions

View File

@@ -7,25 +7,6 @@
#include "Application.h"
#include "Log.h"
bool HashedObject::checkHash() const
{
uint256 hash = Serializer::getSHA512Half(mData);
return hash == mHash;
}
bool HashedObject::checkFixHash()
{
uint256 hash = Serializer::getSHA512Half(mData);
if (hash == mHash) return true;
mHash = hash;
return false;
}
void HashedObject::setHash()
{
mHash = Serializer::getSHA512Half(mData);
}
HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) :
mCache(cacheSize, cacheAge), mWritePending(false)
{
@@ -43,10 +24,7 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
return false;
}
HashedObject::pointer object = boost::make_shared<HashedObject>(type, index, data);
object->setHash();
if (object->getHash() != hash)
throw std::runtime_error("Object added to store doesn't have valid hash");
HashedObject::pointer object = boost::make_shared<HashedObject>(type, index, data, hash);
{
boost::recursive_mutex::scoped_lock sl(mWriteMutex);
@@ -159,13 +137,9 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
return HashedObject::pointer();
}
obj = boost::make_shared<HashedObject>(htype, index, data);
obj->mHash = hash;
obj = boost::make_shared<HashedObject>(htype, index, data, hash);
mCache.canonicalize(hash, obj);
}
#ifdef DEBUG
assert(obj->checkHash());
#endif
Log(lsTRACE) << "HOS: " << hash.GetHex() << " fetch: in db";
return obj;
}

View File

@@ -27,12 +27,8 @@ public:
uint32 mLedgerIndex;
std::vector<unsigned char> mData;
HashedObject(HashedObjectType type, uint32 index, const std::vector<unsigned char>& data) :
mType(type), mLedgerIndex(index), mData(data) { ; }
bool checkHash() const;
bool checkFixHash();
void setHash();
HashedObject(HashedObjectType type, uint32 index, const std::vector<unsigned char>& data, const uint256& hash) :
mType(type), mHash(hash), mLedgerIndex(index), mData(data) { ; }
const std::vector<unsigned char>& getData() { return mData; }
const uint256& getHash() { return mHash; }