Browse Source

Stratum: Fix nonce2 sizes greater than 4 and (on big-endian) smaller than 4

Luke Dashjr 12 years ago
parent
commit
f08199b4a6
3 changed files with 17 additions and 3 deletions
  1. 9 3
      miner.c
  2. 4 0
      miner.h
  3. 4 0
      util.c

+ 9 - 3
miner.c

@@ -7146,10 +7146,16 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	cg_ilock(&pool->data_lock);
 
 	/* Generate coinbase */
-	// FIXME: This only works if (n2size == 4) || (n2size < 4 && littleendian)
 	bytes_resize(&work->nonce2, pool->n2size);
-	memcpy(bytes_buf(&work->nonce2), &pool->nonce2, pool->n2size);
-	memcpy(&coinbase[pool->swork.nonce2_offset], &pool->nonce2, pool->n2size);
+	memcpy(bytes_buf(&work->nonce2),
+#ifdef WORDS_BIGENDIAN
+	// NOTE: On big endian, the most significant bits are stored at the end, so skip the LSBs
+	       &((char*)&pool->nonce2)[pool->nonce2off],
+#else
+	       &pool->nonce2,
+#endif
+	       pool->nonce2sz);
+	memcpy(&coinbase[pool->swork.nonce2_offset], bytes_buf(&work->nonce2), pool->n2size);
 	pool->nonce2++;
 
 	/* Downgrade to a read lock to read off the pool variables */

+ 4 - 0
miner.h

@@ -1162,6 +1162,10 @@ struct pool {
 	char *nonce1;
 	size_t n1_len;
 	uint32_t nonce2;
+	int nonce2sz;
+#ifdef WORDS_BIGENDIAN
+	int nonce2off;
+#endif
 	int n2size;
 	char *sessionid;
 	bool has_stratum;

+ 4 - 0
util.c

@@ -2048,6 +2048,10 @@ resend:
 	pool->nonce1 = nonce1;
 	pool->n1_len = strlen(nonce1) / 2;
 	pool->n2size = n2size;
+	pool->nonce2sz  = (n2size > sizeof(pool->nonce2)) ? sizeof(pool->nonce2) : n2size;
+#ifdef WORDS_BIGENDIAN
+	pool->nonce2off = (n2size < sizeof(pool->nonce2)) ? (sizeof(pool->nonce2) - n2size) : 0;
+#endif
 	cg_wunlock(&pool->data_lock);
 
 	if (sessionid)