Browse Source

Fixed bug in test's BlockChainLoader making it crazy slow and constantly

importing blocks it already had.
cl-refactor
Gav Wood 10 years ago
parent
commit
4aca199707
  1. 1
      libethereum/BlockChain.h
  2. 3
      libtestutils/BlockChainLoader.cpp
  3. 4
      libtestutils/StateLoader.cpp
  4. 4
      libtestutils/StateLoader.h

1
libethereum/BlockChain.h

@ -83,7 +83,6 @@ using ProgressCallback = std::function<void(unsigned, unsigned)>;
/**
* @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
{

3
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"])

4
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();
}

4
libtestutils/StateLoader.h

@ -23,6 +23,7 @@
#include <json/json.h>
#include <libethereum/State.h>
#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;
};
}
}

Loading…
Cancel
Save