@@ -727,7 +727,14 @@ fn test_invalid_shutdown_script() {
727
727
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
728
728
}
729
729
730
- fn do_test_closing_signed_reinit_timeout ( timeout_step : u8 ) {
730
+ #[ derive( PartialEq ) ]
731
+ enum TimeoutStep {
732
+ AfterShutdown ,
733
+ AfterClosingSigned ,
734
+ NoTimeout ,
735
+ }
736
+
737
+ fn do_test_closing_signed_reinit_timeout ( timeout_step : TimeoutStep ) {
731
738
// The range-based closing signed negotiation allows the funder to restart the process with a
732
739
// new range if the previous range did not overlap. This allows implementations to request user
733
740
// intervention allowing users to enter a new fee range. We do not implement the sending side
@@ -759,9 +766,11 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: u8) {
759
766
}
760
767
761
768
let mut node_0_closing_signed = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendClosingSigned , nodes[ 1 ] . node. get_our_node_id( ) ) ;
769
+ // nodes[0] should use a "reasonable" feerate, well under the 10 sat/vByte that nodes[1] thinks
770
+ // is the current prevailing feerate.
762
771
assert ! ( node_0_closing_signed. fee_satoshis <= 500 ) ;
763
772
764
- if timeout_step != 0 {
773
+ if timeout_step != TimeoutStep :: AfterShutdown {
765
774
nodes[ 1 ] . node . handle_closing_signed ( & nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_closing_signed) ;
766
775
// At this point nodes[1] should send back a warning message indicating it disagrees with the
767
776
// given channel-closing fee. Currently we do not implement warning messages so instead we
@@ -779,12 +788,12 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: u8) {
779
788
let node_1_closing_signed = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendClosingSigned , nodes[ 0 ] . node. get_our_node_id( ) ) ;
780
789
nodes[ 0 ] . node . handle_closing_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & node_1_closing_signed) ;
781
790
let node_0_2nd_closing_signed = get_closing_signed_broadcast ! ( nodes[ 0 ] . node, nodes[ 1 ] . node. get_our_node_id( ) ) ;
782
- if timeout_step > 1 {
791
+ if timeout_step == TimeoutStep :: NoTimeout {
783
792
nodes[ 1 ] . node . handle_closing_signed ( & nodes[ 0 ] . node . get_our_node_id ( ) , & node_0_2nd_closing_signed. 1 . unwrap ( ) ) ;
784
793
}
785
794
}
786
795
787
- if timeout_step <= 1 {
796
+ if timeout_step != TimeoutStep :: NoTimeout {
788
797
assert ! ( nodes[ 1 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . is_empty( ) ) ;
789
798
} else {
790
799
assert_eq ! ( nodes[ 1 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . len( ) , 1 ) ;
@@ -797,17 +806,16 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: u8) {
797
806
assert_eq ! ( txn. len( ) , 1 ) ;
798
807
assert_eq ! ( txn[ 0 ] . output. len( ) , 2 ) ;
799
808
800
- // If we timed out we should have a P2WPKH and P2WSH output, otherwise both should be P2WPKH.
801
- if timeout_step <= 1 {
802
- assert ! ( ( txn[ 0 ] . output[ 0 ] . script_pubkey. len( ) == 20 +1 +1 &&
803
- txn[ 0 ] . output[ 1 ] . script_pubkey. len( ) == 32 +1 +1 ) ||
804
- ( txn[ 0 ] . output[ 1 ] . script_pubkey. len( ) == 20 +1 +1 &&
805
- txn[ 0 ] . output[ 0 ] . script_pubkey. len( ) == 32 +1 +1 ) ) ;
809
+ if timeout_step != TimeoutStep :: NoTimeout {
810
+ assert ! ( ( txn[ 0 ] . output[ 0 ] . script_pubkey. is_v0_p2wpkh( ) &&
811
+ txn[ 0 ] . output[ 1 ] . script_pubkey. is_v0_p2wsh( ) ) ||
812
+ ( txn[ 0 ] . output[ 1 ] . script_pubkey. is_v0_p2wpkh( ) &&
813
+ txn[ 0 ] . output[ 0 ] . script_pubkey. is_v0_p2wsh( ) ) ) ;
806
814
check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
807
815
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
808
816
} else {
809
- assert_eq ! ( txn[ 0 ] . output[ 0 ] . script_pubkey. len ( ) , 20 + 1 + 1 ) ;
810
- assert_eq ! ( txn[ 0 ] . output[ 1 ] . script_pubkey. len ( ) , 20 + 1 + 1 ) ;
817
+ assert ! ( txn[ 0 ] . output[ 0 ] . script_pubkey. is_v0_p2wpkh ( ) ) ;
818
+ assert ! ( txn[ 0 ] . output[ 1 ] . script_pubkey. is_v0_p2wpkh ( ) ) ;
811
819
812
820
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
813
821
assert_eq ! ( events. len( ) , 1 ) ;
@@ -822,7 +830,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: u8) {
822
830
823
831
#[ test]
824
832
fn test_closing_signed_reinit_timeout ( ) {
825
- do_test_closing_signed_reinit_timeout ( 0 ) ;
826
- do_test_closing_signed_reinit_timeout ( 1 ) ;
827
- do_test_closing_signed_reinit_timeout ( 2 ) ;
833
+ do_test_closing_signed_reinit_timeout ( TimeoutStep :: AfterShutdown ) ;
834
+ do_test_closing_signed_reinit_timeout ( TimeoutStep :: AfterClosingSigned ) ;
835
+ do_test_closing_signed_reinit_timeout ( TimeoutStep :: NoTimeout ) ;
828
836
}
0 commit comments