From 2b73ac9095aeb753b9e527b954fc84f3e45d5af8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 23 Nov 2023 21:20:41 +0700 Subject: [PATCH 1/5] v6.21.1-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 5ad9a6af..3b022f68 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define APP_ID "xmrig-proxy" #define APP_NAME "xmrig-proxy" #define APP_DESC "XMRig Stratum proxy" -#define APP_VERSION "6.21.0" +#define APP_VERSION "6.21.1-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2023 xmrig.com" @@ -30,7 +30,7 @@ #define APP_VER_MAJOR 6 #define APP_VER_MINOR 21 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 1 #ifdef _MSC_VER # if (_MSC_VER >= 1930) From b5a3aa8c3bd0ff064d1e74b299c771be7e7b7545 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 23 Mar 2024 00:55:29 +0700 Subject: [PATCH 2/5] Fix build with recent libuv. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4519067..f8240144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.5) project(xmrig-proxy) @@ -120,7 +120,7 @@ if (WIN32) ) add_definitions(/DWIN32) - set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv) + set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv dbghelp) elseif (APPLE) set(SOURCES_OS "${SOURCES_OS}" From 4d105d767710c78b201540539cc341970f27581a Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:34:41 +0100 Subject: [PATCH 3/5] Added missing `XMRIG_64_BIT` macro to cmake xmrig-proxy always showed 32 bit in "ABOUT" because of this missing macro. --- cmake/os.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/os.cmake b/cmake/os.cmake index c9e46165..005583f1 100644 --- a/cmake/os.cmake +++ b/cmake/os.cmake @@ -43,3 +43,10 @@ elseif(XMRIG_OS_UNIX) add_definitions(/DXMRIG_OS_FREEBSD) endif() endif() + +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(XMRIG_64_BIT ON) + add_definitions(-DXMRIG_64_BIT) +else() + set(XMRIG_64_BIT OFF) +endif() From c360e95ff52fec244b20e3a1371423d6fa5661f5 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 26 Mar 2024 21:44:41 +0700 Subject: [PATCH 4/5] Sync changes with XMRig. --- CHANGELOG.md | 6 ++ src/base/api/Api.cpp | 33 ++++++--- src/base/api/Api.h | 4 +- src/base/crypto/Coin.cpp | 1 + src/base/crypto/Coin.h | 1 + src/base/io/log/FileLogWriter.cpp | 74 +++++++++++++++++---- src/base/io/log/FileLogWriter.h | 18 ++++- src/base/net/http/HttpApiResponse.cpp | 7 +- src/base/net/stratum/Client.cpp | 8 +-- src/base/net/stratum/Pool.h | 12 ++-- src/base/tools/cryptonote/BlockTemplate.cpp | 19 +++++- src/base/tools/cryptonote/WalletAddress.cpp | 37 ++++++++++- 12 files changed, 175 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59bb8825..580c3205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v6.21.1 +- The dependencies of all prebuilt releases have been updated. Support for old Ubuntu releases has been dropped. +- [#3391](https://github.com/xmrig/xmrig/pull/3391) Added support for townforge (monero fork using randomx). +- [#3420](https://github.com/xmrig/xmrig/pull/3420) Fixed segfault in HTTP API rebind. +- [#3436](https://github.com/xmrig/xmrig/pull/3436) Fixed, the file log writer was not thread-safe. + # v6.21.0 - [#548](https://github.com/xmrig/xmrig-proxy/pull/548) Sync changes with XMRig. - [#553](https://github.com/xmrig/xmrig-proxy/pull/553) Fixes for **Zephyr** solo mining. diff --git a/src/base/api/Api.cpp b/src/base/api/Api.cpp index ea78c35e..77f8e4aa 100644 --- a/src/base/api/Api.cpp +++ b/src/base/api/Api.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2023 SChernykh - * Copyright (c) 2016-2023 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 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 @@ -25,6 +25,8 @@ #include "base/crypto/keccak.h" #include "base/io/Env.h" #include "base/io/json/Json.h" +#include "base/io/log/Log.h" +#include "base/io/log/Tags.h" #include "base/kernel/Base.h" #include "base/tools/Chrono.h" #include "base/tools/Cvt.h" @@ -91,7 +93,11 @@ xmrig::Api::Api(Base *base) : xmrig::Api::~Api() { # ifdef XMRIG_FEATURE_HTTP - delete m_httpd; + if (m_httpd) { + m_httpd->stop(); + delete m_httpd; + m_httpd = nullptr; // Ensure the pointer is set to nullptr after deletion + } # endif } @@ -109,8 +115,15 @@ void xmrig::Api::start() genWorkerId(m_base->config()->apiWorkerId()); # ifdef XMRIG_FEATURE_HTTP - m_httpd = new Httpd(m_base); - m_httpd->start(); + if (!m_httpd) { + m_httpd = new Httpd(m_base); + if (!m_httpd->start()) { + LOG_ERR("%s " RED_BOLD("HTTP API server failed to start."), Tags::network()); + + delete m_httpd; // Properly handle failure to start + m_httpd = nullptr; + } + } # endif } @@ -118,7 +131,9 @@ void xmrig::Api::start() void xmrig::Api::stop() { # ifdef XMRIG_FEATURE_HTTP - m_httpd->stop(); + if (m_httpd) { + m_httpd->stop(); + } # endif } @@ -126,13 +141,15 @@ void xmrig::Api::stop() void xmrig::Api::tick() { # ifdef XMRIG_FEATURE_HTTP - if (m_httpd->isBound() || !m_base->config()->http().isEnabled()) { + if (!m_httpd || !m_base->config()->http().isEnabled() || m_httpd->isBound()) { return; } if (++m_ticks % 10 == 0) { m_ticks = 0; - m_httpd->start(); + if (m_httpd) { + m_httpd->start(); + } } # endif } diff --git a/src/base/api/Api.h b/src/base/api/Api.h index 7c686ff4..f3ad04c1 100644 --- a/src/base/api/Api.h +++ b/src/base/api/Api.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2023 SChernykh - * Copyright (c) 2016-2023 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/base/crypto/Coin.cpp b/src/base/crypto/Coin.cpp index 2508e9cc..c528acec 100644 --- a/src/base/crypto/Coin.cpp +++ b/src/base/crypto/Coin.cpp @@ -54,6 +54,7 @@ static const CoinInfo coinInfo[] = { { Algorithm::KAWPOW_RVN, "RVN", "Ravencoin", 0, 0, BLUE_BG_BOLD( WHITE_BOLD_S " raven ") }, { Algorithm::RX_WOW, "WOW", "Wownero", 300, 100000000000, MAGENTA_BG_BOLD(WHITE_BOLD_S " wownero ") }, { Algorithm::RX_0, "ZEPH", "Zephyr", 120, 1000000000000, BLUE_BG_BOLD( WHITE_BOLD_S " zephyr ") }, + { Algorithm::RX_0, "Townforge","Townforge", 30, 100000000, MAGENTA_BG_BOLD(WHITE_BOLD_S " townforge ") }, }; diff --git a/src/base/crypto/Coin.h b/src/base/crypto/Coin.h index 166618b1..12ac1497 100644 --- a/src/base/crypto/Coin.h +++ b/src/base/crypto/Coin.h @@ -40,6 +40,7 @@ class Coin RAVEN, WOWNERO, ZEPHYR, + TOWNFORGE, MAX }; diff --git a/src/base/io/log/FileLogWriter.cpp b/src/base/io/log/FileLogWriter.cpp index b41f7f39..a449dc9a 100644 --- a/src/base/io/log/FileLogWriter.cpp +++ b/src/base/io/log/FileLogWriter.cpp @@ -22,7 +22,6 @@ #include -#include namespace xmrig { @@ -40,6 +39,32 @@ static void fsWriteCallback(uv_fs_t *req) } // namespace xmrig +xmrig::FileLogWriter::FileLogWriter() +{ + init(); +} + +xmrig::FileLogWriter::FileLogWriter(const char* fileName) +{ + init(); + open(fileName); +} + +xmrig::FileLogWriter::~FileLogWriter() +{ + uv_close(reinterpret_cast(&m_flushAsync), nullptr); + + uv_mutex_destroy(&m_buffersLock); +} + +void xmrig::FileLogWriter::init() +{ + uv_mutex_init(&m_buffersLock); + + uv_async_init(uv_default_loop(), &m_flushAsync, on_flush); + m_flushAsync.data = this; +} + bool xmrig::FileLogWriter::open(const char *fileName) { assert(fileName != nullptr); @@ -77,11 +102,12 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size) uv_buf_t buf = uv_buf_init(new char[size], size); memcpy(buf.base, data, size); - auto req = new uv_fs_t; - req->data = buf.base; + uv_mutex_lock(&m_buffersLock); - uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, m_pos, fsWriteCallback); - m_pos += size; + m_buffers.emplace_back(buf); + uv_async_send(&m_flushAsync); + + uv_mutex_unlock(&m_buffersLock); return true; } @@ -89,18 +115,38 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size) bool xmrig::FileLogWriter::writeLine(const char *data, size_t size) { - const uv_buf_t buf[2] = { - uv_buf_init(new char[size], size), - uv_buf_init(const_cast(m_endl), sizeof(m_endl) - 1) - }; + if (!isOpen()) { + return false; + } + + constexpr size_t N = sizeof(m_endl) - 1; + + uv_buf_t buf = uv_buf_init(new char[size + N], size + N); + memcpy(buf.base, data, size); + memcpy(buf.base + size, m_endl, N); - memcpy(buf[0].base, data, size); + uv_mutex_lock(&m_buffersLock); - auto req = new uv_fs_t; - req->data = buf[0].base; + m_buffers.emplace_back(buf); + uv_async_send(&m_flushAsync); - uv_fs_write(uv_default_loop(), req, m_file, buf, 2, m_pos, fsWriteCallback); - m_pos += (buf[0].len + buf[1].len); + uv_mutex_unlock(&m_buffersLock); return true; } + +void xmrig::FileLogWriter::flush() +{ + uv_mutex_lock(&m_buffersLock); + + for (uv_buf_t buf : m_buffers) { + uv_fs_t* req = new uv_fs_t; + req->data = buf.base; + + uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, m_pos, fsWriteCallback); + m_pos += buf.len; + } + m_buffers.clear(); + + uv_mutex_unlock(&m_buffersLock); +} diff --git a/src/base/io/log/FileLogWriter.h b/src/base/io/log/FileLogWriter.h index f3606aa3..66b8a13c 100644 --- a/src/base/io/log/FileLogWriter.h +++ b/src/base/io/log/FileLogWriter.h @@ -22,6 +22,8 @@ #include #include +#include +#include namespace xmrig { @@ -30,8 +32,10 @@ namespace xmrig { class FileLogWriter { public: - FileLogWriter() = default; - FileLogWriter(const char *fileName) { open(fileName); } + FileLogWriter(); + FileLogWriter(const char* fileName); + + ~FileLogWriter(); inline bool isOpen() const { return m_file >= 0; } inline int64_t pos() const { return m_pos; } @@ -49,6 +53,16 @@ class FileLogWriter int m_file = -1; int64_t m_pos = 0; + + uv_mutex_t m_buffersLock; + std::vector m_buffers; + + uv_async_t m_flushAsync; + + void init(); + + static void on_flush(uv_async_t* async) { reinterpret_cast(async->data)->flush(); } + void flush(); }; diff --git a/src/base/net/http/HttpApiResponse.cpp b/src/base/net/http/HttpApiResponse.cpp index e6758df9..3ee38a09 100644 --- a/src/base/net/http/HttpApiResponse.cpp +++ b/src/base/net/http/HttpApiResponse.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2014-2019 heapwolf - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 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 @@ -17,7 +17,6 @@ * along with this program. If not, see . */ - #include "base/net/http/HttpApiResponse.h" #include "3rdparty/rapidjson/prettywriter.h" #include "3rdparty/rapidjson/stringbuffer.h" @@ -65,7 +64,7 @@ void xmrig::HttpApiResponse::end() } } - if (!m_doc.MemberCount()) { + if (m_doc.IsObject() && m_doc.ObjectEmpty()) { return HttpResponse::end(); } diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 50e35bcc..54246e72 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2019 jtgrassie - * Copyright (c) 2018-2023 SChernykh - * Copyright (c) 2016-2023 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 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 @@ -609,7 +609,7 @@ bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code) parseExtensions(result); - const bool rc = parseJob(result["job"], code); + const bool rc = parseJob(Json::getObject(result, "job"), code); m_jobs = 0; return rc; @@ -844,7 +844,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co m_listener->onLoginSuccess(this); if (m_job.isValid()) { - m_listener->onJobReceived(this, m_job, result["job"]); + m_listener->onJobReceived(this, m_job, Json::getObject(result, "job")); } return; diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index a8beee62..a78eb6bb 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2019 Howard Chu - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 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 @@ -59,7 +59,7 @@ class Pool static const char *kCoin; static const char *kDaemon; static const char *kDaemonPollInterval; - static const char* kDaemonJobTimeout; + static const char *kDaemonJobTimeout; static const char *kEnabled; static const char *kFingerprint; static const char *kKeepalive; @@ -70,11 +70,11 @@ class Pool static const char *kSOCKS5; static const char *kSubmitToOrigin; static const char *kTls; - static const char* kSni; + static const char *kSni; static const char *kUrl; static const char *kUser; - static const char* kSpendSecretKey; - static const char* kDaemonZMQPort; + static const char *kSpendSecretKey; + static const char *kDaemonZMQPort; static const char *kNicehashHost; constexpr static int kKeepAliveTimeout = 60; diff --git a/src/base/tools/cryptonote/BlockTemplate.cpp b/src/base/tools/cryptonote/BlockTemplate.cpp index 1a26a914..310fedf4 100644 --- a/src/base/tools/cryptonote/BlockTemplate.cpp +++ b/src/base/tools/cryptonote/BlockTemplate.cpp @@ -1,8 +1,8 @@ /* XMRig * Copyright (c) 2012-2013 The Cryptonote developers * Copyright (c) 2014-2021 The Monero Project - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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 @@ -207,7 +207,11 @@ bool xmrig::BlockTemplate::parse(bool hashes) setOffset(MINER_TX_PREFIX_OFFSET, ar.index()); ar(m_txVersion); - ar(m_unlockTime); + + if (m_coin != Coin::TOWNFORGE) { + ar(m_unlockTime); + } + ar(m_numInputs); // must be 1 input @@ -280,6 +284,10 @@ bool xmrig::BlockTemplate::parse(bool hashes) ar(m_viewTag); } + if (m_coin == Coin::TOWNFORGE) { + ar(m_unlockTime); + } + ar(m_extraSize); setOffset(TX_EXTRA_OFFSET, ar.index()); @@ -335,6 +343,11 @@ bool xmrig::BlockTemplate::parse(bool hashes) uint8_t vin_rct_type = 0; ar(vin_rct_type); + // no way I'm parsing a full game update here + if (m_coin == Coin::TOWNFORGE && m_height % 720 == 0) { + return true; + } + // must be RCTTypeNull (0) if (vin_rct_type != 0) { return false; diff --git a/src/base/tools/cryptonote/WalletAddress.cpp b/src/base/tools/cryptonote/WalletAddress.cpp index f9b8a9f7..3719031a 100644 --- a/src/base/tools/cryptonote/WalletAddress.cpp +++ b/src/base/tools/cryptonote/WalletAddress.cpp @@ -1,8 +1,8 @@ /* XMRig * Copyright (c) 2012-2013 The Cryptonote developers * Copyright (c) 2014-2021 The Monero Project - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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,6 +33,25 @@ bool xmrig::WalletAddress::decode(const char *address, size_t size) { + uint64_t tf_tag = 0; + if (size >= 4 && !strncmp(address, "TF", 2)) { + tf_tag = 0x424200; + switch (address[2]) + { + case '1': tf_tag |= 0; break; + case '2': tf_tag |= 1; break; + default: tf_tag = 0; return false; + } + switch (address[3]) { + case 'M': tf_tag |= 0; break; + case 'T': tf_tag |= 0x10; break; + case 'S': tf_tag |= 0x20; break; + default: tf_tag = 0; return false; + } + address += 4; + size -= 4; + } + static constexpr std::array block_sizes{ 0, 2, 3, 5, 6, 7, 9, 10, 11 }; static constexpr char alphabet[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; constexpr size_t alphabet_size = sizeof(alphabet) - 1; @@ -114,6 +133,10 @@ bool xmrig::WalletAddress::decode(const char *address, size_t size) if (memcmp(m_checksum, md, sizeof(m_checksum)) == 0) { m_data = { address, size }; + if (tf_tag) { + m_tag = tf_tag; + } + return true; } } @@ -228,6 +251,16 @@ const xmrig::WalletAddress::TagInfo &xmrig::WalletAddress::tagInfo(uint64_t tag) { 0x54, { Coin::GRAFT, TESTNET, PUBLIC, 28881, 28882 } }, { 0x55, { Coin::GRAFT, TESTNET, INTEGRATED, 28881, 28882 } }, { 0x70, { Coin::GRAFT, TESTNET, SUBADDRESS, 28881, 28882 } }, + + { 0x424200, { Coin::TOWNFORGE, MAINNET, PUBLIC, 18881, 18882 } }, + { 0x424201, { Coin::TOWNFORGE, MAINNET, SUBADDRESS, 18881, 18882 } }, + + { 0x424210, { Coin::TOWNFORGE, TESTNET, PUBLIC, 28881, 28882 } }, + { 0x424211, { Coin::TOWNFORGE, TESTNET, SUBADDRESS, 28881, 28882 } }, + + { 0x424220, { Coin::TOWNFORGE, STAGENET, PUBLIC, 38881, 38882 } }, + { 0x424221, { Coin::TOWNFORGE, STAGENET, SUBADDRESS, 38881, 38882 } }, + }; const auto it = tags.find(tag); From 704060b59a8cbbaf7aaf1bb4b6a378b561f4741e Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 26 Mar 2024 22:07:45 +0700 Subject: [PATCH 5/5] v6.21.1 --- src/version.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/version.h b/src/version.h index 3b022f68..53d35aae 100644 --- a/src/version.h +++ b/src/version.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2023 SChernykh - * Copyright (c) 2016-2023 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,10 +22,10 @@ #define APP_ID "xmrig-proxy" #define APP_NAME "xmrig-proxy" #define APP_DESC "XMRig Stratum proxy" -#define APP_VERSION "6.21.1-dev" +#define APP_VERSION "6.21.1" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" -#define APP_COPYRIGHT "Copyright (C) 2016-2023 xmrig.com" +#define APP_COPYRIGHT "Copyright (C) 2016-2024 xmrig.com" #define APP_KIND "proxy" #define APP_VER_MAJOR 6