@@ -46,7 +46,7 @@ pub(crate) struct LightningWalletImpl {
4646 store : Arc < dyn DynStore > ,
4747 payment_receipt_flag : watch:: Receiver < ( ) > ,
4848 channel_pending_receipt_flag : watch:: Receiver < u128 > ,
49- splice_pending_receipt_flag : watch:: Receiver < u128 > ,
49+ splice_pending_receipt_flag : watch:: Receiver < Option < ( u128 , OutPoint ) > > ,
5050 lsp_node_id : PublicKey ,
5151 lsp_socket_addr : SocketAddress ,
5252}
@@ -176,7 +176,7 @@ impl LightningWallet {
176176 Arc :: new ( builder. build_with_store ( node_entropy, LdkNodeStore ( Arc :: clone ( & store) ) ) ?) ;
177177 let ( payment_receipt_sender, payment_receipt_flag) = watch:: channel ( ( ) ) ;
178178 let ( channel_pending_sender, channel_pending_receipt_flag) = watch:: channel ( 0 ) ;
179- let ( splice_pending_sender, splice_pending_receipt_flag) = watch:: channel ( 0 ) ;
179+ let ( splice_pending_sender, splice_pending_receipt_flag) = watch:: channel ( None ) ;
180180 let ev_handler = Arc :: new ( LdkEventHandler {
181181 event_queue,
182182 ldk_node : Arc :: clone ( & ldk_node) ,
@@ -222,10 +222,14 @@ impl LightningWallet {
222222 flag. wait_for ( |t| t == & channel_id) . await . expect ( "channel pending not received" ) ;
223223 }
224224
225- pub ( crate ) async fn await_splice_pending ( & self , channel_id : u128 ) {
225+ pub ( crate ) async fn await_splice_pending ( & self , channel_id : u128 ) -> OutPoint {
226226 let mut flag = self . inner . splice_pending_receipt_flag . clone ( ) ;
227227 flag. mark_unchanged ( ) ;
228- flag. wait_for ( |t| t == & channel_id) . await . expect ( "splice pending not received" ) ;
228+ let got = flag
229+ . wait_for ( |t| matches ! ( t, Some ( ( id, _) ) if * id == channel_id) )
230+ . await
231+ . expect ( "splice pending not received" ) ;
232+ got. expect ( "matched value is Some" ) . 1
229233 }
230234
231235 pub ( crate ) fn get_on_chain_address ( & self ) -> Result < Address , NodeError > {
@@ -343,53 +347,28 @@ impl LightningWallet {
343347 amount_sats,
344348 ) ?;
345349
346- loop {
350+ let funding_txo =
347351 self . await_splice_pending ( chan. user_channel_id . 0 ) . await ;
348- let channels = self . inner . ldk_node . list_channels ( ) ;
349- let new_chan = channels
350- . iter ( )
351- . find ( |c| c. user_channel_id == chan. user_channel_id ) ;
352- match new_chan {
353- Some ( c) => {
354- if c. funding_txo
355- . is_some_and ( |f| f != chan. funding_txo . unwrap ( ) )
356- {
357- let funding_txo = c. funding_txo . unwrap ( ) ;
358-
359- let id = PaymentId ( funding_txo. txid . to_byte_array ( ) ) ;
360- let details = PaymentDetails {
361- id,
362- kind : PaymentKind :: Onchain {
363- txid : funding_txo. txid ,
364- status : ConfirmationStatus :: Unconfirmed , // todo how do we update this?
365- } ,
366- amount_msat : Some ( amount_sats * 1_000 ) ,
367- fee_paid_msat : Some ( 69 ) , // todo get real fee
368- direction : PaymentDirection :: Outbound ,
369- status : PaymentStatus :: Succeeded ,
370- latest_update_timestamp : SystemTime :: now ( )
371- . duration_since ( SystemTime :: UNIX_EPOCH )
372- . unwrap ( )
373- . as_secs ( ) ,
374- } ;
375-
376- store:: write_splice_out (
377- self . inner . store . as_ref ( ) ,
378- & details,
379- )
380- . await ;
381- return Ok ( id) ;
382- }
383- } ,
384- None => {
385- log_error ! (
386- self . inner. logger,
387- "Channel disappeared while awaiting splice out"
388- ) ;
389- return Err ( NodeError :: WalletOperationFailed ) ;
390- } ,
391- }
392- }
352+
353+ let id = PaymentId ( funding_txo. txid . to_byte_array ( ) ) ;
354+ let details = PaymentDetails {
355+ id,
356+ kind : PaymentKind :: Onchain {
357+ txid : funding_txo. txid ,
358+ status : ConfirmationStatus :: Unconfirmed , // todo how do we update this?
359+ } ,
360+ amount_msat : Some ( amount_sats * 1_000 ) ,
361+ fee_paid_msat : Some ( 69 ) , // todo get real fee
362+ direction : PaymentDirection :: Outbound ,
363+ status : PaymentStatus :: Succeeded ,
364+ latest_update_timestamp : SystemTime :: now ( )
365+ . duration_since ( SystemTime :: UNIX_EPOCH )
366+ . unwrap ( )
367+ . as_secs ( ) ,
368+ } ;
369+
370+ store:: write_splice_out ( self . inner . store . as_ref ( ) , & details) . await ;
371+ Ok ( id)
393372 } ,
394373 }
395374 }
@@ -587,26 +566,10 @@ impl graduated_rebalancer::LightningWallet for LightningWallet {
587566 fn await_splice_pending (
588567 & self , channel_id : u128 ,
589568 ) -> Pin < Box < dyn Future < Output = OutPoint > + Send + ' _ > > {
590- Box :: pin ( async move {
591- // todo since we can't see if we have any active splices, we just await the next splice pending event
592- // this is kinda race-y hopefully we can fix
593- self . await_splice_pending ( channel_id) . await ;
594- loop {
595- let channels = self . inner . ldk_node . list_channels ( ) ;
596- let chan = channels
597- . into_iter ( )
598- . find ( |c| c. user_channel_id . 0 == channel_id && c. funding_txo . is_some ( ) ) ;
599- match chan {
600- Some ( c) => {
601- return c. funding_txo . expect ( "channel has no funding txo" ) ;
602- } ,
603- None => {
604- self . await_splice_pending ( channel_id) . await ;
605- // Wait for the next channel pending event
606- } ,
607- }
608- }
609- } )
569+ // `ChannelDetails.funding_txo` from `list_channels` still reports the old funding
570+ // outpoint between `SplicePending` and `SpliceLocked`, so we return the new outpoint
571+ // from the event itself rather than reading it back from the channel.
572+ Box :: pin ( async move { self . await_splice_pending ( channel_id) . await } )
610573 }
611574}
612575
0 commit comments