Skip to content

Commit 652e7c7

Browse files
committed
Guard get_and_clear_pending_msg_events
1 parent f1acbfd commit 652e7c7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use util::logger::Logger;
6262
use util::errors::APIError;
6363

6464
use std::{cmp, mem};
65+
use std::cell::RefCell;
6566
use std::collections::{HashMap, hash_map, HashSet};
6667
use std::io::{Cursor, Read};
6768
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
35613562
L::Target: Logger,
35623563
{
35633564
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();
35673570

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()
35723583
}
35733584
}
35743585

0 commit comments

Comments
 (0)