Skip to content

Commit 7cae27a

Browse files
committed
f ret enum
1 parent bc224f8 commit 7cae27a

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
@@ -1023,6 +1023,7 @@ pub struct ChainParameters {
10231023
}
10241024

10251025
#[derive(Copy, Clone, PartialEq)]
1026+
#[must_use]
10261027
enum NotifyOption {
10271028
DoPersist,
10281029
SkipPersist,
@@ -1048,7 +1049,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
10481049
impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, it's unused
10491050
fn notify_on_drop<C: AChannelManager>(cm: &'a C) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> {
10501051
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
10521053

10531054
PersistenceNotifierGuard {
10541055
persistence_notifier: &cm.get_cm().persistence_notifier,
@@ -1774,7 +1775,7 @@ macro_rules! process_events_body {
17741775

17751776
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
17761777
// 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; }
17781779

17791780
// TODO: This behavior should be documented. It's unintuitive that we query
17801781
// ChannelMonitors when clearing other events.
@@ -3806,14 +3807,14 @@ where
38063807
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
38073808
///
38083809
/// 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 {
38103811
#[cfg(debug_assertions)]
38113812
self.background_events_processed_since_startup.store(true, Ordering::Release);
38123813

38133814
let mut background_events = Vec::new();
38143815
mem::swap(&mut *self.pending_background_events.lock().unwrap(), &mut background_events);
38153816
if background_events.is_empty() {
3816-
return false;
3817+
return NotifyOption::SkipPersist;
38173818
}
38183819

38193820
for event in background_events.drain(..) {
@@ -3854,13 +3855,13 @@ where
38543855
},
38553856
}
38563857
}
3857-
true
3858+
NotifyOption::DoPersist
38583859
}
38593860

38603861
#[cfg(any(test, feature = "_test_utils"))]
38613862
/// Process background events, for functional testing
38623863
pub fn test_process_background_events(&self) {
3863-
self.process_background_events();
3864+
let _ = self.process_background_events();
38643865
}
38653866

38663867
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
38903891
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
38913892
pub fn maybe_update_chan_fees(&self) {
38923893
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();
38953895

38963896
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
38973897

@@ -3927,8 +3927,7 @@ where
39273927
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
39283928
pub fn timer_tick_occurred(&self) {
39293929
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();
39323931

39333932
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
39343933

@@ -6135,11 +6134,7 @@ where
61356134
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
61366135
let events = RefCell::new(Vec::new());
61376136
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();
61436138

61446139
// TODO: This behavior should be documented. It's unintuitive that we query
61456140
// ChannelMonitors when clearing other events.
@@ -6654,7 +6649,7 @@ where
66546649
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
66556650
let force_persist = self.process_background_events();
66566651
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 }
66586653
} else {
66596654
NotifyOption::SkipPersist
66606655
}

0 commit comments

Comments
 (0)