From 47e9ca15b2d7794a681b4933dd6adc67b38b02cb Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 12 Aug 2022 23:53:50 +0000 Subject: [PATCH] Rename `PersistenceNotifier` to simply `Notifier` ... as it is no longer persistence-specific (though still only used for persistence). --- lightning/src/ln/channelmanager.rs | 16 ++++++++-------- lightning/src/util/wakers.rs | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 577c3d82c..3279050a0 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -55,7 +55,7 @@ use util::config::{UserConfig, ChannelConfig}; use util::events::{EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination}; use util::{byte_utils, events}; use util::crypto::sign; -use util::wakers::PersistenceNotifier; +use util::wakers::Notifier; use util::scid_utils::fake_scid; use util::ser::{BigSize, FixedLengthReader, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter}; use util::logger::{Level, Logger}; @@ -790,10 +790,10 @@ pub struct ChannelManager, - persistence_notifier: PersistenceNotifier, + persistence_notifier: Notifier, keys_manager: K, @@ -833,18 +833,18 @@ enum NotifyOption { /// notify or not based on whether relevant changes have been made, providing a closure to /// `optionally_notify` which returns a `NotifyOption`. struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> { - persistence_notifier: &'a PersistenceNotifier, + persistence_notifier: &'a Notifier, should_persist: F, // We hold onto this result so the lock doesn't get released immediately. _read_guard: RwLockReadGuard<'a, ()>, } impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, it's unused - fn notify_on_drop(lock: &'a RwLock<()>, notifier: &'a PersistenceNotifier) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> { + fn notify_on_drop(lock: &'a RwLock<()>, notifier: &'a Notifier) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> { PersistenceNotifierGuard::optionally_notify(lock, notifier, || -> NotifyOption { NotifyOption::DoPersist }) } - fn optionally_notify NotifyOption>(lock: &'a RwLock<()>, notifier: &'a PersistenceNotifier, persist_check: F) -> PersistenceNotifierGuard<'a, F> { + fn optionally_notify NotifyOption>(lock: &'a RwLock<()>, notifier: &'a Notifier, persist_check: F) -> PersistenceNotifierGuard<'a, F> { let read_guard = lock.read().unwrap(); PersistenceNotifierGuard { @@ -1625,7 +1625,7 @@ impl ChannelMana pending_events: Mutex::new(Vec::new()), pending_background_events: Mutex::new(Vec::new()), total_consistency_lock: RwLock::new(()), - persistence_notifier: PersistenceNotifier::new(), + persistence_notifier: Notifier::new(), keys_manager, @@ -7240,7 +7240,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> pending_events: Mutex::new(pending_events_read), pending_background_events: Mutex::new(pending_background_events_read), total_consistency_lock: RwLock::new(()), - persistence_notifier: PersistenceNotifier::new(), + persistence_notifier: Notifier::new(), keys_manager: args.keys_manager, logger: args.logger, diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index ba218e4e1..1532133ee 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -22,13 +22,13 @@ use std::time::Instant; /// Used to signal to the ChannelManager persister that the manager needs to be re-persisted to /// disk/backups, through `await_persistable_update_timeout` and `await_persistable_update`. -pub(crate) struct PersistenceNotifier { +pub(crate) struct Notifier { /// Users won't access the persistence_lock directly, but rather wait on its bool using /// `wait_timeout` and `wait`. persistence_lock: (Mutex, Condvar), } -impl PersistenceNotifier { +impl Notifier { pub(crate) fn new() -> Self { Self { persistence_lock: (Mutex::new(false), Condvar::new()), @@ -108,7 +108,7 @@ mod tests { use core::sync::atomic::{AtomicBool, Ordering}; use std::thread; - let persistence_notifier = Arc::new(PersistenceNotifier::new()); + let persistence_notifier = Arc::new(Notifier::new()); let thread_notifier = Arc::clone(&persistence_notifier); let exit_thread = Arc::new(AtomicBool::new(false)); @@ -129,7 +129,7 @@ mod tests { // Check that we can block indefinitely until updates are available. let _ = persistence_notifier.wait(); - // Check that the PersistenceNotifier will return after the given duration if updates are + // Check that the Notifier will return after the given duration if updates are // available. loop { if persistence_notifier.wait_timeout(Duration::from_millis(100)) { @@ -139,7 +139,7 @@ mod tests { exit_thread.store(true, Ordering::SeqCst); - // Check that the PersistenceNotifier will return after the given duration even if no updates + // Check that the Notifier will return after the given duration even if no updates // are available. loop { if !persistence_notifier.wait_timeout(Duration::from_millis(100)) { -- 2.39.5