From f15715f3f34d26774ecae4c7705f21f6e309c053 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 20 Jul 2023 12:50:35 +0200 Subject: [PATCH] Use double precision for pool difficulty --- src/mining.cpp | 2 +- src/mining.h | 4 ++-- src/stratum.cpp | 10 +++++----- src/stratum.h | 4 ++-- src/utils.cpp | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index 656eea1..5e208c3 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -111,7 +111,7 @@ void runStratumWorker(void *name) { // connect to pool - float currentPoolDifficulty = atof(DEFAULT_DIFFICULTY); + double currentPoolDifficulty = DEFAULT_DIFFICULTY; while(true) { diff --git a/src/mining.h b/src/mining.h index 742b3e6..6a4c8f8 100644 --- a/src/mining.h +++ b/src/mining.h @@ -5,7 +5,7 @@ // Mining #define MAX_NONCE 5000000U #define TARGET_NONCE 471136297U -#define DEFAULT_DIFFICULTY "1e-9" +#define DEFAULT_DIFFICULTY 1e-9 #define KEEPALIVE_TIME_ms 30000 #define POOLINACTIVITY_TIME_ms 60000 @@ -21,7 +21,7 @@ typedef struct{ uint8_t bytearray_pooltarget[32]; uint8_t merkle_result[32]; uint8_t bytearray_blockheader[80]; - float poolDifficulty; + double poolDifficulty; bool inRun; bool newJob; bool newJob2; diff --git a/src/stratum.cpp b/src/stratum.cpp index dacaaaf..a3c9a0e 100644 --- a/src/stratum.cpp +++ b/src/stratum.cpp @@ -216,7 +216,7 @@ bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job m return true; } -bool parse_mining_set_difficulty(String line, float& difficulty) +bool parse_mining_set_difficulty(String line, double& difficulty) { Serial.println(" Parsing Method [SET DIFFICULTY]"); if(!verifyPayload(&line)) return false; @@ -226,8 +226,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((float)doc["params"][0],12); - difficulty = (float)doc["params"][0]; + Serial.print(" difficulty: "); Serial.println((double)doc["params"][0],12); + difficulty = (double)doc["params"][0]; #ifdef DEBUG_MINING Serial.print(" job_id: "); Serial.println(job_id); @@ -236,12 +236,12 @@ bool parse_mining_set_difficulty(String line, float& difficulty) return true; } -bool tx_suggest_difficulty(WiFiClient& client, const char * difficulty) +bool tx_suggest_difficulty(WiFiClient& client, double difficulty) { char payload[BUFFER] = {0}; id = getNextId(id); - sprintf(payload, "{\"id\": %d, \"method\": \"mining.suggest_difficulty\", \"params\": [%s]}\n", id, difficulty); + sprintf(payload, "{\"id\": %d, \"method\": \"mining.suggest_difficulty\", \"params\": [%.10g]}\n", id, difficulty); Serial.print(" Sending : "); Serial.print(payload); return client.print(payload); diff --git a/src/stratum.h b/src/stratum.h index cdd47b3..44f65de 100644 --- a/src/stratum.h +++ b/src/stratum.h @@ -62,8 +62,8 @@ bool parse_mining_notify(String line, mining_job& mJob); bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce); //Difficulty Methods -bool tx_suggest_difficulty(WiFiClient& client, const char * difficulty); -bool parse_mining_set_difficulty(String line, float& difficulty); +bool tx_suggest_difficulty(WiFiClient& client, double difficulty); +bool parse_mining_set_difficulty(String line, double& difficulty); #endif // STRATUM_API_H \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 3050dc8..f7e95ab 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -155,7 +155,7 @@ miner_data init_miner_data(void){ miner_data newMinerData; - newMinerData.poolDifficulty = atof(DEFAULT_DIFFICULTY); + newMinerData.poolDifficulty = DEFAULT_DIFFICULTY; newMinerData.inRun = false; newMinerData.newJob = false;