From 8ec58a83941fd6aa197304e165af18c25af599fd Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 1 Jul 2017 22:37:27 +0300 Subject: [PATCH] Fix nicehash support, please note --nicehash option now specified per pool. --- src/App.cpp | 2 +- src/net/Client.cpp | 3 +-- src/net/Job.cpp | 3 ++- src/net/Job.h | 22 ++++++++++++---------- src/workers/DoubleWorker.cpp | 2 +- src/workers/Handle.cpp | 3 +-- src/workers/Handle.h | 4 +--- src/workers/SingleWorker.cpp | 2 +- src/workers/Worker.cpp | 1 - src/workers/Worker.h | 1 - src/workers/Workers.cpp | 4 ++-- src/workers/Workers.h | 2 +- 12 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 4d3305ff2..9d970d12b 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -105,7 +105,7 @@ int App::exec() Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash()); Summary::print(); - Workers::start(m_options->affinity(), false); + Workers::start(m_options->affinity()); m_network->connect(); diff --git a/src/net/Client.cpp b/src/net/Client.cpp index 3b9eecbd6..ffd721142 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -165,7 +165,7 @@ bool Client::parseJob(const json_t *params, int *code) return false; } - Job job; + Job job(m_id, m_url.isNicehash()); if (!job.setId(json_string_value(json_object_get(params, "job_id")))) { *code = 3; return false; @@ -181,7 +181,6 @@ bool Client::parseJob(const json_t *params, int *code) return false; } - job.setPoolId(m_id); m_job = std::move(job); LOG_DEBUG("[%s:%u] job: \"%s\", diff: %lld", m_url.host(), m_url.port(), job.id(), job.diff()); diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 9934903f3..cda6c9ae3 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -56,7 +56,8 @@ static inline char hf_bin2hex(unsigned char c) } -Job::Job(int poolId) : +Job::Job(int poolId, bool nicehash) : + m_nicehash(nicehash), m_poolId(poolId), m_size(0), m_diff(0), diff --git a/src/net/Job.h b/src/net/Job.h index 262465fca..d8a9e203e 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -34,20 +34,21 @@ class Job { public: - Job(int poolId = -2); + Job(int poolId = -2, bool nicehash = false); bool setBlob(const char *blob); bool setId(const char *id); bool setTarget(const char *target); - inline bool isValid() const { return m_size > 0 && m_diff > 0; } - inline const char *id() const { return m_id; } - inline const uint8_t *blob() const { return m_blob; } - inline int poolId() const { return m_poolId; } - inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } - inline uint32_t diff() const { return m_diff; } - inline uint32_t size() const { return m_size; } - inline uint64_t target() const { return m_target; } - inline void setPoolId(int poolId) { m_poolId = poolId; } + inline bool isNicehash() const { return m_nicehash; } + inline bool isValid() const { return m_size > 0 && m_diff > 0; } + inline const char *id() const { return m_id; } + inline const uint8_t *blob() const { return m_blob; } + inline int poolId() const { return m_poolId; } + inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } + inline uint32_t diff() const { return m_diff; } + inline uint32_t size() const { return m_size; } + inline uint64_t target() const { return m_target; } + inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } static bool fromHex(const char* in, unsigned int len, unsigned char* out); static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast(blob + 39); } @@ -55,6 +56,7 @@ public: static void toHex(const unsigned char* in, unsigned int len, char* out); private: + bool m_nicehash; int m_poolId; VAR_ALIGN(16, char m_id[64]); VAR_ALIGN(16, uint8_t m_blob[84]); // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index 41b9aec79..90fbf2b3f 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -85,7 +85,7 @@ void DoubleWorker::consumeJob() memcpy(m_blob, m_job.blob(), m_job.size()); memcpy(m_blob + m_job.size(), m_job.blob(), m_job.size()); - if (m_nicehash) { + if (m_job.isNicehash()) { m_nonce1 = (*Job::nonce(m_blob) & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id); m_nonce2 = (*Job::nonce(m_blob + m_job.size()) & 0xff000000U) + (0xffffffU / (m_threads * 2) * (m_id + m_threads)); } diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp index c97d10b12..9cebd097c 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/Handle.cpp @@ -25,8 +25,7 @@ #include "workers/Handle.h" -Handle::Handle(int threadId, int threads, int64_t affinity, bool nicehash) : - m_nicehash(nicehash), +Handle::Handle(int threadId, int threads, int64_t affinity) : m_threadId(threadId), m_threads(threads), m_affinity(affinity), diff --git a/src/workers/Handle.h b/src/workers/Handle.h index 96a512e37..6ec3d2405 100644 --- a/src/workers/Handle.h +++ b/src/workers/Handle.h @@ -35,10 +35,9 @@ class IWorker; class Handle { public: - Handle(int threadId, int threads, int64_t affinity, bool nicehash); + Handle(int threadId, int threads, int64_t affinity); void start(void (*callback) (void *)); - inline bool nicehash() const { return m_nicehash; } inline int threadId() const { return m_threadId; } inline int threads() const { return m_threads; } inline int64_t affinity() const { return m_affinity; } @@ -46,7 +45,6 @@ public: inline void setWorker(IWorker *worker) { m_worker = worker; } private: - bool m_nicehash; int m_threadId; int m_threads; int64_t m_affinity; diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index 9c56b7d8f..477694ebf 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -77,7 +77,7 @@ void SingleWorker::consumeJob() memcpy(m_result.jobId, m_job.id(), sizeof(m_result.jobId)); m_result.poolId = m_job.poolId(); - if (m_nicehash) { + if (m_job.isNicehash()) { m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_threads * m_id); } else { diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 96cd41825..583c1d459 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -31,7 +31,6 @@ Worker::Worker(Handle *handle) : - m_nicehash(handle->nicehash()), m_id(handle->threadId()), m_threads(handle->threads()), m_hashCount(0), diff --git a/src/workers/Worker.h b/src/workers/Worker.h index 84f3ccf87..11c4a198f 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.h @@ -48,7 +48,6 @@ public: protected: void storeStats(); - bool m_nicehash; cryptonight_ctx *m_ctx; int m_id; int m_threads; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index f78d8e277..1ee6262ef 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -69,7 +69,7 @@ void Workers::setJob(const Job &job) } -void Workers::start(int64_t affinity, bool nicehash) +void Workers::start(int64_t affinity) { const int threads = Mem::threads(); m_hashrate = new Hashrate(threads); @@ -85,7 +85,7 @@ void Workers::start(int64_t affinity, bool nicehash) uv_timer_start(&m_timer, Workers::onTick, 500, 500); for (int i = 0; i < threads; ++i) { - Handle *handle = new Handle(i, threads, affinity, nicehash); + Handle *handle = new Handle(i, threads, affinity); m_workers.push_back(handle); handle->start(Workers::onReady); } diff --git a/src/workers/Workers.h b/src/workers/Workers.h index ffeddb00c..8bc07c1d4 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -44,7 +44,7 @@ class Workers public: static Job job(); static void setJob(const Job &job); - static void start(int64_t affinity, bool nicehash); + static void start(int64_t affinity); static void submit(const JobResult &result); static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }