@@ -7474,24 +7474,20 @@ fn test_upfront_shutdown_script() {
7474
7474
}
7475
7475
7476
7476
#[ test]
7477
- fn test_upfront_shutdown_script_unsupport_segwit ( ) {
7478
- // We test that channel is closed early
7479
- // if a segwit program is passed as upfront shutdown script,
7480
- // but the peer does not support segwit.
7477
+ fn test_invalid_upfront_shutdown_script ( ) {
7481
7478
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
7482
7479
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
7483
7480
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
7484
7481
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
7485
7482
7486
7483
nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 100000 , 10001 , 42 , None ) . unwrap ( ) ;
7487
7484
7485
+ // Use a segwit v0 script with an unsupported witness program
7488
7486
let mut open_channel = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
7489
- open_channel. shutdown_scriptpubkey = Present ( Builder :: new ( ) . push_int ( 16 )
7487
+ open_channel. shutdown_scriptpubkey = Present ( Builder :: new ( ) . push_int ( 0 )
7490
7488
. push_slice ( & [ 0 , 0 ] )
7491
7489
. into_script ( ) ) ;
7492
-
7493
- let features = InitFeatures :: known ( ) . clear_shutdown_anysegwit ( ) ;
7494
- nodes[ 0 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , features, & open_channel) ;
7490
+ nodes[ 0 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , InitFeatures :: known ( ) , & open_channel) ;
7495
7491
7496
7492
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7497
7493
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7505,7 +7501,7 @@ fn test_upfront_shutdown_script_unsupport_segwit() {
7505
7501
}
7506
7502
7507
7503
#[ test]
7508
- fn test_shutdown_script_any_segwit_allowed ( ) {
7504
+ fn test_segwit_v0_shutdown_script ( ) {
7509
7505
let mut config = UserConfig :: default ( ) ;
7510
7506
config. channel_options . announced_channel = true ;
7511
7507
config. peer_channel_config_limits . force_announced_channel_preference = false ;
@@ -7516,14 +7512,16 @@ fn test_shutdown_script_any_segwit_allowed() {
7516
7512
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & user_cfgs) ;
7517
7513
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
7518
7514
7519
- //// We test if the remote peer accepts opt_shutdown_anysegwit, a witness program can be used on shutdown
7520
7515
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1000000 , 1000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
7521
7516
nodes[ 1 ] . node . close_channel ( & OutPoint { txid : chan. 3 . txid ( ) , index : 0 } . to_channel_id ( ) ) . unwrap ( ) ;
7517
+
7518
+ // Use a segwit v0 script supported even without opt_shutdown_anysegwit
7522
7519
let mut node_0_shutdown = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendShutdown , nodes[ 0 ] . node. get_our_node_id( ) ) ;
7523
- node_0_shutdown. scriptpubkey = Builder :: new ( ) . push_int ( 16 )
7524
- . push_slice ( & [ 0 , 0 ] )
7520
+ node_0_shutdown. scriptpubkey = Builder :: new ( ) . push_int ( 0 )
7521
+ . push_slice ( & [ 0 ; 20 ] )
7525
7522
. into_script ( ) ;
7526
7523
nodes[ 0 ] . node . handle_shutdown ( & nodes[ 1 ] . node . get_our_node_id ( ) , & InitFeatures :: known ( ) , & node_0_shutdown) ;
7524
+
7527
7525
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7528
7526
assert_eq ! ( events. len( ) , 2 ) ;
7529
7527
match events[ 0 ] {
@@ -7537,7 +7535,7 @@ fn test_shutdown_script_any_segwit_allowed() {
7537
7535
}
7538
7536
7539
7537
#[ test]
7540
- fn test_shutdown_script_any_segwit_not_allowed ( ) {
7538
+ fn test_anysegwit_shutdown_script ( ) {
7541
7539
let mut config = UserConfig :: default ( ) ;
7542
7540
config. channel_options . announced_channel = true ;
7543
7541
config. peer_channel_config_limits . force_announced_channel_preference = false ;
@@ -7548,30 +7546,30 @@ fn test_shutdown_script_any_segwit_not_allowed() {
7548
7546
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & user_cfgs) ;
7549
7547
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
7550
7548
7551
- //// We test that if the remote peer does not accept opt_shutdown_anysegwit, the witness program cannot be used on shutdown
7552
7549
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1000000 , 1000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
7553
7550
nodes[ 1 ] . node . close_channel ( & OutPoint { txid : chan. 3 . txid ( ) , index : 0 } . to_channel_id ( ) ) . unwrap ( ) ;
7551
+
7552
+ // Use a non-v0 segwit script supported by opt_shutdown_anysegwit
7554
7553
let mut node_0_shutdown = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendShutdown , nodes[ 0 ] . node. get_our_node_id( ) ) ;
7555
- // Make an any segwit version script
7556
7554
node_0_shutdown. scriptpubkey = Builder :: new ( ) . push_int ( 16 )
7557
7555
. push_slice ( & [ 0 , 0 ] )
7558
7556
. into_script ( ) ;
7559
- let flags_no = InitFeatures :: known ( ) . clear_shutdown_anysegwit ( ) ;
7560
- nodes [ 0 ] . node . handle_shutdown ( & nodes [ 1 ] . node . get_our_node_id ( ) , & flags_no , & node_0_shutdown ) ;
7557
+ nodes [ 0 ] . node . handle_shutdown ( & nodes [ 1 ] . node . get_our_node_id ( ) , & InitFeatures :: known ( ) , & node_0_shutdown ) ;
7558
+
7561
7559
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7562
7560
assert_eq ! ( events. len( ) , 2 ) ;
7561
+ match events[ 0 ] {
7562
+ MessageSendEvent :: SendShutdown { node_id, .. } => { assert_eq ! ( node_id, nodes[ 1 ] . node. get_our_node_id( ) ) }
7563
+ _ => panic ! ( "Unexpected event" ) ,
7564
+ }
7563
7565
match events[ 1 ] {
7564
- MessageSendEvent :: HandleError { action : ErrorAction :: SendErrorMessage { ref msg } , node_id } => {
7565
- assert_eq ! ( node_id, nodes[ 1 ] . node. get_our_node_id( ) ) ;
7566
- assert_eq ! ( msg. data, "Got a nonstandard scriptpubkey (60020000) from remote peer" . to_owned( ) )
7567
- } ,
7566
+ MessageSendEvent :: SendClosingSigned { node_id, .. } => { assert_eq ! ( node_id, nodes[ 1 ] . node. get_our_node_id( ) ) }
7568
7567
_ => panic ! ( "Unexpected event" ) ,
7569
7568
}
7570
- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7571
7569
}
7572
7570
7573
7571
#[ test]
7574
- fn test_shutdown_script_segwit_but_not_anysegwit ( ) {
7572
+ fn test_invalid_shutdown_script ( ) {
7575
7573
let mut config = UserConfig :: default ( ) ;
7576
7574
config. channel_options . announced_channel = true ;
7577
7575
config. peer_channel_config_limits . force_announced_channel_preference = false ;
@@ -7582,15 +7580,16 @@ fn test_shutdown_script_segwit_but_not_anysegwit() {
7582
7580
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & user_cfgs) ;
7583
7581
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
7584
7582
7585
- //// We test that if shutdown any segwit is supported and we send a witness script with 0 version, this is not accepted
7586
7583
let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1000000 , 1000000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
7587
7584
nodes[ 1 ] . node . close_channel ( & OutPoint { txid : chan. 3 . txid ( ) , index : 0 } . to_channel_id ( ) ) . unwrap ( ) ;
7585
+
7586
+ // Use a segwit v0 script with an unsupported witness program
7588
7587
let mut node_0_shutdown = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendShutdown , nodes[ 0 ] . node. get_our_node_id( ) ) ;
7589
- // Make a segwit script that is not a valid as any segwit
7590
7588
node_0_shutdown. scriptpubkey = Builder :: new ( ) . push_int ( 0 )
7591
7589
. push_slice ( & [ 0 , 0 ] )
7592
7590
. into_script ( ) ;
7593
7591
nodes[ 0 ] . node . handle_shutdown ( & nodes[ 1 ] . node . get_our_node_id ( ) , & InitFeatures :: known ( ) , & node_0_shutdown) ;
7592
+
7594
7593
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7595
7594
assert_eq ! ( events. len( ) , 2 ) ;
7596
7595
match events[ 1 ] {
0 commit comments