Browse Source

Easy reset of blockchain.

cl-refactor
Gav Wood 11 years ago
parent
commit
20ce1680d2
  1. 6
      alethzero/Main.ui
  2. 11
      alethzero/MainWin.cpp
  3. 1
      alethzero/MainWin.h
  4. 6
      libethcore/TrieDB.cpp
  5. 1
      libethcore/TrieDB.h
  6. 5
      libethereum/BlockChain.cpp
  7. 6
      libethereum/Client.cpp
  8. 2
      libethereum/Client.h
  9. 1
      libethereum/State.cpp

6
alethzero/Main.ui

@ -150,6 +150,7 @@
</property> </property>
<addaction name="debugStep"/> <addaction name="debugStep"/>
<addaction name="paranoia"/> <addaction name="paranoia"/>
<addaction name="killBlockchain"/>
</widget> </widget>
<addaction name="menu_File"/> <addaction name="menu_File"/>
<addaction name="menu_Network"/> <addaction name="menu_Network"/>
@ -1026,6 +1027,11 @@
<string>Mining &amp;Paranoia</string> <string>Mining &amp;Paranoia</string>
</property> </property>
</action> </action>
<action name="killBlockchain">
<property name="text">
<string>&amp;Kill Blockchain</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

11
alethzero/MainWin.cpp

@ -168,7 +168,6 @@ Main::Main(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
g_logPost = [=](std::string const& s, char const* c) { simpleDebugOut(s, c); ui->log->addItem(QString::fromStdString(s)); }; g_logPost = [=](std::string const& s, char const* c) { simpleDebugOut(s, c); ui->log->addItem(QString::fromStdString(s)); };
m_client.reset(new Client("AlethZero")); m_client.reset(new Client("AlethZero"));
m_client->setParanoia(false);
m_refresh = new QTimer(this); m_refresh = new QTimer(this);
connect(m_refresh, SIGNAL(timeout()), SLOT(refresh())); connect(m_refresh, SIGNAL(timeout()), SLOT(refresh()));
@ -881,6 +880,16 @@ void Main::on_data_textChanged()
updateFee(); updateFee();
} }
void Main::on_killBlockchain_triggered()
{
writeSettings();
ui->mine->setChecked(false);
ui->net->setChecked(false);
m_client.reset();
m_client.reset(new Client("AlethZero", Address(), string(), true));
readSettings();
}
bool Main::isCreation() const bool Main::isCreation() const
{ {
return ui->destination->currentText().isEmpty() || ui->destination->currentText() == "(Create Contract)"; return ui->destination->currentText().isEmpty() || ui->destination->currentText() == "(Create Contract)";

1
alethzero/MainWin.h

@ -76,6 +76,7 @@ private slots:
void on_debug_clicked(); void on_debug_clicked();
void on_debugTimeline_valueChanged(); void on_debugTimeline_valueChanged();
void on_jsInput_returnPressed(); void on_jsInput_returnPressed();
void on_killBlockchain_triggered();
void refresh(bool _override = false); void refresh(bool _override = false);
void refreshNetwork(); void refreshNetwork();

6
libethcore/TrieDB.cpp

@ -29,4 +29,10 @@ namespace eth
const h256 c_shaNull = sha3(rlp("")); const h256 c_shaNull = sha3(rlp(""));
Overlay::~Overlay()
{
if (m_db.use_count() == 1 && m_db.get())
cnote << "Closing state DB";
}
} }

1
libethcore/TrieDB.h

@ -65,6 +65,7 @@ class Overlay: public BasicMap
{ {
public: public:
Overlay(ldb::DB* _db = nullptr): m_db(_db) {} Overlay(ldb::DB* _db = nullptr): m_db(_db) {}
~Overlay();
ldb::DB* db() const { return m_db.get(); } ldb::DB* db() const { return m_db.get(); }
void setDB(ldb::DB* _db, bool _clearOverlay = true) { m_db = std::shared_ptr<ldb::DB>(_db); if (_clearOverlay) m_over.clear(); } void setDB(ldb::DB* _db, bool _clearOverlay = true) { m_db = std::shared_ptr<ldb::DB>(_db); if (_clearOverlay) m_over.clear(); }

5
libethereum/BlockChain.cpp

@ -102,11 +102,14 @@ BlockChain::BlockChain(std::string _path, bool _killExisting)
m_detailsDB->Get(m_readOptions, ldb::Slice("best"), &l); m_detailsDB->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();
cout << "Opened blockchain db. Latest: " << m_lastBlockHash << endl; cnote << "Opened blockchain DB. Latest: " << m_lastBlockHash;
} }
BlockChain::~BlockChain() BlockChain::~BlockChain()
{ {
cnote << "Closing blockchain DB";
delete m_detailsDB;
delete m_db;
} }
template <class T, class V> template <class T, class V>

6
libethereum/Client.cpp

@ -50,11 +50,11 @@ void VersionChecker::setOk()
} }
} }
Client::Client(std::string const& _clientVersion, Address _us, std::string const& _dbPath): Client::Client(std::string const& _clientVersion, Address _us, std::string const& _dbPath, bool _forceClean):
m_clientVersion(_clientVersion), m_clientVersion(_clientVersion),
m_vc(_dbPath, PeerServer::protocolVersion()), m_vc(_dbPath, PeerServer::protocolVersion()),
m_bc(_dbPath, !m_vc.ok()), m_bc(_dbPath, !m_vc.ok() || _forceClean),
m_stateDB(State::openDB(_dbPath, !m_vc.ok())), m_stateDB(State::openDB(_dbPath, !m_vc.ok() || _forceClean)),
m_preMine(_us, m_stateDB), m_preMine(_us, m_stateDB),
m_postMine(_us, m_stateDB), m_postMine(_us, m_stateDB),
m_workState(Active) m_workState(Active)

2
libethereum/Client.h

@ -78,7 +78,7 @@ class Client
{ {
public: public:
/// Constructor. /// Constructor.
explicit Client(std::string const& _clientVersion, Address _us = Address(), std::string const& _dbPath = std::string()); explicit Client(std::string const& _clientVersion, Address _us = Address(), std::string const& _dbPath = std::string(), bool _forceClean = false);
/// Destructor. /// Destructor.
~Client(); ~Client();

1
libethereum/State.cpp

@ -64,6 +64,7 @@ Overlay State::openDB(std::string _path, bool _killExisting)
o.create_if_missing = true; o.create_if_missing = true;
ldb::DB* db = nullptr; ldb::DB* db = nullptr;
ldb::DB::Open(o, _path + "/state", &db); ldb::DB::Open(o, _path + "/state", &db);
cnote << "Opened state DB.";
return Overlay(db); return Overlay(db);
} }

Loading…
Cancel
Save