From 7a1ff6bfed6a4118e77ddb0b13b7bde4951abc2e Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Sep 2019 16:45:17 +0700 Subject: [PATCH 01/10] v3.1.4-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 151e925b..81e2bcce 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "3.1.3" +#define APP_VERSION "3.1.4-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 3 #define APP_VER_MINOR 1 -#define APP_VER_PATCH 3 +#define APP_VER_PATCH 4 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From e57798360fe344d72b1bddfa2637472c16b63057 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 21 Sep 2019 03:22:19 +0700 Subject: [PATCH 02/10] #1183 Disable stdin handler if not available. --- src/base/io/Console.cpp | 16 +++++++- src/base/io/Console.h | 12 ++++-- src/base/io/log/backends/ConsoleLog.cpp | 22 ++++++++--- src/base/io/log/backends/ConsoleLog.h | 12 ++++-- src/base/tools/Object.h | 52 +++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 src/base/tools/Object.h diff --git a/src/base/io/Console.cpp b/src/base/io/Console.cpp index 0e5cd269..bba73035 100644 --- a/src/base/io/Console.cpp +++ b/src/base/io/Console.cpp @@ -31,8 +31,11 @@ xmrig::Console::Console(IConsoleListener *listener) : m_listener(listener) { - m_tty = new uv_tty_t; + if (!isSupported()) { + return; + } + m_tty = new uv_tty_t; m_tty->data = this; uv_tty_init(uv_default_loop(), m_tty, 0, 1); @@ -53,6 +56,10 @@ xmrig::Console::~Console() void xmrig::Console::stop() { + if (!m_tty) { + return; + } + uv_tty_reset_mode(); Handle::close(m_tty); @@ -60,6 +67,13 @@ void xmrig::Console::stop() } +bool xmrig::Console::isSupported() const +{ + const uv_handle_type type = uv_guess_handle(0); + return type == UV_TTY || type == UV_NAMED_PIPE; +} + + void xmrig::Console::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf) { auto console = static_cast(handle->data); diff --git a/src/base/io/Console.h b/src/base/io/Console.h index c0a36ec4..0a075348 100644 --- a/src/base/io/Console.h +++ b/src/base/io/Console.h @@ -26,9 +26,11 @@ #define XMRIG_CONSOLE_H -#include +#include "base/tools/Object.h" +#include + namespace xmrig { @@ -39,18 +41,22 @@ class IConsoleListener; class Console { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(Console) + Console(IConsoleListener *listener); ~Console(); void stop(); private: + bool isSupported() const; + static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf); - char m_buf[1]; + char m_buf[1] = { 0 }; IConsoleListener *m_listener; - uv_tty_t *m_tty; + uv_tty_t *m_tty = nullptr; }; diff --git a/src/base/io/log/backends/ConsoleLog.cpp b/src/base/io/log/backends/ConsoleLog.cpp index a5b6c1a7..34a7d66b 100644 --- a/src/base/io/log/backends/ConsoleLog.cpp +++ b/src/base/io/log/backends/ConsoleLog.cpp @@ -24,7 +24,7 @@ */ -#include +#include #include "base/tools/Handle.h" @@ -32,9 +32,13 @@ #include "base/io/log/Log.h" -xmrig::ConsoleLog::ConsoleLog() : - m_stream(nullptr) +xmrig::ConsoleLog::ConsoleLog() { + if (!isSupported()) { + Log::colors = false; + return; + } + m_tty = new uv_tty_t; if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) { @@ -66,7 +70,7 @@ xmrig::ConsoleLog::~ConsoleLog() void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors) { - if (Log::colors != colors) { + if (!m_tty || Log::colors != colors) { return; } @@ -86,12 +90,18 @@ void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool c } +bool xmrig::ConsoleLog::isSupported() const +{ + const uv_handle_type type = uv_guess_handle(1); + return type == UV_TTY || type == UV_NAMED_PIPE; +} + + bool xmrig::ConsoleLog::isWritable() const { if (!m_stream || uv_is_writable(m_stream) != 1) { return false; } - const uv_handle_type type = uv_guess_handle(1); - return type == UV_TTY || type == UV_NAMED_PIPE; + return isSupported(); } diff --git a/src/base/io/log/backends/ConsoleLog.h b/src/base/io/log/backends/ConsoleLog.h index 90e4fa14..6277cc7b 100644 --- a/src/base/io/log/backends/ConsoleLog.h +++ b/src/base/io/log/backends/ConsoleLog.h @@ -27,11 +27,12 @@ #define XMRIG_CONSOLELOG_H -typedef struct uv_stream_s uv_stream_t; -typedef struct uv_tty_s uv_tty_t; +using uv_stream_t = struct uv_stream_s; +using uv_tty_t = struct uv_tty_s; #include "base/kernel/interfaces/ILogBackend.h" +#include "base/tools/Object.h" namespace xmrig { @@ -40,6 +41,8 @@ namespace xmrig { class ConsoleLog : public ILogBackend { public: + XMRIG_DISABLE_COPY_MOVE(ConsoleLog) + ConsoleLog(); ~ConsoleLog() override; @@ -47,10 +50,11 @@ protected: void print(int level, const char *line, size_t offset, size_t size, bool colors) override; private: + bool isSupported() const; bool isWritable() const; - uv_stream_t *m_stream; - uv_tty_t *m_tty; + uv_stream_t *m_stream = nullptr; + uv_tty_t *m_tty = nullptr; }; diff --git a/src/base/tools/Object.h b/src/base/tools/Object.h new file mode 100644 index 00000000..7e460e44 --- /dev/null +++ b/src/base/tools/Object.h @@ -0,0 +1,52 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_OBJECT_H +#define XMRIG_OBJECT_H + + +#include + + +namespace xmrig { + + +#define XMRIG_DISABLE_COPY_MOVE(X) \ + X(const X &other) = delete; \ + X(X &&other) = delete; \ + X &operator=(const X &other) = delete; \ + X &operator=(X &&other) = delete; + + +#define XMRIG_DISABLE_COPY_MOVE_DEFAULT(X) \ + X() = delete; \ + X(const X &other) = delete; \ + X(X &&other) = delete; \ + X &operator=(const X &other) = delete; \ + X &operator=(X &&other) = delete; + + +} /* namespace xmrig */ + +#endif /* XMRIG_OBJECT_H */ From cf6bd0e7726b989da7740b9661e32057f75fde91 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 21 Sep 2019 19:05:52 +0700 Subject: [PATCH 03/10] #1183 Fixed crash in background mode. --- src/App.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/App.cpp b/src/App.cpp index de45a499..008df0a7 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -150,7 +150,11 @@ void xmrig::App::onSignal(int signum) void xmrig::App::close() { m_signals->stop(); - m_console->stop(); + + if (m_console) { + m_console->stop(); + } + m_controller->stop(); Log::destroy(); From e1d1a5226cce0c9c177c01b94ebbf14fde98542f Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 27 Sep 2019 05:41:45 +0700 Subject: [PATCH 04/10] Added coin option. --- CMakeLists.txt | 2 + src/base/kernel/config/BaseTransform.cpp | 19 +++++ src/base/kernel/config/BaseTransform.h | 2 + src/base/kernel/interfaces/IConfig.h | 1 + src/base/net/stratum/Client.cpp | 12 ++- src/base/net/stratum/Job.h | 1 + src/base/net/stratum/Pool.cpp | 4 + src/base/net/stratum/Pool.h | 4 +- src/base/net/stratum/Pools.cpp | 5 +- src/config.json | 1 + src/core/config/Config_default.h | 1 + src/core/config/Config_platform.h | 1 + src/core/config/usage.h | 1 + src/crypto/common/Coin.cpp | 103 +++++++++++++++++++++++ src/crypto/common/Coin.h | 75 +++++++++++++++++ 15 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 src/crypto/common/Coin.cpp create mode 100644 src/crypto/common/Coin.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b3a4b5dc..c75efb41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ set(HEADERS_CRYPTO src/crypto/cn/skein_port.h src/crypto/cn/soft_aes.h src/crypto/common/Algorithm.h + src/crypto/common/Coin.h src/crypto/common/keccak.h src/crypto/common/Nonce.h src/crypto/common/portable/mm_malloc.h @@ -105,6 +106,7 @@ set(SOURCES_CRYPTO src/crypto/cn/CnCtx.cpp src/crypto/cn/CnHash.cpp src/crypto/common/Algorithm.cpp + src/crypto/common/Coin.cpp src/crypto/common/keccak.cpp src/crypto/common/Nonce.cpp src/crypto/common/VirtualMemory.cpp diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index 12e7d848..7090b6b7 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -47,6 +47,7 @@ namespace xmrig static const char *kAlgo = "algo"; static const char *kApi = "api"; +static const char *kCoin = "coin"; static const char *kHttp = "http"; static const char *kPools = "pools"; @@ -107,6 +108,15 @@ void xmrig::BaseTransform::finalize(rapidjson::Document &doc) } } } + + if (m_coin.isValid() && doc.HasMember(kPools)) { + auto &pools = doc[kPools]; + for (Value &pool : pools.GetArray()) { + if (!pool.HasMember(kCoin)) { + pool.AddMember(StringRef(kCoin), m_coin.toJSON(), allocator); + } + } + } } @@ -122,6 +132,15 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch } break; + case IConfig::CoinKey: /* --coin */ + if (!doc.HasMember(kPools)) { + m_coin = arg; + } + else { + return add(doc, kPools, kCoin, arg); + } + break; + case IConfig::UserpassKey: /* --userpass */ { const char *p = strrchr(arg, ':'); diff --git a/src/base/kernel/config/BaseTransform.h b/src/base/kernel/config/BaseTransform.h index 02b28c12..ab83a63f 100644 --- a/src/base/kernel/config/BaseTransform.h +++ b/src/base/kernel/config/BaseTransform.h @@ -27,6 +27,7 @@ #include "base/kernel/interfaces/IConfigTransform.h" +#include "crypto/common/Coin.h" #include "rapidjson/document.h" @@ -99,6 +100,7 @@ protected: protected: Algorithm m_algorithm; + Coin m_coin; private: diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index 86b8067c..52aed25f 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -43,6 +43,7 @@ public: enum Keys { // common AlgorithmKey = 'a', + CoinKey = 1025, ApiWorkerIdKey = 4002, ApiIdKey = 4005, HttpPort = 4100, diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index b87466ab..b9189247 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -334,6 +334,9 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) if (algo) { job.setAlgorithm(algo); } + else if (m_pool.coin().isValid()) { + job.setAlgorithm(m_pool.coin().algorithm(job.blob()[0])); + } job.setHeight(Json::getUint64(params, "height")); @@ -426,7 +429,12 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo { if (!algorithm.isValid()) { if (!isQuiet()) { - LOG_ERR("[%s] Unknown/unsupported algorithm \"%s\" detected, reconnect", url(), algo); + if (algo == nullptr) { + LOG_ERR("[%s] unknown algorithm, make sure you set \"algo\" or \"coin\" option", url(), algo); + } + else { + LOG_ERR("[%s] unsupported algorithm \"%s\" detected, reconnect", url(), algo); + } } return false; @@ -436,7 +444,7 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo m_listener->onVerifyAlgorithm(this, algorithm, &ok); if (!ok && !isQuiet()) { - LOG_ERR("[%s] Incompatible/disabled algorithm \"%s\" detected, reconnect", url(), algorithm.shortName()); + LOG_ERR("[%s] incompatible/disabled algorithm \"%s\" detected, reconnect", url(), algorithm.shortName()); } return ok; diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 2b256a12..a1a3b611 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -73,6 +73,7 @@ public: inline uint8_t fixedByte() const { return *(m_blob + 42); } inline uint8_t index() const { return m_index; } inline void reset() { m_size = 0; m_diff = 0; } + inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; } inline void setAlgorithm(const char *algo) { m_algorithm = algo; } inline void setClientId(const String &id) { m_clientId = id; } inline void setHeight(uint64_t height) { m_height = height; } diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index ba31c35d..1b9adfc4 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -48,6 +48,7 @@ namespace xmrig { static const char *kAlgo = "algo"; +static const char *kCoin = "coin"; static const char *kDaemon = "daemon"; static const char *kDaemonPollInterval = "daemon-poll-interval"; static const char *kEnabled = "enabled"; @@ -120,6 +121,7 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : m_fingerprint = Json::getString(object, kFingerprint); m_pollInterval = Json::getUint64(object, kDaemonPollInterval, kDefaultPollInterval); m_algorithm = Json::getString(object, kAlgo); + m_coin = Json::getString(object, kCoin); m_flags.set(FLAG_ENABLED, Json::getBool(object, kEnabled, true)); m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash)); @@ -186,6 +188,7 @@ bool xmrig::Pool::isEqual(const Pool &other) const && m_keepAlive == other.m_keepAlive && m_port == other.m_port && m_algorithm == other.m_algorithm + && m_coin == other.m_coin && m_fingerprint == other.m_fingerprint && m_host == other.m_host && m_password == other.m_password @@ -268,6 +271,7 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const Value obj(kObjectType); obj.AddMember(StringRef(kAlgo), m_algorithm.toJSON(), allocator); + obj.AddMember(StringRef(kCoin), m_coin.toJSON(), allocator); obj.AddMember(StringRef(kUrl), m_url.toJSON(), allocator); obj.AddMember(StringRef(kUser), m_user.toJSON(), allocator); diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index 36c3ed1b..15d31ccc 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -32,7 +32,7 @@ #include "base/tools/String.h" -#include "crypto/common/Algorithm.h" +#include "crypto/common/Coin.h" #include "rapidjson/fwd.h" @@ -74,6 +74,7 @@ public: inline bool isTLS() const { return m_flags.test(FLAG_TLS); } inline bool isValid() const { return !m_host.isNull() && m_port > 0; } inline const Algorithm &algorithm() const { return m_algorithm; } + inline const Coin &coin() const { return m_coin; } inline const String &fingerprint() const { return m_fingerprint; } inline const String &host() const { return m_host; } inline const String &password() const { return !m_password.isNull() ? m_password : kDefaultPassword; } @@ -107,6 +108,7 @@ private: bool parseIPv6(const char *addr); Algorithm m_algorithm; + Coin m_coin; int m_keepAlive; std::bitset m_flags; String m_fingerprint; diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index 4641ecd4..600c97ed 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -135,11 +135,12 @@ void xmrig::Pools::print() const { size_t i = 1; for (const Pool &pool : m_data) { - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") CSI "1;%dm%s" CLEAR " algo " WHITE_BOLD("%s"), + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") CSI "1;%dm%s" CLEAR " %s " WHITE_BOLD("%s"), i, (pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31), pool.url().data(), - pool.algorithm().isValid() ? pool.algorithm().shortName() : "auto" + pool.coin().isValid() ? "coin" : "algo", + pool.coin().isValid() ? pool.coin().name() : (pool.algorithm().isValid() ? pool.algorithm().shortName() : "auto") ); i++; diff --git a/src/config.json b/src/config.json index c9f53f26..3041407d 100644 --- a/src/config.json +++ b/src/config.json @@ -34,6 +34,7 @@ "pools": [ { "algo": null, + "coin": null, "url": "donate.v2.xmrig.com:3333", "user": "YOUR_WALLET_ADDRESS", "pass": "x", diff --git a/src/core/config/Config_default.h b/src/core/config/Config_default.h index c8b2e6e6..b811540a 100644 --- a/src/core/config/Config_default.h +++ b/src/core/config/Config_default.h @@ -68,6 +68,7 @@ R"===( "pools": [ { "algo": null, + "coin": null, "url": "donate.v2.xmrig.com:3333", "user": "YOUR_WALLET_ADDRESS", "pass": "x", diff --git a/src/core/config/Config_platform.h b/src/core/config/Config_platform.h index b7415f4d..649e6725 100644 --- a/src/core/config/Config_platform.h +++ b/src/core/config/Config_platform.h @@ -45,6 +45,7 @@ static const char short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:S"; static const option options[] = { { "algo", 1, nullptr, IConfig::AlgorithmKey }, + { "coin", 1, nullptr, IConfig::CoinKey }, { "api-worker-id", 1, nullptr, IConfig::ApiWorkerIdKey }, { "api-id", 1, nullptr, IConfig::ApiIdKey }, { "http-enabled", 0, nullptr, IConfig::HttpEnabledKey }, diff --git a/src/core/config/usage.h b/src/core/config/usage.h index b41ec6db..3f172427 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -60,6 +60,7 @@ Options:\n\ rx/wow, rx/loki\n" #endif "\ + --coin=COIN specify coin instead of algorithm\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ -u, --user=USERNAME username for mining server\n\ diff --git a/src/crypto/common/Coin.cpp b/src/crypto/common/Coin.cpp new file mode 100644 index 00000000..f5a32851 --- /dev/null +++ b/src/crypto/common/Coin.cpp @@ -0,0 +1,103 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "crypto/common/Coin.h" +#include "rapidjson/document.h" + + +#include + + +#ifdef _MSC_VER +# define strcasecmp _stricmp +#endif + + +namespace xmrig { + + +struct CoinName +{ + const char *name; + const Coin::Id id; +}; + + +static CoinName const coin_names[] = { + { "monero", Coin::MONERO }, + { "xmr", Coin::MONERO }, +}; + + +} /* namespace xmrig */ + + + +xmrig::Algorithm::Id xmrig::Coin::algorithm(uint8_t blobVersion) const +{ + if (id() == MONERO) { + return (blobVersion >= 12) ? Algorithm::RX_0 : Algorithm::CN_R; + } + + return Algorithm::INVALID; +} + + + +const char *xmrig::Coin::name() const +{ + for (const auto &i : coin_names) { + if (i.id == m_id) { + return i.name; + } + } + + return nullptr; +} + + +rapidjson::Value xmrig::Coin::toJSON() const +{ + using namespace rapidjson; + + return isValid() ? Value(StringRef(name())) : Value(kNullType); +} + + +xmrig::Coin::Id xmrig::Coin::parse(const char *name) +{ + if (name == nullptr || strlen(name) < 3) { + return INVALID; + } + + for (const auto &i : coin_names) { + if (strcasecmp(name, i.name) == 0) { + return i.id; + } + } + + return INVALID; +} diff --git a/src/crypto/common/Coin.h b/src/crypto/common/Coin.h new file mode 100644 index 00000000..779d60b8 --- /dev/null +++ b/src/crypto/common/Coin.h @@ -0,0 +1,75 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_COIN_H +#define XMRIG_COIN_H + + +#include "crypto/common/Algorithm.h" +#include "rapidjson/fwd.h" + + +namespace xmrig { + + +class Coin +{ +public: + enum Id : int { + INVALID = -1, + MONERO, + }; + + + Coin() = default; + inline Coin(const char *name) : m_id(parse(name)) {} + inline Coin(Id id) : m_id(id) {} + + + inline bool isEqual(const Coin &other) const { return m_id == other.m_id; } + inline bool isValid() const { return m_id != INVALID; } + inline Id id() const { return m_id; } + + Algorithm::Id algorithm(uint8_t blobVersion) const; + const char *name() const; + rapidjson::Value toJSON() const; + + inline bool operator!=(Coin::Id id) const { return m_id != id; } + inline bool operator!=(const Coin &other) const { return !isEqual(other); } + inline bool operator==(Coin::Id id) const { return m_id == id; } + inline bool operator==(const Coin &other) const { return isEqual(other); } + inline operator Coin::Id() const { return m_id; } + + static Id parse(const char *name); + +private: + Id m_id = INVALID; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_COIN_H */ From 550e3329092417928c0b2ec796d2a14698938f5f Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 27 Sep 2019 23:39:57 +0700 Subject: [PATCH 05/10] Fixed coin option in daemon mode. --- src/base/net/stratum/DaemonClient.cpp | 6 +++++- src/base/net/stratum/Pool.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 0c141c7d..0870dc1d 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -25,7 +25,7 @@ #include -#include +#include #include "3rdparty/http-parser/http_parser.h" @@ -225,6 +225,10 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) job.setDiff(Json::getUint64(params, "difficulty")); job.setId(blocktemplate.data() + blocktemplate.size() - 32); + if (m_pool.coin().isValid()) { + job.setAlgorithm(m_pool.coin().algorithm(job.blob()[0])); + } + m_job = std::move(job); m_blocktemplate = std::move(blocktemplate); m_prevHash = Json::getString(params, "prev_hash"); diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index 1b9adfc4..15586fe8 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -174,7 +174,7 @@ bool xmrig::Pool::isEnabled() const } # endif - if (isDaemon() && !algorithm().isValid()) { + if (isDaemon() && (!algorithm().isValid() && !coin().isValid())) { return false; } From d086318f4e30f6bd1860d3832da089f28966a4e1 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 28 Sep 2019 03:25:03 +0700 Subject: [PATCH 06/10] Set "rx/0" as user visible RandomX name. --- src/crypto/common/Algorithm.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index d3e3fa89..6b5e32c7 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -107,9 +107,8 @@ static AlgoName const algorithm_names[] = { { "cryptonight_turtle", "cn_turtle", Algorithm::CN_PICO_0 }, # endif # ifdef XMRIG_ALGO_RANDOMX + { "randomx/0", "rx/0", Algorithm::RX_0 }, { "randomx/test", "rx/test", Algorithm::RX_0 }, - { "randomx/0", "rx/0", Algorithm::RX_0 }, - { "randomx/0", "rx/0", Algorithm::RX_0 }, { "RandomX", "rx", Algorithm::RX_0 }, { "randomx/wow", "rx/wow", Algorithm::RX_WOW }, { "RandomWOW", nullptr, Algorithm::RX_WOW }, From 17b40ac4ad9f5c15c8801236976ac0efa7190e67 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 28 Sep 2019 03:40:53 +0700 Subject: [PATCH 07/10] v3.2.0-dev --- CHANGELOG.md | 4 ++++ src/version.h | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a3cda0c..45eb61bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v3.2.0 +- Added per pool option `coin` with single possible value `monero` for pools without algorithm negotiation, for upcoming Monero fork. +- [#1183](https://github.com/xmrig/xmrig/issues/1183) Fixed compatibility with systemd. + # v3.1.3 - [#1180](https://github.com/xmrig/xmrig/issues/1180) Fixed possible duplicated shares after algorithm switching. - Fixed wrong config file permissions after write (only gcc builds on recent Windows 10 affected). diff --git a/src/version.h b/src/version.h index 81e2bcce..9e2cdcc5 100644 --- a/src/version.h +++ b/src/version.h @@ -28,15 +28,15 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "3.1.4-dev" +#define APP_VERSION "3.2.0-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" #define APP_KIND "cpu" #define APP_VER_MAJOR 3 -#define APP_VER_MINOR 1 -#define APP_VER_PATCH 4 +#define APP_VER_MINOR 2 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From 9ad174c1296699fc04bb860a453e15e6f70b343c Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 28 Sep 2019 08:28:31 +0700 Subject: [PATCH 08/10] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index aff8b3bf..73ae3fb5 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -25,10 +25,9 @@ Since version 3 mining [algorithm](#algorithm-names) should specified for each p | Name | Memory | Version | Notes | |------|--------|---------|-------| +| `rx/0` | 2 MB | 3.2.0+ | RandomX (Monero). | | `argon2/chukwa` | 512 KB | 3.1.0+ | Argon2id (Chukwa). | | `argon2/wrkz` | 256 KB | 3.1.0+ | Argon2id (WRKZ) | -| `rx/test` | 2 MB | 3.0.0+ | RandomX (reference configuration). | -| `rx/0` | 2 MB | 3.0.0+ | RandomX (reference configuration), reserved for future use. | | `rx/wow` | 1 MB | 3.0.0+ | RandomWOW. | | `rx/loki` | 2 MB | 3.0.0+ | RandomXL. | | `cn/fast` | 2 MB | 3.0.0+ | CryptoNight variant 1 with half iterations. | From f96538dfba1125dcd10f78eb8b0fb3264c43783a Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 28 Sep 2019 08:43:31 +0700 Subject: [PATCH 09/10] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index 73ae3fb5..ab22468d 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -1,27 +1,12 @@ # Algorithms -Since version 3 mining [algorithm](#algorithm-names) should specified for each pool separately (`algo` option), earlier versions was use one global `algo` option and per pool `variant` option (this option was removed in v3). If your pool support [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/issues/168) you may not specify this option at all. - -#### Example -```json -{ - "pools": [ - { - "url": "...", - "algo": "cn/r", - ... - } - ], - ... -} -``` +Algorithm can be defined in 3 ways: -#### Pools with mining algorithm negotiation support. +1. By pool, using algorithm negotiation, in this case no need specify algorithm on miner side. +2. Per pool `coin` option, currently only usable value for this option is `monero`. +3. Per pool `algo` option. - * [www.hashvault.pro](https://www.hashvault.pro/) - * [moneroocean.stream](https://moneroocean.stream) - - ## Algorithm names +## Algorithm names | Name | Memory | Version | Notes | |------|--------|---------|-------| @@ -49,3 +34,21 @@ Since version 3 mining [algorithm](#algorithm-names) should specified for each p | `cn-lite/1` | 1 MB | 2.5.0+ | CryptoNight-Lite variant 1. | | `cn-lite/0` | 1 MB | 0.8.0+ | CryptoNight-Lite variant 0. | | `cn/0` | 2 MB | 0.5.0+ | CryptoNight (original). | + +## Migration to v3 +Since version 3 mining [algorithm](#algorithm-names) should specified for each pool separately (`algo` option), earlier versions was use one global `algo` option and per pool `variant` option (this option was removed in v3). If your pool support [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/issues/168) you may not specify this option at all. + +#### Example +```json +{ + "pools": [ + { + "url": "...", + "algo": "cn/r", + "coin": null + ... + } + ], + ... +} +``` From 8e9e8cd16960a785732fdcfe182c91e09c75e42c Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 28 Sep 2019 09:00:50 +0700 Subject: [PATCH 10/10] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index ab22468d..c31ad6c7 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -6,6 +6,8 @@ Algorithm can be defined in 3 ways: 2. Per pool `coin` option, currently only usable value for this option is `monero`. 3. Per pool `algo` option. +Option `coin` useful for pools without algorithm negotiation support or daemon to allow automatically switch algorithm in next hard fork. + ## Algorithm names | Name | Memory | Version | Notes |