@@ -3605,15 +3605,20 @@ fn test_simple_peer_disconnect() {
3605
3605
fail_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) , payment_hash_6) ;
3606
3606
}
3607
3607
3608
- fn do_test_drop_messages_peer_disconnect ( messages_delivered : u8 ) {
3608
+ fn do_test_drop_messages_peer_disconnect ( messages_delivered : u8 , simulate_broken_lnd : bool ) {
3609
3609
// Test that we can reconnect when in-flight HTLC updates get dropped
3610
3610
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3611
3611
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
3612
3612
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
3613
3613
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3614
+
3615
+ let mut as_funding_locked = None ;
3614
3616
if messages_delivered == 0 {
3615
- create_chan_between_nodes_with_value_a ( & nodes[ 0 ] , & nodes[ 1 ] , 100000 , 10001 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
3617
+ let ( funding_locked, _, _) = create_chan_between_nodes_with_value_a ( & nodes[ 0 ] , & nodes[ 1 ] , 100000 , 10001 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
3618
+ as_funding_locked = Some ( funding_locked) ;
3616
3619
// nodes[1] doesn't receive the funding_locked message (it'll be re-sent on reconnect)
3620
+ // Note that we store it so that if we're running with `simulate_broken_lnd` we can deliver
3621
+ // it before the channel_reestablish message.
3617
3622
} else {
3618
3623
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
3619
3624
}
@@ -3668,6 +3673,17 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
3668
3673
nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
3669
3674
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
3670
3675
if messages_delivered < 3 {
3676
+ if simulate_broken_lnd {
3677
+ // lnd has a long-standing bug where they send a funding_locked prior to a
3678
+ // channel_reestablish if you reconnect prior to funding_locked time.
3679
+ //
3680
+ // Here we simulate that behavior, delivering a funding_locked immediately on
3681
+ // reconnect. Note that we don't bother skipping the now-duplicate funding_locked sent
3682
+ // in `reconnect_nodes` but we currently don't fail based on that.
3683
+ //
3684
+ // See-also <https://github.com/lightningnetwork/lnd/issues/4006>
3685
+ nodes[ 1 ] . node . handle_funding_locked ( & nodes[ 0 ] . node . get_our_node_id ( ) , & as_funding_locked. as_ref ( ) . unwrap ( ) . 0 ) ;
3686
+ }
3671
3687
// Even if the funding_locked messages get exchanged, as long as nothing further was
3672
3688
// received on either side, both sides will need to resend them.
3673
3689
reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , ( true , true ) , ( 0 , 1 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
@@ -3811,17 +3827,18 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
3811
3827
3812
3828
#[ test]
3813
3829
fn test_drop_messages_peer_disconnect_a ( ) {
3814
- do_test_drop_messages_peer_disconnect ( 0 ) ;
3815
- do_test_drop_messages_peer_disconnect ( 1 ) ;
3816
- do_test_drop_messages_peer_disconnect ( 2 ) ;
3817
- do_test_drop_messages_peer_disconnect ( 3 ) ;
3830
+ do_test_drop_messages_peer_disconnect ( 0 , true ) ;
3831
+ do_test_drop_messages_peer_disconnect ( 0 , false ) ;
3832
+ do_test_drop_messages_peer_disconnect ( 1 , false ) ;
3833
+ do_test_drop_messages_peer_disconnect ( 2 , false ) ;
3818
3834
}
3819
3835
3820
3836
#[ test]
3821
3837
fn test_drop_messages_peer_disconnect_b ( ) {
3822
- do_test_drop_messages_peer_disconnect ( 4 ) ;
3823
- do_test_drop_messages_peer_disconnect ( 5 ) ;
3824
- do_test_drop_messages_peer_disconnect ( 6 ) ;
3838
+ do_test_drop_messages_peer_disconnect ( 3 , false ) ;
3839
+ do_test_drop_messages_peer_disconnect ( 4 , false ) ;
3840
+ do_test_drop_messages_peer_disconnect ( 5 , false ) ;
3841
+ do_test_drop_messages_peer_disconnect ( 6 , false ) ;
3825
3842
}
3826
3843
3827
3844
#[ test]
0 commit comments