Display the actual share diff next to the pool required diff, using a suffix creation function to prevent values of >1000 being shown in their entirety.
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 125 126 127 128 129 130 131 132
diff --git a/cgminer.c b/cgminer.c
index d31a022..cd2c31b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1472,6 +1472,51 @@ void tailsprintf(char *f, const char *fmt, ...)
va_end(ap);
}
+/* Convert a uint64_t value into a truncated string for displaying with its
+ * associated suitable for Mega, Giga etc. Buf array needs to be long enough */
+static void suffix_string(uint64_t val, char *buf, int sigdigits)
+{
+ const uint64_t kilo = 1000ull;
+ const uint64_t mega = 1000000ull;
+ const uint64_t giga = 1000000000ull;
+ const uint64_t tera = 1000000000000ull;
+ const uint64_t peta = 1000000000000000ull;
+ const uint64_t exa = 1000000000000000000ull;
+ char suffix[2] = "";
+ double dval;
+
+ if (val >= exa) {
+ val /= peta;
+ dval = (double)val / kilo;
+ sprintf(suffix, "E");
+ } else if (val >= peta) {
+ val /= tera;
+ dval = (double)val / kilo;
+ sprintf(suffix, "P");
+ } else if (val >= tera) {
+ val /= giga;
+ dval = (double)val / kilo;
+ sprintf(suffix, "T");
+ } else if (val >= giga) {
+ val /= mega;
+ dval = (double)val / kilo;
+ sprintf(suffix, "G");
+ } else if (val >= mega) {
+ val /= kilo;
+ dval = (double)val / kilo;
+ sprintf(suffix, "M");
+ } else if (val >= kilo) {
+ dval = (double)val / kilo;
+ sprintf(suffix, "K");
+ } else
+ dval = val;
+
+ if (!sigdigits)
+ sprintf(buf, "%d%s", (unsigned int)dval, suffix);
+ else
+ sprintf(buf, "%.*g%s", sigdigits, dval, suffix);
+}
+
static void get_statline(char *buf, struct cgpu_info *cgpu)
{
double displayed_hashes, displayed_rolling = cgpu->rolling;
@@ -1929,6 +1974,26 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
}
}
+static uint64_t share_diff(const struct work *work)
+{
+ const uint64_t h64 = 0xFFFF000000000000ull;
+ char rtarget[33], *target;
+ uint64_t *data64, d64;
+ uint64_t ret;
+
+ target = bin2hex(work->hash, 32);
+ if (unlikely(!target))
+ quit(1, "Failed to bin2hex in share_diff");
+ swab256(rtarget, target);
+ free(target);
+ data64 = (uint64_t *)(rtarget + 4);
+ d64 = be64toh(*data64);
+ if (unlikely(!d64))
+ d64 = 1;
+ ret = h64 / d64;
+ return ret;
+}
+
static bool submit_upstream_work(const struct work *work, CURL *curl, bool resubmit)
{
char *hexstr = NULL;
@@ -1991,8 +2056,12 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
sprintf(hashshow, "%08lx.%08lx", (unsigned long)(hash32[7]), (unsigned long)(hash32[6]));
else {
int intdiff = round(work->work_difficulty);
+ uint64_t sharediff = share_diff(work);
+ char diffdisp[16];
+
+ suffix_string(sharediff, diffdisp, 0);
- sprintf(hashshow, "%08lx Diff %d%s", (unsigned long)(hash32[6]), intdiff,
+ sprintf(hashshow, "%08lx Diff %s/%d%s", (unsigned long)(hash32[6]), diffdisp, intdiff,
work->block? " BLOCK!" : "");
}
@@ -4079,13 +4148,16 @@ static void stratum_share_result(json_t *val, json_t *res_val, json_t *err_val,
struct stratum_share *sshare)
{
struct work *work = &sshare->work;
+ uint64_t sharediff = share_diff(work);
char hashshow[65];
uint32_t *hash32;
+ char diffdisp[16];
int intdiff;
hash32 = (uint32_t *)(work->hash);
intdiff = round(work->work_difficulty);
- sprintf(hashshow, "%08lx Diff %d%s", (unsigned long)(hash32[6]), intdiff,
+ suffix_string(sharediff, diffdisp, 0);
+ sprintf(hashshow, "%08lx Diff %s/%d%s", (unsigned long)(hash32[6]), diffdisp, intdiff,
work->block? " BLOCK!" : "");
share_result(val, res_val, err_val, work, hashshow, false, "");
}
diff --git a/miner.h b/miner.h
index 3a65d75..5e98244 100644
--- a/miner.h
+++ b/miner.h
@@ -144,10 +144,12 @@ static inline int fsync (int fd)
#ifndef htobe32
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define be32toh(x) bswap_32(x)
+# define be64toh(x) bswap_64(x)
# define htobe32(x) bswap_32(x)
# define htobe64(x) bswap_64(x)
# elif __BYTE_ORDER == __BIG_ENDIAN
# define be32toh(x) (x)
+# define be64toh(x) (x)
# define htobe32(x) (x)
# define htobe64(x) (x)
#else