Merge pull request #103 from golden-guy/bitmaker-dev
Add best diff to miner screen
This commit is contained in:
commit
de655362a7
@ -19,10 +19,12 @@ unsigned long Mhashes = 0;
|
||||
unsigned long totalKHashes = 0;
|
||||
unsigned long elapsedKHs = 0;
|
||||
|
||||
unsigned long halfshares; // increase if blockhash has 16 bits of zeroes
|
||||
unsigned int shares; // increase if blockhash has 32 bits of zeroes
|
||||
unsigned int valids; // increased if blockhash <= target
|
||||
|
||||
// Track best diff
|
||||
double best_diff = 0.0;
|
||||
|
||||
// Variables to hold data from custom textboxes
|
||||
extern char poolString[80];
|
||||
extern int portNumber;
|
||||
@ -308,14 +310,18 @@ void runMiner(void * task_id) {
|
||||
nonce += 2;
|
||||
continue;
|
||||
}
|
||||
halfshares++;
|
||||
|
||||
|
||||
//Check target to submit
|
||||
//Difficulty of 1 > 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
//NM2 pool diff 1e-9 > Target = diff_1 / diff_pool > 0x00003B9ACA00....00
|
||||
//Swapping diff bytes little endian >>>>>>>>>>>>>>>> 0x0000DC59D300....00
|
||||
//if((hash[29] <= 0xDC) && (hash[28] <= 0x59)) //0x00003B9ACA00 > diff value for 1e-9
|
||||
double diff_hash = diff_from_target(hash);
|
||||
|
||||
// update best diff
|
||||
if (diff_hash > best_diff)
|
||||
best_diff = diff_hash;
|
||||
|
||||
if(diff_hash > mMiner.poolDifficulty)//(hash[29] <= 0x3B)//(diff_hash > 1e-9)
|
||||
{
|
||||
tx_mining_submit(client, mWorker, mJob, nonce);
|
||||
@ -344,16 +350,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
|
||||
|
@ -19,9 +19,10 @@ extern unsigned long Mhashes;
|
||||
extern unsigned long totalKHashes;
|
||||
extern unsigned long elapsedKHs;
|
||||
|
||||
extern unsigned long halfshares; // increase if blockhash has 16 bits of zeroes
|
||||
extern unsigned int shares; // increase if blockhash has 32 bits of zeroes
|
||||
extern unsigned int valids; // increased if blockhash <= targethalfshares
|
||||
extern unsigned int valids; // increased if blockhash <= target
|
||||
|
||||
extern double best_diff; // track best diff
|
||||
|
||||
extern OpenFontRender render;
|
||||
extern TFT_eSprite background;
|
||||
@ -243,9 +244,11 @@ void show_MinerScreen(unsigned long mElapsed){
|
||||
//Block templates
|
||||
render.setFontSize(36);
|
||||
render.drawString(String(templates).c_str(), 186, 20, 0xDEDB);
|
||||
//16Bit shares
|
||||
//Best diff
|
||||
char best_diff_string[8] = {0};
|
||||
sprintf(best_diff_string, "%.4f", best_diff);
|
||||
render.setFontSize(36);
|
||||
render.drawString(String(halfshares).c_str(), 186, 48, 0xDEDB);
|
||||
render.drawString(String(best_diff_string).c_str(), 186, 48, 0xDEDB);
|
||||
//32Bit shares
|
||||
render.setFontSize(36);
|
||||
render.drawString(String(shares).c_str(), 186, 76, 0xDEDB);
|
||||
|
@ -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