Skip to content

Commit 179a0d7

Browse files
committed
Add auto-splice manager background task
Spawns a polling loop from MdkClient::start that watches for confirmed on-chain funds and automatically splices them into an existing LSP channel — the symmetric counterpart of the LSP-side splice-instead-of-open on the inbound path. Default poll is 30s; tunable via SpliceConfig. Each tick: 1. Read list_balances().spendable_onchain_balance_sats. Skip if 0. 2. Pick the highest-capacity channel where counterparty is the configured LSP, is_usable, and has a funding_txo. 3. Compute fee = ceil(feerate_sat_per_kwu * 400 vB * 4 / 1000), using the live ChannelFunding feerate. Skip if balance ≤ fee. 4. splice_in(amount = balance - fee). Emit SpliceInitiated on Ok; log+continue on InsufficientFunds; emit SpliceFailed on other. The 400 vB constant covers force-close-recovery (N≤3 confirmed UTXOs) with headroom; the derivation table is in the file's doc comment. Drop it once we bump ldk-node past 4a2cefc1 and switch to splice_in_with_all. In-flight tracking. is_usable alone is not a sound signal: a channel mid-splice can still report is_usable=true after we've sent our 0-conf splice_locked but before the LSP returns theirs (gated on inbound_splice_minimum_depth confirmations). The manager keeps a HashMap<UCID, InFlight { initial_funding_txo, promoted_at }> driven by ChannelDetails::funding_txo. While the channel's active funding still equals the outpoint captured at splice_in time, the splice is in flight and the channel is excluded from the candidate pool (rust-lightning only swaps self.funding once both sides have exchanged splice_locked, in maybe_promote_splice_funding). Once funding_txo flips, the entry is held for BDK_RESYNC_GRACE (60s) so the next tick doesn't race continuously_sync_wallets and re-fire on a UTXO BDK hasn't yet observed as spent. SkipReason::SpliceAlreadyInFlight surfaces it in logs. Idempotency across mdkd restart still relies on BDK locking the selected UTXOs in the pending splice tx — the in-flight map is in- memory only.
1 parent 73c7bd8 commit 179a0d7

5 files changed

Lines changed: 697 additions & 84 deletions

File tree

0 commit comments

Comments
 (0)