Skip to content

Commit 26a3000

Browse files
committed
sweeper async wip
1 parent 4dd2936 commit 26a3000

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lightning/src/util/sweep.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ where
411411
/// Returns `Err` on persistence failure, in which case the call may be safely retried.
412412
///
413413
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
414-
pub fn track_spendable_outputs(
414+
pub async fn track_spendable_outputs(
415415
&self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>,
416416
exclude_static_outputs: bool, delay_until_height: Option<u32>,
417417
) -> Result<(), ()> {
@@ -444,7 +444,7 @@ where
444444

445445
state_lock.outputs.push(output_info);
446446
}
447-
self.persist_state(&*state_lock).map_err(|e| {
447+
self.persist_state(&*state_lock).await.map_err(|e| {
448448
log_error!(self.logger, "Error persisting OutputSweeper: {:?}", e);
449449
})
450450
}
@@ -560,7 +560,7 @@ where
560560
output_info.status.broadcast(cur_hash, cur_height, spending_tx.clone());
561561
}
562562

563-
self.persist_state(&sweeper_state).map_err(|e| {
563+
self.persist_state(&sweeper_state).await.map_err(|e| {
564564
log_error!(self.logger, "Error persisting OutputSweeper: {:?}", e);
565565
})?;
566566

@@ -590,14 +590,15 @@ where
590590
});
591591
}
592592

593-
fn persist_state(&self, sweeper_state: &SweeperState) -> Result<(), io::Error> {
593+
async fn persist_state(&self, sweeper_state: &SweeperState) -> Result<(), io::Error> {
594594
self.kv_store
595-
.write(
595+
.write_async(
596596
OUTPUT_SWEEPER_PERSISTENCE_PRIMARY_NAMESPACE,
597597
OUTPUT_SWEEPER_PERSISTENCE_SECONDARY_NAMESPACE,
598598
OUTPUT_SWEEPER_PERSISTENCE_KEY,
599599
&sweeper_state.encode(),
600600
)
601+
.await
601602
.map_err(|e| {
602603
log_error!(
603604
self.logger,
@@ -970,16 +971,18 @@ where
970971
}
971972

972973
/// Tells the sweeper to track the given outputs descriptors. Wraps [`OutputSweeper::track_spendable_outputs`].
973-
pub fn track_spendable_outputs(
974+
pub async fn track_spendable_outputs(
974975
&self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>,
975976
exclude_static_outputs: bool, delay_until_height: Option<u32>,
976977
) -> Result<(), ()> {
977-
self.sweeper.track_spendable_outputs(
978-
output_descriptors,
979-
channel_id,
980-
exclude_static_outputs,
981-
delay_until_height,
982-
)
978+
self.sweeper
979+
.track_spendable_outputs(
980+
output_descriptors,
981+
channel_id,
982+
exclude_static_outputs,
983+
delay_until_height,
984+
)
985+
.await
983986
}
984987

985988
/// Returns a list of the currently tracked spendable outputs. Wraps [`OutputSweeper::tracked_spendable_outputs`].

0 commit comments

Comments
 (0)