Skip to content

Commit 129c6ad

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. The is_usable filter is not enough on its own: once the splice tx confirms and splice_locked propagates, the channel flips back to usable, but ldk-node's continuously_sync_wallets only reruns every ~60s. Inside that window list_balances still reports the pre-splice on-chain value (BDK has not yet observed that the UTXO was spent), so a tick that lands here will happily re-fire on the same UTXO. The manager keeps a HashMap<u128, Instant> with a 60s TTL bridging splice completion and the next BDK sync; entries are evicted at the start of every tick. 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 4bd3cbb commit 129c6ad

5 files changed

Lines changed: 559 additions & 84 deletions

File tree

0 commit comments

Comments
 (0)