Skip to content

Commit 914ec5c

Browse files
committed
Convert shutdown invalid script checks to warning messages
As required by the warning messages PR, we should simply warn our counterparty in this case and let them try again, continuing to try to use the channel until they tell us otherwise.
1 parent 7e9480b commit 914ec5c

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,12 +3723,12 @@ impl<Signer: Sign> Channel<Signer> {
37233723
assert_eq!(self.channel_state & ChannelState::ShutdownComplete as u32, 0);
37243724

37253725
if !script::is_bolt2_compliant(&msg.scriptpubkey, their_features) {
3726-
return Err(ChannelError::Close(format!("Got a nonstandard scriptpubkey ({}) from remote peer", msg.scriptpubkey.to_bytes().to_hex())));
3726+
return Err(ChannelError::Warn(format!("Got a nonstandard scriptpubkey ({}) from remote peer", msg.scriptpubkey.to_bytes().to_hex())));
37273727
}
37283728

37293729
if self.counterparty_shutdown_scriptpubkey.is_some() {
37303730
if Some(&msg.scriptpubkey) != self.counterparty_shutdown_scriptpubkey.as_ref() {
3731-
return Err(ChannelError::Close(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_bytes().to_hex())));
3731+
return Err(ChannelError::Warn(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_bytes().to_hex())));
37323732
}
37333733
} else {
37343734
self.counterparty_shutdown_scriptpubkey = Some(msg.scriptpubkey.clone());

lightning/src/ln/shutdown_tests.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,17 @@ fn test_upfront_shutdown_script() {
415415
let flags = InitFeatures::known();
416416
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone());
417417
nodes[0].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap();
418-
let mut node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id());
418+
let node_0_orig_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id());
419+
let mut node_0_shutdown = node_0_orig_shutdown.clone();
419420
node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh();
420-
// Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we disconnect peer
421+
// Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we warn
422+
// the peer and ignore the message.
421423
nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
422-
assert!(regex::Regex::new(r"Got shutdown request with a scriptpubkey \([A-Fa-f0-9]+\) which did not match their previous scriptpubkey.").unwrap().is_match(check_closed_broadcast!(nodes[2], true).unwrap().data.as_str()));
423-
check_closed_event!(nodes[2], 1, ClosureReason::ProcessingError { err: "Got shutdown request with a scriptpubkey (a91441c98a140039816273e50db317422c11c2bfcc8887) which did not match their previous scriptpubkey.".to_string() });
424-
check_added_monitors!(nodes[2], 1);
424+
assert!(regex::Regex::new(r"Got shutdown request with a scriptpubkey \([A-Fa-f0-9]+\) which did not match their previous scriptpubkey.")
425+
.unwrap().is_match(&check_warn_msg!(nodes[2], nodes[0].node.get_our_node_id(), chan.2)));
426+
// This allows nodes[2] to retry the shutdown message, which should get a response:
427+
nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &node_0_orig_shutdown);
428+
get_event_msg!(nodes[2], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());
425429

426430
// We test that in case of peer committing upfront to a script, if it doesn't change at closing, we sign
427431
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone());
@@ -668,17 +672,8 @@ fn test_unsupported_anysegwit_shutdown_script() {
668672
node_0_shutdown.scriptpubkey = unsupported_shutdown_script.into_inner();
669673
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_cfgs[1].features, &node_0_shutdown);
670674

671-
let events = nodes[0].node.get_and_clear_pending_msg_events();
672-
assert_eq!(events.len(), 2);
673-
match events[1] {
674-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
675-
assert_eq!(node_id, nodes[1].node.get_our_node_id());
676-
assert_eq!(msg.data, "Got a nonstandard scriptpubkey (60020028) from remote peer".to_owned());
677-
},
678-
_ => panic!("Unexpected event"),
679-
}
680-
check_added_monitors!(nodes[0], 1);
681-
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Got a nonstandard scriptpubkey (60020028) from remote peer".to_string() });
675+
assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2),
676+
"Got a nonstandard scriptpubkey (60020028) from remote peer");
682677
}
683678

684679
#[test]
@@ -704,17 +699,8 @@ fn test_invalid_shutdown_script() {
704699
.into_script();
705700
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
706701

707-
let events = nodes[0].node.get_and_clear_pending_msg_events();
708-
assert_eq!(events.len(), 2);
709-
match events[1] {
710-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
711-
assert_eq!(node_id, nodes[1].node.get_our_node_id());
712-
assert_eq!(msg.data, "Got a nonstandard scriptpubkey (00020000) from remote peer".to_owned())
713-
},
714-
_ => panic!("Unexpected event"),
715-
}
716-
check_added_monitors!(nodes[0], 1);
717-
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Got a nonstandard scriptpubkey (00020000) from remote peer".to_string() });
702+
assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2),
703+
"Got a nonstandard scriptpubkey (00020000) from remote peer");
718704
}
719705

720706
#[derive(PartialEq)]

0 commit comments

Comments
 (0)