Merge pull request #376 from CR4DL/dev

Use custom-diff shares for better proxy and worker stats
This commit is contained in:
xmrig
2019-12-29 21:08:10 +07:00
committed by GitHub
21 changed files with 72 additions and 36 deletions

View File

@@ -115,6 +115,7 @@ public:
AccessLogFileKey = 'A',
BindKey = 'b',
CustomDiffKey = 1102,
CustomDiffStatsKey = 1104,
DebugKey = 1101,
ModeKey = 'm',
PoolCoinKey = 'C',

View File

@@ -28,6 +28,7 @@
],
"colors": true,
"custom-diff": 0,
"custom-diff-stats": false,
"donate-level": 0,
"log-file": null,
"mode": "nicehash",

View File

@@ -81,6 +81,7 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
return false;
}
m_customDiffStats = reader.getBool("custom-diff-stats", m_customDiffStats);
m_debug = reader.getBool("debug", m_debug);
m_algoExt = reader.getBool("algo-ext", m_algoExt);
m_reuseTimeout = reader.getInt("reuse-timeout", m_reuseTimeout);
@@ -153,6 +154,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember("bind", bind, allocator);
doc.AddMember("colors", Log::isColors(), allocator);
doc.AddMember("custom-diff", diff(), allocator);
doc.AddMember("custom-diff-stats", m_customDiffStats, allocator);
doc.AddMember("donate-level", m_pools.donateLevel(), allocator);
doc.AddMember("log-file", m_logFile.toJSON(), allocator);
doc.AddMember("mode", StringRef(modeName()), allocator);

View File

@@ -80,6 +80,7 @@ public:
void toggleVerbose();
inline bool hasAlgoExt() const { return isDonateOverProxy() ? m_algoExt : true; }
inline bool isCustomDiffStats() const { return m_customDiffStats; }
inline bool isDebug() const { return m_debug; }
inline bool isDonateOverProxy() const { return m_pools.donateLevel() == 0 || m_mode == SIMPLE_MODE; }
inline bool isShouldSave() const { return m_upgrade && isAutoSave(); }
@@ -103,6 +104,7 @@ private:
BindHosts m_bind;
bool m_algoExt = true;
bool m_customDiffStats = false;
bool m_debug = false;
int m_mode = NICEHASH_MODE;
int m_reuseTimeout = 0;

View File

@@ -66,6 +66,7 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
case IConfig::ProxyPasswordKey: /* --access-password */
return set(doc, "access-password", arg);
case IConfig::CustomDiffStatsKey: /* --custom-diff-stats */
case IConfig::DebugKey: /* --debug */
return transformBoolean(doc, key, true);
@@ -109,6 +110,9 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
void xmrig::ConfigTransform::transformBoolean(rapidjson::Document &doc, int key, bool enable)
{
switch (key) {
case IConfig::CustomDiffStatsKey: /* --custom-diff-stats */
return set(doc, "custom-diff-stats", enable);
case IConfig::DebugKey: /* --debug */
return set(doc, "debug", enable);

View File

@@ -58,6 +58,7 @@ static struct option const options[] = {
{ "bind", 1, nullptr, IConfig::BindKey },
{ "config", 1, nullptr, IConfig::ConfigKey },
{ "custom-diff", 1, nullptr, IConfig::CustomDiffKey },
{ "custom-diff-stats", 0, nullptr, IConfig::CustomDiffStatsKey},
{ "debug", 0, nullptr, IConfig::DebugKey },
{ "donate-level", 1, nullptr, IConfig::DonateLevelKey },
{ "keepalive", 2, nullptr, IConfig::KeepAliveKey },

View File

@@ -52,6 +52,7 @@ Options:\n\
-r, --retries=N number of times to retry before switch to backup server (default: 1)\n\
-R, --retry-pause=N time to pause between retries (default: 1 second)\n\
--custom-diff=N override pool diff\n\
--custom-diff-stats calculate stats using custom diff shares instead of pool shares\n\
--reuse-timeout=N timeout in seconds for reuse pool connections in simple mode\n\
--verbose verbose output\n\
--user-agent=AGENT set custom user-agent string for pool\n\

View File

@@ -30,6 +30,7 @@
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Job.h"
#include "base/net/stratum/SubmitResult.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "base/tools/Handle.h"
@@ -39,6 +40,7 @@
#include "proxy/Events.h"
#include "proxy/events/CloseEvent.h"
#include "proxy/events/LoginEvent.h"
#include "proxy/events/AcceptEvent.h"
#include "proxy/events/SubmitEvent.h"
#include "proxy/Miner.h"
#include "proxy/tls/TlsContext.h"
@@ -257,6 +259,10 @@ bool xmrig::Miner::parseRequest(int64_t id, const char *method, const rapidjson:
if (event->error() == Error::NoError && m_customDiff && event->request.actualDiff() < m_diff) {
success(id, "OK");
SubmitResult result = SubmitResult(1, m_customDiff, event->request.actualDiff(), event->request.id, 0);
AcceptEvent::start(m_mapperId, this, result, false, true);
return true;
}

View File

@@ -83,6 +83,7 @@ xmrig::Proxy::Proxy(Controller *controller) :
m_splitter = splitter;
m_donate = new DonateSplitter(controller);
m_stats = new Stats(controller);
m_shareLog = new ShareLog(controller, m_stats);
m_accessLog = new AccessLog(controller);
m_workers = new Workers(controller);
@@ -97,12 +98,12 @@ xmrig::Proxy::Proxy(Controller *controller) :
# endif
Events::subscribe(IEvent::ConnectionType, m_miners);
Events::subscribe(IEvent::ConnectionType, &m_stats);
Events::subscribe(IEvent::ConnectionType, m_stats);
Events::subscribe(IEvent::CloseType, m_miners);
Events::subscribe(IEvent::CloseType, m_donate);
Events::subscribe(IEvent::CloseType, splitter);
Events::subscribe(IEvent::CloseType, &m_stats);
Events::subscribe(IEvent::CloseType, m_stats);
Events::subscribe(IEvent::CloseType, m_accessLog);
Events::subscribe(IEvent::CloseType, m_workers);
@@ -110,16 +111,16 @@ xmrig::Proxy::Proxy(Controller *controller) :
Events::subscribe(IEvent::LoginType, m_donate);
Events::subscribe(IEvent::LoginType, &m_customDiff);
Events::subscribe(IEvent::LoginType, splitter);
Events::subscribe(IEvent::LoginType, &m_stats);
Events::subscribe(IEvent::LoginType, m_stats);
Events::subscribe(IEvent::LoginType, m_accessLog);
Events::subscribe(IEvent::LoginType, m_workers);
Events::subscribe(IEvent::SubmitType, m_donate);
Events::subscribe(IEvent::SubmitType, splitter);
Events::subscribe(IEvent::SubmitType, &m_stats);
Events::subscribe(IEvent::SubmitType, m_stats);
Events::subscribe(IEvent::SubmitType, m_workers);
Events::subscribe(IEvent::AcceptType, &m_stats);
Events::subscribe(IEvent::AcceptType, m_stats);
Events::subscribe(IEvent::AcceptType, m_shareLog);
Events::subscribe(IEvent::AcceptType, m_workers);
@@ -190,7 +191,7 @@ void xmrig::Proxy::printConnections()
void xmrig::Proxy::printHashrate()
{
LOG_INFO("\x1B[01;32m* \x1B[01;37mspeed\x1B[0m \x1B[01;30m(1m) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(10m) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(1h) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(12h) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(24h) \x1B[01;36m%03.2f kH/s",
m_stats.hashrate(60), m_stats.hashrate(600), m_stats.hashrate(3600), m_stats.hashrate(3600 * 12), m_stats.hashrate(3600 * 24));
m_stats->hashrate(60), m_stats->hashrate(600), m_stats->hashrate(3600), m_stats->hashrate(3600 * 12), m_stats->hashrate(3600 * 24));
}
@@ -208,7 +209,7 @@ void xmrig::Proxy::toggleDebug()
const xmrig::StatsData &xmrig::Proxy::statsData() const
{
return m_stats.data();
return m_stats->data();
}
@@ -272,7 +273,7 @@ void xmrig::Proxy::gc()
void xmrig::Proxy::print()
{
LOG_INFO("\x1B[01;36m%03.2f kH/s\x1B[0m, shares: \x1B[01;37m%" PRIu64 "\x1B[0m/%s%" PRIu64 "\x1B[0m +%" PRIu64 ", upstreams: \x1B[01;37m%" PRIu64 "\x1B[0m, miners: \x1B[01;37m%" PRIu64 "\x1B[0m (max \x1B[01;37m%" PRIu64 "\x1B[0m) +%u/-%u",
m_stats.hashrate(m_controller->config()->printTime()), m_stats.data().accepted, (m_stats.data().rejected ? "\x1B[0;31m" : "\x1B[1;37m"), m_stats.data().rejected,
m_stats->hashrate(m_controller->config()->printTime()), m_stats->data().accepted, (m_stats->data().rejected ? "\x1B[0;31m" : "\x1B[1;37m"), m_stats->data().rejected,
Counters::accepted, m_splitter->upstreams().active, Counters::miners(), Counters::maxMiners(), Counters::added(), Counters::removed());
Counters::reset();
@@ -281,7 +282,7 @@ void xmrig::Proxy::print()
void xmrig::Proxy::tick()
{
m_stats.tick(m_ticks, m_splitter);
m_stats->tick(m_ticks, m_splitter);
m_ticks++;

View File

@@ -99,7 +99,7 @@ private:
Miners *m_miners;
ProxyDebug *m_debug;
ShareLog *m_shareLog;
Stats m_stats;
Stats *m_stats;
std::vector<Server*> m_servers;
TlsContext *m_tls;
uint64_t m_ticks;

View File

@@ -24,13 +24,16 @@
#include "base/net/stratum/SubmitResult.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "Counters.h"
#include "interfaces/ISplitter.h"
#include "proxy/events/AcceptEvent.h"
#include "proxy/Stats.h"
xmrig::Stats::Stats() :
xmrig::Stats::Stats(Controller *controller) :
m_controller(controller),
m_hashrate(4)
{
}
@@ -107,7 +110,15 @@ void xmrig::Stats::onRejectedEvent(IEvent *event)
void xmrig::Stats::accept(const AcceptEvent *event)
{
m_hashrate.add(event->result.diff);
if (event->isCustomDiff() && !m_controller->config()->isCustomDiffStats()) {
return;
}
m_hashrate.add(m_controller->config()->isCustomDiffStats() ? event->statsDiff() : event->result.diff);
if (event->isCustomDiff()) {
return;
}
m_data.accepted++;
m_data.hashes += event->result.diff;

View File

@@ -38,13 +38,14 @@ namespace xmrig {
class AcceptEvent;
class Controller;
class ISplitter;
class Stats : public IEventListener
{
public:
Stats();
Stats(Controller *controller);
~Stats() override;
void tick(uint64_t ticks, const ISplitter *splitter);
@@ -60,6 +61,7 @@ private:
void accept(const AcceptEvent *event);
void reject(const AcceptEvent *event);
Controller *m_controller;
StatsData m_data;
TickingCounter<uint32_t> m_hashrate;
};

View File

@@ -26,6 +26,8 @@
#define XMRIG_ACCEPTEVENT_H
#include "base/net/stratum/SubmitResult.h"
#include "proxy/Miner.h"
#include "proxy/events/MinerEvent.h"
#include "proxy/Error.h"
@@ -33,31 +35,31 @@
namespace xmrig {
class SubmitResult;
class AcceptEvent : public MinerEvent
{
public:
static inline bool start(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, const char *error = nullptr)
static inline bool start(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, bool customDiff, const char *error = nullptr)
{
return exec(new (m_buf) AcceptEvent(mapperId, miner, result, donate, error));
return exec(new (m_buf) AcceptEvent(mapperId, miner, result, donate, customDiff, error));
}
const SubmitResult &result;
inline bool isCustomDiff() const { return m_customDiff; }
inline bool isDonate() const { return m_donate; }
inline bool isRejected() const override { return m_error != nullptr; }
inline const char *error() const { return m_error; }
inline size_t mapperId() const { return m_mapperId; }
inline uint64_t statsDiff() const { return (miner()->customDiff() ? std::min(miner()->customDiff(), result.diff) : result.diff); }
protected:
inline AcceptEvent(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, const char *error)
inline AcceptEvent(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, bool customDiff, const char *error)
: MinerEvent(AcceptType, miner),
result(result),
m_customDiff(customDiff),
m_donate(donate),
m_error(error),
m_mapperId(mapperId)
@@ -65,6 +67,7 @@ protected:
private:
bool m_customDiff;
bool m_donate;
const char *m_error;
size_t m_mapperId;

View File

@@ -35,7 +35,7 @@
#include "proxy/Stats.h"
xmrig::ShareLog::ShareLog(Controller *controller, const Stats &stats) :
xmrig::ShareLog::ShareLog(Controller *controller, Stats *stats) :
m_stats(stats),
m_controller(controller)
{
@@ -77,12 +77,12 @@ void xmrig::ShareLog::onRejectedEvent(IEvent *event)
void xmrig::ShareLog::accept(const AcceptEvent *event)
{
if (!m_controller->config()->isVerbose() || event->isDonate()) {
if (!m_controller->config()->isVerbose() || event->isDonate() || event->isCustomDiff()) {
return;
}
LOG_INFO("#%03u " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " ip " WHITE_BOLD("%s") " " BLACK_BOLD("(%" PRIu64 " ms)"),
event->mapperId(), m_stats.data().accepted, m_stats.data().rejected, m_stats.data().invalid, event->result.diff, event->ip(), event->result.elapsed);
event->mapperId(), m_stats->data().accepted, m_stats->data().rejected, m_stats->data().invalid, event->result.diff, event->ip(), event->result.elapsed);
}
@@ -93,5 +93,5 @@ void xmrig::ShareLog::reject(const AcceptEvent *event)
}
LOG_INFO("#%03u " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " ip " WHITE_BOLD("%s") " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
event->mapperId(), m_stats.data().accepted, m_stats.data().rejected, m_stats.data().invalid, event->result.diff, event->ip(), event->error(), event->result.elapsed);
event->mapperId(), m_stats->data().accepted, m_stats->data().rejected, m_stats->data().invalid, event->result.diff, event->ip(), event->error(), event->result.elapsed);
}

View File

@@ -40,7 +40,7 @@ class Stats;
class ShareLog : public IEventListener
{
public:
ShareLog(Controller *controller, const Stats &stats);
ShareLog(Controller *controller, Stats *stats);
~ShareLog() override;
protected:
@@ -51,7 +51,7 @@ private:
void accept(const AcceptEvent *event);
void reject(const AcceptEvent *event);
const Stats &m_stats;
Stats *m_stats;
Controller *m_controller;
};

View File

@@ -117,7 +117,7 @@ void xmrig::DonateMapper::onLoginSuccess(IClient *)
void xmrig::DonateMapper::onResultAccepted(IClient *, const SubmitResult &result, const char *error)
{
AcceptEvent::start(m_id, m_miner, result, true, error);
AcceptEvent::start(m_id, m_miner, result, true, false, error);
if (error) {
m_miner->replyWithError(result.reqId, error);

View File

@@ -245,7 +245,7 @@ void xmrig::NonceMapper::onResultAccepted(IStrategy *, IClient *client, const Su
{
const SubmitCtx ctx = submitCtx(result.seq);
AcceptEvent::start(m_id, ctx.miner, result, client->id() == -1, error);
AcceptEvent::start(m_id, ctx.miner, result, client->id() == -1, false, error);
if (!ctx.miner) {
return;

View File

@@ -218,7 +218,7 @@ void xmrig::SimpleMapper::onPause(IStrategy *strategy)
void xmrig::SimpleMapper::onResultAccepted(IStrategy *, IClient *client, const SubmitResult &result, const char *error)
{
AcceptEvent::start(m_id, m_miner, result, client->id() == -1, error);
AcceptEvent::start(m_id, m_miner, result, client->id() == -1, false, error);
if (!m_miner) {
return;

View File

@@ -57,12 +57,12 @@ xmrig::Worker::Worker(size_t id, const std::string &name, const std::string &ip)
}
void xmrig::Worker::add(const SubmitResult &result)
void xmrig::Worker::add(uint64_t diff)
{
m_accepted++;
m_hashes += result.diff;
m_hashes += diff;
m_hashrate.add(result.diff);
m_hashrate.add(diff);
using namespace std::chrono;
m_lastHash = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();

View File

@@ -35,16 +35,13 @@
namespace xmrig {
class SubmitResult;
class Worker
{
public:
Worker();
Worker(size_t id, const std::string &name, const std::string &ip);
void add(const SubmitResult &result);
void add(uint64_t diff);
void tick(uint64_t ticks);
inline const char *ip() const { return m_ip.c_str(); }

View File

@@ -294,6 +294,10 @@ size_t xmrig::Workers::add(const Miner *miner)
void xmrig::Workers::accept(const AcceptEvent *event)
{
if (event->isCustomDiff() && !m_controller->config()->isCustomDiffStats()) {
return;
}
size_t index = 0;
if (!indexByMiner(event->miner(), &index)) {
return;
@@ -301,7 +305,7 @@ void xmrig::Workers::accept(const AcceptEvent *event)
Worker &worker = m_workers[index];
if (!event->isRejected()) {
worker.add(event->result);
worker.add(m_controller->config()->isCustomDiffStats() ? event->statsDiff() : event->result.diff);
}
else {
worker.reject(false);