Skip to content

Commit 0af26bb

Browse files
committed
f ret enum
1 parent 6122c22 commit 0af26bb

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
@@ -1008,6 +1008,7 @@ pub struct ChainParameters {
10081008
}
10091009

10101010
#[derive(Copy, Clone, PartialEq)]
1011+
#[must_use]
10111012
enum NotifyOption {
10121013
DoPersist,
10131014
SkipPersist,
@@ -1033,7 +1034,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
10331034
impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, it's unused
10341035
fn notify_on_drop<C: AChannelManager>(cm: &'a C) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> {
10351036
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
10371038

10381039
PersistenceNotifierGuard {
10391040
persistence_notifier: &cm.get_cm().persistence_notifier,
@@ -1759,7 +1760,7 @@ macro_rules! process_events_body {
17591760

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

17641765
// TODO: This behavior should be documented. It's unintuitive that we query
17651766
// ChannelMonitors when clearing other events.
@@ -3791,14 +3792,14 @@ where
37913792
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
37923793
///
37933794
/// 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 {
37953796
#[cfg(debug_assertions)]
37963797
self.background_events_processed_since_startup.store(true, Ordering::Release);
37973798

37983799
let mut background_events = Vec::new();
37993800
mem::swap(&mut *self.pending_background_events.lock().unwrap(), &mut background_events);
38003801
if background_events.is_empty() {
3801-
return false;
3802+
return NotifyOption::SkipPersist;
38023803
}
38033804

38043805
for event in background_events.drain(..) {
@@ -3839,13 +3840,13 @@ where
38393840
},
38403841
}
38413842
}
3842-
true
3843+
NotifyOption::DoPersist
38433844
}
38443845

38453846
#[cfg(any(test, feature = "_test_utils"))]
38463847
/// Process background events, for functional testing
38473848
pub fn test_process_background_events(&self) {
3848-
self.process_background_events();
3849+
let _ = self.process_background_events();
38493850
}
38503851

38513852
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
38753876
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
38763877
pub fn maybe_update_chan_fees(&self) {
38773878
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();
38803880

38813881
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
38823882

@@ -3912,8 +3912,7 @@ where
39123912
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
39133913
pub fn timer_tick_occurred(&self) {
39143914
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();
39173916

39183917
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
39193918

@@ -6119,11 +6118,7 @@ where
61196118
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
61206119
let events = RefCell::new(Vec::new());
61216120
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();
61276122

61286123
// TODO: This behavior should be documented. It's unintuitive that we query
61296124
// ChannelMonitors when clearing other events.
@@ -6638,7 +6633,7 @@ where
66386633
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
66396634
let force_persist = self.process_background_events();
66406635
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 }
66426637
} else {
66436638
NotifyOption::SkipPersist
66446639
}

0 commit comments

Comments
 (0)