@@ -1415,15 +1415,17 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1415
1415
}
1416
1416
}
1417
1417
1418
- /// Sync the LDK and BDK wallets with the current chain state.
1418
+ /// Manually sync the LDK and BDK wallets with the current chain state.
1419
1419
///
1420
- /// Note that the wallets will be also synced regularly in the background.
1420
+ /// **Note:** The wallets are regularly synced in the background, which is configurable via
1421
+ /// [`Config::onchain_wallet_sync_interval_secs`] and [`Config::wallet_sync_interval_secs`].
1422
+ /// Therefore, using this blocking sync method is almost always redudant and should be avoided
1423
+ /// where possible.
1421
1424
pub fn sync_wallets ( & self ) -> Result < ( ) , Error > {
1422
1425
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
1423
1426
if rt_lock. is_none ( ) {
1424
1427
return Err ( Error :: NotRunning ) ;
1425
1428
}
1426
- let runtime = rt_lock. as_ref ( ) . unwrap ( ) ;
1427
1429
1428
1430
let wallet = Arc :: clone ( & self . wallet ) ;
1429
1431
let tx_sync = Arc :: clone ( & self . tx_sync ) ;
@@ -1446,39 +1448,31 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1446
1448
"Sync of on-chain wallet finished in {}ms." ,
1447
1449
now. elapsed( ) . as_millis( )
1448
1450
) ;
1449
- Ok ( ( ) )
1450
1451
}
1451
1452
Err ( e) => {
1452
1453
log_error ! ( sync_logger, "Sync of on-chain wallet failed: {}" , e) ;
1453
- Err ( e)
1454
+ return Err ( e) ;
1455
+ }
1456
+ } ;
1457
+
1458
+ let now = Instant :: now ( ) ;
1459
+ match tx_sync. sync ( confirmables) . await {
1460
+ Ok ( ( ) ) => {
1461
+ log_info ! (
1462
+ sync_logger,
1463
+ "Sync of Lightning wallet finished in {}ms." ,
1464
+ now. elapsed( ) . as_millis( )
1465
+ ) ;
1466
+ Ok ( ( ) )
1467
+ }
1468
+ Err ( e) => {
1469
+ log_error ! ( sync_logger, "Sync of Lightning wallet failed: {}" , e) ;
1470
+ Err ( e. into ( ) )
1454
1471
}
1455
1472
}
1456
1473
} ,
1457
1474
)
1458
- } ) ?;
1459
-
1460
- let sync_logger = Arc :: clone ( & self . logger ) ;
1461
- tokio:: task:: block_in_place ( move || {
1462
- runtime. block_on ( async move {
1463
- let now = Instant :: now ( ) ;
1464
- match tx_sync. sync ( confirmables) . await {
1465
- Ok ( ( ) ) => {
1466
- log_info ! (
1467
- sync_logger,
1468
- "Sync of Lightning wallet finished in {}ms." ,
1469
- now. elapsed( ) . as_millis( )
1470
- ) ;
1471
- Ok ( ( ) )
1472
- }
1473
- Err ( e) => {
1474
- log_error ! ( sync_logger, "Sync of Lightning wallet failed: {}" , e) ;
1475
- Err ( e)
1476
- }
1477
- }
1478
- } )
1479
- } ) ?;
1480
-
1481
- Ok ( ( ) )
1475
+ } )
1482
1476
}
1483
1477
1484
1478
/// Close a previously opened channel.
0 commit comments