Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Only set database paths if disk db is being used
Browse files Browse the repository at this point in the history
  • Loading branch information
halfalicious committed Nov 27, 2019
1 parent b632e12 commit 193c839
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions libethereum/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 << ")";
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions libethereum/DatabasePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 8 additions & 5 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 193c839

Please sign in to comment.