@@ -123,8 +123,8 @@ pub use builder::BuildError;
123123pub use builder:: NodeBuilder as Builder ;
124124
125125use config:: {
126- default_user_config, NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL ,
127- RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL , RGS_SYNC_INTERVAL ,
126+ default_user_config, LDK_WALLET_SYNC_TIMEOUT_SECS , NODE_ANN_BCAST_INTERVAL ,
127+ PEER_RECONNECTION_INTERVAL , RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL , RGS_SYNC_INTERVAL ,
128128 WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
129129} ;
130130use connection:: ConnectionManager ;
@@ -372,25 +372,31 @@ impl Node {
372372 & * sync_sweeper as & ( dyn Confirm + Sync + Send ) ,
373373 ] ;
374374 let now = Instant :: now( ) ;
375- match tx_sync. sync( confirmables) . await {
376- Ok ( ( ) ) => {
377- log_trace!(
378- sync_logger,
379- "Background sync of Lightning wallet finished in {}ms." ,
380- now. elapsed( ) . as_millis( )
381- ) ;
382- let unix_time_secs_opt =
383- SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
384- * sync_wallet_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
385-
386- periodically_archive_fully_resolved_monitors(
387- Arc :: clone( & archive_cman) ,
388- Arc :: clone( & archive_cmon) ,
389- Arc :: clone( & sync_monitor_archival_height)
390- ) ;
375+ let timeout_fut = tokio:: time:: timeout( Duration :: from_secs( LDK_WALLET_SYNC_TIMEOUT_SECS ) , tx_sync. sync( confirmables) ) ;
376+ match timeout_fut. await {
377+ Ok ( res) => match res {
378+ Ok ( ( ) ) => {
379+ log_trace!(
380+ sync_logger,
381+ "Background sync of Lightning wallet finished in {}ms." ,
382+ now. elapsed( ) . as_millis( )
383+ ) ;
384+ let unix_time_secs_opt =
385+ SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
386+ * sync_wallet_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
387+
388+ periodically_archive_fully_resolved_monitors(
389+ Arc :: clone( & archive_cman) ,
390+ Arc :: clone( & archive_cmon) ,
391+ Arc :: clone( & sync_monitor_archival_height)
392+ ) ;
393+ }
394+ Err ( e) => {
395+ log_error!( sync_logger, "Background sync of Lightning wallet failed: {}" , e)
396+ }
391397 }
392398 Err ( e) => {
393- log_error!( sync_logger, "Background sync of Lightning wallet failed : {}" , e)
399+ log_error!( sync_logger, "Background sync of Lightning wallet timed out : {}" , e)
394400 }
395401 }
396402 }
0 commit comments