Skip to content

Commit 0393a8f

Browse files
committed
Improve sync_wallet docs and use current thread runtime for LDK
1 parent 5679495 commit 0393a8f

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

src/lib.rs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,15 +1415,17 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14151415
}
14161416
}
14171417

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.
14191419
///
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.
14211424
pub fn sync_wallets(&self) -> Result<(), Error> {
14221425
let rt_lock = self.runtime.read().unwrap();
14231426
if rt_lock.is_none() {
14241427
return Err(Error::NotRunning);
14251428
}
1426-
let runtime = rt_lock.as_ref().unwrap();
14271429

14281430
let wallet = Arc::clone(&self.wallet);
14291431
let tx_sync = Arc::clone(&self.tx_sync);
@@ -1446,39 +1448,31 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14461448
"Sync of on-chain wallet finished in {}ms.",
14471449
now.elapsed().as_millis()
14481450
);
1449-
Ok(())
14501451
}
14511452
Err(e) => {
14521453
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())
14541471
}
14551472
}
14561473
},
14571474
)
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+
})
14821476
}
14831477

14841478
/// Close a previously opened channel.

0 commit comments

Comments
 (0)