From: Matt Corallo Date: Mon, 21 Aug 2023 23:04:47 +0000 (+0000) Subject: Send warning messages when repeating shutdown messages at volume X-Git-Tag: v0.0.117-alpha1~51^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2023-08-lnd-6039;p=rust-lightning Send warning messages when repeating shutdown messages at volume --- diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 418f8d545..7da0470bd 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -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. diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 9794dc905..15f536789 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 515dcbba2..dc8d92154 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -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 { diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 23d3a30dc..5335ab651 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -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());