Repository navigation
fix: spark follow-ups - #1355
Conversation
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 reaches several Spark wallet workflows and the Release build setup. Preserve the actual rejected exit data before merging; the current path can delete it after saving a different remote copy. Findings
SummaryThis PR fixes Spark follow-ups across moves, Activity, deposit claims, exit backups and Release builds.
Acknowledged scope from
Verification was limited to source review. Native iOS tests and UI capture were not run in the Linux environment. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Download exit backup] --> B[Stage exit state locally]
B --> C[Try Spark import]
C -->|Temporary failure| D[Keep staged data and retry]
C -->|Rejected| E[Download remote backup again]
E --> F[Save downloaded copy separately]
F --> G[Delete staged exit state]
G --> H[Allow fresh exit backups]
E -. Remote copy may have changed .-> G
Reviews (1) · Last reviewed commit: "fix: spark exit data kept on every rejec..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Follows up the Spark 3.2.0 work: move-to-Spark hashes are now persisted and backed up, and moves show as transfer rows in Activity. Also covers the waiting-claim poll, setting aside exit data Spark rejects, the late-failure retry hold, the Move to Spark sheet re-check and the Release key check. Reviewed 971cd37, full tier, static: iOS does not build on this reviewer's Linux host, so this is reasoned from the code and from CI.
What I checked, and 9 candidates I ruled out
Read in full: MoveToSparkManager.swift, BackupService.swift (exit backup and metadata paths), SparkManager.swift (exit import, deposit claim), SparkTransferFlow.swift (pollDeposit, waitForConfirmations), LightningService.swift (rail uncertainty helpers, emitChannelFreeRailEvent), TimedSheetManager.swift, the four Activity files, the new and changed tests.
Cross-checked against: breez spark-sdk decode_exit_state / import_unilateral_exit_state and the Payment.timestamp adaptors; bitkit-android#1957's BackupJson.kt.
Localization: 61 changed keys across every locale, checked mechanically for placeholder parity with en (0 mismatches); the translations themselves were not read.
CI: SwiftFormat, validate and build-local green; Run Tests, Run Integration Tests and e2e still running when this was posted.
Ruled out
.rejectedset too wide: everySdkError.InvalidInputfrom the import is a property of the payload (unsupported version, wrong network, unparseable JSON, orServiceError::InvalidInputmapped throughFrom<SparkWalletError>). Operator and storage failures map toSparkError/Generic, so they stay.pending.- Setting aside the wrong remote copy: uploads are blocked while restored data is staged, so the
SPARK_EXITcopy fetched on.rejectedis still the one the staged file came from. - Stale
startedtimestamps: every path that clearschannelFreeRailUncertainSendFailedAt(endRailSendUncertainty,forgetRailAttempts) clears the started key too. An entry written before this change has no started value, andisEarlierThanUncertainRailSendreturns false for it, which is the old behaviour. - Retry overwriting
started:markRailSendUncertainwritesstartedonly when no uncertainty exists, and the second call from the catch path keeps the submission time. - Spark clock behind by more than 10 s: the send's own failure would be ignored, but the hold still ends through
railSyncedSinceUncertainSendonce the invoice expires. It is bounded, not stuck. - Waiting-claim poll never surfacing an outcome: a deposit Spark claims at maturity also leaves
listUnclaimedDeposits, so it reads.added. The window still ends in.unavailablebecauseoffers[txid]is set, andwaitForConfirmationsstill cancels the watch and releases the cap. - Restore re-triggering a metadata backup:
MoveToSparkPayments.restoresaves without sending onsavedPublisher, so onlyinsertmarks metadata required. - Sheet re-check clobbering a pending full check:
onSheetDismissedschedules the move-only check only when no timer is valid, and a laterreevaluate()replaces it with a full check. - Android twin reading the new
moveToSparkPaymentHasheskey: Android'sbackupJsonis built fromjsonwithignoreUnknownKeys = true, so an iOS envelope carrying it still decodes there.
Merge confidence: 4/5. CI's unit and integration runs had not finished, iOS could not be built here, and the real channel move (J1) has only been checked with seeded activities.
ben-kaufman
left a comment
There was a problem hiding this comment.
Rejected exit data can still be lost when two devices archive at once.
Reviewer model: gpt-6.1-sol
Reasoning effort: xhigh
|
Pushed 4ac88c9: a Spark failure event now checks whether it belongs to an earlier attempt and ends the hold under one lock. Before, the check and the release were two separate steps, so a retry recorded between them could lose its hold. |
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 4ac88c9.
High: An older Spark failure within ten seconds of an uncertain retry still releases that retry's hold (Bitkit/Services/LightningService.swift:1664). For example, an attempt created at 995 is treated as the retry submitted at 1000. If its delayed failure arrives after the retry returns an unknown error, settlement deletes the retry's uncertainty and recorded attempt. With only the older failed row listed, another send is then allowed while Spark may still complete the retry, risking duplicate payment. The shared predicate also permits the older failure to replace pending Activity. Keep ambiguous failures from releasing the hold, or correlate them with an actual attempt identity. Cover delivery of the close-timestamp event; the current test checks its classification but only delivers the much older event.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.1 Sol
Reasoning effort: high
Combined review
Model: GPT-6.1 Sol
Reasoning effort: high
@pwltr Addressed in 219a499. Before a retry goes out, the send now records Spark's ids of the invoice's earlier attempts, taken from the listing it already reads. A late failure releases the hold, and replaces pending Activity, only when its Spark payment id is not one of those. Where ids are missing, the check fails safe: a failure created before the send or within ten seconds after it keeps the hold. |
|
b0bfc73: a Spark send's Activity row no longer stays Pending after its retry hold ends at the invoice's expiry. The hold keeps the row pending against an earlier attempt's failure; ending it now writes Spark's latest send of the invoice, or marks the stored pending send failed when Spark lists none. Spark syncs also end holds whose invoice expired, so this no longer waits for a new send of the invoice. The same gap was raised on the twin in synonymdev/bitkit-android#1957 (review). |
ben-kaufman
left a comment
There was a problem hiding this comment.
Expiry reconciliation can lose a failed Activity update and overwrite a concurrent row change.
Reviewer model: gpt-6.1-sol
Reasoning effort: xhigh
|
82a5411: an Instant early claim that Spark defers is now capped at the fee the user approved, not the first quote's fee, so Spark still claims a later offer the approved fee covers. After a waiting claim the poll still sends no new quote, as before. An offer above the approved fee ends as Unavailable and is claimed at maturity. This matches the twin's change for synonymdev/bitkit-android#1957 (review). |
pwltr
left a comment
There was a problem hiding this comment.
Please consider splitting the Spark exit-backup recovery and payment retry changes so each can be reworked around the state it must preserve.
Reviewed 82a5411.
Both exit backup paths can reach the canonical write at Bitkit/Services/BackupService.swift:476 without a version tied to the snapshot they archived.
High: If another device has already replaced the staged snapshot in SPARK_EXIT, Bitkit/Services/BackupService.swift:466 and Bitkit/Services/BackupService.swift:1539 archive the staged snapshot and upload the local export over the other device’s backup. Recovery data held only in that other snapshot disappears from normal restore. BitkitTests/SparkExitBackupTests.swift:243 expects the overwrite.
Medium candidate: The same overwrite may occur if another device writes a fresh backup while Bitkit/Services/BackupService.swift:1519 is archiving an undecodable one. The restore gate clears after that archive write, and the fresh backup can reach the canonical write without ever being read.
High: A Spark retry hold saved before upgrade has neither the attempt IDs nor the start time required by Bitkit/Services/LightningService.swift:1701. A late failure for the first attempt can clear the unresolved retry’s hold and allow another send while Spark may still complete the retry. The same missing upgrade fallback lets history sync mark the retry’s pending Activity row failed through Bitkit/Services/CoreService.swift:1009, even while the hold is still active.
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
We keep them in this PR, matching the twin synonymdev/bitkit-android#1957, so both platforms land the same Spark follow-ups together. Both are reworked below around the state they must keep.
Addressed in 5f603e4. When Spark rejects the staged data and
Addressed in 5f603e4. After setting an unreadable backup aside, the restore reads
Addressed in 5f603e4. A send in doubt with no recorded start counts any failure as an earlier attempt's. It stays held, and its Activity row stays pending, until its invoice expires. The expiry step (from b0bfc73 and 24e6da9) then writes the row from Spark's latest send, retrying until the write is saved ( |
pwltr
left a comment
There was a problem hiding this comment.
Please rework the Spark exit backup and payment retry paths around the recovery data and attempt identity they need to preserve.
Reviewed 5f603e4.
High: Both rejection paths read SPARK_EXIT separately from the unconditional replacement at Bitkit/Services/BackupService.swift:486. A second device can upload a usable backup after the staged-data comparison at Bitkit/Services/BackupService.swift:469 or after the post-archive read at Bitkit/Services/BackupService.swift:1534. The fresh export can then erase exit data this device never read or preserved.
High: Bitkit/Services/BackupService.swift:473 deletes the rejected staged file before line 477 records that a newer remote backup needs restoring. If the app stops between those operations, the next launch can overwrite the other device’s backup without reading it.
High: Bitkit/Services/BackupService.swift:1569 can leave the only usable recovery copy under SPARK_EXIT_REJECTED_*, while normal restore at Bitkit/Services/BackupService.swift:1525 reads only SPARK_EXIT. A compatible app can miss the archived exit data it needs when Spark operators are unavailable.
Medium candidate: Bitkit/Managers/SparkManager.swift:1469 treats a failed read of an existing staged file as an absent file. If the staged read fails while Spark can still export, Bitkit/Services/BackupService.swift:481 allows the fresh export to replace the remote copy.
Both payment effects below follow from Bitkit/Services/LightningService.swift:1135 clearing attempt identity as soon as submission returns, while the retry can still be pending.
High: An older Spark failure can pass Bitkit/Services/LightningService.swift:1754, report the retry as failed, and remove its duplicate-payment guard. If Spark history then becomes unavailable, the app can send the same invoice over a channel while the Spark retry is still settling.
Medium: The same failure can pass Bitkit/Services/CoreService.swift:1003 and replace the newer attempt’s Pending Activity row with Failed.
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 send's read of Spark's list can miss an earlier attempt, which a later send then keeps after a newer one, so the kept order may be wrong. Spark's dates decide between two kept attempts again; the kept order only breaks a same-second tie. Verified: swiftformat lint; BitkitTests on the iPhone 17 Pro 2x simulator, new SparkRelaunchActivityTests case fails without the fix
A failure Spark reported while a send's call ran was dropped, so a call that returned the same payment pending left it held with no failure reported. The failure is now kept during the call and replayed once when the call returns that payment failed or pending; a succeeded result drops it. A wipe clears it. Verified: swiftformat lint; BitkitTests on the iPhone 17 Pro 2x simulator, new ChannelFreeRailTests cases included
A failure held during a send call that then threw was dropped; it is now replayed with Spark's date, so the rules of a send in doubt settle it. Whether the call's result fails the send is decided with the call's end, before the send is taken, so the taken-send expiry sweep never reports it too. Verified: swiftformat lint; BitkitTests on the iPhone 17 Pro 2x simulator, new ChannelFreeRailTests case included
A Lightning invoice is never sent through Spark again while an earlier Spark attempt on it is unresolved; the payment shows as pending until Spark settles or fails it. The send's start, kept in the existing uncertain-send record, decides: a failure Spark dates no more than 10 seconds before it is the send's own and ends it at once; an older one is an earlier attempt's and is ignored. A send Spark never settles ends at its invoice's expiry once a sync since the send reached Spark. Removes the retry hold layer and its saved journal from earlier pushes: attempt ids, taken and kept attempts, row writers, the in-call failure buffer and the 10-minute grace. Verified: unit suite (BitkitTests selection) passes on an iPhone 17 Pro simulator, iOS 26.5.
Spark dates each attempt at its start, so of two failed attempts of one invoice the later one's amount, fee and time now stay in Activity: an older attempt's failure no longer replaces them, and a later attempt's failure replaces an older one's also when the fees match. Verified: Spark relaunch activity, channel-free rail, payment safety and wallet activity suites pass on an iPhone 17 Pro simulator, iOS 26.5.
A retry in Spark's send call that wasn't submitted yet has nothing at Spark, so a failure arriving then is an earlier attempt's: it no longer reaches the retry's screen or releases its attempt. Verified: Spark relaunch activity, channel-free rail, payment safety and wallet activity suites pass on an iPhone 17 Pro simulator, iOS 26.5.
A failure event, a listing or an expired invoice ended whatever hold the invoice had once checked. If the send ended and a retry took a new hold in between, the retry lost it and could be sent again while unresolved. Each now ends only the hold it read, by its start. Verified: ChannelFreeRailTests, SparkRelaunchActivityTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the new test fails without the fix
A Spark failure event checked the invoice's hold and ended it in separate steps, so a retry that took the hold in between could still get the earlier send's failure on its screen. The check and the end are now one step under the lock, judged by whichever send holds the invoice then. Verified: ChannelFreeRailTests, SparkRelaunchActivityTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5
A failed attempt Spark dated within the clock margin before a retry read as the retry's own: it could end the retry's hold, fail its screen, replace its Activity row and, at expiry, copy its details into the retry's row. A send's saved start is now at least the margin plus one second after the latest failure Spark dated for the invoice, from its list or its events, so a known earlier failure never reads as the retry's. Nothing new is saved. Startup also ends a held send from the own failure or success it reads, before releasing it, so a channel retry no longer waits on a later read of Spark's history. Verified: ChannelFreeRailTests, SparkRelaunchActivityTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the two new retry tests fail without the floor
A retry sent while Spark's list can't be read knows no earlier failure after a relaunch, so one Spark dated within the clock margin before it could still read as its own. Its start is now saved past the margin after now, as Spark may have dated a failure of the invoice up to then. Verified: ChannelFreeRailTests, SparkRelaunchActivityTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the new test fails without the change
A Spark send whose list can't be read saved its start past now, so its own failure read as an earlier attempt's and kept it held until its invoice expired. Such a send is now refused before anything goes out, unless Spark's operators show no send of the invoice at all after a restore. A listing also settles only the holds taken before it was read, so a send that starts meanwhile is never settled from the older list. Verified: ChannelFreeRailTests, SparkRelaunchActivityTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; both new tests fail without their change
After a restore, an unsynced Spark whose operators show a pre-restore invoice's sends all failed can't date a new send after them, so it was refused with the generic payment failure. It now gets the restored invoice refusal, as on Android. Verified: ChannelFreeRailTests, SparkRelaunchActivityTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5
A retry's success event could end its hold while Spark's list was read, with the list holding only the first attempt's failure, so the invoice read as failed until the next read and Paykit could drop the paid request's proof. The list is now read again when a hold ends during the read, and a hold still ending on the last of three reads stays pending. Verified: SwiftFormat lint on the changed files; SparkRelaunchActivityTests, ChannelFreeRailTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the new test fails with the LightningService change reverted.
A retry's success event could end its hold just after c9937ed's re-read check, or before Spark listed the success, so the retry still read as the earlier attempt's failure and Paykit could drop the paid request's proof. A held send now keeps its pending row unless the same list shows its result: a success, or a failure dated as its own. The re-read loop is gone. Verified: SwiftFormat lint on the changed files; SparkRelaunchActivityTests, ChannelFreeRailTests, SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the new test fails on 6e58693's code.
1ef7403 to
41ed0d3
Compare
|
Rebased onto master ( Only the locale files and
The Spark and Paykit code is unchanged from |
The rebase onto master left three spark exit keys twice in every locale, the extra copy with older wording. Keep master's line. Verified: no duplicate keys in any Localizable.strings; node scripts/validate-translations.js passes.
|
|
pwltr
left a comment
There was a problem hiding this comment.
Reviewed befad53.
Low: Both Spark history retry tests use an already-expired invoice and a failure row with timestamp zero (BitkitTests/ChannelFreeRailTests.swift:1018, BitkitTests/ChannelFreeRailTests.swift:1052). The expiry sweep can release the hold before Spark's listing is read, so both tests can pass without showing that the listed failure released it. Extend the existing timestamped case at BitkitTests/ChannelFreeRailTests.swift:855 to retry again after history becomes unavailable. That covers both assertions with the clock pinned before expiry and a failure dated to the held send.
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
@pwltr thanks. The timestamped case now also retries once Spark's history can't be read, with the clock pinned before expiry and the failure dated to the held send. That lands in the follow-up PR, together with three fixes from a pre-merge review of Merged: approved by @pwltr on |
Closes #1236
Closes #1249
Closes #1264
Closes #1268
Closes #1270
Closes #1279
Closes #1321
Closes #1378
Closes #1374
Closes #1379
Twin: synonymdev/bitkit-android#1957
This PR fixes the Spark follow-ups from the 3.2.0 work: the Move to Spark sheet, payments and Activity row, the deposit claim poll, exit data backups, translations, Spark send retries and the Breez key check.
Description
lightning__spending_confirm__up_to.Out of Scope
SPARK_EXIT_REJECTED_…copies back yet; they only keep the data recoverable.SPARK_EXITbetween this device's read and its write is not detected, as the VSS client's store has no expected version — feat: conditional vss_store with an expected version vss-rust-client-ffi#38, raised in fix: spark follow-ups #1355 (review).Design
N/A — no design available. The row reuses the existing transfer row (icon, colour and layout).
Preview
Activity on a regtest simulator with seeded moves (succeeded, pending, failed), an outside payment with the same description, a sent and a received payment.
case1-activity2x.mp4
case2-detail2x.mp4
QA Notes
Setup
Regtest build of this branch with an LDK channel that can send at least 1,000 sats and Spark connected (as for the
move-to-spark.xmljourney).Journeys
move-to-spark.xml— after the move, Activity lists a "Move to Spark" transfer row with the amount and routing fee, its detail is titled "Move to Spark", and the Spending button is goneManual Tests
N/A
Automated Checks
MoveToSparkQuoteTests.swift— the quote grows to fit the fee, keeps a smaller target, falls back to the last fitting amount, and reports too large, nothing to move and Spark unavailable; move hashes survive a relaunch, back up sorted, restore and wipeSparkTransferFlowTests.swift— a waiting claim is not quoted or claimed again, its cap is the approved fee and is cleared when the poll gives up, and the deposit counts as added once Spark claims itSparkExitBackupTests.swift— unreadable or rejected exit data is set aside and backups go on; different rejected copies never overwrite each other; rejected data another device replaced remotely is kept from the restored copy and the other device's backup is restored, not overwritten; a backup written while an unreadable one is set aside is restored first; discarding rejected staged data keeps newer data staged meanwhileAppStatusHelperTests.swift— the Spark row opens the detail offline once Spark has read its state, and not beforeSparkRelaunchActivityTests.swift— an older Spark attempt's failure keeps the later failed attempt's row, and a later one's replaces itChannelFreeRailTests.swift— a retry stays held while Spark lists only an earlier attempt's failure and ends at its own; a late failure event dated before the send keeps it held, one dated at the send ends it; an earlier failure while a retry is in Spark's call before submission stays off its screen; a retry that takes the invoice while an expired send settles stays held; a failure of an attempt 5 seconds before a retry keeps it held and off its screen, and at expiry fails the retry's own row; a launch that reads a send's own failure lets the node retry while Spark can't list; a Spark send is refused while Spark can't list, and a pre-restore invoice the operators show failed as unverified; a send held while Spark's list is read is not settled from it; a retry whose hold ends during the read without its result listed stays pending; a retry Spark never lists ends at its invoice's expiry; any pending attempt refuses a retryEvidence
unit-tests.yml) on an iPhone 17 Pro simulator, iOS 26.5, at 98d8e2b: all pass but one exit backup test, fixed after; the touched suites (exit backup, move quote and hashes, channel-free rail, transfer flow, wallet activity, exit funding index) pass at 971cd37, and the exit backup suites at f39522a; the Spark suites (channel-free rail, move to Spark, exit backup, Spark send, payment safety, relaunch and transfer activity, transfer flow, claim offer and fee, funding recovery) at 82a5411; the exit backup and rail suites at 5f603e4; the Spark suites again at e114c01; the Spark suites again at 8d0436f; the App Status suites at 859dee8; the rail and payment safety suites at f811fea; the Spark suites again at ed84ea9; the unit suite at d330aa5, f9aeb92, fab6210, 4542de2, 26545fc, 9d4b7e0, 061e5ec, fbc4a64, 3264677, 8497853, 946713c, 7d07dac, 3e655ff, 45d1c14, c02b4b0 and 7b428de; the Spark activity and rail suites at a873836, 1f7698a, c177de8, fa92ad3, 809c8a3, b401fa4, a528bf0, 6e58693, c9937ed and 1ef7403.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)Claude Opus 5.5(reasoning:medium)