Skip to content

Commit

Permalink
Remove storage retries
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Sep 29, 2023
1 parent a4a3312 commit fc84496
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions mutiny-core/src/ldkstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,35 @@ impl<S: MutinyStorage> MutinyNodePersister<S> {
let chain_monitor = self.chain_monitor.clone();
let logger = self.logger.clone();
let object = object.encode();

// todo add retries
// currently we don't retry because we don't have a way to detect for local
// storage if a higher version has been persisted. Without handling this
// we could end up with a previous state being persisted over a newer one.
spawn(async move {
loop {
// Sleep before persisting to give chance for the manager to be persisted
sleep(50).await;
match persist_local_storage(&storage, &key, &object, Some(version), &logger).await {
Ok(()) => {
log_debug!(logger, "Persisted channel monitor: {update_id:?}");

// unwrap is safe, we set it up immediately
let chain_monitor = chain_monitor.lock().await;
let chain_monitor = chain_monitor.as_ref().unwrap();

// these errors are not fatal, so we don't return them just log
if let Err(e) = chain_monitor.channel_monitor_updated(
update_id.funding_txo,
update_id.monitor_update_id,
) {
log_error!(
logger,
"Error notifying chain monitor of channel monitor update: {e:?}"
);
}
break;
}
Err(e) => {
log_error!(logger, "Error persisting channel monitor: {e}");
// sleep for a second before retrying
sleep(1_000).await;
// Sleep before persisting to give chance for the manager to be persisted
sleep(50).await;
match persist_local_storage(&storage, &key, &object, Some(version), &logger).await {
Ok(()) => {
log_debug!(logger, "Persisted channel monitor: {update_id:?}");

// unwrap is safe, we set it up immediately
let chain_monitor = chain_monitor.lock().await;
let chain_monitor = chain_monitor.as_ref().unwrap();

// these errors are not fatal, so we don't return them just log
if let Err(e) = chain_monitor
.channel_monitor_updated(update_id.funding_txo, update_id.monitor_update_id)
{
log_error!(
logger,
"Error notifying chain monitor of channel monitor update: {e:?}"
);
}
}
Err(e) => {
log_error!(logger, "Error persisting channel monitor: {e}");
}
}
});

Expand Down

0 comments on commit fc84496

Please sign in to comment.