Browse Source

Fixes #1509

cl-refactor
Gav Wood 10 years ago
parent
commit
13232d6e04
  1. 2
      alethzero/MainWin.cpp
  2. 9
      eth/main.cpp
  3. 16
      libdevcore/Common.h
  4. 1
      libethcore/Common.cpp
  5. 3
      libethcore/Common.h
  6. 85
      libethereum/BlockChain.cpp
  7. 18
      libethereum/BlockChain.h
  8. 2
      libethereum/CanonBlockChain.cpp
  9. 4
      libethereum/CanonBlockChain.h
  10. 36
      libethereum/Client.cpp
  11. 8
      libethereum/Client.h
  12. 4
      libethereum/State.cpp
  13. 4
      libethereum/State.h
  14. 2
      libtestutils/BlockChainLoader.cpp
  15. 4
      libwebthree/WebThree.cpp
  16. 8
      libwebthree/WebThree.h
  17. 2
      mix/MixClient.h
  18. 2
      neth/main.cpp
  19. 2
      test/blockchain.cpp

2
alethzero/MainWin.cpp

@ -168,7 +168,7 @@ Main::Main(QWidget *parent) :
QSettings s("ethereum", "alethzero"); QSettings s("ethereum", "alethzero");
m_networkConfig = s.value("peers").toByteArray(); m_networkConfig = s.value("peers").toByteArray();
bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size()); bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size());
m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), false, {"eth", "shh"}, p2p::NetworkPreferences(), network)); m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), WithExisting::Trust, {"eth", "shh"}, p2p::NetworkPreferences(), network));
m_httpConnector.reset(new jsonrpc::HttpServer(SensibleHttpPort, "", "", dev::SensibleHttpThreads)); m_httpConnector.reset(new jsonrpc::HttpServer(SensibleHttpPort, "", "", dev::SensibleHttpThreads));
m_server.reset(new OurWebThreeStubServer(*m_httpConnector, *web3(), keysAsVector(m_myKeys), this)); m_server.reset(new OurWebThreeStubServer(*m_httpConnector, *web3(), keysAsVector(m_myKeys), this));

9
eth/main.cpp

@ -129,6 +129,7 @@ void help()
<< " -o,--mode <full/peer> Start a full node or a peer node (Default: full)." << endl << " -o,--mode <full/peer> Start a full node or a peer node (Default: full)." << endl
<< " -p,--port <port> Connect to remote port (default: 30303)." << endl << " -p,--port <port> Connect to remote port (default: 30303)." << endl
<< " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl << " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl
<< " -R,--rebuild-blockchain First rebuild the blockchain from the existing database." << endl
<< " -r,--remote <host> Connect to remote host (default: none)." << endl << " -r,--remote <host> Connect to remote host (default: none)." << 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
<< " -t,--miners <number> Number of mining threads to start (Default: " << thread::hardware_concurrency() << ")" << endl << " -t,--miners <number> Number of mining threads to start (Default: " << thread::hardware_concurrency() << ")" << endl
@ -168,7 +169,7 @@ void version()
} }
Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250"); Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250");
string pretty(h160 _a, dev::eth::State _st) string pretty(h160 _a, dev::eth::State const& _st)
{ {
string ns; string ns;
h256 n; h256 n;
@ -216,7 +217,7 @@ int main(int argc, char** argv)
bool bootstrap = false; bool bootstrap = false;
bool upnp = true; bool upnp = true;
bool forceMining = false; bool forceMining = false;
bool killChain = false; WithExisting killChain = WithExisting::Trust;
bool jit = false; bool jit = false;
bool structuredLogging = false; bool structuredLogging = false;
string structuredLoggingFormat = "%Y-%m-%dT%H:%M:%S"; string structuredLoggingFormat = "%Y-%m-%dT%H:%M:%S";
@ -274,7 +275,9 @@ int main(int argc, char** argv)
} }
} }
else if (arg == "-K" || arg == "--kill-blockchain") else if (arg == "-K" || arg == "--kill-blockchain")
killChain = true; killChain = WithExisting::Kill;
else if (arg == "-B" || arg == "--rebuild-blockchain")
killChain = WithExisting::Verify;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc) else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i]; clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc) else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)

16
libdevcore/Common.h

@ -134,4 +134,20 @@ private:
std::function<void(void)> m_f; std::function<void(void)> m_f;
}; };
enum class WithExisting: int
{
Trust = 0,
Verify,
Kill
};
}
namespace std {
inline dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
{
return static_cast<dev::WithExisting>(max(static_cast<int>(_a), static_cast<int>(_b)));
}
} }

1
libethcore/Common.cpp

@ -35,6 +35,7 @@ namespace eth
const unsigned c_ethashVersion = c_ethashRevision; const unsigned c_ethashVersion = c_ethashRevision;
const unsigned c_protocolVersion = 60; const unsigned c_protocolVersion = 60;
const unsigned c_minorProtocolVersion = 0;
const unsigned c_databaseBaseVersion = 8; const unsigned c_databaseBaseVersion = 8;
#if ETH_FATDB #if ETH_FATDB
const unsigned c_databaseVersionModifier = 1; const unsigned c_databaseVersionModifier = 1;

3
libethcore/Common.h

@ -35,6 +35,9 @@ namespace eth
/// Current protocol version. /// Current protocol version.
extern const unsigned c_protocolVersion; extern const unsigned c_protocolVersion;
/// Current minor protocol version.
extern const unsigned c_minorProtocolVersion;
/// Current database version. /// Current database version.
extern const unsigned c_databaseVersion; extern const unsigned c_databaseVersion;

85
libethereum/BlockChain.cpp

@ -98,7 +98,7 @@ static const unsigned c_minCacheSize = 1024 * 1024 * 32;
#endif #endif
BlockChain::BlockChain(bytes const& _genesisBlock, std::string _path, bool _killExisting) BlockChain::BlockChain(bytes const& _genesisBlock, std::string _path, WithExisting _we, ProgressCallback const& _p)
{ {
// initialise deathrow. // initialise deathrow.
m_cacheUsage.resize(c_collectionQueueSize); m_cacheUsage.resize(c_collectionQueueSize);
@ -108,7 +108,9 @@ BlockChain::BlockChain(bytes const& _genesisBlock, std::string _path, bool _kill
m_genesisBlock = _genesisBlock; m_genesisBlock = _genesisBlock;
m_genesisHash = sha3(RLP(m_genesisBlock)[0].data()); m_genesisHash = sha3(RLP(m_genesisBlock)[0].data());
open(_path, _killExisting); open(_path, _we);
if (_we == WithExisting::Verify)
rebuild(_path, _p);
} }
BlockChain::~BlockChain() BlockChain::~BlockChain()
@ -116,24 +118,23 @@ BlockChain::~BlockChain()
close(); close();
} }
void BlockChain::open(std::string _path, bool _killExisting) void BlockChain::open(std::string const& _path, WithExisting _we)
{ {
if (_path.empty()) std::string path = _path.empty() ? Defaults::get()->m_dbPath : _path;
_path = Defaults::get()->m_dbPath; boost::filesystem::create_directories(path);
boost::filesystem::create_directories(_path); if (_we == WithExisting::Kill)
if (_killExisting)
{ {
boost::filesystem::remove_all(_path + "/blocks"); boost::filesystem::remove_all(path + "/blocks");
boost::filesystem::remove_all(_path + "/details"); boost::filesystem::remove_all(path + "/details");
} }
ldb::Options o; ldb::Options o;
o.create_if_missing = true; o.create_if_missing = true;
ldb::DB::Open(o, _path + "/blocks", &m_blocksDB); ldb::DB::Open(o, path + "/blocks", &m_blocksDB);
ldb::DB::Open(o, _path + "/details", &m_extrasDB); ldb::DB::Open(o, path + "/details", &m_extrasDB);
if (!m_blocksDB || !m_extrasDB) if (!m_blocksDB || !m_extrasDB)
{ {
if (boost::filesystem::space(_path + "/blocks").available < 1024) 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."; cwarn << "Not enough available space found on hard drive. Please free some up and then re-run. Bailing.";
BOOST_THROW_EXCEPTION(NotEnoughAvailableSpace()); BOOST_THROW_EXCEPTION(NotEnoughAvailableSpace());
@ -158,7 +159,6 @@ void BlockChain::open(std::string _path, bool _killExisting)
// TODO: Implement ability to rebuild details map from DB. // TODO: Implement ability to rebuild details map from DB.
std::string l; std::string l;
m_extrasDB->Get(m_readOptions, ldb::Slice("best"), &l); m_extrasDB->Get(m_readOptions, ldb::Slice("best"), &l);
m_lastBlockHash = l.empty() ? m_genesisHash : *(h256*)l.data(); m_lastBlockHash = l.empty() ? m_genesisHash : *(h256*)l.data();
cnote << "Opened blockchain DB. Latest: " << currentHash(); cnote << "Opened blockchain DB. Latest: " << currentHash();
@ -174,6 +174,53 @@ void BlockChain::close()
m_blocks.clear(); m_blocks.clear();
} }
void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned, unsigned)> const& _progress)
{
unsigned originalNumber = number();
// Keep extras DB around, but under a temp name
delete m_extrasDB;
m_extrasDB = nullptr;
boost::filesystem::rename(_path + "/details", _path + "/details.old");
ldb::DB* oldExtrasDB;
ldb::Options o;
o.create_if_missing = true;
ldb::DB::Open(o, _path + "/details.old", &oldExtrasDB);
ldb::DB::Open(o, _path + "/details", &m_extrasDB);
// Open a fresh state DB
OverlayDB db = State::openDB(_path, WithExisting::Kill);
// Clear all memos ready for replay.
m_details.clear();
m_logBlooms.clear();
m_receipts.clear();
m_transactionAddresses.clear();
m_blockHashes.clear();
m_blocksBlooms.clear();
m_lastLastHashes.clear();
m_lastBlockHash = genesisHash();
for (unsigned d = 0; d < originalNumber; ++d)
{
try
{
import(block(queryExtras<BlockHash, ExtraBlockHash>(h256(u256(d)), m_blockHashes, x_blockHashes, NullBlockHash, oldExtrasDB).value), db);
}
catch (...)
{
// Failed to import - stop here.
break;
}
if (_progress)
_progress(d, originalNumber);
}
delete oldExtrasDB;
boost::filesystem::remove_all(_path + "/details.old");
}
template <class T, class V> template <class T, class V>
bool contains(T const& _t, V const& _v) bool contains(T const& _t, V const& _v)
{ {
@ -414,12 +461,22 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
#endif #endif
} }
#if ETH_CATCH #if ETH_CATCH
catch (Exception const& _e) catch (InvalidNonce const& _e)
{ {
clog(BlockChainNote) << " Malformed block: " << diagnostic_information(_e); clog(BlockChainNote) << " Malformed block: " << diagnostic_information(_e);
_e << errinfo_comment("Malformed block "); _e << errinfo_comment("Malformed block ");
throw; throw;
} }
catch (Exception const& _e)
{
clog(BlockChainWarn) << " Malformed block: " << diagnostic_information(_e);
_e << errinfo_comment("Malformed block ");
clog(BlockChainWarn) << "Block: " << bi.hash;
clog(BlockChainWarn) << bi;
clog(BlockChainWarn) << "Block parent: " << bi.parentHash;
clog(BlockChainWarn) << BlockInfo(block(bi.parentHash));
throw;
}
#endif #endif
StructuredLogger::chainReceivedNewBlock( StructuredLogger::chainReceivedNewBlock(

18
libethereum/BlockChain.h

@ -58,6 +58,7 @@ struct FutureTime: virtual Exception {};
struct BlockChainChat: public LogChannel { static const char* name() { return "-B-"; } static const int verbosity = 7; }; struct BlockChainChat: public LogChannel { static const char* name() { return "-B-"; } static const int verbosity = 7; };
struct BlockChainNote: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 4; }; struct BlockChainNote: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 4; };
struct BlockChainWarn: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 1; };
// TODO: Move all this Genesis stuff into Genesis.h/.cpp // TODO: Move all this Genesis stuff into Genesis.h/.cpp
std::map<Address, Account> const& genesisState(); std::map<Address, Account> const& genesisState();
@ -77,6 +78,8 @@ enum {
ExtraBlocksBlooms ExtraBlocksBlooms
}; };
using ProgressCallback = std::function<void(unsigned, unsigned)>;
/** /**
* @brief Implements the blockchain database. All data this gives is disk-backed. * @brief Implements the blockchain database. All data this gives is disk-backed.
* @threadsafe * @threadsafe
@ -85,10 +88,11 @@ enum {
class BlockChain class BlockChain
{ {
public: public:
BlockChain(bytes const& _genesisBlock, std::string _path, bool _killExisting); BlockChain(bytes const& _genesisBlock, std::string _path, WithExisting _we, ProgressCallback const& _p = ProgressCallback());
~BlockChain(); ~BlockChain();
void reopen(std::string _path, bool _killExisting = false) { close(); open(_path, _killExisting); } /// Attempt a database re-open.
void reopen(std::string const& _path, WithExisting _we = WithExisting::Trust) { close(); open(_path, _we); }
/// (Potentially) renders invalid existing bytesConstRef returned by lastBlock. /// (Potentially) renders invalid existing bytesConstRef returned by lastBlock.
/// To be called from main loop every 100ms or so. /// To be called from main loop every 100ms or so.
@ -186,6 +190,10 @@ public:
/// togther with all their quoted uncles. /// togther with all their quoted uncles.
h256Set allUnclesFrom(h256 const& _parent) const; h256Set allUnclesFrom(h256 const& _parent) const;
/// Run through database and verify all blocks by reevaluating.
/// Will call _progress with the progress in this operation first param done, second total.
void rebuild(std::string const& _path, ProgressCallback const& _progress = std::function<void(unsigned, unsigned)>());
/** @returns the hash of all blocks between @a _from and @a _to, all blocks are ordered first by a number of /** @returns the hash of all blocks between @a _from and @a _to, all blocks are ordered first by a number of
* blocks that are parent-to-child, then two sibling blocks, then a number of blocks that are child-to-parent. * blocks that are parent-to-child, then two sibling blocks, then a number of blocks that are child-to-parent.
* *
@ -222,10 +230,10 @@ public:
private: private:
static h256 chunkId(unsigned _level, unsigned _index) { return h256(_index * 0xff + _level); } static h256 chunkId(unsigned _level, unsigned _index) { return h256(_index * 0xff + _level); }
void open(std::string _path, bool _killExisting = false); void open(std::string const& _path, WithExisting _we = WithExisting::Trust);
void close(); void close();
template<class T, unsigned N> T queryExtras(h256 const& _h, std::map<h256, T>& _m, boost::shared_mutex& _x, T const& _n) const template<class T, unsigned N> T queryExtras(h256 const& _h, std::map<h256, T>& _m, boost::shared_mutex& _x, T const& _n, ldb::DB* _extrasDB = nullptr) const
{ {
{ {
ReadGuard l(_x); ReadGuard l(_x);
@ -235,7 +243,7 @@ private:
} }
std::string s; std::string s;
m_extrasDB->Get(m_readOptions, toSlice(_h, N), &s); (_extrasDB ? _extrasDB : m_extrasDB)->Get(m_readOptions, toSlice(_h, N), &s);
if (s.empty()) if (s.empty())
{ {
// cout << "Not found in DB: " << _h << endl; // cout << "Not found in DB: " << _h << endl;

2
libethereum/CanonBlockChain.cpp

@ -92,6 +92,6 @@ bytes CanonBlockChain::createGenesisBlock()
return block.out(); return block.out();
} }
CanonBlockChain::CanonBlockChain(std::string _path, bool _killExisting): BlockChain(CanonBlockChain::createGenesisBlock(), _path, _killExisting) CanonBlockChain::CanonBlockChain(std::string const& _path, WithExisting _we): BlockChain(CanonBlockChain::createGenesisBlock(), _path, _we)
{ {
} }

4
libethereum/CanonBlockChain.h

@ -55,8 +55,8 @@ std::map<Address, Account> const& genesisState();
class CanonBlockChain: public BlockChain class CanonBlockChain: public BlockChain
{ {
public: public:
CanonBlockChain(bool _killExisting = false): CanonBlockChain(std::string(), _killExisting) {} CanonBlockChain(WithExisting _we = WithExisting::Trust): CanonBlockChain(std::string(), _we) {}
CanonBlockChain(std::string _path, bool _killExisting = false); CanonBlockChain(std::string const& _path, WithExisting _we = WithExisting::Trust);
~CanonBlockChain() {} ~CanonBlockChain() {}
/// @returns the genesis block header. /// @returns the genesis block header.

36
libethereum/Client.cpp

@ -38,14 +38,23 @@ using namespace p2p;
VersionChecker::VersionChecker(string const& _dbPath): VersionChecker::VersionChecker(string const& _dbPath):
m_path(_dbPath.size() ? _dbPath : Defaults::dbPath()) m_path(_dbPath.size() ? _dbPath : Defaults::dbPath())
{ {
auto protocolContents = contents(m_path + "/protocol"); bytes statusBytes = contents(m_path + "/status");
auto databaseContents = contents(m_path + "/database"); RLP status(statusBytes);
m_ok = RLP(protocolContents).toInt<unsigned>(RLP::LaisezFaire) == eth::c_protocolVersion && RLP(databaseContents).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion; auto protocolVersion = (unsigned)status[0];
auto minorProtocolVersion = (unsigned)status[1];
auto databaseVersion = (unsigned)status[2];
m_action =
protocolVersion != eth::c_protocolVersion || databaseVersion != c_databaseVersion ?
WithExisting::Kill
: minorProtocolVersion != eth::c_minorProtocolVersion ?
WithExisting::Verify
:
WithExisting::Trust;
} }
void VersionChecker::setOk() void VersionChecker::setOk()
{ {
if (!m_ok) if (m_action != WithExisting::Trust)
{ {
try try
{ {
@ -55,8 +64,7 @@ void VersionChecker::setOk()
{ {
cwarn << "Unhandled exception! Failed to create directory: " << m_path << "\n" << boost::current_exception_diagnostic_information(); cwarn << "Unhandled exception! Failed to create directory: " << m_path << "\n" << boost::current_exception_diagnostic_information();
} }
writeFile(m_path + "/protocol", rlp(eth::c_protocolVersion)); writeFile(m_path + "/status", rlpList(eth::c_protocolVersion, eth::c_minorProtocolVersion, c_databaseVersion));
writeFile(m_path + "/database", rlp(c_databaseVersion));
} }
} }
@ -102,12 +110,12 @@ void BasicGasPricer::update(BlockChain const& _bc)
} }
} }
Client::Client(p2p::Host* _extNet, std::string const& _dbPath, bool _forceClean, u256 _networkId, int _miners): Client::Client(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _forceAction, u256 _networkId, int _miners):
Worker("eth"), Worker("eth"),
m_vc(_dbPath), m_vc(_dbPath),
m_bc(_dbPath, !m_vc.ok() || _forceClean), m_bc(_dbPath, max(m_vc.action(), _forceAction)),
m_gp(new TrivialGasPricer), m_gp(new TrivialGasPricer),
m_stateDB(State::openDB(_dbPath, !m_vc.ok() || _forceClean)), m_stateDB(State::openDB(_dbPath, max(m_vc.action(), _forceAction))),
m_preMine(Address(), m_stateDB), m_preMine(Address(), m_stateDB),
m_postMine(Address(), m_stateDB) m_postMine(Address(), m_stateDB)
{ {
@ -127,12 +135,12 @@ Client::Client(p2p::Host* _extNet, std::string const& _dbPath, bool _forceClean,
startWorking(); startWorking();
} }
Client::Client(p2p::Host* _extNet, std::shared_ptr<GasPricer> _gp, std::string const& _dbPath, bool _forceClean, u256 _networkId, int _miners): Client::Client(p2p::Host* _extNet, std::shared_ptr<GasPricer> _gp, std::string const& _dbPath, WithExisting _forceAction, u256 _networkId, int _miners):
Worker("eth"), Worker("eth"),
m_vc(_dbPath), m_vc(_dbPath),
m_bc(_dbPath, !m_vc.ok() || _forceClean), m_bc(_dbPath, max(m_vc.action(), _forceAction)),
m_gp(_gp), m_gp(_gp),
m_stateDB(State::openDB(_dbPath, !m_vc.ok() || _forceClean)), m_stateDB(State::openDB(_dbPath, max(m_vc.action(), _forceAction))),
m_preMine(Address(), m_stateDB), m_preMine(Address(), m_stateDB),
m_postMine(Address(), m_stateDB) m_postMine(Address(), m_stateDB)
{ {
@ -202,9 +210,9 @@ void Client::killChain()
{ {
WriteGuard l(x_stateDB); WriteGuard l(x_stateDB);
m_stateDB = OverlayDB(); m_stateDB = OverlayDB();
m_stateDB = State::openDB(Defaults::dbPath(), true); m_stateDB = State::openDB(Defaults::dbPath(), WithExisting::Kill);
} }
m_bc.reopen(Defaults::dbPath(), true); m_bc.reopen(Defaults::dbPath(), WithExisting::Kill);
m_preMine = State(Address(), m_stateDB); m_preMine = State(Address(), m_stateDB);
m_postMine = State(Address(), m_stateDB); m_postMine = State(Address(), m_stateDB);

8
libethereum/Client.h

@ -65,10 +65,10 @@ public:
VersionChecker(std::string const& _dbPath); VersionChecker(std::string const& _dbPath);
void setOk(); void setOk();
bool ok() const { return m_ok; } WithExisting action() const { return m_action; }
private: private:
bool m_ok; WithExisting m_action;
std::string m_path; std::string m_path;
}; };
@ -126,7 +126,7 @@ public:
explicit Client( explicit Client(
p2p::Host* _host, p2p::Host* _host,
std::string const& _dbPath = std::string(), std::string const& _dbPath = std::string(),
bool _forceClean = false, WithExisting _forceAction = WithExisting::Trust,
u256 _networkId = 0, u256 _networkId = 0,
int _miners = -1 int _miners = -1
); );
@ -135,7 +135,7 @@ public:
p2p::Host* _host, p2p::Host* _host,
std::shared_ptr<GasPricer> _gpForAdoption, // pass it in with new. std::shared_ptr<GasPricer> _gpForAdoption, // pass it in with new.
std::string const& _dbPath = std::string(), std::string const& _dbPath = std::string(),
bool _forceClean = false, WithExisting _forceAction = WithExisting::Trust,
u256 _networkId = 0, u256 _networkId = 0,
int _miners = -1 int _miners = -1
); );

4
libethereum/State.cpp

@ -46,13 +46,13 @@ using namespace dev::eth;
static const u256 c_blockReward = 1500 * finney; static const u256 c_blockReward = 1500 * finney;
OverlayDB State::openDB(std::string _path, bool _killExisting) OverlayDB State::openDB(std::string _path, WithExisting _we)
{ {
if (_path.empty()) if (_path.empty())
_path = Defaults::get()->m_dbPath; _path = Defaults::get()->m_dbPath;
boost::filesystem::create_directory(_path); boost::filesystem::create_directory(_path);
if (_killExisting) if (_we == WithExisting::Kill)
boost::filesystem::remove_all(_path + "/state"); boost::filesystem::remove_all(_path + "/state");
ldb::Options o; ldb::Options o;

4
libethereum/State.h

@ -123,8 +123,8 @@ public:
Address address() const { return m_ourAddress; } Address address() const { return m_ourAddress; }
/// Open a DB - useful for passing into the constructor & keeping for other states that are necessary. /// Open a DB - useful for passing into the constructor & keeping for other states that are necessary.
static OverlayDB openDB(std::string _path, bool _killExisting = false); static OverlayDB openDB(std::string _path, WithExisting _we = WithExisting::Trust);
static OverlayDB openDB(bool _killExisting = false) { return openDB(std::string(), _killExisting); } static OverlayDB openDB(WithExisting _we = WithExisting::Trust) { return openDB(std::string(), _we); }
OverlayDB const& db() const { return m_db; } OverlayDB const& db() const { return m_db; }
/// @returns the set containing all addresses currently in use in Ethereum. /// @returns the set containing all addresses currently in use in Ethereum.

2
libtestutils/BlockChainLoader.cpp

@ -35,7 +35,7 @@ BlockChainLoader::BlockChainLoader(Json::Value const& _json)
m_state = sl.state(); m_state = sl.state();
// load genesisBlock // load genesisBlock
m_bc.reset(new BlockChain(fromHex(_json["genesisRLP"].asString()), m_dir.path(), true)); m_bc.reset(new BlockChain(fromHex(_json["genesisRLP"].asString()), m_dir.path(), WithExisting::Kill));
// load blocks // load blocks
for (auto const& block: _json["blocks"]) for (auto const& block: _json["blocks"])

4
libwebthree/WebThree.cpp

@ -39,7 +39,7 @@ using namespace dev::shh;
WebThreeDirect::WebThreeDirect( WebThreeDirect::WebThreeDirect(
std::string const& _clientVersion, std::string const& _clientVersion,
std::string const& _dbPath, std::string const& _dbPath,
bool _forceClean, WithExisting _we,
std::set<std::string> const& _interfaces, std::set<std::string> const& _interfaces,
NetworkPreferences const& _n, NetworkPreferences const& _n,
bytesConstRef _network, int _miners bytesConstRef _network, int _miners
@ -50,7 +50,7 @@ WebThreeDirect::WebThreeDirect(
if (_dbPath.size()) if (_dbPath.size())
Defaults::setDBPath(_dbPath); Defaults::setDBPath(_dbPath);
if (_interfaces.count("eth")) if (_interfaces.count("eth"))
m_ethereum.reset(new eth::Client(&m_net, _dbPath, _forceClean, 0, _miners)); m_ethereum.reset(new eth::Client(&m_net, _dbPath, _we, 0, _miners));
if (_interfaces.count("shh")) if (_interfaces.count("shh"))
m_whisper = m_net.registerCapability<WhisperHost>(new WhisperHost); m_whisper = m_net.registerCapability<WhisperHost>(new WhisperHost);

8
libwebthree/WebThree.h

@ -25,17 +25,13 @@
#include <mutex> #include <mutex>
#include <list> #include <list>
#include <atomic> #include <atomic>
#include <boost/asio.hpp> // Make sure boost/asio.hpp is included before windows.h.
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include <libp2p/Host.h> #include <libp2p/Host.h>
#include <libwhisper/WhisperHost.h> #include <libwhisper/WhisperHost.h>
#include <libethereum/Client.h> #include <libethereum/Client.h>
@ -113,7 +109,7 @@ public:
WebThreeDirect( WebThreeDirect(
std::string const& _clientVersion, std::string const& _clientVersion,
std::string const& _dbPath, std::string const& _dbPath,
bool _forceClean = false, WithExisting _we = WithExisting::Trust,
std::set<std::string> const& _interfaces = {"eth", "shh"}, std::set<std::string> const& _interfaces = {"eth", "shh"},
p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(), p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(),
bytesConstRef _network = bytesConstRef(), bytesConstRef _network = bytesConstRef(),

2
mix/MixClient.h

@ -37,7 +37,7 @@ namespace mix
class MixBlockChain: public dev::eth::BlockChain class MixBlockChain: public dev::eth::BlockChain
{ {
public: public:
MixBlockChain(std::string const& _path, h256 _stateRoot): BlockChain(createGenesisBlock(_stateRoot), _path, true) {} MixBlockChain(std::string const& _path, h256 _stateRoot): BlockChain(createGenesisBlock(_stateRoot), _path, WithExisting::Kill) {}
static bytes createGenesisBlock(h256 _stateRoot); static bytes createGenesisBlock(h256 _stateRoot);
}; };

2
neth/main.cpp

@ -550,7 +550,7 @@ int main(int argc, char** argv)
dev::WebThreeDirect web3( dev::WebThreeDirect web3(
clientImplString, clientImplString,
dbPath, dbPath,
killChain, killChain ? WithExisting::Kill : WithExisting::Trust,
mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(), mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(),
netPrefs, netPrefs,
&nodesState, &nodesState,

2
test/blockchain.cpp

@ -78,7 +78,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
// construct blockchain // construct blockchain
TransientDirectory td; TransientDirectory td;
BlockChain bc(rlpGenesisBlock.out(), td.path(), true); BlockChain bc(rlpGenesisBlock.out(), td.path(), WithExisting::Kill);
if (_fillin) if (_fillin)
{ {

Loading…
Cancel
Save