Browse Source

Move n2size from struct pool to struct stratum_work

Luke Dashjr 12 years ago
parent
commit
8f077c386e
4 changed files with 13 additions and 14 deletions
  1. 3 5
      driver-stratum.c
  2. 5 4
      miner.c
  3. 1 1
      miner.h
  4. 4 4
      util.c

+ 3 - 5
driver-stratum.c

@@ -44,7 +44,6 @@ struct stratumsrv_job {
 	
 	struct pool *pool;
 	uint8_t work_restart_id;
-	uint8_t n2size;
 	struct timeval tv_prepared;
 	struct stratum_work swork;
 	char *nonce1;
@@ -81,9 +80,9 @@ void _ssm_gen_dummy_work(struct work *work, struct stratumsrv_job *ssj, const ch
 		.work_restart_id = ssj->work_restart_id,
 		.tv_staged = ssj->tv_prepared,
 	};
-	bytes_resize(&work->nonce2, ssj->n2size);
+	bytes_resize(&work->nonce2, ssj->swork.n2size);
 	s = bytes_buf(&work->nonce2);
-	p = &s[ssj->n2size - _ssm_client_xnonce2sz];
+	p = &s[ssj->swork.n2size - _ssm_client_xnonce2sz];
 	if (extranonce2)
 		hex2bin(p, extranonce2, _ssm_client_xnonce2sz);
 #ifndef __OPTIMIZE__
@@ -104,7 +103,7 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
 	
 	struct stratumsrv_conn *conn;
 	const struct stratum_work * const swork = &pool->swork;
-	const int n2size = pool->n2size;
+	const int n2size = pool->swork.n2size;
 	char my_job_id[33];
 	int i;
 	struct stratumsrv_job *ssj;
@@ -149,7 +148,6 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
 		
 		.pool = pool,
 		.work_restart_id = pool->work_restart_id,
-		.n2size = n2size,
 		.nonce1 = maybe_strdup(pool->nonce1),
 	};
 	timer_set_now(&ssj->tv_prepared);

+ 5 - 4
miner.c

@@ -2965,7 +2965,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 			swork->job_id = NULL;
 			swork->clean = true;
 			// FIXME: Do something with expire
-			pool->nonce2sz = pool->n2size = GBT_XNONCESZ;
+			pool->nonce2sz = swork->n2size = GBT_XNONCESZ;
 			pool->nonce2 = 0;
 			cg_wunlock(&pool->data_lock);
 		}
@@ -8742,9 +8742,10 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	cg_wlock(&pool->data_lock);
 	pool->swork.data_lock_p = &pool->data_lock;
 	
-	bytes_resize(&work->nonce2, pool->n2size);
-	if (pool->nonce2sz < pool->n2size)
-		memset(&bytes_buf(&work->nonce2)[pool->nonce2sz], 0, pool->n2size - pool->nonce2sz);
+	const int n2size = pool->swork.n2size;
+	bytes_resize(&work->nonce2, n2size);
+	if (pool->nonce2sz < n2size)
+		memset(&bytes_buf(&work->nonce2)[pool->nonce2sz], 0, n2size - pool->nonce2sz);
 	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

+ 1 - 1
miner.h

@@ -1139,6 +1139,7 @@ struct stratum_work {
 	
 	bytes_t coinbase;
 	size_t nonce2_offset;
+	int n2size;
 	
 	int merkles;
 	bytes_t merkle_bin;
@@ -1253,7 +1254,6 @@ struct pool {
 #ifdef WORDS_BIGENDIAN
 	int nonce2off;
 #endif
-	int n2size;
 	char *sessionid;
 	bool has_stratum;
 	bool stratum_active;

+ 4 - 4
util.c

@@ -1925,12 +1925,12 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	pool->swork.nonce2_offset = cb1_len + pool->n1_len;
 	cb2_len = strlen(coinbase2) / 2;
 
-	bytes_resize(&pool->swork.coinbase, pool->swork.nonce2_offset + pool->n2size + cb2_len);
+	bytes_resize(&pool->swork.coinbase, pool->swork.nonce2_offset + pool->swork.n2size + cb2_len);
 	uint8_t *coinbase = bytes_buf(&pool->swork.coinbase);
 	hex2bin(coinbase, coinbase1, cb1_len);
 	hex2bin(&coinbase[cb1_len], pool->nonce1, pool->n1_len);
 	// NOTE: gap for nonce2, filled at work generation time
-	hex2bin(&coinbase[pool->swork.nonce2_offset + pool->n2size], coinbase2, cb2_len);
+	hex2bin(&coinbase[pool->swork.nonce2_offset + pool->swork.n2size], coinbase2, cb2_len);
 	
 	bytes_resize(&pool->swork.merkle_bin, 32 * merkles);
 	for (i = 0; i < merkles; i++)
@@ -2445,7 +2445,7 @@ resend:
 	free(pool->nonce1);
 	pool->nonce1 = nonce1;
 	pool->n1_len = strlen(nonce1) / 2;
-	pool->n2size = n2size;
+	pool->swork.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;
@@ -2470,7 +2470,7 @@ out:
 		pool->swork.diff = 1;
 		if (opt_protocol) {
 			applog(LOG_DEBUG, "Pool %d confirmed mining.subscribe with extranonce1 %s extran2size %d",
-			       pool->pool_no, pool->nonce1, pool->n2size);
+			       pool->pool_no, pool->nonce1, pool->swork.n2size);
 		}
 	} else {
 		if (recvd)