Skip to content

Commit dadd363

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 f5ee8c2 commit dadd363

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
@@ -9242,8 +9242,6 @@ where
92429242
}
92439243

92449244
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
9245-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9246-
92479245
match &msg.data as &str {
92489246
"cannot co-op close channel w/ active htlcs"|
92499247
"link failed to shutdown" =>
@@ -9277,13 +9275,21 @@ where
92779275
log_level: Level::Trace,
92789276
}
92799277
});
9278+
// This can happen in a fairly tight loop, so we absolutely cannot trigger
9279+
// a `ChannelManager` write here.
9280+
PersistenceNotifierGuard::optionally_notify(
9281+
self,
9282+
|| -> NotifyOption { NotifyOption::SkipPersistHandleEvents }
9283+
);
92809284
}
92819285
}
92829286
return;
92839287
}
92849288
_ => {}
92859289
}
92869290

9291+
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9292+
92879293
if msg.channel_id.is_zero() {
92889294
let channel_ids: Vec<ChannelId> = {
92899295
let per_peer_state = self.per_peer_state.read().unwrap();

0 commit comments

Comments
 (0)