Fabcoin Core  0.16.2
P2P Digital Currency
EthashClient.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
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.
8 
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.
13 
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/>.
16 */
22 #pragma once
23 
24 #include <tuple>
25 #include <libethereum/Client.h>
26 
27 namespace dev
28 {
29 namespace eth
30 {
31 
32 class Ethash;
33 
34 DEV_SIMPLE_EXCEPTION(InvalidSealEngine);
35 
36 class EthashClient: public Client
37 {
38 public:
41  ChainParams const& _params,
42  int _networkID,
43  p2p::Host* _host,
44  std::shared_ptr<GasPricer> _gpForAdoption,
45  std::string const& _dbPath = std::string(),
46  WithExisting _forceAction = WithExisting::Trust,
48  );
49 
50  Ethash* ethash() const;
51 
53  void setShouldPrecomputeDAG(bool _precompute);
54 
56  bool isMining() const;
57 
59  u256 hashrate() const;
60 
63 
65  bool shouldServeWork() const { return m_bq.items().first == 0 && (isMining() || remoteActive()); }
66 
70  std::tuple<h256, h256, h256> getEthashWork();
71 
76  bool submitEthashWork(h256 const& _mixHash, h64 const& _nonce);
77 
78  void submitExternalHashrate(u256 const& _rate, h256 const& _id);
79 
80 protected:
81  u256 externalHashrate() const;
82 
83  // external hashrate
84  mutable std::unordered_map<h256, std::pair<u256, std::chrono::steady_clock::time_point>> m_externalRates;
86 };
87 
90 
91 }
92 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
u256 hashrate() const
The hashrate...
EthashClient(ChainParams const &_params, int _networkID, p2p::Host *_host, std::shared_ptr< GasPricer > _gpForAdoption, std::string const &_dbPath=std::string(), WithExisting _forceAction=WithExisting::Trust, TransactionQueue::Limits const &_l=TransactionQueue::Limits{1024, 1024})
Trivial forwarding constructor.
Ethash * ethash() const
EthashClient & asEthashClient(Interface &_c)
SharedMutex x_externalRates
Definition: EthashClient.h:85
bool shouldServeWork() const
Definition: EthashClient.h:65
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not t...
Definition: Host.h:129
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 ...
bool submitEthashWork(h256 const &_mixHash, h64 const &_nonce)
Submit the proof for the proof-of-work.
std::pair< unsigned, unsigned > items() const
Get information on the items queued.
Definition: BlockQueue.h:254
void submitExternalHashrate(u256 const &_rate, h256 const &_id)
void setShouldPrecomputeDAG(bool _precompute)
Enable/disable precomputing of the DAG for next epoch.
BlockQueue m_bq
Maintains a list of incoming blocks not yet on the blockchain (to be imported).
Definition: Client.h:295
WithExisting
Definition: Common.h:310
bool isMining() const
Are we mining now?
Main API hub for interfacing with Ethereum.
Definition: Client.h:75
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
Main API hub for interfacing with Ethereum.
Definition: Interface.h:67
Describes the progress of a mining operation.
Definition: Common.h:205
std::unordered_map< h256, std::pair< u256, std::chrono::steady_clock::time_point > > m_externalRates
Definition: EthashClient.h:84
bool remoteActive() const
Is there an active and valid remote worker?
Definition: Client.cpp:571
boost::shared_mutex SharedMutex
Definition: Guards.h:39
u256 externalHashrate() const
WorkingProgress miningProgress() const
Check the progress of the mining.
DEV_SIMPLE_EXCEPTION(InvalidSealEngine)