Browse Source

Add pool and work_restart_id to struct stratum_work so they can be used independently of struct pool

Luke Dashjr 12 years ago
parent
commit
c9d4596810
3 changed files with 12 additions and 8 deletions
  1. 2 7
      driver-stratum.c
  2. 7 1
      miner.c
  3. 3 0
      miner.h

+ 2 - 7
driver-stratum.c

@@ -42,8 +42,6 @@ static notifier_t _ssm_update_notifier;
 struct stratumsrv_job {
 	char *my_job_id;
 	
-	struct pool *pool;
-	uint8_t work_restart_id;
 	struct timeval tv_prepared;
 	struct stratum_work swork;
 	char *nonce1;
@@ -76,8 +74,8 @@ void _ssm_gen_dummy_work(struct work *work, struct stratumsrv_job *ssj, const ch
 	uint8_t *p, *s;
 	
 	*work = (struct work){
-		.pool = ssj->pool,
-		.work_restart_id = ssj->work_restart_id,
+		.pool = ssj->swork.pool,
+		.work_restart_id = ssj->swork.work_restart_id,
 		.tv_staged = ssj->tv_prepared,
 	};
 	bytes_resize(&work->nonce2, ssj->swork.n2size);
@@ -145,9 +143,6 @@ bool stratumsrv_update_notify_str(struct pool * const pool, bool clean)
 	ssj = malloc(sizeof(*ssj));
 	*ssj = (struct stratumsrv_job){
 		.my_job_id = strdup(my_job_id),
-		
-		.pool = pool,
-		.work_restart_id = pool->work_restart_id,
 		.nonce1 = maybe_strdup(pool->nonce1),
 	};
 	timer_set_now(&ssj->tv_prepared);

+ 7 - 1
miner.c

@@ -1047,6 +1047,7 @@ struct pool *add_pool(void)
 	cglock_init(&pool->data_lock);
 	mutex_init(&pool->stratum_lock);
 	timer_unset(&pool->swork.tv_transparency);
+	pool->swork.pool = pool;
 
 	/* Make sure the pool doesn't think we've been idle since time 0 */
 	pool->tv_idle.tv_sec = ~0UL;
@@ -2964,6 +2965,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 			free(swork->job_id);
 			swork->job_id = NULL;
 			swork->clean = true;
+			swork->work_restart_id = pool->work_restart_id;
 			// FIXME: Do something with expire
 			pool->nonce2sz = swork->n2size = GBT_XNONCESZ;
 			pool->nonce2 = 0;
@@ -6319,7 +6321,10 @@ static bool test_work_current(struct work *work)
 			}
 		}
 	  if (work->longpoll) {
+		struct pool * const pool = work->pool;
 		++work->pool->work_restart_id;
+		if (work->tr && work->tr == pool->swork.tr)
+			pool->swork.work_restart_id = pool->work_restart_id;
 		update_last_work(work);
 		if ((!restart) && work->pool == current_pool()) {
 			applog(
@@ -8301,6 +8306,7 @@ static void *stratum_thread(void *userdata)
 				have_block_height(block_id, height);
 			}
 
+			pool->swork.work_restart_id =
 			++pool->work_restart_id;
 			if (test_work_current(work)) {
 				/* Only accept a work update if this stratum
@@ -8757,7 +8763,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	pool->nonce2++;
 	
 	work->pool = pool;
-	work->work_restart_id = work->pool->work_restart_id;
+	work->work_restart_id = pool->swork.work_restart_id;
 	gen_stratum_work2(work, &pool->swork, pool->nonce1);
 	
 	cgtime(&work->tv_staged);

+ 3 - 0
miner.h

@@ -1157,6 +1157,9 @@ struct stratum_work {
 	bool opaque;
 	
 	cglock_t *data_lock_p;
+	
+	struct pool *pool;
+	unsigned char work_restart_id;
 };
 
 #define RBUFSIZE 8192