Skip to content

Commit 4b4fae0

Browse files
committed
f Still hold total_conistency_lock during monitor event processing
1 parent 99d9628 commit 4b4fae0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lightning/src/ln/channelmanager.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,16 @@ macro_rules! process_events_body {
16901690

16911691
let mut result = NotifyOption::SkipPersist;
16921692

1693-
// TODO: This behavior should be documented. It's unintuitive that we query
1694-
// ChannelMonitors when clearing other events.
1695-
if $self.process_pending_monitor_events() {
1696-
result = NotifyOption::DoPersist;
1693+
{
1694+
// We'll acquire our total consistency lock so that we can be sure no other
1695+
// persists happen while processing monitor events.
1696+
let _read_guard = $self.total_consistency_lock.read().unwrap();
1697+
1698+
// TODO: This behavior should be documented. It's unintuitive that we query
1699+
// ChannelMonitors when clearing other events.
1700+
if $self.process_pending_monitor_events() {
1701+
result = NotifyOption::DoPersist;
1702+
}
16971703
}
16981704

16991705
let pending_events = $self.pending_events.lock().unwrap().clone();
@@ -4384,6 +4390,7 @@ where
43844390
}
43854391

43864392
fn channel_monitor_updated(&self, funding_txo: &OutPoint, highest_applied_update_id: u64, counterparty_node_id: Option<&PublicKey>) {
4393+
debug_assert!(self.total_consistency_lock.try_write().is_err()); // Caller holds read lock
43874394
let counterparty_node_id = match counterparty_node_id {
43884395
Some(cp_id) => cp_id.clone(),
43894396
None => {

0 commit comments

Comments
 (0)