@@ -9030,8 +9030,6 @@ where
9030
9030
}
9031
9031
9032
9032
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
9033
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9034
-
9035
9033
match &msg.data as &str {
9036
9034
"cannot co-op close channel w/ active htlcs"|
9037
9035
"link failed to shutdown" =>
@@ -9044,34 +9042,45 @@ where
9044
9042
// We're not going to bother handling this in a sensible way, instead simply
9045
9043
// repeating the Shutdown message on repeat until morale improves.
9046
9044
if !msg.channel_id.is_zero() {
9047
- let per_peer_state = self.per_peer_state.read().unwrap();
9048
- let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
9049
- if peer_state_mutex_opt.is_none() { return; }
9050
- let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
9051
- if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
9052
- if let Some(msg) = chan.get_outbound_shutdown() {
9053
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
9054
- node_id: *counterparty_node_id,
9055
- msg,
9056
- });
9057
- }
9058
- peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
9059
- node_id: *counterparty_node_id,
9060
- action: msgs::ErrorAction::SendWarningMessage {
9061
- msg: msgs::WarningMessage {
9062
- channel_id: msg.channel_id,
9063
- data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
9064
- },
9065
- log_level: Level::Trace,
9045
+ PersistenceNotifierGuard::optionally_notify(
9046
+ self,
9047
+ || -> NotifyOption {
9048
+ let per_peer_state = self.per_peer_state.read().unwrap();
9049
+ let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
9050
+ if peer_state_mutex_opt.is_none() { return NotifyOption::SkipPersistNoEvents; }
9051
+ let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
9052
+ if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
9053
+ if let Some(msg) = chan.get_outbound_shutdown() {
9054
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
9055
+ node_id: *counterparty_node_id,
9056
+ msg,
9057
+ });
9058
+ }
9059
+ peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
9060
+ node_id: *counterparty_node_id,
9061
+ action: msgs::ErrorAction::SendWarningMessage {
9062
+ msg: msgs::WarningMessage {
9063
+ channel_id: msg.channel_id,
9064
+ data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
9065
+ },
9066
+ log_level: Level::Trace,
9067
+ }
9068
+ });
9069
+ // This can happen in a fairly tight loop, so we absolutely cannot trigger
9070
+ // a `ChannelManager` write here.
9071
+ return NotifyOption::SkipPersistHandleEvents;
9066
9072
}
9067
- });
9068
- }
9073
+ NotifyOption::SkipPersistNoEvents
9074
+ }
9075
+ );
9069
9076
}
9070
9077
return;
9071
9078
}
9072
9079
_ => {}
9073
9080
}
9074
9081
9082
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9083
+
9075
9084
if msg.channel_id.is_zero() {
9076
9085
let channel_ids: Vec<ChannelId> = {
9077
9086
let per_peer_state = self.per_peer_state.read().unwrap();
0 commit comments