@@ -1342,15 +1342,17 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1342
1342
}
1343
1343
}
1344
1344
1345
- /// Sync the LDK and BDK wallets with the current chain state.
1345
+ /// Manually sync the LDK and BDK wallets with the current chain state.
1346
1346
///
1347
- /// Note that the wallets will be also synced regularly in the background.
1347
+ /// **Note:** The wallets are regularly synced in the background, which is configurable via
1348
+ /// [`Config::onchain_wallet_sync_interval_secs`] and [`Config::wallet_sync_interval_secs`].
1349
+ /// Therefore, using this blocking sync method is almost always redudant and should be avoided
1350
+ /// where possible.
1348
1351
pub fn sync_wallets ( & self ) -> Result < ( ) , Error > {
1349
1352
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
1350
1353
if rt_lock. is_none ( ) {
1351
1354
return Err ( Error :: NotRunning ) ;
1352
1355
}
1353
- let runtime = rt_lock. as_ref ( ) . unwrap ( ) ;
1354
1356
1355
1357
let wallet = Arc :: clone ( & self . wallet ) ;
1356
1358
let tx_sync = Arc :: clone ( & self . tx_sync ) ;
@@ -1373,39 +1375,31 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1373
1375
"Sync of on-chain wallet finished in {}ms." ,
1374
1376
now. elapsed( ) . as_millis( )
1375
1377
) ;
1376
- Ok ( ( ) )
1377
1378
}
1378
1379
Err ( e) => {
1379
1380
log_error ! ( sync_logger, "Sync of on-chain wallet failed: {}" , e) ;
1380
- Err ( e)
1381
+ return Err ( e) ;
1382
+ }
1383
+ } ;
1384
+
1385
+ let now = Instant :: now ( ) ;
1386
+ match tx_sync. sync ( confirmables) . await {
1387
+ Ok ( ( ) ) => {
1388
+ log_info ! (
1389
+ sync_logger,
1390
+ "Sync of Lightning wallet finished in {}ms." ,
1391
+ now. elapsed( ) . as_millis( )
1392
+ ) ;
1393
+ Ok ( ( ) )
1394
+ }
1395
+ Err ( e) => {
1396
+ log_error ! ( sync_logger, "Sync of Lightning wallet failed: {}" , e) ;
1397
+ Err ( e. into ( ) )
1381
1398
}
1382
1399
}
1383
1400
} ,
1384
1401
)
1385
- } ) ?;
1386
-
1387
- let sync_logger = Arc :: clone ( & self . logger ) ;
1388
- tokio:: task:: block_in_place ( move || {
1389
- runtime. block_on ( async move {
1390
- let now = Instant :: now ( ) ;
1391
- match tx_sync. sync ( confirmables) . await {
1392
- Ok ( ( ) ) => {
1393
- log_info ! (
1394
- sync_logger,
1395
- "Sync of Lightning wallet finished in {}ms." ,
1396
- now. elapsed( ) . as_millis( )
1397
- ) ;
1398
- Ok ( ( ) )
1399
- }
1400
- Err ( e) => {
1401
- log_error ! ( sync_logger, "Sync of Lightning wallet failed: {}" , e) ;
1402
- Err ( e)
1403
- }
1404
- }
1405
- } )
1406
- } ) ?;
1407
-
1408
- Ok ( ( ) )
1402
+ } )
1409
1403
}
1410
1404
1411
1405
/// Close a previously opened channel.
0 commit comments