|
|
@ -4477,12 +4477,13 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len) |
|
|
|
|
|
|
|
|
|
|
|
static void gen_stratum_work(struct pool *pool, struct work *work) |
|
|
|
static void gen_stratum_work(struct pool *pool, struct work *work) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char header[257], hash1[129], *nonce2, *buf; |
|
|
|
|
|
|
|
unsigned char *coinbase, merkle_root[33], merkle_sha[65], *merkle_hash; |
|
|
|
unsigned char *coinbase, merkle_root[33], merkle_sha[65], *merkle_hash; |
|
|
|
|
|
|
|
int len, cb1_len, n1_len, cb2_len, i, j; |
|
|
|
|
|
|
|
unsigned char rtarget[33], target[33]; |
|
|
|
|
|
|
|
char header[257], hash1[129], *nonce2; |
|
|
|
uint32_t *data32, *swap32; |
|
|
|
uint32_t *data32, *swap32; |
|
|
|
uint64_t diff, diff64; |
|
|
|
uint8_t *data8; |
|
|
|
char target[65]; |
|
|
|
int diff; |
|
|
|
int len, cb1_len, n1_len, cb2_len, i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
mutex_lock(&pool->pool_lock); |
|
|
|
|
|
|
|
|
|
|
@ -4551,18 +4552,25 @@ static void gen_stratum_work(struct pool *pool, struct work *work) |
|
|
|
if (unlikely(!hex2bin(work->hash1, hash1, 64))) |
|
|
|
if (unlikely(!hex2bin(work->hash1, hash1, 64))) |
|
|
|
quit(1, "Failed to convert hash1 in gen_stratum_work"); |
|
|
|
quit(1, "Failed to convert hash1 in gen_stratum_work"); |
|
|
|
|
|
|
|
|
|
|
|
/* Generate target as hex where 0x00000000FFFFFFFF is diff 1 */ |
|
|
|
/* Scale to any diff by setting number of bits according to diff */ |
|
|
|
diff64 = (1Ull << (31 + diff)) - 1; |
|
|
|
hex2bin(rtarget, "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32); |
|
|
|
diff64 = ~htobe64(diff64); |
|
|
|
data8 = (uint8_t *)(rtarget + 4); |
|
|
|
sprintf(target, "ffffffffffffffffffffffffffffffffffffffffffffffff"); |
|
|
|
for (i = 1, j = 0; i < diff; i++, j++) { |
|
|
|
buf = bin2hex((const unsigned char *)&diff64, 8); |
|
|
|
int byte = j / 8; |
|
|
|
if (unlikely(!buf)) |
|
|
|
int bit = j % 8; |
|
|
|
quit(1, "Failed to convert diff64 to buf in gen_stratum_work"); |
|
|
|
|
|
|
|
strcat(target, buf); |
|
|
|
data8[byte] &= ~(8 >> bit); |
|
|
|
free(buf); |
|
|
|
} |
|
|
|
applog(LOG_DEBUG, "Generated target %s", target); |
|
|
|
swab256(target, rtarget); |
|
|
|
if (unlikely(!hex2bin(work->target, target, 32))) |
|
|
|
if (opt_debug) { |
|
|
|
quit(1, "Failed to convert target to bin in gen_stratum_work"); |
|
|
|
char *htarget = bin2hex(target, 32); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (likely(htarget)) { |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "Generated target %s", htarget); |
|
|
|
|
|
|
|
free(htarget); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
memcpy(work->target, target, 256); |
|
|
|
|
|
|
|
|
|
|
|
work->pool = pool; |
|
|
|
work->pool = pool; |
|
|
|
work->stratum = true; |
|
|
|
work->stratum = true; |
|
|
|