Repository navigation
Hold session k1 and reject invoice replay on ndebits - #1028
Merged
Merged
Conversation
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>
This was referenced 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
marked this pull request as ready for review
September 7, 2026 15:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
k1so two wallets cannot both claim one ATM QR. Hold starts when Pub accepts a valid direct-payment21002. Deny or confirmed Lightning fail releases it; a new invoice may reusek1. Lightning success stays consumed forever. Only released rows are pruned (24h).21002on a held or succeededk1is GFY 6k1_already_processed.bolt11that is in-flight, already paid, or already failed is GFY 6 with the matchingreasontoken.clink_versiontag still count as v1. Explicit"2"and mixed1+2are rejected (21002 gets GFY).${databaseFile}.instance.lockfor 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 ifexecthrows. Commit failure propagates without a secondEndTx(false).k1is 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.jsonstill points atfile:../ClinkSDKfor development and is not in this PR.Spec: shocknet/CLINK#19
Test plan
npx tsc --noEmit— passinstanceLock.spec.ts— memory skip, live second process rejected,kill -9then reacquire, exactly one concurrent owner