diff options
| author | Adam Soltys <[email protected]> | 2026-03-19 23:51:57 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-03-19 23:51:57 -0700 |
| commit | 7f1be926fc1acc41776b7ba6f97b762b4586d8d1 (patch) | |
| tree | d258e8c5afb847c382f70c6689842f69138fc02e | |
| parent | 42a90f201d03aa96d004e6c3cf3f37f5afd8d1ee (diff) | |
| download | coinos-server-7f1be926fc1acc41776b7ba6f97b762b4586d8d1.tar.gz coinos-server-7f1be926fc1acc41776b7ba6f97b762b4586d8d1.zip | |
ensure lightning payments get processed
| -rw-r--r-- | index.ts | 3 | ||||
| -rw-r--r-- | lib/lightning.ts | 9 |
2 files changed, 11 insertions, 1 deletions
@@ -1,7 +1,7 @@ import app from "$lib/app"; import { admin, auth, optional } from "$lib/auth"; -import { fixBolt12, listenForLightning, replay } from "$lib/lightning"; +import { fixBolt12, listenForLightning, ensureListenerAlive, replay } from "$lib/lightning"; import { startHealthCheck } from "$lib/health"; import { getLocations } from "$lib/locations"; import nwc from "$lib/nwc"; @@ -33,6 +33,7 @@ try { } catch (e) {} setTimeout(listenForLightning, 2000); +setInterval(ensureListenerAlive, 120000); setInterval(sendHeartbeat, 2000); app.get("/balances", info.balances); diff --git a/lib/lightning.ts b/lib/lightning.ts index 764ce627..0de5aa6b 100644 --- a/lib/lightning.ts +++ b/lib/lightning.ts @@ -10,6 +10,7 @@ const LISTENER_RETRY_DELAY = 5000; // 5 seconds const MAX_LISTENER_RETRIES = 10; let listenerRetries = 0; let listenerActive = false; +let lastPayTime = Date.now(); export async function listenForLightning() { if (listenerActive) { @@ -36,6 +37,7 @@ export async function listenForLightning() { } = inv; await s("pay_index", pay_index); + lastPayTime = Date.now(); // Reset retry counter on successful receive if (listenerRetries > 0) { @@ -119,6 +121,13 @@ export async function listenForLightning() { } } +export function ensureListenerAlive() { + if (!listenerActive) { + warn("lightning listener: not active, restarting"); + listenForLightning(); + } +} + export async function replay(index) { const inv = await lnListen.waitanyinvoice(index - 1); const { |
