Skip to content

Commit e944a5f

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 ecbe6a0 commit e944a5f

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
@@ -3494,12 +3494,12 @@ impl<Signer: Sign> Channel<Signer> {
34943494
assert_eq!(self.channel_state & ChannelState::ShutdownComplete as u32, 0);
34953495

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

35003500
if self.counterparty_shutdown_scriptpubkey.is_some() {
35013501
if Some(&msg.scriptpubkey) != self.counterparty_shutdown_scriptpubkey.as_ref() {
3502-
return Err(ChannelError::Close(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_bytes().to_hex())));
3502+
return Err(ChannelError::Warn(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_bytes().to_hex())));
35033503
}
35043504
} else {
35053505
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
@@ -438,13 +438,17 @@ fn test_upfront_shutdown_script() {
438438
let flags = InitFeatures::known();
439439
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone());
440440
nodes[0].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap();
441-
let mut node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id());
441+
let node_0_orig_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id());
442+
let mut node_0_shutdown = node_0_orig_shutdown.clone();
442443
node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh();
443-
// Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we disconnect peer
444+
// Test we enforce upfront_scriptpbukey if by providing a diffrent one at closing that we warn
445+
// the peer and ignore the message.
444446
nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
445-
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()));
446-
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() });
447-
check_added_monitors!(nodes[2], 1);
447+
assert!(regex::Regex::new(r"Got shutdown request with a scriptpubkey \([A-Fa-f0-9]+\) which did not match their previous scriptpubkey.")
448+
.unwrap().is_match(&check_warn_msg!(nodes[2], nodes[0].node.get_our_node_id(), chan.2)));
449+
// This allows nodes[2] to retry the shutdown message, which should get a response:
450+
nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &InitFeatures::known(), &node_0_orig_shutdown);
451+
get_event_msg!(nodes[2], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());
448452

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

694-
let events = nodes[0].node.get_and_clear_pending_msg_events();
695-
assert_eq!(events.len(), 2);
696-
match events[1] {
697-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
698-
assert_eq!(node_id, nodes[1].node.get_our_node_id());
699-
assert_eq!(msg.data, "Got a nonstandard scriptpubkey (60020028) from remote peer".to_owned());
700-
},
701-
_ => panic!("Unexpected event"),
702-
}
703-
check_added_monitors!(nodes[0], 1);
704-
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Got a nonstandard scriptpubkey (60020028) from remote peer".to_string() });
698+
assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2),
699+
"Got a nonstandard scriptpubkey (60020028) from remote peer");
705700
}
706701

707702
#[test]
@@ -727,17 +722,8 @@ fn test_invalid_shutdown_script() {
727722
.into_script();
728723
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
729724

730-
let events = nodes[0].node.get_and_clear_pending_msg_events();
731-
assert_eq!(events.len(), 2);
732-
match events[1] {
733-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
734-
assert_eq!(node_id, nodes[1].node.get_our_node_id());
735-
assert_eq!(msg.data, "Got a nonstandard scriptpubkey (00020000) from remote peer".to_owned())
736-
},
737-
_ => panic!("Unexpected event"),
738-
}
739-
check_added_monitors!(nodes[0], 1);
740-
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Got a nonstandard scriptpubkey (00020000) from remote peer".to_string() });
725+
assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2),
726+
"Got a nonstandard scriptpubkey (00020000) from remote peer");
741727
}
742728

743729
#[derive(PartialEq)]

0 commit comments

Comments
 (0)