@@ -8,7 +8,7 @@ use bitcoin_bech32::WitnessProgram;
88use lightning:: chain:: { chainmonitor, ChannelMonitorUpdateStatus } ;
99use lightning:: chain:: { BestBlock , Filter , Watch } ;
1010use lightning:: events:: bump_transaction:: { BumpTransactionEventHandler , Wallet } ;
11- use lightning:: events:: { Event , PaymentFailureReason , PaymentPurpose } ;
11+ use lightning:: events:: { Event , PaymentFailureReason , PaymentPurpose , ReplayEvent } ;
1212use lightning:: ln:: channelmanager:: { self , PaymentId , RecentPaymentDetails } ;
1313use lightning:: ln:: channelmanager:: {
1414 ChainParameters , ChannelManagerReadArgs , SimpleArcChannelManager ,
@@ -505,7 +505,7 @@ async fn handle_ldk_events(
505505 event : Event ,
506506 unlocked_state : Arc < UnlockedAppState > ,
507507 static_state : Arc < StaticState > ,
508- ) {
508+ ) -> Result < ( ) , ReplayEvent > {
509509 match event {
510510 Event :: FundingGenerationReady {
511511 temporary_channel_id,
@@ -578,6 +578,7 @@ async fn handle_ldk_events(
578578
579579 let funding_tx = psbt. clone ( ) . extract_tx ( ) . unwrap ( ) ;
580580 let funding_txid = funding_tx. compute_txid ( ) . to_string ( ) ;
581+ tracing:: info!( "Funding TXID: {funding_txid}" ) ;
581582
582583 let psbt_path = static_state
583584 . ldk_data_dir
@@ -618,7 +619,7 @@ async fn handle_ldk_events(
618619
619620 if let Err ( e) = res {
620621 tracing:: error!( "cannot post consignment: {e}" ) ;
621- return ;
622+ return Err ( ReplayEvent ( ) ) ;
622623 }
623624 }
624625
@@ -980,15 +981,24 @@ async fn handle_ldk_events(
980981
981982 let state_copy = unlocked_state. clone ( ) ;
982983 let psbt_str_copy = psbt_str. clone ( ) ;
984+
985+ let is_chan_colored =
986+ is_channel_rgb ( & channel_id, & PathBuf :: from ( & static_state. ldk_data_dir ) ) ;
987+ tracing:: info!( "Initiator of the channel (colored: {})" , is_chan_colored) ;
988+
983989 let _txid = tokio:: task:: spawn_blocking ( move || {
984- if is_channel_rgb ( & channel_id , & PathBuf :: from ( & static_state . ldk_data_dir ) ) {
985- state_copy. rgb_send_end ( psbt_str_copy) . unwrap ( ) . txid
990+ if is_chan_colored {
991+ state_copy. rgb_send_end ( psbt_str_copy) . map ( |r| r . txid )
986992 } else {
987- state_copy. rgb_send_btc_end ( psbt_str_copy) . unwrap ( )
993+ state_copy. rgb_send_btc_end ( psbt_str_copy)
988994 }
989995 } )
990996 . await
991- . unwrap ( ) ;
997+ . unwrap ( )
998+ . map_err ( |e| {
999+ tracing:: error!( "Error completing channel opening: {e:?}" ) ;
1000+ ReplayEvent ( )
1001+ } ) ?;
9921002
9931003 * unlocked_state. rgb_send_lock . lock ( ) . unwrap ( ) = false ;
9941004 } else {
@@ -997,7 +1007,8 @@ async fn handle_ldk_events(
9971007 . ldk_data_dir
9981008 . join ( format ! ( "consignment_{funding_txid}" ) ) ;
9991009 if !consignment_path. exists ( ) {
1000- return ;
1010+ // vanilla channel
1011+ return Ok ( ( ) ) ;
10011012 }
10021013 let consignment =
10031014 RgbTransfer :: load_file ( consignment_path) . expect ( "successful consignment load" ) ;
@@ -1118,7 +1129,7 @@ async fn handle_ldk_events(
11181129 . channel_manager
11191130 . fail_intercepted_htlc ( intercept_id)
11201131 . unwrap ( ) ;
1121- return ;
1132+ return Ok ( ( ) ) ;
11221133 }
11231134 Some ( x) => x,
11241135 } ;
@@ -1167,7 +1178,7 @@ async fn handle_ldk_events(
11671178 . channel_manager
11681179 . fail_intercepted_htlc ( intercept_id)
11691180 . unwrap ( ) ;
1170- return ;
1181+ return Ok ( ( ) ) ;
11711182 }
11721183
11731184 tracing:: debug!( "Swap is whitelisted, forwarding the htlc..." ) ;
@@ -1208,6 +1219,7 @@ async fn handle_ldk_events(
12081219 } ) ;
12091220 }
12101221 }
1222+ Ok ( ( ) )
12111223}
12121224
12131225impl OutputSpender for RgbOutputSpender {
@@ -1997,10 +2009,7 @@ pub(crate) async fn start_ldk(
19972009 let event_handler = move |event : Event | {
19982010 let unlocked_state_copy = Arc :: clone ( & unlocked_state_copy) ;
19992011 let static_state_copy = Arc :: clone ( & static_state_copy) ;
2000- async move {
2001- handle_ldk_events ( event, unlocked_state_copy, static_state_copy) . await ;
2002- Ok ( ( ) )
2003- }
2012+ async move { handle_ldk_events ( event, unlocked_state_copy, static_state_copy) . await }
20042013 } ;
20052014
20062015 // Background Processing
0 commit comments