1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-29 15:03:03 -05:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Stan Bondi
c418bc4f14 Merge af18c4571e into ee65b3d159 2024-10-24 09:33:56 +02:00
Stan Bondi
af18c4571e Merge branch 'master' into self-select-parse-fix 2021-11-01 18:16:55 +04:00
Stanimal
302290c4a1 Handle submit block response in self select client
This PR fixes self-select client with submit-to-origin=true by handling `submitblock` responses.

Previously, the submit block responses would result in an error message
and enter RETRY state because parseResponse expects all responses to be
for `getblocktemplate`.
2021-03-01 13:07:52 +04:00
11 changed files with 93 additions and 118 deletions

6
.gitignore vendored
View File

@@ -4,3 +4,9 @@ scripts/deps
/CMakeLists.txt.user
/.idea
/src/backend/opencl/cl/cn/cryptonight_gen.cl
*.a
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
/xmrig

View File

@@ -1,7 +1,3 @@
# v6.22.2
- [#3569](https://github.com/xmrig/xmrig/pull/3569) Fixed corrupted API output in some rare conditions.
- [#3571](https://github.com/xmrig/xmrig/pull/3571) Fixed number of threads on the new Intel Core Ultra CPUs.
# v6.22.1
- [#3531](https://github.com/xmrig/xmrig/pull/3531) Always reset nonce on RandomX dataset change.
- [#3534](https://github.com/xmrig/xmrig/pull/3534) Fixed threads auto-config on Zen5.

View File

@@ -30,10 +30,10 @@
#include "base/tools/Handle.h"
inline static const char *format(std::pair<bool, double> h, char *buf, size_t size)
inline static const char *format(double h, char *buf, size_t size)
{
if (h.first) {
snprintf(buf, size, (h.second < 100.0) ? "%04.2f" : "%03.1f", h.second);
if (std::isnormal(h)) {
snprintf(buf, size, (h < 100.0) ? "%04.2f" : "%03.1f", h);
return buf;
}
@@ -80,16 +80,15 @@ double xmrig::Hashrate::average() const
}
const char *xmrig::Hashrate::format(std::pair<bool, double> h, char *buf, size_t size)
const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
{
return ::format(h, buf, size);
}
rapidjson::Value xmrig::Hashrate::normalize(std::pair<bool, double> d)
rapidjson::Value xmrig::Hashrate::normalize(double d)
{
using namespace rapidjson;
return d.first ? Value(floor(d.second * 100.0) / 100.0) : Value(kNullType);
return Json::normalize(d, false);
}
@@ -123,11 +122,11 @@ rapidjson::Value xmrig::Hashrate::toJSON(size_t threadId, rapidjson::Document &d
#endif
std::pair<bool, double> xmrig::Hashrate::hashrate(size_t index, size_t ms) const
double xmrig::Hashrate::hashrate(size_t index, size_t ms) const
{
assert(index < m_threads);
if (index >= m_threads) {
return { false, 0.0 };
return nan("");
}
uint64_t earliestHashCount = 0;
@@ -158,27 +157,17 @@ std::pair<bool, double> xmrig::Hashrate::hashrate(size_t index, size_t ms) const
} while (idx != idx_start);
if (!haveFullSet || earliestStamp == 0 || lastestStamp == 0) {
return { false, 0.0 };
return nan("");
}
if (lastestHashCnt == earliestHashCount) {
return { true, 0.0 };
}
if (lastestStamp == earliestStamp) {
return { false, 0.0 };
if (lastestStamp - earliestStamp == 0) {
return nan("");
}
const auto hashes = static_cast<double>(lastestHashCnt - earliestHashCount);
const auto time = static_cast<double>(lastestStamp - earliestStamp);
const auto time = static_cast<double>(lastestStamp - earliestStamp) / 1000.0;
const auto hr = hashes * 1000.0 / time;
if (!std::isnormal(hr)) {
return { false, 0.0 };
}
return { true, hr };
return hashes / time;
}

View File

@@ -47,16 +47,16 @@ public:
Hashrate(size_t threads);
~Hashrate();
inline std::pair<bool, double> calc(size_t ms) const { return hashrate(0U, ms); }
inline std::pair<bool, double> calc(size_t threadId, size_t ms) const { return hashrate(threadId + 1, ms); }
inline double calc(size_t ms) const { const double data = hashrate(0U, ms); return std::isnormal(data) ? data : 0.0; }
inline double calc(size_t threadId, size_t ms) const { return hashrate(threadId + 1, ms); }
inline size_t threads() const { return m_threads > 0U ? m_threads - 1U : 0U; }
inline void add(size_t threadId, uint64_t count, uint64_t timestamp) { addData(threadId + 1U, count, timestamp); }
inline void add(uint64_t count, uint64_t timestamp) { addData(0U, count, timestamp); }
double average() const;
static const char *format(std::pair<bool, double> h, char *buf, size_t size);
static rapidjson::Value normalize(std::pair<bool, double> d);
static const char *format(double h, char *buf, size_t size);
static rapidjson::Value normalize(double d);
# ifdef XMRIG_FEATURE_API
rapidjson::Value toJSON(rapidjson::Document &doc) const;
@@ -64,7 +64,7 @@ public:
# endif
private:
std::pair<bool, double> hashrate(size_t index, size_t ms) const;
double hashrate(size_t index, size_t ms) const;
void addData(size_t index, uint64_t count, uint64_t timestamp);
constexpr static size_t kBucketSize = 2 << 11;

View File

@@ -342,7 +342,7 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith
}
# ifdef XMRIG_ALGO_RANDOMX
if ((vendor() == VENDOR_INTEL) && (algorithm.family() == Algorithm::RANDOM_X) && L3_exclusive && (PUs < cores.size() * 2)) {
if ((algorithm.family() == Algorithm::RANDOM_X) && L3_exclusive && (PUs > cores.size()) && (PUs < cores.size() * 2)) {
// Use all L3+L2 on latest Intel CPUs with P-cores, E-cores and exclusive L3 cache
cacheHashes = (L3 + L2) / scratchpad;
}

View File

@@ -372,20 +372,15 @@ void xmrig::CudaBackend::printHashrate(bool details)
char num[16 * 3] = { 0 };
auto hashrate_short = hashrate()->calc(Hashrate::ShortInterval);
auto hashrate_medium = hashrate()->calc(Hashrate::MediumInterval);
auto hashrate_large = hashrate()->calc(Hashrate::LargeInterval);
const double hashrate_short = hashrate()->calc(Hashrate::ShortInterval);
const double hashrate_medium = hashrate()->calc(Hashrate::MediumInterval);
const double hashrate_large = hashrate()->calc(Hashrate::LargeInterval);
double scale = 1.0;
const char* h = " H/s";
if ((hashrate_short.second >= 1e6) || (hashrate_medium.second >= 1e6) || (hashrate_large.second >= 1e6)) {
if ((hashrate_short >= 1e6) || (hashrate_medium >= 1e6) || (hashrate_large >= 1e6)) {
scale = 1e-6;
hashrate_short.second *= scale;
hashrate_medium.second *= scale;
hashrate_large.second *= scale;
h = "MH/s";
}
@@ -393,20 +388,12 @@ void xmrig::CudaBackend::printHashrate(bool details)
size_t i = 0;
for (const auto& data : d_ptr->threads) {
auto h0 = hashrate()->calc(i, Hashrate::ShortInterval);
auto h1 = hashrate()->calc(i, Hashrate::MediumInterval);
auto h2 = hashrate()->calc(i, Hashrate::LargeInterval);
h0.second *= scale;
h1.second *= scale;
h2.second *= scale;
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") GREEN(" %s"),
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") GREEN(" %s"),
i,
data.thread.affinity(),
Hashrate::format(h0, num, sizeof num / 3),
Hashrate::format(h1, num + 16, sizeof num / 3),
Hashrate::format(h2, num + 16 * 2, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
data.device.index(),
data.device.topology().toString().data(),
data.device.name().data()
@@ -416,9 +403,9 @@ void xmrig::CudaBackend::printHashrate(bool details)
}
Log::print(WHITE_BOLD_S "| - | - | %8s | %8s | %8s |",
Hashrate::format(hashrate_short , num, sizeof num / 3),
Hashrate::format(hashrate_medium, num + 16, sizeof num / 3),
Hashrate::format(hashrate_large , num + 16 * 2, sizeof num / 3)
Hashrate::format(hashrate_short * scale, num, sizeof num / 3),
Hashrate::format(hashrate_medium * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate_large * scale, num + 16 * 2, sizeof num / 3)
);
}

View File

@@ -352,20 +352,15 @@ void xmrig::OclBackend::printHashrate(bool details)
char num[16 * 3] = { 0 };
auto hashrate_short = hashrate()->calc(Hashrate::ShortInterval);
auto hashrate_medium = hashrate()->calc(Hashrate::MediumInterval);
auto hashrate_large = hashrate()->calc(Hashrate::LargeInterval);
const double hashrate_short = hashrate()->calc(Hashrate::ShortInterval);
const double hashrate_medium = hashrate()->calc(Hashrate::MediumInterval);
const double hashrate_large = hashrate()->calc(Hashrate::LargeInterval);
double scale = 1.0;
const char* h = " H/s";
if ((hashrate_short.second >= 1e6) || (hashrate_medium.second >= 1e6) || (hashrate_large.second >= 1e6)) {
if ((hashrate_short >= 1e6) || (hashrate_medium >= 1e6) || (hashrate_large >= 1e6)) {
scale = 1e-6;
hashrate_short.second *= scale;
hashrate_medium.second *= scale;
hashrate_large.second *= scale;
h = "MH/s";
}
@@ -373,16 +368,12 @@ void xmrig::OclBackend::printHashrate(bool details)
size_t i = 0;
for (const auto& data : d_ptr->threads) {
auto h0 = hashrate()->calc(i, Hashrate::ShortInterval);
auto h1 = hashrate()->calc(i, Hashrate::MediumInterval);
auto h2 = hashrate()->calc(i, Hashrate::LargeInterval);
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
i,
data.affinity,
Hashrate::format(h0, num, sizeof num / 3),
Hashrate::format(h1, num + 16, sizeof num / 3),
Hashrate::format(h2, num + 16 * 2, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
data.device.index(),
data.device.topology().toString().data(),
data.device.printableName().data()
@@ -392,9 +383,9 @@ void xmrig::OclBackend::printHashrate(bool details)
}
Log::print(WHITE_BOLD_S "| - | - | %8s | %8s | %8s |",
Hashrate::format(hashrate_short , num, sizeof num / 3),
Hashrate::format(hashrate_medium, num + 16, sizeof num / 3),
Hashrate::format(hashrate_large , num + 16 * 2, sizeof num / 3)
Hashrate::format(hashrate_short * scale, num, sizeof num / 3),
Hashrate::format(hashrate_medium * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate_large * scale, num + 16 * 2, sizeof num / 3)
);
}

View File

@@ -45,6 +45,8 @@ static const char *kJobId = "job_id";
static const char *kNextSeedHash = "next_seed_hash";
static const char *kPrevHash = "prev_hash";
static const char *kSeedHash = "seed_hash";
static const char *kStatus = "status";
static const char *kStatusOk = "OK";
static const char * const required_fields[] = { kBlocktemplateBlob, kBlockhashingBlob, kHeight, kDifficulty, kPrevHash };
@@ -55,8 +57,9 @@ xmrig::SelfSelectClient::SelfSelectClient(int id, const char *agent, IClientList
m_submitToOrigin(submitToOrigin),
m_listener(listener)
{
m_httpListener = std::make_shared<HttpListener>(this);
m_client = new Client(id, agent, this);
m_httpListener = std::make_shared<HttpListener>(this);
m_client = new Client(id, agent, this);
m_last_submit_req_id = -1;
}
@@ -129,6 +132,20 @@ bool xmrig::SelfSelectClient::parseResponse(int64_t id, rapidjson::Value &result
return false;
}
if (isSubmitBlockResponse(id)) {
xmrig::String submit_status = Json::getString(result, kStatus);
submit_status.toUpper();
if (submit_status == kStatusOk) {
// Ensure that the latest block template is available after block submission
getBlockTemplate();
return true;
}
LOG_ERR("[%s] " RED_BOLD("block not submitted to origin. status = \"%s\""), pool().daemon().url().data(), submit_status.data());
return false;
}
for (auto field : required_fields) {
if (!result.HasMember(field)) {
LOG_ERR("[%s] required field " RED_BOLD("\"%s\"") RED_S " not found", pool().daemon().url().data(), field);
@@ -158,6 +175,10 @@ bool xmrig::SelfSelectClient::parseResponse(int64_t id, rapidjson::Value &result
return true;
}
bool xmrig::SelfSelectClient::isSubmitBlockResponse(int64_t id)
{
return m_last_submit_req_id > -1 && id == m_last_submit_req_id;
}
void xmrig::SelfSelectClient::getBlockTemplate()
{
@@ -282,8 +303,8 @@ void xmrig::SelfSelectClient::submitOriginDaemon(const JobResult& result)
Value params(kArrayType);
params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator());
JsonRequest::create(doc, m_sequence, "submitblock", params);
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend);
m_last_submit_req_id = m_sequence;
JsonRequest::create(doc, m_sequence++, "submitblock", params);
FetchRequest req(HTTP_POST, pool().daemon().host(), pool().daemon().port(), "/json_rpc", doc, pool().daemon().isTLS(), isQuiet());
fetch(tag(), std::move(req), m_httpListener);

View File

@@ -99,6 +99,7 @@ private:
void getBlockTemplate();
void retry();
void setState(State state);
bool isSubmitBlockResponse(int64_t id);
void submitBlockTemplate(rapidjson::Value &result);
void submitOriginDaemon(const JobResult &result);
@@ -112,8 +113,8 @@ private:
int64_t m_sequence = 1;
Job m_job;
State m_state = IdleState;
std::map<int64_t, SubmitResult> m_results;
std::shared_ptr<IHttpListener> m_httpListener;
int64_t m_last_submit_req_id;
std::shared_ptr<IHttpListener> m_httpListener;
String m_blocktemplate;
uint64_t m_blockDiff = 0;
uint64_t m_originNotSubmitted = 0;

View File

@@ -173,7 +173,7 @@ public:
Value total(kArrayType);
Value threads(kArrayType);
std::pair<bool, double> t[3] = { { true, 0.0 }, { true, 0.0 }, { true, 0.0 } };
double t[3] = { 0.0 };
for (IBackend *backend : backends) {
const Hashrate *hr = backend->hashrate();
@@ -181,13 +181,9 @@ public:
continue;
}
const auto h0 = hr->calc(Hashrate::ShortInterval);
const auto h1 = hr->calc(Hashrate::MediumInterval);
const auto h2 = hr->calc(Hashrate::LargeInterval);
if (h0.first) { t[0].second += h0.second; } else { t[0].first = false; }
if (h1.first) { t[1].second += h1.second; } else { t[1].first = false; }
if (h2.first) { t[2].second += h2.second; } else { t[2].first = false; }
t[0] += hr->calc(Hashrate::ShortInterval);
t[1] += hr->calc(Hashrate::MediumInterval);
t[2] += hr->calc(Hashrate::LargeInterval);
if (version > 1) {
continue;
@@ -208,7 +204,7 @@ public:
total.PushBack(Hashrate::normalize(t[2]), allocator);
hashrate.AddMember("total", total, allocator);
hashrate.AddMember("highest", Hashrate::normalize({ maxHashrate[algorithm] > 0.0, maxHashrate[algorithm] }), allocator);
hashrate.AddMember("highest", Hashrate::normalize(maxHashrate[algorithm]), allocator);
if (version == 1) {
hashrate.AddMember("threads", threads, allocator);
@@ -287,7 +283,7 @@ public:
void printHashrate(bool details)
{
char num[16 * 5] = { 0 };
std::pair<bool, double> speed[3] = { { true, 0.0 }, { true, 0.0 }, { true, 0.0 } };
double speed[3] = { 0.0 };
uint32_t count = 0;
double avg_hashrate = 0.0;
@@ -297,13 +293,9 @@ public:
if (hashrate) {
++count;
const auto h0 = hashrate->calc(Hashrate::ShortInterval);
const auto h1 = hashrate->calc(Hashrate::MediumInterval);
const auto h2 = hashrate->calc(Hashrate::LargeInterval);
if (h0.first) { speed[0].second += h0.second; } else { speed[0].first = false; }
if (h1.first) { speed[1].second += h1.second; } else { speed[1].first = false; }
if (h2.first) { speed[2].second += h2.second; } else { speed[2].first = false; }
speed[0] += hashrate->calc(Hashrate::ShortInterval);
speed[1] += hashrate->calc(Hashrate::MediumInterval);
speed[2] += hashrate->calc(Hashrate::LargeInterval);
avg_hashrate += hashrate->average();
}
@@ -320,13 +312,8 @@ public:
double scale = 1.0;
const char* h = "H/s";
if ((speed[0].second >= 1e6) || (speed[1].second >= 1e6) || (speed[2].second >= 1e6) || (maxHashrate[algorithm] >= 1e6)) {
if ((speed[0] >= 1e6) || (speed[1] >= 1e6) || (speed[2] >= 1e6) || (maxHashrate[algorithm] >= 1e6)) {
scale = 1e-6;
speed[0].second *= scale;
speed[1].second *= scale;
speed[2].second *= scale;
h = "MH/s";
}
@@ -335,16 +322,16 @@ public:
# ifdef XMRIG_ALGO_GHOSTRIDER
if (algorithm.family() == Algorithm::GHOSTRIDER) {
snprintf(avg_hashrate_buf, sizeof(avg_hashrate_buf), " avg " CYAN_BOLD("%s %s"), Hashrate::format({ true, avg_hashrate * scale }, num + 16 * 4, 16), h);
snprintf(avg_hashrate_buf, sizeof(avg_hashrate_buf), " avg " CYAN_BOLD("%s %s"), Hashrate::format(avg_hashrate * scale, num + 16 * 4, 16), h);
}
# endif
LOG_INFO("%s " WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("%s") " max " CYAN_BOLD("%s %s") "%s",
Tags::miner(),
Hashrate::format(speed[0], num, 16),
Hashrate::format(speed[1], num + 16, 16),
Hashrate::format(speed[2], num + 16 * 2, 16), h,
Hashrate::format({ maxHashrate[algorithm] > 0.0, maxHashrate[algorithm] * scale }, num + 16 * 3, 16), h,
Hashrate::format(speed[0] * scale, num, 16),
Hashrate::format(speed[1] * scale, num + 16, 16),
Hashrate::format(speed[2] * scale, num + 16 * 2, 16), h,
Hashrate::format(maxHashrate[algorithm] * scale, num + 16 * 3, 16), h,
avg_hashrate_buf
);
@@ -659,10 +646,7 @@ void xmrig::Miner::onTimer(const Timer *)
}
if (backend->hashrate()) {
const auto h = backend->hashrate()->calc(Hashrate::ShortInterval);
if (h.first) {
maxHashrate += h.second;
}
maxHashrate += backend->hashrate()->calc(Hashrate::ShortInterval);
}
}

View File

@@ -22,7 +22,7 @@
#define APP_ID "xmrig"
#define APP_NAME "XMRig"
#define APP_DESC "XMRig miner"
#define APP_VERSION "6.22.2"
#define APP_VERSION "6.22.1"
#define APP_DOMAIN "xmrig.com"
#define APP_SITE "www.xmrig.com"
#define APP_COPYRIGHT "Copyright (C) 2016-2024 xmrig.com"
@@ -30,7 +30,7 @@
#define APP_VER_MAJOR 6
#define APP_VER_MINOR 22
#define APP_VER_PATCH 2
#define APP_VER_PATCH 1
#ifdef _MSC_VER
# if (_MSC_VER >= 1930)