Skip to content

wallet: preview unilateral exits across selected proofs - #1653

Merged
bhandras merged 1 commit into
mainfrom
issue-1651-exit-preview
Nov 27, 2026
Merged

bhandras merged 1 commit into
mainfrom
issue-1651-exit-preview

Conversation

@bhandras

@bhandras bhandras commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

A wallet can hold one confirmed output with enough value to pay for several unilateral exits. The existing exit plan allocates distinct coins across the selection and can derive a funding address while preparing its answer. A mobile client needs to price a selection before asking the user to spend.

Add a read-only wallet RPC, PreviewUnilateralExit. It resolves selected proofs, prices each distinct recovery transaction once, and reports the network fee, wallet-funded portion and estimated transaction count. It tries separate confirmed inputs first and projects change reuse after confirmation. A shortfall produces one estimated deposit amount. A missing target, unusable proof, or economic refusal stays in its original position with an admission error. The remaining viable targets determine fees and the projected deposit. Face value includes every selected descriptor whose amount is known. An active job contributes its full proof cost. Change reuse describes the funding source and can coincide with an existing parent confirmation wait.

The preview creates no exit job or wallet reservation. Existing exit commands keep their current admission behavior. The SDK propagates an older server's unsupported-method error. Approval, the enforceable spending limit and optional split pricing are subsequent parts of #1651.

The Go quote tests cover shared ancestry, distinct coins, confirmed change and the change dust boundary. The SDK test covers read-only compatibility. A Bitcoin Core regtest with an LND wallet previewed two real exits twice, observed a deposit requirement, funded one coin and observed a change-reuse estimate. Neither target had an exit job after either preview.

A Bitcoin Core regtest on LND, lwwallet and btcwallet previewed a missing outpoint followed by a viable two-tree target. The first entry retained its admission error. The second remained viable. Selected amount, estimated transaction count, network fee and deposit matched the viable target's standalone quote.

@bhandras

Copy link
Copy Markdown
Member Author

/gateway review

Review the read-only preview contract. Trace shared transactions, amount and confirmation eligibility, dust and asset fees, the suggested deposit and the SDK on an older daemon. Check for an observable write through an ordinary preview. Report material correctness issues reachable through the new RPC. The execution queue and signed fee cap are separate slices.

@lightninglabs-gateway

lightninglabs-gateway Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

❌ gateway review failed: code-review skill failed across all auth modes: You've hit your org's monthly spend limit · ask your admin to raise it at https://claude.ai/admin-settings/usage · your weekly limit resets Nov 29, 6am (UTC)

See workflow logs for details.

@bhandras
bhandras force-pushed the issue-1651-exit-preview branch from e8e0b2a to fe80208 Compare November 26, 2026 17:14
@bhandras

Copy link
Copy Markdown
Member Author

Claude: Verdict: approve. No merge blockers.

The advisory fix is correct. A cooperative round commitment no longer counts as an admission refusal, and the coin is still quoted.

Advisory fix (waved/rpc_wallet_exit_preview.go)

  • setFundingEligibility sets RoundCommitment from exitPlanRoundCommitment(desc) and sets AdmissionError only for ExitSweepBelowDust / ExitUneconomical. Round state and wallet funding no longer leak into the refusal field.
  • A missing batch expiry is no longer treated as a refusal either. It only affects sort order in QuoteWalletExit, so a zero expiry gets funded first. That is the safe direction.

The same coin stays quotable

  • Every target that is not already completed is added to targets whether or not it has a round commitment or an admission error. The selection total, the shared-ancestry fee union and the deposit figure all still include it. This matches GetExitPlan, where ExitRoundCommitted is advisory and the funding numbers are still computed.

The warning crosses RPC and SDK

  • Proto: UnilateralExitTarget.round_commitment = 8, kept separate from admission_error = 7.
  • swapwallet/admin.go: maps it with errorString(entry.RoundCommitment).
  • SDK: UnilateralExitTarget.RoundCommitment is populated in sdk/wavewalletdk/unilateral_exit_preview.go.
  • Mobile, WASM and the REST client all pass the response through unchanged.
  • Permissions: PreviewUnilateralExit is granted under onchain read, which fits a call with no side effects.

Tests

  • TestPreviewUnilateralExitCommittedTarget asserts that a PendingForfeit VTXO gets RoundCommitment wrapping ErrForfeitInFlight and an empty AdmissionError. That is exactly the earlier blocker.
  • unroll/wallet_exit_quote_test.go covers counting shared ancestry once, change reuse, the fee-input floor and the dust boundary. It also checks that the caller's coin snapshot is not modified.
  • I read the tests but did not run them. CI should confirm they pass.

Non-blocking follow-up

  • No test covers RoundCommitment after it leaves waved. The SDK fixture only sets AdmissionError, and the swapwallet fake returns an empty preview. Adding RoundCommitment: "..." to the previewWalletClient fixture plus one require.Equal would guard the field mapping. The mapping is a direct copy today, so this does not need to hold the merge.

Good to merge.

@bhandras
bhandras force-pushed the issue-1651-exit-preview branch from fe80208 to 5f12a87 Compare November 27, 2026 10:18
@bhandras
bhandras changed the base branch from main to issue-1651-durable-fee-splits November 27, 2026 10:18
@bhandras
bhandras added this pull request to stack #1660 November 27, 2026 10:18
@bhandras

Copy link
Copy Markdown
Member Author

/gateway review

Please review the current commit 5f12a87 against its PR base. Focus on reachable ownership, confirmation gating, and wallet quote correctness within this layer.

@lightninglabs-gateway

lightninglabs-gateway Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

❌ gateway review failed: code-review skill failed across all auth modes: You've hit your org's monthly spend limit · ask your admin to raise it at https://claude.ai/admin-settings/usage · your weekly limit resets Nov 29, 6am (UTC)

See workflow logs for details.

@bhandras

Copy link
Copy Markdown
Member Author

Claude: I found no blocking issues in this layer. The preview is read-only, its quote is never too low for a fresh selection, and the SDK mapping is correct. Tests were not run here because running them needed approval; I reviewed by reading the code and the callers.

What I checked

  • Read-only. waved.PreviewUnilateralExit only reads: the VTXO descriptor, GetUnrollStatus, lineage and proof assembly, and ListWalletUnspent. It never calls exitPlanFundingAddress, unlike GetExitPlan (waved/rpc_exit_plan.go:318). It never leases coins or admits a job. Granting it under onchain:read (waved/rpc_auth.go) is correct.
  • Shared ancestry is priced once. QuoteWalletExit keeps one set of proof txids across all targets. Each parent and its CPFP child are counted once, and each target still gets its own final spend. The commitment tx is an external prevout, so it is never priced. TestWalletExitQuoteSharedAncestry covers the sibling-output case.
  • Funding projection never quotes too little. Fees are paid from fresh confirmed coins first (smallest coin covering fee + DustLimit), then from projected change. Fees still unpaid are summed into one deposit of max(DefaultFeeInputMinAmountSat, missing + DustLimit). That deposit can pay the remaining packages one after another, and every step leaves change at or above dust. The caller's amounts slice is left unchanged.
  • Asset targets. The extra claim child comes from AssessExitFeasibility{AssetClaim: true}, which adds child plus sweep vbytes and no sweep fee. This matches PlanExitFunding, so the preview and admission agree.
  • Eligibility. Completed jobs skip lineage resolution, so a VTXO that is already spent does not fail the batch. ResolveLineage rejects only Spent, Forfeited and Failed, so in-progress and round-committed targets are still priced. The round commitment is reported as an advisory through exitPlanRoundCommitment, the same as GetExitPlan. AdmissionError is set only for below-dust and uneconomical results, which no amount of funding can fix.
  • Mapping. swapwallet → proto → SDK carries every field. A target with no job maps to EXIT_JOB_STATUS_UNSPECIFIED. funding_action is chosen as deposit, then reuse change, then confirmed inputs, which matches the quote.

Follow-ups (not blocking)

  1. Targets with a running exit job are priced as if nothing has happened yet. Proof nodes that already confirmed are charged again, and coins leased to that job are missing from the snapshot. The preview then overstates fees and may suggest a deposit the user does not need. It never understates. If the UI shows a deposit for such targets, consider skipping confirmed nodes or leaving these targets out of the quote.
  2. One bad outpoint fails the whole request. GetExitPlan reports per-entry errors; this RPC returns FailedPrecondition for the whole batch. That is fine if clients only send live VTXOs, but the difference should be documented on the RPC.

@bhandras
bhandras force-pushed the issue-1651-exit-preview branch from 5f12a87 to 80fd194 Compare November 27, 2026 12:54
@bhandras

Copy link
Copy Markdown
Member Author

/gateway review

Re-review 80fd194 against its immediate parent. Check confirmed-spender ownership and per-entry admission within the scope of this PR. Report concrete blockers and distinguish them from follow-ups.

@lightninglabs-gateway

lightninglabs-gateway Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

❌ gateway review failed: code-review skill failed across all auth modes: You've hit your org's monthly spend limit · ask your admin to raise it at https://claude.ai/admin-settings/usage · your weekly limit resets Nov 29, 6am (UTC)

See workflow logs for details.

@bhandras

Copy link
Copy Markdown
Member Author

Claude: I found no material defects in #1653 at 80fd194b. Safe to merge.

Here is what I traced, in the three areas you asked about.

Per-entry refusals

  • waved/rpc_wallet_exit_preview.go: the entry is created before its proof is resolved, so every outpoint keeps its request position.
  • An unknown outpoint becomes AdmissionError and does not fail the request. GetVTXO wraps the not-found case as vtxo.ErrVTXONotFound (db/vtxo_store.go:203), so the errors.Is check matches.
  • Terminal VTXOs (Spent, Forfeited, Failed) are refused by ResolveLineage through validateProofDescriptorActive (unroll/proof_assembler.go:290). They become entry errors and are left out of the quote.
  • Dust and uneconomical refusals use PlanExitFunding with an empty wallet snapshot. That is correct: AssessExitFeasibility checks dust and economics before wallet funding (unroll/feasibility.go:368-386), so the empty snapshot cannot hide those reasons. Asset claims skip both checks on purpose.
  • A round-committed coin gets a warning only and is still priced. This matches GetExitPlan and the manual Unroll path.
  • Only request-level problems fail the whole call: a malformed or duplicate outpoint, or a store or status lookup error.

Viable aggregate

  • QuoteWalletExit charges each shared proof node and its fee child once across the selection. Each target adds one final spend. An asset target adds one more wallet-funded claim child, with no sweep fee.
  • The economic check runs per target on the full proof, while the aggregate counts shared nodes once. The per-target check is stricter, but it is the same check Unroll admission applies, so the preview cannot accept a target that admission would refuse.
  • projectExitFeeCoins: it never changes the caller's coin list. The 10,000 sat floor (DefaultFeeInputMinAmountSat) only limits which existing coins count, and no broadcaster enforces it. The deposit (unmet fees plus dust, at least the floor) is enough to fund the leftover packages one after another.

Active-job funding

  • Completed jobs are skipped before lineage resolution. They add their face value and no fee, as documented.
  • Active jobs are priced on their full proof against the current confirmed coins. When a job has already spent its fee coins, the preview can report DEPOSIT and a non-zero additional_funding_sat that is not actually needed. This is the documented contract ("not a remaining-cost estimate", "Active jobs are priced from their full proofs") and the deposit is still enough. It cannot lose funds or block recovery. At worst it asks for more than needed. Not a blocker.
  • If a fee spike makes an active job look uneconomical, it gets an AdmissionError and drops out of the aggregate. That is display-only and does not affect the running job.

I could not run the new tests: the test commands were blocked by the permission prompt. The verdict comes from reading the code.

@bhandras
bhandras force-pushed the issue-1651-exit-preview branch from 80fd194 to e88a656 Compare November 27, 2026 13:05
@bhandras

Copy link
Copy Markdown
Member Author

/gateway review

Review e88a656 against its immediate parent. Check confirmed-spender recovery and the wallet preview semantics in their respective PRs.

@lightninglabs-gateway

lightninglabs-gateway Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

❌ gateway review failed: code-review skill failed across all auth modes: You've hit your org's monthly spend limit · ask your admin to raise it at https://claude.ai/admin-settings/usage · your weekly limit resets Nov 29, 6am (UTC)

See workflow logs for details.

@bhandras

Copy link
Copy Markdown
Member Author

Claude: No merge blockers. e88a656 is ready to merge.

What changed since 80fd194: formatting only, in waved/rpc_wallet_exit_preview.go. One condition is wrapped and some blank lines were added before continue. The logic is the same as what you reviewed. The other files in the 80fd194..e88a656 diff are the txconfirm commits from the rebase, not this PR.

Per-entry error partition (waved/rpc_wallet_exit_preview.go:96-170)

Case Result In AmountSat In quote
Bad or duplicate outpoint whole RPC fails, InvalidArgument – –
ErrVTXONotFound AdmissionError no (0) no
Any other GetVTXO error whole RPC fails – –
GetUnrollStatus error whole RPC fails – –
Job completed entry skipped, no error yes no
Lineage resolve fails AdmissionError, or ctx error if cancelled yes no
Proof assembly fails AdmissionError yes no
Sweep below dust / uneconomical AdmissionError yes no
Round commitment advisory only, still priced yes yes
  • A target with no job does not fail the RPC. GetUnrollStatus returns Found:false with a nil error (waved/rpc_server.go:5626-5637). That was the only case that could have sunk the whole batch.
  • The entry pointer is taken after append and only used inside the same loop pass. Safe.
  • A round commitment stays an advisory. That matches GetExitPlan and the waved/CLAUDE.md rule.

Aggregation (unroll/wallet_exit_quote.go)

  • Proof transactions shared across targets are deduplicated by txid. Each target still adds its own sweep, plus one more child for an asset claim.
  • QuoteWalletExit errors only on a rate ≤ 0 or a nil proof. The handler rules out both before calling it.
  • Transactions == 0 only happens when there are no targets. In that case the handler returns early, so FundingAction stays UNSPECIFIED, which is correct.
  • The caller's coin list is not modified. The test asserts this.

Documented semantics (wallet.proto)

  • selected_amount_sat: "including refused or completed, unknown contributes zero". Matches the code.
  • estimated_transactions: "viable unfinished targets, full proofs, not remaining cost". Matches the code.
  • admission_error: "excluded from aggregate costs, siblings still contribute". Matches the code.
  • additional_funding_sat: "sufficient single deposit for serial recovery, zero does not imply admission". Matches projectExitFeeCoins.
  • The funding-action order in swapwallet/admin.go (deposit, then reuse change, then confirmed inputs) matches the enum docs.

Not blocking, optional follow-up: the handler has no test where some targets are refused and some are viable in one request. The unknown-target test and the quote tests cover each half separately.

As requested, I made no edits, ran no tests, and posted nothing.

@bhandras
bhandras force-pushed the issue-1651-exit-preview branch from e88a656 to 0e35630 Compare November 27, 2026 13:35
Base automatically changed from issue-1651-durable-fee-splits to main November 27, 2026 13:35
Quote each shared recovery transaction once and project confirmed wallet
change across later packages. Expose the selection and per-target status
through a read-only wallet RPC so clients can preview without allocating
an address or admitting an exit.
@bhandras
bhandras force-pushed the issue-1651-exit-preview branch from 0e35630 to db4fcb0 Compare November 27, 2026 13:35
@bhandras
bhandras merged commit b856f94 into main Nov 27, 2026
21 of 22 checks passed
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.

1 participant