Skip to content

feat: update spending balance modal - #1373

Open
ovitrif wants to merge 42 commits into
fix/spark-follow-ups-2from
feat/update-spending-balance-modal
Open

ovitrif wants to merge 42 commits into
fix/spark-follow-ups-2from
feat/update-spending-balance-modal

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1374

Twin: synonymdev/bitkit-android#1967
Dependency: #1355

Description

  • Replaces the Move to Spark screens with the v64 modal: "Update Spending Balance" with the live routing fee as "Update fee: ", Later and Update; on success "Spending Balance Updated" with OK. The one-time sheet and the Move To Spark buttons on Spending and Lightning Connections all open it.
  • Once the move settles, every channel it emptied is closed cooperatively and gets the usual transfer row; a failed close leaves the channel for a manual close. Channels that could send less than the move minimum are left alone, and nothing closes while another Lightning payment is in flight.
  • A Lightning payment that only the channels and Spark together can cover runs with one swipe: the confirm screen adds an "Update fee" row and opens its details so the fee shows before the swipe, which waits for the quote, the swipe moves the channel balance to Spark, then pays from Spark.
    • At swipe time, and again right before the move, the update is quoted again; if its fee rose, or none was shown, the payment returns to confirm with the new fee and nothing moves. An automatic payment that hits this falls back to a manual confirm.
    • An LNURL-pay that needs the update shows its fee before the first swipe.
    • Any failed update releases a payment request instead of leaving it pending; one refused for a risen fee is restored for the next swipe.
    • Before moving, the quote and Spark's balance must cover the payment; otherwise nothing moves.
    • A payment request refused by its allowance check moves nothing.
    • If the payment fails after the move, the funds stay in Spark and the usual payment error shows.
    • QuickPay never sends such a payment: it checks again right before paying and opens Confirm when the update is needed.
    • Contact payments can use the update; Pubky swaps are quoted only with what one rail can pay.
  • Removes the Spark Route row from the send confirm screen; the key stays for the Pubky Swaps row.
  • Removes the CJIT receive card, its button and the liquidity flow; CJIT history stays. Without Lightning receive, the Spending and Auto receive tabs hide.
  • Translates the new strings into every shipped locale and drops the removed keys from each.
  • Differs from the twin where iOS code differs:
    • The modal resets when its sheet is dismissed, as other iOS sheets do.
    • Channel closes reuse TransferViewModel.closeChannels.
    • The LNURL-pay confirm shows the Update fee row whenever the payment needs the update.
    • The Spending tab bar shortcut and Receive's Transfer Unavailable step go with the CJIT flow.
    • After the move, the payment waits up to 60 s for Spark's balance, rechecking every 2 s.

Out of Scope

  • If the app is killed after a move settles and before its channels close, they stay open for a manual close.
  • States without frames (a move in flight, nothing to move, too large, failed) keep today's behaviour in the modal.
  • DisplayText, BodyMText: the headline and body line heights are the shared components' (about 2 pt under the frame's 44 and 22).

Design

Figma page "Bitkit - Progress v64" in the Bitkit Wallet file:

Preview

Figma frame on the left, the app on the right, on 42a656e8f.

Update Spending Balance Spending Balance Updated

Screens without a v64 frame

Send confirm with the Update fee row Receive without the CJIT card

Recordings at 2x: J1 on 42a656e8f, J2 on f2b60fc6c, the others on 1ca4159a7.

J1: move to Spark J2: payment with an update J3: transfer unavailable
pr4-j12x.mp4
pr4-j22x.mp4
pr4-j32x.mp4
J4: USDT receive tabs J5: receive tabs wraparound
pr4-j42x.mp4
pr4-j52x.mp4

Figma notes

Every note above the v64 frames for these flows, with what this PR does about it.

Modal Update Spending balance (Spark)

  • "Bitkit is switching Lightning providers. Update your spending balance … Update fee": this PR, with the live routing fee

Modal Update Spending (Spark) done

  • "Funds moved to spark": this PR shows it once the move succeeds
  • "Also auto close channel after sending the funds to Spark balance": this PR closes every channel the move emptied

Changelog v64

QA Notes

Setup

  • Local Spark regtest stack from synonymdev/bitkit-docker (docs/spark-regtest.md), so the wallet holds an LDK channel to the stack's SSP Lightning node on the same chain as Spark.
  • Debug build (regtest) pointed at that stack: its local Spark config (SPARK_LOCAL_CONFIG_B64 from the docs) as the Spark SDK config with fee ladders off, Electrum on the stack, and the stack's chain API as Spark's chain service. This branch has no build setting for a local Spark, so this is a local patch to Env.swift and SparkManager.swift, not part of this PR.
  • J1: new wallet with 500 000 sats in savings and a 400 000-sat channel to the SSP node.
  • J2: a fresh compose project of the stack (new volumes), and a new wallet with savings, 30 000 on Spark, a 32 000-sat channel to the SSP node, QuickPay off, and a 50 000-sat invoice from another node on the stack.
  • J3: Spark failing to start (replace the wallet's regtest/wallet0/spark directory with a file), restored after.

Journeys

  • J1: updated move-to-spark.xml — Update modal with its fee, Later, Update, Updated modal, emptied channel closed — passed on 42a656e8f
  • J2: added update-spending-balance-payment.xml — a payment only channels and Spark together cover: "Update fee" row, no Route row, one swipe — passed on f2b60fc6c
  • J3: updated transfer-unavailable-sheet.xml — with Spark down, the funding options and Receive without Lightning tabs — passed on 1ca4159a7
  • J4: updated usdt-receive-swipe-tabs.xml — tabs without the CJIT card — passed on 1ca4159a7
  • J5: updated receive-tabs-wraparound.xml — passed on 1ca4159a7, step 10 included
  • J6: updated paykit-spark-route.xml (Route row removed) — not run: needs a paykit stack with a Pubky profile

Automated Checks

  • added MoveToSparkUpdateTests.swift — update-fee guard, coverage before moving, closing only the channels a move emptied, the swipe waiting for the newest quote
  • updated MoveToSparkMathTests.swift, MoveToSparkQuoteTests.swift, MoveToSparkLateOutcomeTests.swift — when a payment needs the update, swap routes and Spark legs never do
  • updated LnurlPayConfirmTests.swift — an automatic payment needing the update waits for a swipe; a refused fee restores only the current send
  • added QuickPayPaymentCoordinatorTests.swift case — a payment that needs the update falls back to Confirm
  • updated ReceiveTabsTests.swift — without Lightning receive the Spending and Auto tabs hide
  • removed ReceiveLiquidityDecisionTests.swift, TabBarReceiveTests.swift with the CJIT flow

Evidence

On an iPhone 17 Pro simulator (regtest) with the local Spark stack:

  • J1: the modal read "Update fee: ₿ 2"; Later kept it away after a relaunch; Update moved 394 602 sats to Spark and showed "Spending Balance Updated"; the channel closed cooperatively with its 4 060-sat remainder sent to savings; Lightning Connections listed only Spark via Breez, and the Move To Spark button was gone.
  • J2: confirm showed 50 000 with its details open, "Instant (± ₿ 202)", "Update fee ₿ 2" and no Route row; after the over-half-balance dialog, one swipe moved 30 458 to Spark and sent 50 000 from Spark, which needed more than its 30 000 balance; the emptied channel closed and savings received its 372-sat remainder.
  • J3: Spark failing to start left Manual Setup as the only enabled funding option, and Receive showed only Savings.
  • J4, J5: Receive has no CJIT card; the tabs wrap from USDT straight to Savings, and with USDT off run Savings, Spending, Savings, Auto.
  • Between 1ca4159a7 and 42a656e8f only the modal's artwork placement and fix: spark follow-ups #1355's base changes landed; the send, retry and Move to Spark test classes pass on 42a656e8f.

Gaps

  • J6, as above.
  • If the app is killed after a move settles and before its channels close, they stay open for a manual close.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium), Claude Sonnet 5.5 (reasoning: high)
  • Review: Claude Opus 5.5 (reasoning: medium)

@ovitrif ovitrif self-assigned this Nov 19, 2026
@ovitrif
ovitrif requested review from a team, ben-kaufman and coreyphillips and removed request for a team November 19, 2026 12:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T12:57:21.503711Z 42a656e 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 19, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge based on the code reviewed.

Summary

Replaces the Move to Spark screens with an Update Spending Balance modal and lets Lightning payments combine channel and Spark funds after showing the update fee.

  • The Update Spending Balance modal moves channel funds to Spark and closes emptied channels.
  • One swipe can move channel funds to Spark and pay a Lightning invoice.
  • Receive no longer offers CJIT, and hides Lightning tabs when it cannot receive Lightning.

No actionable issues found. Tests were not run in this Linux environment.

ovitrif explicitly leaves app termination between move settlement and channel closure out of scope; those channels remain available for manual closure.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Review Lightning payment] --> B{Needs combined funds?}
    B -- No --> G[Send payment]
    B -- Yes --> C[Show update fee]
    C --> D[Swipe and refresh quote]
    D --> E{New or higher update fee?}
    E -- Yes --> C
    E -- No --> F[Check allowance and coverage]
    F --> H[Move channel funds to Spark]
    H --> I[Close emptied channels]
    H --> J[Wait for Spark balance]
    J --> G
Loading

Reviews (1) · Last reviewed commit: "fix: keep the modal artwork 32 above its..." · Reviewed by Greptile

Replaces the Move to Spark screens with the Update Spending Balance
modal: the live routing fee as "Update fee", Later and Update, then
Spending Balance Updated with OK. The one-time timed sheet and the
Move To Spark buttons on Spending and Lightning Connections open it.
States without frames (in flight, partly moved, too large, failed) keep
their behaviour inside the modal; their dismiss buttons share the
UpdateSpendingBalanceDismiss id. The modal resets the move manager when
it closes.

Verified: swiftformat --lint on the changed Swift files
Once a move settles, on its first outcome or a late success, every
channel it emptied is closed cooperatively with the usual transfer row;
a failed close leaves the channel for a manual close. Channels that
could send less than the move minimum before it are left alone. This
replaces the single-channel Close button after a move.

Verified: swiftformat --lint on the changed Swift files
A Lightning payment that only the channels and Spark together can cover
runs with one swipe: confirm adds an "Update fee" row and opens its
details, the swipe waits for the quote, moves the channel balance to
Spark, then pays from Spark.

The update fee guard charges nothing the user did not see: the update
is quoted again at the swipe and right before the move, and a fee that
rose, or none shown, returns to confirm with the new fee and moves
nothing. Before moving, the quote and Spark's balance must cover the
payment and Spark's fee for it. A request refused by its allowance
check moves nothing, and any failed update releases the request. A
payment failing after the move leaves the funds in Spark with the usual
payment error. An LNURL-pay that needs the update shows its fee before
the first swipe. QuickPay never sends such a payment, and Paykit routes
are quoted only with what one rail can pay.

Verified: swiftformat --lint on the changed Swift files
Send confirm no longer shows the Route row for a Paykit payment over Spark. The Pubky Swaps route row keeps it, so wallet__send_swap_route stays, as on Android.

Verified: swiftformat --lint on the changed Swift files
Removes the CJIT receive card, its Receive Lightning Funds button and
the liquidity flow behind it: Receive's Transfer Unavailable step, the
edit-amount liquidity check and the Spending tab bar shortcut to it.
CJIT history stays. Without a Lightning invoice from a usable Spark
wallet or channel, the Spending and Auto receive tabs hide.

Verified: swiftformat --lint on the changed Swift files
Adds the update spending balance modal and Update fee strings to every shipped locale and drops the removed move to spark and CJIT receive keys.

Verified: node scripts/validate-translations.js
Adds the update spending balance payment journey, rewrites move to spark for the modal, and drops the CJIT receive and route steps from the receive, transfer unavailable and paykit journeys.

Verified: xmllint --noout on each journey
A first subscription payment that needs the spending balance update no
longer pays by itself behind the progress cover. Send confirm opens the
manual confirmation before quoting or moving, and does so again when the
fee rises at move time instead of landing on the failure screen.
LNURL-pay gets the same rule through a flag its automatic start checks.

Verified: swiftformat --lint on the changed files
When the update fee rises at move time, send confirm and LNURL-pay
release the request's private payment list and stay on Confirm. They
now restore the request as the raised mining fee path does, so the next
swipe prepares it again; a send closed or replaced meanwhile is left
alone.

Verified: swiftformat --lint on the changed files
A fee estimate that needs no update now invalidates an update quote
still loading, so that quote can no longer write Spark's fee over the
Lightning estimate or bring the Update fee row back. The run counter and
the quote holding the swipe move into one value type.

Verified: swiftformat --lint on the changed files
A Paykit swap route pays through its swap provider, never from the
channels, so send confirm and LNURL-pay neither quote the update for it
nor stop its swipe over an update fee, as on Android.

Verified: swiftformat --lint on the changed files
The frames bottom-align the modal's content, so on a taller sheet the extra space goes above the artwork, not around it.

Verified: swiftformat --lint
Verified: none (file rename only)

@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. Replaces the Move to Spark screen with the Update Spending Balance modal, closes the channels a move emptied, lets a Lightning payment that fits only across the channels and Spark together pay in one swipe after showing an update fee, and removes the CJIT receive card and the Route row. Reviewed f2b60fc against its base fix/spark-follow-ups-2 (#1355), oversized tier: 55 files, +1282/-870.

What I checked, and 5 candidates I ruled out

Reviewed in full (the paths that move funds): the diff of MoveToSparkManager.swift, SendConfirmationView.swift, LnurlPayConfirm.swift, SendAmountView.swift, SendSheet.swift, PaymentNavigationHelper.swift, WalletViewModel.swift, AppViewModel.swift, PaykitPaymentProofService.swift, MoveToSparkSheet.swift, MainNavView.swift, LightningConnectionsView.swift, SpendingWalletScreen.swift, plus TransferViewModel.closeChannels, WalletViewModel.sendWithTimeout and performSwapRoutedPayment on the head.
Not reviewed: the CJIT and receive removals (ReceiveQr, ReceiveEdit, ReceiveSheet, TabBar, ReceiveTransferUnavailable), the localisation files, the unit tests and the journeys. That is the oversized tier's limit, not a judgement on them.
Build: not built. iOS does not build on this reviewer's Linux host, so this review is reasoned from the code and from CI.
CI: SwiftFormat green; Run Tests still pending at review time.

Ruled out

  • An update fee charged unseen: the swipe re-quotes in confirmSparkUpdateQuote before biometrics, and updateSpendingBalanceIfNeeded quotes again and refuses with updateFeeUnseen when no fee was shown or the fresh one is higher. Both automatic paths (SendConfirmationView with isAutomatic, LnurlPayConfirm.startAutomaticPaymentIfNeeded) switch to manual confirmation instead of paying, and QuickPay is skipped by the new needsUpdateToSend check in PaymentNavigationHelper.shouldUseQuickpay.
  • A failed update reported as a payment that may have gone out: every update failure throws MoveToSparkError before privatePaymentListOutcome = .uncertain and before sendWithTimeout, and PaykitPaymentProofService now treats MoveToSparkError as nothing sent, which matches.
  • Two moves paying from the same channel balance: payOverChannels chains on moveTail, and checkCoverage prices the payment from Spark's own quote before anything moves.
  • A double close of one channel: the close runs on exactly one of the settled and onLateSuccess paths of a move. A second overlapping move would need the modal and a send sheet open at once.
  • The swap route quoted against the combined balance: quoteSwapRoute in SendAmountView still passes the uncapped wallet.maxSendLightningSats (which now includes the update), while the hold invoice is paid without an update. The route is behind Env.isPubkySwapsRouteEnabled (debug regtest with PUBKY_SWAPS_ROUTES only), and the hold payment fails before anything is committed, so this is below the posting bar.

Merge confidence: 3/5, the oversized tier: the receive and CJIT removals, the tests and the journeys were not reviewed, and the unit tests had not finished in CI.

Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed (the review runner does not report it)

@ovitrif

ovitrif commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

Spark replaces Lightning spending in 3.2.0, and this modal is how the Spending balance moves to Spark, so it ships in 3.2.0. This PR now closes #1374, which carries the milestone.

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

Two independent reviews.

worth doing, does not block

  • Pubky swap quotes now get a spending figure only an update can fund (Bitkit/Views/Wallets/Send/SendAmountView.swift:521). A Pubky swap can now be quoted and committed for an amount only the spending balance update can fund, and its hold payment then fails. maxSendLightningSats now includes MoveToSparkMath.combinedSendableSats, the amount Spark could send after a move (WalletViewModel.swift:1606). SendAmountView.quoteSwapRoute still passes that figure to PubkySwapsRouteService.quote as lightningSpendableSats (SendAmountView.swift:521). The insufficient-funds check at :448 reads the same figure. Swap routes deliberately skip the update: sparkUpdatePaymentSats returns nil when hasSwapRoute. performSwapRoutedPayment then commits the quote and pays the hold invoice with LightningService.shared.send on a single rail (SendConfirmationView.swift:1594-1603). For an amount above both rails but within their sum, the sequence is: bitkit-core quotes, Confirm commits (which spends the quote), and the hold payment fails because neither rail can carry it. The user lands on the failure screen. The PR already clamps routeContactPayment to MoveToSparkMath.singleRailSendableSats() for this reason ("The hold payment goes out over one rail"). The swap quote and its Amount check need the same clamp. Confirmed by reading the code paths only. Not run: the route is behind PUBKY_SWAPS_ROUTES, which is debug and regtest only, so this is non-blocking.
  • Coverage check and post-move wait apply different Spark fee rules (Bitkit/Managers/MoveToSparkManager.swift:563-579). Before moving, checkCoverage and waitForSpark judge whether Spark can pay using two different rules, so the check can pass for a payment the wait will never accept. - checkCoverage (MoveToSparkManager.swift:563) approves the move when spark.balanceSats + quote.amountSats >= amountSats + estimateSparkFee. - After the move, waitForSpark (:571) waits for SparkSendState.canSend(amountSats). That uses ChannelFreeRailFees.sendableSats and always reserves the 0.25% service fee. The PR's own test shows the gap. testTheUpdateMustCoverThePaymentAndSparksFee accepts 30,000 + 20,000 against a payment of 49,998 with a fee of 2. But sendableSats(balanceSats: 50000) is 49,875 by the formula in LightningService.swift:42, so canSend(49998) is false. In that case the move happens and the emptied channel starts closing. The swipe then waits 60 s and throws updateUnsettled, which the user sees as a failed payment. Whether this happens in production depends on whether Spark's prepared lightningFeeSats includes its 0.25% service fee. The Breez SDK bindings don't say, and I couldn't confirm it. The J2 evidence (₿ 202 on 50,000) suggests it may, in which case only the test is misleading. Suggested fix: also require SparkSendState(balanceSats: have).canSend(amountSats) in coversPayment, so the pre-move check matches the condition the wait and LightningService.shouldPayWithRail use.
  • Exact-capacity invoices miss the combined-balance path (Bitkit/Managers/MoveToSparkManager.swift:101-103). An amount equal to channel capacity falls between the direct-send and update checks. This predicate requires the amount to exceed capacity, while canSendWithChannels requires capacity to exceed the amount. An isolated execution with 32,000 sats in channels and 30,000 on Spark rejected 32,000 sats but accepted 32,001 through the update path.

the reviewers disagree, your call

  • Contact payments reject amounts that need a spending update (Bitkit/Views/Wallets/Send/SendAmountView.swift:576-579). Objection: Real, but non-blocking rather than blocking: Confirmed. Every contact payment with bitcoin endpoints goes through the router (SendAmountView:423-428, SendConfirmationView:1722-1729), which only gets the single-rail limit, while the amount check at line 448 uses the combined maxSendLightningSats. A split-balance contact LNURL or request is refused with the amount-exceeded toast and never reaches the update code that the PR says handles requests. The Android twin (#1967) puts this exact // The hold payment goes out over one rail cap on the Pubky Swaps quote and gives the Paykit router the full max. So iOS put it on the wrong call and left the swap quote at line 521 uncapped. Non-blocking because base had the same refusal and no funds are at risk.
  • A refreshed quote can replace the fee approved by the swipe (Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift:383-386). Objection: Real, but non-blocking rather than blocking: Confirmed. confirmSparkUpdateQuote runs before requestPinCheck, and that call pushes .pin onto the stack (SendSheet:907-925). When PIN pops, the view's .task runs again (the comments at lines 102 and 562 already note PIN cancels it). It reassigns sparkUpdateQuote while the LNURL callback is still pending, and line 386 reads that reassigned value as shown, so a fee that rose after the swipe passes the guard. SendConfirmationView:2023 does the same through calculateRoutingFee. Non-blocking: it needs PIN without biometrics plus a fee rise within seconds, and the overcharge is a few sats. The fix is to capture the approved quote at the swipe and pass that.

An in-flight payment's HTLC lowers a channel's send limit until it
settles, so after a move a channel the move did not empty could look
emptied and be closed. The close after a move now skips every channel
while the node lists an outbound payment as pending, or can't list its
payments.

Verified: swiftformat --lint on the changed files; simulator unit tests for MoveToSpark, LnurlPayConfirm, SendConfirmation, ChannelFreeRail, SparkTransferFlow, WalletViewModelSend and QuickPayPaymentCoordinator (294 passed)
An HTLC still counting against the peer's in-flight limit lowers a channel's send limit without emptying it. A channel now closes only when its outbound capacity is under the move minimum too.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (42 passed); swiftformat --lint
LDK's outbound capacity leaves out the commitment fee the funder keeps back, so a channel a full move emptied could still read 1 000 sats or more and stay open. The close check now takes that fee off the capacity of a channel we funded, the higher of an anchor and a legacy commitment at its feerate.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (43 passed); swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 19, 2026 16:36
A send the user made from another channel while a move ran could empty that channel and settle before the move, and the move then closed it too. Each move now reads the payments when it starts and closes nothing if a payment other than a move's changed since. The commitment fee taken off a funded channel's capacity no longer counts the anchors LDK already took off: an anchor commitment with two HTLCs, as LDK reserves.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (44 passed); swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 19, 2026 16:54
The close check took an anchor commitment's fee off every channel we funded, so a legacy channel a move emptied could still read over 1 000 sats and stay open. ldk-node does not expose the channel type, so it is read from the channel before the move: a send limit at least the legacy reserve under the capacity means a legacy commitment, whose fee is one HTLC at twice the feerate.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (45 passed); swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 19, 2026 17:51
A peer's in-flight cap made an anchor channel read as legacy, so the close took the legacy fee off a channel that could still send 1 332 sats once the move's HTLC cleared. The close no longer estimates any commitment fee: a channel with capacity left whose send limit is under the minimum is read again every 2 s for up to 30 s, and closes only if its limit stays under it.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (43 passed); swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 19, 2026 18:33
After the 30 s recheck a channel could still close on a send limit the move's HTLC held down, though it could send 1 332 sats once that cleared. A channel with capacity left now closes only when the gap between its capacity and limit is exactly LDK's commitment fee for an anchor or a legacy commitment; otherwise it stays open for a manual close.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (43 passed); swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 19, 2026 19:04
A send limit the peer's in-flight cap held down could match a commitment reserve by chance, so the first read skipped the recheck and closed a channel the move had not emptied. A channel with capacity left now closes only when its reserve explains its limit in two reads 2 s apart with nothing changed between them.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (44 passed); swiftformat --lint
@ovitrif
ovitrif requested a review from ben-kaufman November 19, 2026 20:03
The reserve check used one HTLC for a legacy commitment, so a legacy channel a move emptied (1 400 sats of capacity sending 860 at 253 sat/kW) matched neither reserve and stayed open. It now predicts the limit as LDK 0.2 computes it once HTLCs clear: an above-dust HTLC and the fee spike buffer HTLC, doubled for legacy, and one HTLC less under the dust limit.

Verified: m1a MoveToSparkMathTests, MoveToSparkUpdateTests, MoveToSparkQuoteTests, MoveToSparkLateOutcomeTests (44 passed); swiftformat --lint
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.

4 participants