added --rand-nonce option to try random instead of sequentially increasing nonces
This commit is contained in:
parent
b6bf6d9bc9
commit
6516517235
7 changed files with 31 additions and 8 deletions
|
@ -79,6 +79,7 @@ Options:\n\
|
||||||
--print-time=N print hashrate report every N seconds\n\
|
--print-time=N print hashrate report every N seconds\n\
|
||||||
-h, --help display this help and exit\n\
|
-h, --help display this help and exit\n\
|
||||||
-V, --version output version information 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' },
|
{ "user", 1, nullptr, 'u' },
|
||||||
{ "userpass", 1, nullptr, 'O' },
|
{ "userpass", 1, nullptr, 'O' },
|
||||||
{ "version", 0, nullptr, 'V' },
|
{ "version", 0, nullptr, 'V' },
|
||||||
|
{ "rand-nonce", 0, nullptr, 1008 },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -366,6 +368,10 @@ bool Options::parseArg(int key, char *arg)
|
||||||
m_printTime = v;
|
m_printTime = v;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 1008: /* --rand-nonce */
|
||||||
|
m_pools.back()->setRandNonce(true);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
showUsage(1);
|
showUsage(1);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -186,7 +186,7 @@ bool Client::parseJob(const json_t *params, int *code)
|
||||||
return false;
|
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")))) {
|
if (!job.setId(json_string_value(json_object_get(params, "job_id")))) {
|
||||||
*code = 3;
|
*code = 3;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -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_nicehash(nicehash),
|
||||||
|
m_randnonce(randnonce),
|
||||||
m_poolId(poolId),
|
m_poolId(poolId),
|
||||||
m_size(0),
|
m_size(0),
|
||||||
m_diff(0),
|
m_diff(0),
|
||||||
|
|
|
@ -27,19 +27,19 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#include "align.h"
|
#include "align.h"
|
||||||
|
|
||||||
|
|
||||||
class Job
|
class Job
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Job(int poolId = -2, bool nicehash = false);
|
Job(int poolId = -2, bool nicehash = false, bool randnonce = false);
|
||||||
bool setBlob(const char *blob);
|
bool setBlob(const char *blob);
|
||||||
bool setId(const char *id);
|
bool setId(const char *id);
|
||||||
bool setTarget(const char *target);
|
bool setTarget(const char *target);
|
||||||
|
|
||||||
inline bool isNicehash() const { return m_nicehash; }
|
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 bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||||
inline const char *id() const { return m_id; }
|
inline const char *id() const { return m_id; }
|
||||||
inline const uint8_t *blob() const { return m_blob; }
|
inline const uint8_t *blob() const { return m_blob; }
|
||||||
|
@ -49,6 +49,7 @@ public:
|
||||||
inline uint32_t size() const { return m_size; }
|
inline uint32_t size() const { return m_size; }
|
||||||
inline uint64_t target() const { return m_target; }
|
inline uint64_t target() const { return m_target; }
|
||||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||||
|
inline void setRandNonce(bool randnonce) { m_randnonce = randnonce; }
|
||||||
|
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
inline char *rawBlob() { return m_rawBlob; }
|
inline char *rawBlob() { return m_rawBlob; }
|
||||||
|
@ -64,6 +65,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_nicehash;
|
bool m_nicehash;
|
||||||
|
bool m_randnonce;
|
||||||
int m_poolId;
|
int m_poolId;
|
||||||
VAR_ALIGN(16, char m_id[64]);
|
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.
|
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.
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#include "net/Url.h"
|
#include "net/Url.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +36,7 @@
|
||||||
Url::Url() :
|
Url::Url() :
|
||||||
m_keepAlive(false),
|
m_keepAlive(false),
|
||||||
m_nicehash(false),
|
m_nicehash(false),
|
||||||
|
m_randnonce(false),
|
||||||
m_host(nullptr),
|
m_host(nullptr),
|
||||||
m_password(nullptr),
|
m_password(nullptr),
|
||||||
m_user(nullptr),
|
m_user(nullptr),
|
||||||
|
@ -59,6 +59,7 @@ Url::Url() :
|
||||||
Url::Url(const char *url) :
|
Url::Url(const char *url) :
|
||||||
m_keepAlive(false),
|
m_keepAlive(false),
|
||||||
m_nicehash(false),
|
m_nicehash(false),
|
||||||
|
m_randnonce(false),
|
||||||
m_host(nullptr),
|
m_host(nullptr),
|
||||||
m_password(nullptr),
|
m_password(nullptr),
|
||||||
m_user(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_keepAlive(keepAlive),
|
||||||
m_nicehash(nicehash),
|
m_nicehash(nicehash),
|
||||||
|
m_randnonce(randnonce),
|
||||||
m_password(password ? strdup(password) : nullptr),
|
m_password(password ? strdup(password) : nullptr),
|
||||||
m_user(user ? strdup(user) : nullptr),
|
m_user(user ? strdup(user) : nullptr),
|
||||||
m_port(port)
|
m_port(port)
|
||||||
|
@ -91,6 +93,10 @@ bool Url::isNicehash() const
|
||||||
{
|
{
|
||||||
return isValid() && (m_nicehash || strstr(m_host, ".nicehash.com"));
|
return isValid() && (m_nicehash || strstr(m_host, ".nicehash.com"));
|
||||||
}
|
}
|
||||||
|
bool Url::isRandNonce() const
|
||||||
|
{
|
||||||
|
return m_randnonce;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Url::parse(const char *url)
|
bool Url::parse(const char *url)
|
||||||
|
@ -170,6 +176,7 @@ Url &Url::operator=(const Url *other)
|
||||||
{
|
{
|
||||||
m_keepAlive = other->m_keepAlive;
|
m_keepAlive = other->m_keepAlive;
|
||||||
m_nicehash = other->m_nicehash;
|
m_nicehash = other->m_nicehash;
|
||||||
|
m_randnonce = other->m_randnonce;
|
||||||
m_port = other->m_port;
|
m_port = other->m_port;
|
||||||
|
|
||||||
free(m_host);
|
free(m_host);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
|
|
||||||
Url();
|
Url();
|
||||||
Url(const char *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();
|
~Url();
|
||||||
|
|
||||||
inline bool isKeepAlive() const { return m_keepAlive; }
|
inline bool isKeepAlive() const { return m_keepAlive; }
|
||||||
|
@ -48,8 +48,10 @@ public:
|
||||||
inline uint16_t port() const { return m_port; }
|
inline uint16_t port() const { return m_port; }
|
||||||
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
|
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
|
||||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||||
|
inline void setRandNonce(bool randnonce) { m_randnonce = randnonce; }
|
||||||
|
|
||||||
bool isNicehash() const;
|
bool isNicehash() const;
|
||||||
|
bool isRandNonce() const;
|
||||||
bool parse(const char *url);
|
bool parse(const char *url);
|
||||||
bool setUserpass(const char *userpass);
|
bool setUserpass(const char *userpass);
|
||||||
void setPassword(const char *password);
|
void setPassword(const char *password);
|
||||||
|
@ -60,6 +62,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool m_keepAlive;
|
bool m_keepAlive;
|
||||||
bool m_nicehash;
|
bool m_nicehash;
|
||||||
|
bool m_randnonce;
|
||||||
char *m_host;
|
char *m_host;
|
||||||
char *m_password;
|
char *m_password;
|
||||||
char *m_user;
|
char *m_user;
|
||||||
|
|
|
@ -54,7 +54,11 @@ void SingleWorker::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_count++;
|
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)) {
|
if (CryptoNight::hash(m_job, m_result, m_ctx)) {
|
||||||
Workers::submit(m_result);
|
Workers::submit(m_result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue