Commit 159587baa8c50d37b2feff287a82d78815078446

Con Kolivas 2014-03-16T22:11:33

Share more fields between stratum and gbt

diff --git a/cgminer.c b/cgminer.c
index 351476c..d6e0ea7 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6770,7 +6770,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	/* Generate merkle root */
 	gen_hash(pool->coinbase, merkle_root, pool->coinbase_len);
 	memcpy(merkle_sha, merkle_root, 32);
-	for (i = 0; i < pool->swork.merkles; i++) {
+	for (i = 0; i < pool->merkles; i++) {
 		memcpy(merkle_sha + 32, pool->swork.merkle_bin[i], 32);
 		gen_hash(merkle_sha, merkle_root, 64);
 		memcpy(merkle_sha, merkle_root, 32);
@@ -6790,7 +6790,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	/* Copy parameters required for share submission */
 	work->job_id = strdup(pool->swork.job_id);
 	work->nonce1 = strdup(pool->nonce1);
-	work->ntime = strdup(pool->swork.ntime);
+	work->ntime = strdup(pool->ntime);
 	cg_runlock(&pool->data_lock);
 
 	if (opt_debug) {
diff --git a/miner.h b/miner.h
index fb9c238..de6fdb3 100644
--- a/miner.h
+++ b/miner.h
@@ -1125,15 +1125,10 @@ enum pool_enable {
 
 struct stratum_work {
 	char *job_id;
-	char *prev_hash;
 	unsigned char **merkle_bin;
-	char *bbversion;
-	char *nbit;
-	char *ntime;
 	bool clean;
 
 	size_t header_len;
-	int merkles;
 	double diff;
 };
 
@@ -1255,7 +1250,6 @@ struct pool {
 	int gbt_txns;
 
 	bool gbt_solo;
-	int merkles;
 	unsigned char merklebin[16 * 32];
 	int transactions;
 	unsigned char **txn_data;
@@ -1268,7 +1262,12 @@ struct pool {
 	int coinbase_len;
 	int nonce2_offset;
 	unsigned char header_bin[128];
+	int merkles;
 	int merkle_offset;
+	char *prev_hash;
+	char *bbversion;
+	char *nbit;
+	char *ntime;
 
 	struct timeval tv_lastwork;
 };
diff --git a/util.c b/util.c
index 1e36123..cb4c8dd 100644
--- a/util.c
+++ b/util.c
@@ -1595,7 +1595,7 @@ static char *json_array_string(json_t *val, unsigned int entry)
 	return NULL;
 }
 
-static char *blank_merkel = "0000000000000000000000000000000000000000000000000000000000000000";
+static char *blank_merkle = "0000000000000000000000000000000000000000000000000000000000000000";
 
 static bool parse_notify(struct pool *pool, json_t *val)
 {
@@ -1643,22 +1643,22 @@ static bool parse_notify(struct pool *pool, json_t *val)
 
 	cg_wlock(&pool->data_lock);
 	free(pool->swork.job_id);
-	free(pool->swork.prev_hash);
-	free(pool->swork.bbversion);
-	free(pool->swork.nbit);
-	free(pool->swork.ntime);
+	free(pool->prev_hash);
+	free(pool->bbversion);
+	free(pool->nbit);
+	free(pool->ntime);
 	pool->swork.job_id = job_id;
-	pool->swork.prev_hash = prev_hash;
+	pool->prev_hash = prev_hash;
 	cb1_len = strlen(coinbase1) / 2;
 	cb2_len = strlen(coinbase2) / 2;
-	pool->swork.bbversion = bbversion;
-	pool->swork.nbit = nbit;
-	pool->swork.ntime = ntime;
+	pool->bbversion = bbversion;
+	pool->nbit = nbit;
+	pool->ntime = ntime;
 	pool->swork.clean = clean;
 	alloc_len = pool->coinbase_len = cb1_len + pool->n1_len + pool->n2size + cb2_len;
 	pool->nonce2_offset = cb1_len + pool->n1_len;
 
-	for (i = 0; i < pool->swork.merkles; i++)
+	for (i = 0; i < pool->merkles; i++)
 		free(pool->swork.merkle_bin[i]);
 	if (merkles) {
 		pool->swork.merkle_bin = realloc(pool->swork.merkle_bin,
@@ -1679,15 +1679,15 @@ static bool parse_notify(struct pool *pool, json_t *val)
 			}
 		}
 	}
-	pool->swork.merkles = merkles;
+	pool->merkles = merkles;
 	if (clean)
 		pool->nonce2 = 0;
-	pool->merkle_offset = strlen(pool->swork.bbversion) +
-			      strlen(pool->swork.prev_hash);
+	pool->merkle_offset = strlen(pool->bbversion) +
+			      strlen(pool->prev_hash);
 	pool->swork.header_len = pool->merkle_offset +
 	/* merkle_hash */	 32 +
-				 strlen(pool->swork.ntime) +
-				 strlen(pool->swork.nbit) +
+				 strlen(pool->ntime) +
+				 strlen(pool->nbit) +
 	/* nonce */		 8 +
 	/* workpadding */	 96;
 	pool->merkle_offset /= 2;
@@ -1696,11 +1696,11 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	header = alloca(pool->swork.header_len);
 	snprintf(header, pool->swork.header_len,
 		"%s%s%s%s%s%s%s",
-		pool->swork.bbversion,
-		pool->swork.prev_hash,
-		blank_merkel,
-		pool->swork.ntime,
-		pool->swork.nbit,
+		pool->bbversion,
+		pool->prev_hash,
+		blank_merkle,
+		pool->ntime,
+		pool->nbit,
 		"00000000", /* nonce */
 		workpadding);
 	ret = hex2bin(pool->header_bin, header, 128);