Skip to content

Commit 28efe14

Browse files
committed
f ret enum
1 parent c82dcac commit 28efe14

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
@@ -1017,6 +1017,7 @@ pub struct ChainParameters {
10171017
}
10181018

10191019
#[derive(Copy, Clone, PartialEq)]
1020+
#[must_use]
10201021
enum NotifyOption {
10211022
DoPersist,
10221023
SkipPersist,
@@ -1042,7 +1043,7 @@ struct PersistenceNotifierGuard<'a, F: Fn() -> NotifyOption> {
10421043
impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, it's unused
10431044
fn notify_on_drop<C: AChannelManager>(cm: &'a C) -> PersistenceNotifierGuard<'a, impl Fn() -> NotifyOption> {
10441045
let read_guard = cm.get_cm().total_consistency_lock.read().unwrap();
1045-
cm.get_cm().process_background_events();
1046+
let _ = cm.get_cm().process_background_events(); // We always persist
10461047

10471048
PersistenceNotifierGuard {
10481049
persistence_notifier: &cm.get_cm().persistence_notifier,
@@ -1768,7 +1769,7 @@ macro_rules! process_events_body {
17681769

17691770
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
17701771
// ensure any startup-generated background events are handled first.
1771-
if $self.process_background_events() { result = NotifyOption::DoPersist; }
1772+
if $self.process_background_events() == NotifyOption::DoPersist { result = NotifyOption::DoPersist; }
17721773

17731774
// TODO: This behavior should be documented. It's unintuitive that we query
17741775
// ChannelMonitors when clearing other events.
@@ -3800,14 +3801,14 @@ where
38003801
/// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors.
38013802
///
38023803
/// Expects the caller to have a total_consistency_lock read lock.
3803-
fn process_background_events(&self) -> bool {
3804+
fn process_background_events(&self) -> NotifyOption {
38043805
#[cfg(debug_assertions)]
38053806
self.background_events_processed_since_startup.store(true, Ordering::Release);
38063807

38073808
let mut background_events = Vec::new();
38083809
mem::swap(&mut *self.pending_background_events.lock().unwrap(), &mut background_events);
38093810
if background_events.is_empty() {
3810-
return false;
3811+
return NotifyOption::SkipPersist;
38113812
}
38123813

38133814
for event in background_events.drain(..) {
@@ -3848,13 +3849,13 @@ where
38483849
},
38493850
}
38503851
}
3851-
true
3852+
NotifyOption::DoPersist
38523853
}
38533854

38543855
#[cfg(any(test, feature = "_test_utils"))]
38553856
/// Process background events, for functional testing
38563857
pub fn test_process_background_events(&self) {
3857-
self.process_background_events();
3858+
let _ = self.process_background_events();
38583859
}
38593860

38603861
fn update_channel_fee(&self, chan_id: &[u8; 32], chan: &mut Channel<<SP::Target as SignerProvider>::Signer>, new_feerate: u32) -> NotifyOption {
@@ -3884,8 +3885,7 @@ where
38843885
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
38853886
pub fn maybe_update_chan_fees(&self) {
38863887
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
3887-
let mut should_persist = NotifyOption::SkipPersist;
3888-
if self.process_background_events() { should_persist = NotifyOption::DoPersist; }
3888+
let mut should_persist = self.process_background_events();
38893889

38903890
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
38913891

@@ -3921,8 +3921,7 @@ where
39213921
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
39223922
pub fn timer_tick_occurred(&self) {
39233923
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
3924-
let mut should_persist = NotifyOption::SkipPersist;
3925-
if self.process_background_events() { should_persist = NotifyOption::DoPersist; }
3924+
let mut should_persist = self.process_background_events();
39263925

39273926
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
39283927

@@ -6129,11 +6128,7 @@ where
61296128
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
61306129
let events = RefCell::new(Vec::new());
61316130
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
6132-
let mut result = NotifyOption::SkipPersist;
6133-
6134-
if self.process_background_events() {
6135-
result = NotifyOption::DoPersist;
6136-
}
6131+
let mut result = self.process_background_events();
61376132

61386133
// TODO: This behavior should be documented. It's unintuitive that we query
61396134
// ChannelMonitors when clearing other events.
@@ -6648,7 +6643,7 @@ where
66486643
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
66496644
let force_persist = self.process_background_events();
66506645
if let Ok(persist) = handle_error!(self, self.internal_channel_update(counterparty_node_id, msg), *counterparty_node_id) {
6651-
if force_persist { NotifyOption::DoPersist } else { persist }
6646+
if force_persist == NotifyOption::DoPersist { NotifyOption::DoPersist } else { persist }
66526647
} else {
66536648
NotifyOption::SkipPersist
66546649
}

0 commit comments

Comments
 (0)