Repository navigation
fix: keep the force transfer's fee request in step with the savings send - #2155
Conversation
Release the savings-send hold when the exit wallet's journal holds no attempt and the funding address was never used; keep the fee request a partial payment reduced across marking and a failed top-up; send no fee request when unconfirmed funding already covers the fees. Verified: gradlew testDevDebugUnitTest SparkExitRepoTest, PaykitPaymentProofRepoTest, SendPendingViewModelTest (pass; the three new tests fail with the main-code changes reverted), gradlew detekt
The start's read of the funding address keeps the last read too, a wipe forgets it, and the release checks the journal's wallet before and after reading it. Verified: gradlew testDevDebugUnitTest SparkExitRepoTest, PaykitPaymentProofRepoTest, SendPendingViewModelTest (pass), 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. |
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryKeeps the force transfer’s fee request in step with its savings payment.
No actionable issues found. Tests were inspected but not run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Started savings payment] --> B{Journal read succeeds?}
B -->|No| H[Keep hold]
B -->|Yes| C{Journal empty and wallet matches?}
C -->|No| H
C -->|Yes| D{Address unused?}
D -->|No or unreadable| H
D -->|Yes| E[Clear hold]
E --> F[Recalculate fee request from last funding read]
Reviews (1) · Last reviewed commit: "fix: keep the last funding read from the..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Releases a force transfer's savings-payment hold when the exit wallet's journal holds no attempt and the funding address was never used, keeps the fee request reduced by the last address read, and skips the fee notification while unconfirmed funding already covers the fees. Reviewed 14c105b, full tier, static: not built here (auto reviews of this repo never run Gradle).
What I checked, and 4 candidates I ruled out
Read in full: the diff; in SparkExitRepo.kt load, tickLocked, refreshFundingSeen/noteFundingSeen, updateAlerts, payFunding, markSavingsSend, clearSavingsSend, both keepAcceptedSavingsSend; EsploraSparkExitChain.isAddressUsed; OnchainSendAttemptStore.current; SparkExitAlerts.isFundingAskBack
Tests read: the three new SparkExitRepoTest cases and the fundingChain(txCount) change
CI: still running at review time (build-and-test, lint pending)
Ruled out
- Clearing the hold between marking and admitting a send:
payFundingmarks and sends undertickMutex, and all three callers of the suspendkeepAcceptedSavingsSend(load,tickLockedand the retry'sisDuecheck insidepayFunding) hold it, so the empty-journal path never sees a marked payment that is about to be admitted. - Reading another wallet's journal:
OnchainSendAttemptStore.current()readslightningService.currentWalletIndex, and the wallet is compared to the exit's before the read and again insideisStartedSendNeverSent, so a switch during the read keeps the marker. - A failed address read releasing the hold:
runSuspendCatching { !chain.isAddressUsed(address) }.getOrDefault(false)keeps the marker on any error, andisAddressUsedcounts mempool as well as chain transactions. - A stale last read reducing the wrong ask:
lastReadreturns the cached UTXOs only when their address is the record's current funding address, and a wipe resets the cache.
Merge confidence: 4/5, no findings and each rule has a test, but this is the funds path of a force transfer, CI had not finished and the device run is still to come.
Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed (the review run does not report its effort setting)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
jvsena42
left a comment
There was a problem hiding this comment.
Code scan at 14c105b: no findings in the code.
LOW (PR body, no line to anchor): the change is user-visible (Progress shows the fee request sooner after a restart and keeps it reduced after a failed savings payment; one notification is dropped), but the body has no QA Notes, so there is no #### Journeys and no case a reviewer can run. Please add QA Notes from the template. The three rules are mostly not drivable as journeys (process death between marking and dispatch; 144 blocks on the hosted Spark regtest), so N/A — not drivable; see Manual Tests. with cases 1.–3. (one per rule) would fit. Also, the Twin: line names issues; leave it out until the iOS PR exists.
Checked and clean:
- No amount or fee path changes.
sendFunding,payFunding,paySavingsRefusal,retrySavingsPayment,payHigherFeeLockedandSparkExitMath.savingsRefusalare untouched. The newfundingStateonly feeds Progress and the refusal'sfundingargument. - The new marker clear (
keepAcceptedSavingsSend) cannot release a payment that went out:current()is null only with no keychain entry, or afterreleaseInterruptedUnsubmittedPreparationdeleted an attempt that never dispatched (initialDispatchAttemptedis persisted before native dispatch).- Keychain or decode errors keep the marker.
- A journal entry replaced by a later
admitmeans the exit's send was accepted, andisAddressUsed(chain plus mempool) keeps the marker.
- No second payment after a clear without a new approval. A start killed before dispatch leaves no refusal, and a killed
paySavingsRefusalkeeps its refusal, so it is offered again and paid once. - Every caller of
keepAcceptedSavingsSendholdstickMutex, andpayFundingandretrySavingsPaymenthold it frommarkSavingsSendto the saved txid. - Cancellation: both new reads use
runSuspendCatching, andclearSavingsSenddoes not suspend.lastFundingReadis memory only, so after process death the behaviour equals master. - v3.1.1 has no Spark exit state, so there is nothing to migrate.
- Overlap with #2142: the two heads merge cleanly, and #2142's release (inactive exit or no shortfall) and this PR's clear never meet in the same state. Whichever merges second should rerun
SparkExitRepoTest.
perf: one extra GET /address/{addr} per load and tick, only while a marker exists with an empty journal; no device measurement needed.
Device gate (partial): 14c105b — not run yet; a reduced fee request after another wallet's partial payment and a failed savings payment, on the local Spark stack. Result to follow.
Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating; Fable 5.2 (claude-fable-5-2) primary review
Reasoning effort: Not exposed
Fixed in the PR body: QA Notes added, with Journeys
#2142 merged first. On this head merged with master, |
|
QA for 14c105b: Tested on Pixel 10 Pro XL (Android 16 emulator), local regtest. A local debug-only change stopped the app once, right after the force transfer saved its savings payment marker and before the send journal took the payment. 🟢 A started savings payment that never went outA started savings payment that never went out After the relaunch the app released the hold: the marker was gone, the funding address had no transactions, and Progress showed Amount to pay ₿ 7 623 with Cancel transfer enabled.
Not run on device:
|
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 14c105b.
Low: The fee reminder can be missed when covering funding drops out. If a Savings hold expires while an unconfirmed output and a smaller confirmed output cover the fee, SparkExitRepo.kt:507 skips the reminder. If the unconfirmed output later disappears, Progress asks for the remainder, but SparkExitWorker.kt:389 has no hold transition left to notify on and the confirmed partial payment suppresses the first-funding reminder.
Low candidate: An empty send journal and a single address-history response can release a hold for a payment that could still arrive. An accepted attempt can be replaced after local follow-up, and an interrupted preparation can then leave the journal empty. SparkExitChain.kt:211 also treats missing counters as zero. If the funding host has yet to see the accepted payment, SparkExitRepo.kt:1167 can release the hold before the payment appears, exposing a new payment request and potentially permitting cancellation if the fresh UTXO read is also empty.
Low: A failed funding-address read can undo the restored remainder. SparkExitRepo.kt:453 falls back only to a read from the same tick, so SparkExitRepo.kt:469 can publish the full request while the repository still counts the previously observed partial payment. Progress shows the full amount until a read succeeds. This gap also exists on the base and affects the reduced request this change restores.
Review details
Quick review: Claude Opus 5.5, high reasoning effort
General review: GPT-6.2 Sol, high reasoning effort
Verification: GPT-6.2 Sol, high reasoning effort
All three are tracked in #2157 and will be fixed in its follow-up PR for 3.2.0. For the candidate, that starts with checking whether the replaced-then-emptied journal sequence is reachable. |
|
Merging: approved on 14c105b, device run on this head posted above, all checks green. |
Closes #2151
Description
Follow-up to @pwltr's review of #2146 (#2146 (review)). The marker a savings payment leaves on a force transfer no longer keeps Progress and the background worker out of step with the send journal and the funding already seen:
A send that never went out releases the hold. After a restart the marker is cleared only when all of these hold:
The journal saves an attempt before it goes out, and the address read covers a payment the journal no longer holds. Any other case keeps the marker until its 144-block timeout, as before.
The fee request stays reduced. Marking the send and a definitive top-up failure now use the last read of the funding address, so a partial payment from another wallet still lowers the request instead of showing the full shortfall.
No fee request notification while funding covers the fees. When the marker expires and unconfirmed funding at the address already covers the fees, the worker no longer sends the fee request.
Out of Scope
SparkExitRepo: the fee request notification on enteringNeedsFunding. That phase means a new, higher shortfall, and aSeenstate left from earlier funding must not hide it.Design
N/A — no UI changes.
Preview
N/A — Progress shows the same fee request; only when it updates changes.
QA Notes
Setup
Local Spark regtest stack, dev debug build of this head. A Spark balance large enough to start a force transfer, and an on-chain savings balance to pay its funding from.
Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
Automated Checks
SparkExitRepoTest.kt— a started payment the journal never sent frees the request only once its address shows nothing, and only for the exit wallet's journalSparkExitRepoTest.kt— a failed savings payment keeps the request another wallet's payment reducedSparkExitRepoTest.kt— an expired marker sends no fee request while covering funding confirmsEvidence
SparkExitRepoTest,PaykitPaymentProofRepoTest,SendPendingViewModelTestand detekt pass on 14c105b, andSparkExitRepoTestandPaykitPaymentProofRepoTestpass again on 14c105b merged with master after #2142. On a Pixel 10 Pro XL emulator (Android 16) against local regtest, case 1 passes on 14c105b: after relaunch the log shows the unsent payment forgotten, the funding address is unused and Progress shows the full request with Cancel transfer enabled (QA).Gaps
Models used
Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)