@@ -1017,6 +1017,7 @@ pub struct ChainParameters {
1017
1017
}
1018
1018
1019
1019
#[ derive( Copy , Clone , PartialEq ) ]
1020
+ #[ must_use]
1020
1021
enum NotifyOption {
1021
1022
DoPersist ,
1022
1023
SkipPersist ,
@@ -1042,7 +1043,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
1042
1043
impl < ' a > PersistenceNotifierGuard < ' a , fn ( ) -> NotifyOption > { // We don't care what the concrete F is here, it's unused
1043
1044
fn notify_on_drop < C : AChannelManager > ( cm : & ' a C ) -> PersistenceNotifierGuard < ' a , impl Fn ( ) -> NotifyOption > {
1044
1045
let read_guard = cm. get_cm ( ) . total_consistency_lock . read ( ) . unwrap ( ) ;
1045
- cm. get_cm ( ) . process_background_events ( ) ;
1046
+ let _ = cm. get_cm ( ) . process_background_events ( ) ; // We always persist
1046
1047
1047
1048
PersistenceNotifierGuard {
1048
1049
persistence_notifier : & cm. get_cm ( ) . persistence_notifier ,
@@ -1768,7 +1769,7 @@ macro_rules! process_events_body {
1768
1769
1769
1770
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
1770
1771
// ensure any startup-generated background events are handled first.
1771
- if $self. process_background_events( ) { result = NotifyOption :: DoPersist ; }
1772
+ if $self. process_background_events( ) == NotifyOption :: DoPersist { result = NotifyOption :: DoPersist ; }
1772
1773
1773
1774
// TODO: This behavior should be documented. It's unintuitive that we query
1774
1775
// ChannelMonitors when clearing other events.
@@ -3800,14 +3801,14 @@ where
3800
3801
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
3801
3802
///
3802
3803
/// Expects the caller to have a total_consistency_lock read lock.
3803
- fn process_background_events ( & self ) -> bool {
3804
+ fn process_background_events ( & self ) -> NotifyOption {
3804
3805
#[ cfg( debug_assertions) ]
3805
3806
self . background_events_processed_since_startup . store ( true , Ordering :: Release ) ;
3806
3807
3807
3808
let mut background_events = Vec :: new ( ) ;
3808
3809
mem:: swap ( & mut * self . pending_background_events . lock ( ) . unwrap ( ) , & mut background_events) ;
3809
3810
if background_events. is_empty ( ) {
3810
- return false ;
3811
+ return NotifyOption :: SkipPersist ;
3811
3812
}
3812
3813
3813
3814
for event in background_events. drain ( ..) {
@@ -3848,13 +3849,13 @@ where
3848
3849
} ,
3849
3850
}
3850
3851
}
3851
- true
3852
+ NotifyOption :: DoPersist
3852
3853
}
3853
3854
3854
3855
#[ cfg( any( test, feature = "_test_utils" ) ) ]
3855
3856
/// Process background events, for functional testing
3856
3857
pub fn test_process_background_events ( & self ) {
3857
- self . process_background_events ( ) ;
3858
+ let _ = self . process_background_events ( ) ;
3858
3859
}
3859
3860
3860
3861
fn update_channel_fee ( & self , chan_id : & [ u8 ; 32 ] , chan : & mut Channel < <SP :: Target as SignerProvider >:: Signer > , new_feerate : u32 ) -> NotifyOption {
@@ -3884,8 +3885,7 @@ where
3884
3885
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
3885
3886
pub fn maybe_update_chan_fees ( & self ) {
3886
3887
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3887
- let mut should_persist = NotifyOption :: SkipPersist ;
3888
- if self . process_background_events ( ) { should_persist = NotifyOption :: DoPersist ; }
3888
+ let mut should_persist = self . process_background_events ( ) ;
3889
3889
3890
3890
let new_feerate = self . fee_estimator . bounded_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
3891
3891
@@ -3921,8 +3921,7 @@ where
3921
3921
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
3922
3922
pub fn timer_tick_occurred ( & self ) {
3923
3923
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3924
- let mut should_persist = NotifyOption :: SkipPersist ;
3925
- if self . process_background_events ( ) { should_persist = NotifyOption :: DoPersist ; }
3924
+ let mut should_persist = self . process_background_events ( ) ;
3926
3925
3927
3926
let new_feerate = self . fee_estimator . bounded_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
3928
3927
@@ -6129,11 +6128,7 @@ where
6129
6128
fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
6130
6129
let events = RefCell :: new ( Vec :: new ( ) ) ;
6131
6130
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
6132
- let mut result = NotifyOption :: SkipPersist ;
6133
-
6134
- if self . process_background_events ( ) {
6135
- result = NotifyOption :: DoPersist ;
6136
- }
6131
+ let mut result = self . process_background_events ( ) ;
6137
6132
6138
6133
// TODO: This behavior should be documented. It's unintuitive that we query
6139
6134
// ChannelMonitors when clearing other events.
@@ -6648,7 +6643,7 @@ where
6648
6643
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
6649
6644
let force_persist = self . process_background_events ( ) ;
6650
6645
if let Ok ( persist) = handle_error ! ( self , self . internal_channel_update( counterparty_node_id, msg) , * counterparty_node_id) {
6651
- if force_persist { NotifyOption :: DoPersist } else { persist }
6646
+ if force_persist == NotifyOption :: DoPersist { NotifyOption :: DoPersist } else { persist }
6652
6647
} else {
6653
6648
NotifyOption :: SkipPersist
6654
6649
}
0 commit comments