From 24643e9ba0621aa2e64a485ba06f3c9429ba6ae7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 21 May 2014 22:28:03 +1000 Subject: [PATCH] Get the network difficulty from the block header and use that to determine possible block solves in proxy mode --- src/libckpool.c | 6 +++--- src/libckpool.h | 2 +- src/stratifier.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 8929429e..4c13a1fe 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1565,16 +1565,16 @@ double diff_from_target(uchar *target) /* Return the network difficulty from the block header which is in packed form, * as a double. */ -double diff_from_header(uchar *header) +double diff_from_nbits(char *nbits) { double numerator; uint32_t diff32; uint8_t pow; int powdiff; - pow = header[72]; + pow = nbits[0]; powdiff = (8 * (0x1d - 3)) - (8 * (pow - 3)); - diff32 = be32toh(*((uint32_t *)(header + 72))) & 0x00FFFFFF; + diff32 = be32toh(*((uint32_t *)nbits)) & 0x00FFFFFF; numerator = 0xFFFFULL << powdiff; return numerator / (double)diff32; } diff --git a/src/libckpool.h b/src/libckpool.h index 7fb967e8..4a0340d1 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -380,7 +380,7 @@ void suffix_string(double val, char *buf, size_t bufsiz, int sigdigits); double le256todouble(const uchar *target); double diff_from_target(uchar *target); -double diff_from_header(uchar *header); +double diff_from_nbits(char *nbits); void target_from_diff(uchar *target, double diff); void gen_hash(uchar *data, uchar *hash, int len); diff --git a/src/stratifier.c b/src/stratifier.c index 3198462b..4910868a 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -88,6 +88,7 @@ struct workbase { /* GBT/shared variables */ char target[68]; double diff; + double network_diff; uint32_t version; uint32_t curtime; char prevhash[68]; @@ -367,6 +368,7 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block) int len, ret; wb->gentime = time(NULL); + wb->network_diff = diff_from_nbits(wb->headerbin + 72); len = strlen(ckp->logdir) + 8 + 1 + 16; wb->logdir = ckalloc(len); @@ -1184,7 +1186,11 @@ static void test_blocksolve(workbase_t *wb, const uchar *data, double diff, cons char hexcoinbase[512]; /* Submit anything over 95% of the diff in case of rounding errors */ - if (diff < current_workbase->diff * 0.95) + if (diff < current_workbase->network_diff * 0.95) + return; + + LOGWARNING("Possible block solve diff %f !", diff); + if (wb->proxy) return; gbt_block = ckalloc(512); @@ -1268,8 +1274,7 @@ static double submission_diff(stratum_instance_t *client, workbase_t *wb, const ret = diff_from_target(hash); /* Test we haven't solved a block regardless of share status */ - if (!wb->proxy) - test_blocksolve(wb, swap, ret, coinbase, cblen); + test_blocksolve(wb, swap, ret, coinbase, cblen); return ret; }