From 2a2712ab90e10487cf7b506f7f34db5f8f3a0f5c Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 20 Nov 2018 07:24:14 +0700 Subject: [PATCH] Sync changes. --- src/common/Platform.cpp | 7 ++++--- src/common/Platform.h | 11 +++++++---- src/common/Platform_mac.cpp | 12 +++++++++++- src/common/Platform_unix.cpp | 11 +++++++++++ src/common/Platform_win.cpp | 38 ++++++++++++++++++++++++++++++++++-- src/common/net/Client.cpp | 6 ++++++ src/common/net/Id.h | 6 +++--- src/common/net/Job.cpp | 18 ++++++----------- src/common/net/Job.h | 5 +++-- src/common/utils/timestamp.h | 10 +++++++++- src/net/JobResult.h | 21 ++++++++++++++++---- src/workers/MultiWorker.cpp | 2 +- 12 files changed, 114 insertions(+), 33 deletions(-) diff --git a/src/common/Platform.cpp b/src/common/Platform.cpp index a95f78e7e..17fcc38e6 100644 --- a/src/common/Platform.cpp +++ b/src/common/Platform.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 SChernykh + * Copyright 2016-2018 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 @@ -36,7 +37,7 @@ char Platform::m_defaultConfigName[520] = { 0 }; -xmrig::c_str Platform::m_userAgent; +xmrig::String Platform::m_userAgent; const char *Platform::defaultConfigName() diff --git a/src/common/Platform.h b/src/common/Platform.h index 5dfb9ff7f..fc10e83b3 100644 --- a/src/common/Platform.h +++ b/src/common/Platform.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 SChernykh + * Copyright 2016-2018 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 @@ -28,7 +29,7 @@ #include -#include "common/utils/c_str.h" +#include "base/tools/String.h" class Platform @@ -36,7 +37,9 @@ class Platform public: static bool setThreadAffinity(uint64_t cpu_id); static const char *defaultConfigName(); + static uint32_t setTimerResolution(uint32_t resolution); static void init(const char *userAgent); + static void restoreTimerResolution(); static void setProcessPriority(int priority); static void setThreadPriority(int priority); @@ -46,7 +49,7 @@ private: static char *createUserAgent(); static char m_defaultConfigName[520]; - static xmrig::c_str m_userAgent; + static xmrig::String m_userAgent; }; diff --git a/src/common/Platform_mac.cpp b/src/common/Platform_mac.cpp index d0c533b08..b587c01ff 100644 --- a/src/common/Platform_mac.cpp +++ b/src/common/Platform_mac.cpp @@ -65,9 +65,19 @@ bool Platform::setThreadAffinity(uint64_t cpu_id) } +uint32_t Platform::setTimerResolution(uint32_t resolution) +{ + return resolution; +} + + +void Platform::restoreTimerResolution() +{ +} + + void Platform::setProcessPriority(int priority) { - } diff --git a/src/common/Platform_unix.cpp b/src/common/Platform_unix.cpp index 058920ec5..1263b8464 100644 --- a/src/common/Platform_unix.cpp +++ b/src/common/Platform_unix.cpp @@ -92,6 +92,17 @@ bool Platform::setThreadAffinity(uint64_t cpu_id) } +uint32_t Platform::setTimerResolution(uint32_t resolution) +{ + return resolution; +} + + +void Platform::restoreTimerResolution() +{ +} + + void Platform::setProcessPriority(int priority) { } diff --git a/src/common/Platform_win.cpp b/src/common/Platform_win.cpp index 32b850d14..d220f58d7 100644 --- a/src/common/Platform_win.cpp +++ b/src/common/Platform_win.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 SChernykh + * Copyright 2016-2018 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 @@ -22,6 +23,7 @@ */ +#include #include #include #include @@ -37,6 +39,9 @@ #endif +static uint32_t timerResolution = 0; + + static inline OSVERSIONINFOEX winOsVersion() { typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); @@ -94,6 +99,34 @@ bool Platform::setThreadAffinity(uint64_t cpu_id) } +uint32_t Platform::setTimerResolution(uint32_t resolution) +{ +# ifdef XMRIG_AMD_PROJECT + TIMECAPS tc; + + if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { + return 0; + } + + timerResolution = std::min(std::max(tc.wPeriodMin, resolution), tc.wPeriodMax); + + return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0; +# else + return resolution; +# endif +} + + +void Platform::restoreTimerResolution() +{ +# ifdef XMRIG_AMD_PROJECT + if (timerResolution) { + timeEndPeriod(timerResolution); + } +# endif +} + + void Platform::setProcessPriority(int priority) { if (priority == -1) { @@ -121,6 +154,7 @@ void Platform::setProcessPriority(int priority) case 5: prio = REALTIME_PRIORITY_CLASS; + break; default: break; diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 1d1d86c7f..c0ab50b1f 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -212,6 +212,10 @@ const char *Client::tlsVersion() const int64_t Client::submit(const JobResult &result) { + if (result.clientId != m_rpcId) { + return -1; + } + using namespace rapidjson; # ifdef XMRIG_PROXY_PROJECT @@ -355,6 +359,8 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } + m_job.setClientId(m_rpcId); + if (m_job != job) { m_jobs++; m_job = std::move(job); diff --git a/src/common/net/Id.h b/src/common/net/Id.h index 5fb2db521..4b13e7935 100644 --- a/src/common/net/Id.h +++ b/src/common/net/Id.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __ID_H__ -#define __ID_H__ +#ifndef XMRIG_ID_H +#define XMRIG_ID_H #include @@ -95,4 +95,4 @@ private: } /* namespace xmrig */ -#endif /* __ID_H__ */ +#endif /* XMRIG_ID_H */ diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 2bfb39f0e..6d3ee9936 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -91,6 +91,12 @@ Job::~Job() } +bool 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; +} + + bool Job::setBlob(const char *blob) { if (!blob) { @@ -214,18 +220,6 @@ char *Job::toHex(const unsigned char* in, unsigned int len) #endif -bool Job::operator==(const Job &other) const -{ - return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; -} - - -bool Job::operator!=(const Job &other) const -{ - return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0; -} - - xmrig::Variant Job::variant() const { using namespace xmrig; diff --git a/src/common/net/Job.h b/src/common/net/Job.h index b561b9c1b..51e3428eb 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -42,6 +42,7 @@ public: Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId); ~Job(); + bool isEqual(const Job &other) const; bool setBlob(const char *blob); bool setTarget(const char *target); void setAlgorithm(const char *algo); @@ -81,8 +82,8 @@ public: static char *toHex(const unsigned char* in, unsigned int len); # endif - bool operator==(const Job &other) const; - bool operator!=(const Job &other) const; + inline bool operator==(const Job &other) const { return isEqual(other); } + inline bool operator!=(const Job &other) const { return !isEqual(other); } private: xmrig::Variant variant() const; diff --git a/src/common/utils/timestamp.h b/src/common/utils/timestamp.h index 6b6a8ab24..7fc4ab503 100644 --- a/src/common/utils/timestamp.h +++ b/src/common/utils/timestamp.h @@ -31,7 +31,7 @@ namespace xmrig { -static inline int64_t currentMSecsSinceEpoch() +static inline int64_t steadyTimestamp() { using namespace std::chrono; if (high_resolution_clock::is_steady) { @@ -42,6 +42,14 @@ static inline int64_t currentMSecsSinceEpoch() } +static inline int64_t currentMSecsSinceEpoch() +{ + using namespace std::chrono; + + return time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); +} + + } /* namespace xmrig */ #endif /* XMRIG_TIMESTAMP_H */ diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 4a920ca08..071cbb8b1 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __JOBRESULT_H__ -#define __JOBRESULT_H__ +#ifndef XMRIG_JOBRESULT_H +#define XMRIG_JOBRESULT_H #include @@ -36,17 +36,29 @@ class JobResult { public: inline JobResult() : poolId(0), diff(0), nonce(0) {} - inline JobResult(int poolId, const xmrig::Id &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) : + inline JobResult(int poolId, const xmrig::Id &jobId, const xmrig::Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) : poolId(poolId), diff(diff), nonce(nonce), algorithm(algorithm), + clientId(clientId), jobId(jobId) { memcpy(this->result, result, sizeof(this->result)); } + inline JobResult(const Job &job) : poolId(0), diff(0), nonce(0) + { + jobId = job.id(); + clientId = job.clientId(); + poolId = job.poolId(); + diff = job.diff(); + nonce = *job.nonce(); + algorithm = job.algorithm(); + } + + inline uint64_t actualDiff() const { return Job::toDiff(reinterpret_cast(result)[3]); @@ -58,7 +70,8 @@ public: uint32_t nonce; uint8_t result[32]; xmrig::Algorithm algorithm; + xmrig::Id clientId; xmrig::Id jobId; }; -#endif /* __JOBRESULT_H__ */ +#endif /* XMRIG_JOBRESULT_H */ diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index a6dbc73ac..645259b63 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -108,7 +108,7 @@ void MultiWorker::start() for (size_t i = 0; i < N; ++i) { if (*reinterpret_cast(m_hash + (i * 32) + 24) < m_state.job.target()) { - Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); + Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); } *nonce(i) += 1;