diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 13 | ||||
-rw-r--r-- | src/leveldbwrapper.cpp | 8 | ||||
-rw-r--r-- | src/leveldbwrapper.h | 5 | ||||
-rw-r--r-- | src/test/test_bitcoin.cpp | 5 | ||||
-rw-r--r-- | src/txdb.cpp | 4 | ||||
-rw-r--r-- | src/txdb.h | 4 |
6 files changed, 29 insertions, 10 deletions
diff --git a/src/init.cpp b/src/init.cpp index a04e4e0a94..f2a1216a46 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1127,8 +1127,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) delete pcoinscatcher; delete pblocktree; - pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex); - pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex); + // Detect database obfuscated by future versions of the DBWrapper + bool chainstateScrambled; + bool blockDbScrambled; + + pblocktree = new CBlockTreeDB(nBlockTreeDBCache, blockDbScrambled, false, fReindex); + pcoinsdbview = new CCoinsViewDB(nCoinDBCache, chainstateScrambled, false, fReindex); pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview); pcoinsTip = new CCoinsViewCache(pcoinscatcher); @@ -1139,6 +1143,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) CleanupBlockRevFiles(); } + if (chainstateScrambled || blockDbScrambled) { + strLoadError = _("Reindex required as the chainstate or block database is obfuscated"); + break; + } + if (!LoadBlockIndex()) { strLoadError = _("Error loading block database"); break; diff --git a/src/leveldbwrapper.cpp b/src/leveldbwrapper.cpp index 26cacf95ae..1fc3685315 100644 --- a/src/leveldbwrapper.cpp +++ b/src/leveldbwrapper.cpp @@ -43,7 +43,7 @@ static leveldb::Options GetOptions(size_t nCacheSize) return options; } -CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe) +CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool &isObfuscated, bool fMemory, bool fWipe) { penv = NULL; readoptions.verify_checksums = true; @@ -67,6 +67,9 @@ CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCa leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb); HandleError(status); LogPrintf("Opened LevelDB successfully\n"); + + std::vector<unsigned char> obfuscate_key; + isObfuscated = Read(OBFUSCATE_KEY_KEY, obfuscate_key); } CLevelDBWrapper::~CLevelDBWrapper() @@ -87,3 +90,6 @@ bool CLevelDBWrapper::WriteBatch(CLevelDBBatch& batch, bool fSync) throw(leveldb HandleError(status); return true; } + +// Taken from future release of DBWrapper +const std::string CLevelDBWrapper::OBFUSCATE_KEY_KEY("\000obfuscate_key", 14); diff --git a/src/leveldbwrapper.h b/src/leveldbwrapper.h index c65e842704..a1d6de8e24 100644 --- a/src/leveldbwrapper.h +++ b/src/leveldbwrapper.h @@ -85,8 +85,11 @@ private: //! the database itself leveldb::DB* pdb; + //! the key under which a obfuscation key may be stored by a future version of DBWrapper + static const std::string OBFUSCATE_KEY_KEY; + public: - CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false); + CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool &isObfuscated, bool fMemory = false, bool fWipe = false); ~CLevelDBWrapper(); template <typename K, typename V> diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index c727303ea1..2714ca5eee 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -49,8 +49,9 @@ TestingSetup::TestingSetup() pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); - pblocktree = new CBlockTreeDB(1 << 20, true); - pcoinsdbview = new CCoinsViewDB(1 << 23, true); + bool isObfuscated; + pblocktree = new CBlockTreeDB(1 << 20, isObfuscated, true); + pcoinsdbview = new CCoinsViewDB(1 << 23, isObfuscated, true); pcoinsTip = new CCoinsViewCache(pcoinsdbview); InitBlockIndex(); #ifdef ENABLE_WALLET diff --git a/src/txdb.cpp b/src/txdb.cpp index df9ff8d8c9..f3e56075f9 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -39,7 +39,7 @@ void static BatchWriteHashBestChain(CLevelDBBatch &batch, const uint256 &hash) { batch.Write(DB_BEST_BLOCK, hash); } -CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe) { +CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool &isObfuscated, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, isObfuscated, fMemory, fWipe) { } bool CCoinsViewDB::GetCoins(const uint256 &txid, CCoins &coins) const { @@ -77,7 +77,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return db.WriteBatch(batch); } -CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) { +CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool &isObfuscated, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, isObfuscated, fMemory, fWipe) { } bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) { diff --git a/src/txdb.h b/src/txdb.h index bef5dc9fd1..c39d7188de 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -32,7 +32,7 @@ class CCoinsViewDB : public CCoinsView protected: CLevelDBWrapper db; public: - CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false); + CCoinsViewDB(size_t nCacheSize, bool &isObfuscated, bool fMemory = false, bool fWipe = false); bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; @@ -45,7 +45,7 @@ public: class CBlockTreeDB : public CLevelDBWrapper { public: - CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false); + CBlockTreeDB(size_t nCacheSize, bool &isObfuscated, bool fMemory = false, bool fWipe = false); private: CBlockTreeDB(const CBlockTreeDB&); void operator=(const CBlockTreeDB&); |