mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-22 18:54:43 +00:00
Display backend for shares.
This commit is contained in:
parent
b1eac17d60
commit
23ebcfb2db
14 changed files with 121 additions and 32 deletions
|
@ -27,10 +27,15 @@
|
|||
#define XMRIG_TAGS_H
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
const char *backend_tag(uint32_t backend);
|
||||
const char *cpu_tag();
|
||||
const char *net_tag();
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_OPENCL
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define XMRIG_WORKERJOB_H
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
#include "base/net/stratum/Job.h"
|
||||
|
@ -47,9 +47,9 @@ public:
|
|||
inline uint8_t index() const { return m_index; }
|
||||
|
||||
|
||||
inline void add(const Job &job, uint64_t sequence, uint32_t reserveCount)
|
||||
inline void add(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
|
||||
{
|
||||
m_sequence = sequence;
|
||||
m_sequence = Nonce::sequence(backend);
|
||||
|
||||
if (currentJob() == job) {
|
||||
return;
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
save(job, reserveCount);
|
||||
save(job, reserveCount, backend);
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,13 +82,15 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
inline void save(const Job &job, uint32_t reserveCount)
|
||||
inline void save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
|
||||
{
|
||||
m_index = job.index();
|
||||
const size_t size = job.size();
|
||||
m_jobs[index()] = job;
|
||||
m_rounds[index()] = 0;
|
||||
|
||||
m_jobs[index()].setBackend(backend);
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
memcpy(m_blobs[index()] + (i * size), job.blob(), size);
|
||||
*nonce(i) = Nonce::next(index(), *nonce(i), reserveCount, job.isNicehash());
|
||||
|
@ -96,7 +98,7 @@ private:
|
|||
}
|
||||
|
||||
|
||||
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N];
|
||||
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]{};
|
||||
Job m_jobs[2];
|
||||
uint32_t m_rounds[2] = { 0, 0 };
|
||||
uint64_t m_sequence = 0;
|
||||
|
@ -126,12 +128,14 @@ inline void xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize)
|
|||
|
||||
|
||||
template<>
|
||||
inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount)
|
||||
inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
|
||||
{
|
||||
m_index = job.index();
|
||||
m_jobs[index()] = job;
|
||||
m_rounds[index()] = 0;
|
||||
|
||||
m_jobs[index()].setBackend(backend);
|
||||
|
||||
memcpy(blob(), job.blob(), job.size());
|
||||
*nonce() = Nonce::next(index(), *nonce(), reserveCount, currentJob().isNicehash());
|
||||
}
|
||||
|
|
|
@ -210,6 +210,24 @@ public:
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
const char *xmrig::backend_tag(uint32_t backend)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
if (backend == Nonce::OPENCL) {
|
||||
return ocl_tag();
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_CUDA
|
||||
if (backend == Nonce::CUDA) {
|
||||
return cuda_tag();
|
||||
}
|
||||
# endif
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::cpu_tag()
|
||||
{
|
||||
return tag;
|
||||
|
|
|
@ -303,7 +303,7 @@ void xmrig::CpuWorker<N>::consumeJob()
|
|||
return;
|
||||
}
|
||||
|
||||
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount);
|
||||
m_job.add(m_miner->job(), kReserveCount, Nonce::CPU);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) {
|
||||
|
|
|
@ -153,7 +153,7 @@ bool xmrig::CudaWorker::consumeJob()
|
|||
}
|
||||
|
||||
const size_t batch_size = intensity();
|
||||
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CUDA), roundSize(batch_size) * batch_size);
|
||||
m_job.add(m_miner->job(), roundSize(batch_size) * batch_size, Nonce::CUDA);
|
||||
|
||||
return m_runner->set(m_job.currentJob(), m_job.blob());;
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ bool xmrig::OclWorker::consumeJob()
|
|||
return false;
|
||||
}
|
||||
|
||||
m_job.add(m_miner->job(), Nonce::sequence(Nonce::OPENCL), roundSize(m_intensity) * m_intensity);
|
||||
m_job.add(m_miner->job(), roundSize(m_intensity) * m_intensity, Nonce::OPENCL);
|
||||
|
||||
try {
|
||||
m_runner->set(m_job.currentJob(), m_job.blob());
|
||||
|
|
|
@ -214,7 +214,7 @@ int64_t xmrig::Client::submit(const JobResult &result)
|
|||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
|
||||
# else
|
||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff());
|
||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend);
|
||||
# endif
|
||||
|
||||
return send(doc);
|
||||
|
|
|
@ -119,7 +119,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
|
||||
# else
|
||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff());
|
||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend);
|
||||
# endif
|
||||
|
||||
send(HTTP_POST, kJsonRPC, doc);
|
||||
|
|
|
@ -157,6 +157,7 @@ void xmrig::Job::copy(const Job &other)
|
|||
m_size = other.m_size;
|
||||
m_clientId = other.m_clientId;
|
||||
m_id = other.m_id;
|
||||
m_backend = other.m_backend;
|
||||
m_diff = other.m_diff;
|
||||
m_height = other.m_height;
|
||||
m_target = other.m_target;
|
||||
|
@ -174,3 +175,34 @@ void xmrig::Job::copy(const Job &other)
|
|||
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Job::move(Job &&other)
|
||||
{
|
||||
m_algorithm = other.m_algorithm;
|
||||
m_nicehash = other.m_nicehash;
|
||||
m_size = other.m_size;
|
||||
m_clientId = std::move(other.m_clientId);
|
||||
m_id = std::move(other.m_id);
|
||||
m_backend = other.m_backend;
|
||||
m_diff = other.m_diff;
|
||||
m_height = other.m_height;
|
||||
m_target = other.m_target;
|
||||
m_index = other.m_index;
|
||||
m_seed = std::move(other.m_seed);
|
||||
m_extraNonce = std::move(other.m_extraNonce);
|
||||
m_poolWallet = std::move(other.m_poolWallet);
|
||||
|
||||
memcpy(m_blob, other.m_blob, sizeof(m_blob));
|
||||
|
||||
other.m_size = 0;
|
||||
other.m_diff = 0;
|
||||
other.m_algorithm = Algorithm::INVALID;
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_rawSeedHash = std::move(other.m_rawSeedHash);
|
||||
|
||||
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
|
||||
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
|
||||
# endif
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ public:
|
|||
|
||||
Job() = default;
|
||||
Job(bool nicehash, const Algorithm &algorithm, const String &clientId);
|
||||
|
||||
inline Job(const Job &other) { copy(other); }
|
||||
inline Job(Job &&other) noexcept { move(std::move(other)); }
|
||||
|
||||
~Job() = default;
|
||||
|
||||
bool isEqual(const Job &other) const;
|
||||
|
@ -71,6 +75,7 @@ public:
|
|||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint32_t backend() const { return m_backend; }
|
||||
inline uint64_t diff() const { return m_diff; }
|
||||
inline uint64_t height() const { return m_height; }
|
||||
inline uint64_t target() const { return m_target; }
|
||||
|
@ -79,6 +84,7 @@ public:
|
|||
inline void reset() { m_size = 0; m_diff = 0; }
|
||||
inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; }
|
||||
inline void setAlgorithm(const char *algo) { m_algorithm = algo; }
|
||||
inline void setBackend(uint32_t backend) { m_backend = backend; }
|
||||
inline void setClientId(const String &id) { m_clientId = id; }
|
||||
inline void setExtraNonce(const String &extraNonce) { m_extraNonce = extraNonce; }
|
||||
inline void setHeight(uint64_t height) { m_height = height; }
|
||||
|
@ -95,12 +101,14 @@ public:
|
|||
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
|
||||
static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
|
||||
|
||||
inline bool operator==(const Job &other) const { return isEqual(other); }
|
||||
inline bool operator!=(const Job &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Job &other) const { return isEqual(other); }
|
||||
inline Job &operator=(const Job &other) { copy(other); return *this; }
|
||||
inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; }
|
||||
|
||||
private:
|
||||
void copy(const Job &other);
|
||||
void move(Job &&other);
|
||||
|
||||
Algorithm m_algorithm;
|
||||
bool m_nicehash = false;
|
||||
|
@ -110,6 +118,7 @@ private:
|
|||
String m_extraNonce;
|
||||
String m_id;
|
||||
String m_poolWallet;
|
||||
uint32_t m_backend = 0;
|
||||
uint64_t m_diff = 0;
|
||||
uint64_t m_height = 0;
|
||||
uint64_t m_target = 0;
|
||||
|
|
|
@ -37,9 +37,10 @@ class SubmitResult
|
|||
public:
|
||||
SubmitResult() = default;
|
||||
|
||||
inline SubmitResult(int64_t seq, uint64_t diff, uint64_t actualDiff, int64_t reqId = 0) :
|
||||
inline SubmitResult(int64_t seq, uint64_t diff, uint64_t actualDiff, int64_t reqId, uint32_t backend) :
|
||||
reqId(reqId),
|
||||
seq(seq),
|
||||
backend(backend),
|
||||
actualDiff(actualDiff),
|
||||
diff(diff),
|
||||
m_start(Chrono::steadyMSecs())
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
|
||||
int64_t reqId = 0;
|
||||
int64_t seq = 0;
|
||||
uint32_t backend = 0;
|
||||
uint64_t actualDiff = 0;
|
||||
uint64_t diff = 0;
|
||||
uint64_t elapsed = 0;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace xmrig {
|
|||
class Nonce
|
||||
{
|
||||
public:
|
||||
enum Backend {
|
||||
enum Backend : uint32_t {
|
||||
CPU,
|
||||
OPENCL,
|
||||
CUDA,
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
algorithm(job.algorithm()),
|
||||
clientId(job.clientId()),
|
||||
jobId(job.id()),
|
||||
backend(job.backend()),
|
||||
nonce(nonce),
|
||||
diff(job.diff()),
|
||||
index(job.index())
|
||||
|
@ -61,9 +62,10 @@ public:
|
|||
const Algorithm algorithm;
|
||||
const String clientId;
|
||||
const String jobId;
|
||||
const uint32_t nonce = 0;
|
||||
const uint64_t diff = 0;
|
||||
const uint8_t index = 0;
|
||||
const uint32_t backend;
|
||||
const uint32_t nonce;
|
||||
const uint64_t diff;
|
||||
const uint8_t index;
|
||||
|
||||
private:
|
||||
uint8_t m_result[32] = { 0 };
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <memory>
|
||||
|
||||
|
||||
#include "backend/common/Tags.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
|
@ -55,6 +56,22 @@
|
|||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static const char *tag = BLUE_BG_BOLD(WHITE_BOLD_S " net ");
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
||||
const char *xmrig::net_tag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Network::Network(Controller *controller) :
|
||||
m_controller(controller),
|
||||
m_donate(nullptr),
|
||||
|
@ -97,19 +114,19 @@ void xmrig::Network::connect()
|
|||
void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
||||
{
|
||||
if (m_donate && m_donate == strategy) {
|
||||
LOG_NOTICE("dev donate started");
|
||||
LOG_NOTICE("%s " WHITE_BOLD("dev donate started"), tag);
|
||||
return;
|
||||
}
|
||||
|
||||
m_state.onActive(client);
|
||||
|
||||
const char *tlsVersion = client->tlsVersion();
|
||||
LOG_INFO(WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
||||
client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
|
||||
LOG_INFO("%s " WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
||||
tag, client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
|
||||
|
||||
const char *fingerprint = client->tlsFingerprint();
|
||||
if (fingerprint != nullptr) {
|
||||
LOG_INFO(BLACK_BOLD("fingerprint (SHA-256): \"%s\""), fingerprint);
|
||||
LOG_INFO("%s " BLACK_BOLD("fingerprint (SHA-256): \"%s\""), tag, fingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,12 +195,12 @@ void xmrig::Network::onLogin(IStrategy *, IClient *client, rapidjson::Document &
|
|||
void xmrig::Network::onPause(IStrategy *strategy)
|
||||
{
|
||||
if (m_donate && m_donate == strategy) {
|
||||
LOG_NOTICE("dev donate finished");
|
||||
LOG_NOTICE("%s " WHITE_BOLD("dev donate finished"), tag);
|
||||
m_strategy->resume();
|
||||
}
|
||||
|
||||
if (!m_strategy->isActive()) {
|
||||
LOG_ERR("no active pools, stop mining");
|
||||
LOG_ERR("%s " RED("no active pools, stop mining"), tag);
|
||||
m_state.stop();
|
||||
|
||||
return m_controller->miner()->pause();
|
||||
|
@ -196,12 +213,12 @@ void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult
|
|||
m_state.add(result, error);
|
||||
|
||||
if (error) {
|
||||
LOG_INFO(RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
||||
m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
|
||||
LOG_INFO("%s " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
||||
backend_tag(result.backend), m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
|
||||
}
|
||||
else {
|
||||
LOG_INFO(GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
||||
m_state.accepted, m_state.rejected, result.diff, result.elapsed);
|
||||
LOG_INFO("%s " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
||||
backend_tag(result.backend), m_state.accepted, m_state.rejected, result.diff, result.elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,12 +249,12 @@ void xmrig::Network::onRequest(IApiRequest &request)
|
|||
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
||||
{
|
||||
if (job.height()) {
|
||||
LOG_INFO(MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64),
|
||||
client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName(), job.height());
|
||||
LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64),
|
||||
tag, client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName(), job.height());
|
||||
}
|
||||
else {
|
||||
LOG_INFO(MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s"),
|
||||
client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName());
|
||||
LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s"),
|
||||
tag, client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName());
|
||||
}
|
||||
|
||||
if (!donate && m_donate) {
|
||||
|
|
Loading…
Reference in a new issue