Skip to content

Commit f070fef

Browse files
committed
f move method into closure
1 parent 4a8edf6 commit f070fef

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,39 +2140,42 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21402140
///
21412141
/// Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
21422142
pub fn timer_tick_occurred(&self) {
2143-
let should_persist = std::cell::RefCell::new(PersistenceGuardOption::SkipPersist);
2144-
let mut _persistence_guard = PersistenceNotifierGuard::optionally_persist(&self.total_consistency_lock, &self.persistence_notifier, || *should_persist.borrow());
2145-
if self.process_background_events() { *should_persist.borrow_mut() = PersistenceGuardOption::DoPersist; }
2143+
PersistenceNotifierGuard::optionally_persist(&self.total_consistency_lock, &self.persistence_notifier, || {
2144+
let mut should_persist = PersistenceGuardOption::SkipPersist;
2145+
if self.process_background_events() { should_persist = PersistenceGuardOption::DoPersist; }
21462146

2147-
let mut channel_state_lock = self.channel_state.lock().unwrap();
2148-
let channel_state = &mut *channel_state_lock;
2149-
for (_, chan) in channel_state.by_id.iter_mut() {
2150-
match chan.get_update_status() {
2151-
UpdateStatus::Enabled if !chan.is_live() => chan.set_update_status(UpdateStatus::DisabledStaged),
2152-
UpdateStatus::Disabled if chan.is_live() => chan.set_update_status(UpdateStatus::EnabledStaged),
2153-
UpdateStatus::DisabledStaged if chan.is_live() => chan.set_update_status(UpdateStatus::Enabled),
2154-
UpdateStatus::EnabledStaged if !chan.is_live() => chan.set_update_status(UpdateStatus::Disabled),
2155-
UpdateStatus::DisabledStaged if !chan.is_live() => {
2156-
if let Ok(update) = self.get_channel_update(&chan) {
2157-
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
2158-
msg: update
2159-
});
2160-
}
2161-
*should_persist.borrow_mut() = PersistenceGuardOption::DoPersist;
2162-
chan.set_update_status(UpdateStatus::Disabled);
2163-
},
2164-
UpdateStatus::EnabledStaged if chan.is_live() => {
2165-
if let Ok(update) = self.get_channel_update(&chan) {
2166-
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
2167-
msg: update
2168-
});
2169-
}
2170-
*should_persist.borrow_mut() = PersistenceGuardOption::DoPersist;
2171-
chan.set_update_status(UpdateStatus::Enabled);
2172-
},
2173-
_ => {},
2147+
let mut channel_state_lock = self.channel_state.lock().unwrap();
2148+
let channel_state = &mut *channel_state_lock;
2149+
for (_, chan) in channel_state.by_id.iter_mut() {
2150+
match chan.get_update_status() {
2151+
UpdateStatus::Enabled if !chan.is_live() => chan.set_update_status(UpdateStatus::DisabledStaged),
2152+
UpdateStatus::Disabled if chan.is_live() => chan.set_update_status(UpdateStatus::EnabledStaged),
2153+
UpdateStatus::DisabledStaged if chan.is_live() => chan.set_update_status(UpdateStatus::Enabled),
2154+
UpdateStatus::EnabledStaged if !chan.is_live() => chan.set_update_status(UpdateStatus::Disabled),
2155+
UpdateStatus::DisabledStaged if !chan.is_live() => {
2156+
if let Ok(update) = self.get_channel_update(&chan) {
2157+
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
2158+
msg: update
2159+
});
2160+
}
2161+
should_persist = PersistenceGuardOption::DoPersist;
2162+
chan.set_update_status(UpdateStatus::Disabled);
2163+
},
2164+
UpdateStatus::EnabledStaged if chan.is_live() => {
2165+
if let Ok(update) = self.get_channel_update(&chan) {
2166+
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
2167+
msg: update
2168+
});
2169+
}
2170+
should_persist = PersistenceGuardOption::DoPersist;
2171+
chan.set_update_status(UpdateStatus::Enabled);
2172+
},
2173+
_ => {},
2174+
}
21742175
}
2175-
}
2176+
2177+
should_persist
2178+
});
21762179
}
21772180

21782181
/// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect

0 commit comments

Comments
 (0)