Repository navigation
fix: record a refused lightning paykit payment before its cleanup - #1547
Conversation
When the recheck before submission refuses a Lightning payment of a Paykit request, the automatic and manual paths now move the journal entry back to submitted before the proof is cleared and the payment list released. Recovery after a kill in between, or after a failed ledger write, then finds an unsent attempt and records it as failed instead of leaving it open. Verified: unit suite (BitkitTests, CI selection) on an iOS 26.5 simulator, 4740 tests, 0 failures; swiftformat --lint on the changed files
The uncertain-send test now reads the journal when the proof would be cleared, so a guard that journals every failure as unsent fails it, and the manual recovery test seeds a manual ledger attempt. Verified: PaykitAllowanceExecutorTests on an iOS 26.5 simulator, 145 tests, 0 failures; swiftformat --lint
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
QA for 1013dbf: Tested on iPhone 17 simulator, iOS 26.5. 🟢 Unit suite, App starts and recovers on this buildUnit suite The unit suite passes on this commit, including both new recovery tests; the allowance executor tests pass again on 1916bb5, which only tightens tests. App starts and recovers on this build A fresh install creates a wallet, and a kill and relaunch come back to Home with no allowance recovery warnings in the log.
Device tests skipped
|
[Medium impact] The change is limited to Lightning Paykit request payment recovery. The refusal write must be checked before cleanup for this crash fix to be safe to merge. Findings
SummaryThis PR saves a refused Lightning payment as
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Lightning payment refused] --> B[Save submitted stage]
B --> C{Save succeeded?}
C -- Yes --> D[Clear proof]
C -- No, error hidden --> D
D --> E{App stops before failed outcome?}
E -- No --> F[Record failed outcome]
E -- Yes --> G[Recover from saved stage]
G --> H[Old sending or sent stage stays open]
Reviews (1) · Last reviewed commit: "test: check the journal an uncertain lig..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Moves a refused Lightning Paykit payment's journal entry back to submitted before its proof is cleared, on the automatic and the manual path, so recovery after a kill fails it instead of leaving it open. Reviewed 1916bb5, full tier.
What I checked, and 5 candidates I ruled out
Read in full: payLightning and lightningPaymentSettled in PaykitAllowanceExecutor.swift, verifiedOutcome and the recovery loop, setStage / setStageDurably, beginManualPayment / manualLightningPaymentSent, PaykitPaymentProofService.failLightningPayment, SendConfirmationView.sendLightningPayment and its manual caller.
Traced: automatic refusal -> journal .submitted -> recovery's .prepared, .submitted branch asks the node by hash, and .failed, .unknown resolves to .failed. Manual refusal (up front and at the recheck) -> journal moves from .sent to .submitted before failLightningPayment(paymentHash:) -> same recovery branch.
CI: SwiftFormat, validate and Greptile green; unit and integration runs still pending at review time.
Build: Not built: on this track the review reasons from the code and CI, and iOS does not build on Linux.
Ruled out
- The executor and the proof service disagree on "sent nothing":
failLightningPayment(paymentHash:submissionError:)now guards on the same staticsubmissionSentNothing, so the stage is moved back exactly when the cleanup runs. - A settlement already recorded gets overwritten with
.submitted:setStageskips terminal stages, andlightningPaymentSettledstill matches.submitted. .submittedmakes the wallet offer an already-paid request again:hasSentPaymentcounts.sending/.sent/.unknown/.succeededonly, and a refused send left nothing at the node.- Recovery fails a payment the node does know: a hash the node reports
.pendingor.succeededstill wins in the.submittedbranch. - An uncertain error loses its
sendingstage: the guard only fires whensubmissionSentNothingis true, and the updated test pins.sendingfor the uncertain case.
Merge confidence: 4/5, the change is covered by the new PaykitAllowanceExecutorTests cases but CI's unit run had not finished and the branch was not built here.
Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed (the reviewer's run metadata does not carry a reasoning setting)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 1916bb5.
1 actionable finding — resolve or provide an evidence-backed rebuttal.
A kill after the unsent journal save and before the started Lightning proof is deleted closes an automatic refusal and sends its queued acceptance, while the pending list still hides the request. The new tests check the journal stage and the ledger outcome, not a proof left in place.
The resolved comment about a failed journal save was withdrawn. That case keeps the old stage, and retaining the proof would not change it. The finding here is the successful save.
Compared the same ordering on bitkit-android#2176 at 2484af16. That PR also writes submitted before deleting the proof, and its request refresh also omits paymentStarted proofs from the pending list. That was a comparison of this flow only.
Device testing was not performed. The author reports the unit suite and a fresh-install smoke on 1013dbf, and PaykitAllowanceExecutorTests again on 1916bb5. This review did not re-run them.
Suggested additional test cases:
- iOS unit: automatic refusal whose journal is left at
submitted, with the Lightning proof still stored (paymentStarted, payment hash, no preimage) and node lookupunknown. Recover. The proof is removed, the request is not in the in-flight set, and the recorded outcome isfailed.
Findings
- [MEDIUM] Remove the started proof when recovery fails an unsent refusal — inline at
Bitkit/Services/PaykitAllowanceExecutor.swift:1364.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Recovery of a refusal killed between its unsent journal save and the proof cleanup recorded the attempt as failed but kept the proof, which hid the request from the pending list. Recovery now removes the Lightning proof of an attempt the node never saw before it fails it, and leaves the attempt open when the removal cannot be saved. Verified: unit suite (CI selection) on an iOS 26.5 simulator; swiftformat --lint on the changed files
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 1916bb56, including affected code paths, at bcef29a3. Baseline: previous review. Inherited coverage is the manual refusal's journal rewind and the submissionSentNothing split. This pass reassessed recovery's new proof removal.
1 actionable finding — resolve or provide an evidence-backed rebuttal.
Recovery of an unsent Lightning attempt deletes every pending proof with that payment hash. Another request that still holds the same invoice loses its started proof, which is what keeps that request off the pending list and what a later success uses to notify the payee. Limit the removal to the attempt's own request, as bitkit-android#2176 does at 249f54e9. The hash-wide helper is tracked in #1510; this commit adds a launch-time caller.
Compared the recovery proof-removal contract on the Android twin at 249f54e9. Device testing: not performed in this review. The new PaykitAllowanceExecutorTests cases check call order on a mock.
Suggested additional test cases
- iOS unit: two Paykit requests share one Lightning invoice and both have a started proof. One journal entry is
submitted, the other issending, and the node lookup for that hash isunknown. Run allowance recovery. Thesubmittedattempt is recorded failed, and thesendingrequest's proof is still stored.
Earlier findings reconciled at this revision: 1 verified fixed.
Findings
- [MEDIUM] Scope recovery proof removal to the attempt's request — inline at
Bitkit/Services/PaykitAllowanceExecutor.swift:876.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Two Paykit requests can hold started proofs for the same invoice. Recovery's removal matched the payment hash alone, so failing one request's unsent attempt also deleted the other request's proof, which put that request back on the pending list and lost its payee proof. Recovery now removes the proof of the attempt's request and identity. Verified: unit suite (CI selection) on an iOS 26.5 simulator before the test-only tightening, then PaykitAllowanceExecutorTests and PaykitPaymentProofServiceTests; swiftformat --lint on the changed files
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since bcef29a3, including the affected recovery and proof-removal paths, at 19089426. Baseline: previous QA review.
No new actionable code findings.
Recovery removes the Lightning proof for the failed attempt's request and payer identity before it saves the outcome. A removal that cannot be saved leaves the attempt open. Another request's proof of the same invoice, and another identity's proof of the same request, remain. An unsent payment is unknown to the node, so later proof reconciliation leaves that other proof in place.
On bitkit-android#2176 at 249f54e9, recovery also discards only that request's proof before saving the outcome. iOS also matches the payer identity. Inherited from the baseline: the manual Lightning refusal rewinds the journal before proof cleanup, and submissionSentNothing stays separate from proof deletion.
Device testing: not performed in this review. The author's manual checks stay N/A; this follow-up is the proof-selection predicate, and the kill window cannot be staged on a device. PaykitAllowanceExecutorTests.swift and PaykitPaymentProofServiceTests.swift were inspected and not executed here.
Earlier findings reconciled at this revision: 1 verified fixed.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Closes #1522
Twin: synonymdev/bitkit-android#2176
This PR records a refused Lightning Paykit payment as unsent before its proof is cleared, so a crash in between can no longer leave the attempt open.
Description
sending. The journal now moves back tosubmittedfirst, which recovery reads as never sent and records as failed once the node has no payment for the hash.sentduring that cleanup.Out of Scope
Design
N/A — no UI changes.
Preview
N/A — no user-visible changes.
QA Notes
Setup
N/A — the changed window (a kill between the refusal's cleanup and its ledger write) cannot be staged on a device; unit tests cover it.
Journeys
N/A — no user-visible behaviour change.
Manual Tests
N/A
Automated Checks
PaykitAllowanceExecutorTests.swift— a refused automatic payment is journaledsubmittedwhen its proof is cleared; recovery fails a refused manual payment whose outcome was never recorded and removes its proof first; recovery removes the started proof of a refused automatic payment before failing it; recovery leaves a refused payment open when its proof cannot be removedPaykitPaymentProofServiceTests.swift— a failed Lightning payment of one request keeps another request's and another identity's proof of the same invoicePaykitAllowanceExecutorTests.swift— an uncertain send stayssendingwhen the proof would be clearedEvidence
PaykitAllowanceExecutorTestsandPaykitPaymentProofServiceTestsagain on 1908942 after the test-only tightening: 248 tests, 0 failures.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)