Browse Source

Lots of build fixes. Now minimal version builds ok.

cl-refactor
Gav Wood 10 years ago
parent
commit
405653c250
  1. 2
      alethzero/MainWin.cpp
  2. 11
      eth/main.cpp
  3. 2
      libethash-cl/ethash_cl_miner.cpp
  4. 2
      libethash-cl/ethash_cl_miner.h
  5. 3
      libethcore/Common.cpp
  6. 3
      libethcore/Common.h
  7. 14
      libethcore/Ethash.cpp
  8. 6
      libethcore/Ethash.h
  9. 124
      libethereum/Client.cpp
  10. 10
      libethereum/Client.h
  11. 4
      libethereum/ClientBase.cpp
  12. 43
      libethereum/ClientBase.h
  13. 33
      libethereum/Farm.h
  14. 2
      libethereum/Interface.h
  15. 0
      libethereum/Miner.cpp
  16. 0
      libethereum/Miner.h
  17. 5
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  18. 4
      libwebthree/WebThree.cpp
  19. 3
      libwebthree/WebThree.h

2
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()));

11
eth/main.cpp

@ -36,6 +36,7 @@
#include <libevm/VMFactory.h>
#include <libethereum/All.h>
#include <libwebthree/WebThree.h>
#include <libethcore/ProofOfWork.h>
#if ETH_READLINE
#include <readline/readline.h>
#include <readline/history.h>
@ -44,7 +45,6 @@
#include <libweb3jsonrpc/WebThreeStubServer.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#endif
#include <libethcore/Ethasher.h>
#include "BuildInfo.h"
using namespace std;
using namespace dev;
@ -210,7 +210,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);
}
@ -271,7 +271,6 @@ int main(int argc, char** argv)
/// Mining params
unsigned mining = ~(unsigned)0;
int miners = -1;
bool forceMining = false;
KeyPair us = KeyPair::create();
Address coinbase = us.address();
@ -477,8 +476,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];
@ -537,9 +534,7 @@ int main(int argc, char** argv)
killChain,
nodeMode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(),
netPrefs,
&nodesState,
miners
);
&nodesState);
if (mode == OperationMode::DAGInit)
doInitDAG(web3.ethereum()->blockChain().number() + (initDAG == PendingBlock ? 30000 : 0));

2
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()
{

2
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;

3
libethcore/Common.cpp

@ -23,6 +23,7 @@
#include <random>
#include <libdevcrypto/SHA3.h>
#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<pair<u256, string>> const& units()
{

3
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);

14
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);

6
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<EthashCLHook> m_hook;
std::unique_ptr<ethash_cl_miner> m_miner;
EthashCLHook* m_hook;
ethash_cl_miner* m_miner;
h256 m_minerSeed;
WorkPackage m_lastWork; ///< Work loaded into m_miner.
MineInfo m_info;

124
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<GasPricer> _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;
ReadGuard l(x_localMiners);
for (LocalMiner const& m: m_localMiners)
ret += m.miningProgress().hashes / m.miningProgress().ms;
return ret / 1000;
return 0;
}
std::list<MineInfo> Client::miningHistory()
{
std::list<MineInfo> 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<MineInfo> 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<ProofOfWork>(_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)

10
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<EthereumHost> m_host; ///< Our Ethereum Host. Don't do anything if we can't lock.
GenericFarm<ProofOfWork> 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;

4
libethereum/ClientBase.cpp

@ -20,10 +20,12 @@
* @date 2015
*/
#include <libdevcore/StructuredLogger.h>
#include "ClientBase.h"
#include <libdevcore/StructuredLogger.h>
#include "BlockChain.h"
#include "Executive.h"
#include "State.h"
using namespace std;
using namespace dev;

43
libethereum/ClientBase.h

@ -25,6 +25,7 @@
#include <chrono>
#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<dev::eth::WatchChannel, true>()
#define cwatch LogOutputStream<WatchChannel, true>()
struct WorkInChannel: public LogChannel { static const char* name() { return ">W>"; } static const int verbosity = 16; };
struct WorkOutChannel: public LogChannel { static const char* name() { return "<W<"; } static const int verbosity = 16; };
struct WorkChannel: public LogChannel { static const char* name() { return "-W-"; } static const int verbosity = 21; };
#define cwork dev::LogOutputStream<dev::eth::WorkChannel, true>()
#define cworkin dev::LogOutputStream<dev::eth::WorkInChannel, true>()
#define cworkout dev::LogOutputStream<dev::eth::WorkOutChannel, true>()
#define cwork LogOutputStream<WorkChannel, true>()
#define cworkin LogOutputStream<WorkInChannel, true>()
#define cworkout LogOutputStream<WorkOutChannel, true>()
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<h256, u256> 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;

33
libethereum/Farm.h

@ -29,6 +29,7 @@
#include <libethcore/Common.h>
#include <libethcore/Miner.h>
#include <libethcore/BlockInfo.h>
#include <libethcore/ProofOfWork.h>
namespace dev
{
@ -45,17 +46,25 @@ template <class PoW>
class GenericFarm: public GenericFarmFace<PoW>
{
public:
using WorkPackage = typename PoW::WorkPackage;
using Solution = typename PoW::Solution;
using Miner = GenericMiner<PoW>;
/**
* @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<PoW::CPUMiner>(); }
bool startCPU() { return start<typename PoW::CPUMiner>(); }
/**
* @brief (Re)start miners for GPU only.
* @returns true if started properly.
*/
bool startGPU() { start<PoW::GPUMiner>(); }
bool startGPU() { return start<typename PoW::GPUMiner>(); }
/**
* @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<bool(Solution const&)>;
/**
* @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<bool(Solution const&)> _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<Miner> 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<Miner>(new MinerType(std::make_pair(this, i))));
return true;
}
@ -149,7 +160,7 @@ private:
WorkPackage m_work;
BlockInfo m_header;
function<bool(Solution const&)> m_onSolutionFound;
SolutionFound m_onSolutionFound;
};
}

2
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<h256, u256> getWork() = 0;
virtual ProofOfWork::WorkPackage getWork() = 0;
/// Submit the nonce for the proof-of-work.
virtual bool submitWork(ProofOfWork::Solution const& _proof) = 0;

0
libethereum/Miner.cpp

0
libethereum/Miner.h

5
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;
}

4
libwebthree/WebThree.cpp

@ -42,7 +42,7 @@ WebThreeDirect::WebThreeDirect(
WithExisting _we,
std::set<std::string> 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<WhisperHost>(new WhisperHost);

3
libwebthree/WebThree.h

@ -112,8 +112,7 @@ public:
WithExisting _we = WithExisting::Trust,
std::set<std::string> const& _interfaces = {"eth", "shh"},
p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(),
bytesConstRef _network = bytesConstRef(),
int _miners = -1
bytesConstRef _network = bytesConstRef()
);
/// Destructor.

Loading…
Cancel
Save