Nonce starting point + fix halving blocks

- Added different nonce start point for each thread
- Fixed halving block calculation
- Added firmware version on initial screen
This commit is contained in:
BitMaker 2023-07-11 00:25:23 +02:00
parent 2adfede605
commit 54ace9455d
4 changed files with 43 additions and 28 deletions

View File

@ -10,11 +10,14 @@
#include "mbedtls/md.h" #include "mbedtls/md.h"
#include "media/images.h" #include "media/images.h"
#include "media/myFonts.h" #include "media/myFonts.h"
#include "media/Free_Fonts.h"
#include "OpenFontRender.h" #include "OpenFontRender.h"
#include "wManager.h" #include "wManager.h"
#include "mining.h" #include "mining.h"
#include "monitor.h" #include "monitor.h"
#define CURRENT_VERSION "V1.5.2"
//3 seconds WDT //3 seconds WDT
#define WDT_TIMEOUT 3 #define WDT_TIMEOUT 3
OneButton button1(PIN_BUTTON_1); OneButton button1(PIN_BUTTON_1);
@ -98,7 +101,8 @@ void setup()
/******** PRINT INIT SCREEN *****/ /******** PRINT INIT SCREEN *****/
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
tft.pushImage(0, 0, initWidth, initHeight, initScreen); tft.pushImage(0, 0, initWidth, initHeight, initScreen);
tft.setTextColor(TFT_BLACK);
tft.drawString(CURRENT_VERSION, 24, 130, FONT2);
delay(2000); delay(2000);
/******** INIT WIFI ************/ /******** INIT WIFI ************/
@ -134,7 +138,7 @@ void setup()
// Start mining tasks // Start mining tasks
//BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL); //BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL);
xTaskCreate(runMiner, "Miner0", 15000, NULL, 1, NULL); xTaskCreate(runMiner, "Miner0", 15000, NULL, 1, NULL);
//xTaskCreate(runMiner, "Miner1", 15000, NULL, 1, NULL); xTaskCreate(runMiner, "Miner1", 15000, NULL, 1, NULL);
/******** MONITOR SETUP *****/ /******** MONITOR SETUP *****/
setup_monitor(); setup_monitor();

View File

@ -181,9 +181,9 @@ void runStratumWorker(void *name) {
case MINING_NOTIFY: if(parse_mining_notify(line, mJob)){ case MINING_NOTIFY: if(parse_mining_notify(line, mJob)){
//Increse templates readed //Increse templates readed
templates++; templates++;
//Stop miner current job //Stop miner current jobs
mMiner.inRun = false; mMiner.inRun = false;
//Prepare data for new job //Prepare data for new jobs
mMiner=calculateMiningData(mWorker,mJob); mMiner=calculateMiningData(mWorker,mJob);
mMiner.poolDifficulty = currentPoolDifficulty; mMiner.poolDifficulty = currentPoolDifficulty;
mMiner.newJob = true; mMiner.newJob = true;
@ -215,6 +215,8 @@ void runStratumWorker(void *name) {
#include "shaTests/customSHA256.h" #include "shaTests/customSHA256.h"
#include "mbedtls/sha256.h" #include "mbedtls/sha256.h"
void runMiner(void * name){ void runMiner(void * name){
unsigned long nonce;
unsigned long max_nonce;
while(1){ while(1){
@ -223,9 +225,18 @@ void runMiner(void * name){
if(mMiner.newJob==true || mMiner.newJob2==true) break; if(mMiner.newJob==true || mMiner.newJob2==true) break;
vTaskDelay(100 / portTICK_PERIOD_MS); //Small delay vTaskDelay(100 / portTICK_PERIOD_MS); //Small delay
} }
vTaskDelay(10 / portTICK_PERIOD_MS); //Small delay to join both mining threads
if(mMiner.newJob) mMiner.newJob = false; //Clear newJob flag if(mMiner.newJob) {
else if(mMiner.newJob2) mMiner.newJob2 = false; //Clear newJob flag mMiner.newJob = false; //Clear newJob flag
nonce = 0;
max_nonce = MAX_NONCE;
}
else if(mMiner.newJob2){
mMiner.newJob2 = false; //Clear newJob flag
nonce = TARGET_NONCE - MAX_NONCE;
max_nonce = TARGET_NONCE;
}
mMiner.inRun = true; //Set inRun flag mMiner.inRun = true; //Set inRun flag
//Prepare Premining data //Prepare Premining data
@ -248,12 +259,11 @@ void runMiner(void * name){
Serial.println(""); Serial.println("");
*/ */
// search a valid nonce // search a valid nonce
unsigned long nonce = TARGET_NONCE - MAX_NONCE;
uint32_t startT = micros(); uint32_t startT = micros();
unsigned char *header64 = mMiner.bytearray_blockheader + 64; unsigned char *header64 = mMiner.bytearray_blockheader + 64;
Serial.println(">>> STARTING TO HASH NONCES"); Serial.println(">>> STARTING TO HASH NONCES");
while(true) { while(true) {
//memcpy(mMiner.bytearray_blockheader + 76, &nonce, 4); memcpy(mMiner.bytearray_blockheader + 76, &nonce, 4);
//Con midstate //Con midstate
// Primer SHA-256 // Primer SHA-256
@ -274,7 +284,7 @@ void runMiner(void * name){
Serial.println(""); */ Serial.println(""); */
hashes++; hashes++;
if (nonce++> TARGET_NONCE) break; //exit if (nonce++> max_nonce) break; //exit
if(!mMiner.inRun) { Serial.println ("MINER WORK ABORTED >> waiting new job"); break;} if(!mMiner.inRun) { Serial.println ("MINER WORK ABORTED >> waiting new job"); break;}
// check if 16bit share // check if 16bit share

View File

@ -80,13 +80,12 @@ void updateGlobalData(void){
} }
http.end(); http.end();
//Make second API call to get remaining Blocks
//OLD code gets remaining blocks to next difficulty ajustment
/*//Make second API call to get remaining Blocks
http.begin(getDifficulty); http.begin(getDifficulty);
httpCode = http.GET(); httpCode = http.GET();
//TODO -> current data is giving new difficulty event
// -> add halving table and calculate blocks to next event
// -> calculate percentage to nearest event
if (httpCode > 0) { if (httpCode > 0) {
String payload = http.getString(); String payload = http.getString();
@ -101,7 +100,7 @@ void updateGlobalData(void){
mGlobalUpdate = millis(); mGlobalUpdate = millis();
} }
http.end(); http.end();*/
//Make third API call to get fees //Make third API call to get fees
http.begin(getFees); http.begin(getFees);
@ -252,20 +251,16 @@ void show_MinerScreen(unsigned long mElapsed){
render.drawString(String(shares).c_str(), 186, 76, 0xDEDB); render.drawString(String(shares).c_str(), 186, 76, 0xDEDB);
//Hores //Hores
char timeMining[15]; char timeMining[15];
unsigned long secElapsed = millis() / 1000; unsigned long secElapsed = millis() / 1000;
int days = secElapsed / 86400; int days = secElapsed / 86400;
int hours = (secElapsed - (days * 86400)) / 3600; //Number of seconds in an hour int hours = (secElapsed - (days * 86400)) / 3600; //Number of seconds in an hour
int mins = (secElapsed - (days * 86400) - (hours * 3600)) / 60; //Remove the number of hours and calculate the minutes. int mins = (secElapsed - (days * 86400) - (hours * 3600)) / 60; //Remove the number of hours and calculate the minutes.
int secs = secElapsed - (days * 86400) - (hours * 3600) - (mins * 60); int secs = secElapsed - (days * 86400) - (hours * 3600) - (mins * 60);
sprintf(timeMining, "%01d,%02d:%02d:%02d", days, hours, mins, secs); sprintf(timeMining, "%01d %02d:%02d:%02d", days, hours, mins, secs);
render.setFontSize(33); render.setFontSize(27);
render.rdrawString(String(timeMining).c_str(), 315, 102, 0xDEDB); render.rdrawString(String(timeMining).c_str(), 315, 104, 0xDEDB);
//Minutss
//render.setFontSize(36);
//render.rdrawString(String(mins).c_str(), 253, 99, 0xDEDB);
//Segons
//render.setFontSize(36);
//render.rdrawString(String(sec).c_str(), 298, 99, 0xDEDB);
//Valid Blocks //Valid Blocks
render.setFontSize(48); render.setFontSize(48);
render.drawString(String(valids).c_str(), 285, 56, 0xDEDB); render.drawString(String(valids).c_str(), 285, 56, 0xDEDB);
@ -283,10 +278,10 @@ void show_MinerScreen(unsigned long mElapsed){
render.rdrawString(getTime().c_str(), 286, 1, TFT_BLACK); render.rdrawString(getTime().c_str(), 286, 1, TFT_BLACK);
// pool url // pool url
background.setTextSize(1); /*background.setTextSize(1);
background.setTextDatum(MC_DATUM); background.setTextDatum(MC_DATUM);
background.setTextColor(0xDEDB); background.setTextColor(0xDEDB);
background.drawString(String(poolString), 59, 85, FONT2); background.drawString(String(poolString), 59, 85, FONT2);*/
//Push prepared background to screen //Push prepared background to screen
background.pushSprite(0,0); background.pushSprite(0,0);
@ -390,10 +385,14 @@ void show_GlobalHashScreen(unsigned long mElapsed){
//Print BlockHeight //Print BlockHeight
render.setFontSize(55); render.setFontSize(55);
render.rdrawString(getBlockHeight().c_str(), 140, 104, 0xDEDB); gData.currentBlock = getBlockHeight();
render.rdrawString(gData.currentBlock.c_str(), 140, 104, 0xDEDB);
//Draw percentage rectangle //Draw percentage rectangle
//width percent bar 140 - 2 //width percent bar 140 - 2
unsigned long cBlock = gData.currentBlock.toInt();
gData.remainingBlocks = (((cBlock / HALVING_BLOCKS)+1) * HALVING_BLOCKS) - cBlock;
gData.progressPercent = (HALVING_BLOCKS-gData.remainingBlocks)*100/HALVING_BLOCKS;
int x2 = 2 + (138*gData.progressPercent/100); int x2 = 2 + (138*gData.progressPercent/100);
background.fillRect(2, 149, x2, 168, 0xDEDB); background.fillRect(2, 149, x2, 168, 0xDEDB);

View File

@ -25,6 +25,8 @@
#define getFees "https://mempool.space/api/v1/fees/recommended" #define getFees "https://mempool.space/api/v1/fees/recommended"
#define UPDATE_Global_min 2 #define UPDATE_Global_min 2
#define NEXT_HALVING_EVENT 840000
#define HALVING_BLOCKS 210000
typedef struct{ typedef struct{
uint8_t screen; uint8_t screen;
@ -33,7 +35,7 @@ typedef struct{
typedef struct{ typedef struct{
String globalHash; //hexahashes String globalHash; //hexahashes
String lastBlock; String currentBlock;
String difficulty; String difficulty;
String blocksHalving; String blocksHalving;
float progressPercent; float progressPercent;