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