@@ -1614,6 +1614,36 @@ macro_rules! handle_new_monitor_update {
1614
1614
}
1615
1615
}
1616
1616
1617
+ macro_rules! process_events_body {
1618
+ ( $self: expr, $event_to_handle: expr, $handle_event: expr) => {
1619
+ // We'll acquire our total consistency lock until the returned future completes so that
1620
+ // we can be sure no other persists happen while processing events.
1621
+ let _read_guard = $self. total_consistency_lock. read( ) . unwrap( ) ;
1622
+
1623
+ let mut result = NotifyOption :: SkipPersist ;
1624
+
1625
+ // TODO: This behavior should be documented. It's unintuitive that we query
1626
+ // ChannelMonitors when clearing other events.
1627
+ if $self. process_pending_monitor_events( ) {
1628
+ result = NotifyOption :: DoPersist ;
1629
+ }
1630
+
1631
+ let pending_events = mem:: replace( & mut * $self. pending_events. lock( ) . unwrap( ) , vec![ ] ) ;
1632
+ if !pending_events. is_empty( ) {
1633
+ result = NotifyOption :: DoPersist ;
1634
+ }
1635
+
1636
+ for event in pending_events {
1637
+ $event_to_handle = event;
1638
+ $handle_event;
1639
+ }
1640
+
1641
+ if result == NotifyOption :: DoPersist {
1642
+ $self. persistence_notifier. notify( ) ;
1643
+ }
1644
+ }
1645
+ }
1646
+
1617
1647
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 >
1618
1648
where
1619
1649
M :: Target : chain:: Watch < <SP :: Target as SignerProvider >:: Signer > ,
@@ -5744,30 +5774,8 @@ where
5744
5774
pub async fn process_pending_events_async < Future : core:: future:: Future , H : Fn ( Event ) -> Future > (
5745
5775
& self , handler : H
5746
5776
) {
5747
- // We'll acquire our total consistency lock until the returned future completes so that
5748
- // we can be sure no other persists happen while processing events.
5749
- let _read_guard = self . total_consistency_lock . read ( ) . unwrap ( ) ;
5750
-
5751
- let mut result = NotifyOption :: SkipPersist ;
5752
-
5753
- // TODO: This behavior should be documented. It's unintuitive that we query
5754
- // ChannelMonitors when clearing other events.
5755
- if self . process_pending_monitor_events ( ) {
5756
- result = NotifyOption :: DoPersist ;
5757
- }
5758
-
5759
- let pending_events = mem:: replace ( & mut * self . pending_events . lock ( ) . unwrap ( ) , vec ! [ ] ) ;
5760
- if !pending_events. is_empty ( ) {
5761
- result = NotifyOption :: DoPersist ;
5762
- }
5763
-
5764
- for event in pending_events {
5765
- handler ( event) . await ;
5766
- }
5767
-
5768
- if result == NotifyOption :: DoPersist {
5769
- self . persistence_notifier . notify ( ) ;
5770
- }
5777
+ let mut ev;
5778
+ process_events_body ! ( self , ev, { handler( ev) . await } ) ;
5771
5779
}
5772
5780
}
5773
5781
@@ -5849,26 +5857,8 @@ where
5849
5857
/// An [`EventHandler`] may safely call back to the provider in order to handle an event.
5850
5858
/// However, it must not call [`Writeable::write`] as doing so would result in a deadlock.
5851
5859
fn process_pending_events < H : Deref > ( & self , handler : H ) where H :: Target : EventHandler {
5852
- PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
5853
- let mut result = NotifyOption :: SkipPersist ;
5854
-
5855
- // TODO: This behavior should be documented. It's unintuitive that we query
5856
- // ChannelMonitors when clearing other events.
5857
- if self . process_pending_monitor_events ( ) {
5858
- result = NotifyOption :: DoPersist ;
5859
- }
5860
-
5861
- let pending_events = mem:: replace ( & mut * self . pending_events . lock ( ) . unwrap ( ) , vec ! [ ] ) ;
5862
- if !pending_events. is_empty ( ) {
5863
- result = NotifyOption :: DoPersist ;
5864
- }
5865
-
5866
- for event in pending_events {
5867
- handler. handle_event ( event) ;
5868
- }
5869
-
5870
- result
5871
- } ) ;
5860
+ let mut ev;
5861
+ process_events_body ! ( self , ev, handler. handle_event( ev) ) ;
5872
5862
}
5873
5863
}
5874
5864
0 commit comments