Browse Source

Store a reference timeval with ntime_roll_limits

Luke Dashjr 11 years ago
parent
commit
afdee6f96b
3 changed files with 15 additions and 11 deletions
  1. 11 8
      miner.c
  2. 3 2
      miner.h
  3. 1 1
      util.c

+ 11 - 8
miner.c

@@ -2819,19 +2819,21 @@ bool pool_may_redirect_to(struct pool * const pool, const char * const uri)
 	return match_domains(pool->rpc_url, strlen(pool->rpc_url), uri, strlen(uri));
 }
 
-void set_simple_ntime_roll_limit(struct ntime_roll_limits * const nrl, const uint32_t ntime_base, const int ntime_roll)
+void set_simple_ntime_roll_limit(struct ntime_roll_limits * const nrl, const uint32_t ntime_base, const int ntime_roll, const struct timeval * const tvp_ref)
 {
+	const int offsets = max(ntime_roll, 60);
 	*nrl = (struct ntime_roll_limits){
 		.min = ntime_base,
 		.max = ntime_base + ntime_roll,
-		.minoff = -ntime_roll,
-		.maxoff = ntime_roll,
+		.tv_ref = *tvp_ref,
+		.minoff = -offsets,
+		.maxoff = offsets,
 	};
 }
 
-void work_set_simple_ntime_roll_limit(struct work * const work, const int ntime_roll)
+void work_set_simple_ntime_roll_limit(struct work * const work, const int ntime_roll, const struct timeval * const tvp_ref)
 {
-	set_simple_ntime_roll_limit(&work->ntime_roll_limits, upk_u32be(work->data, 0x44), ntime_roll);
+	set_simple_ntime_roll_limit(&work->ntime_roll_limits, upk_u32be(work->data, 0x44), ntime_roll, tvp_ref);
 }
 
 static double target_diff(const unsigned char *);
@@ -2942,6 +2944,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 		work->ntime_roll_limits = (struct ntime_roll_limits){
 			.min = tmpl->mintime,
 			.max = tmpl->maxtime,
+			.tv_ref = tv_now,
 			.minoff = tmpl->mintimeoff,
 			.maxoff = tmpl->maxtimeoff,
 		};
@@ -2967,7 +2970,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
 		return false;
 	}
 	else
-		work_set_simple_ntime_roll_limit(work, 0);
+		work_set_simple_ntime_roll_limit(work, 0, &tv_now);
 
 	if (!jobj_binary(res_val, "midstate", work->midstate, sizeof(work->midstate), false)) {
 		// Calculate it ourselves
@@ -4910,7 +4913,7 @@ void get_benchmark_work(struct work *work)
 	copy_time(&work->tv_staged, &work->tv_getwork);
 	work->getwork_mode = GETWORK_MODE_BENCHMARK;
 	calc_diff(work, 0);
-	work_set_simple_ntime_roll_limit(work, 60);
+	work_set_simple_ntime_roll_limit(work, 60, &work->tv_getwork);
 }
 
 static void wake_gws(void);
@@ -5413,7 +5416,7 @@ static void roll_work(struct work *work)
 	ntime = be32toh(*work_ntime);
 	ntime++;
 	*work_ntime = htobe32(ntime);
-		work_set_simple_ntime_roll_limit(work, 0);
+		work_set_simple_ntime_roll_limit(work, 0, &work->ntime_roll_limits.tv_ref);
 
 		applog(LOG_DEBUG, "Successfully rolled time header in work");
 	}

+ 3 - 2
miner.h

@@ -1141,6 +1141,7 @@ struct bfg_tmpl_ref {
 struct ntime_roll_limits {
 	uint32_t min;
 	uint32_t max;
+	struct timeval tv_ref;
 	uint16_t minoff;
 	uint16_t maxoff;
 };
@@ -1449,8 +1450,8 @@ extern void clean_work(struct work *work);
 extern void free_work(struct work *work);
 extern void __copy_work(struct work *work, const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
-extern void set_simple_ntime_roll_limit(struct ntime_roll_limits *, uint32_t ntime_base, int ntime_roll);
-extern void work_set_simple_ntime_roll_limit(struct work *, int ntime_roll);
+extern void set_simple_ntime_roll_limit(struct ntime_roll_limits *, uint32_t ntime_base, int ntime_roll, const struct timeval *tvp_ref);
+extern void work_set_simple_ntime_roll_limit(struct work *, int ntime_roll, const struct timeval *tvp_ref);
 extern char *devpath_to_devid(const char *);
 extern struct thr_info *get_thread(int thr_id);
 extern struct cgpu_info *get_devices(int id);

+ 1 - 1
util.c

@@ -2124,7 +2124,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	hex2bin(&pool->swork.diffbits[0], nbit, 4);
 	
 	/* Nominally allow a driver to ntime roll 60 seconds */
-	set_simple_ntime_roll_limit(&pool->swork.ntime_roll_limits, pool->swork.ntime, 60);
+	set_simple_ntime_roll_limit(&pool->swork.ntime_roll_limits, pool->swork.ntime, 60, &pool->swork.tv_received);
 	
 	cb1_len = strlen(coinbase1) / 2;
 	pool->swork.nonce2_offset = cb1_len + pool->n1_len;