diff --git a/CMakeLists.txt b/CMakeLists.txt index d8e71cb..6921dde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,7 @@ add_definitions(/DXMRIG_ALGO_CN_HEAVY) add_definitions(/DXMRIG_ALGO_CN_PICO) add_definitions(/DXMRIG_ALGO_CN_GPU) add_definitions(/DXMRIG_ALGO_ARGON2) +add_definitions(/DXMRIG_ALGO_ASTROBWT) if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$" AND CMAKE_SIZEOF_VOID_P EQUAL 8) add_definitions(/DRAPIDJSON_SSE2) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index bf22e61..edae8be 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -59,12 +59,14 @@ static const char *kHash = "hash"; static const char *kHeight = "height"; static const char *kJsonRPC = "/json_rpc"; +static const size_t BlobReserveSize = 8; + } xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) : BaseClient(id, listener), - m_monero(true) + m_apiVersion(API_MONERO) { m_httpListener = std::make_shared(this); m_timer = new Timer(this); @@ -103,17 +105,25 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result) return -1; } + char *data = (m_apiVersion == API_DERO) ? m_blockhashingblob.data() : m_blocktemplate.data(); + # ifdef XMRIG_PROXY_PROJECT - memcpy(m_blocktemplate.data() + 78, result.nonce, 8); + memcpy(data + 78, result.nonce, 8); # else - Buffer::toHex(reinterpret_cast(&result.nonce), 4, m_blocktemplate.data() + 78); + Buffer::toHex(reinterpret_cast(&result.nonce), 4, data + 78); # endif using namespace rapidjson; Document doc(kObjectType); Value params(kArrayType); - params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator()); + if (m_apiVersion == API_DERO) { + params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator()); + params.PushBack(m_blockhashingblob.toJSON(), doc.GetAllocator()); + } + else { + params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator()); + } JsonRequest::create(doc, m_sequence, "submitblock", params); @@ -131,6 +141,10 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result) void xmrig::DaemonClient::connect() { + if ((m_pool.algorithm() == Algorithm::ASTROBWT_DERO) || (m_pool.coin() == Coin::DERO)) { + m_apiVersion = API_DERO; + } + setState(ConnectingState); getBlockTemplate(); } @@ -172,7 +186,7 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data) if (data.method == HTTP_GET) { if (data.url == kGetHeight) { if (!doc.HasMember(kHash)) { - m_monero = false; + m_apiVersion = API_CRYPTONOTE_DEFAULT; return send(HTTP_GET, kGetInfo); } @@ -200,7 +214,21 @@ void xmrig::DaemonClient::onTimer(const Timer *) getBlockTemplate(); } else if (m_state == ConnectedState) { - send(HTTP_GET, m_monero ? kGetHeight : kGetInfo); + if (m_apiVersion == API_DERO) { + using namespace rapidjson; + Document doc(kObjectType); + auto& allocator = doc.GetAllocator(); + + doc.AddMember("id", m_sequence, allocator); + doc.AddMember("jsonrpc", "2.0", allocator); + doc.AddMember("method", "get_info", allocator); + + send(HTTP_POST, kJsonRPC, doc); + ++m_sequence; + } + else { + send(HTTP_GET, (m_apiVersion == API_MONERO) ? kGetHeight : kGetInfo); + } } } @@ -216,7 +244,14 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) Job job(false, m_pool.algorithm(), String()); String blocktemplate = Json::getString(params, kBlocktemplateBlob); - if (blocktemplate.isNull() || !job.setBlob(Json::getString(params, "blockhashing_blob"))) { + + m_blockhashingblob = Json::getString(params, "blockhashing_blob"); + if (m_apiVersion == API_DERO) { + const uint64_t offset = Json::getUint64(params, "reserved_offset"); + Buffer::toHex(Buffer::randomBytes(BlobReserveSize).data(), BlobReserveSize, m_blockhashingblob.data() + offset * 2); + } + + if (blocktemplate.isNull() || !job.setBlob(m_blockhashingblob)) { *code = 4; return false; } @@ -263,6 +298,13 @@ bool xmrig::DaemonClient::parseResponse(int64_t id, const rapidjson::Value &resu return false; } + if (result.HasMember("top_block_hash")) { + if (m_prevHash != Json::getString(result, "top_block_hash")) { + getBlockTemplate(); + } + return true; + } + int code = -1; if (result.HasMember(kBlocktemplateBlob) && parseJob(result, &code)) { return true; @@ -286,7 +328,12 @@ int64_t xmrig::DaemonClient::getBlockTemplate() Value params(kObjectType); params.AddMember("wallet_address", m_user.toJSON(), allocator); - params.AddMember("extra_nonce", Buffer::randomBytes(8).toHex().toJSON(doc), allocator); + if (m_apiVersion == API_DERO) { + params.AddMember("reserve_size", BlobReserveSize, allocator); + } + else { + params.AddMember("extra_nonce", Buffer::randomBytes(BlobReserveSize).toHex().toJSON(doc), allocator); + } JsonRequest::create(doc, m_sequence, "getblocktemplate", params); @@ -338,6 +385,10 @@ void xmrig::DaemonClient::send(int method, const char *url, const char *data, si client->setQuiet(isQuiet()); client->connect(m_pool.host(), m_pool.port()); + + if (method != HTTP_GET) { + client->headers.insert({ "Content-Type", "application/json" }); + } } diff --git a/src/base/net/stratum/DaemonClient.h b/src/base/net/stratum/DaemonClient.h index adaef14..0b14f5d 100644 --- a/src/base/net/stratum/DaemonClient.h +++ b/src/base/net/stratum/DaemonClient.h @@ -76,9 +76,15 @@ private: void send(int method, const char *url, const rapidjson::Document &doc); void setState(SocketState state); - bool m_monero; + enum { + API_CRYPTONOTE_DEFAULT, + API_MONERO, + API_DERO, + } m_apiVersion; + std::shared_ptr m_httpListener; String m_blocktemplate; + String m_blockhashingblob; String m_prevHash; String m_tlsFingerprint; String m_tlsVersion; diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 2a5f7d5..0b3904f 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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,8 +25,6 @@ #include "crypto/common/Algorithm.h" - - #include "crypto/cn/CnAlgo.h" #include "rapidjson/document.h" @@ -124,6 +122,10 @@ static AlgoName const algorithm_names[] = { { "chukwa", nullptr, Algorithm::AR2_CHUKWA }, { "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ }, # endif +# ifdef XMRIG_ALGO_ASTROBWT + { "astrobwt", nullptr, Algorithm::ASTROBWT_DERO }, + { "astrobwt/dero", nullptr, Algorithm::ASTROBWT_DERO }, +# endif }; @@ -210,6 +212,18 @@ size_t xmrig::Algorithm::l3() const } # endif +# ifdef XMRIG_ALGO_ASTROBWT + if (f == ASTROBWT) { + switch (m_id) { + case ASTROBWT_DERO: + return oneMiB * 20; + + default: + break; + } + } +# endif + return 0; } @@ -228,6 +242,12 @@ uint32_t xmrig::Algorithm::maxIntensity() const } # endif +# ifdef XMRIG_ALGO_ASTROBWT + if (family() == ASTROBWT) { + return 1; + } +# endif + # ifdef XMRIG_ALGO_CN_GPU if (m_id == CN_GPU) { return 1; @@ -291,6 +311,11 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) return ARGON2; # endif +# ifdef XMRIG_ALGO_ASTROBWT + case ASTROBWT_DERO: + return ASTROBWT; +# endif + default: break; } diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index 7f87283..fa821f2 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -71,6 +71,7 @@ public: RX_SFX, // "rx/sfx" RandomSFX (Safex Cash). AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa). AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ) + ASTROBWT_DERO, // "astrobwt" AstroBWT (Dero) MAX }; @@ -81,7 +82,8 @@ public: CN_HEAVY, CN_PICO, RANDOM_X, - ARGON2 + ARGON2, + ASTROBWT }; inline Algorithm() = default; diff --git a/src/crypto/common/Coin.cpp b/src/crypto/common/Coin.cpp index 32a1ff5..f8f3894 100644 --- a/src/crypto/common/Coin.cpp +++ b/src/crypto/common/Coin.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -50,7 +50,8 @@ static CoinName const coin_names[] = { { "monero", Coin::MONERO }, { "xmr", Coin::MONERO }, { "arqma", Coin::ARQMA }, - { "arq", Coin::ARQMA } + { "arq", Coin::ARQMA }, + { "dero", Coin::DERO }, }; @@ -67,6 +68,9 @@ xmrig::Algorithm::Id xmrig::Coin::algorithm(uint8_t blobVersion) const case ARQMA: return (blobVersion >= 15) ? Algorithm::RX_ARQ : Algorithm::CN_PICO_0; + case DERO: + return (blobVersion >= 4) ? Algorithm::ASTROBWT_DERO : Algorithm::CN_0; + case INVALID: break; } diff --git a/src/crypto/common/Coin.h b/src/crypto/common/Coin.h index 3df3784..d4b2aaa 100644 --- a/src/crypto/common/Coin.h +++ b/src/crypto/common/Coin.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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,8 @@ public: enum Id : int { INVALID = -1, MONERO, - ARQMA + ARQMA, + DERO };