@@ -548,3 +548,112 @@ fn test_quiescence_timeout_while_waiting_for_counterparty_stfu() {
548
548
} ;
549
549
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . iter( ) . find_map( f) . is_some( ) ) ;
550
550
}
551
+
552
+ fn do_test_quiescence_during_disconnection ( with_pending_claim : bool , propose_disconnected : bool ) {
553
+ // Test that we'll start trying for quiescence immediately after reconnection if we're waiting
554
+ // to do some quiescence-required action.
555
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
556
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
557
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
558
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
559
+ let chan_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 2 ;
560
+
561
+ let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
562
+ let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
563
+
564
+ // First get both nodes off the starting state so we don't have to deal with channel_ready
565
+ // retransmissions on reconect.
566
+ send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100_000 ) ;
567
+
568
+ let ( preimage, payment_hash, ..) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100_000 ) ;
569
+ if with_pending_claim {
570
+ // Optionally reconnect with pending quiescence while there's some pending messages to
571
+ // deliver.
572
+ nodes[ 1 ] . node . claim_funds ( preimage) ;
573
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
574
+ expect_payment_claimed ! ( nodes[ 1 ] , payment_hash, 100_000 ) ;
575
+ let _ = get_htlc_update_msgs ( & nodes[ 1 ] , & node_a_id) ;
576
+ }
577
+
578
+ if !propose_disconnected {
579
+ nodes[ 1 ] . node . maybe_propose_quiescence ( & node_a_id, & chan_id) . unwrap ( ) ;
580
+ }
581
+
582
+ nodes[ 0 ] . node . peer_disconnected ( node_b_id) ;
583
+ nodes[ 1 ] . node . peer_disconnected ( node_a_id) ;
584
+
585
+ if propose_disconnected {
586
+ nodes[ 1 ] . node . maybe_propose_quiescence ( & node_a_id, & chan_id) . unwrap ( ) ;
587
+ }
588
+
589
+ let init_msg = msgs:: Init {
590
+ features : nodes[ 1 ] . node . init_features ( ) ,
591
+ networks : None ,
592
+ remote_network_address : None ,
593
+ } ;
594
+ nodes[ 0 ] . node . peer_connected ( node_b_id, & init_msg, true ) . unwrap ( ) ;
595
+ nodes[ 1 ] . node . peer_connected ( node_a_id, & init_msg, true ) . unwrap ( ) ;
596
+
597
+ let reestab_a = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendChannelReestablish , node_b_id) ;
598
+ let reestab_b = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendChannelReestablish , node_a_id) ;
599
+
600
+ nodes[ 0 ] . node . handle_channel_reestablish ( node_b_id, & reestab_b) ;
601
+ get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendChannelUpdate , node_b_id) ;
602
+
603
+ nodes[ 1 ] . node . handle_channel_reestablish ( node_a_id, & reestab_a) ;
604
+ let mut bs_msgs = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
605
+ bs_msgs. retain ( |msg| !matches ! ( msg, MessageSendEvent :: SendChannelUpdate { .. } ) ) ;
606
+ assert_eq ! ( bs_msgs. len( ) , 1 , "{bs_msgs:?}" ) ;
607
+ let stfu = if with_pending_claim {
608
+ // Node B should first re-send its channel update, then try to enter quiescence once that
609
+ // completes...
610
+ let msg = bs_msgs. pop ( ) . unwrap ( ) ;
611
+ if let MessageSendEvent :: UpdateHTLCs { mut updates, .. } = msg {
612
+ let fulfill = updates. update_fulfill_htlcs . pop ( ) . unwrap ( ) ;
613
+ nodes[ 0 ] . node . handle_update_fulfill_htlc ( node_b_id, fulfill) ;
614
+ let cs = updates. commitment_signed ;
615
+ nodes[ 0 ] . node . handle_commitment_signed_batch_test ( node_b_id, & cs) ;
616
+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
617
+
618
+ let ( raa, cs) = get_revoke_commit_msgs ( & nodes[ 0 ] , & node_b_id) ;
619
+ nodes[ 1 ] . node . handle_revoke_and_ack ( node_a_id, & raa) ;
620
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
621
+ nodes[ 1 ] . node . handle_commitment_signed_batch_test ( node_a_id, & cs) ;
622
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
623
+
624
+ let mut bs_raa_stfu = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
625
+ assert_eq ! ( bs_raa_stfu. len( ) , 2 ) ;
626
+ if let MessageSendEvent :: SendRevokeAndACK { msg, .. } = & bs_raa_stfu[ 0 ] {
627
+ nodes[ 0 ] . node . handle_revoke_and_ack ( node_b_id, & msg) ;
628
+ expect_payment_sent ! ( & nodes[ 0 ] , preimage) ;
629
+ } else {
630
+ panic ! ( "Unexpected first message {bs_raa_stfu:?}" ) ;
631
+ }
632
+
633
+ bs_raa_stfu. pop ( ) . unwrap ( )
634
+ } else {
635
+ panic ! ( "Unexpected message {msg:?}" ) ;
636
+ }
637
+ } else {
638
+ bs_msgs. pop ( ) . unwrap ( )
639
+ } ;
640
+ if let MessageSendEvent :: SendStfu { msg, .. } = stfu {
641
+ nodes[ 0 ] . node . handle_stfu ( node_b_id, & msg) ;
642
+ } else {
643
+ panic ! ( "Unexpected message {stfu:?}" ) ;
644
+ }
645
+
646
+ let stfu_resp = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendStfu , node_b_id) ;
647
+ nodes[ 1 ] . node . handle_stfu ( node_a_id, & stfu_resp) ;
648
+
649
+ assert ! ( nodes[ 0 ] . node. exit_quiescence( & node_b_id, & chan_id) . unwrap( ) ) ;
650
+ assert ! ( nodes[ 1 ] . node. exit_quiescence( & node_a_id, & chan_id) . unwrap( ) ) ;
651
+ }
652
+
653
+ #[ test]
654
+ fn test_quiescence_during_disconnection ( ) {
655
+ do_test_quiescence_during_disconnection ( false , false ) ;
656
+ do_test_quiescence_during_disconnection ( true , false ) ;
657
+ do_test_quiescence_during_disconnection ( false , true ) ;
658
+ do_test_quiescence_during_disconnection ( true , true ) ;
659
+ }
0 commit comments