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:
@@ -436,6 +436,53 @@ void xmrig::CpuWorker<N>::start()
|
||||
// Submit full 32-byte nonce + rx_hash as result
|
||||
JobResults::submit(JobResult(job, current_solo_nonces + i * 32, m_hash + (i * 32)));
|
||||
}
|
||||
} else if (job.algorithm() == Algorithm::RX_HUSH && !m_job.isSoloMining()) {
|
||||
// ── DRAGONX/HUSH pool mining: dual check ──
|
||||
//
|
||||
// DragonX uses dual PoW: the block hash is SHA256D(header + RandomX solution),
|
||||
// NOT the RandomX hash itself. We must check SHA256D for EVERY hash to detect
|
||||
// blocks, and also check the RandomX hash for share difficulty.
|
||||
//
|
||||
// Reconstruct the 140-byte header with the 4-byte nonce at offset 108.
|
||||
// In pool mode, bytes 112-139 of nNonce are zero (only 4-byte nonce used).
|
||||
uint8_t blob_for_header[140];
|
||||
memcpy(blob_for_header, m_job.blob(), 108); // header base
|
||||
memset(blob_for_header + 108, 0, 32); // clear 32-byte nonce field
|
||||
memcpy(blob_for_header + 108, ¤t_job_nonces[i], 4); // 4-byte nonce at offset 108
|
||||
|
||||
bool submitted = false;
|
||||
|
||||
// Check SHA256D for block detection if pool sent block_target
|
||||
if (job.hasBlockTarget()) {
|
||||
alignas(8) uint8_t pow_hash[32];
|
||||
dragonx_pow_hash(blob_for_header, m_hash + (i * 32), pow_hash);
|
||||
|
||||
// Compare pow_hash <= block_target (both in uint256 internal byte order)
|
||||
// byte[31] is MSB (most significant in arith terms), compare from there down
|
||||
bool isBlock = true;
|
||||
for (int b = 31; b >= 0; --b) {
|
||||
if (pow_hash[b] < job.blockTarget()[b]) {
|
||||
break; // pow_hash < target → is a block
|
||||
} else if (pow_hash[b] > job.blockTarget()[b]) {
|
||||
isBlock = false;
|
||||
break; // pow_hash > target → not a block
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlock) {
|
||||
// SHA256D meets block target — submit immediately
|
||||
JobResults::submit(job, current_job_nonces[i], m_hash + (i * 32), nullptr);
|
||||
submitted = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Also check RandomX hash for normal share difficulty (if not already submitted)
|
||||
if (!submitted) {
|
||||
const uint64_t value = *reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24);
|
||||
if (value < job.target()) {
|
||||
JobResults::submit(job, current_job_nonces[i], m_hash + (i * 32), nullptr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// ── Standard XMRig path (Monero, CryptoNight, etc.) ──
|
||||
const uint64_t value = *reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24);
|
||||
|
||||
Reference in New Issue
Block a user