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

Download snapshot through Parity's warp protocol #4622

Merged
merged 7 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions eth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ int main(int argc, char** argv)
("no-discovery", "Disable node discovery, implies --no-bootstrap.")
("pin", "Only accept or connect to trusted peers.");

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

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

dev::WebThreeDirect web3(
WebThreeDirect::composeClientVersion("eth"),
getDataDir(),
chainParams,
withExisting,
nodeMode == NodeMode::Full ? caps : set<string>(),
netPrefs,
&nodesState,
testingMode
);
dev::WebThreeDirect web3(WebThreeDirect::composeClientVersion("eth"), getDataDir(),
snapshotPath, chainParams, withExisting, nodeMode == NodeMode::Full ? caps : set<string>(),
netPrefs, &nodesState, testingMode);

if (!extraData.empty())
web3.ethereum()->setExtraData(extraData);
Expand Down
136 changes: 66 additions & 70 deletions libethashseal/EthashClient.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
This file is part of cpp-ethereum.
This file is part of cpp-ethereum.

cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthashClient.cpp
* @author Gav Wood <i@gavwood.com>
Expand All @@ -30,112 +30,108 @@ namespace fs = boost::filesystem;

EthashClient& dev::eth::asEthashClient(Interface& _c)
{
if (dynamic_cast<Ethash*>(_c.sealEngine()))
return dynamic_cast<EthashClient&>(_c);
throw InvalidSealEngine();
if (dynamic_cast<Ethash*>(_c.sealEngine()))
return dynamic_cast<EthashClient&>(_c);
throw InvalidSealEngine();
}

EthashClient* dev::eth::asEthashClient(Interface* _c)
{
if (dynamic_cast<Ethash*>(_c->sealEngine()))
return &dynamic_cast<EthashClient&>(*_c);
throw InvalidSealEngine();
if (dynamic_cast<Ethash*>(_c->sealEngine()))
return &dynamic_cast<EthashClient&>(*_c);
throw InvalidSealEngine();
}

DEV_SIMPLE_EXCEPTION(ChainParamsNotEthash);

EthashClient::EthashClient(
ChainParams const& _params,
int _networkID,
p2p::Host* _host,
std::shared_ptr<GasPricer> _gpForAdoption,
fs::path const& _dbPath,
WithExisting _forceAction,
TransactionQueue::Limits const& _limits
):
Client(_params, _networkID, _host, _gpForAdoption, _dbPath, _forceAction, _limits)
EthashClient::EthashClient(ChainParams const& _params, int _networkID, p2p::Host* _host,
std::shared_ptr<GasPricer> _gpForAdoption, fs::path const& _dbPath,
fs::path const& _snapshotPath, WithExisting _forceAction,
TransactionQueue::Limits const& _limits)
: Client(
_params, _networkID, _host, _gpForAdoption, _dbPath, _snapshotPath, _forceAction, _limits)
{
// will throw if we're not an Ethash seal engine.
asEthashClient(*this);
// will throw if we're not an Ethash seal engine.
asEthashClient(*this);
}

EthashClient::~EthashClient()
{
terminate();
terminate();
}

Ethash* EthashClient::ethash() const
{
return dynamic_cast<Ethash*>(Client::sealEngine());
return dynamic_cast<Ethash*>(Client::sealEngine());
}

bool EthashClient::isMining() const
{
return ethash()->farm().isMining();
return ethash()->farm().isMining();
}

WorkingProgress EthashClient::miningProgress() const
{
if (isMining())
return ethash()->farm().miningProgress();
return WorkingProgress();
if (isMining())
return ethash()->farm().miningProgress();
return WorkingProgress();
}

u256 EthashClient::hashrate() const
{
u256 r = externalHashrate();
if (isMining())
r += miningProgress().rate();
return r;
u256 r = externalHashrate();
if (isMining())
r += miningProgress().rate();
return r;
}

std::tuple<h256, h256, h256> EthashClient::getEthashWork()
{
// lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
// this will be reset as soon as a new block arrives, allowing more transactions to be processed.
bool oldShould = shouldServeWork();
m_lastGetWork = chrono::system_clock::now();

if (!sealEngine()->shouldSeal(this))
return std::tuple<h256, h256, h256>();

// if this request has made us bother to serve work, prep it now.
if (!oldShould && shouldServeWork())
onPostStateChanged();
else
// otherwise, set this to true so that it gets prepped next time.
m_remoteWorking = true;
ethash()->manuallySetWork(m_sealingInfo);
return std::tuple<h256, h256, h256>(m_sealingInfo.hash(WithoutSeal), Ethash::seedHash(m_sealingInfo), Ethash::boundary(m_sealingInfo));
// lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
// this will be reset as soon as a new block arrives, allowing more transactions to be processed.
bool oldShould = shouldServeWork();
m_lastGetWork = chrono::system_clock::now();

if (!sealEngine()->shouldSeal(this))
return std::tuple<h256, h256, h256>();

// if this request has made us bother to serve work, prep it now.
if (!oldShould && shouldServeWork())
onPostStateChanged();
else
// otherwise, set this to true so that it gets prepped next time.
m_remoteWorking = true;
ethash()->manuallySetWork(m_sealingInfo);
return std::tuple<h256, h256, h256>(m_sealingInfo.hash(WithoutSeal), Ethash::seedHash(m_sealingInfo), Ethash::boundary(m_sealingInfo));
}

bool EthashClient::submitEthashWork(h256 const& _mixHash, h64 const& _nonce)
{
ethash()->manuallySubmitWork(_mixHash, _nonce);
return true;
ethash()->manuallySubmitWork(_mixHash, _nonce);
return true;
}

void EthashClient::setShouldPrecomputeDAG(bool _precompute)
{
bytes trueBytes {1};
bytes falseBytes {0};
sealEngine()->setOption("precomputeDAG", _precompute ? trueBytes: falseBytes);
bytes trueBytes {1};
bytes falseBytes {0};
sealEngine()->setOption("precomputeDAG", _precompute ? trueBytes: falseBytes);
}

void EthashClient::submitExternalHashrate(u256 const& _rate, h256 const& _id)
{
WriteGuard writeGuard(x_externalRates);
m_externalRates[_id] = make_pair(_rate, chrono::steady_clock::now());
WriteGuard writeGuard(x_externalRates);
m_externalRates[_id] = make_pair(_rate, chrono::steady_clock::now());
}

u256 EthashClient::externalHashrate() const
{
u256 ret = 0;
WriteGuard writeGuard(x_externalRates);
for (auto i = m_externalRates.begin(); i != m_externalRates.end();)
if (chrono::steady_clock::now() - i->second.second > chrono::seconds(5))
i = m_externalRates.erase(i);
else
ret += i++->second.first;
return ret;
u256 ret = 0;
WriteGuard writeGuard(x_externalRates);
for (auto i = m_externalRates.begin(); i != m_externalRates.end();)
if (chrono::steady_clock::now() - i->second.second > chrono::seconds(5))
i = m_externalRates.erase(i);
else
ret += i++->second.first;
return ret;
}
90 changes: 43 additions & 47 deletions libethashseal/EthashClient.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
This file is part of cpp-ethereum.
This file is part of cpp-ethereum.

cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthashClient.h
* @author Gav Wood <i@gavwood.com>
Expand All @@ -37,54 +37,50 @@ DEV_SIMPLE_EXCEPTION(InvalidSealEngine);
class EthashClient: public Client
{
public:
/// Trivial forwarding constructor.
EthashClient(
ChainParams const& _params,
int _networkID,
p2p::Host* _host,
std::shared_ptr<GasPricer> _gpForAdoption,
boost::filesystem::path const& _dbPath = boost::filesystem::path(),
WithExisting _forceAction = WithExisting::Trust,
TransactionQueue::Limits const& _l = TransactionQueue::Limits{1024, 1024}
);
~EthashClient();
/// Trivial forwarding constructor.
EthashClient(ChainParams const& _params, int _networkID, p2p::Host* _host,
std::shared_ptr<GasPricer> _gpForAdoption, boost::filesystem::path const& _dbPath = {},
boost::filesystem::path const& _snapshotPath = {},
WithExisting _forceAction = WithExisting::Trust,
TransactionQueue::Limits const& _l = TransactionQueue::Limits{1024, 1024});
~EthashClient();

Ethash* ethash() const;
Ethash* ethash() const;

/// Enable/disable precomputing of the DAG for next epoch
void setShouldPrecomputeDAG(bool _precompute);
/// Enable/disable precomputing of the DAG for next epoch
void setShouldPrecomputeDAG(bool _precompute);

/// Are we mining now?
bool isMining() const;
/// Are we mining now?
bool isMining() const;

/// The hashrate...
u256 hashrate() const;
/// The hashrate...
u256 hashrate() const;

/// Check the progress of the mining.
WorkingProgress miningProgress() const;
/// Check the progress of the mining.
WorkingProgress miningProgress() const;

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

/// Update to the latest transactions and get hash of the current block to be mined minus the
/// nonce (the 'work hash') and the difficulty to be met.
/// @returns Tuple of hash without seal, seed hash, target boundary.
std::tuple<h256, h256, h256> getEthashWork();
/// Update to the latest transactions and get hash of the current block to be mined minus the
/// nonce (the 'work hash') and the difficulty to be met.
/// @returns Tuple of hash without seal, seed hash, target boundary.
std::tuple<h256, h256, h256> getEthashWork();

/** @brief Submit the proof for the proof-of-work.
* @param _s A valid solution.
* @return true if the solution was indeed valid and accepted.
*/
bool submitEthashWork(h256 const& _mixHash, h64 const& _nonce);
/** @brief Submit the proof for the proof-of-work.
* @param _s A valid solution.
* @return true if the solution was indeed valid and accepted.
*/
bool submitEthashWork(h256 const& _mixHash, h64 const& _nonce);

void submitExternalHashrate(u256 const& _rate, h256 const& _id);
void submitExternalHashrate(u256 const& _rate, h256 const& _id);

protected:
u256 externalHashrate() const;
u256 externalHashrate() const;

// external hashrate
mutable std::unordered_map<h256, std::pair<u256, std::chrono::steady_clock::time_point>> m_externalRates;
mutable SharedMutex x_externalRates;
// external hashrate
mutable std::unordered_map<h256, std::pair<u256, std::chrono::steady_clock::time_point>> m_externalRates;
mutable SharedMutex x_externalRates;
};

EthashClient& asEthashClient(Interface& _c);
Expand Down
24 changes: 13 additions & 11 deletions libethcore/Exceptions.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
This file is part of cpp-ethereum.
This file is part of cpp-ethereum.

cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Exceptions.h
* @author Gav Wood <i@gavwood.com>
Expand Down Expand Up @@ -93,5 +93,7 @@ DEV_SIMPLE_EXCEPTION(InvalidStateChunkData);
DEV_SIMPLE_EXCEPTION(InvalidBlockChunkData);
DEV_SIMPLE_EXCEPTION(AccountAlreadyImported);
DEV_SIMPLE_EXCEPTION(InvalidWarpStatusPacket);
DEV_SIMPLE_EXCEPTION(FailedToDownloadManifest);
DEV_SIMPLE_EXCEPTION(FailedToDownloadDaoForkBlockHeader);
}
}
Loading