mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-22 11:39:33 +00:00
#3245 Improved algorithm negotiation for donation rounds by sending extra information about current mining job.
This commit is contained in:
parent
a2e9b3456d
commit
c4e1363148
5 changed files with 58 additions and 41 deletions
|
@ -7,8 +7,8 @@
|
|||
* Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 tevador <tevador@gmail.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2023 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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<DonateStrategy *>(m_donate)->update(client, job);
|
||||
}
|
||||
|
||||
m_controller->miner()->setJob(job, donate);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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<size_t>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 <vector>
|
||||
|
||||
|
||||
#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<Pool> 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
|
||||
|
|
Loading…
Reference in a new issue