]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move `Persister` back to lots of generic bounds
authorMatt Corallo <git@bluematt.me>
Sat, 11 May 2024 16:01:32 +0000 (16:01 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 14 May 2024 20:46:40 +0000 (20:46 +0000)
...as we currently struggle with `AChannelManager` on it

lightning-background-processor/src/lib.rs
lightning/src/util/persist.rs

index 79493a697ffb158f1a47e56c7384ed86e0f0ddbd..5a8bf4c2e16f7e93dd7b0605d8b59ea0cdba9435 100644 (file)
@@ -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<<CM::Target as AChannelManager>::Signer>,
-               PS::Target: 'static + Persister<'a, CM, L, SC>,
-               CM::Target: AChannelManager + Send + Sync,
+               PS::Target: 'static + Persister<'a, <<CM as Deref>::Target as AChannelManager>::M, <<CM as Deref>::Target as AChannelManager>::T, <<CM as Deref>::Target as AChannelManager>::ES, <<CM as Deref>::Target as AChannelManager>::NS, <<CM as Deref>::Target as AChannelManager>::SP, <<CM as Deref>::Target as AChannelManager>::F, <<CM as Deref>::Target as AChannelManager>::R, L, SC>,
+               CM::Target: AChannelManager<L = L> + Send + Sync,
                PM::Target: APeerManager + Send + Sync,
        {
                let stop_thread = Arc::new(AtomicBool::new(false));
index 249a089cd4883170be76bf8574855379ab48c643..febe8c3590306903953a0b37cd94636de4afafc4 100644 (file)
@@ -154,18 +154,24 @@ pub trait KVStore {
        fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> Result<Vec<String>, 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<<SP::Target as SignerProvider>::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<M, T, ES, NS, SP, F, R, L>) -> Result<(), io::Error>;
 
        /// Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
        fn persist_graph(&self, network_graph: &NetworkGraph<L>) -> 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<<SP::Target as SignerProvider>::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<M, T, ES, NS, SP, F, R, L>) -> Result<(), io::Error> {
                self.write(CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
                        CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
                        CHANNEL_MANAGER_PERSISTENCE_KEY,