@@ -1011,6 +1011,7 @@ pub struct ChainParameters {
1011
1011
}
1012
1012
1013
1013
#[ derive( Copy , Clone , PartialEq ) ]
1014
+ #[ must_use]
1014
1015
enum NotifyOption {
1015
1016
DoPersist ,
1016
1017
SkipPersist ,
@@ -1036,7 +1037,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
1036
1037
impl < ' a > PersistenceNotifierGuard < ' a , fn ( ) -> NotifyOption > { // We don't care what the concrete F is here, it's unused
1037
1038
fn notify_on_drop < C : AChannelManager > ( cm : & ' a C ) -> PersistenceNotifierGuard < ' a , impl Fn ( ) -> NotifyOption > {
1038
1039
let read_guard = cm. get_cm ( ) . total_consistency_lock . read ( ) . unwrap ( ) ;
1039
- cm. get_cm ( ) . process_background_events ( ) ;
1040
+ let _ = cm. get_cm ( ) . process_background_events ( ) ; // We always persist
1040
1041
1041
1042
PersistenceNotifierGuard {
1042
1043
persistence_notifier : & cm. get_cm ( ) . persistence_notifier ,
@@ -1762,7 +1763,7 @@ macro_rules! process_events_body {
1762
1763
1763
1764
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
1764
1765
// ensure any startup-generated background events are handled first.
1765
- if $self. process_background_events( ) { result = NotifyOption :: DoPersist ; }
1766
+ if $self. process_background_events( ) == NotifyOption :: DoPersist { result = NotifyOption :: DoPersist ; }
1766
1767
1767
1768
// TODO: This behavior should be documented. It's unintuitive that we query
1768
1769
// ChannelMonitors when clearing other events.
@@ -3794,14 +3795,14 @@ where
3794
3795
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
3795
3796
///
3796
3797
/// Expects the caller to have a total_consistency_lock read lock.
3797
- fn process_background_events ( & self ) -> bool {
3798
+ fn process_background_events ( & self ) -> NotifyOption {
3798
3799
#[ cfg( debug_assertions) ]
3799
3800
self . background_events_processed_since_startup . store ( true , Ordering :: Release ) ;
3800
3801
3801
3802
let mut background_events = Vec :: new ( ) ;
3802
3803
mem:: swap ( & mut * self . pending_background_events . lock ( ) . unwrap ( ) , & mut background_events) ;
3803
3804
if background_events. is_empty ( ) {
3804
- return false ;
3805
+ return NotifyOption :: SkipPersist ;
3805
3806
}
3806
3807
3807
3808
for event in background_events. drain ( ..) {
@@ -3842,13 +3843,13 @@ where
3842
3843
} ,
3843
3844
}
3844
3845
}
3845
- true
3846
+ NotifyOption :: DoPersist
3846
3847
}
3847
3848
3848
3849
#[ cfg( any( test, feature = "_test_utils" ) ) ]
3849
3850
/// Process background events, for functional testing
3850
3851
pub fn test_process_background_events ( & self ) {
3851
- self . process_background_events ( ) ;
3852
+ let _ = self . process_background_events ( ) ;
3852
3853
}
3853
3854
3854
3855
fn update_channel_fee ( & self , chan_id : & [ u8 ; 32 ] , chan : & mut Channel < <SP :: Target as SignerProvider >:: Signer > , new_feerate : u32 ) -> NotifyOption {
@@ -3878,8 +3879,7 @@ where
3878
3879
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
3879
3880
pub fn maybe_update_chan_fees ( & self ) {
3880
3881
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3881
- let mut should_persist = NotifyOption :: SkipPersist ;
3882
- if self . process_background_events ( ) { should_persist = NotifyOption :: DoPersist ; }
3882
+ let mut should_persist = self . process_background_events ( ) ;
3883
3883
3884
3884
let new_feerate = self . fee_estimator . bounded_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
3885
3885
@@ -3915,8 +3915,7 @@ where
3915
3915
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
3916
3916
pub fn timer_tick_occurred ( & self ) {
3917
3917
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3918
- let mut should_persist = NotifyOption :: SkipPersist ;
3919
- if self . process_background_events ( ) { should_persist = NotifyOption :: DoPersist ; }
3918
+ let mut should_persist = self . process_background_events ( ) ;
3920
3919
3921
3920
let new_feerate = self . fee_estimator . bounded_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
3922
3921
@@ -6122,11 +6121,7 @@ where
6122
6121
fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
6123
6122
let events = RefCell :: new ( Vec :: new ( ) ) ;
6124
6123
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
6125
- let mut result = NotifyOption :: SkipPersist ;
6126
-
6127
- if self . process_background_events ( ) {
6128
- result = NotifyOption :: DoPersist ;
6129
- }
6124
+ let mut result = self . process_background_events ( ) ;
6130
6125
6131
6126
// TODO: This behavior should be documented. It's unintuitive that we query
6132
6127
// ChannelMonitors when clearing other events.
@@ -6641,7 +6636,7 @@ where
6641
6636
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
6642
6637
let force_persist = self . process_background_events ( ) ;
6643
6638
if let Ok ( persist) = handle_error ! ( self , self . internal_channel_update( counterparty_node_id, msg) , * counterparty_node_id) {
6644
- if force_persist { NotifyOption :: DoPersist } else { persist }
6639
+ if force_persist == NotifyOption :: DoPersist { NotifyOption :: DoPersist } else { persist }
6645
6640
} else {
6646
6641
NotifyOption :: SkipPersist
6647
6642
}
0 commit comments