Skip to content

fix: keep the force transfer's fee request in step with the savings send - #2155

Merged
ovitrif merged 2 commits into
masterfrom
fix/spark-exit-savings-marker-gaps
Nov 27, 2026
Merged

ovitrif merged 2 commits into
masterfrom
fix/spark-exit-savings-marker-gaps

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

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 send journal read succeeds and holds no attempt;
    • the journal is the exit wallet's, checked before and after the read;
    • the funding address was never used, in a block or the mempool.

    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

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

  • 1. Start a force transfer, tap Pay from savings, and kill the app before the payment is sent → after relaunch Progress offers Pay from savings again with the full request, and no payment left the wallet — process death between marking and dispatch is not in Capabilities
  • 2. Start a force transfer, pay part of its funding from another wallet, then make Pay from savings fail (for example, savings below the request) → Progress keeps the reduced request, not the full shortfall — funding from a second wallet is not in Capabilities
  • 3. Leave a savings payment's marker to expire (144 blocks) while unconfirmed funding at the address already covers the fees → no fee request notification arrives — mining 144 blocks under a held marker is not in Capabilities

Automated Checks

  • added 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 journal
  • added SparkExitRepoTest.kt — a failed savings payment keeps the request another wallet's payment reduced
  • added SparkExitRepoTest.kt — an expired marker sends no fee request while covering funding confirms

Evidence

SparkExitRepoTest, PaykitPaymentProofRepoTest, SendPendingViewModelTest and detekt pass on 14c105b, and SparkExitRepoTest and PaykitPaymentProofRepoTest pass 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

  • 2: not run. Once another wallet's funding shows up, Pay from savings refuses before it starts, so the app can't reach a failed savings payment after a partial payment; covered by the unit test.
  • 3: not run. Regtest confirms the covering funding in the next block, so it can't stay unconfirmed for 144 blocks; covered by the unit test.

Models used

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

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
@ovitrif ovitrif self-assigned this Nov 27, 2026
@ovitrif
ovitrif requested review from jvsena42 and pwltr November 27, 2026 11:39
@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-27T11:40:56.213774Z 14c105b 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.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Keeps the force transfer’s fee request in step with its savings payment.

  • An unsent savings payment no longer keeps the fee request hidden.
  • Partial funding still reduces the fee request around a savings send.
  • Covered funding no longer triggers a returning fee reminder.

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]
Loading

Reviews (1) · Last reviewed commit: "fix: keep the last funding read from the..." · 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. 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: payFunding marks and sends under tickMutex, and all three callers of the suspend keepAcceptedSavingsSend (load, tickLocked and the retry's isDue check inside payFunding) 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() reads lightningService.currentWalletIndex, and the wallet is compared to the exit's before the read and again inside isStartedSendNeverSent, 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, and isAddressUsed counts mempool as well as chain transactions.
  • A stale last read reducing the wrong ask: lastRead returns 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)

@github-actions

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 14c105b (run).

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

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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, payHigherFeeLocked and SparkExitMath.savingsRefusal are untouched. The new fundingState only feeds Progress and the refusal's funding argument.
  • The new marker clear (keepAcceptedSavingsSend) cannot release a payment that went out:
    • current() is null only with no keychain entry, or after releaseInterruptedUnsubmittedPreparation deleted an attempt that never dispatched (initialDispatchAttempted is persisted before native dispatch).
    • Keychain or decode errors keep the marker.
    • A journal entry replaced by a later admit means the exit's send was accepted, and isAddressUsed (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 paySavingsRefusal keeps its refusal, so it is offered again and paid once.
  • Every caller of keepAcceptedSavingsSend holds tickMutex, and payFunding and retrySavingsPayment hold it from markSavingsSend to the saved txid.
  • Cancellation: both new reads use runSuspendCatching, and clearSavingsSend does not suspend. lastFundingRead is 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

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@jvsena42

LOW (PR body, no line to anchor): … the body has no QA Notes … Also, the Twin: line names issues; leave it out until the iOS PR exists.

Fixed in the PR body: QA Notes added, with Journeys N/A — not drivable; see Manual Tests. and Manual Tests 1–3, one per rule. The Twin: line is gone until the iOS PR opens.

Whichever merges second should rerun SparkExitRepoTest.

#2142 merged first. On this head merged with master, SparkExitRepoTest and PaykitPaymentProofRepoTest pass, and the merge is clean.

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

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 out
A 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.

caseA-restart2x.mp4

Not run on device:

  • A reduced fee request after a failed top-up: Pay from savings reads the address first and stops once another wallet's funding is there, so the app never reaches a failed top-up after a partial payment.
  • No fee request notification at marker expiry: the funding must stay unconfirmed for 144 blocks, and every regtest block here confirms it.

@pwltr pwltr 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.

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

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low: The fee reminder can be missed when covering funding drops out.
Low candidate: An empty send journal and a single address-history response can release a hold for a payment that could still arrive.
Low: A failed funding-address read can undo the restored remainder.

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.

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved on 14c105b, device run on this head posted above, all checks green.

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.

bug: progress keeps a stale fee request after a savings payment

4 participants