More clean target parse.

This commit is contained in:
XMRig 2024-08-04 19:51:11 +07:00
parent 4570187459
commit 8da49f2650
No known key found for this signature in database
GPG key ID: 446A53638BE94409
2 changed files with 46 additions and 33 deletions

View file

@ -7,8 +7,8 @@
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2019 Howard Chu <https://github.com/hyc> * Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh> * Copyright 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2024 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -24,11 +24,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
#include "base/tools/Alignment.h" #include "base/tools/Alignment.h"
#include "base/tools/Buffer.h" #include "base/tools/Buffer.h"
@ -112,26 +110,36 @@ bool xmrig::Job::setSeedHash(const char *hash)
bool xmrig::Job::setTarget(const char *target) bool xmrig::Job::setTarget(const char *target)
{ {
if (!target) { static auto parse = [](const char *target, const Algorithm &algorithm) -> uint64_t {
if (!target) {
return 0;
}
if (algorithm == Algorithm::RX_YADA) {
return strtoull(target, nullptr, 16);
}
const auto raw = Cvt::fromHex(target, strlen(target));
switch (raw.size()) {
case 4:
return 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / uint64_t(*reinterpret_cast<const uint32_t *>(raw.data())));
case 8:
return *reinterpret_cast<const uint64_t *>(raw.data());
default:
break;
}
return 0;
};
if ((m_target = parse(target, algorithm())) == 0) {
return false; return false;
} }
const auto raw = Cvt::fromHex(target, strlen(target)); m_diff = toDiff(m_target);
const size_t size = raw.size();
if (algorithm() == Algorithm::RX_YADA) {
m_target = strtoull(target, nullptr, 16);
}
else {
if (size == 4) {
m_target = 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / uint64_t(*reinterpret_cast<const uint32_t *>(raw.data())));
}
else if (size == 8) {
m_target = *reinterpret_cast<const uint64_t *>(raw.data());
}
else {
return false;
}
}
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
assert(sizeof(m_rawTarget) > (size * 2)); assert(sizeof(m_rawTarget) > (size * 2));
@ -140,7 +148,6 @@ bool xmrig::Job::setTarget(const char *target)
memcpy(m_rawTarget, target, std::min(size * 2, sizeof(m_rawTarget))); memcpy(m_rawTarget, target, std::min(size * 2, sizeof(m_rawTarget)));
# endif # endif
m_diff = toDiff(m_target);
return true; return true;
} }
@ -177,14 +184,22 @@ void xmrig::Job::setSigKey(const char *sig_key)
int32_t xmrig::Job::nonceOffset() const int32_t xmrig::Job::nonceOffset() const
{ {
auto f = algorithm().family(); switch (algorithm().family()) {
if (f == Algorithm::KAWPOW) return 32; case Algorithm::KAWPOW:
if (f == Algorithm::GHOSTRIDER) return 76; return 32;
auto id = algorithm().id(); case Algorithm::GHOSTRIDER:
if (id == Algorithm::RX_YADA) return 147; return 76;
return 39; default:
break;
}
if (algorithm() == Algorithm::RX_YADA) {
return 147;
}
return 39;
} }
uint32_t xmrig::Job::getNumTransactions() const uint32_t xmrig::Job::getNumTransactions() const

View file

@ -7,8 +7,8 @@
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2019 Howard Chu <https://github.com/hyc> * Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh> * Copyright 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2024 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -27,11 +27,9 @@
#ifndef XMRIG_JOB_H #ifndef XMRIG_JOB_H
#define XMRIG_JOB_H #define XMRIG_JOB_H
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include "base/crypto/Algorithm.h" #include "base/crypto/Algorithm.h"
#include "base/tools/Buffer.h" #include "base/tools/Buffer.h"
#include "base/tools/String.h" #include "base/tools/String.h"
@ -111,7 +109,7 @@ public:
inline bool operator!=(const Job &other) const { return !isEqual(other); } inline bool operator!=(const Job &other) const { return !isEqual(other); }
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=(const Job &other) { if (this != &other) { copy(other); } return *this; }
inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; } inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; }
# ifdef XMRIG_FEATURE_BENCHMARK # ifdef XMRIG_FEATURE_BENCHMARK