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

Commit

Permalink
Retry spendable outputs in background
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Feb 7, 2024
1 parent 1d1cc31 commit 3a7bdab
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions mutiny-core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,38 +579,52 @@ impl<S: MutinyStorage> NodeBuilder<S> {
});

if !retry_spendable_outputs.is_empty() {
log_info!(
logger,
"Retrying {} spendable outputs",
retry_spendable_outputs.len()
);
let event_handler = event_handler.clone();
let persister = persister.clone();

match event_handler
.handle_spendable_outputs(&retry_spendable_outputs)
.await
{
Ok(_) => {
log_info!(logger, "Successfully retried spendable outputs");
persister.clear_failed_spendable_outputs()?;
}
Err(_) => {
// retry them individually then only save failed ones
// if there was only one we don't need to retry
if retry_spendable_outputs.len() > 1 {
let mut failed = vec![];
for o in retry_spendable_outputs {
if event_handler
.handle_spendable_outputs(&[o.clone()])
.await
.is_err()
{
failed.push(o);
// We need to process our unhandled spendable outputs
// can do this in the background, no need to block on it
utils::spawn(async move {
let start = Instant::now();
log_info!(
logger,
"Retrying {} spendable outputs",
retry_spendable_outputs.len()
);

match event_handler
.handle_spendable_outputs(&retry_spendable_outputs)
.await
{
Ok(_) => {
log_info!(logger, "Successfully retried spendable outputs");
persister.clear_failed_spendable_outputs()?;
}
Err(_) => {
// retry them individually then only save failed ones
// if there was only one we don't need to retry
if retry_spendable_outputs.len() > 1 {
let mut failed = vec![];
for o in retry_spendable_outputs {
if event_handler
.handle_spendable_outputs(&[o.clone()])
.await
.is_err()
{
failed.push(o);
}
}
}
persister.set_failed_spendable_outputs(failed)?;
};
persister.set_failed_spendable_outputs(failed)?;
};
}
}
}

log_info!(
logger,
"Retrying spendable outputs took {}ms",
start.elapsed().as_millis()
);
});
}

// Check all existing channels against default configs.
Expand Down

0 comments on commit 3a7bdab

Please sign in to comment.