From 193c8397fa9e7d41d1cebe0cdef49fcc94c1c6c5 Mon Sep 17 00:00:00 2001 From: Nils-Erik Frantzell Date: Tue, 26 Nov 2019 20:32:27 -0800 Subject: [PATCH] Only set database paths if disk db is being used --- libethereum/BlockChain.cpp | 5 +++-- libethereum/DatabasePaths.cpp | 7 ++----- libethereum/State.cpp | 13 ++++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index bc882413aa0..b9a32c7c4b0 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -198,9 +198,9 @@ bool BlockChain::open(fs::path const& _path, WithExisting _we) unsigned lastMinor = c_databaseMinorVersion; bool rebuildNeeded = false; - db_paths::setDatabasePaths(_path, m_genesisHash); if (db::isDiskDatabase()) { + db_paths::setDatabasePaths(_path, m_genesisHash); if (_we == WithExisting::Kill) { LOG(m_loggerInfo) @@ -234,6 +234,7 @@ bool BlockChain::open(fs::path const& _path, WithExisting _we) } else { + // First launch with new database LOG(m_loggerDetail) << "Creating database minor version file: " << db_paths::extrasDatabaseMinorVersionPath() << " (minor version: " << c_databaseMinorVersion << ")"; @@ -302,7 +303,7 @@ bool BlockChain::open(fs::path const& _path, WithExisting _we) // database because the extras database format may have changed m_lastBlockNumber = info(m_lastBlockHash).number(); - LOG(m_loggerInfo) << "Opened blockchain database. Latest: " << currentHash() + LOG(m_loggerInfo) << "Opened blockchain database. Latest block hash: " << currentHash() << (!rebuildNeeded ? "(rebuild not needed)" : "*** REBUILD NEEDED ***"); return rebuildNeeded; } diff --git a/libethereum/DatabasePaths.cpp b/libethereum/DatabasePaths.cpp index 37a455645fd..a3d3ad15e00 100644 --- a/libethereum/DatabasePaths.cpp +++ b/libethereum/DatabasePaths.cpp @@ -30,11 +30,8 @@ bool databasePathsSet() void setDatabasePaths(fs::path const& _rootPath, h256 const& _genesisHash) { - if (_genesisHash == h256{}) - { - BOOST_THROW_EXCEPTION(InvalidHash()); - } - + // Allow empty hashes since they are required by tests + g_rootPath = _rootPath.empty() ? db::databasePath() : _rootPath; g_chainPath = g_rootPath / fs::path(toHex(_genesisHash.ref().cropped(0, 4))); g_stateDbPath = g_chainPath / fs::path("state"); diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 6dac1c6ac6e..325af2841c9 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -44,12 +44,15 @@ State::State(State const& _s): OverlayDB State::openDB(fs::path const& _basePath, h256 const& _genesisHash, WithExisting _we) { - db_paths::setDatabasePaths(_basePath); - if (db::isDiskDatabase() && _we == WithExisting::Kill) + if (db::isDiskDatabase()) { - clog(VerbosityInfo, "statedb") - << "Deleting state database: " << db_paths::stateDatabasePath(); - fs::remove_all(db_paths::stateDatabasePath()); + db_paths::setDatabasePaths(_basePath, _genesisHash); + if (_we == WithExisting::Kill) + { + clog(VerbosityInfo, "statedb") + << "Deleting state database: " << db_paths::stateDatabasePath(); + fs::remove_all(db_paths::stateDatabasePath()); + } } try