Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 3a7bdab

Browse files
committed
Retry spendable outputs in background
1 parent 1d1cc31 commit 3a7bdab

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

mutiny-core/src/node.rs

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -579,38 +579,52 @@ impl<S: MutinyStorage> NodeBuilder<S> {
579579
});
580580

581581
if !retry_spendable_outputs.is_empty() {
582-
log_info!(
583-
logger,
584-
"Retrying {} spendable outputs",
585-
retry_spendable_outputs.len()
586-
);
582+
let event_handler = event_handler.clone();
583+
let persister = persister.clone();
587584

588-
match event_handler
589-
.handle_spendable_outputs(&retry_spendable_outputs)
590-
.await
591-
{
592-
Ok(_) => {
593-
log_info!(logger, "Successfully retried spendable outputs");
594-
persister.clear_failed_spendable_outputs()?;
595-
}
596-
Err(_) => {
597-
// retry them individually then only save failed ones
598-
// if there was only one we don't need to retry
599-
if retry_spendable_outputs.len() > 1 {
600-
let mut failed = vec![];
601-
for o in retry_spendable_outputs {
602-
if event_handler
603-
.handle_spendable_outputs(&[o.clone()])
604-
.await
605-
.is_err()
606-
{
607-
failed.push(o);
585+
// We need to process our unhandled spendable outputs
586+
// can do this in the background, no need to block on it
587+
utils::spawn(async move {
588+
let start = Instant::now();
589+
log_info!(
590+
logger,
591+
"Retrying {} spendable outputs",
592+
retry_spendable_outputs.len()
593+
);
594+
595+
match event_handler
596+
.handle_spendable_outputs(&retry_spendable_outputs)
597+
.await
598+
{
599+
Ok(_) => {
600+
log_info!(logger, "Successfully retried spendable outputs");
601+
persister.clear_failed_spendable_outputs()?;
602+
}
603+
Err(_) => {
604+
// retry them individually then only save failed ones
605+
// if there was only one we don't need to retry
606+
if retry_spendable_outputs.len() > 1 {
607+
let mut failed = vec![];
608+
for o in retry_spendable_outputs {
609+
if event_handler
610+
.handle_spendable_outputs(&[o.clone()])
611+
.await
612+
.is_err()
613+
{
614+
failed.push(o);
615+
}
608616
}
609-
}
610-
persister.set_failed_spendable_outputs(failed)?;
611-
};
617+
persister.set_failed_spendable_outputs(failed)?;
618+
};
619+
}
612620
}
613-
}
621+
622+
log_info!(
623+
logger,
624+
"Retrying spendable outputs took {}ms",
625+
start.elapsed().as_millis()
626+
);
627+
});
614628
}
615629

616630
// Check all existing channels against default configs.

0 commit comments

Comments
 (0)