Skip to content

Commit 00d71f7

Browse files
committed
f rename and redo docs
1 parent 8dac8c3 commit 00d71f7

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -523,30 +523,34 @@ impl BestBlock {
523523
}
524524

525525
#[derive(Copy, Clone, PartialEq)]
526-
enum PersistenceGuardOption {
526+
enum NotifyOption {
527527
DoPersist,
528528
SkipPersist,
529529
}
530530

531531
/// Whenever we release the `ChannelManager`'s `total_consistency_lock`, from read mode, it is
532532
/// desirable to notify any listeners on `await_persistable_update_timeout`/
533-
/// `await_persistable_update` that new updates are available for persistence. Therefore, this
533+
/// `await_persistable_update` when new updates are available for persistence. Therefore, this
534534
/// struct is responsible for locking the total consistency lock and, upon going out of scope,
535535
/// sending the aforementioned notification (since the lock being released indicates that the
536536
/// updates are ready for persistence).
537-
struct PersistenceNotifierGuard<'a, F: Fn() -> PersistenceGuardOption> {
537+
///
538+
/// We allow callers to either always notify by constructing with `notify_on_drop` or chose to
539+
/// notify or not based on whether relevant changes have been made, providing a closure to
540+
/// `optionally_notify` which returns a `NotifyOption`.
541+
struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
538542
persistence_notifier: &'a PersistenceNotifier,
539543
should_persist: F,
540544
// We hold onto this result so the lock doesn't get released immediately.
541545
_read_guard: RwLockReadGuard<'a, ()>,
542546
}
543547

544-
impl<'a> PersistenceNotifierGuard<'a, fn() -> PersistenceGuardOption> { // We don't care what the concrete F is here, its unused
545-
fn notify_on_drop(lock: &'a RwLock<()>, notifier: &'a PersistenceNotifier) -> PersistenceNotifierGuard<'a, impl Fn() -> PersistenceGuardOption> {
546-
PersistenceNotifierGuard::optionally_notify(lock, notifier, || -> PersistenceGuardOption { PersistenceGuardOption::DoPersist })
548+
impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, its unused
549+
fn notify_on_drop(lock: &'a RwLock<()>, notifier: &'a PersistenceNotifier) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> {
550+
PersistenceNotifierGuard::optionally_notify(lock, notifier, || -> NotifyOption { NotifyOption::DoPersist })
547551
}
548552

549-
fn optionally_notify<F: Fn() -> PersistenceGuardOption>(lock: &'a RwLock<()>, notifier: &'a PersistenceNotifier, persist_check: F) -> PersistenceNotifierGuard<'a, F> {
553+
fn optionally_notify<F: Fn() -> NotifyOption>(lock: &'a RwLock<()>, notifier: &'a PersistenceNotifier, persist_check: F) -> PersistenceNotifierGuard<'a, F> {
550554
let read_guard = lock.read().unwrap();
551555

552556
PersistenceNotifierGuard {
@@ -557,9 +561,9 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> PersistenceGuardOption> { // We do
557561
}
558562
}
559563

560-
impl<'a, F: Fn() -> PersistenceGuardOption> Drop for PersistenceNotifierGuard<'a, F> {
564+
impl<'a, F: Fn() -> NotifyOption> Drop for PersistenceNotifierGuard<'a, F> {
561565
fn drop(&mut self) {
562-
if (self.should_persist)() == PersistenceGuardOption::DoPersist {
566+
if (self.should_persist)() == NotifyOption::DoPersist {
563567
self.persistence_notifier.notify();
564568
}
565569
}
@@ -2141,8 +2145,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21412145
/// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
21422146
pub fn timer_tick_occurred(&self) {
21432147
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
2144-
let mut should_persist = PersistenceGuardOption::SkipPersist;
2145-
if self.process_background_events() { should_persist = PersistenceGuardOption::DoPersist; }
2148+
let mut should_persist = NotifyOption::SkipPersist;
2149+
if self.process_background_events() { should_persist = NotifyOption::DoPersist; }
21462150

21472151
let mut channel_state_lock = self.channel_state.lock().unwrap();
21482152
let channel_state = &mut *channel_state_lock;
@@ -2158,7 +2162,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21582162
msg: update
21592163
});
21602164
}
2161-
should_persist = PersistenceGuardOption::DoPersist;
2165+
should_persist = NotifyOption::DoPersist;
21622166
chan.set_update_status(UpdateStatus::Disabled);
21632167
},
21642168
UpdateStatus::EnabledStaged if chan.is_live() => {
@@ -2167,7 +2171,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21672171
msg: update
21682172
});
21692173
}
2170-
should_persist = PersistenceGuardOption::DoPersist;
2174+
should_persist = NotifyOption::DoPersist;
21712175
chan.set_update_status(UpdateStatus::Enabled);
21722176
},
21732177
_ => {},

0 commit comments

Comments
 (0)