Browse Source

Get the network difficulty from the block header and use that to determine possible block solves in proxy mode

master
Con Kolivas 11 years ago
parent
commit
24643e9ba0
  1. 6
      src/libckpool.c
  2. 2
      src/libckpool.h
  3. 11
      src/stratifier.c

6
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;
}

2
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);

11
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;
}

Loading…
Cancel
Save