@@ -1380,17 +1380,15 @@ impl Node {
13801380 ///
13811381 /// This API is experimental. Currently, a splice-in will be marked as an outbound payment, but
13821382 /// this classification may change in the future.
1383- pub fn splice_in (
1383+ fn splice_in_inner (
13841384 & self , user_channel_id : & UserChannelId , counterparty_node_id : PublicKey ,
1385- splice_amount_sats : u64 ,
1385+ splice_amount_sats : Option < u64 > ,
13861386 ) -> Result < ( ) , Error > {
13871387 let open_channels =
13881388 self . channel_manager . list_channels_with_counterparty ( & counterparty_node_id) ;
13891389 if let Some ( channel_details) =
13901390 open_channels. iter ( ) . find ( |c| c. user_channel_id == user_channel_id. 0 )
13911391 {
1392- self . check_sufficient_funds_for_channel ( splice_amount_sats, & counterparty_node_id) ?;
1393-
13941392 const EMPTY_SCRIPT_SIG_WEIGHT : u64 =
13951393 1 /* empty script_sig */ * bitcoin:: constants:: WITNESS_SCALE_FACTOR as u64 ;
13961394
@@ -1410,25 +1408,63 @@ impl Node {
14101408 satisfaction_weight : EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT ,
14111409 } ;
14121410
1413- let shared_output = bitcoin:: TxOut {
1414- value : shared_input. previous_utxo . value + Amount :: from_sat ( splice_amount_sats) ,
1415- // will not actually be the exact same script pubkey after splice
1416- // but it is the same size and good enough for coin selection purposes
1417- script_pubkey : funding_output. script_pubkey . clone ( ) ,
1418- } ;
1419-
14201411 let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
14211412
1422- let inputs = self
1423- . wallet
1424- . select_confirmed_utxos ( vec ! [ shared_input] , & [ shared_output] , fee_rate)
1425- . map_err ( |( ) | {
1426- log_error ! (
1413+ let ( splice_amount_sats, inputs) = match splice_amount_sats {
1414+ Some ( amount) => {
1415+ self . check_sufficient_funds_for_channel ( amount, & counterparty_node_id) ?;
1416+
1417+ let shared_output = bitcoin:: TxOut {
1418+ value : shared_input. previous_utxo . value + Amount :: from_sat ( amount) ,
1419+ // will not actually be the exact same script pubkey after splice
1420+ // but it is the same size and good enough for coin selection purposes
1421+ script_pubkey : funding_output. script_pubkey . clone ( ) ,
1422+ } ;
1423+
1424+ let inputs = self
1425+ . wallet
1426+ . select_confirmed_utxos ( vec ! [ shared_input] , & [ shared_output] , fee_rate)
1427+ . map_err ( |( ) | {
1428+ log_error ! (
1429+ self . logger,
1430+ "Failed to splice channel: insufficient confirmed UTXOs" ,
1431+ ) ;
1432+ Error :: ChannelSplicingFailed
1433+ } ) ?;
1434+
1435+ ( amount, inputs)
1436+ } ,
1437+ None => {
1438+ let cur_anchor_reserve_sats =
1439+ total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
1440+
1441+ let ( amount, inputs) = self
1442+ . wallet
1443+ . get_max_splice_in_amount (
1444+ shared_input,
1445+ funding_output. script_pubkey . clone ( ) ,
1446+ cur_anchor_reserve_sats,
1447+ fee_rate,
1448+ )
1449+ . map_err ( |e| {
1450+ log_error ! (
1451+ self . logger,
1452+ "Failed to determine max splice-in amount: {e:?}"
1453+ ) ;
1454+ e
1455+ } ) ?;
1456+
1457+ log_info ! (
14271458 self . logger,
1428- "Failed to splice channel: insufficient confirmed UTXOs" ,
1459+ "Splicing in with all balance: {}sats (fee rate: {} sat/kw, anchor reserve: {}sats)" ,
1460+ amount,
1461+ fee_rate. to_sat_per_kwu( ) ,
1462+ cur_anchor_reserve_sats,
14291463 ) ;
1430- Error :: ChannelSplicingFailed
1431- } ) ?;
1464+
1465+ ( amount, inputs)
1466+ } ,
1467+ } ;
14321468
14331469 let change_address = self . wallet . get_new_internal_address ( ) ?;
14341470
@@ -1482,6 +1518,42 @@ impl Node {
14821518 }
14831519 }
14841520
1521+ /// Add funds to an existing channel from a transaction output you control.
1522+ ///
1523+ /// This provides for increasing a channel's outbound liquidity without re-balancing or closing
1524+ /// it. Once negotiation with the counterparty is complete, the channel remains operational
1525+ /// while waiting for a new funding transaction to confirm.
1526+ ///
1527+ /// # Experimental API
1528+ ///
1529+ /// This API is experimental. Currently, a splice-in will be marked as an outbound payment, but
1530+ /// this classification may change in the future.
1531+ pub fn splice_in (
1532+ & self , user_channel_id : & UserChannelId , counterparty_node_id : PublicKey ,
1533+ splice_amount_sats : u64 ,
1534+ ) -> Result < ( ) , Error > {
1535+ self . splice_in_inner ( user_channel_id, counterparty_node_id, Some ( splice_amount_sats) )
1536+ }
1537+
1538+ /// Add all available on-chain funds into an existing channel.
1539+ ///
1540+ /// This is similar to [`Node::splice_in`] but uses all available confirmed on-chain funds
1541+ /// instead of requiring a specific amount.
1542+ ///
1543+ /// This provides for increasing a channel's outbound liquidity without re-balancing or closing
1544+ /// it. Once negotiation with the counterparty is complete, the channel remains operational
1545+ /// while waiting for a new funding transaction to confirm.
1546+ ///
1547+ /// # Experimental API
1548+ ///
1549+ /// This API is experimental. Currently, a splice-in will be marked as an outbound payment, but
1550+ /// this classification may change in the future.
1551+ pub fn splice_in_with_all (
1552+ & self , user_channel_id : & UserChannelId , counterparty_node_id : PublicKey ,
1553+ ) -> Result < ( ) , Error > {
1554+ self . splice_in_inner ( user_channel_id, counterparty_node_id, None )
1555+ }
1556+
14851557 /// Remove funds from an existing channel, sending them to an on-chain address.
14861558 ///
14871559 /// This provides for decreasing a channel's outbound liquidity without re-balancing or closing
0 commit comments