Display correct share hash and share difficulty with scrypt mining.
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
diff --git a/cgminer.c b/cgminer.c
index a945465..1385a56 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -47,6 +47,7 @@
#include "driver-cpu.h"
#include "driver-opencl.h"
#include "bench_block.h"
+#include "scrypt.h"
#if defined(unix)
#include <errno.h>
@@ -1988,7 +1989,17 @@ static uint64_t share_diff(const struct work *work)
return ret;
}
-static bool submit_upstream_work(const struct work *work, CURL *curl, bool resubmit)
+static uint32_t scrypt_diff(const struct work *work)
+{
+ const uint32_t scrypt_diffone = 0x0000fffful;
+ uint32_t d32 = work->outputhash;
+
+ if (unlikely(!d32))
+ d32 = 1;
+ return scrypt_diffone / d32;
+}
+
+static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
{
char *hexstr = NULL;
json_t *val, *res, *err;
@@ -2046,13 +2057,19 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
if (!QUIET) {
int intdiff = floor(work->work_difficulty);
+ char diffdisp[16];
hash32 = (uint32_t *)(work->hash);
- if (opt_scrypt)
- sprintf(hashshow, "%08lx Diff %d", (unsigned long)(hash32[7]), intdiff);
- else {
+ if (opt_scrypt) {
+ uint32_t sharediff;
+
+ scrypt_outputhash(work);
+ sharediff = scrypt_diff(work);
+ suffix_string(sharediff, diffdisp, 0);
+
+ sprintf(hashshow, "%08lx Diff %s/%d", (unsigned long)work->outputhash, diffdisp, intdiff);
+ } else {
uint64_t sharediff = share_diff(work);
- char diffdisp[16];
suffix_string(sharediff, diffdisp, 0);
diff --git a/miner.h b/miner.h
index 22618b2..73e6ec3 100644
--- a/miner.h
+++ b/miner.h
@@ -897,10 +897,10 @@ struct work {
unsigned char target[32];
unsigned char hash[32];
+ uint32_t outputhash;
+
int rolls;
- uint32_t output[1];
- uint32_t valid;
dev_blk_ctx blk;
struct thr_info *thr;
diff --git a/scrypt.c b/scrypt.c
index 652f3c3..e48996c 100644
--- a/scrypt.c
+++ b/scrypt.c
@@ -405,6 +405,18 @@ static uint32_t scrypt_1024_1_1_256_sp(const uint32_t* input, char* scratchpad)
return PBKDF2_SHA256_80_128_32(input, X);
}
+void scrypt_outputhash(struct work *work)
+{
+ uint32_t data[20];
+ char *scratchbuf;
+ uint32_t *nonce = (uint32_t *)(work->data + 76);
+
+ be32enc_vect(data, (const uint32_t *)work->data, 19);
+ data[19] = htobe32(*nonce);
+ scratchbuf = alloca(131584);
+ work->outputhash = scrypt_1024_1_1_256_sp(data, scratchbuf);
+}
+
/* Used externally as confirmation of correct OCL code */
bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{
diff --git a/scrypt.h b/scrypt.h
index 4ea3abd..a5efb10 100644
--- a/scrypt.h
+++ b/scrypt.h
@@ -1,9 +1,13 @@
#ifndef SCRYPT_H
#define SCRYPT_H
+#include "miner.h"
+
#ifdef USE_SCRYPT
extern bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget,
uint32_t nonce);
+extern void scrypt_outputhash(struct work *work);
+
#else /* USE_SCRYPT */
static inline bool scrypt_test(__maybe_unused unsigned char *pdata,
__maybe_unused const unsigned char *ptarget,
@@ -11,6 +15,10 @@ static inline bool scrypt_test(__maybe_unused unsigned char *pdata,
{
return false;
}
+
+static inline void scrypt_outputhash(struct work *work)
+{
+}
#endif /* USE_SCRYPT */
#endif /* SCRYPT_H */