diff options
| author | Adam Soltys <[email protected]> | 2026-09-23 07:31:46 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-23 07:31:46 -0700 |
| commit | bd54987e1f2d708f7e9c5e6e903bcd3c4502b495 (patch) | |
| tree | fd56d999985fdece9628237fd1b1c3ac6036e7f7 /lib/lightning.ts | |
| parent | 1bf4d9c1bb50c35cdd76eb34156c41b45f86c79a (diff) | |
| download | coinos-server-bd54987e1f2d708f7e9c5e6e903bcd3c4502b495.tar.gz coinos-server-bd54987e1f2d708f7e9c5e6e903bcd3c4502b495.zip | |
lightning: don't wedge the listener on an already-credited preimage
Skip settlements whose preimage was already credited instead of retrying
until the process exits, and reject previously used preimages when they
are queued.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Diffstat (limited to 'lib/lightning.ts')
| -rw-r--r-- | lib/lightning.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/lightning.ts b/lib/lightning.ts index 48410ffe..6c37ddf1 100644 --- a/lib/lightning.ts +++ b/lib/lightning.ts @@ -155,9 +155,15 @@ export async function listenForLightning() { }); // credit() may decline a duplicate idempotency claim. Only advance the - // listener once the durable payment pointer proves the ledger write won. - if (!(await getPayment(paymentRequest))) + // listener once the durable payment pointer proves the ledger write won — + // unless the preimage was already credited by an earlier settlement (a + // reused merchant preimage), which can never persist and would otherwise + // wedge the listener in a restart loop. + if (!(await getPayment(paymentRequest))) { + if (preimage && (await db.get(`credited:${preimage}`))) + return warn("preimage already credited, skipping", paymentRequest); throw new Error(`lightning credit did not persist for ${paymentRequest}`); + } })(); // db.set is awaited directly: s() is intentionally fire-and-forget and an |
