From 91ad6fcf3d35c803bcc7b7f33d02f3bd52d8defe Mon Sep 17 00:00:00 2001 From: SChernykh <sergey.v.chernykh@gmail.com> Date: Mon, 1 Mar 2021 17:46:05 +0100 Subject: [PATCH] Fixed many "new job" messages when solo mining Fix for https://github.com/xmrig/xmrig/issues/2127 --- src/base/net/stratum/DaemonClient.cpp | 26 ++++++++++++++++++++++---- src/base/net/stratum/DaemonClient.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 554ee8a89..07cc73608 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -179,12 +179,30 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data) return send(kGetInfo); } - if (isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, kHash))) { - getBlockTemplate(); + const uint64_t height = Json::getUint64(doc, kHeight); + const String hash = Json::getString(doc, kHash); + + if (isOutdated(height, hash)) { + // Multiple /getheight responses can come at once resulting in multiple getBlockTemplate() calls + if ((height != m_blocktemplateRequestHeight) || (hash != m_blocktemplateRequestHash)) { + m_blocktemplateRequestHeight = height; + m_blocktemplateRequestHash = hash; + getBlockTemplate(); + } } } - else if (data.url == kGetInfo && isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, "top_block_hash"))) { - getBlockTemplate(); + else if (data.url == kGetInfo) { + const uint64_t height = Json::getUint64(doc, kHeight); + const String hash = Json::getString(doc, "top_block_hash"); + + if (isOutdated(height, hash)) { + // Multiple /getinfo responses can come at once resulting in multiple getBlockTemplate() calls + if ((height != m_blocktemplateRequestHeight) || (hash != m_blocktemplateRequestHash)) { + m_blocktemplateRequestHeight = height; + m_blocktemplateRequestHash = hash; + getBlockTemplate(); + } + } } return; diff --git a/src/base/net/stratum/DaemonClient.h b/src/base/net/stratum/DaemonClient.h index 94858b50b..ff4f9e041 100644 --- a/src/base/net/stratum/DaemonClient.h +++ b/src/base/net/stratum/DaemonClient.h @@ -89,6 +89,8 @@ private: String m_tlsFingerprint; String m_tlsVersion; Timer *m_timer; + uint64_t m_blocktemplateRequestHeight = 0; + String m_blocktemplateRequestHash; };