mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-22 19:49:36 +00:00
Implemented donate for KawPow.
This commit is contained in:
parent
dd8777c11b
commit
bbd3f05bf6
24 changed files with 320 additions and 166 deletions
|
@ -41,7 +41,7 @@ class WorkerJob
|
|||
{
|
||||
public:
|
||||
inline const Job ¤tJob() const { return m_jobs[index()]; }
|
||||
inline uint32_t *nonce(size_t i = 0) { return reinterpret_cast<uint32_t*>(blob() + (i * currentJob().size()) + nonce_offset()); }
|
||||
inline uint32_t *nonce(size_t i = 0) { return reinterpret_cast<uint32_t*>(blob() + (i * currentJob().size()) + nonceOffset()); }
|
||||
inline uint64_t sequence() const { return m_sequence; }
|
||||
inline uint8_t *blob() { return m_blobs[index()]; }
|
||||
inline uint8_t index() const { return m_index; }
|
||||
|
@ -88,8 +88,8 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
inline int32_t nonce_offset() const { return currentJob().nonce_offset(); }
|
||||
inline size_t nonce_size() const { return currentJob().nonce_size(); }
|
||||
inline int32_t nonceOffset() const { return currentJob().nonceOffset(); }
|
||||
inline size_t nonceSize() const { return currentJob().nonceSize(); }
|
||||
|
||||
inline void save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ private:
|
|||
template<>
|
||||
inline uint32_t *xmrig::WorkerJob<1>::nonce(size_t)
|
||||
{
|
||||
return reinterpret_cast<uint32_t*>(blob() + nonce_offset());
|
||||
return reinterpret_cast<uint32_t*>(blob() + nonceOffset());
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,7 +139,7 @@ inline bool xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize)
|
|||
}
|
||||
|
||||
// Increment higher 32 bits of a 64-bit nonce when lower 32 bits overflow
|
||||
if (!currentJob().isNicehash() && (nonce_size() == sizeof(uint64_t)) && (*n < prev_nonce)) {
|
||||
if (!currentJob().isNicehash() && (nonceSize() == sizeof(uint64_t)) && (*n < prev_nonce)) {
|
||||
++n[1];
|
||||
|
||||
Job& job = m_jobs[index()];
|
||||
|
|
|
@ -43,7 +43,6 @@ set(HEADERS_BASE
|
|||
src/base/net/http/HttpListener.h
|
||||
src/base/net/stratum/BaseClient.h
|
||||
src/base/net/stratum/Client.h
|
||||
src/base/net/stratum/EthStratumClient.h
|
||||
src/base/net/stratum/Job.h
|
||||
src/base/net/stratum/NetworkState.h
|
||||
src/base/net/stratum/Pool.h
|
||||
|
@ -96,7 +95,6 @@ set(SOURCES_BASE
|
|||
src/base/net/http/Http.cpp
|
||||
src/base/net/stratum/BaseClient.cpp
|
||||
src/base/net/stratum/Client.cpp
|
||||
src/base/net/stratum/EthStratumClient.cpp
|
||||
src/base/net/stratum/Job.cpp
|
||||
src/base/net/stratum/NetworkState.cpp
|
||||
src/base/net/stratum/Pool.cpp
|
||||
|
@ -209,3 +207,16 @@ if (WITH_ENV_VARS)
|
|||
else()
|
||||
remove_definitions(/DXMRIG_FEATURE_ENV)
|
||||
endif()
|
||||
|
||||
|
||||
if (WITH_KAWPOW)
|
||||
list(APPEND HEADERS_BASE
|
||||
src/base/net/stratum/AutoClient.h
|
||||
src/base/net/stratum/EthStratumClient.h
|
||||
)
|
||||
|
||||
list(APPEND SOURCES_BASE
|
||||
src/base/net/stratum/AutoClient.cpp
|
||||
src/base/net/stratum/EthStratumClient.cpp
|
||||
)
|
||||
endif()
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
inline bool isValid() const { return m_id != INVALID; }
|
||||
inline Id id() const { return m_id; }
|
||||
|
||||
Algorithm::Id algorithm(uint8_t blobVersion) const;
|
||||
Algorithm::Id algorithm(uint8_t blobVersion = 255) const;
|
||||
const char *name() const;
|
||||
rapidjson::Value toJSON() const;
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -42,10 +43,13 @@ class SubmitResult;
|
|||
class IStrategyListener
|
||||
{
|
||||
public:
|
||||
virtual ~IStrategyListener() = default;
|
||||
XMRIG_DISABLE_COPY_MOVE(IStrategyListener);
|
||||
|
||||
IStrategyListener() = default;
|
||||
virtual ~IStrategyListener() = default;
|
||||
|
||||
virtual void onActive(IStrategy *strategy, IClient *client) = 0;
|
||||
virtual void onJob(IStrategy *strategy, IClient *client, const Job &job) = 0;
|
||||
virtual void onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value ¶ms) = 0;
|
||||
virtual void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) = 0;
|
||||
virtual void onPause(IStrategy *strategy) = 0;
|
||||
virtual void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) = 0;
|
||||
|
|
90
src/base/net/stratum/AutoClient.cpp
Normal file
90
src/base/net/stratum/AutoClient.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 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 "base/net/stratum/AutoClient.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
||||
|
||||
xmrig::AutoClient::AutoClient(int id, const char *agent, IClientListener *listener) :
|
||||
EthStratumClient(id, agent, listener)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::AutoClient::handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
|
||||
{
|
||||
if (m_mode == DEFAULT_MODE) {
|
||||
return Client::handleResponse(id, result, error);
|
||||
}
|
||||
|
||||
return EthStratumClient::handleResponse(id, result, error);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::AutoClient::parseLogin(const rapidjson::Value &result, int *code)
|
||||
{
|
||||
if (result.HasMember("job")) {
|
||||
return Client::parseLogin(result, code);
|
||||
}
|
||||
|
||||
setRpcId(Json::getString(result, "id"));
|
||||
if (rpcId().isNull()) {
|
||||
*code = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
const Algorithm algo(Json::getString(result, "algo"));
|
||||
if (algo.family() != Algorithm::KAWPOW) {
|
||||
*code = 6;
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
setExtraNonce(Json::getValue(result, "extra_nonce"));
|
||||
} catch (const std::exception &ex) {
|
||||
*code = 6;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mode = ETH_MODE;
|
||||
setAlgo(algo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int64_t xmrig::AutoClient::submit(const JobResult &result)
|
||||
{
|
||||
if (m_mode == DEFAULT_MODE) {
|
||||
return Client::submit(result);
|
||||
}
|
||||
|
||||
return EthStratumClient::submit(result);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::AutoClient::parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error)
|
||||
{
|
||||
if (m_mode == DEFAULT_MODE) {
|
||||
return Client::parseNotification(method, params, error);
|
||||
}
|
||||
|
||||
return EthStratumClient::parseNotification(method, params, error);
|
||||
}
|
61
src/base/net/stratum/AutoClient.h
Normal file
61
src/base/net/stratum/AutoClient.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 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_AUTOCLIENT_H
|
||||
#define XMRIG_AUTOCLIENT_H
|
||||
|
||||
|
||||
#include "base/net/stratum/EthStratumClient.h"
|
||||
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class AutoClient : public EthStratumClient
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(AutoClient)
|
||||
|
||||
AutoClient(int id, const char *agent, IClientListener *listener);
|
||||
~AutoClient() override = default;
|
||||
|
||||
protected:
|
||||
inline void login() override { Client::login(); }
|
||||
|
||||
bool handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error) override;
|
||||
bool parseLogin(const rapidjson::Value &result, int *code) override;
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error) override;
|
||||
|
||||
private:
|
||||
enum Mode {
|
||||
DEFAULT_MODE,
|
||||
ETH_MODE
|
||||
};
|
||||
|
||||
Mode m_mode = DEFAULT_MODE;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_AUTOCLIENT_H */
|
|
@ -445,23 +445,6 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code)
|
||||
{
|
||||
m_rpcId = result["id"].GetString();
|
||||
if (m_rpcId.isNull()) {
|
||||
*code = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
parseExtensions(result);
|
||||
|
||||
const bool rc = parseJob(result["job"], code);
|
||||
m_jobs = 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Client::send(BIO *bio)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
|
@ -629,6 +612,23 @@ void xmrig::Client::handshake()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code)
|
||||
{
|
||||
setRpcId(Json::getString(result, "id"));
|
||||
if (rpcId().isNull()) {
|
||||
*code = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
parseExtensions(result);
|
||||
|
||||
const bool rc = parseJob(result["job"], code);
|
||||
m_jobs = 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Client::login()
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
@ -819,7 +819,11 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
|
|||
|
||||
m_failures = 0;
|
||||
m_listener->onLoginSuccess(this);
|
||||
m_listener->onJobReceived(this, m_job, result["job"]);
|
||||
|
||||
if (m_job.isValid()) {
|
||||
m_listener->onJobReceived(this, m_job, result["job"]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,13 +81,16 @@ protected:
|
|||
|
||||
void onResolved(const Dns &dns, int status) override;
|
||||
|
||||
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
|
||||
inline const char *mode() const override { return "pool"; }
|
||||
inline void onLine(char *line, size_t size) override { parse(line, size); }
|
||||
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
|
||||
inline const char *mode() const override { return "pool"; }
|
||||
inline void onLine(char *line, size_t size) override { parse(line, size); }
|
||||
|
||||
inline const char* agent() const { return m_agent; }
|
||||
inline const char* url() const { return m_pool.url(); }
|
||||
inline const char *agent() const { return m_agent; }
|
||||
inline const char *url() const { return m_pool.url(); }
|
||||
inline const String &rpcId() const { return m_rpcId; }
|
||||
inline void setRpcId(const char *id) { m_rpcId = id; }
|
||||
|
||||
virtual bool parseLogin(const rapidjson::Value &result, int *code);
|
||||
virtual void login();
|
||||
virtual void parseNotification(const char* method, const rapidjson::Value& params, const rapidjson::Value& error);
|
||||
|
||||
|
@ -100,7 +103,6 @@ private:
|
|||
|
||||
bool isCriticalError(const char *message);
|
||||
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
||||
bool parseLogin(const rapidjson::Value &result, int *code);
|
||||
bool send(BIO *bio);
|
||||
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
|
||||
bool write(const uv_buf_t &buf);
|
||||
|
|
|
@ -63,8 +63,8 @@ int64_t xmrig::EthStratumClient::submit(const JobResult& result)
|
|||
auto& allocator = doc.GetAllocator();
|
||||
|
||||
Value params(kArrayType);
|
||||
params.PushBack(StringRef(m_pool.user().data()), allocator);
|
||||
params.PushBack(StringRef(result.jobId.data()), allocator);
|
||||
params.PushBack(m_pool.user().toJSON(), allocator);
|
||||
params.PushBack(result.jobId.toJSON(), allocator);
|
||||
|
||||
std::stringstream s;
|
||||
s << "0x" << std::hex << std::setw(16) << std::setfill('0') << result.nonce;
|
||||
|
@ -135,15 +135,14 @@ bool xmrig::EthStratumClient::handleResponse(int64_t id, const rapidjson::Value
|
|||
return true;
|
||||
}
|
||||
|
||||
handleSubmitResponse(id, errorMessage(error));
|
||||
return false;
|
||||
return handleSubmitResponse(id, errorMessage(error));
|
||||
}
|
||||
|
||||
|
||||
void xmrig::EthStratumClient::parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &)
|
||||
{
|
||||
if (strcmp(method, "mining.set_target") == 0) {
|
||||
return setTarget(params);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(method, "mining.notify") == 0) {
|
||||
|
@ -162,11 +161,13 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
|
|||
Job job;
|
||||
job.setId(arr[0].GetString());
|
||||
|
||||
Algorithm algo = m_pool.algorithm();
|
||||
if (algo == Algorithm::INVALID) {
|
||||
algo = m_pool.coin().algorithm(0);
|
||||
auto algo = m_pool.algorithm();
|
||||
if (!algo.isValid()) {
|
||||
algo = m_pool.coin().algorithm();
|
||||
}
|
||||
|
||||
job.setAlgorithm(algo);
|
||||
job.setExtraNonce(m_extraNonce.second);
|
||||
|
||||
std::stringstream s;
|
||||
|
||||
|
@ -174,7 +175,7 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
|
|||
s << arr[1].GetString();
|
||||
|
||||
// nonce template (8 bytes)
|
||||
for (uint64_t i = 0, k = m_extraNonce; i < sizeof(m_extraNonce); ++i, k >>= 8) {
|
||||
for (uint64_t i = 0, k = m_extraNonce.first; i < sizeof(m_extraNonce.first); ++i, k >>= 8) {
|
||||
s << std::hex << std::setw(2) << std::setfill('0') << (k & 0xFF);
|
||||
}
|
||||
|
||||
|
@ -187,7 +188,7 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
|
|||
std::string target_str = arr[3].GetString();
|
||||
target_str.resize(16, '0');
|
||||
const uint64_t target = strtoull(target_str.c_str(), nullptr, 16);
|
||||
job.setDiff(job.toDiff(target));
|
||||
job.setDiff(Job::toDiff(target));
|
||||
|
||||
job.setHeight(arr[5].GetUint64());
|
||||
|
||||
|
@ -223,40 +224,14 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
|
|||
}
|
||||
|
||||
|
||||
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error) const
|
||||
void xmrig::EthStratumClient::setExtraNonce(const rapidjson::Value &nonce)
|
||||
{
|
||||
if (error.IsArray() && error.GetArray().Size() > 1) {
|
||||
auto &value = error.GetArray()[1];
|
||||
if (value.IsString()) {
|
||||
return value.GetString();
|
||||
}
|
||||
}
|
||||
|
||||
if (error.IsString()) {
|
||||
return error.GetString();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::EthStratumClient::extraNonce(const rapidjson::Value &result) const
|
||||
{
|
||||
if (!result.IsArray()) {
|
||||
throw std::runtime_error("invalid mining.subscribe response: result is not an array");
|
||||
}
|
||||
|
||||
if (result.GetArray().Size() <= 1) {
|
||||
throw std::runtime_error("invalid mining.subscribe response: result array is too short");
|
||||
}
|
||||
|
||||
auto &extra_nonce = result.GetArray()[1];
|
||||
if (!extra_nonce.IsString()) {
|
||||
if (!nonce.IsString()) {
|
||||
throw std::runtime_error("invalid mining.subscribe response: extra nonce is not a string");
|
||||
}
|
||||
|
||||
const char* s = extra_nonce.GetString();
|
||||
size_t len = extra_nonce.GetStringLength();
|
||||
const char *s = nonce.GetString();
|
||||
size_t len = nonce.GetStringLength();
|
||||
|
||||
// Skip "0x"
|
||||
if ((len >= 2) && (s[0] == '0') && (s[1] == 'x')) {
|
||||
|
@ -277,30 +252,28 @@ uint64_t xmrig::EthStratumClient::extraNonce(const rapidjson::Value &result) con
|
|||
|
||||
LOG_DEBUG("[%s] extra nonce set to %s", url(), s);
|
||||
|
||||
return std::stoull(extra_nonce_str, nullptr, 16);
|
||||
|
||||
m_extraNonce = { std::stoull(extra_nonce_str, nullptr, 16), s };
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::EthStratumClient::target(const rapidjson::Value ¶ms) const
|
||||
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error) const
|
||||
{
|
||||
if (!params.IsArray()) {
|
||||
throw std::runtime_error("invalid mining.set_target notification: params is not an array");
|
||||
if (error.IsArray() && error.GetArray().Size() > 1) {
|
||||
auto &value = error.GetArray()[1];
|
||||
if (value.IsString()) {
|
||||
return value.GetString();
|
||||
}
|
||||
}
|
||||
|
||||
if (params.GetArray().Size() != 1) {
|
||||
throw std::runtime_error("invalid mining.set_target notification: params array has wrong size");
|
||||
if (error.IsString()) {
|
||||
return error.GetString();
|
||||
}
|
||||
|
||||
auto &new_target = params.GetArray()[0];
|
||||
if (!new_target.IsString()) {
|
||||
throw std::runtime_error("invalid mining.set_target notification: target is not a string");
|
||||
if (error.IsObject()) {
|
||||
return Json::getString(error, "message");
|
||||
}
|
||||
|
||||
std::string new_target_str = new_target.GetString();
|
||||
new_target_str.resize(16, '0');
|
||||
|
||||
return std::stoull(new_target_str, nullptr, 16);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -321,7 +294,7 @@ void xmrig::EthStratumClient::authorize()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::EthStratumClient::onAuthorizeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed)
|
||||
void xmrig::EthStratumClient::onAuthorizeResponse(const rapidjson::Value &result, bool success, uint64_t)
|
||||
{
|
||||
try {
|
||||
if (!success) {
|
||||
|
@ -356,31 +329,27 @@ void xmrig::EthStratumClient::onAuthorizeResponse(const rapidjson::Value &result
|
|||
}
|
||||
|
||||
|
||||
void xmrig::EthStratumClient::onSubscribeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed)
|
||||
void xmrig::EthStratumClient::onSubscribeResponse(const rapidjson::Value &result, bool success, uint64_t)
|
||||
{
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
m_extraNonce = extraNonce(result);
|
||||
} catch (const std::exception &ex) {
|
||||
LOG_ERR("%s " RED("%s"), tag(), ex.what());
|
||||
}
|
||||
}
|
||||
if (!result.IsArray()) {
|
||||
throw std::runtime_error("invalid mining.subscribe response: result is not an array");
|
||||
}
|
||||
|
||||
if (result.GetArray().Size() <= 1) {
|
||||
throw std::runtime_error("invalid mining.subscribe response: result array is too short");
|
||||
}
|
||||
|
||||
void xmrig::EthStratumClient::setTarget(const rapidjson::Value ¶ms)
|
||||
{
|
||||
try {
|
||||
m_target = target(params);
|
||||
setExtraNonce(result.GetArray()[1]);
|
||||
} catch (const std::exception &ex) {
|
||||
LOG_ERR("%s " RED("%s"), tag(), ex.what());
|
||||
|
||||
return;
|
||||
m_extraNonce = { 0, {} };
|
||||
}
|
||||
|
||||
LOG_DEBUG("[%s] target set to %016" PRIX64, url(), m_target);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,20 +23,19 @@
|
|||
#include "base/net/stratum/Client.h"
|
||||
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IClientListener;
|
||||
|
||||
|
||||
class EthStratumClient : public Client
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(EthStratumClient)
|
||||
|
||||
EthStratumClient(int id, const char *agent, IClientListener *listener);
|
||||
|
||||
protected:
|
||||
~EthStratumClient() override = default;
|
||||
|
||||
protected:
|
||||
int64_t submit(const JobResult &result) override;
|
||||
|
@ -46,19 +45,17 @@ protected:
|
|||
bool handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error) override;
|
||||
void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error) override;
|
||||
|
||||
void setExtraNonce(const rapidjson::Value &nonce);
|
||||
|
||||
private:
|
||||
const char *errorMessage(const rapidjson::Value &error) const;
|
||||
uint64_t extraNonce(const rapidjson::Value &result) const;
|
||||
uint64_t target(const rapidjson::Value ¶ms) const;
|
||||
void authorize();
|
||||
void onAuthorizeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);
|
||||
void onSubscribeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);
|
||||
void setTarget(const rapidjson::Value ¶ms);
|
||||
void subscribe();
|
||||
|
||||
bool m_authorized = false;
|
||||
uint64_t m_target = 0;
|
||||
uint64_t m_extraNonce = 0;
|
||||
bool m_authorized = false;
|
||||
std::pair<uint64_t, String> m_extraNonce{};
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -71,17 +71,18 @@ public:
|
|||
inline const String &extraNonce() const { return m_extraNonce; }
|
||||
inline const String &id() const { return m_id; }
|
||||
inline const String &poolWallet() const { return m_poolWallet; }
|
||||
inline int32_t nonce_offset() const { return (algorithm().family() == Algorithm::KAWPOW) ? 32 : 39; }
|
||||
inline size_t nonce_size() const { return (algorithm().family() == Algorithm::KAWPOW) ? 8 : 4; }
|
||||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + nonce_offset()); }
|
||||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + nonceOffset()); }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline uint8_t *blob() { return m_blob; }
|
||||
inline int32_t nonceOffset() const { return (algorithm().family() == Algorithm::KAWPOW) ? 32 : 39; }
|
||||
inline size_t nonceSize() const { return (algorithm().family() == Algorithm::KAWPOW) ? 8 : 4; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + nonce_offset()); }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + nonceOffset()); }
|
||||
inline uint32_t backend() const { return m_backend; }
|
||||
inline uint64_t diff() const { return m_diff; }
|
||||
inline uint64_t height() const { return m_height; }
|
||||
inline uint64_t target() const { return m_target; }
|
||||
inline uint8_t *blob() { return m_blob; }
|
||||
inline uint8_t fixedByte() const { return *(m_blob + 42); }
|
||||
inline uint8_t index() const { return m_index; }
|
||||
inline void reset() { m_size = 0; m_diff = 0; }
|
||||
inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; }
|
||||
|
|
|
@ -118,12 +118,12 @@ void xmrig::NetworkState::onActive(IStrategy *strategy, IClient *client)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::NetworkState::onJob(IStrategy *strategy, IClient *client, const Job &job)
|
||||
void xmrig::NetworkState::onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value ¶ms)
|
||||
{
|
||||
m_algorithm = job.algorithm();
|
||||
m_diff = job.diff();
|
||||
|
||||
StrategyProxy::onJob(strategy, client, job);
|
||||
StrategyProxy::onJob(strategy, client, job, params);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
protected:
|
||||
void onActive(IStrategy *strategy, IClient *client) override;
|
||||
void onJob(IStrategy *strategy, IClient *client, const Job &job) override;
|
||||
void onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value ¶ms) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;
|
||||
|
||||
|
|
|
@ -37,7 +37,11 @@
|
|||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/EthStratumClient.h"
|
||||
|
||||
#ifdef XMRIG_ALGO_KAWPOW
|
||||
# include "base/net/stratum/AutoClient.h"
|
||||
# include "base/net/stratum/EthStratumClient.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
|
@ -81,6 +85,20 @@ xmrig::Pool::Pool(const char *url) :
|
|||
}
|
||||
|
||||
|
||||
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls, Mode mode) :
|
||||
m_keepAlive(keepAlive),
|
||||
m_mode(mode),
|
||||
m_flags(1 << FLAG_ENABLED),
|
||||
m_password(password),
|
||||
m_user(user),
|
||||
m_pollInterval(kDefaultPollInterval),
|
||||
m_url(host, port, tls)
|
||||
{
|
||||
m_flags.set(FLAG_NICEHASH, nicehash);
|
||||
m_flags.set(FLAG_TLS, tls);
|
||||
}
|
||||
|
||||
|
||||
xmrig::Pool::Pool(const rapidjson::Value &object) :
|
||||
m_flags(1 << FLAG_ENABLED),
|
||||
m_pollInterval(kDefaultPollInterval),
|
||||
|
@ -121,19 +139,6 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
|
|||
}
|
||||
|
||||
|
||||
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) :
|
||||
m_keepAlive(keepAlive),
|
||||
m_flags(1 << FLAG_ENABLED),
|
||||
m_password(password),
|
||||
m_user(user),
|
||||
m_pollInterval(kDefaultPollInterval),
|
||||
m_url(host, port, tls)
|
||||
{
|
||||
m_flags.set(FLAG_NICEHASH, nicehash);
|
||||
m_flags.set(FLAG_TLS, tls);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Pool::isEnabled() const
|
||||
{
|
||||
# ifndef XMRIG_FEATURE_TLS
|
||||
|
@ -186,10 +191,13 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
|
|||
IClient *client = nullptr;
|
||||
|
||||
if (m_mode == MODE_POOL) {
|
||||
# ifdef XMRIG_ALGO_KAWPOW
|
||||
if ((m_algorithm.family() == Algorithm::KAWPOW) || (m_coin == Coin::RAVEN)) {
|
||||
client = new EthStratumClient(id, Platform::userAgent(), listener);
|
||||
}
|
||||
else {
|
||||
else
|
||||
# endif
|
||||
{
|
||||
client = new Client(id, Platform::userAgent(), listener);
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +209,11 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
|
|||
client = new SelfSelectClient(id, Platform::userAgent(), listener);
|
||||
}
|
||||
# endif
|
||||
# ifdef XMRIG_ALGO_KAWPOW
|
||||
else if (m_mode == MODE_AUTO_ETH) {
|
||||
client = new AutoClient(id, Platform::userAgent(), listener);
|
||||
}
|
||||
# endif
|
||||
|
||||
assert(client != nullptr);
|
||||
|
||||
|
|
|
@ -49,7 +49,8 @@ public:
|
|||
enum Mode {
|
||||
MODE_POOL,
|
||||
MODE_DAEMON,
|
||||
MODE_SELF_SELECT
|
||||
MODE_SELF_SELECT,
|
||||
MODE_AUTO_ETH
|
||||
};
|
||||
|
||||
static const String kDefaultPassword;
|
||||
|
@ -76,16 +77,9 @@ public:
|
|||
constexpr static uint64_t kDefaultPollInterval = 1000;
|
||||
|
||||
Pool() = default;
|
||||
Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls, Mode mode);
|
||||
Pool(const char *url);
|
||||
Pool(const rapidjson::Value &object);
|
||||
Pool(const char *host,
|
||||
uint16_t port,
|
||||
const char *user = nullptr,
|
||||
const char *password = nullptr,
|
||||
int keepAlive = 0,
|
||||
bool nicehash = false,
|
||||
bool tls = false
|
||||
);
|
||||
|
||||
inline bool isNicehash() const { return m_flags.test(FLAG_NICEHASH); }
|
||||
inline bool isTLS() const { return m_flags.test(FLAG_TLS) || m_url.isTLS(); }
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
|
||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
|
@ -96,7 +97,7 @@ void xmrig::FailoverStrategy::resume()
|
|||
return;
|
||||
}
|
||||
|
||||
m_listener->onJob(this, active(), active()->job());
|
||||
m_listener->onJob(this, active(), active()->job(), rapidjson::Value(rapidjson::kNullType));
|
||||
}
|
||||
|
||||
|
||||
|
@ -164,10 +165,10 @@ void xmrig::FailoverStrategy::onLogin(IClient *client, rapidjson::Document &doc,
|
|||
}
|
||||
|
||||
|
||||
void xmrig::FailoverStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value &)
|
||||
void xmrig::FailoverStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms)
|
||||
{
|
||||
if (m_active == client->id()) {
|
||||
m_listener->onJob(this, client, job);
|
||||
m_listener->onJob(this, client, job, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
|
||||
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
|
@ -65,7 +66,7 @@ void xmrig::SinglePoolStrategy::resume()
|
|||
return;
|
||||
}
|
||||
|
||||
m_listener->onJob(this, m_client, m_client->job());
|
||||
m_listener->onJob(this, m_client, m_client->job(), rapidjson::Value(rapidjson::kNullType));
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,9 +105,9 @@ void xmrig::SinglePoolStrategy::onClose(IClient *, int)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::SinglePoolStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value &)
|
||||
void xmrig::SinglePoolStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms)
|
||||
{
|
||||
m_listener->onJob(this, client, job);
|
||||
m_listener->onJob(this, client, job, params);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ protected:
|
|||
m_listener->onActive(strategy, client);
|
||||
}
|
||||
|
||||
inline void onJob(IStrategy *strategy, IClient *client, const Job &job) override
|
||||
inline void onJob(IStrategy *strategy, IClient *client, const Job &job, const rapidjson::Value ¶ms) override
|
||||
{
|
||||
m_listener->onJob(strategy, client, job);
|
||||
m_listener->onJob(strategy, client, job, params);
|
||||
}
|
||||
|
||||
inline void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
"cn/0": false,
|
||||
"cn-lite/0": false
|
||||
},
|
||||
"donate-level": 5,
|
||||
"donate-level": 1,
|
||||
"donate-over-proxy": 1,
|
||||
"log-file": null,
|
||||
"pools": [
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
* XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
|
||||
* BTC: 1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT
|
||||
*/
|
||||
constexpr const int kDefaultDonateLevel = 5;
|
||||
constexpr const int kDefaultDonateLevel = 1;
|
||||
constexpr const int kMinimumDonateLevel = 1;
|
||||
|
||||
|
||||
|
|
|
@ -132,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;
|
||||
|
|
|
@ -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 ¶ms) override;
|
||||
void onJobResult(const JobResult &result) override;
|
||||
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
|
|
|
@ -69,10 +69,16 @@ xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener
|
|||
keccak(reinterpret_cast<const uint8_t *>(user.data()), user.size(), hash);
|
||||
Buffer::toHex(hash, 32, m_userId);
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
m_pools.emplace_back(kDonateHostTls, 443, m_userId, 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, 3333, m_userId, nullptr, 0, true);
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
m_pools.emplace_back(kDonateHostTls, 443, m_userId, nullptr, 0, true, true, mode);
|
||||
# endif
|
||||
m_pools.emplace_back(kDonateHost, 3333, m_userId, nullptr, 0, true, false, mode);
|
||||
|
||||
if (m_pools.size() > 1) {
|
||||
m_strategy = new FailoverStrategy(m_pools, 10, 2, this, true);
|
||||
|
@ -252,7 +258,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());
|
||||
|
||||
|
@ -291,10 +297,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 ¶ms)
|
||||
{
|
||||
if (isActive()) {
|
||||
m_listener->onJob(this, client, job);
|
||||
m_listener->onJob(this, client, job, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ¶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 {}
|
||||
|
@ -95,7 +95,7 @@ private:
|
|||
IClient *createProxy();
|
||||
void idle(double min, double max);
|
||||
void setAlgorithms(rapidjson::Document &doc, rapidjson::Value ¶ms);
|
||||
void setJob(IClient *client, const Job &job);
|
||||
void setJob(IClient *client, const Job &job, const rapidjson::Value ¶ms);
|
||||
void setResult(IClient *client, const SubmitResult &result, const char *error);
|
||||
void setState(State state);
|
||||
|
||||
|
|
Loading…
Reference in a new issue