Browse Source

Perform merkle bin hex2bin on stratum notify to avoid doing it on each work generation.

Con Kolivas 12 years ago
parent
commit
5237bf350d
3 changed files with 14 additions and 11 deletions
  1. 1 4
      cgminer.c
  2. 1 1
      miner.h
  3. 12 6
      util.c

+ 1 - 4
cgminer.c

@@ -5605,10 +5605,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	gen_hash(pool->coinbase, merkle_root, pool->swork.cb_len);
 	memcpy(merkle_sha, merkle_root, 32);
 	for (i = 0; i < pool->swork.merkles; i++) {
-		unsigned char merkle_bin[32];
-
-		hex2bin(merkle_bin, pool->swork.merkle[i], 32);
-		memcpy(merkle_sha + 32, merkle_bin, 32);
+		memcpy(merkle_sha + 32, pool->swork.merkle_bin[i], 32);
 		gen_hash(merkle_sha, merkle_root, 64);
 		memcpy(merkle_sha, merkle_root, 32);
 	}

+ 1 - 1
miner.h

@@ -1088,7 +1088,7 @@ enum pool_enable {
 struct stratum_work {
 	char *job_id;
 	char *prev_hash;
-	char **merkle;
+	unsigned char **merkle_bin;
 	char *bbversion;
 	char *nbit;
 	char *ntime;

+ 12 - 6
util.c

@@ -1258,11 +1258,19 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	pool->nonce2_offset = cb1_len + pool->n1_len;
 
 	for (i = 0; i < pool->swork.merkles; i++)
-		free(pool->swork.merkle[i]);
+		free(pool->swork.merkle_bin[i]);
 	if (merkles) {
-		pool->swork.merkle = realloc(pool->swork.merkle, sizeof(char *) * merkles + 1);
-		for (i = 0; i < merkles; i++)
-			pool->swork.merkle[i] = json_array_string(arr, i);
+		pool->swork.merkle_bin = realloc(pool->swork.merkle_bin,
+						 sizeof(char *) * merkles + 1);
+		for (i = 0; i < merkles; i++) {
+			char *merkle = json_array_string(arr, i);
+
+			pool->swork.merkle_bin[i] = malloc(32);
+			if (unlikely(!pool->swork.merkle_bin[i]))
+				quit(1, "Failed to malloc pool swork merkle_bin");
+			hex2bin(pool->swork.merkle_bin[i], merkle, 32);
+			free(merkle);
+		}
 	}
 	pool->swork.merkles = merkles;
 	if (clean)
@@ -1300,8 +1308,6 @@ static bool parse_notify(struct pool *pool, json_t *val)
 		applog(LOG_DEBUG, "prev_hash: %s", prev_hash);
 		applog(LOG_DEBUG, "coinbase1: %s", coinbase1);
 		applog(LOG_DEBUG, "coinbase2: %s", coinbase2);
-		for (i = 0; i < merkles; i++)
-			applog(LOG_DEBUG, "merkle%d: %s", i, pool->swork.merkle[i]);
 		applog(LOG_DEBUG, "bbversion: %s", bbversion);
 		applog(LOG_DEBUG, "nbit: %s", nbit);
 		applog(LOG_DEBUG, "ntime: %s", ntime);