Add Node::get_max_splice_in_amount accessor#28
Merged
amackillop merged 1 commit intoMay 8, 2026
Merged
Conversation
Computes the wallet's maximum splice-in contribution for a channel via a dry-run drain transaction at the live ChannelFunding fee rate, preserving the anchor-channels reserve as a wallet change output. Plugs directly into splice_in as splice_amount_sats, so callers can splice everything without computing fees themselves. Backports upstream's Node::splice_in_with_all (4a2cefc) without the splice API rework (d9336f2) that sits between it and our pin. A pin bump is painful because of LSPS4 fork rebases on rust-lightning, so we replicate just the amount computation here and leave splice_in unchanged. Once we do bump past d9336f2, this accessor is the only thing that gets replaced with splice_in_with_all, and mdkd's caller follows. The drain pattern mirrors Wallet::send_to_address's AllRetainingReserve branch: drain_wallet plus drain_to(funding script), with an add_recipient for cur_anchor_reserve_sats when non-dust so the reserve survives as wallet change. Wallet net contribution = drain output value minus foreign input total, which is what splice_in adds to the channel. The motivating caller is mdkd's auto-splice manager. It previously computed a static 400 vB upper-bound fee, capped at N=3 client UTXOs, so consolidation flows had to close channels one or two at a time. With this accessor mdkd uses BDK's exact coin selection and that caveat goes away. A pure-mdkd alternative was considered: binary-search splice_in calls until one succeeds. We didn't take it because Error::ChannelSplicingFailed collapses BDK selection failure and genuine peer rejection into one variant, so the retry loop can't tell "shrink the amount" from "give up".
5dce44b
into
lsp-0.7.0_accept-underpaying-htlcs_with_timing_logs
6 of 34 checks passed
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Computes the wallet's maximum splice-in contribution for a channel via a dry-run drain transaction at the live ChannelFunding fee rate, preserving the anchor-channels reserve as a wallet change output. Plugs directly into splice_in as splice_amount_sats, so callers can splice everything without computing fees themselves.
Backports upstream's Node::splice_in_with_all (4a2cefc) without the splice API rework (d9336f2) that sits between it and our pin. A pin bump is painful because of LSPS4 fork rebases on rust-lightning, so we replicate just the amount computation here and leave splice_in unchanged. Once we do bump past d9336f2, this accessor is the only thing that gets replaced with splice_in_with_all, and mdkd's caller follows.
The drain pattern mirrors Wallet::send_to_address's AllRetainingReserve branch: drain_wallet plus drain_to(funding script), with an add_recipient for cur_anchor_reserve_sats when non-dust so the reserve survives as wallet change. Wallet net contribution = drain output value minus foreign input total, which is what splice_in adds to the channel.
The motivating caller is mdkd's auto-splice manager. It previously computed a static 400 vB upper-bound fee, capped at N=3 client UTXOs, so consolidation flows had to close channels one or two at a time. With this accessor mdkd uses BDK's exact coin selection and that caveat goes away.
A pure-mdkd alternative was considered: binary-search splice_in calls until one succeeds. We didn't take it because Error::ChannelSplicingFailed collapses BDK selection failure and genuine peer rejection into one variant, so the retry loop can't tell "shrink the amount" from "give up".