Repository navigation
fix: offer the savings retry after a refused exit start - #2056
Conversation
An exit start whose savings payment was refused before it went out, for a fee above the one confirmed, saves that payment with the exit. Progress prices it again at no less than the refused fee, shows what leaves savings and pays it at that fee from Pay from savings. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.repositories.SparkExit*' --tests 'to.bitkit.ui.settings.lightning.SparkExit*'
The refused payment is paid only while the exit holds no funding and no savings send to its address went out, checked again under the tick lock. Progress drops a price below the refused fee, re-prices on refresh, and a send that went out and failed shows with its own retry. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.repositories.SparkExit*' --tests 'to.bitkit.ui.settings.lightning.SparkExit*' :app:detekt
A refused start payment is offered only while no savings send to the address is unresolved or refused, read from the send attempt itself, and is forgotten once a savings payment went out. A fee refused again is never paid at the older price. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.repositories.SparkExit*' --tests 'to.bitkit.ui.settings.lightning.SparkExit*' :app:detekt
The refused start payment is paid only over a fresh read of the funding address, on a chain Spark reads. Progress prices it again until a price succeeds, as on a launch before the node runs. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.repositories.SparkExit*' --tests 'to.bitkit.ui.settings.lightning.SparkExit*' :app:detekt
Progress stops offering savings once the payment's read of the funding address found funding, keeps its last price when a re-price fails, and stops pricing once it closes. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.repositories.SparkExit*' --tests 'to.bitkit.ui.settings.lightning.SparkExit*' :app:detekt
The pay-time read now sets funding seen through the same path as a tick, and Progress prices the refused payment only while it is open. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
Progress screens are counted, so one closing after another opened never stops the open one's pricing. A test covers pricing only while open. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
The pricing test keeps a failing price retrying, so it fails if one screen closing stops another's pricing or the last one leaves it running. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt; the test fails with the screen count guard removed
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. |
[High impact] The PR appears safe to merge; no actionable issues were found. SummaryAdds a saved retry for emergency-exit funding refused before dispatch because its savings fee increased.
No actionable issues found. Review was based on source inspection; tests and device checks were not run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Funding fee exceeds approval] --> B[Save amount and refused fee]
B --> C[Price retry at fast rate]
C --> D[Show savings total]
D --> E[User taps Pay from savings]
E --> F{Funding still missing and no unresolved send?}
F -->|No| G[Send nothing]
F -->|Yes| H{Prepared fee within approval?}
H -->|No| B
H -->|Yes| I[Send and clear refusal]
Reviews (1) · Last reviewed commit: "test: check a closing progress screen st..." · 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. Saves a start's savings payment refused for a fee above the confirmed one on the exit record, prices it again on Progress at the fast rate (never below the refused fee) and pays it under the tick lock after re-reading the funding address. Reviewed ea06210, full tier, static: on the Bitkit track an auto review does not build the PR's branch, so this is reasoned from the code and from CI.
What I checked, and 5 candidates I ruled out
Read in full: the diff of SparkExitRepo.kt, SparkExitFunding.kt, SparkExitRecord.kt (record field and JSON round-trip), SparkExitViewModel.kt, SparkExitProgressScreen.kt, SparkExitComponents.kt; payFunding, sendFunding, fundingTxid, retrySavingsPayment, cancel, canCancel, SparkExitMath.fundingState at the head
Call sites traced: LightningRepo.sendOnChain down to checkApprovedSpend (where OnchainSendChangedError(miningFee) is wrapped in OnchainSendNotDispatchedError), and the three places that clear savingsRefusal on a paid txid
CI at review time: build-and-test and build-local green; lint, compose-ui / ui-tests and the local e2e shards still running
Ruled out
- A refusal that went out is offered again: a node rejection surfaces as
SparkExitErrorfromfundingTxidand an unknown dispatch asOnchainSendPendingError; both clear the refusal inpayFunding'sonFailure, andsavingsRefusal()also returns null while the send attempt to the address is unresolved or rejected. - Paying after funding arrived: the
isDuecheck runs undertickMutex, reads the address, feedsnoteFundingSeen, andSparkExitMath.savingsRefusalrefuses on anyreceivedSats > 0or a non-Askstate; a failed read throws beforesendFunding. - Paying an older, lower price:
isDuerequiresrefusal.feeSats <= retry.feeSats, andsavingsRetryOfferhides a price below the current refusal until it is priced again. - Two payments at once:
paymentMutex.tryLock()guards the repo path, and the view model returns early whileisRetryingSavingsPayment. - Pricing that keeps running after Progress closes: the screen counter in
start/stopSavingsRetryPricingcancels the job on the last dispose, andloadSavingsRetryis a no-op with no screen open.
Merge confidence: 4/5, no findings and the payment paths are covered by SparkExitRepoTest.kt, but lint and the UI tests had not finished when this was posted and the branch was not built here.
Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: Not exposed (the run metadata names the model but no reasoning level)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed ea06210.
The exit's funding state can lag behind the savings send journal. When the funding address still appears empty, Progress can offer another payment even though a savings transaction was accepted or may still confirm.
Medium candidate: SparkExitRepo.kt:1042 ignores a matching accepted send. The savings retry marks ordinary follow-up complete before saving the exit's funding txid (SparkExitRepo.kt:952, SparkExitRepo.kt:1135). If the app stops between those writes or the exit save fails, Progress can restore Pay from savings while the address still appears empty. That tap can start a fresh send with different inputs, potentially paying the funding amount twice and incurring another mining fee.
Medium candidate: Progress shows the collected quote (SparkExitProgressScreen.kt:230), but the button reads the latest ViewModel quote at tap time (SparkExitViewModel.kt:356). If a refresh publishes a higher quote just before a tap on the old amount, the new cap can allow a fee above the one still visible. Pass the displayed quote with the tap so the prepared-fee check enforces the amount the user saw.
Low candidate: A savings retry that returns a pending error can clear the retry offer without saving the transaction ID (SparkExitRepo.kt:947). While the address read shows no funds, Progress still shows Amount to pay and a copyable address (SparkExitProgressScreen.kt:222). Someone returning to Progress can follow that prompt from another wallet while the savings transaction is still able to confirm.
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
A savings send the node accepted holds back the refused payment's offer and pay, also when the exit's txid was not saved; a failed save keeps the payment as paid in memory. The tap pays the price on screen, never one published after. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt; the accepted-send test fails without the gate
A tick saves the txid of a savings send the node accepted to the funding address when the record lost it, before a later send can take its place in the journal, and cancel holds back while such a send exists. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
jvsena42
left a comment
There was a problem hiding this comment.
Code scan at ea06210: no findings.
Checked and clean:
- Refused vs ambiguous starts: a refusal is written only for
OnchainSendNotDispatchedError(cause = OnchainSendChangedError).checkApprovedSpendthrows that beforeretainPreparedReceiptand before broadcast, and the attempt is released, so a refusal always means nothing went out. Pending and rejected outcomes clear the refusal; unknown and accepted outcomes save the txid and clear it. - Retry gate:
isDueruns undertickMutexand re-reads the address and the liveOnchainSendAttempt. It requires the same sats and a fee no lower than the refusal's. The approved cap is the shownretry.feeSats.sendOnChainstill refuses while another attempt is unresolved. The remaining double-pay window is pwltr's first thread, not repeated here. - Persisted state:
savingsRefusalis optional (objectOrNull) andCURRENT_VERSIONis unchanged. Spark exit isn't in v3.1.1 (git grep -i sparkexitonv3.1.1^{commit}is empty), so there is no upgrade path to cover. - Cancellation and concurrency: check, send and save run
NonCancellableundertickMutex, andcancel()takes the same lock.paymentMutex.tryLockis shared with start, fee bump and node retry. EverysavingsRefusalwriter holdstickMutex. The VM double-tap guard is set synchronously. - Cancel/Back: Cancel deletes the record with its refusal. Back/OK keep it and reprice on re-entry. A relaunch reloads from disk.
- Pricing once on Progress (no reprice on resume) matches the start flow and fee bump on master, so I'm not raising it here.
perf: relevant (new 15 s pricing loop while Progress is open and pricing fails); measurement pending with the gate.
Device gate (partial): ea06210 — not run yet. It needs a refused exit start (prepared fee above the approved one) on a Spark regtest wallet. Device result to follow.
Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating and verifying; Fable 5.2 (claude-fable-5-2) primary review
Reasoning effort: Not exposed
…cord A payment the exit forgot since (dropped, or short) stays forgotten, as the journal keeps an accepted send until the next one. Cancel keeps a lost payment first instead of refusing on the journal alone. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
The savings retry and cancel keep a refused start's accepted payment the record lost under their lock before they check it, and keeping it shows the funding as paid. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
A retry that finds the lost accepted payment keeps it and succeeds instead of failing, and the exit reads both savings sends from one journal read. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
Fixed in 7b6c93b, 5aaccbe, 52aa7d5 and 2222ede. A savings send the node accepted to the funding address now counts as a savings send, so the refused payment is neither offered nor paid again. Each tick, cancel and the retry itself keep its txid on the record (under the tick lock) while the refusal is still on record. That way the payment survives a later send taking its slot in the send journal, and a payment the exit later forgets (dropped, or short) is never brought back. A failed save keeps the payment as paid in memory.
Fixed in 7b6c93b. The button passes the offer it rendered, and the payment is capped at that fee; a fee refused since is refused before it goes out.
This predates this PR: a start whose savings payment ends pending shows the same ask on master. Filed as #2059 (iOS: synonymdev/bitkit-ios#1451) and listed under Out of Scope. synonymdev/bitkit-ios#1449 got the same two fixes, so the twins stay equal. |
Funding seen at the address stays seen when a later read fails, and the refused savings payment is no longer offered over it. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
The funding-seen guard moves into the shared refusal check, where every caller and its tests see it. Verified: ./gradlew :app:testDevDebugUnitTest --tests '*SparkExit*' detekt
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 90b8e37.
Low candidate: A savings retry that returns Pending can lose its link to the exit. SparkExitRepo.kt:948 clears the saved refusal before recording a funding txid, and SparkExitRepo.kt:1074 requires that refusal to keep a matching accepted send. If the wallet records the transaction before the funding explorer sees it, Cancel can become available. An empty read at SparkExitRepo.kt:1229 then lets Cancel delete the active transfer, leaving its payment on the address watched for late funding. To verify this, extend the pending-retry test so the same journal entry becomes Observed while the address still returns no UTXOs, then check whether Cancel preserves the transfer.
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 #2067, because no funds are lost (the payment stays watched as late funding and is swept back to savings) and a push now would void this approval. Merging this PR now: approved, CI green. |
|
Device gate (partial): ea06210 — refusal reproduced on the Android emulator against the local bitkit-docker Spark stack (one-line worktree patch forcing Trigger: Emergency fees prices the funding with ldk-node's input choice (1 input, 422 sats); the start uses Coin Selection = Consolidate over six UTXOs (1 442 sats), so
Still running: the full runbook drive (relaunch-before-price check, cancel/repeat, measurements on a second wallet). |
Closes #1856
Twin: synonymdev/bitkit-ios#1449
Description
Out of Scope
Design
N/A — no design available. Reuses the existing Progress note and button of the savings retry and the funding screen's savings row; no new strings.
Preview
N/A — the fee mismatch hasn't been reproduced on a device.
QA Notes
Journeys
N/A
Manual Tests
Automated Checks
SparkExitRepoTest.ktSparkExitFundingTest.ktSparkExitViewModelTest.kt./gradlew testDevDebugUnitTest --tests 'to.bitkit.repositories.SparkExit*' --tests 'to.bitkit.ui.settings.lightning.SparkExit*'./gradlew detektModels used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)