Skip to content

Commit

Permalink
add best difficulty since system boot (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoellerDi authored May 24, 2024
1 parent e4fcfdc commit afd4a30
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ <h4>Loading...</h4>
<div class="flex justify-content-between mb-3">
<div>
<span class="block text-500 font-medium mb-3">Best Difficulty</span>
<div class="text-900 font-medium text-xl">{{info.bestDiff}}</div>
<div class="text-900 font-medium text-xl">{{info.bestDiff}}
<span class="text-500">all-time best</span>
</div>
</div>
<div class="flex align-items-center justify-content-center bg-yellow-100 border-round"
[ngStyle]="{width: '2.5rem', height: '2.5rem'}">
<i class="pi pi-star-fill text-yellow-500 text-xl"></i>
</div>
</div>
<span class="text-900 font-medium">{{info.bestSessionDiff}} </span>
<span class="text-500">since system boot</span>
<!-- <span class="text-green-500 font-medium">520 </span>
<span class="text-500">newly registered</span> -->
</div>
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class SystemService {
temp: 60,
hashRate: 475,
bestDiff: "0",
bestSessionDiff: "0",
freeHeap: 200504,
coreVoltage: 1200,
coreVoltageActual: 1200,
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ISystemInfo {
temp: number,
hashRate: number,
bestDiff: string,
bestSessionDiff: string,
freeHeap: number,
coreVoltage: number,
hostname: string,
Expand Down
1 change: 1 addition & 0 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,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));
Expand Down
7 changes: 7 additions & 0 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions main/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit afd4a30

Please sign in to comment.