Checking pool difficulty

This commit is contained in:
BitMaker 2023-05-28 22:58:23 +02:00
parent a8b95f29c3
commit 98d5faefa9
4 changed files with 13 additions and 15 deletions

View File

@ -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]);

View File

@ -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;

View File

@ -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);

View File

@ -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;