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