Skip to content

feat: move LN channel balances to spark - #1212

Merged
ovitrif merged 45 commits into
feat/breez-spark-lightningfrom
feat/move-to-spark
Nov 12, 2026
Merged

ovitrif merged 45 commits into
feat/breez-spark-lightningfrom
feat/move-to-spark

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1206

Twin: synonymdev/bitkit-android#1774
Dependency: #1128
Companion: synonymdev/bitkit-e2e-tests#297

This PR adds Move to Spark: a one-time sheet and an action that pays the balance of a Lightning channel to the user's own Spark wallet over the channel, then offers to close the emptied channel. Blocktank is closing its channels, and moving the balance over Lightning costs only the routing fee, where a close followed by a deposit costs on-chain and claim fees and 3 confirmations. It stacks on #1128: review it against that base; it merges after #1128.

Description

  • Adds MoveToSparkManager, which quotes the move against a new amountless Spark invoice: it starts from what the channels can send and leaves room for the routing fee. The fee shown is LDK's estimate plus a 2 sat margin, and the payment's routing fee is capped at exactly that.
  • Adds a channelsOnly option on LightningService.send and estimateRoutingFees, used through WalletViewModel.sendOverChannels, so the move always goes over the channels and never falls back to Spark; the default shouldPayWithRail routing is unchanged.
  • Adds the Move to Spark screen: quote, swipe to move, then "Moved to Spark" with Close, which opens the existing cooperative close; after a partial move it offers Move The Rest instead.
  • Shows "Amount too large" with Move Half when no route carries the amount, down to a 1,000 sat minimum, so a large balance can move in parts; any other failure, such as an expired invoice or a stopped node, shows "Could not move" with Try Again.
  • Waits up to 2 minutes for the payment's outcome. A payment still in flight then shows "Moving to Spark" with OK only, since its amount may still return to the channel; a failure that arrives later shows "Could not move" and the usual failed notice, and a success that arrives later shows "Moved to Spark".
  • Adds a timed sheet that tells channel holders Blocktank is closing its connections and opens Move to Spark; it shows once, at the top priority, and is checked again once channels and Spark have loaded after a cold start.
  • Adds a Move To Spark button to Spending and Lightning Connections while a channel can still send at least 1,000 sats to a usable Spark wallet, after the fee reserve.
  • Keeps the move's own send and receive from raising the usual payment sent or received notices, since the screen reports the outcome.
  • Records a move as one Activity row, the channel send, with the moved amount and the routing fee, whichever leg arrives first; the Spark receive with the same payment hash only marks a pending or failed send as succeeded.
  • Keeps a running move and its outcome when the app locks and unlocks, or when the screen is left and opened again while its payment is in flight.
  • Fits the smallest screens: button labels stay on one line at 360 dp and on an iPhone SE, the buttons sit at the bottom with the illustration taking the flexible height, and headlines put the white words first and the shorter accent last, as master's screens do.

Out of Scope

  • Activity: a move shows as an outgoing payment for now; a designed Move to Spark row is bug: move to spark activity loses direction and fee #1249.
  • Design: an AI-made first version from existing components; a Figma design and designer review follow.
  • Review follow-ups: the sheet's cold-start re-check behind another sheet, keeping the move's hash across a restart, and makeQuote unit tests — chore: move to spark review follow-ups #1236.
  • Translations: the Move to Spark strings ship in English only; their translations come with the Spark translation follow-up.
  • Emergency exit: Move to Spark should not be offered while a Spark emergency exit runs, but isExiting comes with the exit PR (feat: spark emergency exit #1217), not this PR's base. Every Move to Spark check goes through MoveToSparkMath.isSparkUsable in MoveToSparkManager.swift, so whichever of the two PRs lands second changes that one line to spark.isReady && !spark.isExiting.

Design

N/A — no design available. UI pending design: this is an AI-made first version from existing components; a Figma design and designer review follow.

Preview

iPhone 17 Pro simulator at 2x (iOS 27.0), at 2x speed.

Sheet on Home, Later Too large, Move Half Move the rest Close afterwards
rec-sheet2x.mp4
rec-too-large2x.mp4
rec-move-rest2x.mp4
rec-close2x.mp4

Screens

iPhone 17 Pro simulator at 2x (iOS 27.0), in flow order. Bitkit draws dark only, its system bars included.

Post-update sheet Spending entry Connections entry Finding a route
Too large Confirm: amount and fee Moving Done: part moved
Done: close offer Close confirmation After the close Could not move

QA Notes

Setup

  • A local Spark regtest: the spark profile from feat: local spark regtest network bitkit-docker#37 (./spark up), which runs three Spark operators, the SSP with its Lightning node, the LNURL and data-sync servers and a chain API on bitkit-docker's chain, compatible with Spark SDK 0.28. It does not publish the SSP node's P2P port (9735); publish it in a compose override to open a channel from the app.
  • A debug build launched with SIMCTL_CHILD_SPARK_LOCAL_CONFIG_B64 set to ./spark config --base64 and the Spark chain service pointed at http://127.0.0.1:23090/api; the simulator reaches the stack on the Mac's loopback. This PR has no switch for it; the app-side settings land in separate PRs.
  • In the app, fund Savings (./spark send <address> 500000), then open Lightning Connections, Manual Setup, and open a channel to the SSP node; confirm it with ./spark mine 6.
  • Manual test 1 needs a route limit the stack cannot set: the tested build carried a QA hook, the QA_MOVE_HOOK launch value (limit=<sats>, fail, slow).

Journeys

  • J1: new move-to-spark.xml — sheet once, entry button, move with routing fee, close afterwards, nothing for a wallet without a channel

Manual Tests

  • 1. With a route that cannot carry the balance, open Move To Spark → "Amount too large" offers to move half; repeating it moves a part that routes, and Done offers Move The Rest — needs a route limit the local stack cannot set

Automated Checks

  • added MoveToSparkMathTests.swift — first quote leaves room for a guessed fee, the amount fits under the limit with the fee, the fee cap covers the quoted fee, a move is offered only when 1,000 sats fit beside the fee reserve, halving stops at the minimum, no move without a usable Spark
  • added MoveToSparkLateOutcomeTests.swift — a success after the wait shows the done result with the fee paid, only for the move that still owns the screen
  • added MoveToSparkActivityTests.swift — a move keeps one outgoing Activity row with the routing fee, whichever leg arrives first

Evidence

Tested at 68028ff73 on the stack and build from Setup, iPhone 17 Pro simulator at 2x (iOS 27.0), one 400,000 sat channel to the SSP; the Preview and Screens above are this run. Later commits (c2305be and 26d4ad1) change only the in-flight screen and Activity rows, which this run does not show.

  • J1 sheet: once the channel confirmed, the sheet showed on Home; Later closed it.
  • 1: with the route limit, the full balance showed "Amount too large"; Move Half moved a part with a 0 sat routing fee (direct channel), and Done offered Move The Rest.
  • J1 move and close: Move To Spark moved the rest, Done offered Close, and Close then Close returned to Lightning Connections with no open connection and the balance on Spark.
  • Could not move: with the fail hook, the screen showed "Could not move" with Try Again.

Tested again at 1483196b9 on the same stack and simulator, with a fresh wallet and one channel to the SSP. To bring up the in-flight screen, the build also carried a local hook that ends the settle wait at once.

  • J1 no channel: with Savings funded and no channel, Home showed no sheet, Spending only Transfer From Savings, and Lightning Connections no Move entry.

1-no-channel2x.mp4

  • J1 not again: once the channel confirmed, the sheet showed and Later closed it. After two relaunches, Home stayed clear and the Spending entry stayed.

2-sheet-relaunch2x.mp4

2b-relaunch-again2x.mp4

  • In-flight: the swipe showed Moving to Spark, then the late success turned it into Moved to Spark with a 0 sat routing fee.

3-in-flight2x.mp4

  • Activity: one Sent row, Move to Spark −395,458, beside the Transfer and Received rows, with no Spark received row; its detail shows Successful with fee 0.

4-activity2x.mp4

Gaps

  • Only direct channels to the SSP were tested; a multi-hop route with a real routing fee was not set up locally.

Mainnet tests (run by the author)

These run on real devices with mainnet funds, by the author. Reviewers and review bots don't need to run them, and they don't block review.

Round 1

None yet.

Round 2 (pending)

  • M1: intro — after updating with a funded channel, the post-update sheet shows once on Home and opens Move to Spark
  • M2: move sheet — Move To Spark quotes the channel balance with a routing fee that fits under the channel's limit
  • M3: move — swiping moves the balance over the channel to the Spark wallet, with a routing fee no higher than the one shown
  • M4: channel close — Close Connection on Done closes the emptied channel cooperatively
  • M5: balance after — Spark holds the moved amount and the closed channel's remainder returns to Savings

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: medium)
  • Implementation: claude-opus-5-5 (reasoning: medium)
  • Review: claude-opus-5-5 (reasoning: Not exposed)

Metadata note: the review subagents' run records give the model but not a reasoning setting.

@ovitrif

ovitrif commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 543d414d: the Move To Spark button in Lightning Connections now sits below the open channels instead of above the Spark section, next to the channel it moves and clear of the Spark row and detail that the Spark exit work is changing on the base branch. Layout only; the build and SwiftFormat lint pass.

@ovitrif

ovitrif commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed e8356ce3..0dc18beb, a small-screen pass on the Move to Spark screens:

  • Button labels stay on one line on an iPhone SE: Later / Move Now, Cancel / Move Half, Later / Move Rest, Later / Close.
  • Bottom buttons sit at the screen bottom; the sheet's illustration shrinks so its headline and copy stay whole.
  • Headlines put the white words first and the shorter accent last, as master's screens do.
  • All locales follow the same headline shape and short labels.

Screenshots on an iPhone SE are in Preview. The build, SwiftFormat lint and the translation check pass.

@ovitrif
ovitrif force-pushed the feat/breez-spark-lightning branch from ffba7c7 to 0eed9c2 Compare November 5, 2026 02:10
@ovitrif
ovitrif force-pushed the feat/move-to-spark branch from 0dc18be to fa535a9 Compare November 5, 2026 02:31
@ovitrif

ovitrif commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto the rebuilt Spark base 0eed9c2a, which drops the emergency exit, and force-pushed with a lease (this PR is a draft): 0dc18beb → fa535a9d.

  • MainNavView and NavigationViewModel conflicts kept the new base's routes plus only .moveToSpark.
  • fa535a9d adapts to the removed exit: Spark readiness is SparkManager.isReady alone (no isExiting), and the screen uses its own MoveToSparkAmountRow instead of the exit's row.

The build, SwiftFormat lint, the translation check and the unit test selection pass. The device runs and screens in the description were taken before the rebase on the same Move to Spark code.

@ovitrif

ovitrif commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Merged the new base head b277bebe (Spark chain service on Bitkit electrs) into this PR as da80ffc3. It merged without conflicts and changes only the base's Env.swift, SparkManager.swift and SparkConfigTests.swift; no Move to Spark file changed. SwiftFormat passes on those files; CI runs the build and unit tests.

@ovitrif ovitrif changed the title feat: channel balances move to spark at low fees feat: move LN channel balances to spark Nov 5, 2026
@ovitrif

ovitrif commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Dropped "at the lowest fee" from this PR's changelog line, to match the new title: the line now says what the change does, not how cheaply.

@ovitrif

ovitrif commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed b6612b77: every Move to Spark check (the timed sheet, Home, Spending, Lightning Connections and the move's own guard) now goes through MoveToSparkMath.isSparkUsable. Move to Spark must not be offered during a Spark emergency exit, and isExiting arrives with #1217, not this PR's base. Whichever of the two PRs lands second changes that one line to spark.isReady && !spark.isExiting; this is now under Out of Scope in the description. Build, SwiftFormat and the unit tests pass.

@ovitrif

ovitrif commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Merged the new base head 43abf3ec (Breez SDK 0.28.0) into this PR as 055e7cac. It merged without conflicts; Move to Spark's code needed no change for the 0.28 API. The build and unit tests pass, and UsdtWalletUITests pass on a clean simulator.

@ovitrif

ovitrif commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 56a77229: fixes from an independent pre-review pass.

  • Move to Spark reads the channels fresh from LDK before quoting and after the payment. Done read the cached channels, so after a full move it could offer Move The Rest instead of Close Connection.
  • Only a missing route (RouteNotFound, routeNotFound, retriesExhausted) shows "Amount too large"; any other failure, such as an expired invoice or a stopped node, shows "Could not move" with Try Again.
  • The fee shown is LDK's estimate plus the 2 sat margin, and the payment's routing fee cap is exactly that, so it never pays more than shown.
  • Close after a move started from Lightning Connections no longer pushes a second Connections screen.
  • The move's payment hash matches case-insensitively, and the unused in-flight string is removed from every locale.

The remaining low-severity items are in #1236. The unit test selection from unit-tests.yml, SwiftFormat lint of the changed files and the translation check pass.

@ovitrif
ovitrif marked this pull request as ready for review November 6, 2026 17:19
@ovitrif
ovitrif requested review from a team and pwltr and removed request for a team November 6, 2026 17:19
@ovitrif

ovitrif commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

0ce947b gives every Move illustration the zap's size and makes the amount on Too large bold white. The changed screens and recordings in the description are re-shot.

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

Delta review of 5261e49 and 0ce947b: no findings. resetForWipe (called from AppReset) bumps the generation and clears the move latch and the stored move hashes. A wiped wallet's late outcome now fails the generation == moveGeneration check and leaves the next wallet's screen alone. 0ce947b only changes illustrations and copy styling.

Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed

@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 0ce947b: the too-large screen now shows the amount in bold, and the check, cross and exclamation-mark illustrations are scaled up to match the zap. The other move screens' texts have no highlighted parts, so they look the same as before, and the scaling changes only how the images are drawn, not the layout or any tap target. No findings.

Review details

General review
Model: Claude Opus 5.5
Reasoning effort: high

@jvsena42

Copy link
Copy Markdown
Member

@ovitrif this conflicts with feat/breez-spark-lightning again after the latest push; please rebase. I'll review it again once it merges cleanly.

@ovitrif

ovitrif commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

@jvsena42

this conflicts with feat/breez-spark-lightning again after the latest push; please rebase.

Merged the base at b4f3e04 in 26a0bfc (merged rather than rebased, so the history you reviewed stays). The one conflict was in SpendingWalletScreen.swift: the Move entry stays, and the transfer button takes the base's new totalLightningSats > 0 gate. It merges cleanly now.

Also in this push, at 1483196:

  • e84249f keeps a move's routing fee when its Spark receive settles the send first. This is the twin of feat: move LN channel balances to spark bitkit-android#1774's 5315c3634. MoveToSparkActivityTests.swift covers it.
  • Removed the Move strings' translations. The English strings stay, and the translations follow in the Spark translation follow-up.

@ovitrif
ovitrif requested review from jvsena42 and pwltr November 10, 2026 16:05

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

Re-review after the rebase: own commits e84249fa4 and 1483196b9. No findings.

Routing fee kept (e84249fa4): CoreService.swift:1022-1026 lets an LDK update through the staleness check when it changes the stored fee, the same as Android 5315c3634. Downgrades are still blocked by keepsLightningStatus. settleMove is idempotent once the send succeeded. After the LDK update writes the fee, the next equal-fee listing is skipped, so the two writers don't overwrite each other back and forth. MoveToSparkActivityTests.testSparkReceiveSettlingTheSendTakesTheRoutingFeeFromTheLaterLdkUpdate covers the pending-send, Spark-receive, LDK-send order.

Translations (1483196b9): deferring them is the author's call.

Reviewer model: claude-fable-5-1 (delta review), claude-opus-5-5 (coordination)
Reasoning effort: not exposed (Fable subagent), default (Opus)

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

  • Low — Unresolved watcher survives wipe. Bitkit/ViewModels/WalletViewModel.swift:1228 keeps its event task after timeout, but wipe never finishes that stream. If no terminal payment event arrives, the task remains retained. Add lifecycle teardown while preserving late outcomes for the active wallet. Wipe already clears the move screen's state.
  • Low candidate — Bind submission to the quoted wallet/node. Bitkit/ViewModels/WalletViewModel.swift:1195 supplies no identity check before queued submission. Wipe ordering and generation guards reduce the risk; a successful wrong-wallet dispatch has not been demonstrated.
  • Low candidate — Confirm the synchronous send-error guarantee. Bitkit/Managers/MoveToSparkManager.swift:371 permits a smaller retry after PaymentSendingFailed. The earlier discussion establishes the intended no-payment-created behavior for rc.78; this revision pins rc.79. Duplicate movement is only a conditional concern if that guarantee differs.
Review details

Quick review
Model: Claude Opus 5.5
Reasoning effort: high

General review
Model: GPT-6.1 Sol
Reasoning effort: high

Security review
Model: Kimi K3
Reasoning effort: high

Combined review
Model: GPT-6.1 Sol
Reasoning effort: high

@ovitrif

ovitrif commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low — Unresolved watcher survives wipe.

Fixed in fb26d22. wipe now ends the event stream of any move still waiting for a late outcome, so its watch task finishes and unregisters its listener. Late outcomes for the active wallet are unchanged, and the new generation from resetForWipe already drops the wiped move's result. A new test covers a watch whose stream ends after the timeout: it stops, runs its cleanup and reports no late outcome.

Low candidate — Bind submission to the quoted wallet/node.

No change. The send goes to the node that is running at that moment, and wipe stops that node under the node lifecycle lock before anything else happens, so a send queued behind a wipe fails instead of going out from another wallet. Any result that still arrives is dropped by the generation check.

Low candidate — Confirm the synchronous send-error guarantee.

No change. Between rc.78 and rc.79 ldk-node only bumped rustls (synonymdev/ldk-node@a44cf8f6), so the no-payment-created behaviour for PaymentSendingFailed is the same as in the earlier discussion.

@ovitrif
ovitrif requested review from jvsena42 and pwltr November 11, 2026 15:40

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

Re-review of fb26d2273: no findings. Approving. A move's late-outcome event stream is now kept in moveEventSinks, so wipe can finish it: a wiped node reports no late outcome, and the watch would otherwise wait forever. The new MoveToSparkLateOutcomeTests case covers it. Device gate: no device check needed for this delta.

Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed

@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 fb26d22 against b4f3e04. No actionable code findings. The move retains its identity through timeout and re-entry, and wallet wipe now finishes retained event streams so their listeners can unregister. Activity reconciliation preserves the outgoing move and routing fee across the two rail events.

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

@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

878e102 merges feat/breez-spark-lightning at 07732c1, which now includes the emergency exit from #1217:

  • Conflicts in MainNavView.swift and NavigationViewModel.swift keep both the Move route and the exit routes.
  • SpendingWalletScreen.swift keeps the Move button and takes the base's shownSpendingSats for the transfer button.
  • MoveToSparkMath.isSparkUsable now also requires that no exit is running, so neither the Move entry points nor the sheet offer a move while an exit sweeps Spark's funds to savings. A new test in MoveToSparkMathTests covers it.

The build and the Move unit tests pass locally, and swiftformat 0.64.6 is clean.

@ovitrif
ovitrif requested review from jvsena42 and pwltr November 12, 2026 01:26
@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Merging into feat/breez-spark-lightning: approved by @jvsena42 and @pwltr at fb26d22, no changes requested, no open threads, CI green at 878e102 (Run Tests passed on a rerun after an unrelated Paykit test timed out).

Since those approvals, 878e102 merged the Spark base with the emergency exit from #1217, and MoveToSparkMath.isSparkUsable became isReady && !isExiting, covered by a new test in MoveToSparkMathTests. The merge note above lists the conflict resolutions.

@ovitrif
ovitrif merged commit 743d263 into feat/breez-spark-lightning Nov 12, 2026
11 of 12 checks passed
@ovitrif
ovitrif deleted the feat/move-to-spark branch November 12, 2026 02:40
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.

6 participants