@@ -523,30 +523,34 @@ impl BestBlock {
523
523
}
524
524
525
525
#[ derive( Copy , Clone , PartialEq ) ]
526
- enum PersistenceGuardOption {
526
+ enum NotifyOption {
527
527
DoPersist ,
528
528
SkipPersist ,
529
529
}
530
530
531
531
/// Whenever we release the `ChannelManager`'s `total_consistency_lock`, from read mode, it is
532
532
/// 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
534
534
/// struct is responsible for locking the total consistency lock and, upon going out of scope,
535
535
/// sending the aforementioned notification (since the lock being released indicates that the
536
536
/// 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 > {
538
542
persistence_notifier : & ' a PersistenceNotifier ,
539
543
should_persist : F ,
540
544
// We hold onto this result so the lock doesn't get released immediately.
541
545
_read_guard : RwLockReadGuard < ' a , ( ) > ,
542
546
}
543
547
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 } )
547
551
}
548
552
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 > {
550
554
let read_guard = lock. read ( ) . unwrap ( ) ;
551
555
552
556
PersistenceNotifierGuard {
@@ -557,9 +561,9 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> PersistenceGuardOption> { // We do
557
561
}
558
562
}
559
563
560
- impl < ' a , F : Fn ( ) -> PersistenceGuardOption > Drop for PersistenceNotifierGuard < ' a , F > {
564
+ impl < ' a , F : Fn ( ) -> NotifyOption > Drop for PersistenceNotifierGuard < ' a , F > {
561
565
fn drop ( & mut self ) {
562
- if ( self . should_persist ) ( ) == PersistenceGuardOption :: DoPersist {
566
+ if ( self . should_persist ) ( ) == NotifyOption :: DoPersist {
563
567
self . persistence_notifier . notify ( ) ;
564
568
}
565
569
}
@@ -2141,8 +2145,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2141
2145
/// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
2142
2146
pub fn timer_tick_occurred ( & self ) {
2143
2147
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 ; }
2146
2150
2147
2151
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2148
2152
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
2158
2162
msg : update
2159
2163
} ) ;
2160
2164
}
2161
- should_persist = PersistenceGuardOption :: DoPersist ;
2165
+ should_persist = NotifyOption :: DoPersist ;
2162
2166
chan. set_update_status ( UpdateStatus :: Disabled ) ;
2163
2167
} ,
2164
2168
UpdateStatus :: EnabledStaged if chan. is_live ( ) => {
@@ -2167,7 +2171,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2167
2171
msg : update
2168
2172
} ) ;
2169
2173
}
2170
- should_persist = PersistenceGuardOption :: DoPersist ;
2174
+ should_persist = NotifyOption :: DoPersist ;
2171
2175
chan. set_update_status ( UpdateStatus :: Enabled ) ;
2172
2176
} ,
2173
2177
_ => { } ,
0 commit comments