Fix checkValid function
Diff target needs to be converted to little endian for comparison.
This commit is contained in:
parent
df99eea69d
commit
22737824a5
@ -340,16 +340,12 @@ void runMiner(void * task_id) {
|
|||||||
}
|
}
|
||||||
shares++;
|
shares++;
|
||||||
|
|
||||||
// check if valid header
|
// check if valid header
|
||||||
if(checkValid(hash, mMiner.bytearray_target)){
|
if(checkValid(hash, mMiner.bytearray_target)){
|
||||||
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