From 3aa372ccc3e11c837458b00088ffb6cbe99ff6ca Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 May 2026 04:12:32 +0530 Subject: fix: merge readiness — display_enabled config, real pubkey, probe interval, dedup services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add display_enabled config field (default true, parsed from config.json) - Guard display_init/display_update behind display_enabled check - Fix discovery pubkey: replace hardcoded all-zeros with identity_get()->npub_hex - Revert MINT_HEALTH_PROBE_INTERVAL_S from 30 (testing) to 300 (production) - Remove duplicate services_start_task call in IP event handler - Fix UTF-8 arrow in STA auth threshold log message - Gitignore compiled test binaries (test_mcp_handler, test_mint_health, etc.) - Remove tracked test binaries from git Verified on Board B (stable): - make test-discovery-b: pubkey=d6bfe100..., metric=milliseconds, price_per_step tags - make test-mints-b: 4 mints listed with reachable field - Wallet: 40 sats balance with 4 proofs from previous payment - All API endpoints responding (discovery, mints, wallet, whoami, portal) - 75/75 unit tests passing --- .gitignore | 7 +++++++ main/config.c | 6 +++++- main/config.h | 1 + main/mint_health.h | 2 +- main/tollgate_api.c | 9 ++++----- main/tollgate_main.c | 20 ++++++++++++++------ tests/unit/test_cvm_server | Bin 45728 -> 0 bytes tests/unit/test_lightning_payout | Bin 20560 -> 0 bytes tests/unit/test_lnurl_pay | Bin 21312 -> 0 bytes tests/unit/test_mcp_handler | Bin 63056 -> 0 bytes tests/unit/test_mint_health | Bin 36792 -> 0 bytes tests/unit/test_nip04 | Bin 298792 -> 0 bytes tests/unit/test_tollgate_client | Bin 52072 -> 0 bytes 13 files changed, 32 insertions(+), 13 deletions(-) delete mode 100755 tests/unit/test_cvm_server delete mode 100755 tests/unit/test_lightning_payout delete mode 100755 tests/unit/test_lnurl_pay delete mode 100755 tests/unit/test_mcp_handler delete mode 100755 tests/unit/test_mint_health delete mode 100755 tests/unit/test_nip04 delete mode 100755 tests/unit/test_tollgate_client diff --git a/.gitignore b/.gitignore index b2f1400..80cd5ed 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,11 @@ tests/unit/test_identity tests/unit/test_nostr_event tests/unit/test_cashu tests/unit/test_session +tests/unit/test_mcp_handler +tests/unit/test_mint_health +tests/unit/test_tollgate_client +tests/unit/test_cvm_server +tests/unit/test_lnurl_pay +tests/unit/test_lightning_payout +tests/unit/test_nip04 interop/routers.env diff --git a/main/config.c b/main/config.c index fe0ceba..22b26da 100644 --- a/main/config.c +++ b/main/config.c @@ -36,6 +36,7 @@ esp_err_t tollgate_config_init(void) g_config.cvm_enabled = true; strncpy(g_config.cvm_relays, "wss://relay.primal.net", sizeof(g_config.cvm_relays) - 1); strncpy(g_config.wifi_auth_mode, "WPA2", sizeof(g_config.wifi_auth_mode) - 1); + g_config.display_enabled = true; esp_vfs_spiffs_conf_t conf = { .base_path = "/spiffs", @@ -278,6 +279,9 @@ esp_err_t tollgate_config_init(void) strncpy(g_config.wifi_auth_mode, auth_mode->valuestring, sizeof(g_config.wifi_auth_mode) - 1); } + cJSON *disp_en = cJSON_GetObjectItem(root, "display_enabled"); + if (disp_en && cJSON_IsBool(disp_en)) g_config.display_enabled = cJSON_IsTrue(disp_en); + if (g_config.payout.mint_count == 0 && g_config.mint_url[0] != '\0') { strncpy(g_config.payout.mints[0].url, g_config.mint_url, sizeof(g_config.payout.mints[0].url) - 1); @@ -331,7 +335,7 @@ esp_err_t tollgate_config_get_wifi(wifi_config_t *wifi_config) } else if (strstr(g_config.wifi_auth_mode, "WPA2")) { wifi_config->sta.threshold.authmode = WIFI_AUTH_WPA2_PSK; } - ESP_LOGI(TAG, "STA auth threshold: %s → %d", g_config.wifi_auth_mode, wifi_config->sta.threshold.authmode); + ESP_LOGI(TAG, "STA auth threshold: %s -> %d", g_config.wifi_auth_mode, wifi_config->sta.threshold.authmode); return ESP_OK; } diff --git a/main/config.h b/main/config.h index 1a32cc2..18dfc66 100644 --- a/main/config.h +++ b/main/config.h @@ -67,6 +67,7 @@ typedef struct { char cvm_relays[256]; char wifi_auth_mode[16]; + bool display_enabled; } tollgate_config_t; void tollgate_config_derive_unique(tollgate_config_t *cfg); diff --git a/main/mint_health.h b/main/mint_health.h index 4e9a5a7..f047d6a 100644 --- a/main/mint_health.h +++ b/main/mint_health.h @@ -6,7 +6,7 @@ #include #define MINT_HEALTH_MAX 8 -#define MINT_HEALTH_PROBE_INTERVAL_S 30 +#define MINT_HEALTH_PROBE_INTERVAL_S 300 #define MINT_HEALTH_PROBE_TIMEOUT_MS 15000 #define MINT_HEALTH_RECOVERY_THRESHOLD 3 diff --git a/main/tollgate_api.c b/main/tollgate_api.c index 997dd09..0120003 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c @@ -1,6 +1,7 @@ #include "tollgate_api.h" #include "cashu.h" #include "config.h" +#include "identity.h" #include "session.h" #include "firewall.h" #include "nucula_wallet.h" @@ -16,8 +17,6 @@ static const char *TAG = "tollgate_api"; static httpd_handle_t s_api_server = NULL; -static const char *TOLLGATE_PUBKEY = "0000000000000000000000000000000000000000000000000000000000000000"; - static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) { int sockfd = httpd_req_to_sockfd(req); @@ -34,7 +33,7 @@ static cJSON *create_notice(const char *level, const char *code, const char *con { cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "kind", 21023); - cJSON_AddStringToObject(root, "pubkey", TOLLGATE_PUBKEY); + cJSON_AddStringToObject(root, "pubkey", identity_get()->npub_hex); cJSON *tags = cJSON_CreateArray(); cJSON *level_tag = cJSON_CreateArray(); cJSON_AddItemToArray(level_tag, cJSON_CreateString("level")); @@ -53,7 +52,7 @@ static cJSON *create_session_event(uint32_t client_ip, uint64_t allotment_ms) { cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "kind", 1022); - cJSON_AddStringToObject(root, "pubkey", TOLLGATE_PUBKEY); + cJSON_AddStringToObject(root, "pubkey", identity_get()->npub_hex); cJSON *tags = cJSON_CreateArray(); @@ -95,7 +94,7 @@ static esp_err_t api_get_discovery(httpd_req_t *req) cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "kind", 10021); - cJSON_AddStringToObject(root, "pubkey", TOLLGATE_PUBKEY); + cJSON_AddStringToObject(root, "pubkey", identity_get()->npub_hex); cJSON *tags = cJSON_CreateArray(); diff --git a/main/tollgate_main.c b/main/tollgate_main.c index e81ba7b..15791a3 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c @@ -108,8 +108,6 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base, char gw_ip_str[16]; snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw)); tollgate_client_on_sta_connected(gw_ip_str); - - xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP) { ESP_LOGW(TAG, "Lost IP address"); xEventGroupClearBits(s_wifi_event_group, WIFI_CONNECTED_BIT); @@ -178,6 +176,13 @@ static void start_services(void) s_services_running = true; if (s_services_mutex) xSemaphoreGive(s_services_mutex); ESP_LOGI(TAG, "=== TollGate services started ==="); + + if (cfg->display_enabled) { + display_set_state(DISPLAY_READY); + char portal_url[128]; + snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); + display_update(cfg->ap_ssid, 0, 0, portal_url); + } } static void stop_services(void) @@ -259,9 +264,6 @@ void app_main(void) { ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); - ESP_LOGW(TAG, "Display disabled for stability testing"); - - esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); @@ -271,7 +273,13 @@ void app_main(void) ESP_ERROR_CHECK(tollgate_config_init()); - ESP_ERROR_CHECK(identity_init(tollgate_config_get()->nsec)); + const tollgate_config_t *init_cfg = tollgate_config_get(); + if (init_cfg->display_enabled) { + display_init(); + display_set_state(DISPLAY_BOOT); + } + + ESP_ERROR_CHECK(identity_init(init_cfg->nsec)); tollgate_config_derive_unique((tollgate_config_t *)tollgate_config_get()); diff --git a/tests/unit/test_cvm_server b/tests/unit/test_cvm_server deleted file mode 100755 index 8f0b605..0000000 Binary files a/tests/unit/test_cvm_server and /dev/null differ diff --git a/tests/unit/test_lightning_payout b/tests/unit/test_lightning_payout deleted file mode 100755 index c6aaa5f..0000000 Binary files a/tests/unit/test_lightning_payout and /dev/null differ diff --git a/tests/unit/test_lnurl_pay b/tests/unit/test_lnurl_pay deleted file mode 100755 index 61c9743..0000000 Binary files a/tests/unit/test_lnurl_pay and /dev/null differ diff --git a/tests/unit/test_mcp_handler b/tests/unit/test_mcp_handler deleted file mode 100755 index a001641..0000000 Binary files a/tests/unit/test_mcp_handler and /dev/null differ diff --git a/tests/unit/test_mint_health b/tests/unit/test_mint_health deleted file mode 100755 index 2a48ad2..0000000 Binary files a/tests/unit/test_mint_health and /dev/null differ diff --git a/tests/unit/test_nip04 b/tests/unit/test_nip04 deleted file mode 100755 index cbf4c80..0000000 Binary files a/tests/unit/test_nip04 and /dev/null differ diff --git a/tests/unit/test_tollgate_client b/tests/unit/test_tollgate_client deleted file mode 100755 index 8077223..0000000 Binary files a/tests/unit/test_tollgate_client and /dev/null differ -- cgit v1.2.3