@@ -7518,24 +7518,20 @@ fn test_upfront_shutdown_script() {
75187518}
75197519
75207520#[test]
7521- fn test_upfront_shutdown_script_unsupport_segwit() {
7522- 	// We test that channel is closed early
7523- 	// if a segwit program is passed as upfront shutdown script,
7524- 	// but the peer does not support segwit.
7521+ fn test_invalid_upfront_shutdown_script() {
75257522	let chanmon_cfgs = create_chanmon_cfgs(2);
75267523	let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
75277524	let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
75287525	let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
75297526
75307527	nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
75317528
7529+ 	// Use a segwit v0 script with an unsupported witness program
75327530	let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
7533- 	open_channel.shutdown_scriptpubkey = Present(Builder::new().push_int(16 )
7531+ 	open_channel.shutdown_scriptpubkey = Present(Builder::new().push_int(0 )
75347532		.push_slice(&[0, 0])
75357533		.into_script());
7536- 
7537- 	let features = InitFeatures::known().clear_shutdown_anysegwit();
7538- 	nodes[0].node.handle_open_channel(&nodes[0].node.get_our_node_id(), features, &open_channel);
7534+ 	nodes[0].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel);
75397535
75407536	let events = nodes[0].node.get_and_clear_pending_msg_events();
75417537	assert_eq!(events.len(), 1);
@@ -7549,7 +7545,7 @@ fn test_upfront_shutdown_script_unsupport_segwit() {
75497545}
75507546
75517547#[test]
7552- fn test_shutdown_script_any_segwit_allowed () {
7548+ fn test_segwit_v0_shutdown_script () {
75537549	let mut config = UserConfig::default();
75547550	config.channel_options.announced_channel = true;
75557551	config.peer_channel_config_limits.force_announced_channel_preference = false;
@@ -7560,14 +7556,16 @@ fn test_shutdown_script_any_segwit_allowed() {
75607556	let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
75617557	let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
75627558
7563- 	//// We test if the remote peer accepts opt_shutdown_anysegwit, a witness program can be used on shutdown
75647559	let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known());
75657560	nodes[1].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap();
7561+ 
7562+ 	// Use a segwit v0 script supported even without opt_shutdown_anysegwit
75667563	let mut node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());
7567- 	node_0_shutdown.scriptpubkey = Builder::new().push_int(16 )
7568- 		.push_slice(&[0, 0 ])
7564+ 	node_0_shutdown.scriptpubkey = Builder::new().push_int(0 )
7565+ 		.push_slice(&[0; 20 ])
75697566		.into_script();
75707567	nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
7568+ 
75717569	let events = nodes[0].node.get_and_clear_pending_msg_events();
75727570	assert_eq!(events.len(), 2);
75737571	match events[0] {
@@ -7581,7 +7579,7 @@ fn test_shutdown_script_any_segwit_allowed() {
75817579}
75827580
75837581#[test]
7584- fn test_shutdown_script_any_segwit_not_allowed () {
7582+ fn test_anysegwit_shutdown_script () {
75857583	let mut config = UserConfig::default();
75867584	config.channel_options.announced_channel = true;
75877585	config.peer_channel_config_limits.force_announced_channel_preference = false;
@@ -7592,30 +7590,30 @@ fn test_shutdown_script_any_segwit_not_allowed() {
75927590	let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
75937591	let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
75947592
7595- 	//// We test that if the remote peer does not accept opt_shutdown_anysegwit, the witness program cannot be used on shutdown
75967593	let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known());
75977594	nodes[1].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap();
7595+ 
7596+ 	// Use a non-v0 segwit script supported by opt_shutdown_anysegwit
75987597	let mut node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());
7599- 	// Make an any segwit version script
76007598	node_0_shutdown.scriptpubkey = Builder::new().push_int(16)
76017599		.push_slice(&[0, 0])
76027600		.into_script();
7603- 	let flags_no =  InitFeatures::known().clear_shutdown_anysegwit( );
7604- 	nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &flags_no, &node_0_shutdown); 
7601+ 	nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), & InitFeatures::known(), &node_0_shutdown );
7602+ 
76057603	let events = nodes[0].node.get_and_clear_pending_msg_events();
76067604	assert_eq!(events.len(), 2);
7605+ 	match events[0] {
7606+ 		MessageSendEvent::SendShutdown { node_id, .. } => { assert_eq!(node_id, nodes[1].node.get_our_node_id()) }
7607+ 		_ => panic!("Unexpected event"),
7608+ 	}
76077609	match events[1] {
7608- 		MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id } => {
7609- 			assert_eq!(node_id, nodes[1].node.get_our_node_id());
7610- 			assert_eq!(msg.data, "Got a nonstandard scriptpubkey (60020000) from remote peer".to_owned())
7611- 		},
7610+ 		MessageSendEvent::SendClosingSigned { node_id, .. } => { assert_eq!(node_id, nodes[1].node.get_our_node_id()) }
76127611		_ => panic!("Unexpected event"),
76137612	}
7614- 	check_added_monitors!(nodes[0], 1);
76157613}
76167614
76177615#[test]
7618- fn test_shutdown_script_segwit_but_not_anysegwit () {
7616+ fn test_invalid_shutdown_script () {
76197617	let mut config = UserConfig::default();
76207618	config.channel_options.announced_channel = true;
76217619	config.peer_channel_config_limits.force_announced_channel_preference = false;
@@ -7626,15 +7624,16 @@ fn test_shutdown_script_segwit_but_not_anysegwit() {
76267624	let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
76277625	let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
76287626
7629- 	//// We test that if shutdown any segwit is supported and we send a witness script with 0 version, this is not accepted
76307627	let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known());
76317628	nodes[1].node.close_channel(&OutPoint { txid: chan.3.txid(), index: 0 }.to_channel_id()).unwrap();
7629+ 
7630+ 	// Use a segwit v0 script with an unsupported witness program
76327631	let mut node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id());
7633- 	// Make a segwit script that is not a valid as any segwit
76347632	node_0_shutdown.scriptpubkey = Builder::new().push_int(0)
76357633		.push_slice(&[0, 0])
76367634		.into_script();
76377635	nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
7636+ 
76387637	let events = nodes[0].node.get_and_clear_pending_msg_events();
76397638	assert_eq!(events.len(), 2);
76407639	match events[1] {
0 commit comments