@@ -122,8 +122,8 @@ pub use builder::BuildError;
122122pub use builder:: NodeBuilder as Builder ;
123123
124124use config:: {
125- NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL , RGS_SYNC_INTERVAL ,
126- WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
125+ LDK_WALLET_SYNC_TIMEOUT_SECS , NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL ,
126+ RGS_SYNC_INTERVAL , WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
127127} ;
128128use connection:: ConnectionManager ;
129129use event:: { EventHandler , EventQueue } ;
@@ -366,19 +366,25 @@ impl Node {
366366 & * sync_sweeper as & ( dyn Confirm + Sync + Send ) ,
367367 ] ;
368368 let now = Instant :: now( ) ;
369- match tx_sync. sync( confirmables) . await {
370- Ok ( ( ) ) => {
371- log_trace!(
372- sync_logger,
373- "Background sync of Lightning wallet finished in {}ms." ,
374- now. elapsed( ) . as_millis( )
375- ) ;
376- let unix_time_secs_opt =
377- SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
378- * sync_wallet_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
369+ let timeout_fut = tokio:: time:: timeout( Duration :: from_secs( LDK_WALLET_SYNC_TIMEOUT_SECS ) , tx_sync. sync( confirmables) ) ;
370+ match timeout_fut. await {
371+ Ok ( res) => match res {
372+ Ok ( ( ) ) => {
373+ log_trace!(
374+ sync_logger,
375+ "Background sync of Lightning wallet finished in {}ms." ,
376+ now. elapsed( ) . as_millis( )
377+ ) ;
378+ let unix_time_secs_opt =
379+ SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
380+ * sync_wallet_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
381+ }
382+ Err ( e) => {
383+ log_error!( sync_logger, "Background sync of Lightning wallet failed: {}" , e)
384+ }
379385 }
380386 Err ( e) => {
381- log_error!( sync_logger, "Background sync of Lightning wallet failed : {}" , e)
387+ log_error!( sync_logger, "Background sync of Lightning wallet timed out : {}" , e)
382388 }
383389 }
384390 }
0 commit comments