#3245 Improved algorithm negotiation for donation rounds by sending extra information about current mining job.

This commit is contained in:
XMRig 2023-04-07 23:35:05 +07:00
parent a2e9b3456d
commit c4e1363148
No known key found for this signature in database
GPG key ID: 446A53638BE94409
5 changed files with 58 additions and 41 deletions

View file

@ -7,8 +7,8 @@
* Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 tevador <tevador@gmail.com> * Copyright 2018-2019 tevador <tevador@gmail.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh> * Copyright 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -28,7 +28,7 @@
#define XMRIG_KP_HASH_H #define XMRIG_KP_HASH_H
#include <stdint.h> #include <cstdint>
namespace xmrig namespace xmrig
@ -43,16 +43,16 @@ class KPHash
public: public:
static constexpr uint32_t EPOCH_LENGTH = 7500; static constexpr uint32_t EPOCH_LENGTH = 7500;
static constexpr uint32_t PERIOD_LENGTH = 3; static constexpr uint32_t PERIOD_LENGTH = 3;
static constexpr int CNT_CACHE = 11; static constexpr int CNT_CACHE = 11;
static constexpr int CNT_MATH = 18; static constexpr int CNT_MATH = 18;
static constexpr uint32_t REGS = 32; static constexpr uint32_t REGS = 32;
static constexpr uint32_t LANES = 16; 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]); 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

View file

@ -1,7 +1,7 @@
/* XMRig /* XMRig
* Copyright (c) 2019 Howard Chu <https://github.com/hyc> * Copyright (c) 2019 Howard Chu <https://github.com/hyc>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh> * Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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) { if (!donate && m_donate) {
m_donate->setAlgo(job.algorithm()); static_cast<DonateStrategy *>(m_donate)->update(client, job);
m_donate->setProxy(client->pool().proxy());
} }
m_controller->miner()->setJob(job, donate); m_controller->miner()->setJob(job, donate);

View file

@ -1,7 +1,7 @@
/* XMRig /* XMRig
* Copyright (c) 2019 Howard Chu <https://github.com/hyc> * Copyright (c) 2019 Howard Chu <https://github.com/hyc>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh> * Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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

View file

@ -1,6 +1,6 @@
/* XMRig /* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh> * Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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"; static const char *kDonateHostTls = "donate.ssl.xmrig.com";
#endif #endif
} /* namespace xmrig */ } // namespace xmrig
xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) : 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) int64_t xmrig::DonateStrategy::submit(const JobResult &result)
{ {
return m_proxy ? m_proxy->submit(result) : m_strategy->submit(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); params.AddMember("url", m_pools[0].url().toJSON(), allocator);
# endif # endif
setAlgorithms(doc, params); setParams(doc, params);
} }
void xmrig::DonateStrategy::onLogin(IStrategy *, IClient *, rapidjson::Document &doc, rapidjson::Value &params) void xmrig::DonateStrategy::onLogin(IStrategy *, IClient *, rapidjson::Document &doc, rapidjson::Value &params)
{ {
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 &params) void xmrig::DonateStrategy::setJob(IClient *client, const Job &job, const rapidjson::Value &params)
{
if (isActive()) {
m_listener->onJob(this, client, job, params);
}
}
void xmrig::DonateStrategy::setParams(rapidjson::Document &doc, rapidjson::Value &params)
{ {
using namespace rapidjson; using namespace rapidjson;
auto &allocator = doc.GetAllocator(); auto &allocator = doc.GetAllocator();
auto algorithms = m_controller->miner()->algorithms();
Algorithms algorithms = m_controller->miner()->algorithms();
const size_t index = static_cast<size_t>(std::distance(algorithms.begin(), std::find(algorithms.begin(), algorithms.end(), m_algorithm))); const size_t index = static_cast<size_t>(std::distance(algorithms.begin(), std::find(algorithms.begin(), algorithms.end(), m_algorithm)));
if (index > 0 && index < algorithms.size()) { if (index > 0 && index < algorithms.size()) {
std::swap(algorithms[0], algorithms[index]); 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); 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);
if (!m_seed.empty()) {
void xmrig::DonateStrategy::setJob(IClient *client, const Job &job, const rapidjson::Value &params) params.AddMember("seed_hash", Cvt::toHex(m_seed, doc), allocator);
{
if (isActive()) {
m_listener->onJob(this, client, job, params);
} }
} }

View file

@ -1,6 +1,6 @@
/* XMRig /* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh> * Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,15 +20,12 @@
#define XMRIG_DONATESTRATEGY_H #define XMRIG_DONATESTRATEGY_H
#include <vector>
#include "base/kernel/interfaces/IClientListener.h" #include "base/kernel/interfaces/IClientListener.h"
#include "base/kernel/interfaces/IStrategy.h" #include "base/kernel/interfaces/IStrategy.h"
#include "base/kernel/interfaces/IStrategyListener.h" #include "base/kernel/interfaces/IStrategyListener.h"
#include "base/kernel/interfaces/ITimerListener.h" #include "base/kernel/interfaces/ITimerListener.h"
#include "base/net/stratum/Pool.h" #include "base/net/stratum/Pool.h"
#include "base/tools/Object.h" #include "base/tools/Buffer.h"
namespace xmrig { namespace xmrig {
@ -36,7 +33,6 @@ namespace xmrig {
class Client; class Client;
class Controller; class Controller;
class IStrategyListener;
class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener
@ -47,6 +43,8 @@ public:
DonateStrategy(Controller *controller, IStrategyListener *listener); DonateStrategy(Controller *controller, IStrategyListener *listener);
~DonateStrategy() override; ~DonateStrategy() override;
void update(IClient *client, const Job &job);
protected: protected:
inline bool isActive() const override { return state() == STATE_ACTIVE; } inline bool isActive() const override { return state() == STATE_ACTIVE; }
inline IClient *client() const override { return m_proxy ? m_proxy : m_strategy->client(); } inline IClient *client() const override { return m_proxy ? m_proxy : m_strategy->client(); }
@ -88,13 +86,14 @@ private:
IClient *createProxy(); IClient *createProxy();
void idle(double min, double max); void idle(double min, double max);
void setAlgorithms(rapidjson::Document &doc, rapidjson::Value &params);
void setJob(IClient *client, const Job &job, const rapidjson::Value &params); void setJob(IClient *client, const Job &job, const rapidjson::Value &params);
void setParams(rapidjson::Document &doc, rapidjson::Value &params);
void setResult(IClient *client, const SubmitResult &result, const char *error); void setResult(IClient *client, const SubmitResult &result, const char *error);
void setState(State state); void setState(State state);
Algorithm m_algorithm; Algorithm m_algorithm;
bool m_tls = false; bool m_tls = false;
Buffer m_seed;
char m_userId[65] = { 0 }; char m_userId[65] = { 0 };
const uint64_t m_donateTime; const uint64_t m_donateTime;
const uint64_t m_idleTime; const uint64_t m_idleTime;
@ -105,12 +104,14 @@ private:
State m_state = STATE_NEW; State m_state = STATE_NEW;
std::vector<Pool> m_pools; std::vector<Pool> m_pools;
Timer *m_timer = nullptr; Timer *m_timer = nullptr;
uint64_t m_diff = 0;
uint64_t m_height = 0;
uint64_t m_now = 0; uint64_t m_now = 0;
uint64_t m_timestamp = 0; uint64_t m_timestamp = 0;
}; };
} /* namespace xmrig */ } // namespace xmrig
#endif /* XMRIG_DONATESTRATEGY_H */ #endif // XMRIG_DONATESTRATEGY_H