Simplify the set_target function, allowing it to work properly for fractional diffs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/cgminer.c b/cgminer.c
index f6f5cce..c93479f 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -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);