From b0ed0df76425b1ce6cdc8002c07f8433c374b436 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 17 Aug 2019 19:54:27 +0700 Subject: [PATCH] Added Argon2 support. --- CMakeLists.txt | 1 + src/base/kernel/config/BaseConfig.cpp | 1 + src/base/kernel/config/BaseConfig.h | 4 +- src/crypto/common/Algorithm.cpp | 74 +++++++++++++++++++-------- src/crypto/common/Algorithm.h | 9 +++- src/version.h | 6 +-- 6 files changed, 68 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83a0823..ccb80fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,7 @@ add_definitions(/DXMRIG_ALGO_CN_LITE) add_definitions(/DXMRIG_ALGO_CN_HEAVY) add_definitions(/DXMRIG_ALGO_CN_PICO) add_definitions(/DXMRIG_ALGO_CN_GPU) +add_definitions(/DXMRIG_ALGO_ARGON2) if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$" AND CMAKE_SIZEOF_VOID_P EQUAL 8) add_definitions(/DRAPIDJSON_SSE2) diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 4600a1f..3da06b5 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -134,6 +134,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) Log::colors = reader.getBool("colors", Log::colors); m_logFile = reader.getString("log-file"); m_userAgent = reader.getString("user-agent"); + m_version = reader.getUint("version"); setPrintTime(reader.getUint("print-time", 60)); diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index c5cf29a..b58c47b 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -56,6 +56,7 @@ public: inline const String &apiId() const { return m_apiId; } inline const String &apiWorkerId() const { return m_apiWorkerId; } inline uint32_t printTime() const { return m_printTime; } + inline uint32_t version() const { return m_version; } inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const String &fileName() const override { return m_fileName; } @@ -80,7 +81,8 @@ protected: String m_fileName; String m_logFile; String m_userAgent; - uint32_t m_printTime; + uint32_t m_printTime = 60; + uint32_t m_version = 0; private: inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index db6cb23..d3e3fa8 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -116,30 +116,17 @@ static AlgoName const algorithm_names[] = { { "randomx/loki", "rx/loki", Algorithm::RX_LOKI }, { "RandomXL", nullptr, Algorithm::RX_LOKI }, # endif +# ifdef XMRIG_ALGO_ARGON2 + { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, + { "chukwa", nullptr, Algorithm::AR2_CHUKWA }, + { "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ }, +# endif }; } /* namespace xmrig */ -int xmrig::Algorithm::maxIntensity() const -{ -# ifdef XMRIG_ALGO_RANDOMX - if (family() == RANDOM_X) { - return 1; - } -# endif - -# ifdef XMRIG_ALGO_CN_GPU - if (m_id == CN_GPU) { - return 1; - } -# endif - - return 5; -} - - rapidjson::Value xmrig::Algorithm::toJSON() const { using namespace rapidjson; @@ -170,6 +157,8 @@ size_t xmrig::Algorithm::l2() const size_t xmrig::Algorithm::l3() const { + constexpr size_t oneMiB = 0x100000; + const Family f = family(); assert(f != UNKNOWN); @@ -179,8 +168,6 @@ size_t xmrig::Algorithm::l3() const # ifdef XMRIG_ALGO_RANDOMX if (f == RANDOM_X) { - constexpr size_t oneMiB = 0x100000; - switch (m_id) { case RX_0: case RX_LOKI: @@ -195,10 +182,49 @@ size_t xmrig::Algorithm::l3() const } # endif +# ifdef XMRIG_ALGO_ARGON2 + if (f == ARGON2) { + switch (m_id) { + case AR2_CHUKWA: + return oneMiB / 2; + + case AR2_WRKZ: + return oneMiB / 4; + + default: + break; + } + } +# endif + return 0; } +uint32_t xmrig::Algorithm::maxIntensity() const +{ +# ifdef XMRIG_ALGO_RANDOMX + if (family() == RANDOM_X) { + return 1; + } +# endif + +# ifdef XMRIG_ALGO_ARGON2 + if (family() == ARGON2) { + return 1; + } +# endif + +# ifdef XMRIG_ALGO_CN_GPU + if (m_id == CN_GPU) { + return 1; + } +# endif + + return 5; +} + + xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) { switch (id) { @@ -244,6 +270,12 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) return RANDOM_X; # endif +# ifdef XMRIG_ALGO_ARGON2 + case AR2_CHUKWA: + case AR2_WRKZ: + return ARGON2; +# endif + case INVALID: case MAX: return UNKNOWN; @@ -273,7 +305,7 @@ const char *xmrig::Algorithm::name(bool shortName) const { for (size_t i = 0; i < ARRAY_SIZE(algorithm_names); i++) { if (algorithm_names[i].id == m_id) { - return shortName ? algorithm_names[i].shortName : algorithm_names[i].name; + return (shortName && algorithm_names[i].shortName) ? algorithm_names[i].shortName : algorithm_names[i].name; } } diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index 92fcc61..5226133 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -72,6 +72,10 @@ public: RX_0, // "rx/0" RandomX (reference configuration). RX_WOW, // "rx/wow" RandomWOW (Wownero). RX_LOKI, // "rx/loki" RandomXL (Loki). +# endif +# ifdef XMRIG_ALGO_ARGON2 + AR2_CHUKWA, // "argon2/chukwa" + AR2_WRKZ, // "argon2/wrkz" # endif MAX }; @@ -82,7 +86,8 @@ public: CN_LITE, CN_HEAVY, CN_PICO, - RANDOM_X + RANDOM_X, + ARGON2 }; inline Algorithm() {} @@ -102,10 +107,10 @@ public: inline bool operator==(const Algorithm &other) const { return isEqual(other); } inline operator Algorithm::Id() const { return m_id; } - int maxIntensity() const; rapidjson::Value toJSON() const; size_t l2() const; size_t l3() const; + uint32_t maxIntensity() const; static Family family(Id id); static Id parse(const char *name); diff --git a/src/version.h b/src/version.h index ff86521..5567947 100644 --- a/src/version.h +++ b/src/version.h @@ -28,15 +28,15 @@ #define APP_ID "xmrig-proxy" #define APP_NAME "xmrig-proxy" #define APP_DESC "XMRig Stratum proxy" -#define APP_VERSION "3.0.1-dev" +#define APP_VERSION "3.1.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 "proxy" #define APP_VER_MAJOR 3 -#define APP_VER_MINOR 0 -#define APP_VER_PATCH 1 +#define APP_VER_MINOR 1 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1920)