From 6b409f52ad80a35383043c488ea2eea7c14caba9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 29 Mar 2015 22:54:41 +0200 Subject: [PATCH] More descriptive errors on database fail. Fixes #1343 --- libethcore/Exceptions.h | 1 + libethereum/BlockChain.cpp | 17 +++++++++++++---- libethereum/State.cpp | 13 ++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index df6a08817..db2718fc4 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -38,6 +38,7 @@ using errinfo_difficulty = boost::error_info; using BadFieldError = boost::tuple; struct DatabaseAlreadyOpen: virtual dev::Exception {}; +struct NotEnoughAvailableSpace: virtual dev::Exception {}; struct NotEnoughCash: virtual dev::Exception {}; struct GasPriceTooLow: virtual dev::Exception {}; struct BlockGasLimitReached: virtual dev::Exception {}; diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 688a0c326..508531f9d 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -131,10 +131,19 @@ void BlockChain::open(std::string _path, bool _killExisting) o.create_if_missing = true; ldb::DB::Open(o, _path + "/blocks", &m_blocksDB); ldb::DB::Open(o, _path + "/details", &m_extrasDB); - if (!m_blocksDB) - BOOST_THROW_EXCEPTION(DatabaseAlreadyOpen()); - if (!m_extrasDB) - BOOST_THROW_EXCEPTION(DatabaseAlreadyOpen()); + if (!m_blocksDB || !m_extrasDB) + { + if (boost::filesystem::space(_path + "/blocks").available < 1024) + { + cwarn << "Not enough available space found on hard drive. Please free some up and then re-run. Bailing."; + BOOST_THROW_EXCEPTION(NotEnoughAvailableSpace()); + } + else + { + cwarn << "Database already open. You appear to have another instance of ethereum running. Bailing."; + BOOST_THROW_EXCEPTION(DatabaseAlreadyOpen()); + } + } if (!details(m_genesisHash)) { diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 9817e2bad..378c60fa3 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -60,7 +60,18 @@ OverlayDB State::openDB(std::string _path, bool _killExisting) ldb::DB* db = nullptr; ldb::DB::Open(o, _path + "/state", &db); if (!db) - BOOST_THROW_EXCEPTION(DatabaseAlreadyOpen()); + { + if (boost::filesystem::space(_path + "/state").available < 1024) + { + cwarn << "Not enough available space found on hard drive. Please free some up and then re-run. Bailing."; + BOOST_THROW_EXCEPTION(NotEnoughAvailableSpace()); + } + else + { + cwarn << "Database already open. You appear to have another instance of ethereum running. Bailing."; + BOOST_THROW_EXCEPTION(DatabaseAlreadyOpen()); + } + } cnote << "Opened state DB."; return OverlayDB(db);