Browse Source

Simplify stratum to convert difficulty to target immediately

Luke Dashjr 11 years ago
parent
commit
2367d8906c
3 changed files with 5 additions and 11 deletions
  1. 2 7
      miner.c
  2. 1 2
      miner.h
  3. 2 2
      util.c

+ 2 - 7
miner.c

@@ -8041,7 +8041,7 @@ fishy:
 		/* Since the share is untracked, we can only guess at what the
 		 * work difficulty is based on the current pool diff. */
 		cg_rlock(&pool->data_lock);
-		pool_diff = pool->swork.diff;
+		pool_diff = target_diff(pool->swork.target);
 		cg_runlock(&pool->data_lock);
 
 		if (json_is_true(res_val)) {
@@ -8900,11 +8900,8 @@ void gen_stratum_work2(struct work *work, struct stratum_work *swork, const char
 	memset(&work->data[76], 0, 4);  // nonce
 	memcpy(&work->data[80], workpadding_bin, 48);
 
-	/* Store the stratum work diff to check it still matches the pool's
-	 * stratum diff when submitting shares */
-	work->sdiff = swork->diff;
-
 	/* Copy parameters required for share submission */
+	memcpy(work->target, swork->target, sizeof(work->target));
 	work->job_id = strdup(swork->job_id);
 	work->nonce1 = strdup(nonce1);
 	if (swork->data_lock_p)
@@ -8922,8 +8919,6 @@ void gen_stratum_work2(struct work *work, struct stratum_work *swork, const char
 
 	calc_midstate(work);
 
-	set_target(work->target, work->sdiff);
-
 	local_work++;
 	work->stratum = true;
 	work->blk.nonce = 0;

+ 1 - 2
miner.h

@@ -1145,7 +1145,7 @@ struct stratum_work {
 	uint32_t ntime;
 	struct timeval tv_received;
 
-	double diff;
+	uint8_t target[32];
 
 	bool transparency_probed;
 	struct timeval tv_transparency;
@@ -1305,7 +1305,6 @@ struct work {
 	bool		stratum;
 	char 		*job_id;
 	bytes_t		nonce2;
-	double		sdiff;
 	char		*nonce1;
 
 	unsigned char	work_restart_id;

+ 2 - 2
util.c

@@ -1999,7 +1999,7 @@ static bool parse_diff(struct pool *pool, json_t *val)
 		return false;
 
 	cg_wlock(&pool->data_lock);
-	pool->swork.diff = diff;
+	set_target(pool->swork.target, diff);
 	cg_wunlock(&pool->data_lock);
 
 	applog(LOG_DEBUG, "Pool %d stratum bdifficulty set to %f", pool->pool_no, diff);
@@ -2492,7 +2492,7 @@ out:
 		if (!pool->stratum_url)
 			pool->stratum_url = pool->sockaddr_url;
 		pool->stratum_active = true;
-		pool->swork.diff = 1;
+		set_target(pool->swork.target, 1);
 		if (opt_protocol) {
 			applog(LOG_DEBUG, "Pool %d confirmed mining.subscribe with extranonce1 %s extran2size %d",
 			       pool->pool_no, pool->nonce1, pool->n2size);