Generate merkle root hash in gen_stratum_work.
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 53 54 55 56 57 58
diff --git a/cgminer.c b/cgminer.c
index 56d7dca..67658a1 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4265,12 +4265,24 @@ static struct work *clone_work(struct work *work)
return work;
}
+static void gen_hash(unsigned char *data, unsigned char *hash, int len)
+{
+ unsigned char hash1[32];
+
+ sha2(data, len, hash1, false);
+ sha2(hash1, 32, hash, false);
+}
+
static void gen_stratum_work(struct pool *pool, struct work *work)
{
+ unsigned char merkle_root[32], merkle_sha[64], *merkle_hash;
char *coinbase, *nonce2;
- int len;
+ uint32_t *data32, *swap32;
+ int len, i;
mutex_lock(&pool->pool_lock);
+
+ /* Generate coinbase */
len = strlen(pool->swork.coinbase1) +
strlen(pool->nonce1) +
pool->n2size +
@@ -4283,8 +4295,27 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
strcat(coinbase, nonce2);
free(nonce2);
strcat(coinbase, pool->swork.coinbase2);
+
+ /* Generate merkle root */
+ gen_hash((unsigned char *)coinbase, merkle_root, len);
+ memcpy(merkle_sha, merkle_root, 32);
+ for (i = 0; i < pool->swork.merkles; i++) {
+ memcpy(merkle_sha + 32, pool->swork.merkle[i], 32);
+ gen_hash(merkle_sha, merkle_root, 64);
+ memcpy(merkle_sha, merkle_root, 32);
+ }
+ data32 = (uint32_t *)merkle_sha;
+ swap32 = (uint32_t *)merkle_root;
+ for (i = 0; i < 32 / 4; i++)
+ swap32[i] = swab32(data32[i]);
+ merkle_hash = (unsigned char *)bin2hex((const unsigned char *)merkle_root, 32);
+
mutex_unlock(&pool->pool_lock);
+
applog(LOG_DEBUG, "Generated stratum coinbase %s", coinbase);
+ applog(LOG_DEBUG, "Generated stratum merkle %s", merkle_hash);
+
+ free(merkle_hash);
}
static void get_work(struct work *work, struct thr_info *thr, const int thr_id)