Skip to content

Add Node::get_max_splice_in_amount accessor#28

Merged
amackillop merged 1 commit into
lsp-0.7.0_accept-underpaying-htlcs_with_timing_logsfrom
austin_mdk-715_get-max-splice-amount
May 8, 2026
Merged

Add Node::get_max_splice_in_amount accessor#28
amackillop merged 1 commit into
lsp-0.7.0_accept-underpaying-htlcs_with_timing_logsfrom
austin_mdk-715_get-max-splice-amount

Conversation

@amackillop
Copy link
Copy Markdown

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".

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".
@amackillop amackillop requested a review from martinsaposnic May 8, 2026 13:56
@amackillop amackillop merged commit 5dce44b into lsp-0.7.0_accept-underpaying-htlcs_with_timing_logs May 8, 2026
6 of 34 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