@@ -62,6 +62,7 @@ use util::logger::Logger;
62
62
use util:: errors:: APIError ;
63
63
64
64
use core:: { cmp, mem} ;
65
+ use std:: cell:: RefCell ;
65
66
use std:: collections:: { HashMap , hash_map, HashSet } ;
66
67
use std:: io:: { Cursor , Read } ;
67
68
use std:: sync:: { Arc , Condvar , Mutex , MutexGuard , RwLock , RwLockReadGuard } ;
@@ -3602,14 +3603,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> MessageSend
3602
3603
L :: Target : Logger ,
3603
3604
{
3604
3605
fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
3605
- //TODO: This behavior should be documented. It's non-intuitive that we query
3606
- // ChannelMonitors when clearing other events.
3607
- self . process_pending_monitor_events ( ) ;
3606
+ let events = RefCell :: new ( Vec :: new ( ) ) ;
3607
+ PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3608
+ let mut result = NotifyOption :: SkipPersist ;
3608
3609
3609
- let mut ret = Vec :: new ( ) ;
3610
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3611
- mem:: swap ( & mut ret, & mut channel_state. pending_msg_events ) ;
3612
- ret
3610
+ // TODO: This behavior should be documented. It's unintuitive that we query
3611
+ // ChannelMonitors when clearing other events.
3612
+ if self . process_pending_monitor_events ( ) {
3613
+ result = NotifyOption :: DoPersist ;
3614
+ }
3615
+
3616
+ let mut pending_events = Vec :: new ( ) ;
3617
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3618
+ mem:: swap ( & mut pending_events, & mut channel_state. pending_msg_events ) ;
3619
+
3620
+ if !pending_events. is_empty ( ) {
3621
+ events. replace ( pending_events) ;
3622
+ }
3623
+
3624
+ result
3625
+ } ) ;
3626
+ events. into_inner ( )
3613
3627
}
3614
3628
}
3615
3629
0 commit comments