Add dual SHA256D block check for pool mining mode

Pool sends block_target (full 256-bit network target) with each job.
Miner checks SHA256D(header + RandomX solution) for every hash against
the block target, enabling block detection at full hashrate instead of
only on submitted shares.
This commit is contained in:
2026-03-09 23:52:34 -05:00
parent 95d3ff2c4a
commit 7d22bc2bb5
4 changed files with 95 additions and 0 deletions

View File

@@ -115,6 +115,40 @@ bool xmrig::Job::setSeedHash(const char *hash)
}
bool xmrig::Job::setBlockTarget(const char *target)
{
if (!target) {
m_hasBlockTarget = false;
return false;
}
const size_t len = strlen(target);
if (len != 64) { // 32 bytes = 64 hex chars
m_hasBlockTarget = false;
return false;
}
// Parse 64-char hex string (display order) into uint256-compatible internal byte order.
// Display "00072f0f...000" → internal: data[31]=0x00, data[30]=0x07, data[29]=0x2f, ...
// This matches how Bitcoin/Zcash uint256 stores values (LSB at data[0], MSB at data[31]).
// Raw SHA256D output from OpenSSL also goes into uint256.data[] without reversal,
// so both hash and target are in the same internal byte order for comparison.
uint8_t tmp[32];
if (!Cvt::fromHex(tmp, sizeof(tmp), target, len)) {
m_hasBlockTarget = false;
return false;
}
// Reverse display order to internal byte order (LSB-first / little-endian uint256)
for (int i = 0; i < 32; ++i) {
m_blockTarget[i] = tmp[31 - i];
}
m_hasBlockTarget = true;
return true;
}
bool xmrig::Job::setTarget(const char *target)
{
static auto parse = [](const char *target, size_t size, const Algorithm &algorithm) -> uint64_t {
@@ -297,6 +331,9 @@ void xmrig::Job::copy(const Job &other)
# endif
m_hasMinerSignature = other.m_hasMinerSignature;
m_hasBlockTarget = other.m_hasBlockTarget;
m_isSoloMining = other.m_isSoloMining;
memcpy(m_blockTarget, other.m_blockTarget, sizeof(m_blockTarget));
}
@@ -353,6 +390,9 @@ void xmrig::Job::move(Job &&other)
# endif
m_hasMinerSignature = other.m_hasMinerSignature;
m_hasBlockTarget = other.m_hasBlockTarget;
m_isSoloMining = other.m_isSoloMining;
memcpy(m_blockTarget, other.m_blockTarget, sizeof(m_blockTarget));
}