Repository navigation
fix: record a refused lightning paykit payment before its cleanup - #2176
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: ./gradlew testDevDebugUnitTest for PaykitAllowanceExecutorTest, PaykitPaymentProofRepoTest, PaykitAllowancePayerTest and AppViewModelSendFlowTest; ./gradlew detekt
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. |
Verified: none (changelog fragment only)
[Medium impact] The change affects refused Lightning Paykit payments in allowance workflows. Fix the refusal writes before merging so cleanup cannot proceed after a failed save. Findings
SummaryRecords refused Lightning payments as
Scope acknowledgment: Reviews (1) · Last reviewed commit: "chore: add changelog fragment" · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Twin of synonymdev/bitkit-ios#1547: a refused Lightning Paykit payment is journaled SUBMITTED before its proof is cleared, on the automatic path and in AppViewModel's manual send, so recovery fails it after a kill. Reviewed 2484af1, full tier.
What I checked, and 4 candidates I ruled out
Read in full: the automatic Lightning send in PaykitAllowanceExecutor.kt (associateLightningPayment through the SENT update), journalOutcome, awaitsNode, record, setStage, updateJournalEntry, updateLocalState; PaykitPaymentProofRepo.failLightningPayment / submissionSentNothing; the manual refusal block in AppViewModel.kt.
Traced: automatic refusal -> entry SUBMITTED -> journalOutcome asks the node once it can list payments, FAILED or no record -> FAILED. Manual refusal -> manualLightningPaymentRefused before failLightningPayment, pinned by the inOrder check in AppViewModelSendFlowTest.kt.
CI: detect-changes green; build-and-test, lint and compose-ui still pending at review time.
Build: Not built: on this track the review reasons from the code and CI, and does not run the branch's Gradle build.
Ruled out
- The executor's check and the repo's cleanup disagree:
failLightningPayment(paymentHash, error, requestId)now returnssubmissionSentNothing(error)first, the same predicate the executor reads. - A node settlement racing the cleanup gets overwritten: the change runs inside
updateLocalStateunderstateMutexand keepsSUCCEEDEDandFAILED. - Recovery on a restore before the node runs reads
SUBMITTEDas never sent:awaitsNodeholdsSUBMITTEDentries with a hash until the node can list payments. - A Spark resend refused after an earlier try loses its pending state: the manual call sits inside
authorizationError?.takeIf { sentNothing }, so that case never reaches it.
Merge confidence: 4/5, the new PaykitAllowanceExecutorTest cases and the inOrder check cover it, but CI's build-and-test 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)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 2484af1.
No new actionable code findings.
A refused Lightning Paykit payment is journaled SUBMITTED before its proof is cleared, both for an automatic allowance payment and for a manual payment refused at the authorization check. Recovery fails that SUBMITTED attempt once the node and Spark can list payments and neither has the hash, and it waits while they cannot. The same ordering is in bitkit-ios#1547 at 1916bb5; only this refusal flow was compared.
Device testing was not performed in this review. The kill between proof cleanup and the ledger write cannot be staged on a device. build-and-test and lint succeeded on this commit; this review inspected those results and did not re-run the suite. Other manual Lightning failures that clear the proof before the outcome is recorded remain tracked in #2175. The author also left the live refusal unrun: a contact blocked between review and submission, with a linked issuer and a funded regtest Lightning wallet.
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 discards the Lightning proof of an attempt the node never saw before it fails it, and leaves the attempt open when the discard cannot be saved. Verified: ./gradlew testDevDebugUnitTest for PaykitAllowanceExecutorTest, PaykitPaymentProofRepoTest, PaykitAllowancePayerTest and AppViewModelSendFlowTest; ./gradlew detekt
|
Pushed 249f54e: recovery now discards the started Lightning proof before it fails an unsent attempt. A kill between the |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 2484af1, including affected code paths and prior findings, at 249f54e. Baseline: QA review.
No new actionable code findings.
No new actionable code findings in the follow-up.
Recovery removes the started Lightning proof before it records a failed unsent Paykit attempt, and leaves the attempt open when that removal cannot be saved. A SENDING or SENT entry whose node payment is pending or absent stays open. Compared with bitkit-ios#1547 at bcef29a, only this recovery removal was compared. Android removes the proof for that payment request. iOS removes every Lightning proof for the payment hash. Android's narrower removal follows failLightningPayment, which keeps another request's proof of the same invoice.
Greptile withdrew the save-failure comment. A failed SUBMITTED save still leaves the journal at SENDING or SENT, and recovery still waits for a node payment in that state.
Device testing: not performed in this review. The kill between the refusal journal and proof cleanup cannot be staged on a device. The author reports PaykitAllowanceExecutorTest, PaykitPaymentProofRepoTest, PaykitAllowancePayerTest, and AppViewModelSendFlowTest (1115 tests, 0 failures) and a clean detekt run on this commit; this review did not re-run them. Other manual Lightning failures that clear the proof before the outcome is recorded remain tracked in #2175.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Twin: synonymdev/bitkit-ios#1547
Source: review, synonymdev/bitkit-ios#1493 (review)
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
PaykitAllowanceExecutorTest.kt— a refused automatic payment is journaledSUBMITTEDwhen its proof is cleared; recovery fails a refused manual payment whose outcome was never recorded and discards its proof first; recovery discards the started proof of a refused automatic payment before failing it; recovery leaves a refused payment open when its proof cannot be discardedAppViewModelSendFlowTest.kt— a refused manual payment is journaled unsent before its proof is clearedEvidence
./gradlew testDevDebugUnitTestforPaykitAllowanceExecutorTest,PaykitPaymentProofRepoTest,PaykitAllowancePayerTestandAppViewModelSendFlowTest(1115 tests, 0 failures);./gradlew detektclean.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)