Skip to content

Commit caa9f2c

Browse files
committed
Guard get_and_clear_pending_msg_events
1 parent a611294 commit caa9f2c

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 21 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 core::{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};
@@ -3602,14 +3603,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> MessageSend
36023603
L::Target: Logger,
36033604
{
36043605
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;
36083609

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()
36133627
}
36143628
}
36153629

0 commit comments

Comments
 (0)