mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 20:19:23 +00:00
Refactoring
This commit is contained in:
parent
be7ff62c48
commit
4643742d13
9 changed files with 39 additions and 64 deletions
|
@ -162,7 +162,7 @@ int64_t xmrig::Client::submit(const JobResult &result)
|
|||
Buffer::toHex(reinterpret_cast<const char*>(&result.nonce), 4, nonce);
|
||||
nonce[8] = '\0';
|
||||
|
||||
Buffer::toHex(result.result, 32, data);
|
||||
Buffer::toHex(result.result(), 32, data);
|
||||
data[64] = '\0';
|
||||
# endif
|
||||
|
||||
|
@ -313,7 +313,7 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
return false;
|
||||
}
|
||||
|
||||
Job job(m_id, has<EXT_NICEHASH>(), m_pool.algorithm(), m_rpcId);
|
||||
Job job(has<EXT_NICEHASH>(), m_pool.algorithm(), m_rpcId);
|
||||
|
||||
if (!job.setId(params["job_id"].GetString())) {
|
||||
*code = 3;
|
||||
|
|
|
@ -212,7 +212,7 @@ bool xmrig::DaemonClient::isOutdated(uint64_t height, const char *hash) const
|
|||
|
||||
bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||
{
|
||||
Job job(m_id, false, m_pool.algorithm(), String());
|
||||
Job job(false, m_pool.algorithm(), String());
|
||||
|
||||
String blocktemplate = Json::getString(params, kBlocktemplateBlob);
|
||||
if (blocktemplate.isNull() || !job.setBlob(Json::getString(params, "blockhashing_blob"))) {
|
||||
|
|
|
@ -34,27 +34,16 @@
|
|||
|
||||
|
||||
xmrig::Job::Job() :
|
||||
m_nicehash(false),
|
||||
m_poolId(-2),
|
||||
m_size(0),
|
||||
m_diff(0),
|
||||
m_height(0),
|
||||
m_target(0),
|
||||
m_blob(),
|
||||
m_seedHash()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId) :
|
||||
xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientId) :
|
||||
m_algorithm(algorithm),
|
||||
m_nicehash(nicehash),
|
||||
m_poolId(poolId),
|
||||
m_size(0),
|
||||
m_clientId(clientId),
|
||||
m_diff(0),
|
||||
m_height(0),
|
||||
m_target(0),
|
||||
m_blob(),
|
||||
m_seedHash()
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
static constexpr const size_t kMaxBlobSize = 128;
|
||||
|
||||
Job();
|
||||
Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId);
|
||||
Job(bool nicehash, const Algorithm &algorithm, const String &clientId);
|
||||
~Job();
|
||||
|
||||
bool isEqual(const Job &other) const;
|
||||
|
@ -65,18 +65,18 @@ public:
|
|||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline const uint8_t *seedHash() const { return m_seedHash; }
|
||||
inline int poolId() const { return m_poolId; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
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 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 char *algo) { m_algorithm = algo; }
|
||||
inline void setClientId(const String &id) { m_clientId = id; }
|
||||
inline void setHeight(uint64_t height) { m_height = height; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
inline void setIndex(uint8_t index) { m_index = index; }
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
inline char *rawBlob() { return m_rawBlob; }
|
||||
|
@ -93,15 +93,15 @@ public:
|
|||
|
||||
private:
|
||||
Algorithm m_algorithm;
|
||||
bool m_nicehash;
|
||||
int m_poolId;
|
||||
size_t m_size;
|
||||
bool m_nicehash = false;
|
||||
size_t m_size = 0;
|
||||
String m_clientId;
|
||||
String m_id;
|
||||
uint64_t m_diff;
|
||||
uint64_t m_height;
|
||||
uint64_t m_target;
|
||||
uint64_t m_diff = 0;
|
||||
uint64_t m_height = 0;
|
||||
uint64_t m_target = 0;
|
||||
uint8_t m_blob[kMaxBlobSize];
|
||||
uint8_t m_index = 0;
|
||||
uint8_t m_seedHash[32];
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
if (index() == 1 && job.poolId() >= 0 && job == m_jobs[0]) {
|
||||
if (index() == 1 && job.index() == 0 && job == m_jobs[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
private:
|
||||
inline void save(const Job &job, uint32_t reserveCount)
|
||||
{
|
||||
m_index = job.poolId() == -1 ? 1 : 0;
|
||||
m_index = job.index();
|
||||
const size_t size = job.size();
|
||||
m_jobs[index()] = job;
|
||||
m_rounds[index()] = 0;
|
||||
|
@ -128,7 +128,7 @@ inline void xmrig::WorkerJob<1>::nextRound(uint32_t reserveCount)
|
|||
template<>
|
||||
inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount)
|
||||
{
|
||||
m_index = job.poolId() == -1 ? 1 : 0;
|
||||
m_index = job.index();
|
||||
m_jobs[index()] = job;
|
||||
m_rounds[index()] = 0;
|
||||
|
||||
|
|
|
@ -41,43 +41,31 @@ namespace xmrig {
|
|||
class JobResult
|
||||
{
|
||||
public:
|
||||
inline JobResult() : poolId(0), nonce(0), diff(0) {}
|
||||
inline JobResult(int poolId, const String &jobId, const String &clientId, uint32_t nonce, const uint8_t *result, uint64_t diff, const Algorithm &algorithm) :
|
||||
algorithm(algorithm),
|
||||
poolId(poolId),
|
||||
clientId(clientId),
|
||||
jobId(jobId),
|
||||
inline JobResult() {}
|
||||
|
||||
inline JobResult(const Job &job, uint32_t nonce, const uint8_t *result) :
|
||||
algorithm(job.algorithm()),
|
||||
clientId(job.clientId()),
|
||||
jobId(job.id()),
|
||||
nonce(nonce),
|
||||
diff(diff)
|
||||
diff(job.diff()),
|
||||
index(job.index())
|
||||
{
|
||||
memcpy(this->result, result, sizeof(this->result));
|
||||
memcpy(m_result, result, sizeof(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 JobResult(const Job &job) : poolId(0), nonce(0), diff(0)
|
||||
{
|
||||
jobId = job.id();
|
||||
clientId = job.clientId();
|
||||
poolId = job.poolId();
|
||||
diff = job.diff();
|
||||
nonce = *job.nonce();
|
||||
algorithm = job.algorithm();
|
||||
}
|
||||
const Algorithm algorithm;
|
||||
const String clientId;
|
||||
const String jobId;
|
||||
const uint32_t nonce = 0;
|
||||
const uint64_t diff = 0;
|
||||
const uint8_t index = 0;
|
||||
|
||||
|
||||
inline uint64_t actualDiff() const
|
||||
{
|
||||
return Job::toDiff(reinterpret_cast<const uint64_t*>(result)[3]);
|
||||
}
|
||||
|
||||
|
||||
Algorithm algorithm;
|
||||
int poolId;
|
||||
String clientId;
|
||||
String jobId;
|
||||
uint32_t nonce;
|
||||
uint64_t diff;
|
||||
uint8_t result[32];
|
||||
private:
|
||||
uint8_t m_result[32];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ void xmrig::Network::onJob(IStrategy *strategy, IClient *client, const Job &job)
|
|||
|
||||
void xmrig::Network::onJobResult(const JobResult &result)
|
||||
{
|
||||
if (result.poolId == -1 && m_donate) {
|
||||
if (result.index == 1 && m_donate) {
|
||||
m_donate->submit(result);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ void xmrig::MultiWorker<N>::start()
|
|||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < job.target()) {
|
||||
JobResults::submit(JobResult(job.poolId(), job.id(), job.clientId(), *m_job.nonce(i), m_hash + (i * 32), job.diff(), job.algorithm()));
|
||||
JobResults::submit(JobResult(job, *m_job.nonce(i), m_hash + (i * 32)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,11 +150,9 @@ void Workers::setEnabled(bool enabled)
|
|||
void Workers::setJob(const xmrig::Job &job, bool donate)
|
||||
{
|
||||
uv_rwlock_wrlock(&m_rwlock);
|
||||
m_job = job;
|
||||
|
||||
if (donate) {
|
||||
m_job.setPoolId(-1);
|
||||
}
|
||||
m_job = job;
|
||||
m_job.setIndex(donate ? 1 : 0);
|
||||
|
||||
xmrig::Nonce::reset(donate ? 1 : 0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue