|
|
@ -135,6 +135,28 @@ template <class T> T abiOut(bytes const& _data) |
|
|
|
return ABIDeserialiser<T>::deserialise(o); |
|
|
|
} |
|
|
|
|
|
|
|
class RemoteMiner: public Miner |
|
|
|
{ |
|
|
|
public: |
|
|
|
RemoteMiner() {} |
|
|
|
|
|
|
|
void update(State const& _provisional, BlockChain const& _bc) { m_state = _provisional; m_state.commitToMine(_bc); } |
|
|
|
|
|
|
|
h256 workHash() const { return m_state.info().headerHash(IncludeNonce::WithoutNonce); } |
|
|
|
u256 const& difficulty() const { return m_state.info().difficulty; } |
|
|
|
|
|
|
|
bool submitWork(h256 const& _nonce) { return (m_isComplete = m_state.completeMine(_nonce)); } |
|
|
|
|
|
|
|
virtual bool isComplete() const override { return m_isComplete; } |
|
|
|
virtual bytes const& blockData() const { return m_state.blockData(); } |
|
|
|
|
|
|
|
virtual void noteStateChange() override {} |
|
|
|
|
|
|
|
private: |
|
|
|
bool m_isComplete = false; |
|
|
|
State m_state; |
|
|
|
}; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Main API hub for interfacing with Ethereum. |
|
|
|
*/ |
|
|
@ -253,20 +275,26 @@ public: |
|
|
|
/// Stops mining and sets the number of mining threads (0 for automatic).
|
|
|
|
virtual void setMiningThreads(unsigned _threads = 0); |
|
|
|
/// Get the effective number of mining threads.
|
|
|
|
virtual unsigned miningThreads() const { ReadGuard l(x_miners); return m_miners.size(); } |
|
|
|
virtual unsigned miningThreads() const { ReadGuard l(x_localMiners); return m_localMiners.size(); } |
|
|
|
/// Start mining.
|
|
|
|
/// NOT thread-safe - call it & stopMining only from a single thread
|
|
|
|
virtual void startMining() { startWorking(); ReadGuard l(x_miners); for (auto& m: m_miners) m.start(); } |
|
|
|
virtual void startMining() { startWorking(); ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.start(); } |
|
|
|
/// Stop mining.
|
|
|
|
/// NOT thread-safe
|
|
|
|
virtual void stopMining() { ReadGuard l(x_miners); for (auto& m: m_miners) m.stop(); } |
|
|
|
virtual void stopMining() { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.stop(); } |
|
|
|
/// Are we mining now?
|
|
|
|
virtual bool isMining() { ReadGuard l(x_miners); return m_miners.size() && m_miners[0].isRunning(); } |
|
|
|
virtual bool isMining() { ReadGuard l(x_localMiners); return m_localMiners.size() && m_localMiners[0].isRunning(); } |
|
|
|
/// Check the progress of the mining.
|
|
|
|
virtual MineProgress miningProgress() const; |
|
|
|
/// Get and clear the mining history.
|
|
|
|
std::list<MineInfo> miningHistory(); |
|
|
|
|
|
|
|
/// 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.
|
|
|
|
virtual std::pair<h256, u256> getWork() override; |
|
|
|
/// Submit the nonce for the proof-of-work.
|
|
|
|
virtual bool submitNonce(h256 const&_nonce) override; |
|
|
|
|
|
|
|
// Debug stuff:
|
|
|
|
|
|
|
|
DownloadMan const* downloadMan() const; |
|
|
@ -295,6 +323,7 @@ private: |
|
|
|
/// Do some work. Handles blockchain maintenance and mining.
|
|
|
|
virtual void doWork(); |
|
|
|
|
|
|
|
/// Called when Worker is exiting.
|
|
|
|
virtual void doneWorking(); |
|
|
|
|
|
|
|
/// Overrides for being a mining host.
|
|
|
@ -309,24 +338,27 @@ private: |
|
|
|
State asOf(unsigned _h) const; |
|
|
|
|
|
|
|
VersionChecker m_vc; ///< Dummy object to check & update the protocol version.
|
|
|
|
CanonBlockChain m_bc; ///< Maintains block database.
|
|
|
|
CanonBlockChain m_bc; ///< Maintains block database.
|
|
|
|
TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain.
|
|
|
|
BlockQueue m_bq; ///< Maintains a list of incoming blocks not yet on the blockchain (to be imported).
|
|
|
|
|
|
|
|
mutable SharedMutex x_stateDB; ///< Lock on the state DB, effectively a lock on m_postMine.
|
|
|
|
mutable SharedMutex x_stateDB; ///< Lock on the state DB, effectively a lock on m_postMine.
|
|
|
|
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).
|
|
|
|
|
|
|
|
std::weak_ptr<EthereumHost> m_host; ///< Our Ethereum Host. Don't do anything if we can't lock.
|
|
|
|
|
|
|
|
std::vector<Miner> m_miners; |
|
|
|
mutable SharedMutex x_miners; |
|
|
|
mutable Mutex x_remoteMiner; ///< The remote miner lock.
|
|
|
|
RemoteMiner m_remoteMiner; ///< The remote miner.
|
|
|
|
|
|
|
|
std::vector<LocalMiner> m_localMiners; ///< The in-process miners.
|
|
|
|
mutable SharedMutex x_localMiners; ///< The in-process miners lock.
|
|
|
|
bool m_paranoia = false; ///< Should we be paranoid about our state?
|
|
|
|
bool m_turboMining = false; ///< Don't squander all of our time mining actually just sleeping.
|
|
|
|
bool m_forceMining = false; ///< Mine even when there are no transactions pending?
|
|
|
|
|
|
|
|
mutable std::mutex m_filterLock; |
|
|
|
mutable Mutex m_filterLock; |
|
|
|
std::map<h256, InstalledFilter> m_filters; |
|
|
|
std::map<unsigned, ClientWatch> m_watches; |
|
|
|
|
|
|
|