@@ -8178,8 +8178,6 @@ where
8178
8178
}
8179
8179
8180
8180
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
8181
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8182
-
8183
8181
match &msg.data as &str {
8184
8182
"cannot co-op close channel w/ active htlcs"|
8185
8183
"link failed to shutdown" =>
@@ -8192,34 +8190,45 @@ where
8192
8190
// We're not going to bother handling this in a sensible way, instead simply
8193
8191
// repeating the Shutdown message on repeat until morale improves.
8194
8192
if !msg.channel_id.is_zero() {
8195
- let per_peer_state = self.per_peer_state.read().unwrap();
8196
- let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
8197
- if peer_state_mutex_opt.is_none() { return; }
8198
- let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
8199
- if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
8200
- if let Some(msg) = chan.get_outbound_shutdown() {
8201
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
8202
- node_id: *counterparty_node_id,
8203
- msg,
8204
- });
8205
- }
8206
- peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8207
- node_id: *counterparty_node_id,
8208
- action: msgs::ErrorAction::SendWarningMessage {
8209
- msg: msgs::WarningMessage {
8210
- channel_id: msg.channel_id,
8211
- data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
8212
- },
8213
- log_level: Level::Trace,
8193
+ PersistenceNotifierGuard::optionally_notify(
8194
+ self,
8195
+ || -> NotifyOption {
8196
+ let per_peer_state = self.per_peer_state.read().unwrap();
8197
+ let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
8198
+ if peer_state_mutex_opt.is_none() { return NotifyOption::SkipPersistNoEvents; }
8199
+ let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
8200
+ if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
8201
+ if let Some(msg) = chan.get_outbound_shutdown() {
8202
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
8203
+ node_id: *counterparty_node_id,
8204
+ msg,
8205
+ });
8206
+ }
8207
+ peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8208
+ node_id: *counterparty_node_id,
8209
+ action: msgs::ErrorAction::SendWarningMessage {
8210
+ msg: msgs::WarningMessage {
8211
+ channel_id: msg.channel_id,
8212
+ data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
8213
+ },
8214
+ log_level: Level::Trace,
8215
+ }
8216
+ });
8217
+ // This can happen in a fairly tight loop, so we absolutely cannot trigger
8218
+ // a `ChannelManager` write here.
8219
+ return NotifyOption::SkipPersistHandleEvents;
8214
8220
}
8215
- });
8216
- }
8221
+ NotifyOption::SkipPersistNoEvents
8222
+ }
8223
+ );
8217
8224
}
8218
8225
return;
8219
8226
}
8220
8227
_ => {}
8221
8228
}
8222
8229
8230
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8231
+
8223
8232
if msg.channel_id.is_zero() {
8224
8233
let channel_ids: Vec<ChannelId> = {
8225
8234
let per_peer_state = self.per_peer_state.read().unwrap();
0 commit comments