@@ -1601,6 +1601,36 @@ macro_rules! handle_new_monitor_update {
1601
1601
}
1602
1602
}
1603
1603
1604
+ macro_rules! process_events_body {
1605
+ ( $self: expr, $event_to_handle: expr, $handle_event: expr) => {
1606
+ // We'll acquire our total consistency lock until the returned future completes so that
1607
+ // we can be sure no other persists happen while processing events.
1608
+ let _read_guard = $self. total_consistency_lock. read( ) . unwrap( ) ;
1609
+
1610
+ let mut result = NotifyOption :: SkipPersist ;
1611
+
1612
+ // TODO: This behavior should be documented. It's unintuitive that we query
1613
+ // ChannelMonitors when clearing other events.
1614
+ if $self. process_pending_monitor_events( ) {
1615
+ result = NotifyOption :: DoPersist ;
1616
+ }
1617
+
1618
+ let pending_events = mem:: replace( & mut * $self. pending_events. lock( ) . unwrap( ) , vec![ ] ) ;
1619
+ if !pending_events. is_empty( ) {
1620
+ result = NotifyOption :: DoPersist ;
1621
+ }
1622
+
1623
+ for event in pending_events {
1624
+ $event_to_handle = event;
1625
+ $handle_event;
1626
+ }
1627
+
1628
+ if result == NotifyOption :: DoPersist {
1629
+ $self. persistence_notifier. notify( ) ;
1630
+ }
1631
+ }
1632
+ }
1633
+
1604
1634
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 >
1605
1635
where
1606
1636
M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: Signer > ,
@@ -5724,30 +5754,8 @@ where
5724
5754
pub async fn process_pending_events_async < Future : core:: future:: Future , H : Fn ( Event ) -> Future > (
5725
5755
& self , handler : H
5726
5756
) {
5727
- // We'll acquire our total consistency lock until the returned future completes so that
5728
- // we can be sure no other persists happen while processing events.
5729
- let _read_guard = self . total_consistency_lock . read ( ) . unwrap ( ) ;
5730
-
5731
- let mut result = NotifyOption :: SkipPersist ;
5732
-
5733
- // TODO: This behavior should be documented. It's unintuitive that we query
5734
- // ChannelMonitors when clearing other events.
5735
- if self . process_pending_monitor_events ( ) {
5736
- result = NotifyOption :: DoPersist ;
5737
- }
5738
-
5739
- let pending_events = mem:: replace ( & mut * self . pending_events . lock ( ) . unwrap ( ) , vec ! [ ] ) ;
5740
- if !pending_events. is_empty ( ) {
5741
- result = NotifyOption :: DoPersist ;
5742
- }
5743
-
5744
- for event in pending_events {
5745
- handler ( event) . await ;
5746
- }
5747
-
5748
- if result == NotifyOption :: DoPersist {
5749
- self . persistence_notifier . notify ( ) ;
5750
- }
5757
+ let mut ev;
5758
+ process_events_body ! ( self , ev, { handler( ev) . await } ) ;
5751
5759
}
5752
5760
}
5753
5761
@@ -5829,26 +5837,8 @@ where
5829
5837
/// An [`EventHandler`] may safely call back to the provider in order to handle an event.
5830
5838
/// However, it must not call [`Writeable::write`] as doing so would result in a deadlock.
5831
5839
fn process_pending_events < H : Deref > ( & self , handler : H ) where H :: Target : EventHandler {
5832
- PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
5833
- let mut result = NotifyOption :: SkipPersist ;
5834
-
5835
- // TODO: This behavior should be documented. It's unintuitive that we query
5836
- // ChannelMonitors when clearing other events.
5837
- if self . process_pending_monitor_events ( ) {
5838
- result = NotifyOption :: DoPersist ;
5839
- }
5840
-
5841
- let pending_events = mem:: replace ( & mut * self . pending_events . lock ( ) . unwrap ( ) , vec ! [ ] ) ;
5842
- if !pending_events. is_empty ( ) {
5843
- result = NotifyOption :: DoPersist ;
5844
- }
5845
-
5846
- for event in pending_events {
5847
- handler. handle_event ( event) ;
5848
- }
5849
-
5850
- result
5851
- } ) ;
5840
+ let mut ev;
5841
+ process_events_body ! ( self , ev, handler. handle_event( ev) ) ;
5852
5842
}
5853
5843
}
5854
5844
0 commit comments