upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/tollgate_api.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-21 15:44:46 +0530
committerYour Name <you@example.com>2026-05-21 15:44:46 +0530
commit243e4808246555f86d464d1c476681a902e644ff (patch)
tree4334ebf0f8c2e2ee7f5ebccb93dedd68a2e95b18 /main/tollgate_api.c
parent46d9c97e11ea0b03a7dc03fdef6bd360cbe53d44 (diff)
feat(wallet): lazy keyset loading with exponential backoff + jitter
- Remove eager load_keysets() from init_wallet(), load on first use - Add ensure_keysets() with binary exponential backoff + random jitter - Guard all wallet operations (receive, send, melt, swap_all) with ensure_keysets() - Skip checkstate on TLS failure, let wallet swap verify proofs instead - Pin HTTP server to core 0 (fixes TLS cert verification in checkstate) - Rewrite nucula http.c to use manual open/write/read (same as working health probe) - Disable hardware MPI (CONFIG_MBEDTLS_HARDWARE_MPI=n) - Add http.h stub for unit tests Known issue: progressive TLS failure after 2-3 connections (PK verify 0x4290), wallet receive swap fails. Needs deeper mbedTLS/PSRAM investigation.
Diffstat (limited to 'main/tollgate_api.c')
-rw-r--r--main/tollgate_api.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/main/tollgate_api.c b/main/tollgate_api.c
index 80fe6ed..7f2102e 100644
--- a/main/tollgate_api.c
+++ b/main/tollgate_api.c
@@ -280,16 +280,8 @@ static esp_err_t api_post_payment(httpd_req_t *req)
280 err = cashu_check_proof_states(mint_url, token, states, &state_count); 280 err = cashu_check_proof_states(mint_url, token, states, &state_count);
281 ESP_LOGI(TAG, "Stack HWM after checkstate: %u", uxTaskGetStackHighWaterMark(NULL)); 281 ESP_LOGI(TAG, "Stack HWM after checkstate: %u", uxTaskGetStackHighWaterMark(NULL));
282 if (err != ESP_OK) { 282 if (err != ESP_OK) {
283 free(states); 283 ESP_LOGW(TAG, "Checkstate failed, proceeding without spend check (wallet swap will verify)");
284 free(token); 284 state_count = 0;
285 cJSON *notice = create_notice("error", "payment-error-verification", "Failed to verify token with mint");
286 char *json = cJSON_PrintUnformatted(notice);
287 httpd_resp_set_status(req, "502 Bad Gateway");
288 httpd_resp_set_type(req, "application/json");
289 httpd_resp_send(req, json, strlen(json));
290 cJSON_free(json);
291 cJSON_Delete(notice);
292 return ESP_OK;
293 } 285 }
294 286
295 for (int i = 0; i < state_count; i++) { 287 for (int i = 0; i < state_count; i++) {
@@ -795,11 +787,12 @@ esp_err_t tollgate_api_start(void)
795{ 787{
796 if (s_api_server) return ESP_OK; 788 if (s_api_server) return ESP_OK;
797 789
798 httpd_config_t config = HTTPD_DEFAULT_CONFIG(); 790 httpd_config_t config = HTTPD_DEFAULT_CONFIG();
799 config.server_port = 2121; 791 config.server_port = 2121;
800 config.ctrl_port = 32769; 792 config.ctrl_port = 32769;
801 config.max_uri_handlers = 16; 793 config.max_uri_handlers = 16;
802 config.stack_size = 16384; 794 config.stack_size = 16384;
795 config.core_id = 0;
803 796
804 esp_err_t ret = httpd_start(&s_api_server, &config); 797 esp_err_t ret = httpd_start(&s_api_server, &config);
805 if (ret != ESP_OK) { 798 if (ret != ESP_OK) {