diff --git a/src/backend/common/WorkerJob.h b/src/backend/common/WorkerJob.h index 2ea414761..3511c1fff 100644 --- a/src/backend/common/WorkerJob.h +++ b/src/backend/common/WorkerJob.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,13 +64,17 @@ public: } - inline void nextRound(uint32_t rounds, uint32_t roundSize) + inline bool nextRound(uint32_t rounds, uint32_t roundSize) { + bool ok = true; m_rounds[index()]++; if ((m_rounds[index()] % rounds) == 0) { for (size_t i = 0; i < N; ++i) { - *nonce(i) = Nonce::next(index(), *nonce(i), rounds * roundSize, currentJob().isNicehash()); + *nonce(i) = Nonce::next(index(), *nonce(i), rounds * roundSize, currentJob().isNicehash(), &ok); + if (!ok) { + break; + } } } else { @@ -78,6 +82,8 @@ public: *nonce(i) += roundSize; } } + + return ok; } @@ -114,16 +120,19 @@ inline uint32_t *xmrig::WorkerJob<1>::nonce(size_t) template<> -inline void xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize) +inline bool xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize) { + bool ok = true; m_rounds[index()]++; if ((m_rounds[index()] % rounds) == 0) { - *nonce() = Nonce::next(index(), *nonce(), rounds * roundSize, currentJob().isNicehash()); + *nonce() = Nonce::next(index(), *nonce(), rounds * roundSize, currentJob().isNicehash(), &ok); } else { *nonce() += roundSize; } + + return ok; } diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 0403d9c56..535ecd6b4 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,6 +48,20 @@ namespace xmrig { static constexpr uint32_t kReserveCount = 32768; + +template +inline bool nextRound(WorkerJob &job) +{ + if (!job.nextRound(kReserveCount, 1)) { + JobResults::done(job.currentJob()); + + return false; + } + + return true; +} + + } // namespace xmrig @@ -221,14 +235,20 @@ void xmrig::CpuWorker::start() first = false; randomx_calculate_hash_first(m_vm->get(), tempHash, m_job.blob(), job.size()); } - m_job.nextRound(kReserveCount, 1); + + if (!nextRound(m_job)) { + break; + } + randomx_calculate_hash_next(m_vm->get(), tempHash, m_job.blob(), job.size(), m_hash); } else # endif { fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height()); - m_job.nextRound(kReserveCount, 1); + if (!nextRound(m_job)) { + break; + }; } for (size_t i = 0; i < N; ++i) { diff --git a/src/backend/cpu/CpuWorker.h b/src/backend/cpu/CpuWorker.h index 11aba0478..d9528cf95 100644 --- a/src/backend/cpu/CpuWorker.h +++ b/src/backend/cpu/CpuWorker.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index df90e40fa..42c755f5c 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -5,9 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh * Copyright 2019 jtgrassie - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -181,11 +181,17 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj) int64_t xmrig::Client::submit(const JobResult &result) { # ifndef XMRIG_PROXY_PROJECT - if (result.clientId != m_rpcId) { + if (result.clientId != m_rpcId || m_state != ConnectedState) { return -1; } # endif + if (result.diff == 0) { + close(); + + return -1; + } + using namespace rapidjson; # ifdef XMRIG_PROXY_PROJECT diff --git a/src/crypto/common/Nonce.cpp b/src/crypto/common/Nonce.cpp index 897045caf..f896c5612 100644 --- a/src/crypto/common/Nonce.cpp +++ b/src/crypto/common/Nonce.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,12 +23,12 @@ */ -#include - - #include "crypto/common/Nonce.h" +#include + + namespace xmrig { @@ -54,13 +54,23 @@ xmrig::Nonce::Nonce() } -uint32_t xmrig::Nonce::next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash) +uint32_t xmrig::Nonce::next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash, bool *ok) { uint32_t next; std::lock_guard lock(mutex); if (nicehash) { + if ((m_nonces[index] + reserveCount) > 0x1000000) { + if (ok) { + *ok = false; + } + + pause(true); + + return 0; + } + next = (nonce & 0xFF000000) | m_nonces[index]; } else { diff --git a/src/crypto/common/Nonce.h b/src/crypto/common/Nonce.h index 7335663dd..4fa47b873 100644 --- a/src/crypto/common/Nonce.h +++ b/src/crypto/common/Nonce.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,7 +52,7 @@ public: static inline void stop(Backend backend) { m_sequence[backend] = 0; } static inline void touch(Backend backend) { m_sequence[backend]++; } - static uint32_t next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash); + static uint32_t next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash, bool *ok = nullptr); static void reset(uint8_t index); static void stop(); static void touch(); diff --git a/src/net/JobResult.h b/src/net/JobResult.h index a44a639b5..244227f1e 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,6 +55,17 @@ public: memcpy(m_result, result, sizeof(m_result)); } + inline JobResult(const Job &job) : + algorithm(job.algorithm()), + clientId(job.clientId()), + jobId(job.id()), + backend(job.backend()), + nonce(0), + diff(0), + index(job.index()) + { + } + inline const uint8_t *result() const { return m_result; } inline uint64_t actualDiff() const { return Job::toDiff(reinterpret_cast(m_result)[3]); } inline uint8_t *result() { return m_result; } diff --git a/src/net/JobResults.cpp b/src/net/JobResults.cpp index c9c699f91..49bff807f 100644 --- a/src/net/JobResults.cpp +++ b/src/net/JobResults.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ #include "net/JobResults.h" - #include "base/io/log/Log.h" #include "base/tools/Handle.h" #include "base/tools/Object.h" @@ -272,6 +271,11 @@ static JobResultsPrivate *handler = nullptr; } // namespace xmrig +void xmrig::JobResults::done(const Job &job) +{ + submit(JobResult(job)); +} + void xmrig::JobResults::setListener(IJobResultListener *listener, bool hwAES) { diff --git a/src/net/JobResults.h b/src/net/JobResults.h index 4d16d27bf..1b32e5bdb 100644 --- a/src/net/JobResults.h +++ b/src/net/JobResults.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +42,7 @@ class JobResult; class JobResults { public: + static void done(const Job &job); static void setListener(IJobResultListener *listener, bool hwAES); static void stop(); static void submit(const Job &job, uint32_t nonce, const uint8_t *result);