Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 8a0f6ad

Browse files
authored
Merge pull request #4622 from ethereum/snapshot-download-fibers
Download snapshot through Parity's warp protocol
2 parents e690185 + fdd3dc5 commit 8a0f6ad

File tree

18 files changed

+2562
-2056
lines changed

18 files changed

+2562
-2056
lines changed

eth/main.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ int main(int argc, char** argv)
333333
("no-discovery", "Disable node discovery, implies --no-bootstrap.")
334334
("pin", "Only accept or connect to trusted peers.");
335335

336+
std::string snapshotPath;
336337
po::options_description importExportMode("Import/export modes", c_lineWidth);
337338
importExportMode.add_options()
338339
("import,I", po::value<string>()->value_name("<file>"), "Import blocks from file.")
@@ -342,6 +343,7 @@ int main(int argc, char** argv)
342343
("only", po::value<string>()->value_name("<n>"), "Equivalent to --export-from n --export-to n.")
343344
("format", po::value<string>()->value_name("<binary/hex/human>"), "Set export format.")
344345
("dont-check", "Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid.")
346+
("download-snapshot", po::value<string>(&snapshotPath)->value_name("<path>"), "Download Parity Warp Sync snapshot data to the specified path.")
345347
("import-snapshot", po::value<string>()->value_name("<path>"), "Import blockchain and state data from the Parity Warp Sync snapshot.\n");
346348

347349
po::options_description generalOptions("General Options", c_lineWidth);
@@ -852,16 +854,9 @@ int main(int argc, char** argv)
852854
chainParams.allowFutureBlocks = true;
853855
}
854856

855-
dev::WebThreeDirect web3(
856-
WebThreeDirect::composeClientVersion("eth"),
857-
getDataDir(),
858-
chainParams,
859-
withExisting,
860-
nodeMode == NodeMode::Full ? caps : set<string>(),
861-
netPrefs,
862-
&nodesState,
863-
testingMode
864-
);
857+
dev::WebThreeDirect web3(WebThreeDirect::composeClientVersion("eth"), getDataDir(),
858+
snapshotPath, chainParams, withExisting, nodeMode == NodeMode::Full ? caps : set<string>(),
859+
netPrefs, &nodesState, testingMode);
865860

866861
if (!extraData.empty())
867862
web3.ethereum()->setExtraData(extraData);

libethashseal/EthashClient.cpp

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
This file is part of cpp-ethereum.
2+
This file is part of cpp-ethereum.
33
4-
cpp-ethereum is free software: you can redistribute it and/or modify
5-
it under the terms of the GNU General Public License as published by
6-
the Free Software Foundation, either version 3 of the License, or
7-
(at your option) any later version.
4+
cpp-ethereum is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
88
9-
cpp-ethereum is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
GNU General Public License for more details.
9+
cpp-ethereum is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
1313
14-
You should have received a copy of the GNU General Public License
15-
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
14+
You should have received a copy of the GNU General Public License
15+
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
/** @file EthashClient.cpp
1818
* @author Gav Wood <i@gavwood.com>
@@ -30,112 +30,108 @@ namespace fs = boost::filesystem;
3030

3131
EthashClient& dev::eth::asEthashClient(Interface& _c)
3232
{
33-
if (dynamic_cast<Ethash*>(_c.sealEngine()))
34-
return dynamic_cast<EthashClient&>(_c);
35-
throw InvalidSealEngine();
33+
if (dynamic_cast<Ethash*>(_c.sealEngine()))
34+
return dynamic_cast<EthashClient&>(_c);
35+
throw InvalidSealEngine();
3636
}
3737

3838
EthashClient* dev::eth::asEthashClient(Interface* _c)
3939
{
40-
if (dynamic_cast<Ethash*>(_c->sealEngine()))
41-
return &dynamic_cast<EthashClient&>(*_c);
42-
throw InvalidSealEngine();
40+
if (dynamic_cast<Ethash*>(_c->sealEngine()))
41+
return &dynamic_cast<EthashClient&>(*_c);
42+
throw InvalidSealEngine();
4343
}
4444

4545
DEV_SIMPLE_EXCEPTION(ChainParamsNotEthash);
4646

47-
EthashClient::EthashClient(
48-
ChainParams const& _params,
49-
int _networkID,
50-
p2p::Host* _host,
51-
std::shared_ptr<GasPricer> _gpForAdoption,
52-
fs::path const& _dbPath,
53-
WithExisting _forceAction,
54-
TransactionQueue::Limits const& _limits
55-
):
56-
Client(_params, _networkID, _host, _gpForAdoption, _dbPath, _forceAction, _limits)
47+
EthashClient::EthashClient(ChainParams const& _params, int _networkID, p2p::Host* _host,
48+
std::shared_ptr<GasPricer> _gpForAdoption, fs::path const& _dbPath,
49+
fs::path const& _snapshotPath, WithExisting _forceAction,
50+
TransactionQueue::Limits const& _limits)
51+
: Client(
52+
_params, _networkID, _host, _gpForAdoption, _dbPath, _snapshotPath, _forceAction, _limits)
5753
{
58-
// will throw if we're not an Ethash seal engine.
59-
asEthashClient(*this);
54+
// will throw if we're not an Ethash seal engine.
55+
asEthashClient(*this);
6056
}
6157

6258
EthashClient::~EthashClient()
6359
{
64-
terminate();
60+
terminate();
6561
}
6662

6763
Ethash* EthashClient::ethash() const
6864
{
69-
return dynamic_cast<Ethash*>(Client::sealEngine());
65+
return dynamic_cast<Ethash*>(Client::sealEngine());
7066
}
7167

7268
bool EthashClient::isMining() const
7369
{
74-
return ethash()->farm().isMining();
70+
return ethash()->farm().isMining();
7571
}
7672

7773
WorkingProgress EthashClient::miningProgress() const
7874
{
79-
if (isMining())
80-
return ethash()->farm().miningProgress();
81-
return WorkingProgress();
75+
if (isMining())
76+
return ethash()->farm().miningProgress();
77+
return WorkingProgress();
8278
}
8379

8480
u256 EthashClient::hashrate() const
8581
{
86-
u256 r = externalHashrate();
87-
if (isMining())
88-
r += miningProgress().rate();
89-
return r;
82+
u256 r = externalHashrate();
83+
if (isMining())
84+
r += miningProgress().rate();
85+
return r;
9086
}
9187

9288
std::tuple<h256, h256, h256> EthashClient::getEthashWork()
9389
{
94-
// lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
95-
// this will be reset as soon as a new block arrives, allowing more transactions to be processed.
96-
bool oldShould = shouldServeWork();
97-
m_lastGetWork = chrono::system_clock::now();
98-
99-
if (!sealEngine()->shouldSeal(this))
100-
return std::tuple<h256, h256, h256>();
101-
102-
// if this request has made us bother to serve work, prep it now.
103-
if (!oldShould && shouldServeWork())
104-
onPostStateChanged();
105-
else
106-
// otherwise, set this to true so that it gets prepped next time.
107-
m_remoteWorking = true;
108-
ethash()->manuallySetWork(m_sealingInfo);
109-
return std::tuple<h256, h256, h256>(m_sealingInfo.hash(WithoutSeal), Ethash::seedHash(m_sealingInfo), Ethash::boundary(m_sealingInfo));
90+
// lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
91+
// this will be reset as soon as a new block arrives, allowing more transactions to be processed.
92+
bool oldShould = shouldServeWork();
93+
m_lastGetWork = chrono::system_clock::now();
94+
95+
if (!sealEngine()->shouldSeal(this))
96+
return std::tuple<h256, h256, h256>();
97+
98+
// if this request has made us bother to serve work, prep it now.
99+
if (!oldShould && shouldServeWork())
100+
onPostStateChanged();
101+
else
102+
// otherwise, set this to true so that it gets prepped next time.
103+
m_remoteWorking = true;
104+
ethash()->manuallySetWork(m_sealingInfo);
105+
return std::tuple<h256, h256, h256>(m_sealingInfo.hash(WithoutSeal), Ethash::seedHash(m_sealingInfo), Ethash::boundary(m_sealingInfo));
110106
}
111107

112108
bool EthashClient::submitEthashWork(h256 const& _mixHash, h64 const& _nonce)
113109
{
114-
ethash()->manuallySubmitWork(_mixHash, _nonce);
115-
return true;
110+
ethash()->manuallySubmitWork(_mixHash, _nonce);
111+
return true;
116112
}
117113

118114
void EthashClient::setShouldPrecomputeDAG(bool _precompute)
119115
{
120-
bytes trueBytes {1};
121-
bytes falseBytes {0};
122-
sealEngine()->setOption("precomputeDAG", _precompute ? trueBytes: falseBytes);
116+
bytes trueBytes {1};
117+
bytes falseBytes {0};
118+
sealEngine()->setOption("precomputeDAG", _precompute ? trueBytes: falseBytes);
123119
}
124120

125121
void EthashClient::submitExternalHashrate(u256 const& _rate, h256 const& _id)
126122
{
127-
WriteGuard writeGuard(x_externalRates);
128-
m_externalRates[_id] = make_pair(_rate, chrono::steady_clock::now());
123+
WriteGuard writeGuard(x_externalRates);
124+
m_externalRates[_id] = make_pair(_rate, chrono::steady_clock::now());
129125
}
130126

131127
u256 EthashClient::externalHashrate() const
132128
{
133-
u256 ret = 0;
134-
WriteGuard writeGuard(x_externalRates);
135-
for (auto i = m_externalRates.begin(); i != m_externalRates.end();)
136-
if (chrono::steady_clock::now() - i->second.second > chrono::seconds(5))
137-
i = m_externalRates.erase(i);
138-
else
139-
ret += i++->second.first;
140-
return ret;
129+
u256 ret = 0;
130+
WriteGuard writeGuard(x_externalRates);
131+
for (auto i = m_externalRates.begin(); i != m_externalRates.end();)
132+
if (chrono::steady_clock::now() - i->second.second > chrono::seconds(5))
133+
i = m_externalRates.erase(i);
134+
else
135+
ret += i++->second.first;
136+
return ret;
141137
}

libethashseal/EthashClient.h

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
This file is part of cpp-ethereum.
2+
This file is part of cpp-ethereum.
33
4-
cpp-ethereum is free software: you can redistribute it and/or modify
5-
it under the terms of the GNU General Public License as published by
6-
the Free Software Foundation, either version 3 of the License, or
7-
(at your option) any later version.
4+
cpp-ethereum is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
88
9-
cpp-ethereum is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
GNU General Public License for more details.
9+
cpp-ethereum is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
1313
14-
You should have received a copy of the GNU General Public License
15-
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
14+
You should have received a copy of the GNU General Public License
15+
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
/** @file EthashClient.h
1818
* @author Gav Wood <i@gavwood.com>
@@ -37,54 +37,50 @@ DEV_SIMPLE_EXCEPTION(InvalidSealEngine);
3737
class EthashClient: public Client
3838
{
3939
public:
40-
/// Trivial forwarding constructor.
41-
EthashClient(
42-
ChainParams const& _params,
43-
int _networkID,
44-
p2p::Host* _host,
45-
std::shared_ptr<GasPricer> _gpForAdoption,
46-
boost::filesystem::path const& _dbPath = boost::filesystem::path(),
47-
WithExisting _forceAction = WithExisting::Trust,
48-
TransactionQueue::Limits const& _l = TransactionQueue::Limits{1024, 1024}
49-
);
50-
~EthashClient();
40+
/// Trivial forwarding constructor.
41+
EthashClient(ChainParams const& _params, int _networkID, p2p::Host* _host,
42+
std::shared_ptr<GasPricer> _gpForAdoption, boost::filesystem::path const& _dbPath = {},
43+
boost::filesystem::path const& _snapshotPath = {},
44+
WithExisting _forceAction = WithExisting::Trust,
45+
TransactionQueue::Limits const& _l = TransactionQueue::Limits{1024, 1024});
46+
~EthashClient();
5147

52-
Ethash* ethash() const;
48+
Ethash* ethash() const;
5349

54-
/// Enable/disable precomputing of the DAG for next epoch
55-
void setShouldPrecomputeDAG(bool _precompute);
50+
/// Enable/disable precomputing of the DAG for next epoch
51+
void setShouldPrecomputeDAG(bool _precompute);
5652

57-
/// Are we mining now?
58-
bool isMining() const;
53+
/// Are we mining now?
54+
bool isMining() const;
5955

60-
/// The hashrate...
61-
u256 hashrate() const;
56+
/// The hashrate...
57+
u256 hashrate() const;
6258

63-
/// Check the progress of the mining.
64-
WorkingProgress miningProgress() const;
59+
/// Check the progress of the mining.
60+
WorkingProgress miningProgress() const;
6561

66-
/// @returns true only if it's worth bothering to prep the mining block.
67-
bool shouldServeWork() const { return m_bq.items().first == 0 && (isMining() || remoteActive()); }
62+
/// @returns true only if it's worth bothering to prep the mining block.
63+
bool shouldServeWork() const { return m_bq.items().first == 0 && (isMining() || remoteActive()); }
6864

69-
/// Update to the latest transactions and get hash of the current block to be mined minus the
70-
/// nonce (the 'work hash') and the difficulty to be met.
71-
/// @returns Tuple of hash without seal, seed hash, target boundary.
72-
std::tuple<h256, h256, h256> getEthashWork();
65+
/// Update to the latest transactions and get hash of the current block to be mined minus the
66+
/// nonce (the 'work hash') and the difficulty to be met.
67+
/// @returns Tuple of hash without seal, seed hash, target boundary.
68+
std::tuple<h256, h256, h256> getEthashWork();
7369

74-
/** @brief Submit the proof for the proof-of-work.
75-
* @param _s A valid solution.
76-
* @return true if the solution was indeed valid and accepted.
77-
*/
78-
bool submitEthashWork(h256 const& _mixHash, h64 const& _nonce);
70+
/** @brief Submit the proof for the proof-of-work.
71+
* @param _s A valid solution.
72+
* @return true if the solution was indeed valid and accepted.
73+
*/
74+
bool submitEthashWork(h256 const& _mixHash, h64 const& _nonce);
7975

80-
void submitExternalHashrate(u256 const& _rate, h256 const& _id);
76+
void submitExternalHashrate(u256 const& _rate, h256 const& _id);
8177

8278
protected:
83-
u256 externalHashrate() const;
79+
u256 externalHashrate() const;
8480

85-
// external hashrate
86-
mutable std::unordered_map<h256, std::pair<u256, std::chrono::steady_clock::time_point>> m_externalRates;
87-
mutable SharedMutex x_externalRates;
81+
// external hashrate
82+
mutable std::unordered_map<h256, std::pair<u256, std::chrono::steady_clock::time_point>> m_externalRates;
83+
mutable SharedMutex x_externalRates;
8884
};
8985

9086
EthashClient& asEthashClient(Interface& _c);

libethcore/Exceptions.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
This file is part of cpp-ethereum.
2+
This file is part of cpp-ethereum.
33
4-
cpp-ethereum is free software: you can redistribute it and/or modify
5-
it under the terms of the GNU General Public License as published by
6-
the Free Software Foundation, either version 3 of the License, or
7-
(at your option) any later version.
4+
cpp-ethereum is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
88
9-
cpp-ethereum is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
GNU General Public License for more details.
9+
cpp-ethereum is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
1313
14-
You should have received a copy of the GNU General Public License
15-
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
14+
You should have received a copy of the GNU General Public License
15+
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
/** @file Exceptions.h
1818
* @author Gav Wood <i@gavwood.com>
@@ -93,5 +93,7 @@ DEV_SIMPLE_EXCEPTION(InvalidStateChunkData);
9393
DEV_SIMPLE_EXCEPTION(InvalidBlockChunkData);
9494
DEV_SIMPLE_EXCEPTION(AccountAlreadyImported);
9595
DEV_SIMPLE_EXCEPTION(InvalidWarpStatusPacket);
96+
DEV_SIMPLE_EXCEPTION(FailedToDownloadManifest);
97+
DEV_SIMPLE_EXCEPTION(FailedToDownloadDaoForkBlockHeader);
9698
}
9799
}

0 commit comments

Comments
 (0)