From 4bda726f38060e2ce839fdfa222d342b32cdcebc Mon Sep 17 00:00:00 2001 From: Skot Date: Sun, 2 Jun 2024 09:06:00 -0400 Subject: [PATCH] update system hashrate on every chip share, not just pool shares. (#196) --- components/bm1397/bm1368.c | 11 +++++------ components/bm1397/include/bm1366.h | 1 + components/bm1397/include/bm1368.h | 2 ++ components/bm1397/include/bm1397.h | 1 + main/global_state.h | 1 + main/main.c | 3 +++ main/system.c | 1 - main/tasks/asic_result_task.c | 7 ++++--- main/tasks/asic_task.c | 4 ++-- 9 files changed, 19 insertions(+), 12 deletions(-) diff --git a/components/bm1397/bm1368.c b/components/bm1397/bm1368.c index 95dd7b1c..2d5575fd 100644 --- a/components/bm1397/bm1368.c +++ b/components/bm1397/bm1368.c @@ -324,8 +324,9 @@ static uint8_t _send_init(uint64_t frequency) _send_simple(init10, 11); //set ticket mask - unsigned char init11[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08}; - _send_simple(init11, 11); + // unsigned char init11[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08}; + // _send_simple(init11, 11); + BM1368_set_job_difficulty_mask(BM1368_INITIAL_DIFFICULTY); //Analog Mux Control unsigned char init12[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D}; @@ -426,11 +427,9 @@ int BM1368_set_max_baud(void) return 1000000; } + void BM1368_set_job_difficulty_mask(int difficulty) { - - return; - // Default mask of 256 diff unsigned char job_difficulty_mask[9] = {0x00, TICKET_MASK, 0b00000000, 0b00000000, 0b00000000, 0b11111111}; @@ -452,7 +451,7 @@ void BM1368_set_job_difficulty_mask(int difficulty) job_difficulty_mask[5 - i] = _reverse_bits(value); } - ESP_LOGI(TAG, "Setting job ASIC mask to %d", difficulty); + ESP_LOGI(TAG, "Setting ASIC difficulty mask to %d", difficulty); _send_BM1368((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, false); } diff --git a/components/bm1397/include/bm1366.h b/components/bm1397/include/bm1366.h index b9cfc429..af61461e 100644 --- a/components/bm1397/include/bm1366.h +++ b/components/bm1397/include/bm1366.h @@ -6,6 +6,7 @@ #include "mining.h" #define CRC5_MASK 0x1F +#define BM1366_INITIAL_DIFFICULTY 256 // static const uint64_t BM1366_FREQUENCY = CONFIG_ASIC_FREQUENCY; static const uint64_t BM1366_CORE_COUNT = 672; diff --git a/components/bm1397/include/bm1368.h b/components/bm1397/include/bm1368.h index da131559..c686c3c9 100644 --- a/components/bm1397/include/bm1368.h +++ b/components/bm1397/include/bm1368.h @@ -7,6 +7,8 @@ #define CRC5_MASK 0x1F +#define BM1368_INITIAL_DIFFICULTY 256 + // static const uint64_t BM1368_FREQUENCY = CONFIG_ASIC_FREQUENCY; static const uint64_t BM1368_CORE_COUNT = 672; // static const uint64_t BM1368_HASHRATE_S = BM1368_FREQUENCY * BM1368_CORE_COUNT * 1000000; diff --git a/components/bm1397/include/bm1397.h b/components/bm1397/include/bm1397.h index 913e821a..fc1a7456 100644 --- a/components/bm1397/include/bm1397.h +++ b/components/bm1397/include/bm1397.h @@ -6,6 +6,7 @@ #include "mining.h" #define CRC5_MASK 0x1F +#define BM1397_INITIAL_DIFFICULTY 256 // static const uint64_t ASIC_FREQUENCY = CONFIG_ASIC_FREQUENCY; static const uint64_t BM1397_CORE_COUNT = 672; diff --git a/main/global_state.h b/main/global_state.h index 5d718e24..e839e0d7 100644 --- a/main/global_state.h +++ b/main/global_state.h @@ -28,6 +28,7 @@ typedef struct char * asic_model; AsicFunctions ASIC_functions; double asic_job_frequency_ms; + uint32_t initial_ASIC_difficulty; work_queue stratum_queue; work_queue ASIC_jobs_queue; diff --git a/main/main.c b/main/main.c index 515cd738..bba669d3 100644 --- a/main/main.c +++ b/main/main.c @@ -37,6 +37,7 @@ void app_main(void) .set_difficulty_mask_fn = BM1366_set_job_difficulty_mask, .send_work_fn = BM1366_send_work}; GLOBAL_STATE.asic_job_frequency_ms = BM1366_FULLSCAN_MS; + GLOBAL_STATE.initial_ASIC_difficulty = BM1366_INITIAL_DIFFICULTY; GLOBAL_STATE.ASIC_functions = ASIC_functions; } else if (strcmp(GLOBAL_STATE.asic_model, "BM1368") == 0) { @@ -49,6 +50,7 @@ void app_main(void) uint64_t bm1368_hashrate = GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1368_CORE_COUNT * 1000000; GLOBAL_STATE.asic_job_frequency_ms = ((double) NONCE_SPACE / (double) bm1368_hashrate) * 1000; + GLOBAL_STATE.initial_ASIC_difficulty = BM1368_INITIAL_DIFFICULTY; GLOBAL_STATE.ASIC_functions = ASIC_functions; } else if (strcmp(GLOBAL_STATE.asic_model, "BM1397") == 0) { @@ -61,6 +63,7 @@ void app_main(void) uint64_t bm1397_hashrate = GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1397_CORE_COUNT * 1000000; GLOBAL_STATE.asic_job_frequency_ms = ((double) NONCE_SPACE / (double) bm1397_hashrate) * 1000; + GLOBAL_STATE.initial_ASIC_difficulty = BM1397_INITIAL_DIFFICULTY; GLOBAL_STATE.ASIC_functions = ASIC_functions; } else { diff --git a/main/system.c b/main/system.c index aaa8d65a..99f0040b 100644 --- a/main/system.c +++ b/main/system.c @@ -432,7 +432,6 @@ void SYSTEM_notify_new_ntime(SystemModule * module, uint32_t ntime) void SYSTEM_notify_found_nonce(SystemModule * module, double pool_diff, double found_diff, uint32_t nbits, float power) { // Calculate the time difference in seconds with sub-second precision - // hashrate = (nonce_difficulty * 2^32) / time_to_find module->historical_hashrate[module->historical_hashrate_rolling_index] = pool_diff; diff --git a/main/tasks/asic_result_task.c b/main/tasks/asic_result_task.c index 4cd5ef31..3f3a012f 100644 --- a/main/tasks/asic_result_task.c +++ b/main/tasks/asic_result_task.c @@ -53,9 +53,10 @@ void ASIC_result_task(void *pvParameters) asic_result->nonce, asic_result->rolled_version ^ GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version); - SYSTEM_notify_found_nonce(&GLOBAL_STATE->SYSTEM_MODULE, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff, - nonce_diff, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->target, - GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power); } + + SYSTEM_notify_found_nonce(&GLOBAL_STATE->SYSTEM_MODULE, GLOBAL_STATE->initial_ASIC_difficulty, + nonce_diff, GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->target, + GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power); } } \ No newline at end of file diff --git a/main/tasks/asic_task.c b/main/tasks/asic_task.c index e859a5e3..2000984d 100644 --- a/main/tasks/asic_task.c +++ b/main/tasks/asic_task.c @@ -34,8 +34,8 @@ void ASIC_task(void *pvParameters) if (next_bm_job->pool_diff != GLOBAL_STATE->stratum_difficulty) { - // ESP_LOGI(TAG, "New difficulty %d", next_bm_job->pool_diff); - (*GLOBAL_STATE->ASIC_functions.set_difficulty_mask_fn)(next_bm_job->pool_diff); + ESP_LOGI(TAG, "New pool difficulty %lu", next_bm_job->pool_diff); + //(*GLOBAL_STATE->ASIC_functions.set_difficulty_mask_fn)(next_bm_job->pool_diff); GLOBAL_STATE->stratum_difficulty = next_bm_job->pool_diff; }