Remove donate logic from xmrig
This commit is contained in:
@@ -66,7 +66,6 @@ set(HEADERS
|
||||
src/net/JobResult.h
|
||||
src/net/JobResults.h
|
||||
src/net/Network.h
|
||||
src/net/strategies/DonateStrategy.h
|
||||
src/Summary.h
|
||||
src/version.h
|
||||
)
|
||||
@@ -113,7 +112,6 @@ set(SOURCES
|
||||
src/core/Taskbar.cpp
|
||||
src/net/JobResults.cpp
|
||||
src/net/Network.cpp
|
||||
src/net/strategies/DonateStrategy.cpp
|
||||
src/Summary.cpp
|
||||
src/xmrig.cpp
|
||||
)
|
||||
|
||||
@@ -166,12 +166,6 @@ static void print_memory(const Config *config)
|
||||
|
||||
static void print_threads(const Config *config)
|
||||
{
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s%d%%"),
|
||||
"DONATE",
|
||||
config->pools().donateLevel() == 0 ? RED_BOLD_S : "",
|
||||
config->pools().donateLevel()
|
||||
);
|
||||
|
||||
# ifdef XMRIG_FEATURE_ASM
|
||||
if (config->cpu().assembly() == Assembly::AUTO) {
|
||||
const Assembly assembly = Cpu::info()->assembly();
|
||||
@@ -218,5 +212,3 @@ void xmrig::Summary::print(Controller *controller)
|
||||
print_commands(config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -56,11 +56,6 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
if (index() == 1 && job.index() == 0 && job == m_jobs[0]) {
|
||||
m_index = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
save(job, reserveCount, backend);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +242,6 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
|
||||
case IConfig::RetryPauseKey: /* --retry-pause */
|
||||
case IConfig::PrintTimeKey: /* --print-time */
|
||||
case IConfig::HttpPort: /* --http-port */
|
||||
case IConfig::DonateLevelKey: /* --donate-level */
|
||||
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
|
||||
case IConfig::DaemonJobTimeoutKey: /* --daemon-job-timeout */
|
||||
case IConfig::DnsTtlKey: /* --dns-ttl */
|
||||
@@ -342,12 +341,6 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
|
||||
case IConfig::RetryPauseKey: /* --retry-pause */
|
||||
return set(doc, Pools::kRetryPause, arg);
|
||||
|
||||
case IConfig::DonateLevelKey: /* --donate-level */
|
||||
return set(doc, Pools::kDonateLevel, arg);
|
||||
|
||||
case IConfig::ProxyDonateKey: /* --donate-over-proxy */
|
||||
return set(doc, Pools::kDonateOverProxy, arg);
|
||||
|
||||
case IConfig::HttpPort: /* --http-port */
|
||||
m_http = true;
|
||||
return set(doc, BaseConfig::kHttp, Http::kPort, arg);
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "base/kernel/interfaces/IJsonReader.h"
|
||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
||||
#include "donate.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
@@ -40,8 +39,6 @@
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
const char *Pools::kDonateLevel = "donate-level";
|
||||
const char *Pools::kDonateOverProxy = "donate-over-proxy";
|
||||
const char *Pools::kPools = "pools";
|
||||
const char *Pools::kRetries = "retries";
|
||||
const char *Pools::kRetryPause = "retry-pause";
|
||||
@@ -50,8 +47,7 @@ const char *Pools::kRetryPause = "retry-pause";
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Pools::Pools() :
|
||||
m_donateLevel(kDefaultDonateLevel)
|
||||
xmrig::Pools::Pools()
|
||||
{
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_retries = 2;
|
||||
@@ -70,16 +66,6 @@ bool xmrig::Pools::isEqual(const Pools &other) const
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Pools::donateLevel() const
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
return benchSize() || (m_benchmark && !m_benchmark->id().isEmpty()) ? 0 : m_donateLevel;
|
||||
# else
|
||||
return m_donateLevel;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
xmrig::IStrategy *xmrig::Pools::createStrategy(IStrategyListener *listener) const
|
||||
{
|
||||
if (active() == 1) {
|
||||
@@ -158,8 +144,6 @@ void xmrig::Pools::load(const IJsonReader &reader)
|
||||
}
|
||||
}
|
||||
|
||||
setDonateLevel(reader.getInt(kDonateLevel, kDefaultDonateLevel));
|
||||
setProxyDonate(reader.getInt(kDonateOverProxy, PROXY_DONATE_AUTO));
|
||||
setRetries(reader.getInt(kRetries));
|
||||
setRetryPause(reader.getInt(kRetryPause));
|
||||
}
|
||||
@@ -207,36 +191,12 @@ void xmrig::Pools::toJSON(rapidjson::Value &out, rapidjson::Document &doc) const
|
||||
}
|
||||
# endif
|
||||
|
||||
doc.AddMember(StringRef(kDonateLevel), m_donateLevel, allocator);
|
||||
doc.AddMember(StringRef(kDonateOverProxy), m_proxyDonate, allocator);
|
||||
out.AddMember(StringRef(kPools), toJSON(doc), allocator);
|
||||
doc.AddMember(StringRef(kRetries), retries(), allocator);
|
||||
doc.AddMember(StringRef(kRetryPause), retryPause(), allocator);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Pools::setDonateLevel(int level)
|
||||
{
|
||||
if (level >= kMinimumDonateLevel && level <= 99) {
|
||||
m_donateLevel = level;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Pools::setProxyDonate(int value)
|
||||
{
|
||||
switch (value) {
|
||||
case PROXY_DONATE_NONE:
|
||||
case PROXY_DONATE_AUTO:
|
||||
case PROXY_DONATE_ALWAYS:
|
||||
m_proxyDonate = static_cast<ProxyDonate>(value);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Pools::setRetries(int retries)
|
||||
{
|
||||
if (retries > 0 && retries <= 1000) {
|
||||
|
||||
@@ -43,18 +43,10 @@ class IStrategyListener;
|
||||
class Pools
|
||||
{
|
||||
public:
|
||||
static const char *kDonateLevel;
|
||||
static const char *kDonateOverProxy;
|
||||
static const char *kPools;
|
||||
static const char *kRetries;
|
||||
static const char *kRetryPause;
|
||||
|
||||
enum ProxyDonate {
|
||||
PROXY_DONATE_NONE,
|
||||
PROXY_DONATE_AUTO,
|
||||
PROXY_DONATE_ALWAYS
|
||||
};
|
||||
|
||||
Pools();
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
@@ -66,13 +58,10 @@ public:
|
||||
inline const std::vector<Pool> &data() const { return m_data; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
inline ProxyDonate proxyDonate() const { return m_proxyDonate; }
|
||||
|
||||
inline bool operator!=(const Pools &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Pools &other) const { return isEqual(other); }
|
||||
|
||||
bool isEqual(const Pools &other) const;
|
||||
int donateLevel() const;
|
||||
IStrategy *createStrategy(IStrategyListener *listener) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
size_t active() const;
|
||||
@@ -82,15 +71,11 @@ public:
|
||||
void toJSON(rapidjson::Value &out, rapidjson::Document &doc) const;
|
||||
|
||||
private:
|
||||
void setDonateLevel(int level);
|
||||
void setProxyDonate(int value);
|
||||
void setRetries(int retries);
|
||||
void setRetryPause(int retryPause);
|
||||
|
||||
int m_donateLevel;
|
||||
int m_retries = 5;
|
||||
int m_retryPause = 5;
|
||||
ProxyDonate m_proxyDonate = PROXY_DONATE_AUTO;
|
||||
std::vector<Pool> m_data;
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
|
||||
+2
-4
@@ -55,15 +55,13 @@
|
||||
"cn/0": false,
|
||||
"cn-lite/0": false
|
||||
},
|
||||
"donate-level": 1,
|
||||
"donate-over-proxy": 1,
|
||||
"log-file": null,
|
||||
"pools": [
|
||||
{
|
||||
"algo": null,
|
||||
"coin": null,
|
||||
"url": "donate.v2.xmrig.com:3333",
|
||||
"user": "YOUR_WALLET_ADDRESS",
|
||||
"url": "127.0.0.1:3333",
|
||||
"user": "YOUR_PEYA_WALLET_ADDRESS",
|
||||
"pass": "x",
|
||||
"rig-id": null,
|
||||
"nicehash": false,
|
||||
|
||||
+4
-7
@@ -151,7 +151,6 @@ public:
|
||||
reply.AddMember("kind", APP_KIND, allocator);
|
||||
reply.AddMember("ua", Platform::userAgent().toJSON(), allocator);
|
||||
reply.AddMember("cpu", Cpu::toJSON(doc), allocator);
|
||||
reply.AddMember("donate_level", controller->config()->pools().donateLevel(), allocator);
|
||||
reply.AddMember("paused", !enabled, allocator);
|
||||
|
||||
Value algo(kArrayType);
|
||||
@@ -549,7 +548,7 @@ void xmrig::Miner::setEnabled(bool enabled)
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Miner::setJob(const Job &job, bool donate)
|
||||
void xmrig::Miner::setJob(const Job &job)
|
||||
{
|
||||
for (IBackend *backend : d_ptr->backends) {
|
||||
backend->prepare(job);
|
||||
@@ -571,9 +570,9 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
|
||||
|
||||
mutex.lock();
|
||||
|
||||
const uint8_t index = donate ? 1 : 0;
|
||||
constexpr uint8_t index = 0;
|
||||
|
||||
d_ptr->reset = !(d_ptr->job.index() == 1 && index == 0 && d_ptr->userJobId == job.id());
|
||||
d_ptr->reset = !(d_ptr->userJobId == job.id());
|
||||
|
||||
// Don't reset nonce if pool sends the same hashing blob again, but with different difficulty (for example)
|
||||
if (d_ptr->job.isEqualBlob(job)) {
|
||||
@@ -583,9 +582,7 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
|
||||
d_ptr->job = job;
|
||||
d_ptr->job.setIndex(index);
|
||||
|
||||
if (index == 0) {
|
||||
d_ptr->userJobId = job.id();
|
||||
}
|
||||
d_ptr->userJobId = job.id();
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
const bool ready = d_ptr->initRX();
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public:
|
||||
void execCommand(char command);
|
||||
void pause();
|
||||
void setEnabled(bool enabled);
|
||||
void setJob(const Job &job, bool donate);
|
||||
void setJob(const Job &job);
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -85,15 +85,13 @@ R"===(
|
||||
"cn/0": false,
|
||||
"cn-lite/0": false
|
||||
},
|
||||
"donate-level": 1,
|
||||
"donate-over-proxy": 1,
|
||||
"log-file": null,
|
||||
"pools": [
|
||||
{
|
||||
"algo": null,
|
||||
"coin": null,
|
||||
"url": "donate.v2.xmrig.com:3333",
|
||||
"user": "YOUR_WALLET_ADDRESS",
|
||||
"url": "127.0.0.1:3333",
|
||||
"user": "YOUR_PEYA_WALLET_ADDRESS",
|
||||
"pass": "x",
|
||||
"rig-id": null,
|
||||
"nicehash": false,
|
||||
|
||||
@@ -57,8 +57,6 @@ static const option options[] = {
|
||||
{ "config", 1, nullptr, IConfig::ConfigKey },
|
||||
{ "cpu-affinity", 1, nullptr, IConfig::CPUAffinityKey },
|
||||
{ "cpu-priority", 1, nullptr, IConfig::CPUPriorityKey },
|
||||
{ "donate-level", 1, nullptr, IConfig::DonateLevelKey },
|
||||
{ "donate-over-proxy", 1, nullptr, IConfig::ProxyDonateKey },
|
||||
{ "dry-run", 0, nullptr, IConfig::DryRunKey },
|
||||
{ "keepalive", 0, nullptr, IConfig::KeepAliveKey },
|
||||
{ "log-file", 1, nullptr, IConfig::LogFileKey },
|
||||
|
||||
@@ -72,9 +72,6 @@ static inline const std::string &usage()
|
||||
u += " -r, --retries=N number of times to retry before switch to backup server (default: 5)\n";
|
||||
u += " -R, --retry-pause=N time to pause between retries (default: 5)\n";
|
||||
u += " --user-agent set custom user-agent string for pool\n";
|
||||
u += " --donate-level=N donate level, default 1%% (1 minute in 100 minutes)\n";
|
||||
u += " --donate-over-proxy=N control donate over xmrig-proxy feature\n";
|
||||
|
||||
u += "\nCPU backend:\n";
|
||||
|
||||
u += " --no-cpu disable CPU mining backend\n";
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_DONATE_H
|
||||
#define XMRIG_DONATE_H
|
||||
|
||||
|
||||
/*
|
||||
* Dev donation.
|
||||
*
|
||||
* Percentage of your hashing power that you want to donate to the developer can be 0% but supports XMRig Development.
|
||||
*
|
||||
* Example of how it works for the setting of 1%:
|
||||
* Your miner will mine into your usual pool for a random time (in a range from 49.5 to 148.5 minutes),
|
||||
* then switch to the developer's pool for 1 minute, then switch again to your pool for 99 minutes
|
||||
* and then switch again to developer's pool for 1 minute; these rounds will continue until the miner stops.
|
||||
*
|
||||
* Randomised only on the first round to prevent waves on the donation pool.
|
||||
*
|
||||
* Switching is instant and only happens after a successful connection, so you never lose any hashes.
|
||||
*
|
||||
* If you plan on changing donations to 0%, please consider making a one-off donation to my wallet:
|
||||
* XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
|
||||
*/
|
||||
constexpr const int kDefaultDonateLevel = 1;
|
||||
constexpr const int kMinimumDonateLevel = 1;
|
||||
|
||||
|
||||
#endif // XMRIG_DONATE_H
|
||||
+4
-36
@@ -27,6 +27,7 @@
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/kernel/interfaces/IStrategy.h"
|
||||
#include "base/net/stratum/NetworkState.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
@@ -36,7 +37,6 @@
|
||||
#include "core/Miner.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "net/strategies/DonateStrategy.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
@@ -72,10 +72,6 @@ xmrig::Network::Network(Controller *controller) :
|
||||
const Pools &pools = controller->config()->pools();
|
||||
m_strategy = pools.createStrategy(m_state);
|
||||
|
||||
if (pools.donateLevel() > 0) {
|
||||
m_donate = new DonateStrategy(controller, this);
|
||||
}
|
||||
|
||||
m_timer = new Timer(this, kTickInterval, kTickInterval);
|
||||
}
|
||||
|
||||
@@ -85,7 +81,6 @@ xmrig::Network::~Network()
|
||||
JobResults::stop();
|
||||
|
||||
delete m_timer;
|
||||
delete m_donate;
|
||||
delete m_strategy;
|
||||
delete m_state;
|
||||
}
|
||||
@@ -118,11 +113,6 @@ void xmrig::Network::execCommand(char command)
|
||||
|
||||
void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
||||
{
|
||||
if (m_donate && m_donate == strategy) {
|
||||
LOG_NOTICE("%s " WHITE_BOLD("dev donate started"), Tags::network());
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &pool = client->pool();
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
@@ -165,21 +155,12 @@ void xmrig::Network::onConfigChanged(Config *config, Config *previousConfig)
|
||||
|
||||
void xmrig::Network::onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value &)
|
||||
{
|
||||
if (m_donate && m_donate->isActive() && m_donate != strategy) {
|
||||
return;
|
||||
}
|
||||
|
||||
setJob(client, job, m_donate == strategy);
|
||||
setJob(client, job);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Network::onJobResult(const JobResult &result)
|
||||
{
|
||||
if (result.index == 1 && m_donate) {
|
||||
m_donate->submit(result);
|
||||
return;
|
||||
}
|
||||
|
||||
m_strategy->submit(result);
|
||||
}
|
||||
|
||||
@@ -210,11 +191,6 @@ void xmrig::Network::onLogin(IStrategy *, IClient *client, rapidjson::Document &
|
||||
|
||||
void xmrig::Network::onPause(IStrategy *strategy)
|
||||
{
|
||||
if (m_donate && m_donate == strategy) {
|
||||
LOG_NOTICE("%s " WHITE_BOLD("dev donate finished"), Tags::network());
|
||||
m_strategy->resume();
|
||||
}
|
||||
|
||||
if (!m_strategy->isActive()) {
|
||||
LOG_ERR("%s " RED("no active pools, stop mining"), Tags::network());
|
||||
|
||||
@@ -262,7 +238,7 @@ void xmrig::Network::onRequest(IApiRequest &request)
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
||||
void xmrig::Network::setJob(IClient *client, const Job &job)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (!BenchState::size())
|
||||
@@ -291,11 +267,7 @@ void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
||||
Tags::network(), client->pool().host().data(), client->pool().port(), zmq_buf, diff, scale, job.algorithm().name(), height_buf, tx_buf);
|
||||
}
|
||||
|
||||
if (!donate && m_donate) {
|
||||
static_cast<DonateStrategy *>(m_donate)->update(client, job);
|
||||
}
|
||||
|
||||
m_controller->miner()->setJob(job, donate);
|
||||
m_controller->miner()->setJob(job);
|
||||
}
|
||||
|
||||
|
||||
@@ -305,10 +277,6 @@ void xmrig::Network::tick()
|
||||
|
||||
m_strategy->tick(now);
|
||||
|
||||
if (m_donate) {
|
||||
m_donate->tick(now);
|
||||
}
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
m_controller->api()->tick();
|
||||
# endif
|
||||
|
||||
+1
-2
@@ -73,7 +73,7 @@ protected:
|
||||
private:
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
|
||||
void setJob(IClient *client, const Job &job, bool donate);
|
||||
void setJob(IClient *client, const Job &job);
|
||||
void tick();
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
@@ -82,7 +82,6 @@ private:
|
||||
# endif
|
||||
|
||||
Controller *m_controller;
|
||||
IStrategy *m_donate = nullptr;
|
||||
IStrategy *m_strategy = nullptr;
|
||||
NetworkState *m_state = nullptr;
|
||||
Timer *m_timer = nullptr;
|
||||
|
||||
@@ -1,372 +0,0 @@
|
||||
/* XMRig
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
#include "net/strategies/DonateStrategy.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/Timer.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Miner.h"
|
||||
#include "net/Network.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static inline double randomf(double min, double max) { return (max - min) * (((static_cast<double>(rand())) / static_cast<double>(RAND_MAX))) + min; }
|
||||
static inline uint64_t random(uint64_t base, double min, double max) { return static_cast<uint64_t>(base * randomf(min, max)); }
|
||||
|
||||
static const char *kDonateHost = "donate.v2.xmrig.com";
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
static const char *kDonateHostTls = "donate.ssl.xmrig.com";
|
||||
#endif
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) :
|
||||
m_donateTime(static_cast<uint64_t>(controller->config()->pools().donateLevel()) * 60 * 1000),
|
||||
m_idleTime((100 - static_cast<uint64_t>(controller->config()->pools().donateLevel())) * 60 * 1000),
|
||||
m_controller(controller),
|
||||
m_listener(listener)
|
||||
{
|
||||
uint8_t hash[200];
|
||||
|
||||
const auto &user = controller->config()->pools().data().front().user();
|
||||
keccak(reinterpret_cast<const uint8_t *>(user.data()), user.size(), hash);
|
||||
Cvt::toHex(m_userId, sizeof(m_userId), hash, 32);
|
||||
|
||||
# if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER
|
||||
constexpr Pool::Mode mode = Pool::MODE_AUTO_ETH;
|
||||
# else
|
||||
constexpr Pool::Mode mode = Pool::MODE_POOL;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
m_pools.emplace_back(kDonateHostTls, 443, m_userId, nullptr, nullptr, 0, true, true, mode);
|
||||
# endif
|
||||
m_pools.emplace_back(kDonateHost, 3333, m_userId, nullptr, nullptr, 0, true, false, mode);
|
||||
|
||||
if (m_pools.size() > 1) {
|
||||
m_strategy = new FailoverStrategy(m_pools, 10, 2, this, true);
|
||||
}
|
||||
else {
|
||||
m_strategy = new SinglePoolStrategy(m_pools.front(), 10, 2, this, true);
|
||||
}
|
||||
|
||||
m_timer = new Timer(this);
|
||||
|
||||
setState(STATE_IDLE);
|
||||
}
|
||||
|
||||
|
||||
xmrig::DonateStrategy::~DonateStrategy()
|
||||
{
|
||||
delete m_timer;
|
||||
delete m_strategy;
|
||||
|
||||
if (m_proxy) {
|
||||
m_proxy->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::connect()
|
||||
{
|
||||
m_proxy = createProxy();
|
||||
if (m_proxy) {
|
||||
m_proxy->connect();
|
||||
}
|
||||
|
||||
else {
|
||||
m_strategy->connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo)
|
||||
{
|
||||
m_algorithm = algo;
|
||||
|
||||
m_strategy->setAlgo(algo);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::setProxy(const ProxyUrl &proxy)
|
||||
{
|
||||
m_strategy->setProxy(proxy);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::stop()
|
||||
{
|
||||
m_timer->stop();
|
||||
m_strategy->stop();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::tick(uint64_t now)
|
||||
{
|
||||
m_now = now;
|
||||
|
||||
m_strategy->tick(now);
|
||||
|
||||
if (m_proxy) {
|
||||
m_proxy->tick(now);
|
||||
}
|
||||
|
||||
if (state() == STATE_WAIT && now > m_timestamp) {
|
||||
setState(STATE_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onActive(IStrategy *, IClient *client)
|
||||
{
|
||||
if (isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(STATE_ACTIVE);
|
||||
m_listener->onActive(this, client);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onPause(IStrategy *)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onClose(IClient *, int failures)
|
||||
{
|
||||
if (failures == 2 && m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_AUTO) {
|
||||
m_proxy->deleteLater();
|
||||
m_proxy = nullptr;
|
||||
|
||||
m_strategy->connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onLogin(IClient *, rapidjson::Document &doc, rapidjson::Value ¶ms)
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (m_tls) {
|
||||
char buf[40] = { 0 };
|
||||
snprintf(buf, sizeof(buf), "stratum+ssl://%s", m_pools[0].url().data());
|
||||
params.AddMember("url", Value(buf, allocator), allocator);
|
||||
}
|
||||
else {
|
||||
params.AddMember("url", m_pools[1].url().toJSON(), allocator);
|
||||
}
|
||||
# else
|
||||
params.AddMember("url", m_pools[0].url().toJSON(), allocator);
|
||||
# endif
|
||||
|
||||
setParams(doc, params);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onLogin(IStrategy *, IClient *, rapidjson::Document &doc, rapidjson::Value ¶ms)
|
||||
{
|
||||
setParams(doc, params);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onLoginSuccess(IClient *client)
|
||||
{
|
||||
if (isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(STATE_ACTIVE);
|
||||
m_listener->onActive(this, client);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok)
|
||||
{
|
||||
m_listener->onVerifyAlgorithm(this, client, algorithm, ok);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onVerifyAlgorithm(IStrategy *, const IClient *client, const Algorithm &algorithm, bool *ok)
|
||||
{
|
||||
m_listener->onVerifyAlgorithm(this, client, algorithm, ok);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onTimer(const Timer *)
|
||||
{
|
||||
setState(isActive() ? STATE_WAIT : STATE_CONNECT);
|
||||
}
|
||||
|
||||
|
||||
xmrig::IClient *xmrig::DonateStrategy::createProxy()
|
||||
{
|
||||
if (m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_NONE) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IStrategy *strategy = m_controller->network()->strategy();
|
||||
if (!strategy->isActive() || !strategy->client()->hasExtension(IClient::EXT_CONNECT)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const IClient *client = strategy->client();
|
||||
m_tls = client->hasExtension(IClient::EXT_TLS);
|
||||
|
||||
Pool pool(client->pool().proxy().isValid() ? client->pool().host() : client->ip(), client->pool().port(), m_userId, client->pool().password(), client->pool().spendSecretKey(), 0, true, client->isTLS(), Pool::MODE_POOL);
|
||||
pool.setAlgo(client->pool().algorithm());
|
||||
pool.setProxy(client->pool().proxy());
|
||||
|
||||
IClient *proxy = new Client(-1, Platform::userAgent(), this);
|
||||
proxy->setPool(pool);
|
||||
proxy->setQuiet(true);
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::idle(double min, double max)
|
||||
{
|
||||
m_timer->start(random(m_idleTime, min, max), 0);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
Value algo(kArrayType);
|
||||
|
||||
for (const auto &a : algorithms) {
|
||||
algo.PushBack(StringRef(a.name()), allocator);
|
||||
}
|
||||
|
||||
params.AddMember("algo", algo, allocator);
|
||||
params.AddMember("diff", m_diff, allocator);
|
||||
params.AddMember("height", m_height, allocator);
|
||||
|
||||
if (!m_seed.empty()) {
|
||||
params.AddMember("seed_hash", Cvt::toHex(m_seed, doc), allocator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::setResult(IClient *client, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_listener->onResultAccepted(this, client, result, error);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::setState(State state)
|
||||
{
|
||||
constexpr const uint64_t waitTime = 3000;
|
||||
|
||||
assert(m_state != state && state != STATE_NEW);
|
||||
if (m_state == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
const State prev = m_state;
|
||||
m_state = state;
|
||||
|
||||
switch (state) {
|
||||
case STATE_NEW:
|
||||
break;
|
||||
|
||||
case STATE_IDLE:
|
||||
if (prev == STATE_NEW) {
|
||||
idle(0.5, 1.5);
|
||||
}
|
||||
else if (prev == STATE_CONNECT) {
|
||||
m_timer->start(20000, 0);
|
||||
}
|
||||
else {
|
||||
m_strategy->stop();
|
||||
if (m_proxy) {
|
||||
m_proxy->deleteLater();
|
||||
m_proxy = nullptr;
|
||||
}
|
||||
|
||||
idle(0.8, 1.2);
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_CONNECT:
|
||||
connect();
|
||||
break;
|
||||
|
||||
case STATE_ACTIVE:
|
||||
m_timer->start(m_donateTime, 0);
|
||||
break;
|
||||
|
||||
case STATE_WAIT:
|
||||
m_timestamp = m_now + waitTime;
|
||||
m_listener->onPause(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/* XMRig
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_DONATESTRATEGY_H
|
||||
#define XMRIG_DONATESTRATEGY_H
|
||||
|
||||
|
||||
#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/Buffer.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Client;
|
||||
class Controller;
|
||||
|
||||
|
||||
class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(DonateStrategy)
|
||||
|
||||
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(); }
|
||||
inline void onJob(IStrategy *, IClient *client, const Job &job, const rapidjson::Value ¶ms) override { setJob(client, job, params); }
|
||||
inline void onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms) override { setJob(client, job, params); }
|
||||
inline void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||
inline void onResultAccepted(IStrategy *, IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||
inline void resume() override {}
|
||||
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void setAlgo(const Algorithm &algo) override;
|
||||
void setProxy(const ProxyUrl &proxy) override;
|
||||
void stop() override;
|
||||
void tick(uint64_t now) override;
|
||||
|
||||
void onActive(IStrategy *strategy, IClient *client) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
|
||||
void onClose(IClient *client, int failures) override;
|
||||
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(IClient *client) override;
|
||||
void onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok) override;
|
||||
void onVerifyAlgorithm(IStrategy *strategy, const IClient *client, const Algorithm &algorithm, bool *ok) override;
|
||||
|
||||
void onTimer(const Timer *timer) override;
|
||||
|
||||
private:
|
||||
enum State {
|
||||
STATE_NEW,
|
||||
STATE_IDLE,
|
||||
STATE_CONNECT,
|
||||
STATE_ACTIVE,
|
||||
STATE_WAIT
|
||||
};
|
||||
|
||||
inline State state() const { return m_state; }
|
||||
|
||||
IClient *createProxy();
|
||||
void idle(double min, double max);
|
||||
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;
|
||||
Controller *m_controller;
|
||||
IClient *m_proxy = nullptr;
|
||||
IStrategy *m_strategy = nullptr;
|
||||
IStrategyListener *m_listener;
|
||||
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
|
||||
|
||||
|
||||
#endif // XMRIG_DONATESTRATEGY_H
|
||||
Reference in New Issue
Block a user