From 9d7d03442121270ab8d4c97f45083855c21e8720 Mon Sep 17 00:00:00 2001 From: Skot Croshere Date: Mon, 5 Jun 2023 00:03:07 -0400 Subject: [PATCH] added the difficulty_changed flag to clear the queue on the next mining.notify after a pool difficulty change. --- main/miner.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main/miner.c b/main/miner.c index 08295b5d..4557a06f 100755 --- a/main/miner.c +++ b/main/miner.c @@ -50,6 +50,7 @@ static int sock; static int abandon_work = 0; static uint32_t stratum_difficulty = 8192; +static bool difficulty_changed = false; bm_job ** active_jobs; uint8_t * valid_jobs; @@ -299,8 +300,15 @@ static void stratum_task(void * pvParameters) stratum_method method = parse_stratum_method(line); if (method == MINING_NOTIFY) { - if (should_abandon_work(line) && stratum_queue.count > 0) { - ESP_LOGI(TAG, "Should abandon work, clearing queues"); + if ((difficulty_changed || should_abandon_work(line)) && stratum_queue.count > 0) { + + if (difficulty_changed) { + ESP_LOGI(TAG, "pool diff changed, clearing queues"); + difficulty_changed = false; + } else { + ESP_LOGI(TAG, "clean_jobs is true, clearing queues"); + } + abandon_work = 1; queue_clear(&stratum_queue); @@ -317,9 +325,13 @@ static void stratum_task(void * pvParameters) } queue_enqueue(&stratum_queue, line); } else if (method == MINING_SET_DIFFICULTY) { - stratum_difficulty = parse_mining_set_difficulty_message(line); - ESP_LOGI(TAG, "Set stratum difficulty: %d", stratum_difficulty); - set_job_difficulty_mask(stratum_difficulty); + uint32_t new_difficulty = parse_mining_set_difficulty_message(line); + if (new_difficulty != stratum_difficulty) { + stratum_difficulty = new_difficulty; + difficulty_changed = true; + ESP_LOGI(TAG, "Set stratum difficulty: %d", stratum_difficulty); + set_job_difficulty_mask(stratum_difficulty); + } } else if (method == MINING_SET_VERSION_MASK) { version_mask = parse_mining_set_version_mask_message(line);