diff --git a/src/cpp/ripple/HashedObject.cpp b/src/cpp/ripple/HashedObject.cpp index a12d038757..8a2eb4eedf 100644 --- a/src/cpp/ripple/HashedObject.cpp +++ b/src/cpp/ripple/HashedObject.cpp @@ -366,12 +366,15 @@ HashedObject::pointer HashedObjectStore::retrieveSQLite(const uint256& hash) #ifdef USE_LEVELDB -int HashedObjectStore::import(const std::string& file, bool checkHashes) +int HashedObjectStore::import(const std::string& file) { cLog(lsWARNING) << "Hashed object import from \"" << file << "\"."; UPTR_T importDB(new SqliteDatabase(file.c_str())); importDB->connect(); + leveldb::DB* db = theApp->getHashNodeLDB(); + leveldb::WriteOptions wo; + int count = 0; SQL_FOREACH(importDB, "SELECT * FROM CommittedObjects;") @@ -386,17 +389,19 @@ int HashedObjectStore::import(const std::string& file, bool checkHashes) } else { - std::vector data; + std::vector rawData; + int size = importDB->getBinary("Object", NULL, 0); + rawData.resize(9 + size); + unsigned char* bufPtr = &rawData.front(); + + importDB->getBinary("Object", bufPtr + 9, size); + + uint32 index = importDB->getBigInt("LedgerIndex"); + *reinterpret_cast(bufPtr + 0) = ntohl(index); + *reinterpret_cast(bufPtr + 4) = ntohl(index); + std::string type; importDB->getStr("ObjType", type); - uint32 index = importDB->getBigInt("LedgerIndex"); - - int size = importDB->getBinary("Object", NULL, 0); - data.resize(size); - importDB->getBinary("Object", &(data.front()), size); - - assert(Serializer::getSHA512Half(data) == hash); - HashedObjectType htype = hotUNKNOWN; switch (type[0]) { @@ -408,17 +413,17 @@ int HashedObjectStore::import(const std::string& file, bool checkHashes) assert(false); cLog(lsERROR) << "Invalid hashed object"; } + *(bufPtr + 8) = static_cast(htype); - if (checkHashes && Serializer::getSHA512Half(data) != hash) + leveldb::Status st = db->Put(wo, + leveldb::Slice(reinterpret_cast(hash.begin()), hash.size()), + leveldb::Slice(reinterpret_cast(bufPtr), rawData.size())); + if (!st.ok()) { - cLog(lsWARNING) << "Hash mismatch in import table " << hash - << " " << Serializer::getSHA512Half(data); - } - else - { - store(htype, index, data, hash); - ++count; + cLog(lsFATAL) << "Failed to store hash node"; + assert(false); } + ++count; } if ((count % 10000) == 0) { diff --git a/src/cpp/ripple/HashedObject.h b/src/cpp/ripple/HashedObject.h index 1389108c08..e66f1f680c 100644 --- a/src/cpp/ripple/HashedObject.h +++ b/src/cpp/ripple/HashedObject.h @@ -100,7 +100,7 @@ public: void tune(int size, int age); void sweep() { mCache.sweep(); mNegativeCache.sweep(); } - int import(const std::string& fileName, bool checkHashes); + int import(const std::string& fileName); }; #endif diff --git a/src/cpp/ripple/UpdateTables.cpp b/src/cpp/ripple/UpdateTables.cpp index 557e26b359..6db98d7724 100644 --- a/src/cpp/ripple/UpdateTables.cpp +++ b/src/cpp/ripple/UpdateTables.cpp @@ -116,7 +116,7 @@ void Application::updateTables(bool ldbImport) if (theConfig.LDB_IMPORT) { Log(lsWARNING) << "Importing SQLite -> LevelDB"; - theApp->getHashedObjectStore().import(hashPath.string(), false); + theApp->getHashedObjectStore().import(hashPath.string()); Log(lsWARNING) << "Remove or remname the hashnode.db file"; } else