diff --git a/src/Options.cpp b/src/Options.cpp index 15c7750f..ef26c9ef 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -79,6 +79,7 @@ Options:\n\ --print-time=N print hashrate report every N seconds\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ + --rand-nonce generate random nonces instead of monotonically increasing ones\n\ "; @@ -109,6 +110,7 @@ static struct option const options[] = { { "user", 1, nullptr, 'u' }, { "userpass", 1, nullptr, 'O' }, { "version", 0, nullptr, 'V' }, + { "rand-nonce", 0, nullptr, 1008 }, { 0, 0, 0, 0 } }; @@ -366,6 +368,10 @@ bool Options::parseArg(int key, char *arg) m_printTime = v; break; + case 1008: /* --rand-nonce */ + m_pools.back()->setRandNonce(true); + break; + default: showUsage(1); return false; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index db32ed12..f73cd790 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -186,7 +186,7 @@ bool Client::parseJob(const json_t *params, int *code) return false; } - Job job(m_id, m_url.isNicehash()); + Job job(m_id, m_url.isNicehash(), m_url.isRandNonce()); if (!job.setId(json_string_value(json_object_get(params, "job_id")))) { *code = 3; return false; diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 4929aaf5..ea0a9175 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -56,8 +56,9 @@ static inline char hf_bin2hex(unsigned char c) } -Job::Job(int poolId, bool nicehash) : +Job::Job(int poolId, bool nicehash, bool randnonce) : m_nicehash(nicehash), + m_randnonce(randnonce), m_poolId(poolId), m_size(0), m_diff(0), diff --git a/src/net/Job.h b/src/net/Job.h index e7fca53e..1b0d005f 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -27,19 +27,19 @@ #include - #include "align.h" class Job { public: - Job(int poolId = -2, bool nicehash = false); + Job(int poolId = -2, bool nicehash = false, bool randnonce = 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 isRandNonce() const { return m_randnonce; } 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; } @@ -49,6 +49,7 @@ public: inline uint32_t size() const { return m_size; } inline uint64_t target() const { return m_target; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setRandNonce(bool randnonce) { m_randnonce = randnonce; } # ifdef XMRIG_PROXY_PROJECT inline char *rawBlob() { return m_rawBlob; } @@ -64,6 +65,7 @@ public: private: bool m_nicehash; + bool m_randnonce; 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/net/Url.cpp b/src/net/Url.cpp index 82b788d9..175621e3 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -25,7 +25,6 @@ #include #include - #include "net/Url.h" @@ -37,6 +36,7 @@ Url::Url() : m_keepAlive(false), m_nicehash(false), + m_randnonce(false), m_host(nullptr), m_password(nullptr), m_user(nullptr), @@ -59,6 +59,7 @@ Url::Url() : Url::Url(const char *url) : m_keepAlive(false), m_nicehash(false), + m_randnonce(false), m_host(nullptr), m_password(nullptr), m_user(nullptr), @@ -68,9 +69,10 @@ Url::Url(const char *url) : } -Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash) : +Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash, bool randnonce) : m_keepAlive(keepAlive), m_nicehash(nicehash), + m_randnonce(randnonce), m_password(password ? strdup(password) : nullptr), m_user(user ? strdup(user) : nullptr), m_port(port) @@ -91,6 +93,10 @@ bool Url::isNicehash() const { return isValid() && (m_nicehash || strstr(m_host, ".nicehash.com")); } +bool Url::isRandNonce() const +{ + return m_randnonce; +} bool Url::parse(const char *url) @@ -170,6 +176,7 @@ Url &Url::operator=(const Url *other) { m_keepAlive = other->m_keepAlive; m_nicehash = other->m_nicehash; + m_randnonce = other->m_randnonce; m_port = other->m_port; free(m_host); diff --git a/src/net/Url.h b/src/net/Url.h index 43197195..4b9a56bd 100644 --- a/src/net/Url.h +++ b/src/net/Url.h @@ -37,7 +37,7 @@ public: Url(); Url(const char *url); - Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false ); + Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, bool randnonce = false ); ~Url(); inline bool isKeepAlive() const { return m_keepAlive; } @@ -48,8 +48,10 @@ public: inline uint16_t port() const { return m_port; } inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setRandNonce(bool randnonce) { m_randnonce = randnonce; } bool isNicehash() const; + bool isRandNonce() const; bool parse(const char *url); bool setUserpass(const char *userpass); void setPassword(const char *password); @@ -60,6 +62,7 @@ public: private: bool m_keepAlive; bool m_nicehash; + bool m_randnonce; char *m_host; char *m_password; char *m_user; diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index 58c69e7f..a1fd76c2 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -54,7 +54,11 @@ void SingleWorker::start() } m_count++; - *m_job.nonce() = ++m_result.nonce; + if (m_job.isRandNonce()) { + *m_job.nonce() = m_result.nonce += rand(); + } else { + *m_job.nonce() = ++m_result.nonce; + } if (CryptoNight::hash(m_job, m_result, m_ctx)) { Workers::submit(m_result);