From: Matt Corallo Date: Sat, 11 May 2024 16:01:32 +0000 (+0000) Subject: Move `Persister` back to lots of generic bounds X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=4f8f9b4d9e7dbfbb014c6f7d06d4d31a2f89914c;p=rust-lightning Move `Persister` back to lots of generic bounds ...as we currently struggle with `AChannelManager` on it --- diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 79493a697..5a8bf4c2e 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -338,7 +338,7 @@ macro_rules! define_run_body { if $channel_manager.get_cm().get_and_clear_needs_persistence() { log_trace!($logger, "Persisting ChannelManager..."); - $persister.persist_manager(&$channel_manager)?; + $persister.persist_manager($channel_manager.get_cm())?; log_trace!($logger, "Done persisting ChannelManager."); } if $timer_elapsed(&mut last_freshness_call, FRESHNESS_TIMER) { @@ -440,7 +440,7 @@ macro_rules! define_run_body { // After we exit, ensure we persist the ChannelManager one final time - this avoids // some races where users quit while channel updates were in-flight, with // ChannelMonitor update(s) persisted without a corresponding ChannelManager update. - $persister.persist_manager(&$channel_manager)?; + $persister.persist_manager($channel_manager.get_cm())?; // Persist Scorer on exit if let Some(ref scorer) = $scorer { @@ -814,8 +814,8 @@ impl BackgroundProcessor { F::Target: 'static + FeeEstimator, L::Target: 'static + Logger, P::Target: 'static + Persist<::Signer>, - PS::Target: 'static + Persister<'a, CM, L, SC>, - CM::Target: AChannelManager + Send + Sync, + PS::Target: 'static + Persister<'a, <::Target as AChannelManager>::M, <::Target as AChannelManager>::T, <::Target as AChannelManager>::ES, <::Target as AChannelManager>::NS, <::Target as AChannelManager>::SP, <::Target as AChannelManager>::F, <::Target as AChannelManager>::R, L, SC>, + CM::Target: AChannelManager + Send + Sync, PM::Target: APeerManager + Send + Sync, { let stop_thread = Arc::new(AtomicBool::new(false)); diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs index 249a089cd..febe8c359 100644 --- a/lightning/src/util/persist.rs +++ b/lightning/src/util/persist.rs @@ -154,18 +154,24 @@ pub trait KVStore { fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> Result, io::Error>; } + /// Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk. /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager -pub trait Persister<'a, CM: Deref, L: Deref, S: WriteableScore<'a>> -where - CM::Target: 'static + AChannelManager, - L::Target: 'static + Logger, +pub trait Persister<'a, M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref, S: WriteableScore<'a>> + where M::Target: 'static + chain::Watch<::EcdsaSigner>, + T::Target: 'static + BroadcasterInterface, + ES::Target: 'static + EntropySource, + NS::Target: 'static + crate::sign::NodeSigner, + SP::Target: 'static + SignerProvider, + F::Target: 'static + FeeEstimator, + R::Target: 'static + crate::routing::router::Router, + L::Target: 'static + Logger, { /// Persist the given ['ChannelManager'] to disk, returning an error if persistence failed. /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager - fn persist_manager(&self, channel_manager: &CM) -> Result<(), io::Error>; + fn persist_manager(&self, channel_manager: &crate::ln::channelmanager::ChannelManager) -> Result<(), io::Error>; /// Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed. fn persist_graph(&self, network_graph: &NetworkGraph) -> Result<(), io::Error>; @@ -174,13 +180,17 @@ where fn persist_scorer(&self, scorer: &S) -> Result<(), io::Error>; } - -impl<'a, A: KVStore + ?Sized, CM: Deref, L: Deref, S: WriteableScore<'a>> Persister<'a, CM, L, S> for A -where - CM::Target: 'static + AChannelManager, - L::Target: 'static + Logger, +impl<'a, A: KVStore + ?Sized, M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref, S: WriteableScore<'a>> Persister<'a, M, T, ES, NS, SP, F, R, L, S> for A + where M::Target: 'static + chain::Watch<::EcdsaSigner>, + T::Target: 'static + BroadcasterInterface, + ES::Target: 'static + EntropySource, + NS::Target: 'static + crate::sign::NodeSigner, + SP::Target: 'static + SignerProvider, + F::Target: 'static + FeeEstimator, + R::Target: 'static + crate::routing::router::Router, + L::Target: 'static + Logger, { - fn persist_manager(&self, channel_manager: &CM) -> Result<(), io::Error> { + fn persist_manager(&self, channel_manager: &crate::ln::channelmanager::ChannelManager) -> Result<(), io::Error> { self.write(CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_KEY,