From 669b13189180ea40f73e7202052f04039cfc9dac Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 25 Apr 2026 09:21:14 -0700 Subject: check listpays before reversing --- index.ts | 4 ++-- lib/payments.ts | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 5a3f172b..78c43598 100644 --- a/index.ts +++ b/index.ts @@ -34,7 +34,7 @@ try { setTimeout(listenForLightning, 2000); setInterval(ensureListenerAlive, 120000); -setInterval(sendHeartbeat, 2000); +setInterval(sendHeartbeat, 5000); app.get("/balances", info.balances); app.get("/health", info.health); @@ -46,7 +46,7 @@ app.get("/rates", rates.index); app.get("/locations", locations.list); -app.get("/invoice/:id", invoices.get); +app.get("/invoice/:id", { config: { rateLimit: { max: 30, timeWindow: 10000, keyGenerator: (req) => { const ip = (req.headers["cf-connecting-ip"] as string) || req.ip; const token = (req.headers.authorization || "").slice(0, 50); return token ? `invoice:${token}` : `invoice:${ip}`; } } } }, invoices.get); app.get("/invoices", auth, invoices.list); app.post("/invoice", optional, invoices.create); app.post("/invoice/:id", optional, invoices.update); diff --git a/lib/payments.ts b/lib/payments.ts index 71d6c990..5d823b4d 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -597,7 +597,16 @@ export const sendLightning = async ({ } } catch (e) { err("failed to pay", pr.substr(-8)); - try { await reverse(p); } catch (_) {} + try { + const { pays } = await ln.listpays(pr); + const completed = pays.find((p) => p.status === "complete"); + if (completed) { + warn("payment completed despite error, finalizing", p.id); + try { await finalize(completed, p); } catch (_) {} + } else { + await reverse(p); + } + } catch (_) {} throw e; } @@ -780,7 +789,7 @@ export const catchUp = async () => { err("problem syncing", e.message); } - setTimeout(catchUp, 10000); + setTimeout(catchUp, 30000); }; export const check = async () => { @@ -814,7 +823,7 @@ export const check = async () => { err("payment check failed", e.message); } - setTimeout(check, 2000); + setTimeout(check, 5000); }; const finalize = async (r, p) => { -- cgit v1.2.3