Implemented static benchmark verification (--bench --seed --hash)
This commit is contained in:
parent
027a6f8ae2
commit
36c1cb23e0
14 changed files with 220 additions and 107 deletions
|
@ -34,6 +34,7 @@
|
|||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/net/http/Fetch.h"
|
||||
#include "base/net/http/HttpData.h"
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Timer.h"
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#define XMRIG_DAEMONCLIENT_H
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
|
|
@ -174,6 +174,12 @@ void xmrig::Job::copy(const Job &other)
|
|||
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
|
||||
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
m_benchSize = other.m_benchSize;
|
||||
m_benchHash = other.m_benchHash;
|
||||
m_benchToken = other.m_benchToken;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -205,4 +211,10 @@ void xmrig::Job::move(Job &&other)
|
|||
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
|
||||
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
m_benchSize = other.m_benchSize;
|
||||
m_benchHash = other.m_benchHash;
|
||||
m_benchToken = std::move(other.m_benchToken);
|
||||
# endif
|
||||
}
|
||||
|
|
|
@ -98,18 +98,27 @@ public:
|
|||
inline void setPoolWallet(const String &poolWallet) { m_poolWallet = poolWallet; }
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
inline char *rawBlob() { return m_rawBlob; }
|
||||
inline const char *rawBlob() const { return m_rawBlob; }
|
||||
inline const char *rawTarget() const { return m_rawTarget; }
|
||||
inline const String &rawSeedHash() const { return m_rawSeedHash; }
|
||||
inline char *rawBlob() { return m_rawBlob; }
|
||||
inline const char *rawBlob() const { return m_rawBlob; }
|
||||
inline const char *rawTarget() const { return m_rawTarget; }
|
||||
inline const String &rawSeedHash() const { return m_rawSeedHash; }
|
||||
# endif
|
||||
|
||||
static inline uint64_t toDiff(uint64_t target) { return target ? (0xFFFFFFFFFFFFFFFFULL / target) : 0; }
|
||||
static inline uint64_t toDiff(uint64_t target) { return target ? (0xFFFFFFFFFFFFFFFFULL / target) : 0; }
|
||||
|
||||
inline bool operator!=(const Job &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Job &other) const { return isEqual(other); }
|
||||
inline Job &operator=(const Job &other) { copy(other); return *this; }
|
||||
inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; }
|
||||
inline bool operator!=(const Job &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Job &other) const { return isEqual(other); }
|
||||
inline Job &operator=(const Job &other) { copy(other); return *this; }
|
||||
inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
inline const String &benchToken() const { return m_benchToken; }
|
||||
inline uint32_t benchSize() const { return m_benchSize; }
|
||||
inline uint64_t benchHash() const { return m_benchHash; }
|
||||
inline void setBenchHash(uint64_t benchHash) { m_benchHash = benchHash; }
|
||||
inline void setBenchSize(uint32_t size) { m_benchSize = size; }
|
||||
inline void setBenchToken(const String &token) { m_benchToken = token; }
|
||||
# endif
|
||||
|
||||
private:
|
||||
void copy(const Job &other);
|
||||
|
@ -135,6 +144,12 @@ private:
|
|||
char m_rawTarget[24]{};
|
||||
String m_rawSeedHash;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
String m_benchToken;
|
||||
uint32_t m_benchSize = 0;
|
||||
uint64_t m_benchHash = 0;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -19,35 +19,58 @@
|
|||
#include "base/net/stratum/benchmark/BenchClient.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "base/net/stratum/benchmark/BenchConfig.h"
|
||||
|
||||
|
||||
xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &benchmark, IClientListener* listener) :
|
||||
m_listener(listener)
|
||||
m_listener(listener),
|
||||
m_benchmark(benchmark)
|
||||
{
|
||||
m_job.setAlgorithm(benchmark->algorithm());
|
||||
m_httpListener = std::make_shared<HttpListener>(this);
|
||||
|
||||
std::vector<char> blob(112 * 2 + 1, '0');
|
||||
|
||||
blob.back() = '\0';
|
||||
|
||||
m_job.setBlob(blob.data());
|
||||
m_job.setAlgorithm(m_benchmark->algorithm());
|
||||
m_job.setDiff(std::numeric_limits<uint64_t>::max());
|
||||
m_job.setHeight(1);
|
||||
m_job.setBenchSize(m_benchmark->size());
|
||||
m_job.setBenchHash(m_benchmark->hash());
|
||||
|
||||
if (m_benchmark->isSubmit()) {
|
||||
m_mode = ONLINE_BENCH;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_benchmark->id().isEmpty()) {
|
||||
m_job.setId(m_benchmark->id());
|
||||
m_mode = ONLINE_VERIFY;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_job.setId("00000000");
|
||||
|
||||
if (m_job.benchHash() && m_job.setSeedHash(m_benchmark->seed())) {
|
||||
m_mode = STATIC_VERIFY;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
blob[Job::kMaxSeedSize * 2] = '\0';
|
||||
m_job.setSeedHash(blob.data());
|
||||
|
||||
m_job.setDiff(uint64_t(-1));
|
||||
m_job.setHeight(1);
|
||||
|
||||
m_job.setId("00000000");
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchClient::connect()
|
||||
{
|
||||
m_listener->onLoginSuccess(this);
|
||||
|
||||
rapidjson::Value params;
|
||||
m_listener->onJobReceived(this, m_job, params);
|
||||
if (m_mode == STATIC_BENCH || m_mode == STATIC_VERIFY) {
|
||||
m_listener->onLoginSuccess(this);
|
||||
m_listener->onJobReceived(this, m_job, rapidjson::Value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,3 +78,8 @@ void xmrig::BenchClient::setPool(const Pool &pool)
|
|||
{
|
||||
m_pool = pool;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchClient::onHttpData(const HttpData &data)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -21,12 +21,13 @@
|
|||
|
||||
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class BenchClient : public IClient
|
||||
class BenchClient : public IClient, public IHttpListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(BenchClient)
|
||||
|
@ -63,12 +64,24 @@ public:
|
|||
void connect() override;
|
||||
void setPool(const Pool &pool) override;
|
||||
|
||||
protected:
|
||||
void onHttpData(const HttpData &data) override;
|
||||
|
||||
private:
|
||||
enum Mode : uint32_t {
|
||||
STATIC_BENCH,
|
||||
ONLINE_BENCH,
|
||||
STATIC_VERIFY,
|
||||
ONLINE_VERIFY
|
||||
};
|
||||
|
||||
IClientListener* m_listener;
|
||||
Job m_job;
|
||||
Pool m_pool;
|
||||
std::shared_ptr<BenchConfig> m_benchmark;
|
||||
std::shared_ptr<IHttpListener> m_httpListener;
|
||||
String m_ip;
|
||||
Mode m_mode = STATIC_BENCH;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,11 @@ xmrig::BenchConfig::BenchConfig(uint32_t size, const String &id, const rapidjson
|
|||
if (!m_algorithm.isValid() || m_algorithm.family() != Algorithm::RANDOM_X) {
|
||||
m_algorithm = Algorithm::RX_0;
|
||||
}
|
||||
|
||||
const char *hash = Json::getString(object, kHash);
|
||||
if (hash) {
|
||||
m_hash = strtoull(hash, nullptr, 16);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue