Browse Source

work2d: Standardised way to pad extranonce beyond what work2d manages

Luke Dashjr 12 years ago
parent
commit
75e1184401
3 changed files with 26 additions and 4 deletions
  1. 2 2
      driver-stratum.c
  2. 22 2
      work2d.c
  3. 2 0
      work2d.h

+ 2 - 2
driver-stratum.c

@@ -80,7 +80,7 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
 	char my_job_id[33];
 	int i;
 	struct stratumsrv_job *ssj;
-	ssize_t n2pad = n2size - _ssm_client_octets - _ssm_client_xnonce2sz;
+	ssize_t n2pad = work2d_pad_xnonce_size(swork);
 	if (n2pad < 0)
 		return false;
 	size_t coinb1in_lenx = swork->nonce2_offset * 2;
@@ -96,7 +96,7 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
 	uint32_t ntime_n;
 	bin2hex(prevhash, &swork->header1[4], 32);
 	bin2hex(coinb1, bytes_buf(&swork->coinbase), swork->nonce2_offset);
-	memset(&coinb1[coinb1in_lenx], 'B', n2padx);
+	work2d_pad_xnonce(&coinb1[coinb1in_lenx], swork, true);
 	coinb1[coinb1_lenx] = '\0';
 	bin2hex(coinb2, &bytes_buf(&swork->coinbase)[swork->nonce2_offset + n2size], coinb2_len);
 	p += sprintf(p, "{\"params\":[\"%s\",\"%s\",\"%s\",\"%s\",[", my_job_id, prevhash, coinb1, coinb2);

+ 22 - 2
work2d.c

@@ -48,6 +48,27 @@ void release_work2d_(uint32_t xnonce1)
 	work2d_reserved[xnonce1] = false;
 }
 
+int work2d_pad_xnonce_size(const struct stratum_work * const swork)
+{
+	return swork->n2size - work2d_xnonce1sz - work2d_xnonce2sz;
+}
+
+void *work2d_pad_xnonce(void * const buf_, const struct stratum_work * const swork, const bool hex)
+{
+	uint8_t * const buf = buf_;
+	int pad = work2d_pad_xnonce_size(swork);
+	if (pad < 0)
+		return NULL;
+	if (hex)
+	{
+		pad *= 2;
+		memset(buf, 'b', pad);
+	}
+	else
+		memset(buf, '\xbb', pad);
+	return &buf[pad];
+}
+
 void work2d_gen_dummy_work(struct work * const work, struct stratum_work * const swork, const struct timeval * const tvp_prepared, const void * const xnonce2, const uint32_t xnonce1)
 {
 	uint8_t *p, *s;
@@ -68,8 +89,7 @@ void work2d_gen_dummy_work(struct work * const work, struct stratum_work * const
 #endif
 	p -= work2d_xnonce1sz;
 	memcpy(p, &xnonce1, work2d_xnonce1sz);
-	if (p != s)
-		memset(s, '\xbb', p - s);
+	work2d_pad_xnonce(s, swork, false);
 	gen_stratum_work2(work, swork);
 }
 

+ 2 - 0
work2d.h

@@ -11,6 +11,8 @@ extern void work2d_init();
 extern bool reserve_work2d_(uint32_t *xnonce1_p);
 extern void release_work2d_(uint32_t xnonce1);
 
+extern int work2d_pad_xnonce_size(const struct stratum_work *);
+extern void *work2d_pad_xnonce(void *buf, const struct stratum_work *, bool hex);
 extern void work2d_gen_dummy_work(struct work *, struct stratum_work *, const struct timeval *tvp_prepared, const void *xnonce2, uint32_t xnonce1);
 extern bool work2d_submit_nonce(struct thr_info *, struct stratum_work *, const struct timeval *tvp_prepared, const void *xnonce2, uint32_t xnonce1, uint32_t nonce, uint32_t ntime, bool *out_is_stale);