From b383a382ebe6f7f3fc519b87f6234480241dc0ee Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 7 May 2018 02:37:23 +0700 Subject: [PATCH 01/22] Update README.md --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d69e5ec5e..8f1540a41 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # XMRig -:warning: **You must update miners to version 2.5 before April 6 due [Monero PoW change](https://getmonero.org/2018/02/11/PoW-change-and-key-reuse.html).** - [![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/xmrig/xmrig/releases) [![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/xmrig/xmrig/releases) [![GitHub Release Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/releases) @@ -124,10 +122,10 @@ Please note performance is highly dependent on system load. The numbers above ar ## Release checksums ### SHA-256 ``` -f8e1957e8bfd7f281a76d1e42694049c67f39dea90ac36e9d589c14cdf8924bc xmrig-2.6.1-xenial-amd64.tar.gz/xmrig-2.6.1/xmrig -472c7aaf5aacc1212bfd3f2f96daca4f42d64e2d0db0872891328e7d8503d0c8 xmrig-2.6.1-gcc-win32.zip/xmrig.exe -d53154cef24c884b2be539ac13bfb6e7dba6bbc53b62e91f2877637d43fa4b15 xmrig-2.6.1-gcc-win64.zip/xmrig.exe -a253381b617463e6e1193d49b8afbf720a1c376621da7429d97f192668cd59ad xmrig-2.6.1-msvc-win64.zip/xmrig.exe +ca60d04204aa3195e8cd72887c7deced1a7c664e538256f138b5698d381ceb00 xmrig-2.6.2-xenial-amd64.tar.gz/xmrig-2.6.2/xmrig +49dc64eeecdbfffb452ad3cd7a0118d8640208b0b898b2901464d0be6183c169 xmrig-2.6.2-gcc-win32.zip/xmrig.exe +56141544ac6d03565909b3043fab104bf40cadb32d53a12d821e1328bc50f087 xmrig-2.6.2-gcc-win64.zip/xmrig.exe +24661a8807f4b991c79e587e846aaea589720ed84d79afb41d14709a6fb908ce xmrig-2.6.2-msvc-win64.zip/xmrig.exe ``` ## Contacts From 0086020b5c6c0199e88edd06df42af5743bbff20 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 19 May 2018 11:48:15 +0700 Subject: [PATCH 02/22] Optimize logs architecture. --- src/common/log/ConsoleLog.cpp | 35 +++++------------------------------ src/common/log/ConsoleLog.h | 2 +- src/common/log/FileLog.cpp | 8 ++++---- src/common/log/FileLog.h | 6 +++--- src/common/log/Log.cpp | 31 ++++++++++++++++++++++++++++++- src/common/log/Log.h | 29 ++++++++++++----------------- src/common/log/SysLog.cpp | 6 +++--- src/common/log/SysLog.h | 6 +++--- src/interfaces/ILogBackend.h | 16 ++++++++++++---- 9 files changed, 73 insertions(+), 66 deletions(-) diff --git a/src/common/log/ConsoleLog.cpp b/src/common/log/ConsoleLog.cpp index b7d187d12..a1b6648dc 100644 --- a/src/common/log/ConsoleLog.cpp +++ b/src/common/log/ConsoleLog.cpp @@ -66,7 +66,7 @@ ConsoleLog::ConsoleLog(xmrig::Controller *controller) : } -void ConsoleLog::message(int level, const char* fmt, va_list args) +void ConsoleLog::message(Level level, const char* fmt, va_list args) { time_t now = time(nullptr); tm stime; @@ -77,43 +77,18 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) localtime_r(&now, &stime); # endif - const char* color = nullptr; - const bool colors = m_controller->config()->isColors(); + const bool isColors = m_controller->config()->isColors(); - if (colors) { - switch (level) { - case Log::ERR: - color = Log::kCL_RED; - break; - - case Log::WARNING: - color = Log::kCL_YELLOW; - break; - - case Log::NOTICE: - color = Log::kCL_WHITE; - break; - - case Log::DEBUG: - color = Log::kCL_GRAY; - break; - - default: - color = ""; - break; - } - } - - snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n", + snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", stime.tm_year + 1900, stime.tm_mon + 1, stime.tm_mday, stime.tm_hour, stime.tm_min, stime.tm_sec, - colors ? color : "", + Log::colorByLevel(level, isColors), fmt, - colors ? Log::kCL_N : "" + Log::endl(isColors) ); print(args); diff --git a/src/common/log/ConsoleLog.h b/src/common/log/ConsoleLog.h index 6649be841..a3b0a33a8 100644 --- a/src/common/log/ConsoleLog.h +++ b/src/common/log/ConsoleLog.h @@ -41,7 +41,7 @@ class ConsoleLog : public ILogBackend public: ConsoleLog(xmrig::Controller *controller); - void message(int level, const char *fmt, va_list args) override; + void message(Level level, const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override; private: diff --git a/src/common/log/FileLog.cpp b/src/common/log/FileLog.cpp index cc7188cbd..367f0f687 100644 --- a/src/common/log/FileLog.cpp +++ b/src/common/log/FileLog.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * 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 @@ -40,7 +40,7 @@ FileLog::FileLog(const char *fileName) } -void FileLog::message(int level, const char* fmt, va_list args) +void FileLog::message(Level level, const char* fmt, va_list args) { if (m_file < 0) { return; @@ -73,7 +73,7 @@ void FileLog::message(int level, const char* fmt, va_list args) void FileLog::text(const char* fmt, va_list args) { - message(0, fmt, args); + message(INFO, fmt, args); } diff --git a/src/common/log/FileLog.h b/src/common/log/FileLog.h index 2b3ca5d4b..545056bb6 100644 --- a/src/common/log/FileLog.h +++ b/src/common/log/FileLog.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * 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 +36,7 @@ class FileLog : public ILogBackend public: FileLog(const char *fileName); - void message(int level, const char* fmt, va_list args) override; + void message(Level level, const char* fmt, va_list args) override; void text(const char* fmt, va_list args) override; private: diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index 03237f03a..6144e4f17 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -36,7 +36,16 @@ Log *Log::m_self = nullptr; -void Log::message(Log::Level level, const char* fmt, ...) +static const char *colors[5] = { + Log::kCL_RED, /* ERR */ + Log::kCL_YELLOW, /* WARNING */ + Log::kCL_WHITE, /* NOTICE */ + "", /* INFO */ + Log::kCL_GRAY /* DEBUG */ +}; + + +void Log::message(ILogBackend::Level level, const char* fmt, ...) { uv_mutex_lock(&m_mutex); @@ -76,6 +85,26 @@ void Log::text(const char* fmt, ...) } +const char *Log::colorByLevel(ILogBackend::Level level, bool isColors) +{ + if (!isColors) { + return ""; + } + + return colors[level]; +} + + +const char *Log::endl(bool isColors) +{ +# ifdef _WIN32 + return isColors ? "\x1B[0m\r\n" : "\r\n"; +# else + return isColors ? "\x1B[0m\n" : "\n"; +# endif +} + + Log::~Log() { for (auto backend : m_backends) { diff --git a/src/common/log/Log.h b/src/common/log/Log.h index 31600dc68..6d4959efc 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -30,20 +30,12 @@ #include -class ILogBackend; +#include "interfaces/ILogBackend.h" class Log { public: - enum Level { - ERR, - WARNING, - NOTICE, - INFO, - DEBUG - }; - constexpr static const char* kCL_N = "\x1B[0m"; constexpr static const char* kCL_RED = "\x1B[31m"; constexpr static const char* kCL_YELLOW = "\x1B[33m"; @@ -60,9 +52,12 @@ public: static inline void init() { if (!m_self) { new Log(); } } static inline void release() { assert(m_self != nullptr); delete m_self; } - void message(Level level, const char* fmt, ...); + void message(ILogBackend::Level level, const char* fmt, ...); void text(const char* fmt, ...); + static const char *colorByLevel(ILogBackend::Level level, bool isColors = true); + static const char *endl(bool isColors = true); + private: inline Log() { assert(m_self == nullptr); @@ -92,20 +87,20 @@ private: #define WHITE(x) "\x1B[0;37m" x "\x1B[0m" -#define LOG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) Log::i()->message(Log::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) Log::i()->message(Log::INFO, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__) +#define LOG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__) +#define LOG_NOTICE(x, ...) Log::i()->message(ILogBackend::NOTICE, x, ##__VA_ARGS__) +#define LOG_INFO(x, ...) Log::i()->message(ILogBackend::INFO, x, ##__VA_ARGS__) #ifdef APP_DEBUG -# define LOG_DEBUG(x, ...) Log::i()->message(Log::DEBUG, x, ##__VA_ARGS__) +# define LOG_DEBUG(x, ...) Log::i()->message(ILogBackend::DEBUG, x, ##__VA_ARGS__) #else # define LOG_DEBUG(x, ...) #endif #if defined(APP_DEBUG) || defined(APP_DEVEL) -# define LOG_DEBUG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) -# define LOG_DEBUG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) +# define LOG_DEBUG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__) +# define LOG_DEBUG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__) #else # define LOG_DEBUG_ERR(x, ...) # define LOG_DEBUG_WARN(x, ...) diff --git a/src/common/log/SysLog.cpp b/src/common/log/SysLog.cpp index 70879c33b..5eb4dcd45 100644 --- a/src/common/log/SysLog.cpp +++ b/src/common/log/SysLog.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * 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 @@ -35,7 +35,7 @@ SysLog::SysLog() } -void SysLog::message(int level, const char *fmt, va_list args) +void SysLog::message(Level level, const char *fmt, va_list args) { vsyslog(level, fmt, args); } diff --git a/src/common/log/SysLog.h b/src/common/log/SysLog.h index 38de1a6a5..1e49a48bb 100644 --- a/src/common/log/SysLog.h +++ b/src/common/log/SysLog.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * 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 @@ -33,7 +33,7 @@ class SysLog : public ILogBackend public: SysLog(); - void message(int level, const char *fmt, va_list args) override; + void message(Level level, const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override; }; diff --git a/src/interfaces/ILogBackend.h b/src/interfaces/ILogBackend.h index 458b504c4..b6db72a89 100644 --- a/src/interfaces/ILogBackend.h +++ b/src/interfaces/ILogBackend.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * 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 @@ -31,10 +31,18 @@ class ILogBackend { public: + enum Level { + ERR, + WARNING, + NOTICE, + INFO, + DEBUG + }; + virtual ~ILogBackend() {} - virtual void message(int level, const char* fmt, va_list args) = 0; - virtual void text(const char* fmt, va_list args) = 0; + virtual void message(Level level, const char* fmt, va_list args) = 0; + virtual void text(const char* fmt, va_list args) = 0; }; From 5019493332ae66adbc616f99fc85ef32938aa1e2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 19 May 2018 13:06:49 +0700 Subject: [PATCH 03/22] Correctly reset colors in FileLog. --- src/common/log/ConsoleLog.cpp | 2 +- src/common/log/ConsoleLog.h | 2 +- src/common/log/FileLog.cpp | 34 +++++++++++++++++++++------------- src/common/log/FileLog.h | 9 ++++++++- src/common/log/Log.cpp | 14 +++++++++----- src/common/log/Log.h | 11 ----------- src/common/log/SysLog.cpp | 4 ++-- src/core/Controller.cpp | 2 +- src/interfaces/ILogBackend.h | 2 ++ 9 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/common/log/ConsoleLog.cpp b/src/common/log/ConsoleLog.cpp index a1b6648dc..6cf61980b 100644 --- a/src/common/log/ConsoleLog.cpp +++ b/src/common/log/ConsoleLog.cpp @@ -97,7 +97,7 @@ void ConsoleLog::message(Level level, const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args) { - snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_controller->config()->isColors() ? Log::kCL_N : ""); + snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(m_controller->config()->isColors())); print(args); } diff --git a/src/common/log/ConsoleLog.h b/src/common/log/ConsoleLog.h index a3b0a33a8..81813c816 100644 --- a/src/common/log/ConsoleLog.h +++ b/src/common/log/ConsoleLog.h @@ -48,7 +48,7 @@ private: bool isWritable() const; void print(va_list args); - char m_buf[512]; + char m_buf[kBufferSize]; char m_fmt[256]; uv_buf_t m_uvBuf; uv_stream_t *m_stream; diff --git a/src/common/log/FileLog.cpp b/src/common/log/FileLog.cpp index 367f0f687..9134c7c75 100644 --- a/src/common/log/FileLog.cpp +++ b/src/common/log/FileLog.cpp @@ -30,9 +30,13 @@ #include "common/log/FileLog.h" +#include "common/log/Log.h" +#include "core/Config.h" +#include "core/Controller.h" -FileLog::FileLog(const char *fileName) +FileLog::FileLog(xmrig::Controller *controller, const char *fileName) : + m_controller(controller) { uv_fs_t req; m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr); @@ -55,19 +59,24 @@ void FileLog::message(Level level, const char* fmt, va_list args) localtime_r(&now, &stime); # endif - char *buf = new char[512]; - int size = snprintf(buf, 23, "[%d-%02d-%02d %02d:%02d:%02d] ", - stime.tm_year + 1900, - stime.tm_mon + 1, - stime.tm_mday, - stime.tm_hour, - stime.tm_min, - stime.tm_sec); + const bool isColors = m_controller->config()->isColors(); - size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size; - buf[size] = '\n'; + snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", + stime.tm_year + 1900, + stime.tm_mon + 1, + stime.tm_mday, + stime.tm_hour, + stime.tm_min, + stime.tm_sec, + Log::colorByLevel(level, isColors), + fmt, + Log::endl(isColors) + ); - write(buf, size + 1); + char *buf = new char[kBufferSize]; + const int size = vsnprintf(buf, kBufferSize - 1, m_fmt, args); + + write(buf, size); } @@ -77,7 +86,6 @@ void FileLog::text(const char* fmt, va_list args) } - void FileLog::onWrite(uv_fs_t *req) { delete [] static_cast(req->data); diff --git a/src/common/log/FileLog.h b/src/common/log/FileLog.h index 545056bb6..2c25f0932 100644 --- a/src/common/log/FileLog.h +++ b/src/common/log/FileLog.h @@ -31,10 +31,15 @@ #include "interfaces/ILogBackend.h" +namespace xmrig { + class Controller; +} + + class FileLog : public ILogBackend { public: - FileLog(const char *fileName); + FileLog(xmrig::Controller *controller, const char *fileName); void message(Level level, const char* fmt, va_list args) override; void text(const char* fmt, va_list args) override; @@ -44,7 +49,9 @@ private: void write(char *data, size_t size); + char m_fmt[256]; int m_file; + xmrig::Controller *m_controller; }; #endif /* __FILELOG_H__ */ diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index 6144e4f17..763eb25b0 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -37,11 +37,15 @@ Log *Log::m_self = nullptr; static const char *colors[5] = { - Log::kCL_RED, /* ERR */ - Log::kCL_YELLOW, /* WARNING */ - Log::kCL_WHITE, /* NOTICE */ - "", /* INFO */ - Log::kCL_GRAY /* DEBUG */ + "\x1B[0;31m", /* ERR */ + "\x1B[0;33m", /* WARNING */ + "\x1B[1;37m", /* NOTICE */ + "", /* INFO */ +# ifdef WIN32 + "\x1B[1;30m" /* DEBUG */ +# else + "\x1B[90m" /* DEBUG */ +# endif }; diff --git a/src/common/log/Log.h b/src/common/log/Log.h index 6d4959efc..c4803e3a0 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -36,17 +36,6 @@ class Log { public: - constexpr static const char* kCL_N = "\x1B[0m"; - constexpr static const char* kCL_RED = "\x1B[31m"; - constexpr static const char* kCL_YELLOW = "\x1B[33m"; - constexpr static const char* kCL_WHITE = "\x1B[01;37m"; - -# ifdef WIN32 - constexpr static const char* kCL_GRAY = "\x1B[01;30m"; -# else - constexpr static const char* kCL_GRAY = "\x1B[90m"; -# endif - static inline Log* i() { assert(m_self != nullptr); return m_self; } static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); } static inline void init() { if (!m_self) { new Log(); } } diff --git a/src/common/log/SysLog.cpp b/src/common/log/SysLog.cpp index 5eb4dcd45..bcb963943 100644 --- a/src/common/log/SysLog.cpp +++ b/src/common/log/SysLog.cpp @@ -37,11 +37,11 @@ SysLog::SysLog() void SysLog::message(Level level, const char *fmt, va_list args) { - vsyslog(level, fmt, args); + vsyslog(static_cast(level), fmt, args); } void SysLog::text(const char *fmt, va_list args) { - message(LOG_INFO, fmt, args); + vsyslog(LOG_INFO, fmt, args); } diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index b1e03f32e..ac64f173b 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -110,7 +110,7 @@ int xmrig::Controller::init(int argc, char **argv) } if (config()->logFile()) { - Log::add(new FileLog(config()->logFile())); + Log::add(new FileLog(this, config()->logFile())); } # ifdef HAVE_SYSLOG_H diff --git a/src/interfaces/ILogBackend.h b/src/interfaces/ILogBackend.h index b6db72a89..305549054 100644 --- a/src/interfaces/ILogBackend.h +++ b/src/interfaces/ILogBackend.h @@ -39,6 +39,8 @@ public: DEBUG }; + constexpr static const size_t kBufferSize = 512; + virtual ~ILogBackend() {} virtual void message(Level level, const char* fmt, va_list args) = 0; From 2b3f7f43ceb22a18316d424d31eca949743faf0c Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 19 May 2018 13:47:27 +0700 Subject: [PATCH 04/22] Fix Linux build. --- src/interfaces/ILogBackend.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interfaces/ILogBackend.h b/src/interfaces/ILogBackend.h index 305549054..6e3f5c1c0 100644 --- a/src/interfaces/ILogBackend.h +++ b/src/interfaces/ILogBackend.h @@ -26,6 +26,7 @@ #include +#include class ILogBackend From 14f0e8658c91c27d63115f5f378d8fe562478002 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 19 May 2018 14:44:50 +0700 Subject: [PATCH 05/22] Sync changes with proxy. --- src/common/net/Client.h | 22 ++++++++++++---------- src/common/net/Pool.cpp | 35 +++++++++++++++++++++++++---------- src/common/net/Pool.h | 2 ++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 27273092c..4be8badba 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -30,6 +30,7 @@ #include +#include "common/crypto/Algorithm.h" #include "common/net/Id.h" #include "common/net/Job.h" #include "common/net/Pool.h" @@ -66,16 +67,17 @@ public: void setPool(const Pool &pool); void tick(uint64_t now); - inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } - inline const char *host() const { return m_pool.host(); } - inline const char *ip() const { return m_ip; } - inline const Job &job() const { return m_job; } - inline int id() const { return m_id; } - inline SocketState state() const { return m_state; } - inline uint16_t port() const { return m_pool.port(); } - inline void setQuiet(bool quiet) { m_quiet = quiet; } - inline void setRetries(int retries) { m_retries = retries; } - inline void setRetryPause(int ms) { m_retryPause = ms; } + inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } + inline const char *host() const { return m_pool.host(); } + inline const char *ip() const { return m_ip; } + inline const Job &job() const { return m_job; } + inline int id() const { return m_id; } + inline SocketState state() const { return m_state; } + inline uint16_t port() const { return m_pool.port(); } + inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); } + inline void setQuiet(bool quiet) { m_quiet = quiet; } + inline void setRetries(int retries) { m_retries = retries; } + inline void setRetryPause(int ms) { m_retryPause = ms; } private: enum Extensions { diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index ca73b3158..c12e05d55 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -247,17 +247,15 @@ void Pool::adjust(xmrig::Algo algorithm) m_algorithm.setVariant(xmrig::VARIANT_1); } - m_algorithms.push_back(m_algorithm); + rebuild(); +} -# ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_IPBC); - addVariant(xmrig::VARIANT_AUTO); - } -# endif + +void Pool::setAlgo(const xmrig::Algorithm &algorithm) +{ + m_algorithm = algorithm; + + rebuild(); } @@ -309,3 +307,20 @@ void Pool::addVariant(xmrig::Variant variant) m_algorithms.push_back(algorithm); } + + +void Pool::rebuild() +{ + m_algorithms.clear(); + m_algorithms.push_back(m_algorithm); + +# ifndef XMRIG_PROXY_PROJECT + if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { + addVariant(xmrig::VARIANT_1); + addVariant(xmrig::VARIANT_0); + addVariant(xmrig::VARIANT_XTL); + addVariant(xmrig::VARIANT_IPBC); + addVariant(xmrig::VARIANT_AUTO); + } +# endif +} diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index ad015bf2c..eaabe54d3 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -78,6 +78,7 @@ public: bool setUserpass(const char *userpass); rapidjson::Value toJSON(rapidjson::Document &doc) const; void adjust(xmrig::Algo algorithm); + void setAlgo(const xmrig::Algorithm &algorithm); # ifdef APP_DEBUG void print() const; @@ -86,6 +87,7 @@ public: private: bool parseIPv6(const char *addr); void addVariant(xmrig::Variant variant); + void rebuild(); bool m_nicehash; int m_keepAlive; From 34a3454784662bc8257c31da058a355ea5102d61 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 20 May 2018 14:27:46 +0700 Subject: [PATCH 06/22] Small fix in CMakeLists.txt. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b26b1d93a..c71309c35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ set(HEADERS src/common/utils/c_str.h src/common/utils/mm_malloc.h src/common/xmrig.h - src/core/Config.cpp src/core/ConfigLoader_platform.h src/core/Controller.h src/Cpu.h From 009bd1a5073cec9073e9da67d95f4bb6064b3aa1 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Jun 2018 01:48:31 +0700 Subject: [PATCH 07/22] Sync changes with amd miner and update summary. --- CMakeLists.txt | 5 +-- src/Summary.cpp | 65 +++++++++++++++------------- src/common/config/CommonConfig.cpp | 68 +++++++++++++++--------------- src/common/config/CommonConfig.h | 3 +- src/common/xmrig.h | 6 +++ src/core/Config.cpp | 2 +- src/workers/Hashrate.cpp | 16 +++++-- src/workers/Hashrate.h | 6 ++- 8 files changed, 97 insertions(+), 74 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c71309c35..a242970bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project(xmrig) option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON) -option(WITH_IPBC "CryptoNight-IPBC support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(BUILD_STATIC "Build static binary" OFF) @@ -245,5 +244,5 @@ if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") endif() -add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) -target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) +add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) +target_link_libraries(${PROJECT_NAME} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/src/Summary.cpp b/src/Summary.cpp index e960dd8de..fe538fda6 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -39,7 +39,7 @@ static void print_versions(xmrig::Config *config) { - char buf[16]; + char buf[16] = { 0 }; # if defined(__clang__) snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); @@ -47,24 +47,22 @@ static void print_versions(xmrig::Config *config) snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # elif defined(_MSC_VER) snprintf(buf, 16, " MSVC/%d", MSVC_VERSION); -# else - buf[0] = '\0'; # endif - - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s", - APP_VERSION, uv_version_string(), buf); + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" libuv/%s%s") + : " * %-13s%s/%s libuv/%s%s", + "VERSIONS", APP_NAME, APP_VERSION, uv_version_string(), buf); } static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s", - Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable"); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", + "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); } else { - Log::i()->text(" * HUGE PAGES: %s", Mem::isHugepagesAvailable() ? "available" : "unavailable"); + Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); } # endif } @@ -73,19 +71,20 @@ static void print_memory(xmrig::Config *config) { static void print_cpu(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s (%d) %sx64 %sAES-NI", + "CPU", Cpu::brand(), Cpu::sockets(), - Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", - Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); + Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", + Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } else { - Log::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * %-13s%s (%d) %sx64 %sAES-NI", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } } @@ -94,27 +93,28 @@ static void print_cpu(xmrig::Config *config) static void print_threads(xmrig::Config *config) { if (config->threadsMode() != xmrig::Config::Advanced) { - char buf[32]; + char buf[32] = { 0 }; if (config->affinity() != -1L) { - snprintf(buf, 32, ", affinity=0x%" PRIX64, config->affinity()); - } - else { - buf[0] = '\0'; + snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); } - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") + : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", + "THREADS", config->threadsCount(), config->algorithm().name(), config->algoVariant(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", + config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel(), buf); } else { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, %sdonate=%d%%" : " * THREADS: %d, %s, %sdonate=%d%%", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") + : " * %-13s%d, %s, %sdonate=%d%%", + "THREADS", config->threadsCount(), config->algorithm().name(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", + config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel()); } } @@ -125,9 +125,11 @@ static void print_pools(xmrig::Config *config) const std::vector &pools = config->pools(); for (size_t i = 0; i < pools.size(); ++i) { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s" : " * POOL #%d: %s", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") CYAN_BOLD("%s") " variant " WHITE_BOLD("%s") + : " * POOL #%-7d%s variant %s", i + 1, - pools[i].url() + pools[i].url(), + pools[i].algorithm().variantName() ); } @@ -147,8 +149,9 @@ static void print_api(xmrig::Config *config) return; } - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mAPI BIND: \x1B[01;36m%s:%d" : " * API BIND: %s:%d", - config->isApiIPv6() ? "[::]" : "0.0.0.0", port); + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") + : " * %-13s%s:%d", + "API BIND", config->isApiIPv6() ? "[::]" : "0.0.0.0", port); } #endif @@ -156,10 +159,12 @@ static void print_api(xmrig::Config *config) static void print_commands(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume"); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") + MAGENTA_BOLD("p") WHITE_BOLD("ause, ") + MAGENTA_BOLD("r") WHITE_BOLD("esume")); } else { - Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume"); + Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); } } diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 5eaf68fd9..155485d23 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -72,6 +72,40 @@ xmrig::CommonConfig::~CommonConfig() } +bool xmrig::CommonConfig::save() +{ + if (m_fileName.isNull()) { + return false; + } + + uv_fs_t req; + const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); + if (fd < 0) { + return false; + } + + uv_fs_req_cleanup(&req); + + rapidjson::Document doc; + getJSON(doc); + + FILE *fp = fdopen(fd, "w"); + + char buf[4096]; + rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); + rapidjson::PrettyWriter writer(os); + doc.Accept(writer); + + fclose(fp); + + uv_fs_close(uv_default_loop(), &req, fd, nullptr); + uv_fs_req_cleanup(&req); + + LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); + return true; +} + + bool xmrig::CommonConfig::finalize() { if (m_state == ReadyState) { @@ -254,40 +288,6 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) } -bool xmrig::CommonConfig::save() -{ - if (m_fileName.isNull()) { - return false; - } - - uv_fs_t req; - const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); - if (fd < 0) { - return false; - } - - uv_fs_req_cleanup(&req); - - rapidjson::Document doc; - getJSON(doc); - - FILE *fp = fdopen(fd, "w"); - - char buf[4096]; - rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); - rapidjson::PrettyWriter writer(os); - doc.Accept(writer); - - fclose(fp); - - uv_fs_close(uv_default_loop(), &req, fd, nullptr); - uv_fs_req_cleanup(&req); - - LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); - return true; -} - - void xmrig::CommonConfig::setFileName(const char *fileName) { m_fileName = fileName; diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index d54afe3a1..356f550de 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -64,6 +64,8 @@ public: inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const char *fileName() const override { return m_fileName.data(); } + bool save() override; + protected: enum State { NoneState, @@ -75,7 +77,6 @@ protected: bool parseBoolean(int key, bool enable) override; bool parseString(int key, const char *arg) override; bool parseUint64(int key, uint64_t arg) override; - bool save() override; void setFileName(const char *fileName) override; Algorithm m_algorithm; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index a6fda9fc0..43a2a2525 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -66,6 +66,12 @@ enum Variant { }; +enum AlgoVerify { + VERIFY_HW_AES = 1, + VERIFY_SOFT_AES = 2 +}; + + enum AesMode { AES_AUTO, AES_HW, diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 4c2831643..232e70240 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -116,7 +116,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const Value threads(kArrayType); for (const IThread *thread : m_threads.list) { - threads.PushBack(thread->toConfig(doc), doc.GetAllocator()); + threads.PushBack(thread->toConfig(doc), allocator); } doc.AddMember("threads", threads, allocator); diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 42068eb72..2a7503180 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -35,7 +35,7 @@ #include "workers/Hashrate.h" -inline const char *format(double h, char* buf, size_t size) +inline static const char *format(double h, char *buf, size_t size) { if (isnormal(h)) { snprintf(buf, size, "%03.1f", h); @@ -91,6 +91,9 @@ double Hashrate::calc(size_t ms) const double Hashrate::calc(size_t threadId, size_t ms) const { assert(threadId < m_threads); + if (threadId >= m_threads) { + return nan(""); + } using namespace std::chrono; const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); @@ -149,14 +152,15 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) } -void Hashrate::print() +void Hashrate::print() const { char num1[8] = { 0 }; char num2[8] = { 0 }; char num3[8] = { 0 }; char num4[8] = { 0 }; - LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s max: %s H/s", + LOG_INFO(m_controller->config()->isColors() ? WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s") + : "speed 10s/60s/15m %s %s %s H/s max %s H/s", format(calc(ShortInterval), num1, sizeof(num1)), format(calc(MediumInterval), num2, sizeof(num2)), format(calc(LargeInterval), num3, sizeof(num3)), @@ -180,6 +184,12 @@ void Hashrate::updateHighest() } +const char *Hashrate::format(double h, char *buf, size_t size) +{ + return ::format(h, buf, size); +} + + void Hashrate::onReport(uv_timer_t *handle) { static_cast(handle->data)->print(); diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index e79c757a4..e766f1170 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -38,7 +38,7 @@ class Hashrate { public: enum Intervals { - ShortInterval = 2500, + ShortInterval = 10000, MediumInterval = 60000, LargeInterval = 900000 }; @@ -47,13 +47,15 @@ public: double calc(size_t ms) const; double calc(size_t threadId, size_t ms) const; void add(size_t threadId, uint64_t count, uint64_t timestamp); - void print(); + void print() const; void stop(); void updateHighest(); inline double highest() const { return m_highest; } inline size_t threads() const { return m_threads; } + static const char *format(double h, char *buf, size_t size); + private: static void onReport(uv_timer_t *handle); From 5d6a622b1813187ebdb96dc1338b88d602611a27 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Jun 2018 02:33:21 +0700 Subject: [PATCH 08/22] New detailed hashrate report. --- src/workers/Workers.cpp | 31 +++++++++++++++++++++++++++++++ src/workers/Workers.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index f6ec04b7d..0e75e7361 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -22,6 +22,7 @@ */ #include +#include #include @@ -55,6 +56,7 @@ uv_async_t Workers::m_async; uv_mutex_t Workers::m_mutex; uv_rwlock_t Workers::m_rwlock; uv_timer_t Workers::m_timer; +xmrig::Controller *Workers::m_controller = nullptr; Job Workers::job() @@ -89,6 +91,33 @@ size_t Workers::threads() void Workers::printHashrate(bool detail) { + assert(m_controller != nullptr); + if (!m_controller) { + return; + } + + if (detail) { + const bool isColors = m_controller->config()->isColors(); + char num1[8] = { 0 }; + char num2[8] = { 0 }; + char num3[8] = { 0 }; + + Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); + + size_t i = 0; + for (const xmrig::IThread *thread : m_controller->config()->threads()) { + Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", + thread->index(), + thread->affinity(), + Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1), + Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::MediumInterval), num2, sizeof num2), + Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::LargeInterval), num3, sizeof num3) + ); + + i++; + } + } + m_hashrate->print(); } @@ -131,6 +160,8 @@ void Workers::setJob(const Job &job, bool donate) void Workers::start(xmrig::Controller *controller) { + m_controller = controller; + const std::vector &threads = controller->config()->threads(); m_status.algo = controller->config()->algorithm().algo(); m_status.colors = controller->config()->isColors(); diff --git a/src/workers/Workers.h b/src/workers/Workers.h index ca01e6985..1d619ceac 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -114,6 +114,7 @@ private: static uv_mutex_t m_mutex; static uv_rwlock_t m_rwlock; static uv_timer_t m_timer; + static xmrig::Controller *m_controller; }; From d900a6d9dd091008b0366fb73a01aac6d910168f Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 2 Jun 2018 04:37:12 +0700 Subject: [PATCH 09/22] #446 Fixed SIGBUS error on 32 bit ARM CPUs. --- src/crypto/CryptoNight_monero.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index ea1622ab9..942940a46 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -38,8 +38,9 @@ # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ if (VARIANT > 0) { \ - volatile const uint64_t a = *reinterpret_cast(input + 35 + part * size); \ - volatile const uint64_t b = *(reinterpret_cast(ctx[part]->state) + 24); \ + uint64_t a, b; \ + memcpy(&a, input + 35 + part * size, sizeof a); \ + memcpy(&b, ctx[part]->state + 192, sizeof b); \ tweak1_2_##part = a ^ b; \ } #endif From 26ee5028e114afa7f4f6b6173dfcd9f7f10935ac Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 00:09:59 +0700 Subject: [PATCH 10/22] Use native checks instead of XMRIG_ARMv8. --- src/Cpu_arm.cpp | 5 ++++- src/crypto/CryptoNight_arm.h | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Cpu_arm.cpp b/src/Cpu_arm.cpp index 59ff84217..3e259d0d8 100644 --- a/src/Cpu_arm.cpp +++ b/src/Cpu_arm.cpp @@ -47,8 +47,11 @@ void Cpu::initCommon() { memcpy(m_brand, "Unknown", 7); -# if defined(XMRIG_ARMv8) +# if defined (__arm64__) || defined (__aarch64__) m_flags |= X86_64; +# endif + +# if __ARM_FEATURE_CRYPTO m_flags |= AES; # endif } diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 284b1f5fd..161a095ff 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -73,7 +73,7 @@ static inline __attribute__((always_inline)) __m128i _mm_set_epi64x(const uint64 } -#ifdef XMRIG_ARMv8 +#if __ARM_FEATURE_CRYPTO static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey) { alignas(16) const __m128i zero = { 0 }; @@ -82,6 +82,8 @@ static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, #else static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey) { + alignas(16) const __m128i zero = { 0 }; + return zero; } #endif @@ -96,7 +98,7 @@ static inline __attribute__((always_inline)) uint64_t _mm_cvtsi128_si64(__m128i #define EXTRACT64(X) _mm_cvtsi128_si64(X) -#if defined(XMRIG_ARMv8) +#if defined (__arm64__) || defined (__aarch64__) static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) { unsigned __int128 r = (unsigned __int128) a * (unsigned __int128) b; From 651637d6377a25f2c9b47c48085bad0d3c598d61 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 00:22:26 +0700 Subject: [PATCH 11/22] #446 Better fix, second variable always aligned. --- src/crypto/CryptoNight_monero.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 942940a46..28572d88c 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -38,10 +38,8 @@ # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ if (VARIANT > 0) { \ - uint64_t a, b; \ - memcpy(&a, input + 35 + part * size, sizeof a); \ - memcpy(&b, ctx[part]->state + 192, sizeof b); \ - tweak1_2_##part = a ^ b; \ + memcpy(&tweak1_2_##part, input + 35 + part * size, sizeof tweak1_2_##part); \ + tweak1_2_##part ^= *(reinterpret_cast(ctx[part]->state) + 24); \ } #endif From 6cf24936dfab31e5c4ba580277dae0542464927a Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 02:56:49 +0700 Subject: [PATCH 12/22] #551 Fixed cn-heavy for ARMv8. --- src/crypto/CryptoNight_arm.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 161a095ff..8c59f5968 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -472,9 +472,10 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; - int64_t q = n / (d | 0x5); + const int64x2_t x = vld1q_s64(reinterpret_cast(&l0[idx0 & MASK])); + const int64_t n = vgetq_lane_s64(x, 0); + const int32_t d = vgetq_lane_s32(x, 2); + const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; idx0 = d ^ q; From 1748a7bd5730561ecf917ee4d2fa363a46a662ea Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 05:42:10 +0700 Subject: [PATCH 13/22] Fix double hash mode too. --- src/crypto/CryptoNight_arm.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 8c59f5968..fd5bcb7bc 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -580,10 +580,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ah0 ^= ch; idx0 = al0; - if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; - int64_t q = n / (d | 0x5); + if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { + const int64x2_t x = vld1q_s64(reinterpret_cast(&l0[idx0 & MASK])); + const int64_t n = vgetq_lane_s64(x, 0); + const int32_t d = vgetq_lane_s32(x, 2); + const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; idx0 = d ^ q; @@ -615,9 +616,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = al1; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; - int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; - int64_t q = n / (d | 0x5); + const int64x2_t x = vld1q_s64(reinterpret_cast(&l1[idx1 & MASK])); + const int64_t n = vgetq_lane_s64(x, 0); + const int32_t d = vgetq_lane_s32(x, 2); + const int64_t q = n / (d | 0x5); ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; idx1 = d ^ q; From e320b2e9282f7740811722039c1e4e9cf32de0e2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 Jun 2018 02:09:29 +0700 Subject: [PATCH 14/22] #672 Reverted back "cryptonight-light" and exit if no valid algorithm specified. --- src/common/config/CommonConfig.cpp | 3 ++- src/common/config/CommonConfig.h | 6 +++--- src/common/config/ConfigLoader.cpp | 8 +++++++- src/common/crypto/Algorithm.cpp | 1 + src/interfaces/IConfig.h | 2 ++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 155485d23..668bf0d8d 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -38,6 +38,7 @@ xmrig::CommonConfig::CommonConfig() : + m_algorithm(CRYPTONIGHT, VARIANT_AUTO), m_adjusted(false), m_apiIPv6(false), m_apiRestricted(true), @@ -117,7 +118,7 @@ bool xmrig::CommonConfig::finalize() } if (!m_algorithm.isValid()) { - m_algorithm.setAlgo(CRYPTONIGHT); + return false; } for (Pool &pool : m_pools) { diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 356f550de..95a02fb16 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -48,7 +48,6 @@ public: inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isSyslog() const { return m_syslog; } - inline const Algorithm &algorithm() const { return m_algorithm; } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *logFile() const { return m_logFile.data(); } @@ -61,8 +60,9 @@ public: inline int retryPause() const { return m_retryPause; } inline void setColors(bool colors) { m_colors = colors; } - inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } - inline const char *fileName() const override { return m_fileName.data(); } + inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } + inline const Algorithm &algorithm() const override { return m_algorithm; } + inline const char *fileName() const override { return m_fileName.data(); } bool save() override; diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 919ff00c1..32d0850c0 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -170,7 +170,13 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator } if (!config->finalize()) { - fprintf(stderr, "No valid configuration found. Exiting.\n"); + if (!config->algorithm().isValid()) { + fprintf(stderr, "No valid algorithm specified. Exiting.\n"); + } + else { + fprintf(stderr, "No valid configuration found. Exiting.\n"); + } + delete config; return nullptr; } diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index fce4d7b8c..f3f4c2f4f 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -60,6 +60,7 @@ static AlgoData const algorithms[] = { # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, + { "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, { "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, diff --git a/src/interfaces/IConfig.h b/src/interfaces/IConfig.h index 2422b891b..77e262da6 100644 --- a/src/interfaces/IConfig.h +++ b/src/interfaces/IConfig.h @@ -24,6 +24,7 @@ #define __ICONFIG_H__ +#include "common/crypto/Algorithm.h" #include "rapidjson/fwd.h" @@ -97,6 +98,7 @@ public: virtual bool parseString(int key, const char *arg) = 0; virtual bool parseUint64(int key, uint64_t arg) = 0; virtual bool save() = 0; + virtual const Algorithm &algorithm() const = 0; virtual const char *fileName() const = 0; virtual void getJSON(rapidjson::Document &doc) const = 0; virtual void parseJSON(const rapidjson::Document &doc) = 0; From 48a214c3f19ff9f9e25b3975e7a9fbd2e57628b2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Jun 2018 07:34:58 +0700 Subject: [PATCH 15/22] Move files. --- CMakeLists.txt | 18 +++++++++--------- src/App.h | 2 +- src/api/ApiRouter.h | 2 +- src/common/config/CommonConfig.h | 2 +- src/common/config/ConfigLoader.cpp | 4 ++-- src/common/config/ConfigWatcher.cpp | 2 +- src/{ => common}/interfaces/IClientListener.h | 0 src/{ => common}/interfaces/IConfig.h | 6 ++++++ src/{ => common}/interfaces/IConfigCreator.h | 0 src/{ => common}/interfaces/IConsoleListener.h | 0 .../interfaces/IControllerListener.h | 0 src/{ => common}/interfaces/ILogBackend.h | 4 ++++ src/{ => common}/interfaces/IStrategy.h | 0 .../interfaces/IStrategyListener.h | 0 src/{ => common}/interfaces/IWatcherListener.h | 0 src/common/log/ConsoleLog.h | 2 +- src/common/log/FileLog.h | 2 +- src/common/log/Log.cpp | 2 +- src/common/log/Log.h | 2 +- src/common/net/Client.cpp | 2 +- src/common/net/Pool.cpp | 6 ++++++ src/common/net/strategies/FailoverStrategy.cpp | 2 +- src/common/net/strategies/FailoverStrategy.h | 4 ++-- .../net/strategies/SinglePoolStrategy.cpp | 2 +- src/common/net/strategies/SinglePoolStrategy.h | 4 ++-- src/core/ConfigCreator.h | 2 +- src/core/ConfigLoader_platform.h | 2 +- src/core/Controller.cpp | 2 +- src/core/Controller.h | 2 +- src/net/Network.h | 2 +- src/net/strategies/DonateStrategy.cpp | 2 +- src/net/strategies/DonateStrategy.h | 6 +++--- 32 files changed, 51 insertions(+), 35 deletions(-) rename src/{ => common}/interfaces/IClientListener.h (100%) rename src/{ => common}/interfaces/IConfig.h (95%) rename src/{ => common}/interfaces/IConfigCreator.h (100%) rename src/{ => common}/interfaces/IConsoleListener.h (100%) rename src/{ => common}/interfaces/IControllerListener.h (100%) rename src/{ => common}/interfaces/ILogBackend.h (94%) rename src/{ => common}/interfaces/IStrategy.h (100%) rename src/{ => common}/interfaces/IStrategyListener.h (100%) rename src/{ => common}/interfaces/IWatcherListener.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a242970bc..e263808e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,15 @@ set(HEADERS src/common/Console.h src/common/crypto/Algorithm.h src/common/crypto/keccak.h + src/common/interfaces/IClientListener.h + src/common/interfaces/IConfig.h + src/common/interfaces/IConfigCreator.h + src/common/interfaces/IConsoleListener.h + src/common/interfaces/IControllerListener.h + src/common/interfaces/ILogBackend.h + src/common/interfaces/IStrategy.h + src/common/interfaces/IStrategyListener.h + src/common/interfaces/IWatcherListener.h src/common/log/ConsoleLog.h src/common/log/FileLog.h src/common/log/Log.h @@ -38,17 +47,8 @@ set(HEADERS src/core/ConfigLoader_platform.h src/core/Controller.h src/Cpu.h - src/interfaces/IClientListener.h - src/interfaces/IConfig.h - src/interfaces/IConfigCreator.h - src/interfaces/IConsoleListener.h - src/interfaces/IControllerListener.h src/interfaces/IJobResultListener.h - src/interfaces/ILogBackend.h - src/interfaces/IStrategy.h - src/interfaces/IStrategyListener.h src/interfaces/IThread.h - src/interfaces/IWatcherListener.h src/interfaces/IWorker.h src/Mem.h src/net/JobResult.h diff --git a/src/App.h b/src/App.h index 22269f67c..964400e6b 100644 --- a/src/App.h +++ b/src/App.h @@ -28,7 +28,7 @@ #include -#include "interfaces/IConsoleListener.h" +#include "common/interfaces/IConsoleListener.h" class Console; diff --git a/src/api/ApiRouter.h b/src/api/ApiRouter.h index 3ed458d41..9e32cdaee 100644 --- a/src/api/ApiRouter.h +++ b/src/api/ApiRouter.h @@ -26,7 +26,7 @@ #include "api/NetworkState.h" -#include "interfaces/IControllerListener.h" +#include "common/interfaces/IControllerListener.h" #include "rapidjson/fwd.h" diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 95a02fb16..2a329c7ed 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -28,10 +28,10 @@ #include +#include "common/interfaces/IConfig.h" #include "common/net/Pool.h" #include "common/utils/c_str.h" #include "common/xmrig.h" -#include "interfaces/IConfig.h" namespace xmrig { diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 32d0850c0..cc5d9a493 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -34,12 +34,12 @@ #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" +#include "common/interfaces/IConfig.h" +#include "common/interfaces/IWatcherListener.h" #include "common/net/Pool.h" #include "common/Platform.h" #include "core/ConfigCreator.h" #include "core/ConfigLoader_platform.h" -#include "interfaces/IConfig.h" -#include "interfaces/IWatcherListener.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" #include "rapidjson/filereadstream.h" diff --git a/src/common/config/ConfigWatcher.cpp b/src/common/config/ConfigWatcher.cpp index bde35f237..14107b62c 100644 --- a/src/common/config/ConfigWatcher.cpp +++ b/src/common/config/ConfigWatcher.cpp @@ -27,9 +27,9 @@ #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" +#include "common/interfaces/IWatcherListener.h" #include "common/log/Log.h" #include "core/ConfigCreator.h" -#include "interfaces/IWatcherListener.h" xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) : diff --git a/src/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h similarity index 100% rename from src/interfaces/IClientListener.h rename to src/common/interfaces/IClientListener.h diff --git a/src/interfaces/IConfig.h b/src/common/interfaces/IConfig.h similarity index 95% rename from src/interfaces/IConfig.h rename to src/common/interfaces/IConfig.h index 77e262da6..62c7ba945 100644 --- a/src/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -78,6 +78,12 @@ public: ThreadsKey = 't', HardwareAESKey = 1011, + // xmrig amd + OclPlatform = 1400, + OclAffinity = 1401, + OclDevices = 1402, + OclLaunch = 1403, + // xmrig-proxy AccessLogFileKey = 'A', BindKey = 'b', diff --git a/src/interfaces/IConfigCreator.h b/src/common/interfaces/IConfigCreator.h similarity index 100% rename from src/interfaces/IConfigCreator.h rename to src/common/interfaces/IConfigCreator.h diff --git a/src/interfaces/IConsoleListener.h b/src/common/interfaces/IConsoleListener.h similarity index 100% rename from src/interfaces/IConsoleListener.h rename to src/common/interfaces/IConsoleListener.h diff --git a/src/interfaces/IControllerListener.h b/src/common/interfaces/IControllerListener.h similarity index 100% rename from src/interfaces/IControllerListener.h rename to src/common/interfaces/IControllerListener.h diff --git a/src/interfaces/ILogBackend.h b/src/common/interfaces/ILogBackend.h similarity index 94% rename from src/interfaces/ILogBackend.h rename to src/common/interfaces/ILogBackend.h index 6e3f5c1c0..85a04e935 100644 --- a/src/interfaces/ILogBackend.h +++ b/src/common/interfaces/ILogBackend.h @@ -40,7 +40,11 @@ public: DEBUG }; +# ifdef APP_DEBUG + constexpr static const size_t kBufferSize = 1024; +# else constexpr static const size_t kBufferSize = 512; +# endif virtual ~ILogBackend() {} diff --git a/src/interfaces/IStrategy.h b/src/common/interfaces/IStrategy.h similarity index 100% rename from src/interfaces/IStrategy.h rename to src/common/interfaces/IStrategy.h diff --git a/src/interfaces/IStrategyListener.h b/src/common/interfaces/IStrategyListener.h similarity index 100% rename from src/interfaces/IStrategyListener.h rename to src/common/interfaces/IStrategyListener.h diff --git a/src/interfaces/IWatcherListener.h b/src/common/interfaces/IWatcherListener.h similarity index 100% rename from src/interfaces/IWatcherListener.h rename to src/common/interfaces/IWatcherListener.h diff --git a/src/common/log/ConsoleLog.h b/src/common/log/ConsoleLog.h index 81813c816..bac09a535 100644 --- a/src/common/log/ConsoleLog.h +++ b/src/common/log/ConsoleLog.h @@ -28,7 +28,7 @@ #include -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" namespace xmrig { diff --git a/src/common/log/FileLog.h b/src/common/log/FileLog.h index 2c25f0932..8a58d4e40 100644 --- a/src/common/log/FileLog.h +++ b/src/common/log/FileLog.h @@ -28,7 +28,7 @@ #include -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" namespace xmrig { diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index 763eb25b0..ccf380087 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -29,8 +29,8 @@ #include +#include "common/interfaces/ILogBackend.h" #include "common/log/Log.h" -#include "interfaces/ILogBackend.h" Log *Log::m_self = nullptr; diff --git a/src/common/log/Log.h b/src/common/log/Log.h index c4803e3a0..bfa307173 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -30,7 +30,7 @@ #include -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" class Log diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 921fa618b..a552ed3cd 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -29,9 +29,9 @@ #include +#include "common/interfaces/IClientListener.h" #include "common/log/Log.h" #include "common/net/Client.h" -#include "interfaces/IClientListener.h" #include "net/JobResult.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index c12e05d55..d59435453 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -101,6 +101,12 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const } } +# ifdef XMRIG_PROXY_PROJECT + if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT && m_algorithm.variant() == xmrig::VARIANT_XTL) { + return true; + } +# endif + return false; } diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index 295b4335e..fab785906 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -22,10 +22,10 @@ */ +#include "common/interfaces/IStrategyListener.h" #include "common/net/Client.h" #include "common/net/strategies/FailoverStrategy.h" #include "common/Platform.h" -#include "interfaces/IStrategyListener.h" FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index f86b366a7..07095b3b1 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -28,9 +28,9 @@ #include +#include "common/interfaces/IClientListener.h" +#include "common/interfaces/IStrategy.h" #include "common/net/Pool.h" -#include "interfaces/IClientListener.h" -#include "interfaces/IStrategy.h" class Client; diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index 21ce7b34d..2cfc0976b 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -22,10 +22,10 @@ */ +#include "common/interfaces/IStrategyListener.h" #include "common/net/Client.h" #include "common/net/strategies/SinglePoolStrategy.h" #include "common/Platform.h" -#include "interfaces/IStrategyListener.h" SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index 41d90e349..1a48d6786 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -25,8 +25,8 @@ #define __SINGLEPOOLSTRATEGY_H__ -#include "interfaces/IClientListener.h" -#include "interfaces/IStrategy.h" +#include "common/interfaces/IClientListener.h" +#include "common/interfaces/IStrategy.h" class Client; diff --git a/src/core/ConfigCreator.h b/src/core/ConfigCreator.h index fcc6c5960..054eb78c9 100644 --- a/src/core/ConfigCreator.h +++ b/src/core/ConfigCreator.h @@ -24,8 +24,8 @@ #define __CONFIGCREATOR_H__ +#include "common/interfaces/IConfigCreator.h" #include "core/Config.h" -#include "interfaces/IConfigCreator.h" namespace xmrig { diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 9704d5e30..bc6657d1b 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -33,8 +33,8 @@ #endif +#include "common/interfaces/IConfig.h" #include "version.h" -#include "interfaces/IConfig.h" namespace xmrig { diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index ac64f173b..ce73f0374 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -26,6 +26,7 @@ #include "common/config/ConfigLoader.h" +#include "common/interfaces/IControllerListener.h" #include "common/log/ConsoleLog.h" #include "common/log/FileLog.h" #include "common/log/Log.h" @@ -33,7 +34,6 @@ #include "core/Config.h" #include "core/Controller.h" #include "Cpu.h" -#include "interfaces/IControllerListener.h" #include "net/Network.h" diff --git a/src/core/Controller.h b/src/core/Controller.h index 25f91843c..2c66af532 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -25,7 +25,7 @@ #define __CONTROLLER_H__ -#include "interfaces/IWatcherListener.h" +#include "common/interfaces/IWatcherListener.h" class Network; diff --git a/src/net/Network.h b/src/net/Network.h index 353edc77c..51e95d6d2 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -30,8 +30,8 @@ #include "api/NetworkState.h" +#include "common/interfaces/IStrategyListener.h" #include "interfaces/IJobResultListener.h" -#include "interfaces/IStrategyListener.h" class IStrategy; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 7de776eff..4d353655a 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -23,13 +23,13 @@ #include "common/crypto/keccak.h" +#include "common/interfaces/IStrategyListener.h" #include "common/net/Client.h" #include "common/net/Job.h" #include "common/net/strategies/FailoverStrategy.h" #include "common/net/strategies/SinglePoolStrategy.h" #include "common/Platform.h" #include "common/xmrig.h" -#include "interfaces/IStrategyListener.h" #include "net/strategies/DonateStrategy.h" diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 66c0375c0..95ff6608a 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -30,9 +30,9 @@ #include "common/net/Pool.h" -#include "interfaces/IClientListener.h" -#include "interfaces/IStrategy.h" -#include "interfaces/IStrategyListener.h" +#include "common/interfaces/IClientListener.h" +#include "common/interfaces/IStrategy.h" +#include "common/interfaces/IStrategyListener.h" class Client; From dba78717fa10909bc0f3e111caf2f64cbdc5167f Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Jun 2018 11:48:31 +0700 Subject: [PATCH 16/22] Move dry-run option to common code. --- src/common/config/CommonConfig.cpp | 8 +++++++ src/common/config/CommonConfig.h | 2 ++ src/core/Config.cpp | 36 +++++++++++++----------------- src/core/Config.h | 2 -- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 668bf0d8d..315b09d68 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -44,6 +44,7 @@ xmrig::CommonConfig::CommonConfig() : m_apiRestricted(true), m_background(false), m_colors(true), + m_dryRun(false), m_syslog(false), # ifdef XMRIG_PROXY_PROJECT @@ -172,9 +173,15 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) case ApiIPv6Key: /* ipv6 */ m_apiIPv6 = enable; + break; case ApiRestrictedKey: /* restricted */ m_apiRestricted = enable; + break; + + case IConfig::DryRunKey: /* --dry-run */ + m_dryRun = enable; + break; default: break; @@ -259,6 +266,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) case KeepAliveKey: /* --keepalive */ case NicehashKey: /* --nicehash */ case ApiIPv6Key: /* --api-ipv6 */ + case DryRunKey: /* --dry-run */ return parseBoolean(key, true); case ColorKey: /* --no-color */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 2a329c7ed..ffebb6b25 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -47,6 +47,7 @@ public: inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } + inline bool isDryRun() const { return m_dryRun; } inline bool isSyslog() const { return m_syslog; } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } @@ -85,6 +86,7 @@ protected: bool m_apiRestricted; bool m_background; bool m_colors; + bool m_dryRun; bool m_syslog; bool m_watch; int m_apiPort; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 232e70240..fa6afdb4d 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -43,7 +43,6 @@ static char affinity_tmp[20] = { 0 }; xmrig::Config::Config() : xmrig::CommonConfig(), m_aesMode(AES_AUTO), m_algoVariant(AV_AUTO), - m_dryRun(false), m_hugePages(true), m_safe(false), m_maxCpuUsage(75), @@ -192,19 +191,15 @@ bool xmrig::Config::parseBoolean(int key, bool enable) } switch (key) { - case IConfig::SafeKey: /* --safe */ + case SafeKey: /* --safe */ m_safe = enable; break; - case IConfig::HugePagesKey: /* --no-huge-pages */ + case HugePagesKey: /* --no-huge-pages */ m_hugePages = enable; break; - case IConfig::DryRunKey: /* --dry-run */ - m_dryRun = enable; - break; - - case IConfig::HardwareAESKey: /* hw-aes config only */ + case HardwareAESKey: /* hw-aes config only */ m_aesMode = enable ? AES_HW : AES_SOFT; break; @@ -223,19 +218,18 @@ bool xmrig::Config::parseString(int key, const char *arg) } switch (key) { - case xmrig::IConfig::AVKey: /* --av */ - case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ - case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */ + case AVKey: /* --av */ + case MaxCPUUsageKey: /* --max-cpu-usage */ + case CPUPriorityKey: /* --cpu-priority */ return parseUint64(key, strtol(arg, nullptr, 10)); - case xmrig::IConfig::SafeKey: /* --safe */ - case xmrig::IConfig::DryRunKey: /* --dry-run */ + case SafeKey: /* --safe */ return parseBoolean(key, true); - case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */ + case HugePagesKey: /* --no-huge-pages */ return parseBoolean(key, false); - case xmrig::IConfig::ThreadsKey: /* --threads */ + case ThreadsKey: /* --threads */ if (strncmp(arg, "all", 3) == 0) { m_threads.count = Cpu::threads(); return true; @@ -243,7 +237,7 @@ bool xmrig::Config::parseString(int key, const char *arg) return parseUint64(key, strtol(arg, nullptr, 10)); - case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ + case CPUAffinityKey: /* --cpu-affinity */ { const char *p = strstr(arg, "0x"); return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); @@ -264,7 +258,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) } switch (key) { - case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ + case CPUAffinityKey: /* --cpu-affinity */ if (arg) { m_threads.mask = arg; } @@ -303,25 +297,25 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) bool xmrig::Config::parseInt(int key, int arg) { switch (key) { - case xmrig::IConfig::ThreadsKey: /* --threads */ + case ThreadsKey: /* --threads */ if (arg >= 0 && arg < 1024) { m_threads.count = arg; } break; - case xmrig::IConfig::AVKey: /* --av */ + case AVKey: /* --av */ if (arg >= AV_AUTO && arg < AV_MAX) { m_algoVariant = static_cast(arg); } break; - case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ + case MaxCPUUsageKey: /* --max-cpu-usage */ if (m_maxCpuUsage > 0 && arg <= 100) { m_maxCpuUsage = arg; } break; - case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */ + case CPUPriorityKey: /* --cpu-priority */ if (arg >= 0 && arg <= 5) { m_priority = arg; } diff --git a/src/core/Config.h b/src/core/Config.h index 0c6a21732..f0f1404fb 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -77,7 +77,6 @@ public: inline AesMode aesMode() const { return m_aesMode; } inline AlgoVariant algoVariant() const { return m_algoVariant; } - inline bool isDryRun() const { return m_dryRun; } inline bool isHugePages() const { return m_hugePages; } inline const std::vector &threads() const { return m_threads.list; } inline int priority() const { return m_priority; } @@ -117,7 +116,6 @@ private: AesMode m_aesMode; AlgoVariant m_algoVariant; - bool m_dryRun; bool m_hugePages; bool m_safe; int m_maxCpuUsage; From 974cb4162accd74836effe314c83d8ee62664605 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 7 Jun 2018 07:17:30 +0700 Subject: [PATCH 17/22] Fix Linux build. --- src/common/log/SysLog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/log/SysLog.h b/src/common/log/SysLog.h index 1e49a48bb..5cfeefcdb 100644 --- a/src/common/log/SysLog.h +++ b/src/common/log/SysLog.h @@ -25,7 +25,7 @@ #define __SYSLOG_H__ -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" class SysLog : public ILogBackend From 8908c2c027ec4adcb6fecf80b401bd4435a635cc Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 10 Jun 2018 19:48:34 +0700 Subject: [PATCH 18/22] Added support for "cn/msr" also known as "cn-fast". --- src/common/crypto/Algorithm.cpp | 18 ++++----- src/common/net/Job.cpp | 10 ++--- src/common/net/Pool.cpp | 14 +++---- src/common/xmrig.h | 7 +++- src/crypto/CryptoNight_constants.h | 19 +++++++--- src/crypto/CryptoNight_test.h | 15 ++++++++ src/crypto/CryptoNight_x86.h | 20 +++++----- src/workers/CpuThread.cpp | 60 ++++++++++++++++++++++++------ src/workers/MultiWorker.cpp | 47 +++++++++++------------ src/workers/MultiWorker.h | 1 + 10 files changed, 136 insertions(+), 75 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index f3f4c2f4f..fbfd02311 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -57,6 +57,7 @@ static AlgoData const algorithms[] = { { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, + { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -68,6 +69,8 @@ static AlgoData const algorithms[] = { # ifndef XMRIG_NO_SUMO { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, # endif }; @@ -89,7 +92,9 @@ static const char *variants[] = { "0", "1", "ipbc", - "xtl" + "xtl", + "msr", + "xhv" }; @@ -145,11 +150,6 @@ void xmrig::Algorithm::parseAlgorithm(const char *algo) void xmrig::Algorithm::parseVariant(const char *variant) { - if (m_algo == CRYPTONIGHT_HEAVY) { - m_variant = VARIANT_0; - return; - } - m_variant = VARIANT_AUTO; for (size_t i = 0; i < ARRAY_SIZE(variants); i++) { @@ -163,7 +163,7 @@ void xmrig::Algorithm::parseVariant(const char *variant) void xmrig::Algorithm::parseVariant(int variant) { - if (variant >= VARIANT_AUTO && variant <= VARIANT_XTL) { + if (variant >= VARIANT_AUTO && variant < VARIANT_MAX) { m_variant = static_cast(variant); } else { @@ -175,10 +175,6 @@ void xmrig::Algorithm::parseVariant(int variant) void xmrig::Algorithm::setAlgo(Algo algo) { m_algo = algo; - - if (m_algo == CRYPTONIGHT_HEAVY) { - m_variant = VARIANT_0; - } } diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 81c3b8f8d..9a7ede8e9 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -173,12 +173,12 @@ xmrig::Variant Job::variant() const return xmrig::VARIANT_1; } - if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (m_algorithm.algo() == xmrig::CRYPTONIGHT) { - return xmrig::VARIANT_1; - } + if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] < 7) { + return xmrig::VARIANT_1; + } - return (m_blob[0] > 6 ? xmrig::VARIANT_1 : xmrig::VARIANT_0); + if (m_algorithm.variant() == xmrig::VARIANT_AUTO && m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { + return xmrig::VARIANT_1; } return m_algorithm.variant(); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index d59435453..006d76a13 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -321,12 +321,12 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_IPBC); - addVariant(xmrig::VARIANT_AUTO); - } + addVariant(xmrig::VARIANT_1); + addVariant(xmrig::VARIANT_0); + addVariant(xmrig::VARIANT_XTL); + addVariant(xmrig::VARIANT_IPBC); + addVariant(xmrig::VARIANT_MSR); + addVariant(xmrig::VARIANT_XHV); + addVariant(xmrig::VARIANT_AUTO); # endif } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 43a2a2525..170f4832c 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -61,8 +61,11 @@ enum Variant { VARIANT_AUTO = -1, // Autodetect VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 - VARIANT_IPBC = 2, // CryptoNight Lite variant 1 with XOR (IPBC only) - VARIANT_XTL = 3 // CryptoNight variant 1 (Stellite only) + VARIANT_IPBC = 2, // Modified CryptoNight Lite variant 1 with XOR (IPBC/TUBE only) + VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) + VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) + VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) + VARIANT_MAX }; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 7e6627fd6..73f3e9581 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -38,6 +38,7 @@ namespace xmrig constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; +constexpr const uint32_t CRYPTONIGHT_MSR_ITER = 0x40000; constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0; @@ -102,18 +103,24 @@ inline uint32_t cn_select_mask(Algo algorithm) } -template inline constexpr uint32_t cn_select_iter() { return 0; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template inline constexpr uint32_t cn_select_iter() { return 0; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_MSR_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } -inline uint32_t cn_select_iter(Algo algorithm) +inline uint32_t cn_select_iter(Algo algorithm, Variant variant) { switch(algorithm) { case CRYPTONIGHT: - return CRYPTONIGHT_ITER; + return variant == VARIANT_MSR ? CRYPTONIGHT_MSR_ITER : CRYPTONIGHT_ITER; case CRYPTONIGHT_LITE: return CRYPTONIGHT_LITE_ITER; diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index bf6013e8c..8d8fe4551 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -99,6 +99,21 @@ const static uint8_t test_output_xtl[160] = { }; +// Masari (MSR) +const static uint8_t test_output_msr[160] = { + 0x3C, 0x7A, 0x61, 0x08, 0x4C, 0x5E, 0xB8, 0x65, 0xB4, 0x98, 0xAB, 0x2F, 0x5A, 0x1A, 0xC5, 0x2C, + 0x49, 0xC1, 0x77, 0xC2, 0xD0, 0x13, 0x34, 0x42, 0xD6, 0x5E, 0xD5, 0x14, 0x33, 0x5C, 0x82, 0xC5, + 0x69, 0xDF, 0x38, 0x51, 0x1B, 0xB3, 0xEB, 0x7D, 0xE7, 0x6B, 0x08, 0x8E, 0xB6, 0x7E, 0xB7, 0x1C, + 0x5F, 0x3C, 0x81, 0xC9, 0xF7, 0xCE, 0xAE, 0x28, 0xC0, 0xFE, 0xEB, 0xBA, 0x0B, 0x40, 0x38, 0x1D, + 0x44, 0xD0, 0xD5, 0xD3, 0x98, 0x1F, 0xA3, 0x0E, 0xE9, 0x89, 0x1A, 0xD7, 0x88, 0xCC, 0x25, 0x76, + 0x9C, 0xFF, 0x4D, 0x7F, 0x9C, 0xCF, 0x48, 0x07, 0x91, 0xF9, 0x82, 0xF5, 0x4C, 0xE9, 0xBD, 0x82, + 0x36, 0x36, 0x64, 0x14, 0xED, 0xB8, 0x54, 0xEE, 0x22, 0xA1, 0x66, 0xA3, 0x87, 0x10, 0x76, 0x1F, + 0x5A, 0xCD, 0x4C, 0x31, 0x4C, 0xBA, 0x41, 0xD2, 0xDB, 0x6C, 0x31, 0x2E, 0x7A, 0x64, 0x15, 0xFF, + 0xA6, 0xD9, 0xB9, 0x7D, 0x1C, 0x3C, 0x98, 0xDD, 0x16, 0xE6, 0xD3, 0xAA, 0xEF, 0xB6, 0xB3, 0x53, + 0x74, 0xD1, 0xAC, 0x5C, 0x04, 0x26, 0x7D, 0x71, 0xDE, 0xAB, 0x66, 0x28, 0x91, 0x3A, 0x6F, 0x4F +}; + + #ifndef XMRIG_NO_AEON const static uint8_t test_output_v0_lite[160] = { 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 66bcf8b54..3aa2a927b 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -403,11 +403,11 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) } -template +template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -493,11 +493,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -700,11 +700,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -790,11 +790,11 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -896,11 +896,11 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size } -template +template inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index e42139c08..926a9ba3b 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -62,9 +62,15 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - assert(variant == VARIANT_0 || variant == VARIANT_1 || variant == VARIANT_IPBC || variant == VARIANT_XTL); + assert(variant == VARIANT_0 || + variant == VARIANT_1 || + variant == VARIANT_IPBC || + variant == VARIANT_XTL || + variant == VARIANT_MSR || + variant == VARIANT_XHV + ); - static const cn_hash_fun func_table[90] = { + static const cn_hash_fun func_table[180] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -87,7 +93,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC cryptonight_single_hash, cryptonight_double_hash, @@ -100,6 +106,19 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -134,12 +153,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif # ifndef XMRIG_NO_SUMO @@ -153,18 +176,33 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_triple_hash, cryptonight_quad_hash, cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif }; -# ifndef XMRIG_NO_SUMO - if (algorithm == CRYPTONIGHT_HEAVY) { - variant = VARIANT_0; - } -# endif - - const size_t index = 40 * algorithm + 10 * variant + av - 1; + const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1; # ifndef NDEBUG cn_hash_fun func = func_table[index]; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index c0f884466..f3acf7f8a 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -50,36 +50,23 @@ MultiWorker::~MultiWorker() template bool MultiWorker::selfTest() { - if (m_thread->fn(xmrig::VARIANT_0) == nullptr) { - return false; - } - - m_thread->fn(xmrig::VARIANT_0)(test_input, 76, m_hash, m_ctx); - - if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, sizeof m_hash) == 0) { - m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); - if (memcmp(m_hash, test_output_v1, sizeof m_hash) != 0) { - return false; - } - - m_thread->fn(xmrig::VARIANT_XTL)(test_input, 76, m_hash, m_ctx); - return memcmp(m_hash, test_output_xtl, sizeof m_hash) == 0; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT) { + return verify(xmrig::VARIANT_0, test_output_v0) && + verify(xmrig::VARIANT_1, test_output_v1) && + verify(xmrig::VARIANT_XTL, test_output_xtl) && + verify(xmrig::VARIANT_MSR, test_output_msr); } # ifndef XMRIG_NO_AEON - if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_hash, test_output_v0_lite, sizeof m_hash) == 0) { - m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); - if (memcmp(m_hash, test_output_v1_lite, sizeof m_hash) != 0) { - return false; - } - - m_thread->fn(xmrig::VARIANT_IPBC)(test_input, 76, m_hash, m_ctx); - return memcmp(m_hash, test_output_ipbc_lite, sizeof m_hash) == 0; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE) { + return verify(xmrig::VARIANT_0, test_output_v0_lite) && + verify(xmrig::VARIANT_1, test_output_v1_lite) && + verify(xmrig::VARIANT_IPBC, test_output_ipbc_lite); } # endif # ifndef XMRIG_NO_SUMO - return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, sizeof m_hash) == 0; + return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && verify(xmrig::VARIANT_0, test_output_heavy); # else return false; # endif @@ -140,6 +127,20 @@ bool MultiWorker::resume(const Job &job) } +template +bool MultiWorker::verify(xmrig::Variant variant, const uint8_t *referenceValue) +{ + + xmrig::CpuThread::cn_hash_fun func = m_thread->fn(variant); + if (!func) { + return false; + } + + func(test_input, 76, m_hash, m_ctx); + return memcmp(m_hash, referenceValue, sizeof m_hash) == 0; +} + + template void MultiWorker::consumeJob() { diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index d89bbb335..d4a6910e7 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -48,6 +48,7 @@ protected: private: bool resume(const Job &job); + bool verify(xmrig::Variant variant, const uint8_t *referenceValue); void consumeJob(); void save(const Job &job); From dab4239aca670a844dac383adcd6fc5e2d343ad2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 12:00:59 +0700 Subject: [PATCH 19/22] Added support for cn-heavy/xhv. --- src/common/net/Job.cpp | 12 ++--- src/crypto/CryptoNight_arm.h | 44 +++++++++++++----- src/crypto/CryptoNight_constants.h | 15 ++++++ src/crypto/CryptoNight_monero.h | 8 ++-- src/crypto/CryptoNight_test.h | 15 +++++- src/crypto/CryptoNight_x86.h | 74 ++++++++++++++++++++---------- src/workers/MultiWorker.cpp | 9 ++-- 7 files changed, 128 insertions(+), 49 deletions(-) diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 9a7ede8e9..80b521ea1 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -165,10 +165,6 @@ bool Job::setTarget(const char *target) xmrig::Variant Job::variant() const { - if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) { - return xmrig::VARIANT_0; - } - if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] < 4) { return xmrig::VARIANT_1; } @@ -177,8 +173,12 @@ xmrig::Variant Job::variant() const return xmrig::VARIANT_1; } - if (m_algorithm.variant() == xmrig::VARIANT_AUTO && m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - return xmrig::VARIANT_1; + if (m_algorithm.variant() == xmrig::VARIANT_XHV && m_blob[0] < 3) { + return xmrig::VARIANT_0; + } + + if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { + return m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY ? xmrig::VARIANT_0 : xmrig::VARIANT_1; } return m_algorithm.variant(); diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index fd5bcb7bc..46e1f5304 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -402,10 +402,11 @@ template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32); return; } @@ -436,7 +437,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } else { _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); @@ -455,7 +456,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -478,7 +479,13 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } } @@ -493,10 +500,11 @@ template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 64); return; } @@ -540,7 +548,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); } else { @@ -564,7 +572,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -587,7 +595,13 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } cl = ((uint64_t*) &l1[idx1 & MASK])[0]; @@ -599,7 +613,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } @@ -622,7 +636,13 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si const int64_t q = n / (d | 0x5); ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; - idx1 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx1 = (~d) ^ q; + } + else { + idx1 = d ^ q; + } } } diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 73f3e9581..85a2ab854 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -136,6 +136,21 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) } +template inline constexpr bool cn_is_monero() { return false; } +template<> inline constexpr bool cn_is_monero() { return false; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return false; } + + +inline bool cn_is_monero(Variant variant) +{ + return variant > VARIANT_0 && variant < VARIANT_XHV; +} + + } /* namespace xmrig */ diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 28572d88c..a758fdbc5 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -30,21 +30,21 @@ #ifndef XMRIG_ARM # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ tweak1_2_##part = (*reinterpret_cast(input + 35 + part * size) ^ \ *(reinterpret_cast(ctx[part]->state) + 24)); \ } #else # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ memcpy(&tweak1_2_##part, input + 35 + part * size, sizeof tweak1_2_##part); \ tweak1_2_##part ^= *(reinterpret_cast(ctx[part]->state) + 24); \ } #endif #define VARIANT1_1(p) \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ const uint8_t tmp = reinterpret_cast(p)[11]; \ static const uint32_t table = 0x75310; \ const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ @@ -52,7 +52,7 @@ } #define VARIANT1_2(p, part) \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ (p) ^= tweak1_2_##part; \ } diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 8d8fe4551..187ba07a3 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -161,7 +161,7 @@ const static uint8_t test_output_ipbc_lite[160] = { #ifndef XMRIG_NO_SUMO -const static uint8_t test_output_heavy[160] = { +const static uint8_t test_output_v0_heavy[160] = { 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2, 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, @@ -173,6 +173,19 @@ const static uint8_t test_output_heavy[160] = { 0x53, 0x62, 0x0A, 0x54, 0x7D, 0x43, 0xEA, 0x18, 0x94, 0xED, 0xD8, 0x92, 0x06, 0x6A, 0xA1, 0x51, 0xAD, 0xB1, 0xFD, 0x89, 0xFB, 0x5C, 0xB4, 0x25, 0x6A, 0xDD, 0xB0, 0x09, 0xC5, 0x72, 0x87, 0xEB }; + +const static uint8_t test_output_xhv_heavy[160] = { + 0x5A, 0xC3, 0xF7, 0x85, 0xC4, 0x90, 0xC5, 0x85, 0x50, 0xEC, 0x95, 0xD2, 0x72, 0x65, 0x63, 0x57, + 0x7E, 0x7C, 0x1C, 0x21, 0x2D, 0x0C, 0xDE, 0x59, 0x12, 0x73, 0x20, 0x1E, 0x44, 0xFD, 0xD5, 0xB6, + 0x1F, 0x4E, 0xB2, 0x0A, 0x36, 0x51, 0x4B, 0xF5, 0x4D, 0xC9, 0xE0, 0x90, 0x2C, 0x16, 0x47, 0x3F, + 0xDE, 0x18, 0x29, 0x8E, 0xBB, 0x34, 0x2B, 0xEF, 0x7A, 0x04, 0x22, 0xD1, 0xB1, 0xF2, 0x48, 0xDA, + 0xE3, 0x7F, 0x4B, 0x4C, 0xB4, 0xDF, 0xE8, 0xD3, 0x70, 0xE2, 0xE7, 0x44, 0x25, 0x87, 0x12, 0xF9, + 0x8F, 0x28, 0x0B, 0xCE, 0x2C, 0xEE, 0xDD, 0x88, 0x94, 0x35, 0x48, 0x51, 0xAE, 0xC8, 0x9C, 0x0B, + 0xED, 0x2F, 0xE6, 0x0F, 0x39, 0x05, 0xB4, 0x4A, 0x8F, 0x38, 0x44, 0x2D, 0x4B, 0xE9, 0x7B, 0x81, + 0xC6, 0xB0, 0xE0, 0x0A, 0x39, 0x8C, 0x38, 0xFE, 0x63, 0x31, 0x47, 0x65, 0x0D, 0x2B, 0xF4, 0x96, + 0x13, 0x91, 0x89, 0xB4, 0x5B, 0xA9, 0x2A, 0x7A, 0x09, 0x65, 0x14, 0x20, 0x76, 0x24, 0x6C, 0x80, + 0x1D, 0x3F, 0x9F, 0xCD, 0x68, 0x39, 0xA9, 0x42, 0x27, 0xC1, 0x0C, 0x53, 0x98, 0x35, 0x60, 0x7A +}; #endif diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 3aa2a927b..8ab65023d 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -409,8 +409,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32); return; } @@ -441,7 +442,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } else { _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); @@ -460,7 +461,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -477,12 +478,18 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } } @@ -499,8 +506,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 64); return; } @@ -544,7 +552,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); } else { @@ -568,7 +576,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -585,12 +593,18 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } cl = ((uint64_t*) &l1[idx1 & MASK])[0]; @@ -602,7 +616,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } @@ -619,12 +633,18 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = al1; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; - int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; + int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; + int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; int64_t q = n / (d | 0x5); ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; - idx1 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx1 = (~d) ^ q; + } + else { + idx1 = d ^ q; + } } } @@ -653,7 +673,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si \ b = _mm_xor_si128(b, c); \ \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ cryptonight_monero_tweak(reinterpret_cast(ptr), b); \ } else { \ _mm_store_si128(ptr, b); \ @@ -670,7 +690,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx, EXTRACT64(b), &hi); \ a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \ \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ if (VARIANT == xmrig::VARIANT_IPBC) { \ @@ -688,13 +708,18 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si int32_t d = ((int32_t*)&l[idx & MASK])[2]; \ int64_t q = n / (d | 0x5); \ ((int64_t*)&l[idx & MASK])[0] = n ^ q; \ - idx = d ^ q; \ + if (VARIANT == xmrig::VARIANT_XHV) { \ + idx = (~d) ^ q; \ + } \ + else { \ + idx = d ^ q; \ + } \ } #define CONST_INIT(ctx, n) \ __m128i mc##n; \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ mc##n = _mm_set_epi64x(*reinterpret_cast(input + n * size + 35) ^ \ *(reinterpret_cast((ctx)->state) + 24), 0); \ } @@ -706,8 +731,9 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32 * 3); return; } @@ -796,8 +822,9 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32 * 4); return; } @@ -902,8 +929,9 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32 * 5); return; } diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index f3acf7f8a..73f0dba7a 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -66,10 +66,13 @@ bool MultiWorker::selfTest() # endif # ifndef XMRIG_NO_SUMO - return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && verify(xmrig::VARIANT_0, test_output_heavy); -# else - return false; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY) { + return verify(xmrig::VARIANT_0, test_output_v0_heavy) && + verify(xmrig::VARIANT_XHV, test_output_xhv_heavy); + } # endif + + return false; } From 1d31f1b0b8eae7c60665292d844aa49d80ae284d Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 12:26:49 +0700 Subject: [PATCH 20/22] Fix command line option "-a cn-heavy". --- src/common/net/Pool.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 006d76a13..74e5012a4 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -233,7 +233,10 @@ void Pool::adjust(xmrig::Algo algorithm) m_algorithm.setAlgo(algorithm); if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (algorithm == xmrig::CRYPTONIGHT) { + if (algorithm == xmrig::CRYPTONIGHT_HEAVY) { + m_algorithm.setVariant(xmrig::VARIANT_0); + } + else { m_algorithm.setVariant(xmrig::VARIANT_1); } } From 21b2e2ca1e0761b41c44927a88710de0fa3bc392 Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 11 Jun 2018 15:23:06 +0700 Subject: [PATCH 21/22] Update CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c99e646f4..07fa9b870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# v2.6.3 +- **Added support for new cryptonight-heavy variant xhv** (`cn-heavy/xhv`) for upcoming Haven Protocol fork. +- **Added support for new cryptonight variant msr** (`cn/msr`) also known as `cryptonight-fast` for upcoming Masari fork. +- [#446](https://github.com/xmrig/xmrig/issues/446) Likely fixed SIGBUS error on 32 bit ARM CPUs. +- [#551](https://github.com/xmrig/xmrig/issues/551) Fixed `cn-heavy` algorithm on ARMv8. +- [#614](https://github.com/xmrig/xmrig/issues/614) Fixed display issue with huge pages percentage when colors disabled. +- [#615](https://github.com/xmrig/xmrig/issues/615) Fixed build without libcpuid. +- [#629](https://github.com/xmrig/xmrig/pull/629) Fixed file logging with non-seekable files. +- [#672](https://github.com/xmrig/xmrig/pull/672) Reverted back `cryptonight-light` and exit if no valid algorithm specified. + # v2.6.2 - [#607](https://github.com/xmrig/xmrig/issues/607) Fixed donation bug. - [#610](https://github.com/xmrig/xmrig/issues/610) Fixed ARM build. From 6a7a7ada2eb1935c22ccdc0d3620a8c0a991f56a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 15:44:45 +0700 Subject: [PATCH 22/22] Fix ARM build. --- src/crypto/CryptoNight_arm.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 46e1f5304..845c027ec 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -398,7 +398,7 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) } -template +template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); @@ -496,7 +496,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); @@ -657,19 +657,19 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { } -template +template inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { } -template +template inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { }