Merge e283ff8013
into 850e355049
This commit is contained in:
commit
71e7ac46b8
7 changed files with 39 additions and 8 deletions
|
@ -83,6 +83,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\
|
||||||
";
|
";
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,6 +117,7 @@ static struct option const options[] = {
|
||||||
{ "user-agent", 1, nullptr, 1008 },
|
{ "user-agent", 1, nullptr, 1008 },
|
||||||
{ "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 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -477,6 +479,10 @@ bool Options::parseBoolean(int key, bool enable)
|
||||||
m_colors = enable;
|
m_colors = enable;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 1008: /* --rand-nonce */
|
||||||
|
m_pools.back()->setRandNonce(true);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,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 uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
||||||
|
@ -50,6 +50,7 @@ public:
|
||||||
inline uint32_t diff() const { return (uint32_t) m_diff; }
|
inline uint32_t diff() const { return (uint32_t) m_diff; }
|
||||||
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; }
|
||||||
|
@ -65,6 +66,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;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
|
@ -38,6 +39,8 @@ SingleWorker::SingleWorker(Handle *handle)
|
||||||
|
|
||||||
void SingleWorker::start()
|
void SingleWorker::start()
|
||||||
{
|
{
|
||||||
|
srand(getpid() * time(NULL));
|
||||||
|
bool israndnonce = false;
|
||||||
while (Workers::sequence() > 0) {
|
while (Workers::sequence() > 0) {
|
||||||
if (Workers::isPaused()) {
|
if (Workers::isPaused()) {
|
||||||
do {
|
do {
|
||||||
|
@ -52,16 +55,25 @@ void SingleWorker::start()
|
||||||
consumeJob();
|
consumeJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
israndnonce = m_job.isRandNonce();
|
||||||
|
if (israndnonce) {
|
||||||
|
m_result.nonce += rand();
|
||||||
|
}
|
||||||
while (!Workers::isOutdated(m_sequence)) {
|
while (!Workers::isOutdated(m_sequence)) {
|
||||||
if ((m_count & 0xF) == 0) {
|
if ((m_count & 0xF) == 0) {
|
||||||
storeStats();
|
storeStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_count++;
|
m_count++;
|
||||||
*m_job.nonce() = ++m_result.nonce;
|
if (israndnonce && (m_count & 0xFF) == 0) {
|
||||||
|
*m_job.nonce() = m_result.nonce += (rand() + time(NULL) + getpid());
|
||||||
|
} 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);
|
||||||
|
m_result.nonce += (rand() + time(NULL) + getpid());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue