@@ -2574,7 +2574,7 @@ mod tests {
2574
2574
( announcement, as_update, bs_update, channel_id, tx)
2575
2575
}
2576
2576
2577
- fn create_chan_between_nodes_with_value_a ( node_a : & Node , node_b : & Node , channel_value : u64 , push_msat : u64 ) -> ( ( msgs :: FundingLocked , msgs :: AnnouncementSignatures ) , [ u8 ; 32 ] , Transaction ) {
2577
+ fn create_chan_between_nodes_with_value_init ( node_a : & Node , node_b : & Node , channel_value : u64 , push_msat : u64 ) -> Transaction {
2578
2578
node_a. node . create_channel ( node_b. node . get_our_node_id ( ) , channel_value, push_msat, 42 ) . unwrap ( ) ;
2579
2579
2580
2580
let events_1 = node_a. node . get_and_clear_pending_events ( ) ;
@@ -2647,7 +2647,11 @@ mod tests {
2647
2647
_ => panic ! ( "Unexpected event" ) ,
2648
2648
} ;
2649
2649
2650
- confirm_transaction ( & node_b. chain_monitor , & tx, chan_id) ;
2650
+ tx
2651
+ }
2652
+
2653
+ fn create_chan_between_nodes_with_value_confirm ( node_a : & Node , node_b : & Node , tx : & Transaction ) -> ( ( msgs:: FundingLocked , msgs:: AnnouncementSignatures ) , [ u8 ; 32 ] ) {
2654
+ confirm_transaction ( & node_b. chain_monitor , & tx, tx. version ) ;
2651
2655
let events_5 = node_b. node . get_and_clear_pending_events ( ) ;
2652
2656
assert_eq ! ( events_5. len( ) , 1 ) ;
2653
2657
match events_5[ 0 ] {
@@ -2661,7 +2665,7 @@ mod tests {
2661
2665
2662
2666
let channel_id;
2663
2667
2664
- confirm_transaction ( & node_a. chain_monitor , & tx, chan_id ) ;
2668
+ confirm_transaction ( & node_a. chain_monitor , & tx, tx . version ) ;
2665
2669
let events_6 = node_a. node . get_and_clear_pending_events ( ) ;
2666
2670
assert_eq ! ( events_6. len( ) , 1 ) ;
2667
2671
( match events_6[ 0 ] {
@@ -2671,7 +2675,13 @@ mod tests {
2671
2675
( msg. clone ( ) , announcement_sigs. clone ( ) . unwrap ( ) )
2672
2676
} ,
2673
2677
_ => panic ! ( "Unexpected event" ) ,
2674
- } , channel_id, tx)
2678
+ } , channel_id)
2679
+ }
2680
+
2681
+ fn create_chan_between_nodes_with_value_a ( node_a : & Node , node_b : & Node , channel_value : u64 , push_msat : u64 ) -> ( ( msgs:: FundingLocked , msgs:: AnnouncementSignatures ) , [ u8 ; 32 ] , Transaction ) {
2682
+ let tx = create_chan_between_nodes_with_value_init ( node_a, node_b, channel_value, push_msat) ;
2683
+ let ( msgs, chan_id) = create_chan_between_nodes_with_value_confirm ( node_a, node_b, & tx) ;
2684
+ ( msgs, chan_id, tx)
2675
2685
}
2676
2686
2677
2687
fn create_chan_between_nodes_with_value_b ( node_a : & Node , node_b : & Node , as_funding_msgs : & ( msgs:: FundingLocked , msgs:: AnnouncementSignatures ) ) -> ( msgs:: ChannelAnnouncement , msgs:: ChannelUpdate , msgs:: ChannelUpdate ) {
@@ -5038,6 +5048,47 @@ mod tests {
5038
5048
do_test_drop_messages_peer_disconnect ( 5 ) ;
5039
5049
}
5040
5050
5051
+ #[ test]
5052
+ fn test_funding_peer_disconnect ( ) {
5053
+ // Test that we can lock in our funding tx while disconnected
5054
+ let nodes = create_network ( 2 ) ;
5055
+ let tx = create_chan_between_nodes_with_value_init ( & nodes[ 0 ] , & nodes[ 1 ] , 100000 , 10001 ) ;
5056
+
5057
+ nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
5058
+ nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
5059
+
5060
+ confirm_transaction ( & nodes[ 0 ] . chain_monitor , & tx, tx. version ) ;
5061
+ let events_1 = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
5062
+ assert_eq ! ( events_1. len( ) , 1 ) ;
5063
+ match events_1[ 0 ] {
5064
+ Event :: SendFundingLocked { ref node_id, msg : _, ref announcement_sigs } => {
5065
+ assert_eq ! ( * node_id, nodes[ 1 ] . node. get_our_node_id( ) ) ;
5066
+ assert ! ( announcement_sigs. is_none( ) ) ;
5067
+ } ,
5068
+ _ => panic ! ( "Unexpected event" ) ,
5069
+ }
5070
+
5071
+ confirm_transaction ( & nodes[ 1 ] . chain_monitor , & tx, tx. version ) ;
5072
+ let events_2 = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
5073
+ assert_eq ! ( events_2. len( ) , 1 ) ;
5074
+ match events_2[ 0 ] {
5075
+ Event :: SendFundingLocked { ref node_id, msg : _, ref announcement_sigs } => {
5076
+ assert_eq ! ( * node_id, nodes[ 0 ] . node. get_our_node_id( ) ) ;
5077
+ assert ! ( announcement_sigs. is_none( ) ) ;
5078
+ } ,
5079
+ _ => panic ! ( "Unexpected event" ) ,
5080
+ }
5081
+
5082
+ reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , true , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
5083
+
5084
+ // TODO: We shouldn't need to manually pass list_usable_chanels here once we support
5085
+ // rebroadcasting announcement_signatures upon reconnect.
5086
+
5087
+ let route = nodes[ 0 ] . router . get_route ( & nodes[ 1 ] . node . get_our_node_id ( ) , Some ( & nodes[ 0 ] . node . list_usable_channels ( ) ) , & Vec :: new ( ) , 1000000 , TEST_FINAL_CLTV ) . unwrap ( ) ;
5088
+ let ( payment_preimage, _) = send_along_route ( & nodes[ 0 ] , route, & [ & nodes[ 1 ] ] , 1000000 ) ;
5089
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage) ;
5090
+ }
5091
+
5041
5092
#[ test]
5042
5093
fn test_invalid_channel_announcement ( ) {
5043
5094
//Test BOLT 7 channel_announcement msg requirement for final node, gather data to build customed channel_announcement msgs
0 commit comments