Skip to content

fix: release savings payments a force transfer no longer needs - #1518

Merged
ovitrif merged 10 commits into
masterfrom
fix/spark-exit-release-unneeded-funding
Nov 27, 2026
Merged

ovitrif merged 10 commits into
masterfrom
fix/spark-exit-release-unneeded-funding

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1512
Twin: synonymdev/bitkit-android#2142

Description

  • Fixes a savings payment to a force transfer's funding address blocking every new on-chain send once the exit no longer needs it. The payment had no answer from the node, so it stayed unresolved, and Send Pending could only pay it again, to an address the exit no longer watches.
  • Send Pending now tells such a payment apart by its address (the exit's, or an earlier exit's) and offers to cancel it once the exit no longer needs it: the exit ended (a cancelled exit is covered too, though Progress offers no cancel while the payment is unanswered), or another wallet funded it and none of this payment's transactions landed or are still awaited. The cancel goes through the existing release (it first checks the payment never reached the network, then spends its coins back to the wallet), with its own note.
  • While the exit still needs the payment, Send Pending keeps Retry. Like Progress' Pay from savings, the retry reads the funding address right before sending and refuses when the exit no longer asks for the funding, another wallet's funding reached the address, the exit or address can't be read, or its cancel was approved.
  • An approved cancel is finished from Send Pending even after the exit's record is gone.

Out of Scope

Tracked in #1528:

  • An ended exit's address is not kept when a new exit replaces its record, so a payment to it is treated as an ordinary send. This predates this PR.
  • Progress' Pay from savings refused because funding arrived does not update the funding shown until the next refresh.

Design

N/A — no design available. One new note in the cancel confirmation, translated into every locale.

Preview

N/A — a savings payment the exit no longer needs, with no answer from the node, hasn't been reproduced on a device yet.

QA Notes

Journeys

N/A

Manual Tests

  • 1. start a force transfer paying from savings while its savings send has no answer, then fund the exit from another wallet → Send Pending offers to cancel the savings payment, and new on-chain sends work after it
  • 2. same, but the exit still asks for the funding → Send Pending offers Retry, which pays it once

Automated Checks

  • added SparkExitFundingReleaseTests.swift and SparkExitFundingReleaseServiceTests
  • updated PaykitPaymentProofServiceTests.swift and OnchainSendAttemptServiceTests.swift
  • ran xcodebuild test for those on an iOS 27 simulator
  • ran swiftformat --lint on the changed files

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 send to a Spark exit's funding address, told apart by that
address (the current record's or an earlier exit's), is released through
the existing release path once the exit no longer needs it: the exit was
cancelled or ended, or it holds all its funding and none of it is the
send's. One the exit adopted, or still waits for, is never released.

Send Pending never offers "Retry original payment" for an exit's funding,
which Progress owns, and offers the release with its own note once the
exit no longer needs it. Progress' Pay from savings retry and Send
Pending's retry read the exit again right before dispatch and refuse
once it is funded.

Verified: xcodebuild test of the BitkitTests unit suite (CI selection);
the new release, hidden-retry and pay-again tests fail with the gate
stubbed out; swiftformat --lint; validate-translations.js
A savings send's txid stayed on the exit record after another wallet funded it, so the send was never released. Only a payment the exit still waits for keeps it now. A release already approved also stops for a send that landed as leftover, and paying again refuses once another wallet's funding reached the address.

Verified: xcodebuild test SparkExitFundingReleaseTests, PaykitPaymentProofServiceTests, OnchainSendAttemptServiceTests
Once a release of a savings send to a force transfer's funding address is approved, Send Pending finishes it even after the exit's record is gone, instead of offering Retry. Paying again now ignores the exit's own adopted outputs and their change when it looks for other funding.

Verified: xcodebuild test SparkExitFundingReleaseServiceTests, SparkExitFundingReleaseTests, PaykitPaymentProofServiceTests, OnchainSendAttemptServiceTests
Send Pending hid Retry for every savings send to a force transfer's funding address, so an unresolved one Progress could not pay again stayed stuck and blocked new on-chain sends. It offers Retry again unless the release is offered, and the retry checks right before dispatch that the exit still asks for the funding and nothing else reached the address, the same check Progress uses. A send whose release was approved is never paid again.

Verified: xcodebuild test SparkExitFundingReleaseTests, SparkExitFundingReleaseServiceTests, PaykitPaymentProofServiceTests, OnchainSendAttemptServiceTests; swiftformat --lint on the changed files
A savings send whose cancel was approved is refused before the exit-funding check, so it stays refused once the exit's record is gone, and Send Pending hides Retry for it.

Verified: xcodebuild test SparkExitFundingReleaseTests, SparkExitFundingReleaseServiceTests, PaykitPaymentProofServiceTests, OnchainSendAttemptServiceTests; swiftformat --lint
@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-26T20:05:01.456154Z 895d096 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: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Lets users cancel unresolved savings payments that a force transfer no longer needs.

  • Send Pending can cancel savings payments a Spark exit no longer needs.

No actionable issues found. Tests were not run during this review. Native iOS visual checks were unavailable in this Linux environment.

Acknowledged scope from ovitrif:

  • An ended exit’s address is not retained when a new exit replaces its record; this predates the PR and is excluded.
  • Progress does not immediately refresh its funding display after refusing payment because funding arrived; this is explicitly deferred.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Unresolved savings payment] --> B{Matches an exit address?}
  B -->|No| C[Keep ordinary send behavior]
  B -->|Yes| D{Exit still needs payment?}
  D -->|Yes| E[Offer Retry]
  E --> F[Recheck exit and funding address]
  F --> G[Retry only when allowed]
  D -->|No| H[Offer Cancel]
  H --> I[Check network for original transactions]
  I --> J[Spend original coins back to wallet]
  J --> K[Remove pending send after release succeeds]
Loading

Reviews (1) · Last reviewed commit: "fix: never pay an approved exit funding ..." · 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. iOS twin of synonymdev/bitkit-android#2142: Send Pending releases an unresolved savings send to a Spark exit's funding address once the exit no longer needs it, and Retry checks the exit again right before dispatch. Reviewed 895d096, full tier, static.

What I checked, and 5 candidates I ruled out

Read in full: SparkExitFundingRelease.swift, and the changed parts of OnchainSendAttemptService.swift, PaykitPaymentProofService.swift, SparkExitManager.swift, SendPendingScreen.swift
Call sites traced: canBeAbandoned (approveRelease, recordRelease, abandonUnbroadcast in OnchainSendAttemptService), onchainRequestHasEnded, abandonUnbroadcastOnchainPayment, finishRelease, loadAbandonableAttempt, both retrySamePayment authorize closures, the cancel path that adds the forgotten address to earlierAddressStore
Build: not built. iOS does not build on Linux, so CI is the gate (Run Tests, Run Integration Tests, both still pending at review time; SwiftFormat and validate passed)

Ruled out

  • mayFundSparkExit makes every ordinary send pass canBeAbandoned (the rewritten OnchainSendAttemptServiceTests case drops the store-level refusal): release still needs onchainRequestHasEnded, and for these sends that is exitNoLongerNeeds, true only when the address is the stored exit's or an earlier exit's. storedExit returns nil for another wallet's attempt or an unreadable store, and then nothing is released.
  • Spark deposit funding treated as exit funding: mayFundSparkExit excludes sparkFunding == true, and the test asserts it.
  • Retry pays over another wallet's funding: the Send Pending closure and SparkExitManager's refused-payment retry both call authorizePayAgain before dispatch. A nil utxos read refuses, and .paid passes only when every new UTXO is one of this attempt's candidates.
  • Behaviour differs from Android: isExitFunding, exitNoLongerNeeds, isAdopted and mayPayAgain match the Kotlin twin case for case, including the approved-release refusal.
  • Release shown alongside Retry: offersRetry hides Retry for exit funding once a release is offered or approved, the same rule as Android's canRetry.

Merge confidence: 4/5. No findings, but the unit and integration suites were still running at review time and nothing here builds iOS.

Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: Not exposed (this runtime does not report it)

…ase-unneeded-funding

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

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 8a845f3, resolving a conflict in SparkExitManager.retrySavingsPayment: it keeps master's locked funding read and funding-seen check from #1506, and runs this PR's authorize check before dispatch. This also includes the build fix from #1519.

The manager takes its send journal, the shared one by default, so a test
can drive retrySavingsPayment over its own journal.

Verified: xcodebuild test SparkExitFundingReleaseTests, SparkExitFundingReleaseServiceTests, PaykitPaymentProofServiceTests, OnchainSendAttemptServiceTests, SparkExitReviewTests (pass; the new test fails with the read guard removed), swiftformat --lint
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Added in 56b4444: a test that Pay from savings throws and pays nothing when the funding address can't be read, as @piotr-iohk suggested on #1519 (#1519 (review)). It fails with that read check removed. SparkExitManager now takes its send journal (the shared one by default) so the test can use its own.

Pay again while the exit still asks, waits for this payment or holds its
own coin: a retry re-signs the same inputs, and what savings pays beyond
the ask comes back as leftover. An unreadable list of earlier exit
addresses reads as empty, so it never refuses an ordinary send's Retry.

Verified: xcodebuild test SparkExitFundingReleaseTests, SparkExitFundingReleaseServiceTests, PaykitPaymentProofServiceTests, OnchainSendAttemptServiceTests, SparkExitReviewTests (pass; the partial-payment and unreadable-list tests fail on 56b4444), swiftformat --lint
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 4e64a12, the twin of @jvsena42's review on synonymdev/bitkit-android#2142 (synonymdev/bitkit-android#2142 (review)):

  • Retry after a partial payment from another wallet. It's refused only when other wallets' coins alone cover the funding. Otherwise it's allowed while the exit asks, waits for this payment, or holds this payment's own unconfirmed coin. A retry re-signs the same inputs, so it never pays twice, and what savings pays beyond the ask comes back as leftover.
  • An unreadable list of earlier exit addresses now reads as empty, so it no longer refuses an ordinary send's Retry.

A device run on this head follows.

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

Medium candidate: BitkitTests/SparkExitFundingReleaseTests.swift:38 and BitkitTests/SparkExitFundingReleaseTests.swift:80 call helpers on the SwiftUI view from synchronous tests without @MainActor. If Xcode 26.6 diagnoses the inferred actor isolation under the project's build settings, BitkitTests cannot compile.

A force transfer can ask for more funding at the same address after it first qualifies for Cancel. The screen caches that eligibility, and the service can persist the release decision before the user approves the fee.

Low: Bitkit/Views/Wallets/Send/SendPendingScreen.swift:341 stops checking eligibility once Cancel appears. If the exit asks for a top-up while the sheet stays open, Cancel fails and Retry stays hidden until the user reopens the sheet.

Low: Bitkit/Services/PaykitPaymentProofService.swift:809 saves releaseApproved before the fee and PIN prompts. If the user declines and the exit subsequently asks for a top-up, the saved flag still blocks Retry after reopening Send Pending. Persist the approval once the user has approved the fee and completed any required authentication.

Low: BitkitTests/SparkExitFundingReleaseTests.swift:104 overwrites and deletes the active wallet's earlier-address file. A rerun in a simulator that already has saved exit history can erase it. Use a temporary store for the corrupt-file fixture.

Low: BitkitTests/SparkExitFundingReleaseTests.swift:82 repeats the foreign-payment case at line 69 with a different dummy txid. The Retry assertion in BitkitTests/PaykitPaymentProofServiceTests.swift:4412 also repeats the two visibility cases at BitkitTests/SparkExitFundingReleaseTests.swift:38. Keep the ownership assertions in the service test.

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

QA for 4e64a12:

Tested on iPhone 17 Pro (iOS 27 simulator), local regtest. A local debug-only change made the force transfer's savings payment get no answer once: it was never broadcast and was kept as an unknown outcome.

🟢 Another wallet funds the force transfer in full
Another wallet funds the force transfer in full

After another wallet paid the whole funding (7 700 of 7 623 sats), the force transfer moved on with it. Send Pending showed the savings payment with Cancel expired payment and the force transfer's own note, and no Retry. Cancelling sent its coins back to savings (703 sats fee), and a new 20 000 sats on-chain send went through right after.

case1-cancel2x.mp4

🟢 Another wallet pays only part of the funding
Another wallet pays only part of the funding

After another wallet paid 3 000 of the 7 623 sats, Send Pending offered Retry original payment and no cancel. Retry paid the funding address once (7 623 sats, one transaction). One block later the force transfer confirmed its emergency fees and published its next transaction.

case2-retry2x.mp4

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Medium candidate: BitkitTests/SparkExitFundingReleaseTests.swift:38 and BitkitTests/SparkExitFundingReleaseTests.swift:80 call helpers on the SwiftUI view from synchronous tests without @MainActor.

BitkitTests compiles and passes in CI on this head (Run Tests), so the inferred isolation isn't diagnosed under the project's settings.

Low: … stops checking eligibility once Cancel appears.
Low: … saves releaseApproved before the fee and PIN prompts.
Low: … overwrites and deletes the active wallet's earlier-address file.
Low: … repeats the foreign-payment case.

All four are valid. They're tracked in #1528, which goes in a follow-up PR for 3.2.0 together with the Android twin. That keeps this head and its device run as they are.

@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 4e64a12. No actionable findings.

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

…ase-unneeded-funding

# Conflicts:
#	Bitkit/Managers/SparkExitManager.swift

Verified: SparkExitFundingReleaseTests, SparkExitReviewTests and PaykitPaymentProofServiceTests pass on an iOS simulator
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 7585390 to resolve the conflict with #1457 in SparkExitManager.retrySavingsPayment. It keeps master's handling of a payment refused again, and its guard that only a rejected attempt is paid again, plus this PR's authorizePayAgain check before the retry goes out. fundingReread is taken from master as is.

The Spark exit, payment proof and funding release tests pass on the merge. A device run on this head follows.

@ovitrif
ovitrif requested a review from pwltr November 27, 2026 14:50

@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 7585390. No actionable findings. The merge preserves the rejected-attempt guard and the funding check before retry dispatch, and keeps the earlier funding read as a fallback when the reread fails.

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

QA for 7585390:

Tested on iPhone 17 Pro (iOS 27 simulator), local regtest. A local debug-only change made the force transfer's savings payment get no answer once: it was never broadcast and was kept as an unknown outcome.

🟢 Another wallet funds the force transfer in full
Another wallet funds the force transfer in full

After another wallet paid the whole funding (7 700 of 7 623 sats), the force transfer moved on with it. Send Pending showed the savings payment with Cancel expired payment and the force transfer's own note, and no Retry. Cancelling sent its coins back to savings (703 sats fee), and a new 20 000 sats on-chain send went through right after.

case1-cancel2x.mp4

🟢 Another wallet pays only part of the funding
Another wallet pays only part of the funding

After another wallet paid 3 000 of the 7 623 sats, Send Pending offered Retry original payment and no cancel. Retry paid the funding address once (7 623 sats, one transaction). One block later the force transfer confirmed its emergency fees and published its next transaction.

case2-retry2x.mp4

@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 7585390: no code findings. Both of the Android fixes from synonymdev/bitkit-android#2142 are here in the same shape:

  • mayPayAgain (SparkExitFundingRelease.swift:44-70) is a case-for-case port. It allows a retry in .ask whatever was received, in .paid only for this payment's own txid, and in .seen only while this payment's own coin is unconfirmed. It refuses when other wallets' coins alone cover the funding.
  • The earlier-addresses file is read with (try? …load()) ?? [] (:79-82).

LOW (PR body, no line to anchor): manual test 1 cannot be performed as written. While the savings send has no answer, its address is unresolved and payFunding has set fundingPaymentTxid, so canCancel (SparkExitManager.swift:681-685) is false. Progress hides Cancel (SparkExitViews.swift:1106), and cancel() returns .notCancellable (:763). The "was cancelled" release branch therefore has no UI route at this head. Please reword case 1 to a reachable route (exit funded by another wallet, or exit ended), and drop "or was cancelled" from the description or mark that branch as defensive. Android's QA case was reworded the same way.

Checked and clean:

  • A retry prepares original.address, original.amountSats and recovery.inputs, so every candidate spends the same inputs and at most one confirms. With partial outside funding the excess returns as leftover.
  • approveRelease, recordRelease and abandonUnbroadcast need nativeDispatchInProgress == nil and the expected attempt, so a release cannot run around a retry. releaseApproved is saved before the fee prompt, and mayPayAgain refuses on it from both Send Pending and Progress.
  • Release still needs a fresh sync showing no candidate. Ordinary sends reach the store mutators only through sparkExitFundingHasEnded, which needs an exit address match.
  • Retry: fee approval, then PIN or biometrics, then the exit check, then broadcast. Release: fee, PIN, recordRelease, broadcast. Cancelling a prompt or closing the sheet discards the unsubmitted candidate.
  • An attempt from a non-current wallet is neither retried nor released (:74-75), which is the safe direction.
  • wallet__onchain_abandon_exit_note is in all 15 locales and rendered in a wrapping system alert. The longest (it/ca/de ~218 characters) are in the range of the existing transfer note.
  • v3.1.1 has no Spark exit code, so there is no upgrade path.

perf: Send Pending's 30 s poll now does two small file reads for an unresolved ordinary send, and an exit-funding Retry adds one Esplora round trip between PIN and broadcast.

Device gate (partial): 7585390 — not run yet; partial and full funding from another wallet on the local Spark stack. 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

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@jvsena42

LOW (PR body, no line to anchor): manual test 1 cannot be performed as written.

Fixed in the PR body. Case 1 now funds the exit from another wallet, as on Android. The description keeps the cancelled exit, marked as a branch Progress can't reach while the payment is unanswered.

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

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

@ovitrif
ovitrif merged commit 0c344f4 into master Nov 27, 2026
23 checks passed
@ovitrif
ovitrif deleted the fix/spark-exit-release-unneeded-funding branch November 27, 2026 17:59
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: an unresolved savings send keeps blocking sends after another wallet funds the force transfer

4 participants