@@ -62,6 +62,7 @@ use util::logger::Logger;
62
62
use util:: errors:: APIError ;
63
63
64
64
use std:: { 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 } ;
@@ -3561,14 +3562,24 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> MessageSend
3561
3562
L :: Target : Logger ,
3562
3563
{
3563
3564
fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
3564
- //TODO: This behavior should be documented. It's non-intuitive that we query
3565
- // ChannelMonitors when clearing other events.
3566
- self . process_pending_monitor_events ( ) ;
3565
+ let result = RefCell :: new ( Vec :: new ( ) ) ;
3566
+ PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
3567
+ // TODO: This behavior should be documented. It's unintuitive that we query
3568
+ // ChannelMonitors when clearing other events.
3569
+ self . process_pending_monitor_events ( ) ;
3567
3570
3568
- let mut ret = Vec :: new ( ) ;
3569
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3570
- mem:: swap ( & mut ret, & mut channel_state. pending_msg_events ) ;
3571
- ret
3571
+ let mut pending_events = Vec :: new ( ) ;
3572
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3573
+ mem:: swap ( & mut pending_events, & mut channel_state. pending_msg_events ) ;
3574
+
3575
+ if pending_events. is_empty ( ) {
3576
+ NotifyOption :: SkipPersist
3577
+ } else {
3578
+ result. replace ( pending_events) ;
3579
+ NotifyOption :: DoPersist
3580
+ }
3581
+ } ) ;
3582
+ result. into_inner ( )
3572
3583
}
3573
3584
}
3574
3585
0 commit comments