1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-22 12:34:27 +00:00

Simplify the set_target function, allowing it to work properly for fractional diffs.

This commit is contained in:
Con Kolivas 2013-10-26 23:14:34 +11:00
parent 1e35965710
commit ca91994709

View File

@ -5922,38 +5922,23 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
sha256(hash1, 32, hash);
}
/* Diff 1 is a 256 bit unsigned integer of
* 0x00000000ffff0000000000000000000000000000000000000000000000000000
* so we use a big endian 64 bit unsigned integer centred on the 5th byte to
* cover a huge range of difficulty targets, though not all 256 bits' worth */
void set_target(unsigned char *dest_target, double diff)
{
unsigned char target[32];
unsigned char target[32], rtarget[32];
uint64_t *data64, h64;
double d64;
d64 = diffone;
if (opt_scrypt)
d64 = 0xFFFF00000000ull;
else
d64 = 0xFFFF0000ull;
d64 /= diff;
h64 = d64;
memset(target, 0, 32);
if (h64) {
unsigned char rtarget[32];
memset(rtarget, 0, 32);
if (opt_scrypt)
data64 = (uint64_t *)(rtarget + 2);
else
data64 = (uint64_t *)(rtarget + 4);
*data64 = htobe64(h64);
swab256(target, rtarget);
} else {
/* Support for the classic all FFs just-below-1 diff */
if (opt_scrypt)
memset(target, 0xff, 30);
else
memset(target, 0xff, 28);
}
memset(rtarget, 0xFF, 32);
data64 = (uint64_t *)rtarget;
*data64 = htobe64(h64);
swab256(target, rtarget);
if (opt_debug) {
char *htarget = bin2hex(target, 32);