Skip to content

Commit 42bda27

Browse files
committed
Revert "DRY the event handling in ChannelManager"
This reverts commit fb86fc2. We do so as we'll be modifying the async `process_pending_events` variant while leaving the blocking variant untouched.
1 parent 4a3e9f4 commit 42bda27

File tree

1 file changed

+44
-34
lines changed

1 file changed

+44
-34
lines changed

lightning/src/ln/channelmanager.rs

+44-34
Original file line numberDiff line numberDiff line change
@@ -1678,36 +1678,6 @@ macro_rules! handle_new_monitor_update {
16781678
}
16791679
}
16801680

1681-
macro_rules! process_events_body {
1682-
($self: expr, $event_to_handle: expr, $handle_event: expr) => {
1683-
// We'll acquire our total consistency lock until the returned future completes so that
1684-
// we can be sure no other persists happen while processing events.
1685-
let _read_guard = $self.total_consistency_lock.read().unwrap();
1686-
1687-
let mut result = NotifyOption::SkipPersist;
1688-
1689-
// TODO: This behavior should be documented. It's unintuitive that we query
1690-
// ChannelMonitors when clearing other events.
1691-
if $self.process_pending_monitor_events() {
1692-
result = NotifyOption::DoPersist;
1693-
}
1694-
1695-
let pending_events = mem::replace(&mut *$self.pending_events.lock().unwrap(), vec![]);
1696-
if !pending_events.is_empty() {
1697-
result = NotifyOption::DoPersist;
1698-
}
1699-
1700-
for event in pending_events {
1701-
$event_to_handle = event;
1702-
$handle_event;
1703-
}
1704-
1705-
if result == NotifyOption::DoPersist {
1706-
$self.persistence_notifier.notify();
1707-
}
1708-
}
1709-
}
1710-
17111681
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, L>
17121682
where
17131683
M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
@@ -5805,8 +5775,30 @@ where
58055775
pub async fn process_pending_events_async<Future: core::future::Future, H: Fn(Event) -> Future>(
58065776
&self, handler: H
58075777
) {
5808-
let mut ev;
5809-
process_events_body!(self, ev, { handler(ev).await });
5778+
// We'll acquire our total consistency lock until the returned future completes so that
5779+
// we can be sure no other persists happen while processing events.
5780+
let _read_guard = self.total_consistency_lock.read().unwrap();
5781+
5782+
let mut result = NotifyOption::SkipPersist;
5783+
5784+
// TODO: This behavior should be documented. It's unintuitive that we query
5785+
// ChannelMonitors when clearing other events.
5786+
if self.process_pending_monitor_events() {
5787+
result = NotifyOption::DoPersist;
5788+
}
5789+
5790+
let pending_events = mem::replace(&mut *self.pending_events.lock().unwrap(), vec![]);
5791+
if !pending_events.is_empty() {
5792+
result = NotifyOption::DoPersist;
5793+
}
5794+
5795+
for event in pending_events {
5796+
handler(event).await;
5797+
}
5798+
5799+
if result == NotifyOption::DoPersist {
5800+
self.persistence_notifier.notify();
5801+
}
58105802
}
58115803
}
58125804

@@ -5888,8 +5880,26 @@ where
58885880
/// An [`EventHandler`] may safely call back to the provider in order to handle an event.
58895881
/// However, it must not call [`Writeable::write`] as doing so would result in a deadlock.
58905882
fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler {
5891-
let mut ev;
5892-
process_events_body!(self, ev, handler.handle_event(ev));
5883+
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.persistence_notifier, || {
5884+
let mut result = NotifyOption::SkipPersist;
5885+
5886+
// TODO: This behavior should be documented. It's unintuitive that we query
5887+
// ChannelMonitors when clearing other events.
5888+
if self.process_pending_monitor_events() {
5889+
result = NotifyOption::DoPersist;
5890+
}
5891+
5892+
let pending_events = mem::replace(&mut *self.pending_events.lock().unwrap(), vec![]);
5893+
if !pending_events.is_empty() {
5894+
result = NotifyOption::DoPersist;
5895+
}
5896+
5897+
for event in pending_events {
5898+
handler.handle_event(event);
5899+
}
5900+
5901+
result
5902+
});
58935903
}
58945904
}
58955905

0 commit comments

Comments
 (0)