From 636f4b14d7f07eba8550908225139f22b9d96eb7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 29 Sep 2012 11:38:52 +1000 Subject: [PATCH] Generate the work target in gen_stratum_work, setting default diff to 1 in case it is not yet set. --- cgminer.c | 17 +++++++++++++++-- util.c | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cgminer.c b/cgminer.c index 58e5177d..127bcc57 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4276,9 +4276,10 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len) static void gen_stratum_work(struct pool *pool, struct work *work) { unsigned char merkle_root[32], merkle_sha[64], *merkle_hash; - char header[256], hash1[128], *coinbase, *nonce2; + char header[256], hash1[128], *coinbase, *nonce2, *buf; uint32_t *data32, *swap32; - int len, i, diff; + uint64_t diff, diff64; + int len, i; mutex_lock(&pool->pool_lock); @@ -4328,12 +4329,24 @@ static void gen_stratum_work(struct pool *pool, struct work *work) free(merkle_hash); + /* Convert hex data to binary data for work */ if (!hex2bin(work->data, header, 128)) quit(1, "Failed to convert header to data in gen_stratum_work"); calc_midstate(work); sprintf(hash1, "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000"); if (!hex2bin(work->hash1, hash1, 64)) quit(1, "Failed to convert hash1 in gen_stratum_work"); + + /* Generate target as hex where 0x00000000FFFFFFFF is diff 1 */ + diff64 = 0x00000000FFFFFFFFULL * diff; + diff64 = ~htobe64(diff64); + sprintf((char *)work->target, "ffffffffffffffffffffffffffffffffffffffffffffffff"); + buf = bin2hex((const unsigned char *)&diff64, 8); + if (!buf) + quit(1, "Failed to convert diff64 to buf in gen_stratum_work"); + strcat((char *)work->target, buf); + free(buf); + applog(LOG_DEBUG, "Generated target %s", work->target); } static void get_work(struct work *work, struct thr_info *thr, const int thr_id) diff --git a/util.c b/util.c index 0c75bb57..a2e71519 100644 --- a/util.c +++ b/util.c @@ -1255,6 +1255,7 @@ out: if (ret) { pool->stratum_active = true; + pool->swork.diff = 1; if (opt_protocol) { applog(LOG_DEBUG, "Pool %d confirmed mining.notify with subscription %s extranonce1 %s extran2size %d", pool->pool_no, pool->subscription, pool->nonce1, pool->n2size);