Fix checkValid function
Diff target needs to be converted to little endian for comparison.
This commit is contained in:
parent
5d22a15ac2
commit
0a142ab52a
@ -346,16 +346,12 @@ void runMiner(void * task_id) {
|
||||
}
|
||||
shares++;
|
||||
|
||||
// check if valid header
|
||||
// check if valid header
|
||||
if(checkValid(hash, mMiner.bytearray_target)){
|
||||
Serial.printf("[WORKER] %d CONGRATULATIONS! Valid block found with nonce: %d | 0x%x\n", miner_id, nonce, nonce);
|
||||
valids++;
|
||||
Serial.printf("[WORKER] %d Submitted work valid!\n", miner_id);
|
||||
// STEP 3: Submit mining job
|
||||
tx_mining_submit(client, mWorker, mJob, nonce);
|
||||
client.stop();
|
||||
// exit
|
||||
nonce = MAX_NONCE;
|
||||
// wait for new job
|
||||
break;
|
||||
}
|
||||
// increment nonce
|
||||
|
@ -113,15 +113,18 @@ double diff_from_target(void *target)
|
||||
|
||||
bool checkValid(unsigned char* hash, unsigned char* target) {
|
||||
bool valid = true;
|
||||
unsigned char diff_target[32];
|
||||
memcpy(diff_target, &target, 32);
|
||||
//convert target to little endian for comparison
|
||||
reverse_bytes(diff_target, 32);
|
||||
|
||||
for(uint8_t i=31; i>=0; i--) {
|
||||
if(hash[i] > target[i]) {
|
||||
if(hash[i] > diff_target[i]) {
|
||||
valid = false;
|
||||
break;
|
||||
} else if (hash[i] < target[i]) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MINING
|
||||
if (valid) {
|
||||
Serial.print("\tvalid : ");
|
||||
|
Loading…
Reference in New Issue
Block a user