Commit 1a7a87c2a67b3fc5911e68f1300f81f59bc956cc

Con Kolivas 2013-05-11T20:29:48

Use a discrete device target for scrypt that dynamically changes to ensure we still report a work utility even if no shares are submitted such as in solo mining.

diff --git a/cgminer.c b/cgminer.c
index 04d00db..0964f52 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5566,7 +5566,26 @@ static void hash_sole_work(struct thr_info *mythr)
 				"mining thread %d", thr_id);
 			break;
 		}
-		work->device_diff = MIN(drv->max_diff, work->work_difficulty);
+		work->device_diff = MIN(drv->working_diff, work->work_difficulty);
+#ifdef USE_SCRYPT
+		/* Dynamically adjust the working diff even if the target
+		 * diff is very high to ensure we can still validate scrypt is
+		 * returning shares. */
+		if (opt_scrypt) {
+			double wu;
+
+			wu = total_diff1 / total_secs * 60;
+			if (wu > 30 && drv->working_diff < drv->max_diff &&
+			    drv->working_diff < work->work_difficulty) {
+				drv->working_diff++;
+				applog(LOG_DEBUG, "Driver %s working diff changed to %.0f",
+					drv->dname, drv->working_diff);
+				work->device_diff = MIN(drv->working_diff, work->work_difficulty);
+			} else if (drv->working_diff > work->work_difficulty)
+				drv->working_diff = work->work_difficulty;
+			set_target(work->device_target, work->device_diff);
+		}
+#endif
 
 		do {
 			cgtime(&tv_start);
@@ -6821,6 +6840,8 @@ void fill_device_drv(struct cgpu_info *cgpu)
 		drv->queue_full = &noop_queue_full;
 	if (!drv->max_diff)
 		drv->max_diff = 1;
+	if (!drv->working_diff)
+		drv->working_diff = 1;
 }
 
 void enable_device(struct cgpu_info *cgpu)
diff --git a/driver-opencl.c b/driver-opencl.c
index 8168aa9..de63b13 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -1081,7 +1081,7 @@ static cl_int queue_scrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_u
 	cl_uint le_target;
 	cl_int status = 0;
 
-	le_target = *(cl_uint *)(blk->work->target + 28);
+	le_target = *(cl_uint *)(blk->work->device_target + 28);
 	clState->cldata = blk->work->data;
 	status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL,NULL);
 
diff --git a/miner.h b/miner.h
index d76b44c..471b372 100644
--- a/miner.h
+++ b/miner.h
@@ -336,6 +336,7 @@ struct device_drv {
 
 	/* Highest target diff the device supports */
 	double max_diff;
+	double working_diff;
 };
 
 extern struct device_drv *copy_drv(struct device_drv*);
@@ -1161,6 +1162,9 @@ struct work {
 	unsigned char	target[32];
 	unsigned char	hash[32];
 
+#ifdef USE_SCRYPT
+	unsigned char	device_target[32];
+#endif
 	double		device_diff;
 	uint64_t	share_diff;