Commit 78f246fd0f934437bef187bf71834ca7b0008b11

ckolivas 2014-05-07T12:14:24

Rationalise diffs stored in the work struct and document them to avoid further confusion

diff --git a/cgminer.c b/cgminer.c
index e77da7f..265dd99 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6751,7 +6751,6 @@ void submit_nonce2_nonce(struct thr_info *thr, uint32_t pool_no, uint32_t nonce2
 	pool->nonce2 = nonce2;
 	gen_stratum_work(pool, work);
 
-	work->device_diff = MIN(drv->working_diff, work->work_difficulty);
 	submit_nonce(thr, work, nonce);
 	free_work(work);
 }
@@ -7118,9 +7117,9 @@ static void update_work_stats(struct thr_info *thr, struct work *work)
 	}
 
 	mutex_lock(&stats_lock);
-	total_diff1 += work->device_diff;
-	thr->cgpu->diff1 += work->device_diff;
-	work->pool->diff1 += work->device_diff;
+	total_diff1 += work->work_difficulty;
+	thr->cgpu->diff1 += work->work_difficulty;
+	work->pool->diff1 += work->work_difficulty;
 	thr->cgpu->last_device_valid_work = time(NULL);
 	mutex_unlock(&stats_lock);
 }
@@ -7249,7 +7248,7 @@ static void hash_sole_work(struct thr_info *mythr)
 				"mining thread %d", thr_id);
 			break;
 		}
-		work->device_diff = MIN(drv->working_diff, work->work_difficulty);
+		work->device_diff = MIN(drv->max_diff, work->work_difficulty);
 
 		do {
 			cgtime(&tv_start);
@@ -8833,8 +8832,6 @@ void fill_device_drv(struct device_drv *drv)
 		drv->zero_stats = &noop_zero_stats;
 	if (!drv->max_diff)
 		drv->max_diff = 1;
-	if (!drv->working_diff)
-		drv->working_diff = 1;
 }
 
 void null_device_drv(struct device_drv *drv)
@@ -8870,7 +8867,6 @@ void null_device_drv(struct device_drv *drv)
 
 	drv->zero_stats = &noop_zero_stats;
 	drv->max_diff = 1;
-	drv->working_diff = 1;
 }
 
 void enable_device(struct cgpu_info *cgpu)
diff --git a/driver-hashfast.c b/driver-hashfast.c
index ab18804..8227416 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -1934,7 +1934,7 @@ struct device_drv hashfast_drv = {
 	.drv_id = DRIVER_hashfast,
 	.dname = "Hashfast",
 	.name = "HFA",
-	.max_diff = 256.0, // Limit max diff to get some nonces back regardless
+	.max_diff = 32.0, // Limit max diff to get some nonces back regardless
 	.drv_detect = hfa_detect,
 	.thread_init = hfa_init,
 	.hash_work = &hash_driver_work,
diff --git a/driver-spondoolies.c b/driver-spondoolies.c
index 73d74a1..6aa66cf 100644
--- a/driver-spondoolies.c
+++ b/driver-spondoolies.c
@@ -223,7 +223,7 @@ static void fill_minergate_request(minergate_do_job_req* work, struct work *cg_w
 				   int ntime_offset)
 {
 	uint32_t x[64/4];
-	int wd;
+	uint64_t wd;
 
 	memset(work, 0, sizeof(minergate_do_job_req));
 	//work->
@@ -237,7 +237,7 @@ static void fill_minergate_request(minergate_do_job_req* work, struct work *cg_w
 	//work->leading_zeroes = get_leading_zeroes(cg_work->target);
 	// Is there no better way to get leading zeroes?
 	work->leading_zeroes = 30;
-	wd = (int)round(cg_work->work_difficulty);
+	wd = round(cg_work->work_difficulty);
 	while (wd) {
 		work->leading_zeroes++;
 		wd = wd >> 1;
@@ -430,6 +430,7 @@ struct device_drv spondoolies_drv = {
 	.drv_id = DRIVER_spondoolies,
 	.dname = "Spondoolies",
 	.name = "SPN",
+	.max_diff = 32.0, // Limit max diff to get some nonces back regardless
 	.drv_detect = spondoolies_detect,
 	.get_api_stats = spondoolies_api_stats,
 	.thread_prepare = spondoolies_prepare,
diff --git a/miner.h b/miner.h
index f25dc78..388c433 100644
--- a/miner.h
+++ b/miner.h
@@ -351,7 +351,6 @@ struct device_drv {
 
 	/* Highest target diff the device supports */
 	double max_diff;
-	double working_diff;
 };
 
 extern struct device_drv *copy_drv(struct device_drv*);
@@ -1303,7 +1302,8 @@ struct work {
 	unsigned char	target[32];
 	unsigned char	hash[32];
 
-	unsigned char	device_target[32];
+	/* This is the diff the device is currently aiming for and must be
+	 * the minimum of work_difficulty & drv->max_diff */
 	double		device_diff;
 	uint64_t	share_diff;
 
@@ -1341,6 +1341,8 @@ struct work {
 	uint32_t	id;
 	UT_hash_handle	hh;
 
+	/* This is the diff work we're aiming to submit and should match the
+	 * work->target binary */
 	double		work_difficulty;
 
 	// Allow devices to identify work if multiple sub-devices