Browse Source

Merge commit '0870ab7' into HEAD

Luke Dashjr 13 years ago
parent
commit
33c0916f44
3 changed files with 25 additions and 12 deletions
  1. 15 12
      miner.c
  2. 1 0
      miner.h
  3. 9 0
      util.c

+ 15 - 12
miner.c

@@ -6220,11 +6220,11 @@ static void set_work_target(struct work *work, double diff)
  * other means to detect when the pool has died in stratum_thread */
 static void gen_stratum_work(struct pool *pool, struct work *work)
 {
-	unsigned char *coinbase, merkle_root[32], merkle_sha[64], *merkle_hash;
+	unsigned char *coinbase, merkle_root[32], merkle_sha[64];
 	int len, cb1_len, n1_len, cb2_len, i;
+	char *header, *merkle_hash;
 	uint32_t *data32, *swap32;
 	size_t alloc_len;
-	char *header;
 
 	clean_work(work);
 
@@ -6239,7 +6239,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	len = cb1_len + n1_len + pool->n2size + cb2_len;
 	alloc_len = len;
 	align_len(&alloc_len);
-	coinbase = alloca(alloc_len);
+	coinbase = calloc(alloc_len, 1);
 	hex2bin(coinbase, pool->swork.coinbase1, cb1_len);
 	hex2bin(coinbase + cb1_len, pool->nonce1, n1_len);
 	hex2bin(coinbase + cb1_len + n1_len, work->nonce2, pool->n2size);
@@ -6247,6 +6247,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 
 	/* Generate merkle root */
 	gen_hash(coinbase, merkle_root, len);
+	free(coinbase);
 	memcpy(merkle_sha, merkle_root, 32);
 	for (i = 0; i < pool->swork.merkles; i++) {
 		unsigned char merkle_bin[32];
@@ -6260,15 +6261,17 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	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);
-
-	header = strdup(pool->swork.bbversion);
-	header = realloc_strcat(header, pool->swork.prev_hash);
-	header = realloc_strcat(header, (char *)merkle_hash);
-	header = realloc_strcat(header, pool->swork.ntime);
-	header = realloc_strcat(header, pool->swork.nbit);
-	header = realloc_strcat(header, "00000000"); /* nonce */
-	header = realloc_strcat(header, workpadding);
+	merkle_hash = bin2hex((const unsigned char *)merkle_root, 32);
+
+	header = calloc(pool->swork.header_len, 1);
+	sprintf(header, "%s%s%s%s%s%s%s",
+		pool->swork.bbversion,
+		pool->swork.prev_hash,
+		merkle_hash,
+		pool->swork.ntime,
+		pool->swork.nbit,
+		"00000000", /* nonce */
+		workpadding);
 
 	/* Store the stratum work diff to check it still matches the pool's
 	 * stratum diff when submitting shares */

+ 1 - 0
miner.h

@@ -887,6 +887,7 @@ struct stratum_work {
 	char *ntime;
 	bool clean;
 
+	size_t header_len;
 	int merkles;
 	double diff;
 

+ 9 - 0
util.c

@@ -1265,6 +1265,15 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	pool->swork.merkles = merkles;
 	if (clean)
 		pool->nonce2 = 0;
+	pool->swork.header_len = strlen(pool->swork.bbversion) +
+				 strlen(pool->swork.prev_hash) +
+				 strlen(pool->swork.ntime) +
+				 strlen(pool->swork.nbit) +
+	/* merkle_hash */	 32 +
+	/* nonce */		 8 +
+	/* workpadding */	 96;
+	pool->swork.header_len = pool->swork.header_len * 2 + 1;
+	align_len(&pool->swork.header_len);
 	mutex_unlock(&pool->pool_lock);
 
 	applog(LOG_DEBUG, "Received stratum notify from pool %u with job_id=%s",