From 98d5faefa948a20b2267797e82403c123d72f23b Mon Sep 17 00:00:00 2001 From: BitMaker Date: Sun, 28 May 2023 22:58:23 +0200 Subject: [PATCH] Checking pool difficulty --- src/mining.cpp | 20 +++++++++----------- src/mining.h | 2 +- src/stratum.cpp | 4 ++-- src/utils.cpp | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index d5a3e67..39b7ad3 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -50,6 +50,7 @@ void runStratumWorker(void *name) { // connect to pool IPAddress serverIP(1, 1, 1, 1); //Temporally save poolIPaddres + float currentPoolDifficulty = atof(DEFAULT_DIFFICULTY); bool isMinerSuscribed = false; @@ -61,11 +62,10 @@ void runStratumWorker(void *name) { } //Test vars: - strcpy(poolString, "rr"); - portNumber = 3333; + strcpy(poolString, "rr"); + portNumber = 3002; strcpy(btcString,"rr"); - portNumber = 3002; if (!client.connected()) { isMinerSuscribed = false; Serial.println("Client not connected, trying to connect..."); @@ -118,17 +118,14 @@ void runStratumWorker(void *name) { mMiner.inRun = false; //Prepare data for new job mMiner=calculateMiningData(mWorker,mJob); + mMiner.poolDifficulty = currentPoolDifficulty; mMiner.newJob = true; //Give new job to miner } break; - case MINING_SET_DIFFICULTY: if(parse_mining_set_difficulty(line, mMiner.difficulty)){ - //Calculate new target - //TODO - //Give new target to workers - //TODO - } + case MINING_SET_DIFFICULTY: parse_mining_set_difficulty(line, currentPoolDifficulty); + mMiner.poolDifficulty = currentPoolDifficulty; break; default: Serial.println(" Parsed JSON: unknown"); break; @@ -205,10 +202,11 @@ void runMiner(void * name){ //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); - if(hash[29] <= 0x3B)//(diff_hash > 1e-9) + if(diff_hash > mMiner.poolDifficulty)//(hash[29] <= 0x3B)//(diff_hash > 1e-9) { tx_mining_submit(client, mWorker, mJob, nonce); - Serial.print(" - Current diff share: "); Serial.println(diff_hash); + Serial.print(" - Current diff share: "); Serial.println(diff_hash,12); + Serial.print(" - Current pool diff : "); Serial.println(mMiner.poolDifficulty,12); Serial.print(" - TX SHARE: "); for (size_t i = 0; i < 32; i++) Serial.printf("%02x", hash[i]); diff --git a/src/mining.h b/src/mining.h index dfbb339..2080dff 100644 --- a/src/mining.h +++ b/src/mining.h @@ -19,7 +19,7 @@ typedef struct{ uint8_t bytearray_pooltarget[32]; uint8_t merkle_result[32]; uint8_t bytearray_blockheader[80]; - float difficulty; + float poolDifficulty; bool inRun; bool newJob; }miner_data; diff --git a/src/stratum.cpp b/src/stratum.cpp index 3143210..628ea7a 100644 --- a/src/stratum.cpp +++ b/src/stratum.cpp @@ -227,8 +227,8 @@ bool parse_mining_set_difficulty(String line, float& difficulty) if (error) return false; if (!doc.containsKey("params")) return false; - Serial.print(" difficulty: "); Serial.println((const char *)doc["params"][0]); - //difficulty = (float) doc["params"][0]; + Serial.print(" difficulty: "); Serial.println((float)doc["params"][0],12); + difficulty = (float)doc["params"][0]; #ifdef DEBUG_MINING Serial.print(" job_id: "); Serial.println(job_id); diff --git a/src/utils.cpp b/src/utils.cpp index 4775362..3050dc8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -155,7 +155,7 @@ miner_data init_miner_data(void){ miner_data newMinerData; - newMinerData.difficulty = atof(DEFAULT_DIFFICULTY); + newMinerData.poolDifficulty = atof(DEFAULT_DIFFICULTY); newMinerData.inRun = false; newMinerData.newJob = false;