Skip to content

Commit

Permalink
Send warning messages when repeating shutdown messages at volume
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Aug 21, 2023
1 parent bb7c4d1 commit b149279
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion lightning/src/ln/shutdown_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit b149279

Please sign in to comment.