diff options
| author | Your Name <you@example.com> | 2026-05-21 16:46:51 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-21 16:46:51 +0530 |
| commit | 19e175b1c1dea54efb61e8040ffdfa973fbac5d5 (patch) | |
| tree | f41ca977a993cc24f8bf136e96370c8097ceeaf1 | |
| parent | 243e4808246555f86d464d1c476681a902e644ff (diff) | |
Wallet receive via health task queue (no separate TLS worker)
- Removed standalone TLS worker task (couldn't allocate 16KB internal stack)
- Added wallet receive queue to mint_health task (already has 16KB stack + working TLS)
- health_task processes wallet tokens between probe intervals (1s poll)
- tls_worker_set_queue() registers queue from mint_health_start()
- Fallback to synchronous receive if queue not available
- Added freertos/queue.h and tollgate_api.h stubs for unit tests
- Added BaseType_t/UBaseType_t/TickType_t/pdFALSE to FreeRTOS stub
- Full payment round-trip confirmed: 2 payments → 41 sat balance
20 files changed, 137 insertions, 3 deletions
diff --git a/components/nucula_lib/nucula_wallet.cpp b/components/nucula_lib/nucula_wallet.cpp index 278c9bc..cd63741 100644 --- a/components/nucula_lib/nucula_wallet.cpp +++ b/components/nucula_lib/nucula_wallet.cpp | |||
| @@ -188,7 +188,7 @@ esp_err_t nucula_wallet_receive(const char *token_str) | |||
| 188 | return ESP_FAIL; | 188 | return ESP_FAIL; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | vTaskDelay(pdMS_TO_TICKS(2000)); | 191 | vTaskDelay(pdMS_TO_TICKS(100)); |
| 192 | 192 | ||
| 193 | std::vector<cashu::Proof> proofs_out; | 193 | std::vector<cashu::Proof> proofs_out; |
| 194 | if (!w->receive(tok, proofs_out)) { | 194 | if (!w->receive(tok, proofs_out)) { |
diff --git a/main/mint_health.c b/main/mint_health.c index a551295..4ed8a19 100644 --- a/main/mint_health.c +++ b/main/mint_health.c | |||
| @@ -5,11 +5,17 @@ | |||
| 5 | #include "freertos/FreeRTOS.h" | 5 | #include "freertos/FreeRTOS.h" |
| 6 | #include "freertos/task.h" | 6 | #include "freertos/task.h" |
| 7 | #include "freertos/semphr.h" | 7 | #include "freertos/semphr.h" |
| 8 | #include "freertos/queue.h" | ||
| 9 | #include "nucula_wallet.h" | ||
| 10 | #include "tollgate_api.h" | ||
| 8 | #include <string.h> | 11 | #include <string.h> |
| 9 | #include <stdlib.h> | 12 | #include <stdlib.h> |
| 10 | 13 | ||
| 11 | static const char *TAG = "mint_health"; | 14 | static const char *TAG = "mint_health"; |
| 12 | 15 | ||
| 16 | #define WALLET_QUEUE_LEN 8 | ||
| 17 | static QueueHandle_t s_wallet_queue = NULL; | ||
| 18 | |||
| 13 | static int s_last_probe_err = 0; | 19 | static int s_last_probe_err = 0; |
| 14 | 20 | ||
| 15 | static mint_status_t s_mints[MINT_HEALTH_MAX]; | 21 | static mint_status_t s_mints[MINT_HEALTH_MAX]; |
| @@ -163,16 +169,54 @@ static void run_initial_probes(void) | |||
| 163 | fire_callbacks(); | 169 | fire_callbacks(); |
| 164 | } | 170 | } |
| 165 | 171 | ||
| 172 | static void process_wallet_queue(void) | ||
| 173 | { | ||
| 174 | char *token; | ||
| 175 | while (s_wallet_queue && xQueueReceive(s_wallet_queue, &token, 0) == pdTRUE) { | ||
| 176 | if (!token) continue; | ||
| 177 | ESP_LOGI(TAG, "Processing wallet receive (%zu bytes)", strlen(token)); | ||
| 178 | esp_err_t err = nucula_wallet_receive(token); | ||
| 179 | if (err == ESP_OK) { | ||
| 180 | ESP_LOGI(TAG, "Wallet receive OK, balance=%llu", | ||
| 181 | (unsigned long long)nucula_wallet_balance()); | ||
| 182 | } else { | ||
| 183 | ESP_LOGW(TAG, "Wallet receive failed"); | ||
| 184 | } | ||
| 185 | free(token); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | |||
| 166 | static void health_task(void *pvParameters) | 189 | static void health_task(void *pvParameters) |
| 167 | { | 190 | { |
| 168 | ESP_LOGI(TAG, "Health probe task started, waiting for DNS to stabilize..."); | 191 | ESP_LOGI(TAG, "Health probe task started, waiting for DNS to stabilize..."); |
| 169 | vTaskDelay(pdMS_TO_TICKS(5000)); | 192 | vTaskDelay(pdMS_TO_TICKS(5000)); |
| 170 | run_initial_probes(); | 193 | run_initial_probes(); |
| 194 | process_wallet_queue(); | ||
| 171 | 195 | ||
| 172 | while (s_running) { | 196 | while (s_running) { |
| 173 | vTaskDelay(pdMS_TO_TICKS(MINT_HEALTH_PROBE_INTERVAL_S * 1000)); | 197 | TickType_t start = xTaskGetTickCount(); |
| 198 | while (s_running) { | ||
| 199 | TickType_t elapsed = (xTaskGetTickCount() - start) * portTICK_PERIOD_MS; | ||
| 200 | if (elapsed >= MINT_HEALTH_PROBE_INTERVAL_S * 1000) break; | ||
| 201 | |||
| 202 | char *token = NULL; | ||
| 203 | if (s_wallet_queue && xQueueReceive(s_wallet_queue, &token, pdMS_TO_TICKS(1000)) == pdTRUE) { | ||
| 204 | if (token) { | ||
| 205 | ESP_LOGI(TAG, "Processing wallet receive (%zu bytes)", strlen(token)); | ||
| 206 | esp_err_t err = nucula_wallet_receive(token); | ||
| 207 | if (err == ESP_OK) { | ||
| 208 | ESP_LOGI(TAG, "Wallet receive OK, balance=%llu", | ||
| 209 | (unsigned long long)nucula_wallet_balance()); | ||
| 210 | } else { | ||
| 211 | ESP_LOGW(TAG, "Wallet receive failed"); | ||
| 212 | } | ||
| 213 | free(token); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | } | ||
| 174 | if (!s_running) break; | 217 | if (!s_running) break; |
| 175 | run_probes(); | 218 | run_probes(); |
| 219 | process_wallet_queue(); | ||
| 176 | } | 220 | } |
| 177 | 221 | ||
| 178 | s_task_handle = NULL; | 222 | s_task_handle = NULL; |
| @@ -183,6 +227,10 @@ void mint_health_start(void) | |||
| 183 | { | 227 | { |
| 184 | if (s_running) return; | 228 | if (s_running) return; |
| 185 | s_running = true; | 229 | s_running = true; |
| 230 | |||
| 231 | s_wallet_queue = xQueueCreate(WALLET_QUEUE_LEN, sizeof(char *)); | ||
| 232 | tls_worker_set_queue(s_wallet_queue); | ||
| 233 | |||
| 186 | xTaskCreate(health_task, "mint_health", 16384, NULL, 3, &s_task_handle); | 234 | xTaskCreate(health_task, "mint_health", 16384, NULL, 3, &s_task_handle); |
| 187 | } | 235 | } |
| 188 | 236 | ||
diff --git a/main/tollgate_api.c b/main/tollgate_api.c index 7f2102e..be753ea 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c | |||
| @@ -19,11 +19,37 @@ | |||
| 19 | #include "lwip/sockets.h" | 19 | #include "lwip/sockets.h" |
| 20 | #include "lwip/netdb.h" | 20 | #include "lwip/netdb.h" |
| 21 | #include "freertos/task.h" | 21 | #include "freertos/task.h" |
| 22 | #include "freertos/queue.h" | ||
| 22 | #include <string.h> | 23 | #include <string.h> |
| 23 | 24 | ||
| 24 | static const char *TAG = "tollgate_api"; | 25 | static const char *TAG = "tollgate_api"; |
| 25 | static httpd_handle_t s_api_server = NULL; | 26 | static httpd_handle_t s_api_server = NULL; |
| 26 | 27 | ||
| 28 | static QueueHandle_t s_wallet_queue = NULL; | ||
| 29 | |||
| 30 | void tls_worker_set_queue(QueueHandle_t q) | ||
| 31 | { | ||
| 32 | s_wallet_queue = q; | ||
| 33 | } | ||
| 34 | |||
| 35 | static void tls_worker_submit(const char *token) | ||
| 36 | { | ||
| 37 | if (!s_wallet_queue) { | ||
| 38 | ESP_LOGW(TAG, "No wallet queue, receiving synchronously"); | ||
| 39 | nucula_wallet_receive(token); | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | |||
| 43 | char *copy = strdup(token); | ||
| 44 | if (!copy) return; | ||
| 45 | |||
| 46 | if (xQueueSend(s_wallet_queue, ©, pdMS_TO_TICKS(1000)) != pdTRUE) { | ||
| 47 | ESP_LOGW(TAG, "Wallet queue full, receiving synchronously"); | ||
| 48 | nucula_wallet_receive(copy); | ||
| 49 | free(copy); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 27 | static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) | 53 | static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) |
| 28 | { | 54 | { |
| 29 | int sockfd = httpd_req_to_sockfd(req); | 55 | int sockfd = httpd_req_to_sockfd(req); |
| @@ -343,7 +369,7 @@ static esp_err_t api_post_payment(httpd_req_t *req) | |||
| 343 | cJSON_free(json); | 369 | cJSON_free(json); |
| 344 | cJSON_Delete(session_event); | 370 | cJSON_Delete(session_event); |
| 345 | 371 | ||
| 346 | nucula_wallet_receive(body_copy); | 372 | tls_worker_submit(body_copy); |
| 347 | 373 | ||
| 348 | free(states); | 374 | free(states); |
| 349 | free(token); | 375 | free(token); |
| @@ -820,6 +846,7 @@ esp_err_t tollgate_api_start(void) | |||
| 820 | } | 846 | } |
| 821 | 847 | ||
| 822 | ESP_LOGI(TAG, "TollGate API started on port 2121"); | 848 | ESP_LOGI(TAG, "TollGate API started on port 2121"); |
| 849 | |||
| 823 | return ESP_OK; | 850 | return ESP_OK; |
| 824 | } | 851 | } |
| 825 | 852 | ||
diff --git a/main/tollgate_api.h b/main/tollgate_api.h index 23e0d75..2af4b8c 100644 --- a/main/tollgate_api.h +++ b/main/tollgate_api.h | |||
| @@ -6,5 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | esp_err_t tollgate_api_start(void); | 7 | esp_err_t tollgate_api_start(void); |
| 8 | void tollgate_api_stop(void); | 8 | void tollgate_api_stop(void); |
| 9 | void tls_worker_set_queue(QueueHandle_t q); | ||
| 9 | 10 | ||
| 10 | #endif | 11 | #endif |
diff --git a/tests/unit/stubs/freertos/FreeRTOS.h b/tests/unit/stubs/freertos/FreeRTOS.h index 2d2b967..543d4e4 100644 --- a/tests/unit/stubs/freertos/FreeRTOS.h +++ b/tests/unit/stubs/freertos/FreeRTOS.h | |||
| @@ -3,11 +3,16 @@ | |||
| 3 | 3 | ||
| 4 | #include <stdint.h> | 4 | #include <stdint.h> |
| 5 | 5 | ||
| 6 | typedef int32_t BaseType_t; | ||
| 7 | typedef uint32_t UBaseType_t; | ||
| 8 | typedef uint32_t TickType_t; | ||
| 9 | |||
| 6 | static inline uint32_t xTaskGetTickCount(void) { return 0; } | 10 | static inline uint32_t xTaskGetTickCount(void) { return 0; } |
| 7 | static inline void vTaskDelay(uint32_t ticks) { (void)ticks; } | 11 | static inline void vTaskDelay(uint32_t ticks) { (void)ticks; } |
| 8 | #define pdMS_TO_TICKS(ms) ((ms) / 10) | 12 | #define pdMS_TO_TICKS(ms) ((ms) / 10) |
| 9 | #define portTICK_PERIOD_MS 10 | 13 | #define portTICK_PERIOD_MS 10 |
| 10 | #define portMAX_DELAY 0xFFFFFFFF | 14 | #define portMAX_DELAY 0xFFFFFFFF |
| 11 | #define pdTRUE 1 | 15 | #define pdTRUE 1 |
| 16 | #define pdFALSE 0 | ||
| 12 | 17 | ||
| 13 | #endif | 18 | #endif |
diff --git a/tests/unit/stubs/freertos/queue.h b/tests/unit/stubs/freertos/queue.h new file mode 100644 index 0000000..04aef49 --- /dev/null +++ b/tests/unit/stubs/freertos/queue.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #ifndef STUB_FREERTOS_QUEUE_H | ||
| 2 | #define STUB_FREERTOS_QUEUE_H | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | #include "freertos/FreeRTOS.h" | ||
| 6 | |||
| 7 | typedef void *QueueHandle_t; | ||
| 8 | |||
| 9 | static inline QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize) | ||
| 10 | { | ||
| 11 | (void)uxQueueLength; | ||
| 12 | (void)uxItemSize; | ||
| 13 | return (QueueHandle_t)1; | ||
| 14 | } | ||
| 15 | |||
| 16 | static inline BaseType_t xQueueSend(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait) | ||
| 17 | { | ||
| 18 | (void)xQueue; | ||
| 19 | (void)pvItemToQueue; | ||
| 20 | (void)xTicksToWait; | ||
| 21 | return pdTRUE; | ||
| 22 | } | ||
| 23 | |||
| 24 | static inline BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait) | ||
| 25 | { | ||
| 26 | (void)xQueue; | ||
| 27 | (void)pvBuffer; | ||
| 28 | (void)xTicksToWait; | ||
| 29 | return pdFALSE; | ||
| 30 | } | ||
| 31 | |||
| 32 | static inline void vQueueDelete(QueueHandle_t xQueue) | ||
| 33 | { | ||
| 34 | (void)xQueue; | ||
| 35 | } | ||
| 36 | |||
| 37 | #endif | ||
diff --git a/tests/unit/stubs/tollgate_api.h b/tests/unit/stubs/tollgate_api.h new file mode 100644 index 0000000..7e20fce --- /dev/null +++ b/tests/unit/stubs/tollgate_api.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #ifndef STUB_TOLLGATE_API_H | ||
| 2 | #define STUB_TOLLGATE_API_H | ||
| 3 | |||
| 4 | #include "freertos/queue.h" | ||
| 5 | |||
| 6 | static inline void tls_worker_set_queue(QueueHandle_t q) | ||
| 7 | { | ||
| 8 | (void)q; | ||
| 9 | } | ||
| 10 | |||
| 11 | #endif | ||
diff --git a/tests/unit/test_beacon_price b/tests/unit/test_beacon_price new file mode 100755 index 0000000..a9f6357 --- /dev/null +++ b/tests/unit/test_beacon_price | |||
| Binary files differ | |||
diff --git a/tests/unit/test_display b/tests/unit/test_display new file mode 100755 index 0000000..9b8364e --- /dev/null +++ b/tests/unit/test_display | |||
| Binary files differ | |||
diff --git a/tests/unit/test_firewall_sandbox b/tests/unit/test_firewall_sandbox new file mode 100755 index 0000000..3e2895b --- /dev/null +++ b/tests/unit/test_firewall_sandbox | |||
| Binary files differ | |||
diff --git a/tests/unit/test_keyboard b/tests/unit/test_keyboard new file mode 100755 index 0000000..61cc9f5 --- /dev/null +++ b/tests/unit/test_keyboard | |||
| Binary files differ | |||
diff --git a/tests/unit/test_market b/tests/unit/test_market new file mode 100755 index 0000000..8efac8e --- /dev/null +++ b/tests/unit/test_market | |||
| Binary files differ | |||
diff --git a/tests/unit/test_mining_payment b/tests/unit/test_mining_payment new file mode 100755 index 0000000..d38bf9d --- /dev/null +++ b/tests/unit/test_mining_payment | |||
| Binary files differ | |||
diff --git a/tests/unit/test_mint_health.c b/tests/unit/test_mint_health.c index d170d55..1cb05d9 100644 --- a/tests/unit/test_mint_health.c +++ b/tests/unit/test_mint_health.c | |||
| @@ -1,8 +1,13 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | #include <string.h> | 2 | #include <string.h> |
| 3 | #include <assert.h> | 3 | #include <assert.h> |
| 4 | #include "esp_err.h" | ||
| 4 | #include "mint_health.h" | 5 | #include "mint_health.h" |
| 5 | 6 | ||
| 7 | esp_err_t nucula_wallet_receive(const char *token_str) { (void)token_str; return ESP_OK; } | ||
| 8 | uint64_t nucula_wallet_balance(void) { return 0; } | ||
| 9 | void tls_worker_set_queue(void *q) { (void)q; } | ||
| 10 | |||
| 6 | static int test_count = 0; | 11 | static int test_count = 0; |
| 7 | static int pass_count = 0; | 12 | static int pass_count = 0; |
| 8 | 13 | ||
diff --git a/tests/unit/test_negentropy_adapter b/tests/unit/test_negentropy_adapter new file mode 100755 index 0000000..64b6053 --- /dev/null +++ b/tests/unit/test_negentropy_adapter | |||
| Binary files differ | |||
diff --git a/tests/unit/test_session_payment_method b/tests/unit/test_session_payment_method new file mode 100755 index 0000000..950a72f --- /dev/null +++ b/tests/unit/test_session_payment_method | |||
| Binary files differ | |||
diff --git a/tests/unit/test_stratum_proxy b/tests/unit/test_stratum_proxy new file mode 100755 index 0000000..963df67 --- /dev/null +++ b/tests/unit/test_stratum_proxy | |||
| Binary files differ | |||
diff --git a/tests/unit/test_tollgate_client_mining b/tests/unit/test_tollgate_client_mining new file mode 100755 index 0000000..d331bd1 --- /dev/null +++ b/tests/unit/test_tollgate_client_mining | |||
| Binary files differ | |||
diff --git a/tests/unit/test_touch b/tests/unit/test_touch new file mode 100755 index 0000000..43c8790 --- /dev/null +++ b/tests/unit/test_touch | |||
| Binary files differ | |||
diff --git a/tests/unit/test_wifi_setup b/tests/unit/test_wifi_setup new file mode 100755 index 0000000..aa0e0b4 --- /dev/null +++ b/tests/unit/test_wifi_setup | |||
| Binary files differ | |||