@@ -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:: util:: persist:: KVStoreSync ;
@@ -1290,84 +1288,37 @@ impl Node {
12901288 {
12911289 self . check_sufficient_funds_for_channel ( splice_amount_sats, & counterparty_node_id) ?;
12921290
1293- const EMPTY_SCRIPT_SIG_WEIGHT : u64 =
1294- 1 /* empty script_sig */ * bitcoin:: constants:: WITNESS_SCALE_FACTOR as u64 ;
1295-
1296- let funding_txo = channel_details. funding_txo . ok_or_else ( || {
1297- log_error ! ( self . logger, "Failed to splice channel: channel not yet ready" , ) ;
1298- Error :: ChannelSplicingFailed
1299- } ) ?;
1300-
1301- let funding_output = channel_details. get_funding_output ( ) . ok_or_else ( || {
1302- log_error ! ( self . logger, "Failed to splice channel: channel not yet ready" ) ;
1303- Error :: ChannelSplicingFailed
1304- } ) ?;
1305-
1306- let shared_input = Input {
1307- outpoint : funding_txo. into_bitcoin_outpoint ( ) ,
1308- previous_utxo : funding_output. clone ( ) ,
1309- satisfaction_weight : EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT ,
1310- } ;
1311-
1312- let shared_output = bitcoin:: TxOut {
1313- value : shared_input. previous_utxo . value + Amount :: from_sat ( splice_amount_sats) ,
1314- // will not actually be the exact same script pubkey after splice
1315- // but it is the same size and good enough for coin selection purposes
1316- script_pubkey : funding_output. script_pubkey . clone ( ) ,
1317- } ;
1318-
13191291 let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
13201292
1321- let inputs = self
1322- . wallet
1323- . select_confirmed_utxos ( vec ! [ shared_input] , & [ shared_output] , fee_rate)
1324- . map_err ( |( ) | {
1325- log_error ! (
1326- self . logger,
1327- "Failed to splice channel: insufficient confirmed UTXOs" ,
1328- ) ;
1293+ let funding_template = self
1294+ . channel_manager
1295+ . splice_channel ( & channel_details. channel_id , & counterparty_node_id, fee_rate)
1296+ . map_err ( |e| {
1297+ log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
13291298 Error :: ChannelSplicingFailed
13301299 } ) ?;
13311300
1332- let change_address = self . wallet . get_new_internal_address ( ) ?;
1333-
1334- let contribution = SpliceContribution :: splice_in (
1335- Amount :: from_sat ( splice_amount_sats) ,
1336- inputs,
1337- Some ( change_address. script_pubkey ( ) ) ,
1338- ) ;
1339-
1340- let funding_feerate_per_kw: u32 = match fee_rate. to_sat_per_kwu ( ) . try_into ( ) {
1341- Ok ( fee_rate) => fee_rate,
1342- Err ( _) => {
1343- debug_assert ! ( false ) ;
1344- fee_estimator:: get_fallback_rate_for_target ( ConfirmationTarget :: ChannelFunding )
1345- } ,
1346- } ;
1301+ let contribution = self
1302+ . runtime
1303+ . block_on (
1304+ funding_template
1305+ . splice_in ( Amount :: from_sat ( splice_amount_sats) , Arc :: clone ( & self . wallet ) ) ,
1306+ )
1307+ . map_err ( |( ) | {
1308+ log_error ! ( self . logger, "Failed to splice channel: coin selection failed" ) ;
1309+ Error :: ChannelSplicingFailed
1310+ } ) ?;
13471311
13481312 self . channel_manager
1349- . splice_channel (
1313+ . funding_contributed (
13501314 & channel_details. channel_id ,
13511315 & counterparty_node_id,
13521316 contribution,
1353- funding_feerate_per_kw,
13541317 None ,
13551318 )
13561319 . map_err ( |e| {
13571320 log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
1358- let tx = bitcoin:: Transaction {
1359- version : bitcoin:: transaction:: Version :: TWO ,
1360- lock_time : bitcoin:: absolute:: LockTime :: ZERO ,
1361- input : vec ! [ ] ,
1362- output : vec ! [ bitcoin:: TxOut {
1363- value: Amount :: ZERO ,
1364- script_pubkey: change_address. script_pubkey( ) ,
1365- } ] ,
1366- } ;
1367- match self . wallet . cancel_tx ( & tx) {
1368- Ok ( ( ) ) => Error :: ChannelSplicingFailed ,
1369- Err ( e) => e,
1370- }
1321+ Error :: ChannelSplicingFailed
13711322 } )
13721323 } else {
13731324 log_error ! (
@@ -1376,7 +1327,6 @@ impl Node {
13761327 user_channel_id,
13771328 counterparty_node_id
13781329 ) ;
1379-
13801330 Err ( Error :: ChannelSplicingFailed )
13811331 }
13821332 }
@@ -1407,27 +1357,33 @@ impl Node {
14071357
14081358 self . wallet . parse_and_validate_address ( address) ?;
14091359
1410- let contribution = SpliceContribution :: splice_out ( vec ! [ bitcoin:: TxOut {
1360+ let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
1361+
1362+ let funding_template = self
1363+ . channel_manager
1364+ . splice_channel ( & channel_details. channel_id , & counterparty_node_id, fee_rate)
1365+ . map_err ( |e| {
1366+ log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
1367+ Error :: ChannelSplicingFailed
1368+ } ) ?;
1369+
1370+ let outputs = vec ! [ bitcoin:: TxOut {
14111371 value: Amount :: from_sat( splice_amount_sats) ,
14121372 script_pubkey: address. script_pubkey( ) ,
1413- } ] ) ;
1414-
1415- let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
1416- let funding_feerate_per_kw: u32 = match fee_rate. to_sat_per_kwu ( ) . try_into ( ) {
1417- Ok ( fee_rate) => fee_rate,
1418- Err ( _) => {
1419- debug_assert ! ( false , "FeeRate should always fit within u32" ) ;
1420- log_error ! ( self . logger, "FeeRate should always fit within u32" ) ;
1421- fee_estimator:: get_fallback_rate_for_target ( ConfirmationTarget :: ChannelFunding )
1422- } ,
1423- } ;
1373+ } ] ;
1374+ let contribution = self
1375+ . runtime
1376+ . block_on ( funding_template. splice_out ( outputs, Arc :: clone ( & self . wallet ) ) )
1377+ . map_err ( |( ) | {
1378+ log_error ! ( self . logger, "Failed to splice channel: coin selection failed" ) ;
1379+ Error :: ChannelSplicingFailed
1380+ } ) ?;
14241381
14251382 self . channel_manager
1426- . splice_channel (
1383+ . funding_contributed (
14271384 & channel_details. channel_id ,
14281385 & counterparty_node_id,
14291386 contribution,
1430- funding_feerate_per_kw,
14311387 None ,
14321388 )
14331389 . map_err ( |e| {
0 commit comments