Skip to content

Commit

Permalink
Add custom-diff-stats option for alternative hashrate calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
CR4DL committed Dec 29, 2019
1 parent 0b10ef6 commit 6ce8fbd
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/base/kernel/interfaces/IConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class IConfig
AccessLogFileKey = 'A',
BindKey = 'b',
CustomDiffKey = 1102,
CustomDiffStatsKey = 1104,
DebugKey = 1101,
ModeKey = 'm',
PoolCoinKey = 'C',
Expand Down
1 change: 1 addition & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"colors": true,
"custom-diff": 0,
"custom-diff-stats": false,
"donate-level": 0,
"log-file": null,
"mode": "nicehash",
Expand Down
2 changes: 2 additions & 0 deletions src/core/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/core/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Config : public BaseConfig
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(); }
Expand All @@ -103,6 +104,7 @@ class Config : public BaseConfig

BindHosts m_bind;
bool m_algoExt = true;
bool m_customDiffStats = false;
bool m_debug = false;
int m_mode = NICEHASH_MODE;
int m_reuseTimeout = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/core/config/ConfigTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/core/config/Config_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions src/core/config/usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
19 changes: 10 additions & 9 deletions src/proxy/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -97,29 +98,29 @@ 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);

Events::subscribe(IEvent::LoginType, m_login);
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);

Expand Down Expand Up @@ -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));
}


Expand All @@ -208,7 +209,7 @@ void xmrig::Proxy::toggleDebug()

const xmrig::StatsData &xmrig::Proxy::statsData() const
{
return m_stats.data();
return m_stats->data();
}


Expand Down Expand Up @@ -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();
Expand All @@ -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++;

Expand Down
2 changes: 1 addition & 1 deletion src/proxy/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Proxy : public IBaseListener
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;
Expand Down
11 changes: 9 additions & 2 deletions src/proxy/Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -107,7 +110,11 @@ void xmrig::Stats::onRejectedEvent(IEvent *event)

void xmrig::Stats::accept(const AcceptEvent *event)
{
m_hashrate.add(event->statsDiff());
if (event->isCustomDiff() && !m_controller->config()->isCustomDiffStats()) {
return;
}

m_hashrate.add(m_controller->config()->isCustomDiffStats() ? event->statsDiff() : event->result.diff);

if (event->isCustomDiff()) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/proxy/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -60,6 +61,7 @@ class Stats : public IEventListener
void accept(const AcceptEvent *event);
void reject(const AcceptEvent *event);

Controller *m_controller;
StatsData m_data;
TickingCounter<uint32_t> m_hashrate;
};
Expand Down
6 changes: 3 additions & 3 deletions src/proxy/log/ShareLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -82,7 +82,7 @@ void xmrig::ShareLog::accept(const AcceptEvent *event)
}

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);
}


Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions src/proxy/log/ShareLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -51,7 +51,7 @@ class ShareLog : public IEventListener
void accept(const AcceptEvent *event);
void reject(const AcceptEvent *event);

const Stats &m_stats;
Stats *m_stats;
Controller *m_controller;
};

Expand Down
3 changes: 0 additions & 3 deletions src/proxy/workers/Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
namespace xmrig {


class SubmitResult;


class Worker
{
public:
Expand Down
6 changes: 5 additions & 1 deletion src/proxy/workers/Workers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,18 @@ 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;
}

Worker &worker = m_workers[index];
if (!event->isRejected()) {
worker.add(event->statsDiff());
worker.add(m_controller->config()->isCustomDiffStats() ? event->statsDiff() : event->result.diff);
}
else {
worker.reject(false);
Expand Down

0 comments on commit 6ce8fbd

Please sign in to comment.