Skip to content

Hold session k1 and reject invoice replay on ndebits - #1028

Merged
shocknet-justin merged 3 commits into
dash2from
debit-gfy-6-invoice-conflicts
Sep 21, 2026
Merged

shocknet-justin merged 3 commits into
dash2from
debit-gfy-6-invoice-conflicts

Conversation

@shocknet-justin

@shocknet-justin shocknet-justin commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Persist session k1 so two wallets cannot both claim one ATM QR. Hold starts when Pub accepts a valid direct-payment 21002. Deny or confirmed Lightning fail releases it; a new invoice may reuse k1. Lightning success stays consumed forever. Only released rows are pruned (24h).
  • ATM yes is authorization. A later yes after a no still pays. Pub does not second-guess ATM commands. A second customer 21002 on a held or succeeded k1 is GFY 6 k1_already_processed.
  • Replay of a bolt11 that is in-flight, already paid, or already failed is GFY 6 with the matching reason token.
  • Inbound CLINK events with no clink_version tag still count as v1. Explicit "2" and mixed 1+2 are rejected (21002 gets GFY).
  • Exclusive SQLite lock on ${databaseFile}.instance.lock for process lifetime so two Pubs cannot open the same file DB. A leftover directory from the old mkdir lock is removed unless it has a parseable live PID.
  • Tx() only rolls back if exec throws. Commit failure propagates without a second EndTx(false).

k1 is a correlator, not an auth token. Pointer-less ndebits still GFY 1 (existing TODO: debit from app owner balance).

Depends on unpublished ClinkSDK 1.7.4 (shocknet/ClinkSDK#27). Local package.json still points at file:../ClinkSDK for development and is not in this PR.

Spec: shocknet/CLINK#19

Test plan

  • npx tsc --noEmit — pass
  • instanceLock.spec.ts — memory skip, live second process rejected, kill -9 then reacquire, exactly one concurrent owner

shocknet-justin and others added 2 commits August 26, 2026 11:12
Duplicate customer 21002s and invoice replay get GFY 6. An exclusive instance lock stops two Pubs from opening the same DB. Commit failure no longer issues a rollback EndTx.

Co-authored-by: Cursor <cursoragent@cursor.com>
@shocknet-justin shocknet-justin changed the title better clink errors Hold session k1 and reject invoice replay on ndebits Aug 31, 2026
const serviceFee = this.getSendServiceFee(Types.UserOperationType.OUTGOING_INVOICE, payAmount, isManagedUser)
await this.assertInvoiceDbConflict(req.invoice)
const internalInvoice = await this.storage.paymentStorage.GetInvoiceOwner(req.invoice)
let paymentInfo = { preimage: "", amtPaid: 0, networkFee: 0, serialId: 0 }
@shocknet-justin
shocknet-justin marked this pull request as ready for review September 7, 2026 15:30
@boufni95
boufni95 changed the base branch from master to dash2 September 11, 2026 16:19
@shocknet-justin
shocknet-justin merged commit ed9b878 into dash2 Sep 21, 2026
3 of 4 checks passed
@shocknet-justin
shocknet-justin deleted the debit-gfy-6-invoice-conflicts branch October 13, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants