Skip to content

Commit 2a7e34d

Browse files
committed
f Use sync thread only for BDK wallet
1 parent 7d74b69 commit 2a7e34d

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

src/lib.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -544,49 +544,53 @@ impl LdkLite {
544544
std::thread::spawn(move || {
545545
tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(
546546
async move {
547-
let mut rounds = 0;
548547
loop {
549548
if stop_sync.load(Ordering::Acquire) {
550549
return;
551550
}
552-
// As syncing the on-chain wallet is much more time-intesive, we only sync every
553-
// fifth round.
554-
if rounds == 0 {
555-
let now = Instant::now();
556-
match wallet.sync().await {
557-
Ok(()) => log_info!(
558-
sync_logger,
559-
"On-chain wallet sync finished in {}ms.",
560-
now.elapsed().as_millis()
561-
),
562-
Err(err) => {
563-
log_error!(sync_logger, "On-chain wallet sync failed: {}", err)
564-
}
565-
}
566-
}
567-
rounds = (rounds + 1) % 5;
568-
569-
let confirmables = vec![
570-
&*sync_cman as &(dyn Confirm + Sync + Send),
571-
&*sync_cmon as &(dyn Confirm + Sync + Send),
572-
];
573551
let now = Instant::now();
574-
match tx_sync.sync(confirmables).await {
552+
match wallet.sync().await {
575553
Ok(()) => log_info!(
576554
sync_logger,
577-
"Lightning wallet sync finished in {}ms.",
555+
"On-chain wallet sync finished in {}ms.",
578556
now.elapsed().as_millis()
579557
),
580-
Err(e) => {
581-
log_error!(sync_logger, "Lightning wallet sync failed: {}", e)
558+
Err(err) => {
559+
log_error!(sync_logger, "On-chain wallet sync failed: {}", err)
582560
}
583561
}
584-
tokio::time::sleep(Duration::from_secs(5)).await;
562+
tokio::time::sleep(Duration::from_secs(20)).await;
585563
}
586564
},
587565
);
588566
});
589567

568+
let sync_logger = Arc::clone(&self.logger);
569+
let stop_sync = Arc::clone(&stop_wallet_sync);
570+
tokio_runtime.spawn(async move {
571+
loop {
572+
if stop_sync.load(Ordering::Acquire) {
573+
return;
574+
}
575+
let now = Instant::now();
576+
let confirmables = vec![
577+
&*sync_cman as &(dyn Confirm + Sync + Send),
578+
&*sync_cmon as &(dyn Confirm + Sync + Send),
579+
];
580+
match tx_sync.sync(confirmables).await {
581+
Ok(()) => log_info!(
582+
sync_logger,
583+
"Lightning wallet sync finished in {}ms.",
584+
now.elapsed().as_millis()
585+
),
586+
Err(e) => {
587+
log_error!(sync_logger, "Lightning wallet sync failed: {}", e)
588+
}
589+
}
590+
tokio::time::sleep(Duration::from_secs(5)).await;
591+
}
592+
});
593+
590594
let stop_networking = Arc::new(AtomicBool::new(false));
591595
if let Some(listening_address) = &self.config.listening_address {
592596
// Setup networking

0 commit comments

Comments
 (0)