Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add best difficulty since system boot #162

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
ssid: 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 @@ -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));
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
Loading