20
20
*/
21
21
22
22
#include " Client.h"
23
- #include < chrono>
24
- #include < memory>
25
- #include < thread>
26
- #include < boost/filesystem.hpp>
27
- #include < libdevcore/Log.h>
28
- #include < libp2p/Host.h>
23
+ #include " Block.h"
29
24
#include " Defaults.h"
30
- #include " Executive.h"
31
25
#include " EthereumHost.h"
32
- #include " Block.h"
26
+ #include " Executive.h"
27
+ #include " SnapshotStorage.h"
33
28
#include " TransactionQueue.h"
29
+ #include < libdevcore/Log.h>
30
+ #include < libp2p/Host.h>
31
+ #include < boost/filesystem.hpp>
32
+ #include < chrono>
33
+ #include < memory>
34
+ #include < thread>
35
+
34
36
using namespace std ;
35
37
using namespace dev ;
36
38
using namespace dev ::eth;
@@ -87,19 +89,19 @@ Client::~Client()
87
89
88
90
void Client::init (p2p::Host* _extNet, fs::path const & _dbPath, WithExisting _forceAction, u256 _networkId)
89
91
{
90
- DEV_TIMED_FUNCTION_ABOVE (500 );
92
+ DEV_TIMED_FUNCTION_ABOVE (500 );
91
93
92
- // Cannot be opened until after blockchain is open, since BlockChain may upgrade the database.
94
+ // Cannot be opened until after blockchain is open, since BlockChain may upgrade the database.
93
95
// TODO: consider returning the upgrade mechanism here. will delaying the opening of the blockchain database
94
96
// until after the construction.
95
- m_stateDB = State::openDB (_dbPath, bc ().genesisHash (), _forceAction);
97
+ m_stateDB = State::openDB (_dbPath, bc ().genesisHash (), _forceAction);
96
98
// LAZY. TODO: move genesis state construction/commiting to stateDB openning and have this just take the root from the genesis block.
97
- m_preSeal = bc ().genesisBlock (m_stateDB);
98
- m_postSeal = m_preSeal;
99
+ m_preSeal = bc ().genesisBlock (m_stateDB);
100
+ m_postSeal = m_preSeal;
99
101
100
- m_bq.setChain (bc ());
102
+ m_bq.setChain (bc ());
101
103
102
- m_lastGetWork = std::chrono::system_clock::now () - chrono::seconds (30 );
104
+ m_lastGetWork = std::chrono::system_clock::now () - chrono::seconds (30 );
103
105
m_tqReady = m_tq.onReady ([=]() {
104
106
this ->onTransactionQueueReady ();
105
107
}); // TODO: should read m_tq->onReady(thisThread, syncTransactionQueue);
@@ -111,21 +113,26 @@ void Client::init(p2p::Host* _extNet, fs::path const& _dbPath, WithExisting _for
111
113
bc ().setOnBad ([=](Exception& ex) { this ->onBadBlock (ex); });
112
114
bc ().setOnBlockImport ([=](BlockHeader const & _info) {
113
115
if (auto h = m_host.lock ())
114
- h->onBlockImported (_info);
116
+ h->onBlockImported (_info);
115
117
});
116
118
117
119
if (_forceAction == WithExisting::Rescue)
118
- bc ().rescue (m_stateDB);
120
+ bc ().rescue (m_stateDB);
119
121
120
- m_gp->update (bc ());
122
+ m_gp->update (bc ());
121
123
122
124
auto host = _extNet->registerCapability (make_shared<EthereumHost>(bc (), m_stateDB, m_tq, m_bq, _networkId));
123
- m_host = host;
125
+ m_host = host;
124
126
125
127
_extNet->addCapability (host, EthereumHost::staticName (), EthereumHost::c_oldProtocolVersion); // TODO: remove this once v61+ protocol is common
126
128
127
- m_warpHost =
128
- _extNet->registerCapability (make_shared<WarpHostCapability>(bc (), _networkId, _dbPath));
129
+ auto const snapshotPath = importedSnapshotPath (_dbPath, bc ().genesisHash ());
130
+ if (fs::exists (snapshotPath))
131
+ {
132
+ std::shared_ptr<SnapshotStorageFace> snapshotStorage = createSnapshotStorage (snapshotPath);
133
+ m_warpHost = _extNet->registerCapability (
134
+ make_shared<WarpHostCapability>(bc (), _networkId, snapshotStorage));
135
+ }
129
136
130
137
if (_dbPath.size ())
131
138
Defaults::setDBPath (_dbPath);
0 commit comments