diff --git a/mutiny-core/src/ldkstorage.rs b/mutiny-core/src/ldkstorage.rs index 8d797132b..9cb401d13 100644 --- a/mutiny-core/src/ldkstorage.rs +++ b/mutiny-core/src/ldkstorage.rs @@ -103,36 +103,35 @@ impl MutinyNodePersister { 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}"); + } } });