@@ -9242,8 +9242,6 @@ where
9242
9242
}
9243
9243
9244
9244
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
9245
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9246
-
9247
9245
match &msg.data as &str {
9248
9246
"cannot co-op close channel w/ active htlcs"|
9249
9247
"link failed to shutdown" =>
@@ -9256,34 +9254,45 @@ where
9256
9254
// We're not going to bother handling this in a sensible way, instead simply
9257
9255
// repeating the Shutdown message on repeat until morale improves.
9258
9256
if !msg.channel_id.is_zero() {
9259
- let per_peer_state = self.per_peer_state.read().unwrap();
9260
- let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
9261
- if peer_state_mutex_opt.is_none() { return; }
9262
- let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
9263
- if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
9264
- if let Some(msg) = chan.get_outbound_shutdown() {
9265
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
9266
- node_id: *counterparty_node_id,
9267
- msg,
9268
- });
9269
- }
9270
- peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
9271
- node_id: *counterparty_node_id,
9272
- action: msgs::ErrorAction::SendWarningMessage {
9273
- msg: msgs::WarningMessage {
9274
- channel_id: msg.channel_id,
9275
- data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
9276
- },
9277
- log_level: Level::Trace,
9257
+ PersistenceNotifierGuard::optionally_notify(
9258
+ self,
9259
+ || -> NotifyOption {
9260
+ let per_peer_state = self.per_peer_state.read().unwrap();
9261
+ let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
9262
+ if peer_state_mutex_opt.is_none() { return NotifyOption::SkipPersistNoEvents; }
9263
+ let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
9264
+ if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
9265
+ if let Some(msg) = chan.get_outbound_shutdown() {
9266
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
9267
+ node_id: *counterparty_node_id,
9268
+ msg,
9269
+ });
9270
+ }
9271
+ peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
9272
+ node_id: *counterparty_node_id,
9273
+ action: msgs::ErrorAction::SendWarningMessage {
9274
+ msg: msgs::WarningMessage {
9275
+ channel_id: msg.channel_id,
9276
+ data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
9277
+ },
9278
+ log_level: Level::Trace,
9279
+ }
9280
+ });
9281
+ // This can happen in a fairly tight loop, so we absolutely cannot trigger
9282
+ // a `ChannelManager` write here.
9283
+ return NotifyOption::SkipPersistHandleEvents;
9278
9284
}
9279
- });
9280
- }
9285
+ NotifyOption::SkipPersistNoEvents
9286
+ }
9287
+ );
9281
9288
}
9282
9289
return;
9283
9290
}
9284
9291
_ => {}
9285
9292
}
9286
9293
9294
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9295
+
9287
9296
if msg.channel_id.is_zero() {
9288
9297
let channel_ids: Vec<ChannelId> = {
9289
9298
let per_peer_state = self.per_peer_state.read().unwrap();
0 commit comments