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 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2024 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
@ -24,11 +24,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <cstring>
#include "base/net/stratum/Job.h"
#include "base/tools/Alignment.h"
#include "base/tools/Buffer.h"
@ -112,26 +110,36 @@ bool xmrig::Job::setSeedHash(const char *hash)
bool xmrig::Job::setTarget(const char *target)
{
static auto parse = [](const char *target, const Algorithm &algorithm) -> uint64_t {
if (!target) {
return false;
return 0;
}
if (algorithm == Algorithm::RX_YADA) {
return strtoull(target, nullptr, 16);
}
const auto raw = Cvt::fromHex(target, strlen(target));
const size_t size = raw.size();
if (algorithm() == Algorithm::RX_YADA) {
m_target = strtoull(target, nullptr, 16);
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;
}
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 0;
};
if ((m_target = parse(target, algorithm())) == 0) {
return false;
}
}
m_diff = toDiff(m_target);
# ifdef XMRIG_PROXY_PROJECT
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)));
# endif
m_diff = toDiff(m_target);
return true;
}
@ -177,12 +184,20 @@ void xmrig::Job::setSigKey(const char *sig_key)
int32_t xmrig::Job::nonceOffset() const
{
auto f = algorithm().family();
if (f == Algorithm::KAWPOW) return 32;
if (f == Algorithm::GHOSTRIDER) return 76;
switch (algorithm().family()) {
case Algorithm::KAWPOW:
return 32;
auto id = algorithm().id();
if (id == Algorithm::RX_YADA) return 147;
case Algorithm::GHOSTRIDER:
return 76;
default:
break;
}
if (algorithm() == Algorithm::RX_YADA) {
return 147;
}
return 39;
}

View File

@ -7,8 +7,8 @@
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2024 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
@ -27,11 +27,9 @@
#ifndef XMRIG_JOB_H
#define XMRIG_JOB_H
#include <cstddef>
#include <cstdint>
#include "base/crypto/Algorithm.h"
#include "base/tools/Buffer.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 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; }
# ifdef XMRIG_FEATURE_BENCHMARK