Repository navigation
Warn before opening a channel whose outbound the automatic swap-out would take - #685
Conversation
…ould take Opening a channel from a node with automatic liquidity management adds its capacity to the node's local balance. When that leaves the balance over the swap-out threshold by at least a weighted provider's min swap, the next run swaps the new outbound back out, paying swap fees. The channel request form now asks for confirmation in that case only; a hot wallet's existing confirmation carries the same warning. The forecast shares the weighted-provider rule with AutoLiquidityManagementJob.
The forecast now leaves out providers AutoLiquidityManagementJob can never pick: no swaps in flight allowed, a max swap below the min swap, or Spark without a Spark wallet (Spark disabled included). A node with a swap budget of 0 gets no warning, as every run stops at an exhausted budget. Reading the source node's balance on Save waits at most 5 seconds, so an unreachable LND doesn't hold the button; on timeout there is no warning.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the channel-opening swap-out warning changes.
No open issues 🎉
What changed in this PR
Adds a warning to the channel-opening UI when automatic liquidity management could swap out the new outbound liquidity, helping operators avoid unwanted swap fees.
Changes:
- Adds swap-out confirmation for cold wallets and includes the warning in the existing hot-wallet confirmation.
- Introduces a forecast helper and shares weighted-provider selection with the automatic liquidity job.
- Adds forecast tests covering balance thresholds, provider limits, and node eligibility.
| File | Description |
|---|---|
test/NodeGuard.Tests/Services/SwapOutForecastTests.cs |
Tests forecast thresholds and provider eligibility. |
src/Services/SwapProviderLimits.cs |
Centralizes weighted-provider selection and the Loop fallback. |
src/Services/SwapOutForecast.cs |
Estimates new outbound liquidity subject to automatic swap-out. |
src/Pages/ChannelRequests.razor |
Adds warning confirmations and a five-second balance-read timeout. |
src/Jobs/AutoLiquidityManagementJob.cs |
Uses the shared weighted-provider selection rule. |
Review effort: Balanced
There was a problem hiding this comment.
🔒 Automated security review — no issues found
This PR adds a UI-only warning on the Channel Requests page: before creating an open-channel request it forecasts, via the new static SwapOutForecast, whether AutoLiquidityManagementJob would swap the new outbound back out, and gates creation behind a confirmation modal. The weighted-provider rule moved into SwapProviderLimits.Weighted, shared by job and forecast; the job-side refactor is behavior-preserving (same >0 weight filter, same all-weights-≤0 → Loop fallback). I found no way in: the only user-controlled string in the MarkupString-rendered modal body (node.Name) is HtmlEncode'd and the rest is numeric; request creation is re-entrancy-guarded (_createInFlight / pre-existing _approvalInFlight with try/finally and OkDisabled); ChannelBalanceAsync already swallows all exceptions to null, so the new TimeoutException catch is the only added error path and fails open to "no warning" as described; SparkSettings is registered in DI; no authz, fund-moving, or key-handling path changed.
Reviewed 12 files at 326095d. Nothing to report.
Not a guarantee — one diff, no knowledge of your threat model.
🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.
AutoLiquidityManagementJobswaps the new outbound back out.ChannelRequests.razorasks for confirmation only when the open would lead to a swap-out:MinimumBalanceThresholdSatsby enough for a weighted provider the job can pick: max swaps in flight above 0,min(excess, max swap) >= min swapand, for Spark, a Spark wallet for the node (none while Spark is disabled).SwapOutForecastholds the check. The weighted-provider rule moves toSwapProviderLimits.Weighted, used by both the forecast andAutoLiquidityManagementJob, so they can't drift.SwapOutForecastTests:AutoLiquidityManagementJobTestsand the full suite pass.OpenChannelcallers get no warning.