Skip to content

Commit

Permalink
Move Persister back to lots of generic bounds
Browse files Browse the repository at this point in the history
...as we currently struggle with `AChannelManager` on it
  • Loading branch information
TheBlueMatt committed May 13, 2024
1 parent 434e768 commit e7e551c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
8 changes: 4 additions & 4 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down
32 changes: 21 additions & 11 deletions lightning/src/util/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -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,
Expand Down

0 comments on commit e7e551c

Please sign in to comment.