@@ -138,12 +138,10 @@ use gossip::GossipSource;
138138use graph:: NetworkGraph ;
139139use io:: utils:: write_node_metrics;
140140use lightning:: chain:: BestBlock ;
141- use lightning:: events:: bump_transaction:: { Input , Wallet as LdkWallet } ;
141+ use lightning:: events:: bump_transaction:: Wallet as LdkWallet ;
142142use lightning:: impl_writeable_tlv_based;
143- use lightning:: ln:: chan_utils:: FUNDING_TRANSACTION_WITNESS_WEIGHT ;
144143use lightning:: ln:: channel_state:: { ChannelDetails as LdkChannelDetails , ChannelShutdownState } ;
145144use lightning:: ln:: channelmanager:: PaymentId ;
146- use lightning:: ln:: funding:: SpliceContribution ;
147145use lightning:: ln:: msgs:: SocketAddress ;
148146use lightning:: routing:: gossip:: NodeAlias ;
149147use lightning:: sign:: EntropySource ;
@@ -1295,84 +1293,37 @@ impl Node {
12951293 {
12961294 self . check_sufficient_funds_for_channel ( splice_amount_sats, & counterparty_node_id) ?;
12971295
1298- const EMPTY_SCRIPT_SIG_WEIGHT : u64 =
1299- 1 /* empty script_sig */ * bitcoin:: constants:: WITNESS_SCALE_FACTOR as u64 ;
1300-
1301- let funding_txo = channel_details. funding_txo . ok_or_else ( || {
1302- log_error ! ( self . logger, "Failed to splice channel: channel not yet ready" , ) ;
1303- Error :: ChannelSplicingFailed
1304- } ) ?;
1305-
1306- let funding_output = channel_details. get_funding_output ( ) . ok_or_else ( || {
1307- log_error ! ( self . logger, "Failed to splice channel: channel not yet ready" ) ;
1308- Error :: ChannelSplicingFailed
1309- } ) ?;
1310-
1311- let shared_input = Input {
1312- outpoint : funding_txo. into_bitcoin_outpoint ( ) ,
1313- previous_utxo : funding_output. clone ( ) ,
1314- satisfaction_weight : EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT ,
1315- } ;
1316-
1317- let shared_output = bitcoin:: TxOut {
1318- value : shared_input. previous_utxo . value + Amount :: from_sat ( splice_amount_sats) ,
1319- // will not actually be the exact same script pubkey after splice
1320- // but it is the same size and good enough for coin selection purposes
1321- script_pubkey : funding_output. script_pubkey . clone ( ) ,
1322- } ;
1323-
13241296 let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
13251297
1326- let inputs = self
1327- . wallet
1328- . select_confirmed_utxos ( vec ! [ shared_input] , & [ shared_output] , fee_rate)
1329- . map_err ( |( ) | {
1330- log_error ! (
1331- self . logger,
1332- "Failed to splice channel: insufficient confirmed UTXOs" ,
1333- ) ;
1298+ let funding_template = self
1299+ . channel_manager
1300+ . splice_channel ( & channel_details. channel_id , & counterparty_node_id, fee_rate)
1301+ . map_err ( |e| {
1302+ log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
13341303 Error :: ChannelSplicingFailed
13351304 } ) ?;
13361305
1337- let change_address = self . wallet . get_new_internal_address ( ) ?;
1338-
1339- let contribution = SpliceContribution :: splice_in (
1340- Amount :: from_sat ( splice_amount_sats) ,
1341- inputs,
1342- Some ( change_address. script_pubkey ( ) ) ,
1343- ) ;
1344-
1345- let funding_feerate_per_kw: u32 = match fee_rate. to_sat_per_kwu ( ) . try_into ( ) {
1346- Ok ( fee_rate) => fee_rate,
1347- Err ( _) => {
1348- debug_assert ! ( false ) ;
1349- fee_estimator:: get_fallback_rate_for_target ( ConfirmationTarget :: ChannelFunding )
1350- } ,
1351- } ;
1306+ let contribution = self
1307+ . runtime
1308+ . block_on (
1309+ funding_template
1310+ . splice_in ( Amount :: from_sat ( splice_amount_sats) , Arc :: clone ( & self . wallet ) ) ,
1311+ )
1312+ . map_err ( |( ) | {
1313+ log_error ! ( self . logger, "Failed to splice channel: coin selection failed" ) ;
1314+ Error :: ChannelSplicingFailed
1315+ } ) ?;
13521316
13531317 self . channel_manager
1354- . splice_channel (
1318+ . funding_contributed (
13551319 & channel_details. channel_id ,
13561320 & counterparty_node_id,
13571321 contribution,
1358- funding_feerate_per_kw,
13591322 None ,
13601323 )
13611324 . map_err ( |e| {
13621325 log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
1363- let tx = bitcoin:: Transaction {
1364- version : bitcoin:: transaction:: Version :: TWO ,
1365- lock_time : bitcoin:: absolute:: LockTime :: ZERO ,
1366- input : vec ! [ ] ,
1367- output : vec ! [ bitcoin:: TxOut {
1368- value: Amount :: ZERO ,
1369- script_pubkey: change_address. script_pubkey( ) ,
1370- } ] ,
1371- } ;
1372- match self . wallet . cancel_tx ( & tx) {
1373- Ok ( ( ) ) => Error :: ChannelSplicingFailed ,
1374- Err ( e) => e,
1375- }
1326+ Error :: ChannelSplicingFailed
13761327 } )
13771328 } else {
13781329 log_error ! (
@@ -1381,7 +1332,6 @@ impl Node {
13811332 user_channel_id,
13821333 counterparty_node_id
13831334 ) ;
1384-
13851335 Err ( Error :: ChannelSplicingFailed )
13861336 }
13871337 }
@@ -1412,27 +1362,33 @@ impl Node {
14121362
14131363 self . wallet . parse_and_validate_address ( address) ?;
14141364
1415- let contribution = SpliceContribution :: splice_out ( vec ! [ bitcoin:: TxOut {
1365+ let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
1366+
1367+ let funding_template = self
1368+ . channel_manager
1369+ . splice_channel ( & channel_details. channel_id , & counterparty_node_id, fee_rate)
1370+ . map_err ( |e| {
1371+ log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
1372+ Error :: ChannelSplicingFailed
1373+ } ) ?;
1374+
1375+ let outputs = vec ! [ bitcoin:: TxOut {
14161376 value: Amount :: from_sat( splice_amount_sats) ,
14171377 script_pubkey: address. script_pubkey( ) ,
1418- } ] ) ;
1419-
1420- let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
1421- let funding_feerate_per_kw: u32 = match fee_rate. to_sat_per_kwu ( ) . try_into ( ) {
1422- Ok ( fee_rate) => fee_rate,
1423- Err ( _) => {
1424- debug_assert ! ( false , "FeeRate should always fit within u32" ) ;
1425- log_error ! ( self . logger, "FeeRate should always fit within u32" ) ;
1426- fee_estimator:: get_fallback_rate_for_target ( ConfirmationTarget :: ChannelFunding )
1427- } ,
1428- } ;
1378+ } ] ;
1379+ let contribution = self
1380+ . runtime
1381+ . block_on ( funding_template. splice_out ( outputs, Arc :: clone ( & self . wallet ) ) )
1382+ . map_err ( |( ) | {
1383+ log_error ! ( self . logger, "Failed to splice channel: coin selection failed" ) ;
1384+ Error :: ChannelSplicingFailed
1385+ } ) ?;
14291386
14301387 self . channel_manager
1431- . splice_channel (
1388+ . funding_contributed (
14321389 & channel_details. channel_id ,
14331390 & counterparty_node_id,
14341391 contribution,
1435- funding_feerate_per_kw,
14361392 None ,
14371393 )
14381394 . map_err ( |e| {
0 commit comments