@@ -1678,36 +1678,6 @@ macro_rules! handle_new_monitor_update {
1678
1678
}
1679
1679
}
1680
1680
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
-
1711
1681
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 >
1712
1682
where
1713
1683
M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: Signer > ,
@@ -5805,8 +5775,30 @@ where
5805
5775
pub async fn process_pending_events_async < Future : core:: future:: Future , H : Fn ( Event ) -> Future > (
5806
5776
& self , handler : H
5807
5777
) {
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
+ }
5810
5802
}
5811
5803
}
5812
5804
@@ -5888,8 +5880,26 @@ where
5888
5880
/// An [`EventHandler`] may safely call back to the provider in order to handle an event.
5889
5881
/// However, it must not call [`Writeable::write`] as doing so would result in a deadlock.
5890
5882
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
+ } ) ;
5893
5903
}
5894
5904
}
5895
5905
0 commit comments