@@ -3605,15 +3605,20 @@ fn test_simple_peer_disconnect() {
36053605 fail_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) , payment_hash_6) ;
36063606}
36073607
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 ) {
36093609 // Test that we can reconnect when in-flight HTLC updates get dropped
36103610 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
36113611 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
36123612 let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
36133613 let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3614+
3615+ let mut as_funding_locked = None ;
36143616 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) ;
36163619 // 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.
36173622 } else {
36183623 create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
36193624 }
@@ -3668,6 +3673,17 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) {
36683673 nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
36693674 nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
36703675 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+ }
36713687 // Even if the funding_locked messages get exchanged, as long as nothing further was
36723688 // received on either side, both sides will need to resend them.
36733689 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) {
38113827
38123828#[ test]
38133829fn 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 ) ;
38183834}
38193835
38203836#[ test]
38213837fn 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 ) ;
38253842}
38263843
38273844#[ test]
0 commit comments