From f22540f0e05f4984d2f590e9a3a63c164b89ab5f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 13 Apr 2015 01:38:04 +0200 Subject: [PATCH] Lots of build fixes. Now minimal version builds ok. --- alethzero/MainWin.cpp | 2 +- eth/main.cpp | 11 +- libethash-cl/ethash_cl_miner.cpp | 2 + libethash-cl/ethash_cl_miner.h | 2 + libethcore/Common.cpp | 3 +- libethcore/Common.h | 3 - libethcore/Ethash.cpp | 14 ++- libethcore/Ethash.h | 6 +- libethereum/Client.cpp | 124 ++++++++++------------ libethereum/Client.h | 10 +- libethereum/ClientBase.cpp | 4 +- libethereum/ClientBase.h | 43 ++++---- libethereum/Farm.h | 33 ++++-- libethereum/Interface.h | 2 +- libethereum/Miner.cpp | 0 libethereum/Miner.h | 0 libweb3jsonrpc/WebThreeStubServerBase.cpp | 5 +- libwebthree/WebThree.cpp | 4 +- libwebthree/WebThree.h | 3 +- 19 files changed, 143 insertions(+), 128 deletions(-) delete mode 100644 libethereum/Miner.cpp delete mode 100644 libethereum/Miner.h diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 374829a61..03d216a17 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -164,7 +164,7 @@ Main::Main(QWidget *parent) : statusBar()->addPermanentWidget(ui->chainStatus); statusBar()->addPermanentWidget(ui->blockCount); - ui->blockCount->setText(QString("PV%2 D%3 H%4 v%5").arg(eth::c_protocolVersion).arg(c_databaseVersion).arg(c_ethashVersion).arg(dev::Version)); + ui->blockCount->setText(QString("PV%2 D%3 %4-%5 v%6").arg(eth::c_protocolVersion).arg(c_databaseVersion).arg(ProofOfWork::name()).arg(ProofOfWork::revision()).arg(dev::Version)); connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved())); diff --git a/eth/main.cpp b/eth/main.cpp index 08f4b1de4..66abefd54 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #if ETH_READLINE #include #include @@ -44,7 +45,6 @@ #include #include #endif -#include #include "BuildInfo.h" using namespace std; using namespace dev; @@ -208,7 +208,7 @@ void doInitDAG(unsigned _n) BlockInfo bi; bi.number = _n; cout << "Initializing DAG for epoch beginning #" << (bi.number / 30000 * 30000) << " (seedhash " << bi.seedHash().abridged() << "). This will take a while." << endl; - Ethasher::get()->full(bi); + Ethash::prep(bi); exit(0); } @@ -269,7 +269,6 @@ int main(int argc, char** argv) /// Mining params unsigned mining = ~(unsigned)0; - int miners = -1; bool forceMining = false; KeyPair sigKey = KeyPair::create(); Secret sessionSecret; @@ -478,8 +477,6 @@ int main(int argc, char** argv) g_logVerbosity = atoi(argv[++i]); else if ((arg == "-x" || arg == "--peers") && i + 1 < argc) peers = atoi(argv[++i]); - else if ((arg == "-t" || arg == "--miners") && i + 1 < argc) - miners = atoi(argv[++i]); else if ((arg == "-o" || arg == "--mode") && i + 1 < argc) { string m = argv[++i]; @@ -541,9 +538,7 @@ int main(int argc, char** argv) killChain, nodeMode == NodeMode::Full ? set{"eth", "shh"} : set(), netPrefs, - &nodesState, - miners - ); + &nodesState); if (mode == OperationMode::DAGInit) doInitDAG(web3.ethereum()->blockChain().number() + (initDAG == PendingBlock ? 30000 : 0)); diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 96f1fa582..016d8af58 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -50,6 +50,8 @@ static void add_definition(std::string& source, char const* id, unsigned value) source.insert(source.begin(), buf, buf + strlen(buf)); } +ethash_cl_miner::search_hook::~search_hook() {} + ethash_cl_miner::ethash_cl_miner() : m_opencl_1_1() { diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index e478c739f..d3d9f0223 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/libethash-cl/ethash_cl_miner.h @@ -12,6 +12,8 @@ class ethash_cl_miner public: struct search_hook { + virtual ~search_hook(); // always a virtual destructor for a class with virtuals. + // reports progress, return true to abort virtual bool found(uint64_t const* nonces, uint32_t count) = 0; virtual bool searched(uint64_t start_nonce, uint32_t count) = 0; diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index f0e749aaa..a0ceb389e 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -23,6 +23,7 @@ #include #include #include "Exceptions.h" +#include "ProofOfWork.h" using namespace std; using namespace dev; using namespace dev::eth; @@ -41,7 +42,7 @@ const unsigned c_databaseVersionModifier = 1; const unsigned c_databaseVersionModifier = 0; #endif -const unsigned c_databaseVersion = c_databaseBaseVersion + (c_databaseVersionModifier << 8) + (c_ethashVersion << 9); +const unsigned c_databaseVersion = c_databaseBaseVersion + (c_databaseVersionModifier << 8) + (ProofOfWork::revision() << 9); vector> const& units() { diff --git a/libethcore/Common.h b/libethcore/Common.h index 4d01055f1..bb704405a 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -41,9 +41,6 @@ extern const unsigned c_minorProtocolVersion; /// Current database version. extern const unsigned c_databaseVersion; -/// Current database version. -extern const unsigned c_ethashVersion; - /// User-friendly string representation of the amount _b in wei. std::string formatBalance(bigint const& _b); diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index ac54ebe4d..03c7a3654 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -70,8 +70,7 @@ Ethash::WorkPackage Ethash::package(BlockInfo const& _bi) void Ethash::prep(BlockInfo const& _header) { - if (_header.number % ETHASH_EPOCH_LENGTH == 1) - EthashAux::full(_header); + EthashAux::full(_header); } bool Ethash::preVerify(BlockInfo const& _header) @@ -206,6 +205,12 @@ Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci): { } +Ethash::GPUMiner::~GPUMiner() +{ + delete m_hook; + delete m_miner; +} + bool Ethash::GPUMiner::report(uint64_t _nonce) { Nonce n = (Nonce)(u64)_nonce; @@ -221,7 +226,10 @@ void Ethash::GPUMiner::kickOff(WorkPackage const& _work) { if (m_miner) m_hook->abort(); - m_miner.reset(new ethash_cl_miner); + + delete m_miner; + m_miner = new ethash_cl_miner; + auto p = EthashAux::params(_work.seedHash); auto cb = [&](void* d) { EthashAux::full(_work.seedHash, bytesRef((byte*)d, p.full_size)); }; m_miner->init(p, cb, 32); diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 458cb4e6c..1a7d82149 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -105,6 +105,7 @@ public: public: GPUMiner(ConstructionInfo const& _ci); + ~GPUMiner(); static unsigned instances() { return 1; } @@ -115,8 +116,9 @@ public: private: bool report(uint64_t _nonce); - std::unique_ptr m_hook; - std::unique_ptr m_miner; + EthashCLHook* m_hook; + ethash_cl_miner* m_miner; + h256 m_minerSeed; WorkPackage m_lastWork; ///< Work loaded into m_miner. MineInfo m_info; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 81023f9ef..79216f609 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -126,9 +126,9 @@ Client::Client(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _for m_preMine(m_stateDB, BaseState::CanonGenesis), m_postMine(m_stateDB) { - m_tqReady = m_tq->onReady([=](){ this->onTransactionQueueReady(); }); // TODO: should read m_tq->onReady(thisThread, syncTransactionQueue); - m_bqReady = m_bq->onReady([=](){ this->onBlockQueueReady(); }); // TODO: should read m_bq->onReady(thisThread, syncBlockQueue); - m_farm->onSolutionFound([=](ProofOfWork::Solution const& s){ return this->submitWork(s); }); + m_tqReady = m_tq.onReady([=](){ this->onTransactionQueueReady(); }); // TODO: should read m_tq->onReady(thisThread, syncTransactionQueue); + m_bqReady = m_bq.onReady([=](){ this->onBlockQueueReady(); }); // TODO: should read m_bq->onReady(thisThread, syncBlockQueue); + m_farm.onSolutionFound([=](ProofOfWork::Solution const& s){ return this->submitWork(s); }); m_gp->update(m_bc); @@ -151,9 +151,9 @@ Client::Client(p2p::Host* _extNet, std::shared_ptr _gp, std::string c m_preMine(m_stateDB), m_postMine(m_stateDB) { - m_tq->onReady([=](){ this->onTransactionQueueReady(); }); - m_bq->onReady([=](){ this->onBlockQueueReady(); }); - m_farm->onSolutionFound([=](ProofOfWork::Solution const& s){ return this->submitWork(s); }); + m_tqReady = m_tq.onReady([=](){ this->onTransactionQueueReady(); }); // TODO: should read m_tq->onReady(thisThread, syncTransactionQueue); + m_bqReady = m_bq.onReady([=](){ this->onBlockQueueReady(); }); // TODO: should read m_bq->onReady(thisThread, syncBlockQueue); + m_farm.onSolutionFound([=](ProofOfWork::Solution const& s){ return this->submitWork(s); }); m_gp->update(m_bc); @@ -210,7 +210,7 @@ void Client::killChain() m_tq.clear(); m_bq.clear(); - m_localMiners.clear(); + m_farm.stop(); m_preMine = State(); m_postMine = State(); @@ -248,11 +248,7 @@ void Client::clearPending() m_postMine = m_preMine; } - { - ReadGuard l(x_localMiners); - for (auto& m: m_localMiners) - m.noteStateChange(); - } + startMining(); noteChanged(changeds); } @@ -315,34 +311,23 @@ void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed) void Client::setForceMining(bool _enable) { m_forceMining = _enable; - ReadGuard l(x_localMiners); - for (auto& m: m_localMiners) - m.noteStateChange(); + startMining(); } -MineProgress Client::miningProgress() const +MiningProgress Client::miningProgress() const { - MineProgress ret; - ReadGuard l(x_localMiners); - for (auto& m: m_localMiners) - ret.combine(m.miningProgress()); - return ret; + return MiningProgress(); } uint64_t Client::hashrate() const { - uint64_t ret = 0; - ReadGuard l(x_localMiners); - for (LocalMiner const& m: m_localMiners) - ret += m.miningProgress().hashes / m.miningProgress().ms; - return ret / 1000; + return 0; } std::list Client::miningHistory() { std::list ret; - - ReadGuard l(x_localMiners); +/* ReadGuard l(x_localMiners); if (m_localMiners.empty()) return ret; ret = m_localMiners[0].miningHistory(); @@ -353,11 +338,11 @@ std::list Client::miningHistory() auto li = l.begin(); for (; ri != ret.end() && li != l.end(); ++ri, ++li) ri->combine(*li); - } + }*/ return ret; } -void Client::setupState(State& _s) +/*void Client::setupState(State& _s) { { ReadGuard l(x_stateDB); @@ -378,7 +363,7 @@ void Client::setupState(State& _s) } else _s.commitToMine(m_bc); -} +}*/ ExecutionResult Client::call(Address _dest, bytes const& _data, u256 _gas, u256 _value, u256 _gasPrice, Address const& _from) { @@ -406,15 +391,7 @@ ExecutionResult Client::call(Address _dest, bytes const& _data, u256 _gas, u256 ProofOfWork::WorkPackage Client::getWork() { - Guard l(x_remoteMiner); - BlockInfo bi; - { - ReadGuard l(x_stateDB); - m_remoteMiner.update(m_postMine, m_bc); - m_postMine.commitToMine(m_bc); - bi = m_postMine.info(); - } - return ProofOfWork::package(bi); + return ProofOfWork::package(m_miningInfo); } bool Client::submitWork(ProofOfWork::Solution const& _solution) @@ -422,7 +399,7 @@ bool Client::submitWork(ProofOfWork::Solution const& _solution) bytes newBlock; { WriteGuard l(x_stateDB); - if (!m_postMine.completeMine(_solution)) + if (!m_postMine.completeMine(_solution)) return false; newBlock = m_postMine.blockData(); } @@ -435,7 +412,7 @@ bool Client::submitWork(ProofOfWork::Solution const& _solution) void Client::syncBlockQueue() { - ImportResult ir; + ImportRoute ir; { WriteGuard l(x_stateDB); @@ -446,30 +423,33 @@ void Client::syncBlockQueue() tie(ir.first, ir.second, m_syncBlockQueue) = m_bc.sync(m_bq, db, 100); x_stateDB.lock(); - if (fresh.size()) - m_stateDB = db; + if (ir.first.empty()) + return; + m_stateDB = db; } - - if (!ir.first.empty()) - onChainChanged(ir); - return true; + onChainChanged(ir); } void Client::syncTransactionQueue() { // returns TransactionReceipts, once for each transaction. cwork << "postSTATE <== TQ"; + + h256Set changeds; TransactionReceipts newPendingReceipts = m_postMine.sync(m_bc, m_tq, *m_gp); if (newPendingReceipts.size()) { for (size_t i = 0; i < newPendingReceipts.size(); i++) appendFromNewPending(newPendingReceipts[i], changeds, m_postMine.pending()[i].sha3()); - changeds.insert(PendingChangedFilter); - if (isMining()) - cnote << "Additional transaction ready: Restarting mining operation."; - resyncStateNeeded = true; + // TODO: Tell farm about new transaction (i.e. restartProofOfWork mining). + onPostStateChanged(); + + // Tell watches about the new transactions. + noteChanged(changeds); + + // Tell network about the new transactions. if (auto h = m_host.lock()) h->noteNewTransactions(); } @@ -504,27 +484,41 @@ void Client::onChainChanged(ImportRoute const& _ir) h256Set changeds; for (auto const& h: _ir.first) - if (h != _ir.second) - appendFromNewBlock(h, changeds); + appendFromNewBlock(h, changeds); changeds.insert(ChainChangedFilter); - noteChanged(changeds); // RESTART MINING - // LOCKS NEEDED? - Guard l(x_stateDB); - cwork << "preSTATE <== CHAIN"; - if (m_preMine.sync(m_bc) || m_postMine.address() != m_preMine.address()) + // LOCKS REALLY NEEDED? { - if (isMining()) - cnote << "New block on chain: Restarting mining operation."; - m_postMine = m_preMine; - resyncStateNeeded = true; - changeds.insert(PendingChangedFilter); + ReadGuard l(x_stateDB); + if (m_preMine.sync(m_bc) || m_postMine.address() != m_preMine.address()) + { + if (isMining()) + cnote << "New block on chain."; + + m_postMine = m_preMine; + changeds.insert(PendingChangedFilter); + + x_stateDB.unlock(); + onPostStateChanged(); + x_stateDB.lock(); + } + } + + noteChanged(changeds); +} +void Client::onPostStateChanged() +{ + cnote << "Post state changed: Restarting mining..."; + { + WriteGuard l(x_stateDB); m_postMine.commitToMine(m_bc); - m_farm.setWork(m_postMine.info()); + m_miningInfo = m_postMine.info(); } + + m_farm.setWork(m_miningInfo); } void Client::noteChanged(h256Set const& _filters) diff --git a/libethereum/Client.h b/libethereum/Client.h index 9f6bbfeb6..2235c4459 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -40,7 +40,6 @@ #include "TransactionQueue.h" #include "State.h" #include "CommonNet.h" -#include "Miner.h" #include "ABI.h" #include "Farm.h" #include "ClientBase.h" @@ -103,8 +102,6 @@ struct ClientDetail: public LogChannel { static const char* name() { return " C */ class Client: public ClientBase, Worker { - friend class OldMiner; - public: /// New-style Constructor. explicit Client( @@ -254,6 +251,10 @@ private: /// Magically called when m_tq needs syncing. Be nice and don't block. void onBlockQueueReady() { Guard l(x_fakeSignalSystemState); m_syncBlockQueue = true; } + /// Called when the post state has changed (i.e. when more transactions are in it or we're mining on a new block). + /// This updates m_miningInfo. + void onPostStateChanged(); + void checkWatchGarbage(); VersionChecker m_vc; ///< Dummy object to check & update the protocol version. @@ -265,12 +266,11 @@ private: OverlayDB m_stateDB; ///< Acts as the central point for the state database, so multiple States can share it. State m_preMine; ///< The present state of the client. State m_postMine; ///< The state of the client which we're mining (i.e. it'll have all the rewards added). + BlockInfo m_miningInfo; ///< The header we're attempting to mine on (derived from m_postMine). std::weak_ptr m_host; ///< Our Ethereum Host. Don't do anything if we can't lock. GenericFarm m_farm; ///< Our mining farm. - mutable Mutex x_remoteMiner; ///< The remote miner lock. - RemoteMiner m_remoteMiner; ///< The remote miner. Handler m_tqReady; Handler m_bqReady; diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 5a0aef7c3..ecc0fb7f5 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -20,10 +20,12 @@ * @date 2015 */ -#include #include "ClientBase.h" + +#include #include "BlockChain.h" #include "Executive.h" +#include "State.h" using namespace std; using namespace dev; diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 4b3cc5002..15dbbf1ab 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -25,6 +25,7 @@ #include #include "Interface.h" #include "LogFilter.h" +#include "TransactionQueue.h" namespace dev { @@ -60,15 +61,15 @@ struct ClientWatch }; struct WatchChannel: public LogChannel { static const char* name() { return "(o)"; } static const int verbosity = 7; }; -#define cwatch dev::LogOutputStream() +#define cwatch LogOutputStream() struct WorkInChannel: public LogChannel { static const char* name() { return ">W>"; } static const int verbosity = 16; }; struct WorkOutChannel: public LogChannel { static const char* name() { return "() -#define cworkin dev::LogOutputStream() -#define cworkout dev::LogOutputStream() +#define cwork LogOutputStream() +#define cworkin LogOutputStream() +#define cworkout LogOutputStream() -class ClientBase: public dev::eth::Interface +class ClientBase: public Interface { public: ClientBase() {} @@ -110,18 +111,18 @@ public: virtual LocalisedLogEntries checkWatch(unsigned _watchId) override; virtual h256 hashFromNumber(BlockNumber _number) const override; - virtual eth::BlockInfo blockInfo(h256 _hash) const override; - virtual eth::BlockDetails blockDetails(h256 _hash) const override; - virtual eth::Transaction transaction(h256 _transactionHash) const override; - virtual eth::Transaction transaction(h256 _blockHash, unsigned _i) const override; - virtual eth::Transactions transactions(h256 _blockHash) const override; - virtual eth::TransactionHashes transactionHashes(h256 _blockHash) const override; - virtual eth::BlockInfo uncle(h256 _blockHash, unsigned _i) const override; - virtual eth::UncleHashes uncleHashes(h256 _blockHash) const override; + virtual BlockInfo blockInfo(h256 _hash) const override; + virtual BlockDetails blockDetails(h256 _hash) const override; + virtual Transaction transaction(h256 _transactionHash) const override; + virtual Transaction transaction(h256 _blockHash, unsigned _i) const override; + virtual Transactions transactions(h256 _blockHash) const override; + virtual TransactionHashes transactionHashes(h256 _blockHash) const override; + virtual BlockInfo uncle(h256 _blockHash, unsigned _i) const override; + virtual UncleHashes uncleHashes(h256 _blockHash) const override; virtual unsigned transactionCount(h256 _blockHash) const override; virtual unsigned uncleCount(h256 _blockHash) const override; virtual unsigned number() const override; - virtual eth::Transactions pending() const override; + virtual Transactions pending() const override; virtual h256s pendingHashes() const override; void injectBlock(bytes const& _block); @@ -142,13 +143,13 @@ public: /// TODO: consider moving it to a separate interface - virtual void startMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::startMining")); } - virtual void stopMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::stopMining")); } - virtual bool isMining() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::isMining")); } - virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::hashrate")); } - virtual eth::MineProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::miningProgress")); } - virtual std::pair getWork() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::getWork")); } - virtual bool submitWork(eth::ProofOfWork::Solution const&) override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::submitWork")); } + virtual void startMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::startMining")); } + virtual void stopMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::stopMining")); } + virtual bool isMining() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::isMining")); } + virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::hashrate")); } + virtual MiningProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::miningProgress")); } + virtual ProofOfWork::WorkPackage getWork() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::getWork")); } + virtual bool submitWork(ProofOfWork::Solution const&) override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::submitWork")); } State asOf(BlockNumber _h) const; diff --git a/libethereum/Farm.h b/libethereum/Farm.h index 137c137d3..09c7f0e78 100644 --- a/libethereum/Farm.h +++ b/libethereum/Farm.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace dev { @@ -45,17 +46,25 @@ template class GenericFarm: public GenericFarmFace { public: + using WorkPackage = typename PoW::WorkPackage; + using Solution = typename PoW::Solution; + using Miner = GenericMiner; + /** * @brief Sets the current mining mission. * @param _bi The block (header) we wish to be mining. */ void setWork(BlockInfo const& _bi) { - WriteGuard l(x_work); - m_header = _bi; - m_work = PoW::package(m_header); - ReadGuard l(x_miners); - for (auto const& m: miners) + WorkPackage w; + { + WriteGuard l(x_work); + m_header = _bi; + w = m_work = PoW::package(m_header); + } + + ReadGuard l2(x_miners); + for (auto const& m: m_miners) m->setWork(m_work); } @@ -63,13 +72,13 @@ public: * @brief (Re)start miners for CPU only. * @returns true if started properly. */ - bool startCPU() { return start(); } + bool startCPU() { return start(); } /** * @brief (Re)start miners for GPU only. * @returns true if started properly. */ - bool startGPU() { start(); } + bool startGPU() { return start(); } /** * @brief Stop all mining activities. @@ -92,12 +101,14 @@ public: */ MiningProgress const& miningProgress() const { ReadGuard l(x_progress); return m_progress; } + using SolutionFound = std::function; + /** * @brief Provides a valid header based upon that received previously with setWork(). * @param _bi The now-valid header. * @return true if the header was good and that the Farm should pause until more work is submitted. */ - void onSolutionFound(function _handler) { m_onSolutionFound = _handler; } + void onSolutionFound(SolutionFound const& _handler) { m_onSolutionFound = _handler; } private: /** @@ -116,7 +127,7 @@ private: ReadGuard l(x_miners); for (std::shared_ptr const& m: m_miners) if (m.get() != _m) - m->pause(); + m->setWork(); m_work.headerHash = h256(); return true; } @@ -135,7 +146,7 @@ private: m_miners.clear(); m_miners.reserve(MinerType::instances()); for (unsigned i = 0; i < MinerType::instances(); ++i) - m_miners.push_back(new MinerType(std::make_pair(this, i))); + m_miners.push_back(std::shared_ptr(new MinerType(std::make_pair(this, i)))); return true; } @@ -149,7 +160,7 @@ private: WorkPackage m_work; BlockInfo m_header; - function m_onSolutionFound; + SolutionFound m_onSolutionFound; }; } diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 0ab81728b..b72a29c00 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -183,7 +183,7 @@ public: virtual uint64_t hashrate() const = 0; /// Get hash of the current block to be mined minus the nonce (the 'work hash'). - virtual std::pair getWork() = 0; + virtual ProofOfWork::WorkPackage getWork() = 0; /// Submit the nonce for the proof-of-work. virtual bool submitWork(ProofOfWork::Solution const& _proof) = 0; diff --git a/libethereum/Miner.cpp b/libethereum/Miner.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/libethereum/Miner.h b/libethereum/Miner.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 7e7b83e3c..65fb71a5c 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -758,8 +758,9 @@ Json::Value WebThreeStubServerBase::eth_getWork() { Json::Value ret(Json::arrayValue); auto r = client()->getWork(); - ret.append(toJS(r.first)); - ret.append(toJS(r.second)); + ret.append(toJS(r.headerHash)); + ret.append(toJS(r.seedHash)); + ret.append(toJS(r.boundary)); return ret; } diff --git a/libwebthree/WebThree.cpp b/libwebthree/WebThree.cpp index 8ea2133f0..bbe0d55ec 100644 --- a/libwebthree/WebThree.cpp +++ b/libwebthree/WebThree.cpp @@ -42,7 +42,7 @@ WebThreeDirect::WebThreeDirect( WithExisting _we, std::set const& _interfaces, NetworkPreferences const& _n, - bytesConstRef _network, int _miners + bytesConstRef _network ): m_clientVersion(_clientVersion), m_net(_clientVersion, _n, _network) @@ -50,7 +50,7 @@ WebThreeDirect::WebThreeDirect( if (_dbPath.size()) Defaults::setDBPath(_dbPath); if (_interfaces.count("eth")) - m_ethereum.reset(new eth::Client(&m_net, _dbPath, _we, 0, _miners)); + m_ethereum.reset(new eth::Client(&m_net, _dbPath, _we, 0)); if (_interfaces.count("shh")) m_whisper = m_net.registerCapability(new WhisperHost); diff --git a/libwebthree/WebThree.h b/libwebthree/WebThree.h index 87cf62d4a..90a4aa3c2 100644 --- a/libwebthree/WebThree.h +++ b/libwebthree/WebThree.h @@ -112,8 +112,7 @@ public: WithExisting _we = WithExisting::Trust, std::set const& _interfaces = {"eth", "shh"}, p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(), - bytesConstRef _network = bytesConstRef(), - int _miners = -1 + bytesConstRef _network = bytesConstRef() ); /// Destructor.