@@ -1023,6 +1023,7 @@ pub struct ChainParameters {
1023
1023
}
1024
1024
1025
1025
#[ derive( Copy , Clone , PartialEq ) ]
1026
+ #[ must_use]
1026
1027
enum NotifyOption {
1027
1028
DoPersist ,
1028
1029
SkipPersist ,
@@ -1048,7 +1049,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
1048
1049
impl < ' a > PersistenceNotifierGuard < ' a , fn ( ) -> NotifyOption > { // We don't care what the concrete F is here, it's unused
1049
1050
fn notify_on_drop < C : AChannelManager > ( cm : & ' a C ) -> PersistenceNotifierGuard < ' a , impl Fn ( ) -> NotifyOption > {
1050
1051
let read_guard = cm. get_cm ( ) . total_consistency_lock . read ( ) . unwrap ( ) ;
1051
- cm. get_cm ( ) . process_background_events ( ) ;
1052
+ let _ = cm. get_cm ( ) . process_background_events ( ) ; // We always persist
1052
1053
1053
1054
PersistenceNotifierGuard {
1054
1055
persistence_notifier : & cm. get_cm ( ) . persistence_notifier ,
@@ -1774,7 +1775,7 @@ macro_rules! process_events_body {
1774
1775
1775
1776
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
1776
1777
// ensure any startup-generated background events are handled first.
1777
- if $self. process_background_events( ) { result = NotifyOption :: DoPersist ; }
1778
+ if $self. process_background_events( ) == NotifyOption :: DoPersist { result = NotifyOption :: DoPersist ; }
1778
1779
1779
1780
// TODO: This behavior should be documented. It's unintuitive that we query
1780
1781
// ChannelMonitors when clearing other events.
@@ -3806,14 +3807,14 @@ where
3806
3807
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
3807
3808
///
3808
3809
/// Expects the caller to have a total_consistency_lock read lock.
3809
- fn process_background_events ( & self ) -> bool {
3810
+ fn process_background_events ( & self ) -> NotifyOption {
3810
3811
#[ cfg( debug_assertions) ]
3811
3812
self . background_events_processed_since_startup . store ( true , Ordering :: Release ) ;
3812
3813
3813
3814
let mut background_events = Vec :: new ( ) ;
3814
3815
mem:: swap ( & mut * self . pending_background_events . lock ( ) . unwrap ( ) , & mut background_events) ;
3815
3816
if background_events. is_empty ( ) {
3816
- return false ;
3817
+ return NotifyOption :: SkipPersist ;
3817
3818
}
3818
3819
3819
3820
for event in background_events. drain ( ..) {
@@ -3854,13 +3855,13 @@ where
3854
3855
} ,
3855
3856
}
3856
3857
}
3857
- true
3858
+ NotifyOption :: DoPersist
3858
3859
}
3859
3860
3860
3861
#[ cfg( any( test, feature = "_test_utils" ) ) ]
3861
3862
/// Process background events, for functional testing
3862
3863
pub fn test_process_background_events ( & self ) {
3863
- self . process_background_events ( ) ;
3864
+ let _ = self . process_background_events ( ) ;
3864
3865
}
3865
3866
3866
3867
fn update_channel_fee ( & self , chan_id : & [ u8 ; 32 ] , chan : & mut Channel < <SP :: Target as SignerProvider >:: Signer > , new_feerate : u32 ) -> NotifyOption {
@@ -3890,8 +3891,7 @@ where
3890
3891
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
3891
3892
pub fn maybe_update_chan_fees ( & self ) {
3892
3893
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3893
- let mut should_persist = NotifyOption :: SkipPersist ;
3894
- if self . process_background_events ( ) { should_persist = NotifyOption :: DoPersist ; }
3894
+ let mut should_persist = self . process_background_events ( ) ;
3895
3895
3896
3896
let new_feerate = self . fee_estimator . bounded_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
3897
3897
@@ -3927,8 +3927,7 @@ where
3927
3927
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
3928
3928
pub fn timer_tick_occurred ( & self ) {
3929
3929
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3930
- let mut should_persist = NotifyOption :: SkipPersist ;
3931
- if self . process_background_events ( ) { should_persist = NotifyOption :: DoPersist ; }
3930
+ let mut should_persist = self . process_background_events ( ) ;
3932
3931
3933
3932
let new_feerate = self . fee_estimator . bounded_sat_per_1000_weight ( ConfirmationTarget :: Normal ) ;
3934
3933
@@ -6135,11 +6134,7 @@ where
6135
6134
fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
6136
6135
let events = RefCell :: new ( Vec :: new ( ) ) ;
6137
6136
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
6138
- let mut result = NotifyOption :: SkipPersist ;
6139
-
6140
- if self . process_background_events ( ) {
6141
- result = NotifyOption :: DoPersist ;
6142
- }
6137
+ let mut result = self . process_background_events ( ) ;
6143
6138
6144
6139
// TODO: This behavior should be documented. It's unintuitive that we query
6145
6140
// ChannelMonitors when clearing other events.
@@ -6654,7 +6649,7 @@ where
6654
6649
PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
6655
6650
let force_persist = self . process_background_events ( ) ;
6656
6651
if let Ok ( persist) = handle_error ! ( self , self . internal_channel_update( counterparty_node_id, msg) , * counterparty_node_id) {
6657
- if force_persist { NotifyOption :: DoPersist } else { persist }
6652
+ if force_persist == NotifyOption :: DoPersist { NotifyOption :: DoPersist } else { persist }
6658
6653
} else {
6659
6654
NotifyOption :: SkipPersist
6660
6655
}
0 commit comments