Skip to content

fix: record a refused lightning paykit payment before its cleanup - #2176

Merged
piotr-iohk merged 3 commits into
masterfrom
fix/paykit-refusal-before-cleanup
Nov 28, 2026
Merged

piotr-iohk merged 3 commits into
masterfrom
fix/paykit-refusal-before-cleanup

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Fixes the automatic allowance payment leaving its attempt open after a kill, because a refusal at the recheck before submission cleared the proof and released the payment list while the journal still read SENDING. The journal now moves back to SUBMITTED first, which recovery reads as never sent and records as failed once the node has no payment for the hash.
  • Fixes the same for the manual payment of a request, whose journal read SENT during that cleanup.
  • Recovery discards the started Lightning proof of such an attempt before it fails it, so the unpaid request comes back to the pending list. It leaves the attempt open when the discard cannot be saved.
  • Splits the "did anything reach the node" check out of the proof repository, so the executor can read it before the cleanup runs.

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

  • added PaykitAllowanceExecutorTest.kt — a refused automatic payment is journaled SUBMITTED when 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 discarded
  • updated AppViewModelSendFlowTest.kt — a refused manual payment is journaled unsent before its proof is cleared

Evidence

  • On 249f54e: ./gradlew testDevDebugUnitTest for PaykitAllowanceExecutorTest, PaykitPaymentProofRepoTest, PaykitAllowancePayerTest and AppViewModelSendFlowTest (1115 tests, 0 failures); ./gradlew detekt clean.

Gaps

  • The refusal itself on a device (a contact blocked between review and submission, with a linked issuer and a funded regtest Lightning wallet) was not run.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: Gemini 4 Neon (reasoning: high)
  • Review rounds: 1

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
@ovitrif ovitrif added this to the 3.2.0 milestone Nov 27, 2026
@ovitrif ovitrif self-assigned this Nov 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T22:02:49.141253Z 3ac4a6c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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)
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · Fix the refusal writes before merging so cleanup cannot proceed after a failed save.RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Refused payments can stay open ▶

Summary

Records refused Lightning payments as SUBMITTED before clearing their proofs.

  • The wallet records refused Paykit payments before clearing their proofs.

Scope acknowledgment: ovitrif explicitly deferred other manual Lightning failure paths to #2175.

Reviews (1) · Last reviewed commit: "chore: add changelog fragment" · Reviewed by Greptile

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 returns submissionSentNothing(error) first, the same predicate the executor reads.
  • A node settlement racing the cleanup gets overwritten: the change runs inside updateLocalState under stateMutex and keeps SUCCEEDED and FAILED.
  • Recovery on a restore before the node runs reads SUBMITTED as never sent: awaitsNode holds SUBMITTED entries 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)

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 249f54e (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@ovitrif

ovitrif commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 249f54e: recovery now discards the started Lightning proof before it fails an unsent attempt. A kill between the SUBMITTED journal save and the proof cleanup used to fail the attempt but keep the proof, which hid the unpaid request from the pending list. If the discard cannot be saved, the attempt stays open and the next recovery tries again. This is the same fix as the twin, for the ordering compared in synonymdev/bitkit-ios#1547 (comment).

@ovitrif
ovitrif requested a review from piotr-iohk November 28, 2026 06:56

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@piotr-iohk
piotr-iohk merged commit 76c508b into master Nov 28, 2026
23 checks passed
@piotr-iohk
piotr-iohk deleted the fix/paykit-refusal-before-cleanup branch November 28, 2026 08:35
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.

3 participants