Repository navigation
iOS: Simplify unilateral exits - #84
Conversation
|
/gateway review Please review 7ee8f79. Focus on the iOS unilateral exit review, funding checks, explicit admission, and observation after navigation or an ambiguous response. Verify the UI uses the existing single-exit SDK contracts and that the funding or progress states cannot accidentally submit twice. Flag concrete regressions introduced by this diff, with the calling path, consequence, and existing guard or recovery. Keep unrelated debt as follow-up. Local simulator unit and a 20-fund UI fixture passed. |
There was a problem hiding this comment.
Gateway review — 3 findings
🔴 0 Blocker · 🟠 1 Major · 🟡 2 Minor · 🔵 0 Nit
Summary
The PR splits the unilateral exit flow into three screens: a fund list with a pinned footer, a plan review that handles funding, and a live status and progress view. It keeps the single-target exitPlan / exitFunds SDK contract. The double-submit guards hold up. submit() sets submitted synchronously behind canStart, and canStart is false while a plan check is in flight. loadPlan() re-checks submitted after its await, so a late plan response cannot reopen the review. An ambiguous exitFunds failure keeps the screen on the status view rather than offering the action again. Polling stops when the scene is inactive or the session is locked. Popping back from the progress screen while a check is in flight is harmless because of the checkingStatus guard.
The regressions are in what the review screen now hides compared with the code it replaces. The funding gate in UnilateralExitFunding.init? drops the old wallet_too_few_inputs branch. A wallet that has enough value but too few separate inputs now gets a generic dead end instead of a funding address. The "active round" warning shown before the irreversible start is gone. The daemon's lastError on a failed exit now sits inside a collapsed Details section.
Lower-severity findings (2)
🟡 F2 (Minor) — Active-round warning dropped before irreversible start · ios/Sample/Sources/UnilateralExitView.swift:163
When entry.canStart is true and entry.roundCommitment is non-empty, the screen no longer warns that starting may interrupt an active round. The removed code showed "These funds already belong to an active round. Starting recovery may interrupt it." in exactly that branch. The new blockedMessage only runs when !entry.canStart, so in that case the user sees "Ready to exit" and a single-tap "Start unilateral exit" with no warning. Show the round-commitment notice next to "Ready to exit" when !entry.roundCommitment.isEmpty.
🟡 F3 (Minor) — Failed exit hides the daemon error behind Details · ios/Sample/Sources/UnilateralExitProgressView.swift:69
When an exit fails, the screen shows "Action needed" but no reason unless the user expands the collapsed "Details" group. The new view shows status.lastError only inside that group. The removed view showed lastError inline in red, and checkFailed only produces a generic "Couldn’t update exit status." Show lastError inline at least when stage == .failed, and keep the copyable row in Details.
Reviewed at medium effort.
Bot commands
/gateway re-review— re-run after pushing changes (maintainers)/gateway dismiss <id>— silence a finding (maintainers)/gateway explain <id>— elaborate on a finding (maintainers or PR author)
| init?(_ entry: ExitPlanEntry) { | ||
| guard !entry.canStart, !entry.exitJobFound, entry.error.isEmpty, | ||
| entry.roundCommitment.isEmpty, | ||
| !entry.fundingAddress.isEmpty, entry.fundingShortfallSat > 0 else { return nil } |
There was a problem hiding this comment.
🟠 F1 (Major) — Too-few-inputs wallets can no longer be funded for exit · ios/Sample/Sources/UnilateralExitView.swift:283
A wallet with enough fee value but too few separate fee inputs gets no way to fund the exit. UnilateralExitFunding.init? requires entry.fundingShortfallSat > 0. When the plan reports infeasibilityReason == "wallet_too_few_inputs" with zero shortfall, fundingOffer is nil. The review screen then shows only "The wallet can’t start this exit right now." (blockedMessage default), with no address, no "Continue to funding" button and no polling. The user cannot start a unilateral exit from this screen.
Why this matters
The removed code in RecoveryViews.swift handled this case explicitly: if item.fundingShortfallSat > 0 || item.infeasibilityReason == "wallet_too_few_inputs". The new gate drops it. paymentCount already handles the case: max(1, required - usable) gives the number of missing inputs, and satsPerPayment falls back to recommendedUTXOAmountSat when the shortfall is 0.
The same gate also affects the funding screen. Suppose that, while fee payments are still unconfirmed, the daemon reports this reason with a zero shortfall. In loadPlan(), fundingOffer becomes nil and funding = nil runs, so awaitingFunding turns false. The polling task then exits before the inputs confirm, and the screen falls back to the dead-end message. I can't tell from the diff whether the daemon returns that combination for unconfirmed inputs. If it does, the automatic funding check never reaches "Ready to exit".
Fix: accept fundingShortfallSat > 0 || (infeasibilityReason == "wallet_too_few_inputs" && requiredFeeUTXOCount > usableFeeUTXOCount). Add a test case to RecoveryPresentationTests with required: 3, usable: 1, shortfall: 0.
There was a problem hiding this comment.
Fixed in a540b32. A missing confirmed fee output still gets a funding offer when the value shortfall is zero. We use the planner’s per-output recommendation and keep checking until the required outputs confirm. Added a test for two missing outputs and a zero shortfall.
|
🤖 gateway audit metadata for this PR — auto-generated, please don't edit. |
Keep the selected amount and review action visible as funds scroll. Show the current daemon plan before funding, and check confirmation until the wallet is ready for the user's explicit approval to start.
Present publication, block delay and the final sweep as a live sequence. Keep the status readable while the wallet waits, and show the sweep transaction when the daemon reports it.
7ee8f79 to
a540b32
Compare
|
/gateway re-review Fixed F1–F3 in a540b32. Missing outputs still get a funding offer with zero value shortfall, with a regression test. I restored the active-round warning before Start and the inline reason for failed exits. Please re-check these paths at the current head. |
There was a problem hiding this comment.
Gateway review
No findings.
Status of prior findings
- F1 addressed: Fixed at
ios/Sample/Sources/UnilateralExitView.swift:285-287. A funding offer is now created when there is a value shortfall, or when the reason iswallet_too_few_inputsand inputs are still missing (required - usable > 0).paymentCount = max(1, missingInputs)and the fallback torecommendedUTXOAmountSatgive 2 × 10,000 sats for therequired: 3, usable: 1, shortfall: 0case.RecoveryPresentationTests.swift:13-21covers that case and the case where nothing is missing (usable: 3). The funding-screen concern is also closed. While inputs are still missing,fundingOfferstays non-nil, soloadPlan()no longer clearsfundingand polling continues. - F2 addressed: Fixed at
ios/Sample/Sources/UnilateralExitView.swift:165-168. WhencanStartis true androundCommitmentis non-empty, the screen now shows "These funds are in an active round. Starting the exit may interrupt it." next to "Ready to exit". - F3 addressed: Fixed at
ios/Sample/Sources/UnilateralExitProgressView.swift:61-63. Whenstage == .failed,lastErrornow shows inline in red. The copyable row in Details is still there.
Reviewed at medium effort.
Bot commands
/gateway re-review— re-run after pushing changes (maintainers)/gateway dismiss <id>— silence a finding (maintainers)/gateway explain <id>— elaborate on a finding (maintainers or PR author)
Replace the cooperative exit menu with the unilateral flow. Keep pending cooperative receipts under Payment checks so existing users can follow their status. Review individual VTXOs or every available one together. Check the selection again before starting the individual SDK calls, and stop on the first unconfirmed result. Show the status of each attempted exit.
|
/gateway re-review The Settings route now replaces the old Exit screen. Users can review multiple VTXOs together. Please check that the new start path uses the exact reviewed selection, stops on an unconfirmed result, and keeps earlier cooperative exit receipts reachable. |
There was a problem hiding this comment.
Gateway review
No findings.
Status of prior findings
- F1 addressed:
UnilateralExitFunding.init?now acceptsinfeasibilityReason == "wallet_too_few_inputs" && missingInputs > 0with a zero shortfall (ios/Sample/Sources/UnilateralExitView.swift:417-421).paymentCount = max(1, missingInputs), andsatsPerPaymentfalls back torecommendedUTXOAmountSat.testExitFundingWithMissingOutputsAndZeroValueShortfallcovers both the positive case and the case with no missing inputs (RecoveryPresentationTests.swift:13-21). - F2 addressed: The active-round warning now appears next to "Ready to exit" when any entry has a non-empty
roundCommitment(ios/Sample/Sources/UnilateralExitView.swift:186-191). - F3 addressed: When
stage == .failed,lastErroris shown inline in red (ios/Sample/Sources/UnilateralExitProgressView.swift:61-63). The copyable row stays in Details.
Reviewed at medium effort.
Bot commands
/gateway re-review— re-run after pushing changes (maintainers)/gateway dismiss <id>— silence a finding (maintainers)/gateway explain <id>— elaborate on a finding (maintainers or PR author)
The review link remains mounted so admission can update the inventory without dismissing the progress screen. Assert that it cannot be used when no funds are available.
Let the user keep the wallet defaults or choose a Bitcoin payout address and initial fee rate. Require an updated quote after edits and pass those exact options to every reviewed exit. Show the chosen payout in progress, including after a restart, and label a completed payout to another address as sent on-chain.
0fca931 to
be8eaa3
Compare
Only offer a deposit when the quote identifies a fee balance or fee input shortage. Older SDK replies can carry a positive shortfall for an uneconomical exit, so use the typed reason instead. Label the separate-exit estimate and the per-exit deposit so their different scopes are visible during review.
Pin the manual exit SDK over the merged shared-proof preview. Wrap the read-only preview with typed terms, costs, funding and target status.
367c548 to
91df923
Compare
|
/gateway re-review Please review the current head 91df923. Check the read-only selection quote, custom terms and re-quote gates, deposit instructions after admission checks, stale funding state after confirmation, and partial or ambiguous starts. Please flag concrete regressions with a reachable calling path and separate existing SDK limits from this diff. |
There was a problem hiding this comment.
Gateway review — 1 finding
🔴 0 Blocker · 🟠 0 Major · 🟡 1 Minor · 🔵 0 Nit
Summary
All three earlier findings are fixed at this head. Funding offers now cover the missing-outputs case, the active-round warning is back before Start, and a failed exit shows its reason inline. The multi-select flow keeps its main guards:
- Exact selection: the quote and the plan must return the selected outpoints in the same order.
- Pre-start re-check: before the first exit,
startUnilateralExitsreads the plan again. It requirescanStartand a fee rate equal to the reviewed rate. - Stop on uncertainty: the loop stops at the first unconfirmed reply.
- No double tap: a second "Check and start" tap does nothing.
isCheckingand.task(id: action)block it in the view, and the store'sstateCreatingCallCountcheck blocks it again. - Cooperative exits: pending cooperative exits are still reachable from Recovery → Payment checks.
One smaller gap remains. On the automatic fee setting, the reviewed rate is checked once but never sent with the individual exit requests.
Lower-severity findings (1)
🟡 F4 (Minor) — Automatic-fee exits are not held to the reviewed rate · ios/Sample/Sources/WalletStore.swift:1189
When the fee setting is automatic, each exit is sent with feeRateSatPerVByte: 0, so the daemon picks its own rate for each one. The reviewed rate is only compared once, against the plan read before the loop. With up to 100 exits started one after another, a fee estimate that moves partway through can start later exits at a rate the user never reviewed. If the SDK treats an explicit rate the same as an automatic one, pass reviewedFeeRate when options.feeRateSatPerVByte == 0. Otherwise, say in the review that the rate is set separately for each exit.
Status of prior findings
- F1 addressed: Fixed in
ios/Sample/Sources/UnilateralExitPlan.swift:109-112. Awallet_too_few_inputsplan with missing inputs now gets a funding offer even when the value shortfall is zero. Each payment falls back torecommendedUTXOAmountSat.RecoveryPresentationTests.swift:13-21tests both the positive case (3 required, 1 usable) and the negative case (3 required, 3 usable). Resolved. - F2 addressed: The review screen shows "Some selected funds are in an active round." when any entry has a round commitment (
UnilateralExitReviewView.swift:155-158). The warning appears before "Check and start". Funding offers are also suppressed for committed entries (UnilateralExitPlan.swift:115, test atRecoveryPresentationTests.swift:78-81). Resolved. - F3 addressed:
lastErroris shown inline in red whenstage == .failed(UnilateralExitProgressView.swift:67-69). The copyable row is still in Details. Resolved.
Reviewed at medium effort.
Bot commands
/gateway re-review— re-run after pushing changes (maintainers)/gateway dismiss <id>— silence a finding (maintainers)/gateway explain <id>— elaborate on a finding (maintainers or PR author)
Show one estimate for the selected funds and reprice destination and fee edits. Check actual funding before showing deposit instructions. Report progress from confirmed wallet jobs and preserve unattempted targets.
|
/gateway re-review F4 is addressed in the review screen. Automatic mode now explains that the wallet sets the rate when each exit starts. Sending an explicit rate would invoke the SDK's custom-terms admission path, which is limited to standard Bitcoin timeout outputs. The simulator checked that the note appears in Automatic mode and disappears after applying a custom rate. |
91df923 to
201a199
Compare
There was a problem hiding this comment.
Gateway review
No findings.
Status of prior findings
- F1 addressed: Still fixed.
UnilateralExitPlan.swift:111setsneedsFunding = missingInputs > 0forwallet_too_few_inputs, so a zero value shortfall still gets a funding offer.testExitFundingWithMissingOutputsAndZeroValueShortfallcovers it. - F2 addressed: Still fixed.
UnilateralExitReviewView.swift:159-162shows "Some selected funds are in an active round." in the unblocked branch, before "Check and start". - F3 addressed: Still fixed.
UnilateralExitProgressView.swift:67-69showsstatus.lastErrorinline in red whenstage == .failed. The copyable row stays in Details. - F4 addressed: Fixed at
UnilateralExitReviewView.swift:155-157. Whenoptions.feeRateSatPerVByte == 0, the review now says the wallet sets the fee rate when each exit starts, so the user isn't led to expect the quoted rate for every exit. The note shows only in Automatic mode, which is the only mode where the rate can drift. With a custom rate,UnilateralExitSelectionPlanalready requires the plan to echo that rate.
Reviewed at medium effort.
Bot commands
/gateway re-review— re-run after pushing changes (maintainers)/gateway dismiss <id>— silence a finding (maintainers)/gateway explain <id>— elaborate on a finding (maintainers or PR author)
What changes
Settings → Unilateral exit opens a scrollable list of recoverable funds. Select individual funds or use Select all. The selected amount and Review exit stay pinned at the bottom.
The review shows one estimate for the selection. It counts shared Bitcoin transactions once and shows estimated network fees, the portion paid from the on-chain wallet, and any estimated extra funding. Destination and fee rate each have an editor. Applying either setting updates the estimate for the selected funds.
The quote performs no funding or exit writes. Check funding requirements consults the existing admission plan before offering a funding address. If the wallet requires separate fee outputs for the next exit, the app gives those instructions only on the funding screen and returns to review when readiness changes. A blocked exit gives a reason and a way to change the selection.
Check and start verifies readiness and the reviewed rate. The progress screen shows which exits the wallet started, their actual job status, and which funds still need an action. Each exit opens its detailed progress and payout.
SDK dependency
Pins lightninglabs/wavelength#1656 on top of the merged shared exit preview and fee-split recovery. The shared quote is advisory. The current admission API still starts each VTXO separately. One approval for a durable queue and enforceable aggregate spending are tracked in lightninglabs/wavelength#1651.
Verification