From 9223c2f02709cd123a6bcf1ca9709ec975b8706c Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 19 Sep 2022 10:33:03 +0200 Subject: [PATCH 1/2] Don't reset when pool sends the same job blob --- src/base/net/stratum/Job.cpp | 8 +++++++- src/base/net/stratum/Job.h | 1 + src/core/Miner.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 7f5d8d3f..7aa910bf 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -48,7 +48,13 @@ xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientI bool xmrig::Job::isEqual(const Job &other) const { - return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0 && m_target == other.m_target; + return m_id == other.m_id && m_clientId == other.m_clientId && isEqualBlob(other) && m_target == other.m_target; +} + + +bool xmrig::Job::isEqualBlob(const Job &other) const +{ + return (m_size == other.m_size) && (memcmp(m_blob, other.m_blob, m_size) == 0); } diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 3fb31baa..e314a266 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -59,6 +59,7 @@ public: ~Job() = default; bool isEqual(const Job &other) const; + bool isEqualBlob(const Job &other) const; bool setBlob(const char *blob); bool setSeedHash(const char *hash); bool setTarget(const char *target); diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index a892345d..9cc9092b 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -561,6 +561,12 @@ void xmrig::Miner::setJob(const Job &job, bool donate) const uint8_t index = donate ? 1 : 0; d_ptr->reset = !(d_ptr->job.index() == 1 && index == 0 && d_ptr->userJobId == job.id()); + + // Don't reset nonce if pool sends the same hashing blob again, but with different difficulty (for example) + if (d_ptr->job.isEqualBlob(job)) { + d_ptr->reset = false; + } + d_ptr->job = job; d_ptr->job.setIndex(index); From 8bd3b393efb048d97e95a43a6b0d6dd8adb0280b Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 19 Sep 2022 10:42:08 +0200 Subject: [PATCH 2/2] Update m_size only if blob was set successfully --- src/base/net/stratum/Job.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 7aa910bf..56f5de80 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -64,19 +64,19 @@ bool xmrig::Job::setBlob(const char *blob) return false; } - m_size = strlen(blob); - if (m_size % 2 != 0) { + size_t size = strlen(blob); + if (size % 2 != 0) { return false; } - m_size /= 2; + size /= 2; const size_t minSize = nonceOffset() + nonceSize(); - if (m_size < minSize || m_size >= sizeof(m_blob)) { + if (size < minSize || size >= sizeof(m_blob)) { return false; } - if (!Cvt::fromHex(m_blob, sizeof(m_blob), blob, m_size * 2)) { + if (!Cvt::fromHex(m_blob, sizeof(m_blob), blob, size * 2)) { return false; } @@ -86,9 +86,10 @@ bool xmrig::Job::setBlob(const char *blob) # ifdef XMRIG_PROXY_PROJECT memset(m_rawBlob, 0, sizeof(m_rawBlob)); - memcpy(m_rawBlob, blob, m_size * 2); + memcpy(m_rawBlob, blob, size * 2); # endif + m_size = size; return true; }