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