@@ -8745,8 +8745,6 @@ where
8745
8745
}
8746
8746
8747
8747
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
8748
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8749
-
8750
8748
match &msg.data as &str {
8751
8749
"cannot co-op close channel w/ active htlcs"|
8752
8750
"link failed to shutdown" =>
@@ -8759,34 +8757,45 @@ where
8759
8757
// We're not going to bother handling this in a sensible way, instead simply
8760
8758
// repeating the Shutdown message on repeat until morale improves.
8761
8759
if !msg.channel_id.is_zero() {
8762
- let per_peer_state = self.per_peer_state.read().unwrap();
8763
- let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
8764
- if peer_state_mutex_opt.is_none() { return; }
8765
- let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
8766
- if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
8767
- if let Some(msg) = chan.get_outbound_shutdown() {
8768
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
8769
- node_id: *counterparty_node_id,
8770
- msg,
8771
- });
8772
- }
8773
- peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8774
- node_id: *counterparty_node_id,
8775
- action: msgs::ErrorAction::SendWarningMessage {
8776
- msg: msgs::WarningMessage {
8777
- channel_id: msg.channel_id,
8778
- data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
8779
- },
8780
- log_level: Level::Trace,
8760
+ PersistenceNotifierGuard::optionally_notify(
8761
+ self,
8762
+ || -> NotifyOption {
8763
+ let per_peer_state = self.per_peer_state.read().unwrap();
8764
+ let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
8765
+ if peer_state_mutex_opt.is_none() { return NotifyOption::SkipPersistNoEvents; }
8766
+ let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap();
8767
+ if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) {
8768
+ if let Some(msg) = chan.get_outbound_shutdown() {
8769
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
8770
+ node_id: *counterparty_node_id,
8771
+ msg,
8772
+ });
8773
+ }
8774
+ peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8775
+ node_id: *counterparty_node_id,
8776
+ action: msgs::ErrorAction::SendWarningMessage {
8777
+ msg: msgs::WarningMessage {
8778
+ channel_id: msg.channel_id,
8779
+ data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
8780
+ },
8781
+ log_level: Level::Trace,
8782
+ }
8783
+ });
8784
+ // This can happen in a fairly tight loop, so we absolutely cannot trigger
8785
+ // a `ChannelManager` write here.
8786
+ return NotifyOption::SkipPersistHandleEvents;
8781
8787
}
8782
- });
8783
- }
8788
+ NotifyOption::SkipPersistNoEvents
8789
+ }
8790
+ );
8784
8791
}
8785
8792
return;
8786
8793
}
8787
8794
_ => {}
8788
8795
}
8789
8796
8797
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8798
+
8790
8799
if msg.channel_id.is_zero() {
8791
8800
let channel_ids: Vec<ChannelId> = {
8792
8801
let per_peer_state = self.per_peer_state.read().unwrap();
0 commit comments