aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-23 07:31:46 -0700
committerAdam Soltys <[email protected]>2026-09-23 07:31:46 -0700
commitbd54987e1f2d708f7e9c5e6e903bcd3c4502b495 (patch)
treefd56d999985fdece9628237fd1b1c3ac6036e7f7 /routes
parent1bf4d9c1bb50c35cdd76eb34156c41b45f86c79a (diff)
downloadcoinos-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 'routes')
-rw-r--r--routes/preimages.ts7
1 files changed, 7 insertions, 0 deletions
diff --git a/routes/preimages.ts b/routes/preimages.ts
index 49673d17..5e7c484f 100644
--- a/routes/preimages.ts
+++ b/routes/preimages.ts
@@ -51,6 +51,13 @@ export default {
for (let p of preimages) {
p = p.toLowerCase();
if (seen.has(p)) continue;
+ // A preimage that already settled (or backs a live invoice) can't be
+ // credited again — reject it rather than let a buyer pay for nothing.
+ if (
+ (await db.exists(`credited:${p}`)) ||
+ (await db.exists(`preimage:${sha256(p)}`))
+ )
+ fail("preimage already used");
seen.add(p);
fresh.push(p);
}