@@ -7518,24 +7518,20 @@ fn test_upfront_shutdown_script() {
7518
7518
}
7519
7519
7520
7520
#[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() {
7525
7522
let chanmon_cfgs = create_chanmon_cfgs(2);
7526
7523
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
7527
7524
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
7528
7525
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
7529
7526
7530
7527
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
7531
7528
7529
+ // Use a segwit v0 script with an unsupported witness program
7532
7530
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 )
7534
7532
.push_slice(&[0, 0])
7535
7533
.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);
7539
7535
7540
7536
let events = nodes[0].node.get_and_clear_pending_msg_events();
7541
7537
assert_eq!(events.len(), 1);
@@ -7549,7 +7545,7 @@ fn test_upfront_shutdown_script_unsupport_segwit() {
7549
7545
}
7550
7546
7551
7547
#[test]
7552
- fn test_shutdown_script_any_segwit_allowed () {
7548
+ fn test_segwit_v0_shutdown_script () {
7553
7549
let mut config = UserConfig::default();
7554
7550
config.channel_options.announced_channel = true;
7555
7551
config.peer_channel_config_limits.force_announced_channel_preference = false;
@@ -7560,14 +7556,16 @@ fn test_shutdown_script_any_segwit_allowed() {
7560
7556
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
7561
7557
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
7562
7558
7563
- //// We test if the remote peer accepts opt_shutdown_anysegwit, a witness program can be used on shutdown
7564
7559
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known());
7565
7560
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
7566
7563
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 ])
7569
7566
.into_script();
7570
7567
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
7568
+
7571
7569
let events = nodes[0].node.get_and_clear_pending_msg_events();
7572
7570
assert_eq!(events.len(), 2);
7573
7571
match events[0] {
@@ -7581,7 +7579,7 @@ fn test_shutdown_script_any_segwit_allowed() {
7581
7579
}
7582
7580
7583
7581
#[test]
7584
- fn test_shutdown_script_any_segwit_not_allowed () {
7582
+ fn test_anysegwit_shutdown_script () {
7585
7583
let mut config = UserConfig::default();
7586
7584
config.channel_options.announced_channel = true;
7587
7585
config.peer_channel_config_limits.force_announced_channel_preference = false;
@@ -7592,30 +7590,30 @@ fn test_shutdown_script_any_segwit_not_allowed() {
7592
7590
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
7593
7591
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
7594
7592
7595
- //// We test that if the remote peer does not accept opt_shutdown_anysegwit, the witness program cannot be used on shutdown
7596
7593
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known());
7597
7594
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
7598
7597
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
7600
7598
node_0_shutdown.scriptpubkey = Builder::new().push_int(16)
7601
7599
.push_slice(&[0, 0])
7602
7600
.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
+
7605
7603
let events = nodes[0].node.get_and_clear_pending_msg_events();
7606
7604
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
+ }
7607
7609
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()) }
7612
7611
_ => panic!("Unexpected event"),
7613
7612
}
7614
- check_added_monitors!(nodes[0], 1);
7615
7613
}
7616
7614
7617
7615
#[test]
7618
- fn test_shutdown_script_segwit_but_not_anysegwit () {
7616
+ fn test_invalid_shutdown_script () {
7619
7617
let mut config = UserConfig::default();
7620
7618
config.channel_options.announced_channel = true;
7621
7619
config.peer_channel_config_limits.force_announced_channel_preference = false;
@@ -7626,15 +7624,16 @@ fn test_shutdown_script_segwit_but_not_anysegwit() {
7626
7624
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
7627
7625
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
7628
7626
7629
- //// We test that if shutdown any segwit is supported and we send a witness script with 0 version, this is not accepted
7630
7627
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known());
7631
7628
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
7632
7631
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
7634
7632
node_0_shutdown.scriptpubkey = Builder::new().push_int(0)
7635
7633
.push_slice(&[0, 0])
7636
7634
.into_script();
7637
7635
nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &InitFeatures::known(), &node_0_shutdown);
7636
+
7638
7637
let events = nodes[0].node.get_and_clear_pending_msg_events();
7639
7638
assert_eq!(events.len(), 2);
7640
7639
match events[1] {
0 commit comments