From 4aca1997073767f2eeef9b32b01a42be7c887ae3 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 8 Apr 2015 15:58:49 +0200 Subject: [PATCH] Fixed bug in test's BlockChainLoader making it crazy slow and constantly importing blocks it already had. --- libethereum/BlockChain.h | 1 - libtestutils/BlockChainLoader.cpp | 3 ++- libtestutils/StateLoader.cpp | 4 +++- libtestutils/StateLoader.h | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index e20ee8f6a..b4e18a037 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -83,7 +83,6 @@ using ProgressCallback = std::function; /** * @brief Implements the blockchain database. All data this gives is disk-backed. * @threadsafe - * @todo Make not memory hog (should actually act as a cache and deallocate old entries). */ class BlockChain { diff --git a/libtestutils/BlockChainLoader.cpp b/libtestutils/BlockChainLoader.cpp index ba0def59e..e6c47e2fe 100644 --- a/libtestutils/BlockChainLoader.cpp +++ b/libtestutils/BlockChainLoader.cpp @@ -31,11 +31,12 @@ using namespace dev::eth; BlockChainLoader::BlockChainLoader(Json::Value const& _json) { // load pre state - StateLoader sl(_json["pre"]); + StateLoader sl(_json["pre"], m_dir.path()); m_state = sl.state(); // load genesisBlock m_bc.reset(new BlockChain(fromHex(_json["genesisRLP"].asString()), m_dir.path(), WithExisting::Kill)); + assert(m_state.rootHash() == m_bc->info().stateRoot); // load blocks for (auto const& block: _json["blocks"]) diff --git a/libtestutils/StateLoader.cpp b/libtestutils/StateLoader.cpp index 464df0ec5..07eb2cef5 100644 --- a/libtestutils/StateLoader.cpp +++ b/libtestutils/StateLoader.cpp @@ -26,7 +26,8 @@ using namespace dev; using namespace dev::eth; using namespace dev::test; -StateLoader::StateLoader(Json::Value const& _json) +StateLoader::StateLoader(Json::Value const& _json, std::string const& _dbPath): + m_state(State::openDB(_dbPath, WithExisting::Kill), BaseState::Empty) { for (string const& name: _json.getMemberNames()) { @@ -53,4 +54,5 @@ StateLoader::StateLoader(Json::Value const& _json) } m_state.commit(); + m_state.db().commit(); } diff --git a/libtestutils/StateLoader.h b/libtestutils/StateLoader.h index e5843d0b4..e1346f69a 100644 --- a/libtestutils/StateLoader.h +++ b/libtestutils/StateLoader.h @@ -23,6 +23,7 @@ #include #include +#include "TransientDirectory.h" namespace dev { @@ -35,11 +36,12 @@ namespace test class StateLoader { public: - StateLoader(Json::Value const& _json); + StateLoader(Json::Value const& _json, std::string const& _dbPath); eth::State const& state() const { return m_state; } private: eth::State m_state; }; + } }