Browse Source

Use default path if none given when rebuilding chain.

cl-refactor
Gav Wood 10 years ago
parent
commit
86384ad0ad
  1. 4
      eth/main.cpp
  2. 14
      libethereum/BlockChain.cpp

4
eth/main.cpp

@ -121,7 +121,7 @@ void help()
<< " --json-rpc-port <n> Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ")." << endl << " --json-rpc-port <n> Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ")." << endl
#endif #endif
<< " -K,--kill First kill the blockchain." << endl << " -K,--kill First kill the blockchain." << endl
<< " -R,--rebuild First rebuild the blockchain from the existing database." << endl << " -R,--rebuild Rebuild the blockchain from the existing database." << endl
<< " -s,--secret <secretkeyhex> Set the secret key for use with send command (default: auto)." << endl << " -s,--secret <secretkeyhex> Set the secret key for use with send command (default: auto)." << endl
<< " -S,--session-secret <secretkeyhex> Set the secret key for use with send command, for this session only." << endl << " -S,--session-secret <secretkeyhex> Set the secret key for use with send command, for this session only." << endl
<< "Client transacting:" << endl << "Client transacting:" << endl
@ -598,7 +598,7 @@ int main(int argc, char** argv)
} }
else if (arg == "-K" || arg == "--kill-blockchain" || arg == "--kill") else if (arg == "-K" || arg == "--kill-blockchain" || arg == "--kill")
killChain = WithExisting::Kill; killChain = WithExisting::Kill;
else if (arg == "-B" || arg == "--rebuild") else if (arg == "-R" || arg == "--rebuild")
killChain = WithExisting::Verify; killChain = WithExisting::Verify;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc) else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
{ {

14
libethereum/BlockChain.cpp

@ -185,6 +185,8 @@ void BlockChain::close()
void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned, unsigned)> const& _progress) void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned, unsigned)> const& _progress)
{ {
std::string path = _path.empty() ? Defaults::get()->m_dbPath : _path;
#if ETH_PROFILING_GPERF #if ETH_PROFILING_GPERF
ProfilerStart("BlockChain_rebuild.log"); ProfilerStart("BlockChain_rebuild.log");
#endif #endif
@ -195,16 +197,16 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
// Keep extras DB around, but under a temp name // Keep extras DB around, but under a temp name
delete m_extrasDB; delete m_extrasDB;
m_extrasDB = nullptr; m_extrasDB = nullptr;
IGNORE_EXCEPTIONS(boost::filesystem::remove_all(_path + "/details.old")); IGNORE_EXCEPTIONS(boost::filesystem::remove_all(path + "/details.old"));
boost::filesystem::rename(_path + "/details", _path + "/details.old"); boost::filesystem::rename(path + "/details", path + "/details.old");
ldb::DB* oldExtrasDB; ldb::DB* oldExtrasDB;
ldb::Options o; ldb::Options o;
o.create_if_missing = true; o.create_if_missing = true;
ldb::DB::Open(o, _path + "/details.old", &oldExtrasDB); ldb::DB::Open(o, path + "/details.old", &oldExtrasDB);
ldb::DB::Open(o, _path + "/details", &m_extrasDB); ldb::DB::Open(o, path + "/details", &m_extrasDB);
// Open a fresh state DB // Open a fresh state DB
State s(State::openDB(_path, WithExisting::Kill), BaseState::CanonGenesis); State s(State::openDB(path, WithExisting::Kill), BaseState::CanonGenesis);
// Clear all memos ready for replay. // Clear all memos ready for replay.
m_details.clear(); m_details.clear();
@ -255,7 +257,7 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
#endif #endif
delete oldExtrasDB; delete oldExtrasDB;
boost::filesystem::remove_all(_path + "/details.old"); boost::filesystem::remove_all(path + "/details.old");
} }
template <class T, class V> template <class T, class V>

Loading…
Cancel
Save