Fix nicehash support, please note --nicehash option now specified per pool.

This commit is contained in:
XMRig 2017-07-01 22:37:27 +03:00
parent 263634f585
commit 8ec58a8394
12 changed files with 23 additions and 26 deletions

View file

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

View file

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

View file

@ -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),

View file

@ -34,11 +34,12 @@
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 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; }
@ -47,7 +48,7 @@ public:
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 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<uint32_t*>(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.

View file

@ -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));
}

View file

@ -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),

View file

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

View file

@ -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 {

View file

@ -31,7 +31,6 @@
Worker::Worker(Handle *handle) :
m_nicehash(handle->nicehash()),
m_id(handle->threadId()),
m_threads(handle->threads()),
m_hashCount(0),

View file

@ -48,7 +48,6 @@ public:
protected:
void storeStats();
bool m_nicehash;
cryptonight_ctx *m_ctx;
int m_id;
int m_threads;

View file

@ -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);
}

View file

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