From 674ef21ed4bdad320edfd6122c8bb3c8cb05ccf8 Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 13 Apr 2024 09:54:22 +0000 Subject: [PATCH] add best difficulty since system boot --- .../axe-os/src/app/components/home/home.component.html | 6 +++++- main/http_server/axe-os/src/app/services/system.service.ts | 1 + main/http_server/axe-os/src/models/ISystemInfo.ts | 1 + main/http_server/http_server.c | 1 + main/system.c | 7 +++++++ main/system.h | 2 ++ 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/main/http_server/axe-os/src/app/components/home/home.component.html b/main/http_server/axe-os/src/app/components/home/home.component.html index 310b3dda4..b53a3beb7 100644 --- a/main/http_server/axe-os/src/app/components/home/home.component.html +++ b/main/http_server/axe-os/src/app/components/home/home.component.html @@ -68,13 +68,17 @@

Loading...

Best Difficulty -
{{info.bestDiff}}
+
{{info.bestDiff}} + all-time best +
+ {{info.bestSessionDiff}} + since system boot diff --git a/main/http_server/axe-os/src/app/services/system.service.ts b/main/http_server/axe-os/src/app/services/system.service.ts index 616a90825..67c1f0b15 100644 --- a/main/http_server/axe-os/src/app/services/system.service.ts +++ b/main/http_server/axe-os/src/app/services/system.service.ts @@ -28,6 +28,7 @@ export class SystemService { temp: 60, hashRate: 475, bestDiff: "0", + bestSessionDiff: "0", freeHeap: 200504, coreVoltage: 1200, coreVoltageActual: 1200, diff --git a/main/http_server/axe-os/src/models/ISystemInfo.ts b/main/http_server/axe-os/src/models/ISystemInfo.ts index dde010848..f8b1b86b9 100644 --- a/main/http_server/axe-os/src/models/ISystemInfo.ts +++ b/main/http_server/axe-os/src/models/ISystemInfo.ts @@ -11,6 +11,7 @@ export interface ISystemInfo { temp: number, hashRate: number, bestDiff: string, + bestSessionDiff: string, freeHeap: number, coreVoltage: number, ssid: string, diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index c01e1d852..f1c25b8ee 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -348,6 +348,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "temp", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.chip_temp); cJSON_AddNumberToObject(root, "hashRate", GLOBAL_STATE->SYSTEM_MODULE.current_hashrate); cJSON_AddStringToObject(root, "bestDiff", GLOBAL_STATE->SYSTEM_MODULE.best_diff_string); + cJSON_AddStringToObject(root, "bestSessionDiff", GLOBAL_STATE->SYSTEM_MODULE.best_session_diff_string); cJSON_AddNumberToObject(root, "freeHeap", esp_get_free_heap_size()); cJSON_AddNumberToObject(root, "coreVoltage", nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE)); diff --git a/main/system.c b/main/system.c index 0c4abe811..b938578a2 100644 --- a/main/system.c +++ b/main/system.c @@ -44,6 +44,7 @@ static void _init_system(GlobalState * global_state, SystemModule * module) module->shares_accepted = 0; module->shares_rejected = 0; module->best_nonce_diff = nvs_config_get_u64(NVS_CONFIG_BEST_DIFF, 0); + module->best_session_nonce_diff = 0; module->start_time = esp_timer_get_time(); module->lastClockSync = 0; module->FOUND_BLOCK = false; @@ -57,6 +58,7 @@ static void _init_system(GlobalState * global_state, SystemModule * module) // set the best diff string _suffix_string(module->best_nonce_diff, module->best_diff_string, DIFF_STRING_SIZE, 0); + _suffix_string(module->best_session_nonce_diff, module->best_session_diff_string, DIFF_STRING_SIZE, 0); // set the ssid string to blank memset(module->ssid, 0, 20); @@ -269,6 +271,11 @@ static double _calculate_network_difficulty(uint32_t nBits) static void _check_for_best_diff(SystemModule * module, double diff, uint32_t nbits) { + if ((uint64_t) diff > module->best_session_nonce_diff) { + module->best_session_nonce_diff = (uint64_t) diff; + _suffix_string((uint64_t) diff, module->best_session_diff_string, DIFF_STRING_SIZE, 0); + } + if ((uint64_t) diff <= module->best_nonce_diff) { return; } diff --git a/main/system.h b/main/system.h index 13d4ae252..1373ad54d 100644 --- a/main/system.h +++ b/main/system.h @@ -23,6 +23,8 @@ typedef struct char oled_buf[20]; uint64_t best_nonce_diff; char best_diff_string[DIFF_STRING_SIZE]; + uint64_t best_session_nonce_diff; + char best_session_diff_string[DIFF_STRING_SIZE]; bool FOUND_BLOCK; bool startup_done; char ssid[20];