This commit is contained in:
MoneroOcean 2020-06-10 18:14:06 -07:00
commit 0ada4ca4ac
150 changed files with 12300 additions and 8764 deletions

View file

@ -43,7 +43,7 @@ class JobResult
public:
JobResult() = delete;
inline JobResult(const Job &job, uint32_t nonce, const uint8_t *result) :
inline JobResult(const Job &job, uint64_t nonce, const uint8_t *result, const uint8_t* header_hash = nullptr, const uint8_t *mix_hash = nullptr) :
algorithm(job.algorithm()),
clientId(job.clientId()),
jobId(job.id()),
@ -53,6 +53,14 @@ public:
index(job.index())
{
memcpy(m_result, result, sizeof(m_result));
if (header_hash) {
memcpy(m_headerHash, header_hash, sizeof(m_headerHash));
}
if (mix_hash) {
memcpy(m_mixHash, mix_hash, sizeof(m_mixHash));
}
}
inline JobResult(const Job &job) :
@ -66,20 +74,24 @@ public:
{
}
inline const uint8_t *result() const { return m_result; }
inline uint64_t actualDiff() const { return Job::toDiff(reinterpret_cast<const uint64_t*>(m_result)[3]); }
inline uint8_t *result() { return m_result; }
inline const uint8_t *result() const { return m_result; }
inline uint64_t actualDiff() const { return Job::toDiff(reinterpret_cast<const uint64_t*>(m_result)[3]); }
inline uint8_t *result() { return m_result; }
inline const uint8_t *headerHash() const { return m_headerHash; }
inline const uint8_t *mixHash() const { return m_mixHash; }
const Algorithm algorithm;
const String clientId;
const String jobId;
const uint32_t backend;
const uint32_t nonce;
const uint64_t nonce;
const uint64_t diff;
const uint8_t index;
private:
uint8_t m_result[32] = { 0 };
uint8_t m_result[32] = { 0 };
uint8_t m_headerHash[32] = { 0 };
uint8_t m_mixHash[32] = { 0 };
};

View file

@ -38,6 +38,12 @@
#endif
#ifdef XMRIG_ALGO_KAWPOW
# include "crypto/kawpow/KPCache.h"
# include "crypto/kawpow/KPHash.h"
#endif
#if defined(XMRIG_FEATURE_OPENCL) || defined(XMRIG_FEATURE_CUDA)
# include "base/tools/Baton.h"
# include "crypto/cn/CnCtx.h"
@ -132,6 +138,39 @@ static void getResults(JobBundle &bundle, std::vector<JobResult> &results, uint3
else if (algorithm.family() == Algorithm::ARGON2) {
errors += bundle.nonces.size(); // TODO ARGON2
}
else if (algorithm.family() == Algorithm::KAWPOW) {
# ifdef XMRIG_ALGO_KAWPOW
for (uint32_t nonce : bundle.nonces) {
*bundle.job.nonce() = nonce;
uint8_t header_hash[32];
uint64_t full_nonce;
memcpy(header_hash, bundle.job.blob(), sizeof(header_hash));
memcpy(&full_nonce, bundle.job.blob() + sizeof(header_hash), sizeof(full_nonce));
uint32_t output[8];
uint32_t mix_hash[8];
{
std::lock_guard<std::mutex> lock(KPCache::s_cacheMutex);
KPCache::s_cache.init(bundle.job.height() / KPHash::EPOCH_LENGTH);
KPHash::calculate(KPCache::s_cache, bundle.job.height(), header_hash, full_nonce, output, mix_hash);
}
for (size_t i = 0; i < sizeof(hash); ++i) {
hash[i] = ((uint8_t*)output)[sizeof(hash) - 1 - i];
}
if (*reinterpret_cast<uint64_t*>(hash + 24) < bundle.job.target()) {
results.emplace_back(bundle.job, full_nonce, (uint8_t*)output, bundle.job.blob(), (uint8_t*)mix_hash);
}
else {
LOG_ERR("COMPUTE ERROR"); // TODO Extend information.
++errors;
}
}
# endif
}
else {
cryptonight_ctx *ctx[1];
CnCtx::create(ctx, memory->scratchpad(), memory->size(), 1);

View file

@ -31,6 +31,7 @@
#include "3rdparty/rapidjson/document.h"
#include "backend/common/Tags.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/net/stratum/Client.h"
#include "base/net/stratum/NetworkState.h"
#include "base/net/stratum/SubmitResult.h"
@ -57,22 +58,6 @@
#include <memory>
namespace xmrig {
static const char *tag = BLUE_BG_BOLD(WHITE_BOLD_S " net ");
} // namespace xmrig
const char *xmrig::net_tag()
{
return tag;
}
xmrig::Network::Network(Controller *controller) :
m_controller(controller)
{
@ -116,17 +101,17 @@ void xmrig::Network::connect()
void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
{
if (m_donate && m_donate == strategy) {
LOG_NOTICE("%s " WHITE_BOLD("dev donate started"), tag);
LOG_NOTICE("%s " WHITE_BOLD("dev donate started"), Tags::network());
return;
}
const char *tlsVersion = client->tlsVersion();
LOG_INFO("%s " WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
tag, client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
Tags::network(), client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
const char *fingerprint = client->tlsFingerprint();
if (fingerprint != nullptr) {
LOG_INFO("%s " BLACK_BOLD("fingerprint (SHA-256): \"%s\""), tag, fingerprint);
LOG_INFO("%s " BLACK_BOLD("fingerprint (SHA-256): \"%s\""), Tags::network(), fingerprint);
}
}
@ -147,7 +132,7 @@ void xmrig::Network::onConfigChanged(Config *config, Config *previousConfig)
}
void xmrig::Network::onJob(IStrategy *strategy, IClient *client, const Job &job)
void xmrig::Network::onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value &)
{
if (m_donate && m_donate->isActive() && m_donate != strategy) {
return;
@ -203,27 +188,44 @@ 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"), tag);
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"), tag);
LOG_ERR("%s " RED("no active pools, stop mining"), Tags::network());
return m_controller->miner()->pause();
}
}
static void scale_diff(uint64_t& diff, const char* &scale)
{
if (diff >= 100000000) {
diff /= 1000000;
scale = "M";
}
else if (diff >= 1000000) {
diff /= 1000;
scale = "K";
}
}
void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult &result, const char *error)
{
uint64_t diff = result.diff;
const char* scale = "";
scale_diff(diff, scale);
if (error) {
LOG_INFO("%s " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
backend_tag(result.backend), m_state->accepted(), m_state->rejected(), result.diff, error, result.elapsed);
LOG_INFO("%s " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64 "%s") " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
backend_tag(result.backend), m_state->accepted(), m_state->rejected(), diff, scale, error, result.elapsed);
}
else {
LOG_INFO("%s " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"),
backend_tag(result.backend), m_state->accepted(), m_state->rejected(), result.diff, result.elapsed);
LOG_INFO("%s " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64 "%s") " " BLACK_BOLD("(%" PRIu64 " ms)"),
backend_tag(result.backend), m_state->accepted(), m_state->rejected(), diff, scale, result.elapsed);
}
}
@ -253,13 +255,17 @@ void xmrig::Network::onRequest(IApiRequest &request)
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
{
uint64_t diff = job.diff();
const char* scale = "";
scale_diff(diff, scale);
if (job.height()) {
LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64),
tag, client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName(), job.height());
LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64 "%s") " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64),
Tags::network(), client->pool().host().data(), client->pool().port(), diff, scale, job.algorithm().shortName(), job.height());
}
else {
LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s"),
tag, client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName());
LOG_INFO("%s " MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64 "%s") " algo " WHITE_BOLD("%s"),
Tags::network(), client->pool().host().data(), client->pool().port(), diff, scale, job.algorithm().shortName());
}
if (!donate && m_donate) {

View file

@ -64,7 +64,7 @@ protected:
void onActive(IStrategy *strategy, IClient *client) override;
void onConfigChanged(Config *config, Config *previousConfig) override;
void onJob(IStrategy *strategy, IClient *client, const Job &job) override;
void onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value &params) override;
void onJobResult(const JobResult &result) override;
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value &params) override;
void onPause(IStrategy *strategy) override;

View file

@ -61,10 +61,17 @@ xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener
m_listener(listener)
{
static char donate_user[] = "89TxfrUmqJJcb1V124WsUzA78Xa3UYHt7Bg8RGMhXVeZYPN8cE5CZEk58Y1m23ZMLHN7wYeJ9da5n5MXharEjrm41hSnWHL";
# ifndef XMRIG_FEATURE_TLS
m_pools.emplace_back(kDonateHost, 20001, donate_user, nullptr, 0, true, true);
# ifdef XMRIG_ALGO_KAWPOW
constexpr Pool::Mode mode = Pool::MODE_AUTO_ETH;
# else
constexpr Pool::Mode mode = Pool::MODE_POOL;
# endif
m_pools.emplace_back(kDonateHost, 10001, donate_user, nullptr, 0, true);
# ifndef XMRIG_FEATURE_TLS
m_pools.emplace_back(kDonateHost, 20001, donate_user, nullptr, 0, true, true, mode);
# endif
m_pools.emplace_back(kDonateHost, 10001, donate_user, nullptr, 0, true, false, mode);
if (m_pools.size() > 1) {
m_strategy = new FailoverStrategy(m_pools, 10, 2, this, true);
@ -244,7 +251,7 @@ xmrig::IClient *xmrig::DonateStrategy::createProxy()
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(), 0, true, client->isTLS());
Pool pool(client->pool().proxy().isValid() ? client->pool().host() : client->ip(), client->pool().port(), m_userId, client->pool().password(), 0, true, client->isTLS(), Pool::MODE_POOL);
pool.setAlgo(client->pool().algorithm());
pool.setProxy(client->pool().proxy());
@ -283,10 +290,10 @@ void xmrig::DonateStrategy::setAlgorithms(rapidjson::Document &doc, rapidjson::V
}
void xmrig::DonateStrategy::setJob(IClient *client, const Job &job)
void xmrig::DonateStrategy::setJob(IClient *client, const Job &job, const rapidjson::Value &params)
{
if (isActive()) {
m_listener->onJob(this, client, job);
m_listener->onJob(this, client, job, params);
}
}

View file

@ -56,8 +56,8 @@ public:
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) override { setJob(client, job); }
inline void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &) override { setJob(client, job); }
inline void onJob(IStrategy *, IClient *client, const Job &job, const rapidjson::Value &params) override { setJob(client, job, params); }
inline void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &params) 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 {}
@ -95,7 +95,7 @@ private:
IClient *createProxy();
void idle(double min, double max);
void setAlgorithms(rapidjson::Document &doc, rapidjson::Value &params);
void setJob(IClient *client, const Job &job);
void setJob(IClient *client, const Job &job, const rapidjson::Value &params);
void setResult(IClient *client, const SubmitResult &result, const char *error);
void setState(State state);