From c4e136314815f6892136f6be604121143fed10f9 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 7 Apr 2023 23:35:05 +0700 Subject: [PATCH] #3245 Improved algorithm negotiation for donation rounds by sending extra information about current mining job. --- src/crypto/kawpow/KPHash.h | 18 +++++------ src/net/Network.cpp | 7 ++--- src/net/Network.h | 8 ++--- src/net/strategies/DonateStrategy.cpp | 45 ++++++++++++++++++--------- src/net/strategies/DonateStrategy.h | 21 +++++++------ 5 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/crypto/kawpow/KPHash.h b/src/crypto/kawpow/KPHash.h index 15bb19023..7ce2d75e1 100644 --- a/src/crypto/kawpow/KPHash.h +++ b/src/crypto/kawpow/KPHash.h @@ -7,8 +7,8 @@ * Copyright 2017-2019 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2018-2019 tevador - * Copyright 2018-2020 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2023 SChernykh + * Copyright 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 @@ -28,7 +28,7 @@ #define XMRIG_KP_HASH_H -#include +#include namespace xmrig @@ -43,16 +43,16 @@ class KPHash public: static constexpr uint32_t EPOCH_LENGTH = 7500; static constexpr uint32_t PERIOD_LENGTH = 3; - static constexpr int CNT_CACHE = 11; - static constexpr int CNT_MATH = 18; - static constexpr uint32_t REGS = 32; - static constexpr uint32_t LANES = 16; + static constexpr int CNT_CACHE = 11; + static constexpr int CNT_MATH = 18; + static constexpr uint32_t REGS = 32; + static constexpr uint32_t LANES = 16; static void calculate(const KPCache& light_cache, uint32_t block_height, const uint8_t (&header_hash)[32], uint64_t nonce, uint32_t (&output)[8], uint32_t (&mix_hash)[8]); }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_KP_HASH_H */ +#endif // XMRIG_KP_HASH_H diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 5b743d5d6..a35662428 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2019 Howard Chu - * 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 @@ -292,8 +292,7 @@ void xmrig::Network::setJob(IClient *client, const Job &job, bool donate) } if (!donate && m_donate) { - m_donate->setAlgo(job.algorithm()); - m_donate->setProxy(client->pool().proxy()); + static_cast(m_donate)->update(client, job); } m_controller->miner()->setJob(job, donate); diff --git a/src/net/Network.h b/src/net/Network.h index 907e61103..b936c0d55 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2019 Howard Chu - * 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 @@ -89,7 +89,7 @@ private: }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_NETWORK_H */ +#endif // XMRIG_NETWORK_H diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 50e988893..03447a017 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2022 SChernykh - * Copyright (c) 2016-2022 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 @@ -48,7 +48,7 @@ static const char *kDonateHost = "donate.v2.xmrig.com"; static const char *kDonateHostTls = "donate.ssl.xmrig.com"; #endif -} /* namespace xmrig */ +} // namespace xmrig xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) : @@ -98,6 +98,17 @@ xmrig::DonateStrategy::~DonateStrategy() } +void xmrig::DonateStrategy::update(IClient *client, const Job &job) +{ + setAlgo(job.algorithm()); + setProxy(client->pool().proxy()); + + m_diff = job.diff(); + m_height = job.height(); + m_seed = job.seed(); +} + + int64_t xmrig::DonateStrategy::submit(const JobResult &result) { return m_proxy ? m_proxy->submit(result) : m_strategy->submit(result); @@ -199,13 +210,13 @@ void xmrig::DonateStrategy::onLogin(IClient *, rapidjson::Document &doc, rapidjs params.AddMember("url", m_pools[0].url().toJSON(), allocator); # endif - setAlgorithms(doc, params); + setParams(doc, params); } void xmrig::DonateStrategy::onLogin(IStrategy *, IClient *, rapidjson::Document &doc, rapidjson::Value ¶ms) { - setAlgorithms(doc, params); + setParams(doc, params); } @@ -270,12 +281,20 @@ void xmrig::DonateStrategy::idle(double min, double max) } -void xmrig::DonateStrategy::setAlgorithms(rapidjson::Document &doc, rapidjson::Value ¶ms) +void xmrig::DonateStrategy::setJob(IClient *client, const Job &job, const rapidjson::Value ¶ms) +{ + if (isActive()) { + m_listener->onJob(this, client, job, params); + } +} + + +void xmrig::DonateStrategy::setParams(rapidjson::Document &doc, rapidjson::Value ¶ms) { using namespace rapidjson; auto &allocator = doc.GetAllocator(); + auto algorithms = m_controller->miner()->algorithms(); - Algorithms algorithms = m_controller->miner()->algorithms(); const size_t index = static_cast(std::distance(algorithms.begin(), std::find(algorithms.begin(), algorithms.end(), m_algorithm))); if (index > 0 && index < algorithms.size()) { std::swap(algorithms[0], algorithms[index]); @@ -287,14 +306,12 @@ void xmrig::DonateStrategy::setAlgorithms(rapidjson::Document &doc, rapidjson::V algo.PushBack(StringRef(a.name()), allocator); } - params.AddMember("algo", algo, allocator); -} + params.AddMember("algo", algo, allocator); + params.AddMember("diff", m_diff, allocator); + params.AddMember("height", m_height, allocator); - -void xmrig::DonateStrategy::setJob(IClient *client, const Job &job, const rapidjson::Value ¶ms) -{ - if (isActive()) { - m_listener->onJob(this, client, job, params); + if (!m_seed.empty()) { + params.AddMember("seed_hash", Cvt::toHex(m_seed, doc), allocator); } } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 56a0580ea..80ec45ca1 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2022 SChernykh - * Copyright (c) 2016-2022 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 @@ -20,15 +20,12 @@ #define XMRIG_DONATESTRATEGY_H -#include - - #include "base/kernel/interfaces/IClientListener.h" #include "base/kernel/interfaces/IStrategy.h" #include "base/kernel/interfaces/IStrategyListener.h" #include "base/kernel/interfaces/ITimerListener.h" #include "base/net/stratum/Pool.h" -#include "base/tools/Object.h" +#include "base/tools/Buffer.h" namespace xmrig { @@ -36,7 +33,6 @@ namespace xmrig { class Client; class Controller; -class IStrategyListener; class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener @@ -47,6 +43,8 @@ public: DonateStrategy(Controller *controller, IStrategyListener *listener); ~DonateStrategy() override; + void update(IClient *client, const Job &job); + protected: inline bool isActive() const override { return state() == STATE_ACTIVE; } inline IClient *client() const override { return m_proxy ? m_proxy : m_strategy->client(); } @@ -88,13 +86,14 @@ private: IClient *createProxy(); void idle(double min, double max); - void setAlgorithms(rapidjson::Document &doc, rapidjson::Value ¶ms); void setJob(IClient *client, const Job &job, const rapidjson::Value ¶ms); + void setParams(rapidjson::Document &doc, rapidjson::Value ¶ms); void setResult(IClient *client, const SubmitResult &result, const char *error); void setState(State state); Algorithm m_algorithm; bool m_tls = false; + Buffer m_seed; char m_userId[65] = { 0 }; const uint64_t m_donateTime; const uint64_t m_idleTime; @@ -105,12 +104,14 @@ private: State m_state = STATE_NEW; std::vector m_pools; Timer *m_timer = nullptr; + uint64_t m_diff = 0; + uint64_t m_height = 0; uint64_t m_now = 0; uint64_t m_timestamp = 0; }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_DONATESTRATEGY_H */ +#endif // XMRIG_DONATESTRATEGY_H