Skip to content

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

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

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

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1451
Twin: synonymdev/bitkit-android#2112

Description

  • On iOS a savings payment of the emergency fees that gets no answer already counts as the exit's own payment: Progress shows it paid, with no Amount to pay or funding address, and the own-payment wait brings the ask back if it never lands. What it did not do is say so.
  • Progress now 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. It reads the journal at load and after every savings payment or retry, and goes once the payment lands, is accepted, or the wait forgets it.
  • The ask comes back on the tick that forgets or adopts the exit's own payment, also after a background run did.
  • Paying a refused payment again ends its send only once a node accepted it; one with no answer stays open, so the note shows.
  • 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; a background run that forgets the payment reads the address too.
  • A failed start reads the send journal at once, so Cancel reflects a send that may still land, and Progress pays a refused payment again only while the journal still holds it refused.

Out of Scope

Design

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

Preview

N/A — a savings payment with no answer hasn't been reproduced on a device.

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 — no journey or device run can hold a send unresolved on demand, so none covers this

Automated Checks

  • updated SparkExitReviewTests.swift
  • ran xcodebuild test for SparkExitReviewTests, SparkExitDriverTests and AppStatusExitTests on an iOS 27 simulator
  • ran swiftformat --lint on the changed files and node scripts/validate-translations.js

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

Progress no longer shows Amount to pay or the funding address while a savings send of the fees may still land; it says to wait for it.

Verified: SparkExitReviewTests, SparkExitFundingTests, OnchainSendAttemptServiceTests on the simulator, swiftformat, validate-translations
…e network

A refused send keeps its own retry and never holds the ask. The journal is read on load, before a tick's network calls and after a retry, so Progress never shows the ask first.

Verified: SparkExitReviewTests, SparkExitFundingTests, OnchainSendAttemptServiceTests on the simulator, swiftformat --lint
A retry of unknown outcome may still land, so its send keeps holding the funding ask, as on Android.

Verified: SparkExitReviewTests, SparkExitFundingTests, OnchainSendAttemptServiceTests on the simulator, swiftformat
A start payment of unknown outcome holds the funding ask at once, as on Android.

Verified: SparkExitReviewTests, SparkExitFundingTests, OnchainSendAttemptServiceTests, SparkExitTests on the simulator, swiftformat --lint
@ovitrif ovitrif self-assigned this Nov 26, 2026
@ovitrif
ovitrif requested review from jvsena42 and pwltr November 26, 2026 11:00
@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-26T11:02:58.383519Z 5cef1d8 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

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking gap in regression tests.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects the Spark emergency-exit Progress funding workflow.

The PR appears safe to merge, with a non-blocking gap in regression tests.

Findings

  1. P2 Key behaviors remain untested ▶

Summary

Progress now hides the funding amount and address while a matching Savings send is pending or unknown.

  • Progress waits when a savings payment may still arrive.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read send journal] --> B{Pending or unknown send?}
  B -->|Yes| C{Matches an exit funding address?}
  C -->|Yes, fees still missing| D[Hide amount and address; show wait note]
  B -->|No| E[Show normal funding state]
  C -->|No| E
Loading

Reviews (1) · Last reviewed commit: "fix: read the savings send after any sta..." · Reviewed by Greptile

Comment thread BitkitTests/SparkExitReviewTests.swift Resolved
pwltr
pwltr previously requested 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 5cef1d8. The hold in Bitkit/Managers/SparkExitManager.swift:371 matches the journal by funding address alone, so it can outlive the payment the exit was waiting for.

  • Medium: Restore external funding after an unresolved Savings payment expires. If the payment never arrives, Bitkit/Services/SparkExit/SparkExitDriver.swift:244 clears the tracked txid and the exit asks for funding again. With the journal still unknown, Bitkit/Views/Settings/Advanced/SparkExitViews.swift:868 keeps hiding the amount, address, and copy button on subsequent refreshes. The user can be left waiting indefinitely with no way to fund the exit from Progress.
  • Low candidate: A confirmed short Savings payment can temporarily hide the remainder. If the journal still reads unknown at Bitkit/Managers/SparkExitManager.swift:619 and the next address read sees the confirmed short payment, the funding calculation asks for the remainder while Progress still tells the user to wait.
  • Low candidate: A retry of a refused Savings payment can leave the external funding instructions visible while the retry may still land. The retry retains the refused status through broadcast at Bitkit/Services/OnchainSendAttemptService.swift:918 and Bitkit/Services/OnchainSendAttemptService.swift:943. If the app closes before saving the outcome and the funding host has yet to see the retry, Progress can show the address again on relaunch. A payment from another wallet during that interval could leave excess funds at the exit address and cost an extra mining fee.
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

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

1 finding (1 P1). Holds Progress's funding ask (Amount to pay and the address) while a savings send of the exit fees is pending or of unknown outcome, reads the send journal before the network on load, each tick and after a start or retry payment, and stops a retry of unknown outcome from ending its send as accepted. Reviewed 5cef1d8, full tier.

What I checked, and 5 candidates I ruled out

Read in full: SparkExitManager.swift (load, reset, retrySavingsPayment, refreshRefusedSavingsPayment, tick, start payment, payFunding), the Progress view in SparkExitViews.swift, OnchainSendAttemptService.swift (status model, record, retrySamePayment, blockingAttempt, resumeAcceptedOrdinarySend, abandonUnbroadcast), SparkExitDriver own-payment expiry, SparkExitFunding.reminders.
Compared with Android: SparkExitRepo.noteSavingsSend on bitkit-android master holds on attempt.isUnresolved for a send to the funding address; same shape as here.
Build: static review, not built (iOS does not build on Linux). node scripts/validate-translations.js passes on the head. CI: SwiftFormat, validate and Greptile green; Run Tests and Integration Tests still pending when this was written.

Ruled out

  • Accepted retry never resumed: after an accepted retry blockingAttempt still returns the attempt (follow-up not done) with .accepted, so landingSendAddress is nil and resumeAcceptedOrdinarySend runs as before.
  • Refused send hidden by the hold: landingSendAddress is nil for .rejected, so the refused note and Pay again stay (covered by testOnlyAPendingOrUnknownSendMayStillLand).
  • A send to another address holds the ask: isSavingsSendLanding matches the funding address only.
  • Funded exit still held: the fundingShortfallSats guard drops it once running.
  • Stale hold after reset: landingSendAddress is cleared with the other per-exit state.

Merge confidence: 3/5, one P1 on the expiry path for an unknown send that never went out.

Reviewer model: claude-opus-5-5, with a cross-check of the finding by xiaomi/mimo-v2.6-pro
Reasoning effort: Not exposed (the run records no named effort for either model)

Comment thread Bitkit/Managers/SparkExitManager.swift Resolved
…or it

An unknown savings payment already keeps its txid on the record, so Progress shows it paid and the own-payment wait brings the ask back if it never lands. The journal-keyed hold could outlive that wait and hide the ask for good; it is gone. The note now shows while the exit waits for its own payment and the send journal has not seen it accepted.

Verified: SparkExitReviewTests, SparkExitFundingTests, SparkExitTests on the simulator, swiftformat --lint, validate-translations
A retry of unknown outcome may still land: its send stays unresolved, so Progress keeps saying so. A refused send is read from the journal, so its note never shows as one that may still land.

Verified: SparkExitReviewTests, SparkExitTests on the simulator, swiftformat --lint
A retry now refreshes whether a savings send may still land, and ends
the send only when its own result was accepted. Progress shows the note
only while the funding is still paid from savings.

Verified: SparkExitReviewTests and SparkExitDriverTests on the simulator, swiftformat
A tick that forgets the exit's own payment brings the ask back at once,
and a savings payment of the funding updates the note right away. A
refused later attempt no longer hides the note while the kept payment
may still land.

Verified: none (tests run after this commit)
A funding state read while the exit still awaited its own payment no
longer holds the ask after a background run or tick forgot it, and the
savings note reads the send journal right at load.

Verified: SparkExitReviewTests and SparkExitDriverTests on the simulator, swiftformat
Verified: none (tests run after this commit)
@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Medium: Restore external funding after an unresolved Savings payment expires.

Fixed in 628ccb5: the hold keys on the exit record, so once the own-payment wait clears the txid the amount, address and copy button come back, whatever the journal says. bfff3d4 and eaa1799 bring the ask back on that same tick, and after a background run.

Low candidate: A confirmed short Savings payment can temporarily hide the remainder.

Fixed in 7e8f98b: the note shows only while the funding still counts as paid, so once the address read asks for the remainder, the remainder shows without the note.

Low candidate: A retry of a refused Savings payment can leave the external funding instructions visible while the retry may still land.

The app closing between a broadcast and saving it on the exit is #1459, which covers this window too.

@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 eaa1799. Progress treats unavailable funding-address UTXOs as zero received, so a 20,000-sat Savings payment against a 35,000-sat requote can leave a copyable request for the full 35,000 sats. The correct remainder at 2 sat/vB is 15,136 sats.

Low A connected background tick can clear the txid after observing the short confirmation, then publish the record without refreshing funding. Progress drops the cached paid state and shows the full amount until a foreground read completes. Bitkit/Managers/SparkExitManager.swift:62, Bitkit/Managers/SparkExitManager.swift:1475, Bitkit/Views/Settings/Advanced/SparkExitViews.swift:737.

Low A foreground tick can read the correct remainder, clear the txid, then replace that remainder with the full amount if the extra address read fails. Bitkit/Managers/SparkExitManager.swift:632, Bitkit/Managers/SparkExitManager.swift:636, Bitkit/Managers/SparkExitManager.swift:728.

Low If a refused Savings payment is retried, the retry has no known outcome, and neither transaction lands, Progress eventually allows funding from another wallet. That payment can advance the exit while the retained receipt still blocks new on-chain sends. Send Pending offers to retry the same payment to the already funded address. The user needs a safe way to resolve the old attempt while accounting for its potentially live transactions. Bitkit/Managers/SparkExitManager.swift:432, Bitkit/Services/OnchainSendAttemptService.swift:350, Bitkit/Services/OnchainSendAttemptService.swift:1023, Bitkit/Services/OnchainSendAttemptService.swift:1394, Bitkit/Views/Wallets/Send/SendPendingScreen.swift:397.

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 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. Twin of
synonymdev/bitkit-android#2123.

Verified: SparkExitReviewTests, SparkExitDriverTests, SparkExitTests on the iOS simulator
A start whose savings payment fails reads the send journal at once, so cancel
reflects a send that may still land; a paid-again retry stays paid in memory
when its save fails.

Verified: none (tests run after this commit)
…yment

Verified: none (tests run after this commit)
Progress re-reads the refused send under the lock before paying it again, and
authorizes the retry only while the journal still holds it refused, so a retry
from Send Pending since the last tick is never paid a second time.

Verified: none (tests run after this commit)
@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low A connected background tick can clear the txid after observing the short confirmation, then publish the record without refreshing funding.

Fixed in cd847b3: a background run that changes the phase or forgets the exit's own payment reads the funding address, as a foreground tick does.

Low A foreground tick can read the correct remainder, clear the txid, then replace that remainder with the full amount if the extra address read fails.

Fixed in ef18c55: a failed re-read keeps the tick's first read, so a short payment still counts and only the rest is asked for (the iOS twin of synonymdev/bitkit-android#2123).

Low If a refused Savings payment is retried, the retry has no known outcome, and neither transaction lands, Progress eventually allows funding from another wallet.

It comes from the retry already on master, so it's tracked in #1512 and fixed in its own PRs: Send Pending stops offering that retry while the exit runs, and offers a release once the exit no longer needs it.

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed c8fd11e:

  • a5cc409, 1910f79: master merged in (it brought fix: offer the savings retry after a refused exit start #1449); the savings-send reads now go through its single journal read.
  • 97bb885: a start whose savings payment fails reads the send journal at once, so Cancel reflects a send that may still land; a payment made again stays paid on Progress when its save fails.
  • c8fd11e: Progress pays a refused savings payment again only while the journal still holds it refused, so a retry made from Send Pending since the last tick is never paid twice.

@ovitrif
ovitrif requested a review from pwltr November 26, 2026 16:45

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

Low: Bind the Progress retry to the refused payment the user tapped. If the user resolves payment A through Send Pending, then a different Savings payment B to the same funding address is refused, Progress can still offer the retry for A. The journal refresh in Bitkit/Managers/SparkExitManager.swift:427 picks up B, and the action in Bitkit/Views/Settings/Advanced/SparkExitViews.swift:1076 can dispatch B without the fee confirmation Send Pending would show for that retry. Carry the attempt ID from the button into the retry and require the fresh journal entry to match it.

Low: Preserve the funding outputs the driver sees when it clears a confirmed short Savings payment. In a foreground tick, Bitkit/Managers/SparkExitManager.swift:839 can read an empty address before the driver sees the output, then fall back to that empty response if the final read fails. In a background run, Bitkit/Managers/SparkExitManager.swift:1700 publishes the cleared transaction ID before the reread finishes, and a failed read leaves Progress without the output. Both paths can show the full amount next to the copyable address at Bitkit/Views/Settings/Advanced/SparkExitViews.swift:940. A confirmed 20,000-sat payment against a 35,000-sat requirement at 2 sat/vB can show 35,000 sats due when 15,136 sats remain. Carry the driver's output observation through to the funding state when publishing the updated record.

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

Low: Bind the Progress retry to the refused payment the user tapped.
Low: Preserve the funding outputs the driver sees when it clears a confirmed short Savings payment.

@pwltr Thanks. Both are real, and both are moved to #1515 so this approved head can merge after its device run.

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

QA for c8fd11e:

Tested on iPhone 17 Pro (iOS 27 simulator), local regtest. A local debug-only change reported the force transfer's savings payment as an unknown outcome once, though it was broadcast, and kept the wallet from seeing it unconfirmed.

🟢 Savings payment with an unknown outcome at the start
Savings payment with an unknown outcome at the start

Progress showed the unresolved-payment note with no amount to pay, no funding address and no Cancel transfer, and kept it over several ticks (3 min).

case1-unknown-start2x.mp4

🟢 App terminated and relaunched
App terminated and relaunched

After relaunch, Progress showed the same note, still with no ask and no Cancel.

case2-relaunch2x.mp4

🟢 The payment confirms
The payment confirms

One block later the note went away and no ask came back. The exit broadcast its next step, and the funding address received exactly one payment (7 623 sats).

case3-lands2x.mp4

…-funding-ask

# Conflicts:
#	Bitkit/Managers/SparkExitManager.swift
@ovitrif
ovitrif requested a review from pwltr November 26, 2026 22:38
@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 3ce2533, resolving the conflicts with #1506 in SparkExitManager: pay from savings keeps the locked funding read from #1506 and this PR's authorize check. refreshFundingSeen keeps this PR's fallback for earlier addresses and returns the UTXOs. This also includes the build fix from #1519. A new device run on this head follows.

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

QA for 3ce2533:

Tested on iPhone 17 Pro (iOS 27 simulator), local regtest. A local debug-only change reported the force transfer's savings payment as an unknown outcome once, though it was broadcast, and kept the wallet from seeing it unconfirmed.

🟢 Savings payment with an unknown outcome at the start
Savings payment with an unknown outcome at the start

Progress showed the unresolved-payment note with no amount to pay, no funding address and no Cancel transfer, and kept it over several ticks (3 min).

case1-unknown-start2x.mp4

🟢 App terminated and relaunched
App terminated and relaunched

After relaunch, Progress showed the same note, still with no ask and no Cancel.

case2-relaunch2x.mp4

🟢 The payment confirms
The payment confirms

One block later the note went away and no ask came back. The exit broadcast its next step, and the funding address received exactly one payment (22 754 sats).

case3-lands2x.mp4

…-funding-ask

# Conflicts:
#	Bitkit/Managers/SparkExitManager.swift
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 27ef013 (with #1519, #1492 and #1493). The one conflict, refreshFundingSeen, keeps this PR's fallback to the tick's earlier read, so SparkExitManager is the same as at 3ce2533. A device run on this head follows.

@piotr-iohk
piotr-iohk self-requested a review November 27, 2026 11:09

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved 27ef013. I reran Run Tests. The failure looks like a timing issue in ProfileRecoveryUITests while tapping the transient ProfilePubkyCopiedToast. The same test passed on the master base.

Run Tests rerun · Passing master run

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

QA for 27ef013:

Tested on iPhone 17 Pro (iOS 27 simulator), local regtest. A local debug-only change reported the force transfer's savings payment as an unknown outcome once, though it was broadcast, and kept the wallet from seeing it unconfirmed.

🟢 Savings payment with an unknown outcome at the start
Savings payment with an unknown outcome at the start

Progress showed the unresolved-payment note with no amount to pay, no funding address and no Cancel transfer, and kept it over several ticks (3 min).

case1-unknown-start2x.mp4

🟢 App terminated and relaunched
App terminated and relaunched

After relaunch, Progress showed the same note, still with no ask and no Cancel.

case2-relaunch2x.mp4

🟢 The payment confirms
The payment confirms

One block later the note went away and no ask came back. The exit broadcast its next step, and the funding address received exactly one payment (7 623 sats).

case3-lands2x.mp4

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

Consider separating Spark exit funding progress from Savings send recovery so each can resolve on its own evidence.

Reviewed 27ef013.

Low candidate: If a Savings retry made from Progress has an unknown outcome and another transaction from the same wallet confirms spending one of its inputs, the exit can stop waiting while unrelated Savings sends stay blocked. Bitkit/Managers/SparkExitManager.swift:463 leaves the journal open, Bitkit/Services/SparkExit/SparkExitDriver.swift:244 expires only the exit's wait, and Bitkit/Services/OnchainSendAttemptService.swift:872 still requires the original inputs on retry. The journal ignores the competing transaction at Bitkit/Services/OnchainSendAttemptService.swift:1418, and the ordinary funding payment is ineligible for release at Bitkit/Services/OnchainSendAttemptService.swift:350. Whether an ordinary retry or wallet reconciliation can clear the journal after the competing spend confirms is still open.

Device checks: app-status-emergency-exit.xml passed on an iOS simulator.

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 candidate: If a Savings retry made from Progress has an unknown outcome and another transaction from the same wallet confirms spending one of its inputs, the exit can stop waiting while unrelated Savings sends stay blocked.

Tracked in #1528, starting with whether an ordinary retry or wallet reconciliation already clears the journal once the competing spend confirms. It'll be fixed in the follow-up PR for 3.2.0 if needed, so this head stays as approved.

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved on 27ef013, device run on this head posted above, all checks green.

@ovitrif
ovitrif merged commit 9b6dbac into master Nov 27, 2026
22 of 23 checks passed
@ovitrif
ovitrif deleted the fix/spark-exit-hold-funding-ask branch November 27, 2026 14:39
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 asks for funding while a savings payment may still confirm

4 participants