Repository navigation
fix: refuse a spark retry at another amount - #2071
Conversation
A retry of an amountless invoice reuses its earlier attempt's Spark key, so at another amount Spark returned the first payment while the send showed the new amount. Each attempt now keeps its amount, and a retry under the same key at another amount is refused before anything goes out. Verified: SparkRepoTest, CacheStoreTest, the unit suite and lint pass.
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)
[Critical impact] The PR appears safe to merge; no actionable issues were found. SummaryStores the amount of each Spark send attempt and refuses a different amount when a retry would reuse its key.
Acknowledged scope from Reviews (1) · Last reviewed commit: "fix: refuse a spark retry at another amo..." · Reviewed by Greptile |
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Stores the amount each kept Spark send attempt sent and refuses a retry under the same key at another amount with SparkError.SendRefused before anything is written or sent. Reviewed d547aca, full tier, static: per this repo's track rules the branch was not built here, so this rests on the code and CI.
What I checked, and 5 candidates I ruled out
Read in full: SparkRepo.payInvoice with nextSendAttempt, isPaidLocally, settleUncertainSend; CacheStore.setSparkSendAttempt / restoreSparkSendAttempt; LightningRepo.payInvoiceChecked (the Spark branch and its authorizeSend admission).
Call sites traced: SparkRepo.payInvoice from LightningRepo.payInvoiceChecked, reached by AppViewModel.sendLightning, the swap hold pay and PaykitAllowanceExecutor; setSparkSendAttempt has the one caller in SparkRepo.
CI: build-and-test, lint, detekt and build-local green; the e2e-tests-local jobs and compose-ui were still pending at review time.
Ruled out
- Refusal leaves state behind:
ensureKeptAmountruns beforeaddSparkSendHash,setSparkSendAttemptandaddSparkUncertainSend, and thefinallydrops thesendsInFlightentry; inLightningRepothe refusal is not aPaymentPendingException, soisAdmittedrestoresrailBeforeandreleaseSendruns. - Held send loses its hold on refusal: the throw happens before
dropUnsentSendis defined or called, sosparkUncertainSendsand the kept attempt stay; the held-send test asserts both. - Fixed-amount invoice sent with and without an explicit amount:
sendAmountSatsfalls back toamountMsat / 1000, so100uLandnullon a 100 sat invoice compare equal. - Attempts stored before this change:
amountSatsdefaults to null andensureKeptAmountskips them; the body states no store build carries keyed sends yet, and the field is additive for the serializer. - Earlier attempt COMPLETED at another amount returns success: that early return predates this diff and sits with the out-of-scope pending case (#2072), not this change.
Merge confidence: 4/5, no findings and the new paths are covered by SparkRepoTest.kt, but the e2e jobs had not finished and the review is static.
Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed
Paying an amountless invoice again at another amount while its first payment was pending opened Payment Pending at the new amount, and its success receipt kept it. Pending now shows the amount stored for the payment it waits on. Fixes #2072 Verified: AppViewModelSendFlowTest, the unit suite and lint pass.
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at d547aca.
1 actionable finding — resolve or provide an evidence-backed rebuttal.
Persisting amountSats on SparkSendAttempt and refusing a same-key retry at another amount before writing or sending prevents Spark from returning an earlier payment under a new amount, and properly advances to the next key once Spark lists the earlier attempt failed. However, throwing SparkError.SendRefused while an earlier attempt is still held in doubt deletes any other Paykit request's pending Lightning payment proof for that payment hash via PaykitPaymentProofRepo.failLightningPayment(paymentHash, error). Companion synonymdev/bitkit-ios#1415 (inspected at 3c465d3) avoids that by converting a refused retry of a held send to a pending duplicate in LightningService.throwPendingIfInDoubt; Android intentionally keeps an error on Confirm to avoid showing the new draft amount on Pending/Success (#2072), so PaykitPaymentProofRepo.failLightningPayment needs request-scoped removal (or a held-refusal guard) to preserve the earlier request's proof.
Validation: CI checks at d547aca passed for build-and-test, lint, detekt, and compose-ui / ui-tests; e2e-tests-local (send, multi_address_local, onchain_boost_receive_widgets) were still in progress at review time. Local Gradle execution could not run in this environment because no Android SDK is installed. Automated coverage recommendation (yes): add a unit test in PaykitPaymentProofRepoTest.kt or AppViewModelSendFlowTest.kt verifying that refusing a second Paykit request for a held amountless invoice at another amount preserves the earlier request's pending Lightning proof.
Recommended before device testing:
- Scope
PaykitPaymentProofRepo.failLightningPaymentto the refused request (or otherwise preserve an earlier held request's pending Lightning proof) and add regression test coverage. - Wait for the in-progress
e2e-tests-localCI jobs at d547aca to complete.
Device testing: not performed in this review (code-only review; the author notes no device run was performed because staging a held-in-doubt leaf-selection failure is covered by unit tests).
Findings
- [MEDIUM] Refusing a held Spark retry at another amount deletes an earlier Paykit request's pending proof — inline at
app/src/main/java/to/bitkit/repositories/SparkRepo.kt:1036.
Reviewer model: gemini-4-neon
Reasoning effort: high
A refused Spark retry cleared every Paykit Lightning proof of its invoice, so refusing a second request's retry at another amount dropped the first request's pending proof. A refusal now clears only its own request's proof. Verified: PaykitPaymentProofRepoTest, PaykitAllowanceExecutorTest and AppViewModelSendFlowTest pass.
A refused authorization, a failed spending balance update and an allowance's unsaved sending stage still cleared every Lightning proof of the invoice. They now clear only their own request's proof. Pending also skips a failed earlier payment's amount and shows the draft amount. Verified: PaykitPaymentProofRepoTest, PaykitAllowanceExecutorTest and AppViewModelSendFlowTest pass.
Verified: just compile, just test and just lint pass.
A repeat that waits on an earlier Spark send not yet in Activity showed the draft amount on Pending. It now shows the amount kept on that send's attempt. Verified: AppViewModelSendFlowTest passes.
pwltr
left a comment
There was a problem hiding this comment.
Reviewed d547aca. The changed-amount guard uses the saved Spark attempt at submission, even when the user has already made a spending-balance transfer or the original attempt stopped before calling the SDK.
Low: A larger retry can move channel funds to Spark before the amount refusal. If the first amountless attempt is held and the new amount needs both balances, AppViewModel.kt:8243 executes the approved update before SparkRepo.kt:662 checks the saved amount. This can incur the update fee and schedule closure of emptied channels even when the original attempt never reached Spark and the retry will be refused as soon as it reaches Spark submission.
Low: Process death after the amount and hold are saved in SparkRepo.kt:677–686, but before the SDK call, leaves a restored hold that refuses a corrected amount. The user can still use the original amount or obtain a fresh invoice.
Low candidate: A second Paykit request prepared before the first entered its hold could lose the first request's proof association. Fresh resolution excludes held invoice hashes in PrivatePaykitRepo.kt:2307, but if the already-prepared request can pass the private-list and request guards, its changed-amount refusal reaches the hash-wide deletion in PaykitPaymentProofRepo.kt:933. The earlier request then has no local association for delivering its proof if Spark settles it.
Pre-existing Low: Reopening the app and retrying an already-paid amountless invoice at another amount can show the new amount on Success. SparkRepo.kt:609 returns the completed hash without resubmitting, and AppViewModel.kt:8273 only looks up the original amount when the current ViewModel has already processed that hash.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
Out of scope: tracked in #2120, because it needs a held first attempt and a retry that needs both balances.
Out of scope: tracked in #2121, because the original amount or a fresh invoice still works.
Fixed in a423e00 and b805940: every proof clear tied to one request now clears only that request's proof.
Out of scope: tracked in #2122, because it predates this PR. |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since d547acaa, including affected code paths, at e3a80464. Baseline: previous review (inheriting unchanged CacheStore and SparkRepo coverage; changelog.d/next/2071.fixed.md changed and was reassessed).
1 actionable finding — resolve or provide an evidence-backed rebuttal.
Request-scoped Paykit proof clearing in PaykitPaymentProofRepo, PaykitAllowanceExecutor, and AppViewModel correctly preserves another request's pending Lightning proof on the same invoice when a request fails before sending. One medium issue remains in AppViewModel.earlierLightningSendSats, where using a missing Activity row as a proxy for an active Spark hold both lets a failed Spark attempt's retained sparkSendAttempts amount leak into a subsequent pending LDK send (when no Activity row is stored or readable) and lets an earlier FAILED Activity row mask a live held Spark retry's amount.
Parity (synonymdev/bitkit-ios#1415 at 3c465d35): Both apps persist amountSats on the kept Spark send attempt and refuse same-key retries when the amount changes. On iOS, LightningService.throwPendingIfInDoubt converts a refusal while a hold is in doubt into DuplicatePayment so the earlier held send's Paykit proof/allowance/QuickPay state is retained; Android returns SparkError.SendRefused to the caller (keeping Spark's hold) and scopes request-bound Paykit proof clears to requestId, which fits Android's contract.
Validation and coverage: At e3a80464, CI build-and-test and lint passed, while compose-ui and several e2e-tests-local shards were still pending at inspection time. Automated regression coverage (yes): extend AppViewModelSendFlowTest.kt to populate sparkUncertainSends for the held-Spark case and add cases for (1) a missing Activity row with a non-held sparkSendAttempts entry returning the new LDK draft amount, and (2) an earlier FAILED Activity row paired with an active sparkUncertainSends hold returning the held Spark amount.
Device testing: not performed in this review.
Earlier findings reconciled at this revision: 2 still present, 1 verified fixed, 1 tracked separately outside this PR.
Tracked separately (outside this PR; unresolved): Repeating an already-paid amountless Spark invoice at another amount after restart shows the new amount on Success. Pre-existing issue outside this PR, tracked in open same-repository issue #2122. Both at base 576ac14 and at head e3a8046, SparkRepo.payInvoice returns paymentHash immediately when earlier.status == PaymentStatus.COMPLETED (before reaching any code changed by this PR), and AppViewModel.proceedWithLightningPayment only calls earlierLightningSendSats when wasPaidBefore is true in the in-memory processedPayments set (empty after app restart), so onSendSuccess displays displayAmountSats. This PR neither introduces nor worsens that path. This is not a runtime verification or merge-readiness declaration.
Findings
- [MEDIUM] Gate sparkSendAttempts fallback on active Spark holds in earlierLightningSendSats — inline at
app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt:8325.
Existing concerns
- [LOW] Larger held Spark retry executes spending balance update before amount refusal — Review #2071 (review) is dismissed and the author deferred this concern as out of scope in #2071 (comment), tracking it in open issue #2120. At e3a8046, the mechanism remains in code and is introduced by this PR's ensureKeptAmount refusal running after updateSpendingBalanceIfNeeded, so it stays open with its canonical issue reference and no material new evidence.
- [LOW] Process death between saving Spark attempt/hold and SDK call refuses a corrected amount on retry — Review #2071 (review) is dismissed and the author deferred this concern as out of scope in #2071 (comment), tracking it in open issue #2121. At e3a8046, the mechanism remains present and is introduced by persisting sendSats before the SDK call and checking ensureKeptAmount on reused keys (paying the original amount or a fresh invoice still works); it stays open with its canonical issue reference and no material new evidence.
Reviewer model: gemini-4-neon
Reasoning effort: high
pwltr
left a comment
There was a problem hiding this comment.
Reviewed e3a8046.
Low: AppViewModel.kt:8322 looks up the amount by invoice hash without checking which attempt the result describes. After a failed Spark send, an unavailable Activity read lets the failed attempt's cached amount appear on Pending for a new LDK payment (AppViewModel.kt:8294) or on Success when repeating a payment already settled by LDK (AppViewModel.kt:8274). The Pending amount can carry through to Success when settlement supplies no amount (SendPendingScreen.kt:115). In the reverse case, an older failed Activity row prevents the lookup from reaching the amount of a newer held Spark retry (AppViewModel.kt:8326), so a repeat routed through LDK shows the newly entered amount while it waits for the held Spark payment.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
Pending fell back to the kept Spark attempt's amount whenever Activity had no sent row, so a failed attempt's amount showed for a new payment, and a failed row hid a held retry's amount. Pending now shows a non-failed sent row's amount, else the kept amount while Spark holds that send, else the draft amount. Verified: AppViewModelSendFlowTest passes.
Fixed in 2c5eb30: Pending shows a non-failed sent row's amount, else the kept Spark amount only while Spark holds that send, else the draft amount. A failed attempt's amount no longer shows, and a failed row no longer hides a held retry's amount. |
|
@ovitrif please resolve conflicts. |
Keeps master's repaid-invoice helpers next to this branch's pending amount lookup, and passes an amount and a request matcher in master's new tests. Verified: just compile, just test and just lint pass.
@piotr-iohk Resolved in ea7c231: merged master, keeping its repaid-invoice helpers beside this PR's Pending amount lookup, and gave master's new |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR at ea7c231, re-reviewed after the comparison base changed (576ac143 → c12ff7cb) and touched reviewed files.
No new actionable code findings.
All five changed surfaces (CacheStore attempt-amount persistence, SparkRepo same-key amount refusal, AppViewModel pending-repeat amount resolution, request-scoped Paykit Lightning proof clearing across PaykitPaymentProofRepo/PaykitAllowanceExecutor/AppViewModel, and the changelog fragment) and their callers were verified.
Compared against companion synonymdev/bitkit-ios#1415 at 3c465d3: both platforms persist amountSats on kept Spark send attempts and refuse same-key retries at a different amount before dispatching while preserving active holds. Where iOS converts held-send refusals and pending repeats to NodeError.DuplicatePayment, Android intentionally refuses same-key amount changes with SparkError.SendRefused (scoping Paykit proof clears to requestId so another request's proof for the same invoice stays intact) and opens Payment Pending at the earlier payment's amount (preferring a non-failed SENT Activity row and falling back to sparkSendAttempts[hash].amountSats only while hash is in sparkUncertainSends).
Local Gradle execution could not run in this container (no Android SDK installed). On CI at ea7c231, build-and-test, lint, detekt, and compose-ui / ui-tests passed; e2e-tests-local - send was still in progress when checked.
Recommended before device testing
- Wait for e2e-tests-local - send to complete green at ea7c231.
Suggested additional test cases
- Android (regtest, Spark-funded wallet without channels): generate an amountless hold invoice, pay
1,000sats so Spark leaves the send pending, dismiss Payment Pending, paste the same invoice, enter2,000sats, and confirm. Expected: Payment Pending opens showing1,000sats (not2,000), and after settling the hold invoice, Payment Success shows1,000sats.
Device testing: not performed in this review.
Earlier findings reconciled at this revision: 2 still present, 1 verified fixed, 1 tracked separately outside this PR.
Tracked separately (outside this PR; unresolved): Repeating an already-paid amountless Spark invoice at another amount after restart shows the new amount on Success. Pre-existing issue outside this PR, tracked in open same-repository issue #2122. Master PR #2113 (commit 350bb2c, included in both base c12ff7c and head ea7c231) narrowed the plain-invoice path by adding AppViewModel.lightningRepeat to read persisted SUCCEEDED Activity rows before proceedWithLightningPayment, but the underlying proceedWithLightningPayment (checking in-memory processedPayments via wasPaidBefore) and SparkRepo.payInvoice (early return on PaymentStatus.COMPLETED) path remains unchanged at both base and head for contact payments (contactPaymentContext != null, skipped at AppViewModel.kt:8364) and whenever activityRepo.getActivity lacks a SUCCEEDED row. This PR neither introduces nor modifies that path. This is not a runtime verification or merge-readiness declaration.
Existing concerns
- [LOW] Larger held Spark retry executes spending balance update before amount refusal — Mechanism remains present at ea7c231 and is introduced by this PR's ensureKeptAmount refusal running inside SparkRepo.payInvoice after AppViewModel.updateSpendingBalanceIfNeeded. Review #2071 (review) is dismissed and the author deferred this concern as out of scope in #2071 (comment), tracking it in open issue #2120. No material new evidence since previous reporting.
- [LOW] Process death between saving Spark attempt/hold and SDK call refuses a corrected amount on retry — Mechanism remains present at ea7c231 and is introduced by persisting sendSats before calling Spark and refusing mismatched amounts in ensureKeptAmount on reused keys (paying the original amount or a fresh invoice still works). Review #2071 (review) is dismissed and the author deferred this concern as out of scope in #2071 (comment), tracking it in open issue #2121. No material new evidence since previous reporting.
Reviewer model: gemini-4-neon
Reasoning effort: high
pwltr
left a comment
There was a problem hiding this comment.
Reviewed ea7c231. The Pending amount lookup can display an older attempt’s amount or interrupt navigation after submission.
Low: app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt:8349 uses a PENDING Activity row before checking the live Spark hold. If the first 1,000-sat attempt fails and its Activity update is deferred, a fresh 2,000-sat attempt can enter Pending while the older row is still readable. Pending then shows 1,000 sats, and SendPendingScreen.kt:117 can carry that amount into Success when settlement supplies no amount.
Low: app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt:8353 reads the cache after tracking a submitted payment as pending. If there is no usable Activity row and the cache read throws an I/O error, the send flow skips Pending navigation and the immediate check for an already-settled Spark payment.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
Out of scope: both tracked in #2135, because each needs a deferred Activity update or a cache read failure, and fixing them here would void the approval before 3.2.0. |
|
Merging: approved and CI green on ea7c231. |
Fixes #2074
Fixes #2072
Companion: synonymdev/bitkit-ios#1415
A retry of an amountless invoice reuses its earlier attempt's Spark key, so at another amount Spark returned the first payment while the send showed the new amount. Found by @pwltr's review of the iOS twin, synonymdev/bitkit-ios#1415, which carries the same fix.
Description
SparkError.SendRefusedbefore any attempt is written or anything goes out, so Confirm shows an error. The earlier attempt's hold and its waiters stay as they were.Out of Scope
Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
N/A — no device testing required: a same-key retry at another amount needs a send held in doubt, which the unit tests stage.
Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
N/A
Automated Checks
SparkRepoTest.kt— a retry under the same key at another amount is refused and nothing is sentSparkRepoTest.kt— a retry under the same key is refused when the invoice's own amount differs from the kept oneSparkRepoTest.kt— a retry of a held send at another amount is refused and keeps the send heldSparkRepoTest.kt— a retry at another amount goes out under the next key once Spark lists its attempt failedCacheStoreTest.kt— kept attempts store their amountAppViewModelSendFlowTest.kt— repaying an amountless invoice still pending with another amount shows the pending amountAppViewModelSendFlowTest.kt— repaying an amountless invoice held by Spark without an Activity row shows the held amountAppViewModelSendFlowTest.kt— repaying an amountless invoice whose earlier payment failed shows the new amount as pendingAppViewModelSendFlowTest.kt— repaying an amountless invoice after a failed Spark attempt without activity shows the new amountAppViewModelSendFlowTest.kt— repaying an amountless invoice held by Spark after a failed row shows the held amountAppViewModelSendFlowTest.ktandPaykitAllowanceExecutorTest.kt— proof clears pass the request idPaykitPaymentProofRepoTest.kt— a refused submission for one request keeps another request's proof of the same invoiceEvidence
just compile,just testandjust lintpass at the head.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)gemini-4-neon-high(reasoning:Not exposed)Metadata note: the Gemini self-review records the model only, not a reasoning setting.