Skip to content

Commit

Permalink
Fix difficulty on front end UI
Browse files Browse the repository at this point in the history
  • Loading branch information
cjepson committed Jan 27, 2016
1 parent 7ea75e1 commit d7751bb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4136,16 +4136,26 @@ static int block_sort(struct block *blocka, struct block *blockb)
/* Decode the current block difficulty which is in packed form */
static void set_blockdiff(const struct work *work)
{
uint8_t pow = work->data[72];
uint32_t* data_cast_as_32 = (uint32_t*) work->data;
uint32_t diff32BE = data_cast_as_32[29];

/* Mask off the exponent and make it into a byte */
uint8_t pow = (uint8_t)((diff32BE&0xff000000)>>24);

/* Pop off the rest and shift it according to */
/* the exponent. Divide mindiff by it. */
/* Testnet has a different mindiff than mainnet */
/* mindiff, this may calculate incorrectly on */
/* testnet mining. */
int powdiff = (8 * (0x1d - 3)) - (8 * (pow - 3));
uint32_t diff32 = be32toh(*((uint32_t *)(work->data + 72))) & 0x00FFFFFF;
uint32_t diff32 = be32toh(diff32BE) & 0x00FFFFFF;
double numerator = 0xFFFFULL << powdiff;
double ddiff = numerator / (double)diff32;

if (unlikely(current_diff != ddiff)) {
suffix_string(ddiff, block_diff, sizeof(block_diff), 0);
current_diff = ddiff;
applog(LOG_NOTICE, "Network diff set to %s", block_diff);
applog(LOG_NOTICE, "Network diff set to %s (target %x)", block_diff, diff32BE);
}
}

Expand Down

0 comments on commit d7751bb

Please sign in to comment.