]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Send warning messages when repeating shutdown messages at volume 2023-08-lnd-6039
authorMatt Corallo <git@bluematt.me>
Mon, 21 Aug 2023 23:04:47 +0000 (23:04 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 21 Aug 2023 23:04:47 +0000 (23:04 +0000)
lightning/src/events/mod.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/msgs.rs
lightning/src/ln/shutdown_tests.rs

index 418f8d5459a18e7fe3711327ba119ab87d2de5ef..7da0470bdf02ebcb50a31313286007c5af25df59 100644 (file)
@@ -1501,6 +1501,7 @@ impl MaybeReadable for Event {
 /// broadcast to most peers).
 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
 #[derive(Clone, Debug)]
+#[cfg_attr(test, derive(PartialEq))]
 pub enum MessageSendEvent {
        /// Used to indicate that we've accepted a channel open and should send the accept_channel
        /// message provided to the given peer.
index 9794dc905f4c62a8bea91f71ea56bea56be15678..15f536789bf43713279e5e231e415d26bf5b1129 100644 (file)
@@ -7512,6 +7512,16 @@ where
                                                                msg,
                                                        });
                                                }
+                                               peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
+                                                       node_id: *counterparty_node_id,
+                                                       action: msgs::ErrorAction::SendWarningMessage {
+                                                               msg: msgs::WarningMessage {
+                                                                       channel_id: msg.channel_id,
+                                                                       data: "You appear to be exhibiting LND bug 6039, we'll keep sending you shutdown messages until you handle them correctly".to_owned()
+                                                               },
+                                                               log_level: Level::Trace,
+                                                       }
+                                               });
                                        }
                                }
                                return;
index 515dcbba2d2e136846697dc990d582270e07e1d4..dc8d9215438e09a4eb505a4106f15083003519bc 100644 (file)
@@ -1144,7 +1144,7 @@ enum EncodingType {
 }
 
 /// Used to put an error message in a [`LightningError`].
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
 pub enum ErrorAction {
        /// The peer took some action which made us think they were useless. Disconnect them.
        DisconnectPeer {
index 23d3a30dc8314fb83bac214c250c3c73abdb487b..5335ab651417cf22f6fc718bbb3b51836818f88a 100644 (file)
@@ -219,7 +219,13 @@ fn test_lnd_bug_6039() {
        // see if LND will accept our protocol compliance.
        let err_msg = msgs::ErrorMessage { channel_id: chan.2, data: "link failed to shutdown".to_string() };
        nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &err_msg);
-       let _node_0_repeated_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id());
+       let node_a_responses = nodes[0].node.get_and_clear_pending_msg_events();
+       assert_eq!(node_a_responses[0], MessageSendEvent::SendShutdown {
+                       node_id: nodes[1].node.get_our_node_id(),
+                       msg: node_0_shutdown,
+               });
+       if let MessageSendEvent::HandleError { action: msgs::ErrorAction::SendWarningMessage { .. }, .. }
+               = node_a_responses[1] {} else { panic!(); }
 
        let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());