Skip to content

Commit f32b7c2

Browse files
committed
f ret enum
1 parent 592f0d6 commit f32b7c2

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ pub struct ChainParameters {
10111011
}
10121012

10131013
#[derive(Copy, Clone, PartialEq)]
1014+
#[must_use]
10141015
enum NotifyOption {
10151016
DoPersist,
10161017
SkipPersist,
@@ -1036,7 +1037,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
10361037
impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, it's unused
10371038
fn notify_on_drop<C: AChannelManager>(cm: &'a C) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> {
10381039
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
10401041

10411042
PersistenceNotifierGuard {
10421043
persistence_notifier: &cm.get_cm().persistence_notifier,
@@ -1762,7 +1763,7 @@ macro_rules! process_events_body {
17621763

17631764
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
17641765
// 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; }
17661767

17671768
// TODO: This behavior should be documented. It's unintuitive that we query
17681769
// ChannelMonitors when clearing other events.
@@ -3794,14 +3795,14 @@ where
37943795
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
37953796
///
37963797
/// 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 {
37983799
#[cfg(debug_assertions)]
37993800
self.background_events_processed_since_startup.store(true, Ordering::Release);
38003801

38013802
let mut background_events = Vec::new();
38023803
mem::swap(&mut *self.pending_background_events.lock().unwrap(), &mut background_events);
38033804
if background_events.is_empty() {
3804-
return false;
3805+
return NotifyOption::SkipPersist;
38053806
}
38063807

38073808
for event in background_events.drain(..) {
@@ -3842,13 +3843,13 @@ where
38423843
},
38433844
}
38443845
}
3845-
true
3846+
NotifyOption::DoPersist
38463847
}
38473848

38483849
#[cfg(any(test, feature = "_test_utils"))]
38493850
/// Process background events, for functional testing
38503851
pub fn test_process_background_events(&self) {
3851-
self.process_background_events();
3852+
let _ = self.process_background_events();
38523853
}
38533854

38543855
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
38783879
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
38793880
pub fn maybe_update_chan_fees(&self) {
38803881
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();
38833883

38843884
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
38853885

@@ -3915,8 +3915,7 @@ where
39153915
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
39163916
pub fn timer_tick_occurred(&self) {
39173917
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();
39203919

39213920
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
39223921

@@ -6122,11 +6121,7 @@ where
61226121
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
61236122
let events = RefCell::new(Vec::new());
61246123
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();
61306125

61316126
// TODO: This behavior should be documented. It's unintuitive that we query
61326127
// ChannelMonitors when clearing other events.
@@ -6641,7 +6636,7 @@ where
66416636
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
66426637
let force_persist = self.process_background_events();
66436638
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 }
66456640
} else {
66466641
NotifyOption::SkipPersist
66476642
}

0 commit comments

Comments
 (0)