Skip to content

Commit a0228bd

Browse files
committed
Avoid writing ChannelManager when hitting lnd bug 6039
When we hit lnd bug 6039, we end up sending error messages to peers in a loop. This should be fine, but because we used the generic `PersistenceNotifierGuard::notify_on_drop` lock above the specific handling, we end up writing `ChannelManager` every time we manage a round-trip to our peer. This can add up quite quickly, and isn't actually changing, so we really need to avoid writing the `ChannelManager` in this case.
1 parent e2108f2 commit a0228bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9026,8 +9026,6 @@ where
90269026
}
90279027

90289028
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
9029-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9030-
90319029
match &msg.data as &str {
90329030
"cannot co-op close channel w/ active htlcs"|
90339031
"link failed to shutdown" =>
@@ -9061,13 +9059,21 @@ where
90619059
log_level: Level::Trace,
90629060
}
90639061
});
9062+
// This can happen in a fairly tight loop, so we absolutely cannot trigger
9063+
// a `ChannelManager` write here.
9064+
PersistenceNotifierGuard::optionally_notify(
9065+
self,
9066+
|| -> NotifyOption { NotifyOption::SkipPersistHandleEvents }
9067+
);
90649068
}
90659069
}
90669070
return;
90679071
}
90689072
_ => {}
90699073
}
90709074

9075+
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9076+
90719077
if msg.channel_id.is_zero() {
90729078
let channel_ids: Vec<ChannelId> = {
90739079
let per_peer_state = self.per_peer_state.read().unwrap();

0 commit comments

Comments
 (0)