@@ -123,8 +123,8 @@ pub use builder::BuildError;
123
123
pub use builder:: NodeBuilder as Builder ;
124
124
125
125
use 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 ,
128
128
WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
129
129
} ;
130
130
use connection:: ConnectionManager ;
@@ -377,25 +377,31 @@ impl Node {
377
377
& * sync_sweeper as & ( dyn Confirm + Sync + Send ) ,
378
378
] ;
379
379
let now = Instant :: now( ) ;
380
- match tx_sync. sync( confirmables) . await {
381
- Ok ( ( ) ) => {
382
- log_trace!(
383
- sync_logger,
384
- "Background sync of Lightning wallet finished in {}ms." ,
385
- now. elapsed( ) . as_millis( )
386
- ) ;
387
- let unix_time_secs_opt =
388
- SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
389
- * sync_wallet_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
390
-
391
- periodically_archive_fully_resolved_monitors(
392
- Arc :: clone( & archive_cman) ,
393
- Arc :: clone( & archive_cmon) ,
394
- Arc :: clone( & sync_monitor_archival_height)
395
- ) ;
380
+ let timeout_fut = tokio:: time:: timeout( Duration :: from_secs( LDK_WALLET_SYNC_TIMEOUT_SECS ) , tx_sync. sync( confirmables) ) ;
381
+ match timeout_fut. await {
382
+ Ok ( res) => match res {
383
+ Ok ( ( ) ) => {
384
+ log_trace!(
385
+ sync_logger,
386
+ "Background sync of Lightning wallet finished in {}ms." ,
387
+ now. elapsed( ) . as_millis( )
388
+ ) ;
389
+ let unix_time_secs_opt =
390
+ SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
391
+ * sync_wallet_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
392
+
393
+ periodically_archive_fully_resolved_monitors(
394
+ Arc :: clone( & archive_cman) ,
395
+ Arc :: clone( & archive_cmon) ,
396
+ Arc :: clone( & sync_monitor_archival_height)
397
+ ) ;
398
+ }
399
+ Err ( e) => {
400
+ log_error!( sync_logger, "Background sync of Lightning wallet failed: {}" , e)
401
+ }
396
402
}
397
403
Err ( e) => {
398
- log_error!( sync_logger, "Background sync of Lightning wallet failed : {}" , e)
404
+ log_error!( sync_logger, "Background sync of Lightning wallet timed out : {}" , e)
399
405
}
400
406
}
401
407
}
@@ -1167,6 +1173,8 @@ impl Node {
1167
1173
tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) . block_on (
1168
1174
async move {
1169
1175
let now = Instant :: now ( ) ;
1176
+ // We don't add an additional timeout here, as `Wallet::sync` already returns
1177
+ // after a timeout.
1170
1178
match wallet. sync ( ) . await {
1171
1179
Ok ( ( ) ) => {
1172
1180
log_info ! (
@@ -1187,6 +1195,8 @@ impl Node {
1187
1195
} ;
1188
1196
1189
1197
let now = Instant :: now ( ) ;
1198
+ // We don't add an additional timeout here, as
1199
+ // `FeeEstimator::update_fee_estimates` already returns after a timeout.
1190
1200
match fee_estimator. update_fee_estimates ( ) . await {
1191
1201
Ok ( ( ) ) => {
1192
1202
log_info ! (
@@ -1207,30 +1217,40 @@ impl Node {
1207
1217
}
1208
1218
1209
1219
let now = Instant :: now ( ) ;
1210
- match tx_sync. sync ( confirmables) . await {
1211
- Ok ( ( ) ) => {
1212
- log_info ! (
1213
- sync_logger,
1214
- "Sync of Lightning wallet finished in {}ms." ,
1215
- now. elapsed( ) . as_millis( )
1216
- ) ;
1220
+ let tx_sync_timeout_fut = tokio:: time:: timeout (
1221
+ Duration :: from_secs ( LDK_WALLET_SYNC_TIMEOUT_SECS ) ,
1222
+ tx_sync. sync ( confirmables) ,
1223
+ ) ;
1224
+ match tx_sync_timeout_fut. await {
1225
+ Ok ( res) => match res {
1226
+ Ok ( ( ) ) => {
1227
+ log_info ! (
1228
+ sync_logger,
1229
+ "Sync of Lightning wallet finished in {}ms." ,
1230
+ now. elapsed( ) . as_millis( )
1231
+ ) ;
1217
1232
1218
- let unix_time_secs_opt = SystemTime :: now ( )
1219
- . duration_since ( UNIX_EPOCH )
1220
- . ok ( )
1221
- . map ( |d| d. as_secs ( ) ) ;
1222
- * sync_wallet_timestamp. write ( ) . unwrap ( ) = unix_time_secs_opt;
1233
+ let unix_time_secs_opt = SystemTime :: now ( )
1234
+ . duration_since ( UNIX_EPOCH )
1235
+ . ok ( )
1236
+ . map ( |d| d. as_secs ( ) ) ;
1237
+ * sync_wallet_timestamp. write ( ) . unwrap ( ) = unix_time_secs_opt;
1223
1238
1224
- periodically_archive_fully_resolved_monitors (
1225
- archive_cman,
1226
- archive_cmon,
1227
- sync_monitor_archival_height,
1228
- ) ;
1229
- Ok ( ( ) )
1239
+ periodically_archive_fully_resolved_monitors (
1240
+ archive_cman,
1241
+ archive_cmon,
1242
+ sync_monitor_archival_height,
1243
+ ) ;
1244
+ Ok ( ( ) )
1245
+ } ,
1246
+ Err ( e) => {
1247
+ log_error ! ( sync_logger, "Sync of Lightning wallet failed: {}" , e) ;
1248
+ Err ( e. into ( ) )
1249
+ } ,
1230
1250
} ,
1231
1251
Err ( e) => {
1232
- log_error ! ( sync_logger, "Sync of Lightning wallet failed : {}" , e) ;
1233
- Err ( e . into ( ) )
1252
+ log_error ! ( sync_logger, "Sync of Lightning wallet timed out : {}" , e) ;
1253
+ Err ( Error :: TxSyncTimeout )
1234
1254
} ,
1235
1255
}
1236
1256
} ,
0 commit comments