Skip to content

Commit

Permalink
Avoid writing ChannelManager when hitting lnd bug 6039
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed Mar 14, 2024
1 parent f5ee8c2 commit dadd363
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9242,8 +9242,6 @@ where
}

fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);

match &msg.data as &str {
"cannot co-op close channel w/ active htlcs"|
"link failed to shutdown" =>
Expand Down Expand Up @@ -9277,13 +9275,21 @@ where
log_level: Level::Trace,
}
});
// This can happen in a fairly tight loop, so we absolutely cannot trigger
// a `ChannelManager` write here.
PersistenceNotifierGuard::optionally_notify(
self,
|| -> NotifyOption { NotifyOption::SkipPersistHandleEvents }
);
}
}
return;
}
_ => {}
}

let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);

if msg.channel_id.is_zero() {
let channel_ids: Vec<ChannelId> = {
let per_peer_state = self.per_peer_state.read().unwrap();
Expand Down

0 comments on commit dadd363

Please sign in to comment.