From b6a97de687d66632bcb4d9a27818c9e21f840842 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 4 Oct 2013 21:39:42 +1000 Subject: [PATCH] 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. --- cgminer.c | 18 ++++++++++++++++++ miner.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/cgminer.c b/cgminer.c index 84788130..5d0667d7 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 72e3d153..9c49a350 100644 --- a/miner.h +++ b/miner.h @@ -1383,6 +1383,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);