diff --git a/src/HashedObject.cpp b/src/HashedObject.cpp index 6d59e8b293..512a0ab025 100644 --- a/src/HashedObject.cpp +++ b/src/HashedObject.cpp @@ -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(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(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(htype, index, data); - obj->mHash = hash; + obj = boost::make_shared(htype, index, data, hash); mCache.canonicalize(hash, obj); } -#ifdef DEBUG - assert(obj->checkHash()); -#endif Log(lsTRACE) << "HOS: " << hash.GetHex() << " fetch: in db"; return obj; } diff --git a/src/HashedObject.h b/src/HashedObject.h index 514a026670..0331cfa9b3 100644 --- a/src/HashedObject.h +++ b/src/HashedObject.h @@ -27,12 +27,8 @@ public: uint32 mLedgerIndex; std::vector mData; - HashedObject(HashedObjectType type, uint32 index, const std::vector& data) : - mType(type), mLedgerIndex(index), mData(data) { ; } - - bool checkHash() const; - bool checkFixHash(); - void setHash(); + HashedObject(HashedObjectType type, uint32 index, const std::vector& data, const uint256& hash) : + mType(type), mHash(hash), mLedgerIndex(index), mData(data) { ; } const std::vector& getData() { return mData; } const uint256& getHash() { return mHash; }