27 #include <boost/algorithm/string.hpp> 31 #include <libcpuid/libcpuid.h> 37 unsigned EthashCPUMiner::s_numInstances = 0;
40 static string jsonEncode(map<string, string>
const& _m)
44 for (
auto const& i: _m)
46 string k = boost::replace_all_copy(boost::replace_all_copy(i.first,
"\\",
"\\\\"),
"'",
"\\'");
47 string v = boost::replace_all_copy(boost::replace_all_copy(i.second,
"\\",
"\\\\"),
"'",
"\\'");
50 ret +=
"\"" + k +
"\":\"" + v +
"\"";
79 auto tid = std::this_thread::get_id();
80 static std::mt19937_64 s_eng((
utcTime() + std::hash<decltype(tid)>()(tid)));
82 uint64_t tryNonce = s_eng();
91 this_thread::sleep_for(chrono::milliseconds(500));
95 h256 boundary = w.boundary;
103 if (!(hashCount % 100))
110 string baseline =
toString(std::thread::hardware_concurrency()) +
"-thread CPU";
113 if (!cpuid_present())
115 struct cpu_raw_data_t raw;
116 struct cpu_id_t data;
117 if (cpuid_get_raw_data(&raw) < 0)
119 if (cpu_identify(&raw, &data) < 0)
121 map<string, string> m;
122 m[
"vendor"] = data.vendor_str;
123 m[
"codename"] = data.cpu_codename;
124 m[
"brand"] = data.brand_str;
125 m[
"L1 cache"] =
toString(data.l1_data_cache);
126 m[
"L2 cache"] =
toString(data.l2_cache);
127 m[
"L3 cache"] =
toString(data.l3_cache);
128 m[
"cores"] =
toString(data.num_cores);
129 m[
"threads"] =
toString(data.num_logical_cpus);
130 m[
"clocknominal"] =
toString(cpu_clock_by_os());
131 m[
"clocktested"] =
toString(cpu_clock_measure(200, 0));
139 return jsonEncode(m);
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void pause() override
No work left to be done.
Proof of work definition for Ethash.
bool submitProof(Solution const &_s)
Notes that the Miner found a solution.
WorkPackage const & work() const
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
std::shared_ptr< FullAllocation > FullType
std::hash for asio::adress
uint64_t hashCount() const
void accumulateHashes(unsigned _n)
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
static FullType full(h256 const &_seedHash, bool _createIfMissing=false, std::function< int(unsigned)> const &_f=std::function< int(unsigned)>())
Kicks off generation of DAG for _blocknumber and blocks until ready;.
void stopWorking()
Stop worker thread; causes call to stopWorking().
void workLoop() override
Overrides doWork(); should call shouldStop() often and exit when true.
void startWorking()
Starts worker thread; causes startedWorking() to be called.
Type of a seedhash/blockhash e.t.c.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u64
static unsigned computeFull(h256 const &_seedHash, bool _createIfMissing=true)
Kicks off generation of DAG for _seedHash and.
void kickOff() override
Begin working on a given work package, discarding any previous work.
ethash_return_value_t ethash_full_compute(ethash_full_t full, ethash_h256_t const header_hash, uint64_t nonce)
Calculate the full client data.
A miner - a member and adoptee of the Farm.
static std::string platformInfo()
typename EthashProofOfWork::WorkPackage WorkPackage