Use cpu scrypt code to check if an scrypt share is below target before submitting it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/Makefile.am b/Makefile.am
index a784ef9..1473375 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,6 +45,10 @@ cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
cgminer_SOURCES += adl.c adl.h adl_functions.h
cgminer_SOURCES += *.cl
+if HAS_SCRYPT
+cgminer_SOURCES += scrypt.c
+endif
+
if HAS_CPUMINE
# original CPU related sources, unchanged
cgminer_SOURCES += \
@@ -56,10 +60,6 @@ cgminer_SOURCES += \
# the CPU portion extracted from original main.c
cgminer_SOURCES += driver-cpu.h driver-cpu.c
-if HAS_SCRYPT
-cgminer_SOURCES += scrypt.c
-endif
-
if HAS_YASM
AM_CFLAGS = -DHAS_YASM
if HAVE_x86_64
diff --git a/cgminer.c b/cgminer.c
index f2ea382..4801012 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4012,7 +4012,7 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
/* Do one last check before attempting to submit the work */
/* Side effect: sets work->data for us */
if (!test_nonce(work, nonce)) {
- applog(LOG_INFO, "Share below target");
+ applog(LOG_INFO, "Pool %d share below target", work->pool->pool_no);
return true;
}
return submit_work_sync(thr, work);
diff --git a/findnonce.c b/findnonce.c
index a11333a..92e4881 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -220,6 +220,8 @@ static void send_nonce(struct pc_data *pcd, cl_uint nonce)
}
}
+extern bool scrypt_scan_nonce(unsigned char *pdata, uint32_t nonce);
+
static void *postcalc_hash(void *userdata)
{
struct pc_data *pcd = (struct pc_data *)userdata;
@@ -234,9 +236,13 @@ static void *postcalc_hash(void *userdata)
if (nonce) {
applog(LOG_DEBUG, "OCL NONCE %u", nonce);
#ifdef USE_SCRYPT
- if (opt_scrypt)
- submit_nonce(thr, pcd->work, nonce);
- else
+ if (opt_scrypt) {
+ struct work *work = pcd->work;
+ if (scrypt_scan_nonce(work, nonce))
+ submit_nonce(thr, work, nonce);
+ else
+ applog(LOG_INFO, "Pool %d share below target", work->pool->pool_no);
+ } else
#endif
send_nonce(pcd, nonce);
nonces++;
diff --git a/scrypt.c b/scrypt.c
index 4334bcf..14378d6 100644
--- a/scrypt.c
+++ b/scrypt.c
@@ -407,6 +407,20 @@ static uint32_t scrypt_1024_1_1_256_sp(const uint32_t* input, char* scratchpad)
return PBKDF2_SHA256_80_128_32(input, X);
}
+bool scrypt_scan_nonce(struct work *work, uint32_t nonce)
+{
+ uint32_t Htarg, tmp_hash7, data[20];
+ unsigned char *scratchbuf;
+
+ be32enc_vect(data, (const uint32_t *)work->data, 19);
+ data[19] = htobe32(nonce);
+
+ Htarg = ((const uint32_t *)work->target)[7];
+ scratchbuf = alloca(131584);
+ tmp_hash7 = scrypt_1024_1_1_256_sp(data, scratchbuf);
+ return (tmp_hash7 <= Htarg);
+}
+
bool scanhash_scrypt(struct thr_info *thr, const unsigned char *pmidstate, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget,
@@ -423,7 +437,7 @@ bool scanhash_scrypt(struct thr_info *thr, const unsigned char *pmidstate, unsig
be32enc_vect(data, (const uint32_t *)pdata, 19);
- scratchbuf = malloc(131583);
+ scratchbuf = malloc(131584);
if (unlikely(!scratchbuf)) {
applog(LOG_ERR, "Failed to malloc scratchbuf in scanhash_scrypt");
return ret;