Commit 4c79252dc8198694eeb451212f71247cbfc73d10

Con Kolivas 2013-10-04T21:39:42

Provide a way for drivers to submit work that it has internally rolled the ntime value by returning the amount it has ntime rolled to be added.

diff --git a/cgminer.c b/cgminer.c
index 1e752be..09eac53 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6084,6 +6084,24 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 	return ret;
 }
 
+/* Allows drivers to submit work items where the driver has changed the ntime
+ * value by noffset. Must be only used with a work protocol that does not ntime
+ * roll itself intrinsically to generate work (eg stratum). */
+bool submit_noffset_nonce(struct thr_info *thr, struct work *work, uint32_t nonce,
+			  int noffset)
+{
+	unsigned char bin[4];
+	uint32_t h32, *be32 = (uint32_t *)bin;
+
+	hex2bin(bin, work->ntime, 4);
+	h32 = be32toh(*be32) + noffset;
+	*be32 = htobe32(h32);
+	free(work->ntime);
+	work->ntime = bin2hex(bin, 4);
+
+	return submit_nonce(thr, work, nonce);
+}
+
 static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)
 {
 	if (wdiff->tv_sec > opt_scantime ||
diff --git a/miner.h b/miner.h
index d2a408c..aecdf67 100644
--- a/miner.h
+++ b/miner.h
@@ -1388,6 +1388,8 @@ extern void inc_hw_errors(struct thr_info *thr);
 extern bool test_nonce(struct work *work, uint32_t nonce);
 extern void submit_tested_work(struct thr_info *thr, struct work *work);
 extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
+extern bool submit_noffset_nonce(struct thr_info *thr, struct work *work, uint32_t nonce,
+			  int noffset);
 extern struct work *get_queued(struct cgpu_info *cgpu);
 extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
 extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);