Skip to content

fix: hold the funding ask while a savings send is unresolved - #2112

Merged
ovitrif merged 8 commits into
masterfrom
fix/spark-exit-hold-funding-ask
Nov 26, 2026
Merged

ovitrif merged 8 commits into
masterfrom
fix/spark-exit-hold-funding-ask

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2059
Closes #2123
Twin: synonymdev/bitkit-ios#1457

Description

  • Fixes Progress asking for the emergency fees (Amount to pay and the funding address) after a savings payment of them got no answer, so paying from another wallet could pay them twice. A start, a refused start paid again, or a node-refused payment paid again could end pending without keeping its transaction on the exit.
  • Its transaction (from the error, or else from the send journal) is now kept as the exit's own payment, as one of unknown result already was: Progress shows it paid, cancel stays off, and the own-payment wait brings the ask back if it never lands.
  • Progress notes "Your savings payment hasn't confirmed yet. Wait for it before you pay from another wallet." while the exit waits for its own payment, the funding still counts as paid, and the send journal has not seen it accepted. Every payment and retry refreshes that state at once.
  • A retry the send journal rolled back to refused (it never went out) is not kept, so its retry is offered again.
  • The ask comes back on the tick that forgets the exit's own payment, and Progress holds it before the first read of the funding address when the exit keeps a payment.
  • When the funding address read after that tick fails, Progress goes by the tick's first read, so a short savings payment that confirmed still counts and only the rest is asked for (bug: force transfer asks for the whole fee after a short savings payment confirmed #2123).
  • A higher fee paid from savings with no answer is kept the same way, with its fee bump.

Out of Scope

Design

N/A — no design available. One new note on Progress, translated into every locale.

Preview

See the QA comment: #2112 (comment)

QA Notes

Journeys

N/A

Manual Tests

  • 1. start an emergency exit paying from savings while its savings send has no answer → Progress shows "Your savings payment hasn't confirmed yet. Wait for it before you pay from another wallet." and no Amount to pay or funding address — checked on an emulator with a local debug-only change that drops the send's answer (QA comment)

Automated Checks

  • updated SparkExitRepoTest.kt; the kept, rolled-back and forgotten payment tests, and the failed re-read test, fail without the fix
  • updated SparkExitViewModelTest.kt
  • ran ./gradlew testDevDebugUnitTest --tests '*SparkExit*'
  • ran ./gradlew detekt

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: 7

A savings payment that ends with no answer keeps its transaction as the exit's own payment, as one of unknown result already did, so Progress shows it paid and the own-payment wait brings the ask back if it never lands. Progress says to wait for it while the send journal has not seen it accepted.

Verified: SparkExit unit tests, detekt
A failed check now ends the test instead of leaving runTest driving the loop.

Verified: SparkExit unit tests, detekt; the kept-payment check fails without the fix
A retry, accepted or not, and a start paid with no answer now update
whether a savings send may still land, so Progress shows its note only
while it may. A tick that forgets the exit's own payment brings the ask
back at once.

Verified: none (tests run after this commit)
A retry the send journal rolled back to refused is never kept as the
exit's payment. Progress shows the may-still-land note only while the
funding is paid from savings, and holds the ask before the first read
of the funding address when the record keeps a payment.

Verified: SparkExit unit tests and detekt
Verified: SparkExit unit tests and detekt
@ovitrif ovitrif self-assigned this Nov 26, 2026
@ovitrif
ovitrif requested review from jvsena42 and pwltr November 26, 2026 13:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 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-26T13:24:12.994123Z 544ec02 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 26, 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 unresolved savings payments on the exit so Progress does not invite a second payment.

  • The exit keeps a savings payment while its result is unclear.
  • Progress tells people to wait while a savings payment may still arrive.

ovitrif explicitly deferred the app-stop window between broadcast and saving the payment. ovitrif also excluded unresolved higher-fee savings payments because that existing path has no funding ask.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Savings send] --> B{Result}
  B -->|Accepted or unknown| C[Keep payment on exit]
  B -->|Pending error| D{Journal rolled retry back?}
  D -->|Yes| E[Keep retry available]
  D -->|No| C
  C --> F[Hide funding ask]
  F --> G{Payment arrives?}
  G -->|Yes| H[Use funding]
  G -->|Wait expires| I[Forget payment and restore ask]
Loading

Reviews (1) · Last reviewed commit: "test: cover the kept, rolled-back and fo..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 1eef286 (run).

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

@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. A savings payment of the exit's fees that ends with no answer is now kept as the exit's own payment (txid from the error, else from the send journal unless the journal says refused), so Progress holds the funding ask and shows a wait note instead of offering another wallet. Reviewed 544ec02, full tier, static: Bitkit Android PRs are not built on this reviewer's machine, so this rests on the code and CI.

What I checked, and 4 candidates I ruled out

Read in full: payFunding, keepFundingPayment, pendingFundingTxid, noteSavingsSend, savingsSend, retrySavingsPayment and the tick's funding refresh in SparkExitRepo.kt; isAwaitingOwnPayment in SparkExitRecord.kt; isSavingsSendLanding and progressFunding in SparkExitViewModel.kt; the Progress row.
Tests read: the kept, rolled-back and forgotten payment cases in SparkExitRepoTest.kt, and SparkExitViewModelTest.kt.
CI: build-and-test, lint, detekt, compose-ui green.

Ruled out

  • A never-sent payment holding the ask forever: pendingFundingTxid drops a Rejected journal entry, and a kept txid that never lands is forgotten by the existing own-payment wait, whose tick now refreshes the funding state when fundingPaymentTxid changes.
  • Retry path losing the cleared refusal flag: the old isSavingsPaymentRefused = false is replaced by noteSavingsSend, which recomputes it from the journal on both outcomes.
  • Save failure on retry now swallowed: same contract as the start path already had (kept in memory, saved by a later tick), stated in the kdoc.
  • Paid shown before any funding read for an exit with no payment: progressFunding falls back to Paid only when isAwaitingOwnPayment, which needs a kept txid not yet in funding.

Merge confidence: 4/5, no findings, but manual test 1 cannot be run on demand and no device run covers the new note.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer carries the model id only)

pwltr
pwltr previously approved these changes Nov 26, 2026

@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 544ec02.

Low: A failed funding-address read can make Progress ask for the full emergency fee after a short savings payment has already confirmed. The first read calculates the amount still due, and the driver clears the savings payment ID after seeing the short confirmation. That ID change triggers another read at SparkExitRepo.kt:328. If it fails, SparkExitRepo.kt:431 recalculates the amount without the confirmed output. Preserve the verified remainder when the second read fails and the funding requirement is unchanged.

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

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low: A failed funding-address read can make Progress ask for the full emergency fee after a short savings payment has already confirmed.

Confirmed, and left out of this PR so the approval stands: it needs that second read to fail right after the first succeeded, and the next successful read restores the remainder. Tracked in #2123.

A tick that forgets the exit's own payment reads the funding address again;
when that read fails it now goes by the tick's first read, so a short savings
payment still counts and only the rest is asked for.

Verified: ./gradlew testDevDebugUnitTest --tests '*SparkExit*' (the new test failed before the fix)
A higher fee whose savings payment got no answer may still go out: the exit
now keeps it like one of unknown result, with its fee bump, and Progress says
it may still land.

Verified: ./gradlew testDevDebugUnitTest --tests '*SparkExit*'
Verified: ./gradlew testDevDebugUnitTest --tests '*SparkExit*', ./gradlew detekt
@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 1eef286:

@ovitrif
ovitrif requested a review from pwltr November 26, 2026 15:56
@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

QA for 1eef286:

Tested on Pixel emulator (Android 16), local regtest. A local debug-only change broadcast the exit's savings payment and then dropped its answer once.

🟢 Savings payment with no answer holds the funding ask
Savings payment with no answer holds the funding ask

Progress shows "Your savings payment hasn't confirmed yet. Wait for it before you pay from another wallet." with no Amount to pay, no funding address and no Cancel.

case1-unanswered-start2x.mp4

🟢 The hold survives a relaunch
The hold survives a relaunch

After a force-stop and relaunch, Progress shows the same note, still with no ask and no Cancel.

case2-relaunch2x.mp4

🟢 The payment lands and the exit goes on
The payment lands and the exit goes on

Once it confirms, the note goes, no ask comes back, the emergency fees show confirmed and the exit broadcasts its first transaction; the funding address holds exactly one payment.

case3-lands2x.mp4

🟠 A higher fee from savings with no answer
A higher fee from savings with no answer

Not run: regtest fee estimates stay flat, so Progress never offered a higher fee. Covered by SparkExitRepoTest.


@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 1eef286.

Low — Progress can ask for the full emergency fee after the driver has seen a confirmed partial Savings payment. If the first address read misses the output, SparkExitDriver.kt:507 can see it on a later read and clear the saved transaction ID. If the final read fails, SparkExitRepo.kt:330 falls back to the first list and asks for the full shortfall. Extend the failed-refresh test so the partial output first appears during the driver's reads, and preserve that observation for the amount shown in Progress.

Low candidate — A failed journal read can make a rolled-back Savings retry appear paid. OnchainSendCoordinator.kt:229 can discard an unsent retry and return a pending error naming that transaction. If the journal read at SparkExitRepo.kt:998 also fails, the exit trusts the discarded ID and hides the retry until its payment wait expires. Extend the rollback test to fail that separate read and check whether Progress still offers the retry once the journal is readable again.

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

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low — Progress can ask for the full emergency fee after the driver has seen a confirmed partial Savings payment.

Low candidate — A failed journal read can make a rolled-back Savings retry appear paid.

Both need a failed read on top of a narrow timing, so they're in #2134 for a follow-up, and this PR keeps its approval.

@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 1eef286: no findings.

Checked and clean:

  • No double funding while held. A kept txid makes fundingState Paid, so Progress shows no amount or address. Before the first read, progressFunding falls back to Paid when isAwaitingOwnPayment. The 4 h funding reminder needs fundingPaymentTxid == null. If an earlier external payment and the savings send both land, the driver adopts what covers the shortfall and sweeps the rest back to savings (unchanged design).
  • No dead end after a failed send. withOwnPaymentLooked forgets the kept txid after 3 blocks unknown or 144 blocks, and the forget tick now re-reads funding, so the ask comes back with a notification. A retry that never dispatched is rolled back and Rejected is never kept, so the retry stays offered.
  • Only OnchainSendPendingError keeps a txid (its own, or the journal's when evidence is Pending/Unknown and the address matches). I traced every source of that error, and all carry a txid. The note shows only while the send is unresolved and not refused.
  • Cancel/Back/relaunch while held: canCancel needs no txid and no unresolved savings send, re-read under tickMutex. Every exit payment path runs NonCancellable. The txid is saved by keepFundingPayment and re-saved by the driver if that save fails.
  • New string lightning__spark_exit__savings_unresolved is in all 16 locales, placed alphabetically, with no placeholders and apostrophes escaped. It renders in BodyS with no maxLines inside the scroll column; the longest is fr (117 vs 91 chars).
  • Parity with synonymdev/bitkit-ios#1457: same key, wording, identifier and note condition.

perf: not relevant (one journal read per exit payment, one extra UTXO read on a tick that changes the funding txid).

Device gate (partial): 1eef286 — not run yet; the note needs a savings send with a dropped answer on the local Spark stack (the body's debug fault). 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

@jvsena42

Copy link
Copy Markdown
Member

Device gate (partial): 1eef286 — run on the Android emulator against the local bitkit-docker Spark stack (PR build plus the one-line sparkSharesNodeChain patch, since this branch doesn't contain #2139).

  • Reproduced without the debug fault: airplane mode turned on just as the exit's savings send dispatches. Progress shows SparkExitSavingsUnresolved with the exact text, no Amount to pay, no funding address and no Cancel. It stays held through six relaunches.
    21:41:28.529 ERROR [LightningRepo.kt:351] Error executing 'sendOnChain' [OnchainSendPendingError='On-chain send outcome is unknown; do not send again']
    21:41:28.876 ERROR [SparkExitRepo.kt:791] Failed to start the Spark exit [OnchainSendPendingError='On-chain send outcome is unknown; do not send again']
    
  • Forget path (the tx never left): the note stays through blocks 1 and 2. After block 3 the ask comes back with Amount to pay ₿ 10 795 and the address, which holds 0 sats on chain.
  • A send that lands: the note goes once the wallet sees the tx in the mempool, before any block. The exit then moves on after one block with exactly one funding payment.
  • l10n: the note in fr, pl, el and de reads correctly and isn't clipped.

Still running: the driver's run of the runbook.

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved on 1eef286, CI green, and the device run on this head passed (QA above).

@ovitrif
ovitrif merged commit aae7897 into master Nov 26, 2026
32 of 34 checks passed
@ovitrif
ovitrif deleted the fix/spark-exit-hold-funding-ask branch November 26, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants