@@ -20,6 +20,7 @@ use chain::channelmonitor::ChannelMonitor;
2020use chain:: transaction:: OutPoint ;
2121use chain:: { ChannelMonitorUpdateErr , Listen , Watch } ;
2222use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure } ;
23+ use ln:: channel:: AnnouncementSigsState ;
2324use ln:: features:: InitFeatures ;
2425use ln:: msgs;
2526use ln:: msgs:: { ChannelMessageHandler , RoutingMessageHandler } ;
@@ -1402,6 +1403,11 @@ fn monitor_failed_no_reestablish_response() {
14021403 let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
14031404 let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
14041405 let channel_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
1406+ {
1407+ let mut lock;
1408+ get_channel_ref ! ( nodes[ 0 ] , lock, channel_id) . announcement_sigs_state = AnnouncementSigsState :: PeerReceived ;
1409+ get_channel_ref ! ( nodes[ 1 ] , lock, channel_id) . announcement_sigs_state = AnnouncementSigsState :: PeerReceived ;
1410+ }
14051411
14061412 // Route the payment and deliver the initial commitment_signed (with a monitor update failure
14071413 // on receipt).
@@ -1789,9 +1795,9 @@ fn monitor_update_claim_fail_no_response() {
17891795 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2) ;
17901796}
17911797
1792- // confirm_a_first and restore_b_before_conf are wholly unrelated to earlier bools and
17931798// restore_b_before_conf has no meaning if !confirm_a_first
1794- fn do_during_funding_monitor_fail ( confirm_a_first : bool , restore_b_before_conf : bool ) {
1799+ // restore_b_before_lock has no meaning if confirm_a_first
1800+ fn do_during_funding_monitor_fail ( confirm_a_first : bool , restore_b_before_conf : bool , restore_b_before_lock : bool ) {
17951801 // Test that if the monitor update generated by funding_transaction_generated fails we continue
17961802 // the channel setup happily after the update is restored.
17971803 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
@@ -1833,6 +1839,8 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18331839 if confirm_a_first {
18341840 confirm_transaction ( & nodes[ 0 ] , & funding_tx) ;
18351841 nodes[ 1 ] . node . handle_funding_locked ( & nodes[ 0 ] . node . get_our_node_id ( ) , & get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendFundingLocked , nodes[ 1 ] . node. get_our_node_id( ) ) ) ;
1842+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1843+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
18361844 } else {
18371845 assert ! ( !restore_b_before_conf) ;
18381846 confirm_transaction ( & nodes[ 1 ] , & funding_tx) ;
@@ -1851,20 +1859,32 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18511859 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
18521860 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
18531861 }
1862+ if !confirm_a_first && !restore_b_before_lock {
1863+ confirm_transaction ( & nodes[ 0 ] , & funding_tx) ;
1864+ nodes[ 1 ] . node . handle_funding_locked ( & nodes[ 0 ] . node . get_our_node_id ( ) , & get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendFundingLocked , nodes[ 1 ] . node. get_our_node_id( ) ) ) ;
1865+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1866+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
1867+ }
18541868
18551869 chanmon_cfgs[ 1 ] . persister . set_update_ret ( Ok ( ( ) ) ) ;
18561870 let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
18571871 nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
18581872 check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
18591873
18601874 let ( channel_id, ( announcement, as_update, bs_update) ) = if !confirm_a_first {
1861- nodes[ 0 ] . node . handle_funding_locked ( & nodes[ 1 ] . node . get_our_node_id ( ) , & get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendFundingLocked , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
1862-
1863- confirm_transaction ( & nodes[ 0 ] , & funding_tx) ;
1864- let ( funding_locked, channel_id) = create_chan_between_nodes_with_value_confirm_second ( & nodes[ 1 ] , & nodes[ 0 ] ) ;
1865- ( channel_id, create_chan_between_nodes_with_value_b ( & nodes[ 0 ] , & nodes[ 1 ] , & funding_locked) )
1875+ if !restore_b_before_lock {
1876+ let ( funding_locked, channel_id) = create_chan_between_nodes_with_value_confirm_second ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
1877+ ( channel_id, create_chan_between_nodes_with_value_b ( & nodes[ 1 ] , & nodes[ 0 ] , & funding_locked) )
1878+ } else {
1879+ nodes[ 0 ] . node . handle_funding_locked ( & nodes[ 1 ] . node . get_our_node_id ( ) , & get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendFundingLocked , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
1880+ confirm_transaction ( & nodes[ 0 ] , & funding_tx) ;
1881+ let ( funding_locked, channel_id) = create_chan_between_nodes_with_value_confirm_second ( & nodes[ 1 ] , & nodes[ 0 ] ) ;
1882+ ( channel_id, create_chan_between_nodes_with_value_b ( & nodes[ 0 ] , & nodes[ 1 ] , & funding_locked) )
1883+ }
18661884 } else {
18671885 if restore_b_before_conf {
1886+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1887+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
18681888 confirm_transaction ( & nodes[ 1 ] , & funding_tx) ;
18691889 }
18701890 let ( funding_locked, channel_id) = create_chan_between_nodes_with_value_confirm_second ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
@@ -1884,9 +1904,10 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18841904
18851905#[ test]
18861906fn during_funding_monitor_fail ( ) {
1887- do_during_funding_monitor_fail ( true , true ) ;
1888- do_during_funding_monitor_fail ( true , false ) ;
1889- do_during_funding_monitor_fail ( false , false ) ;
1907+ do_during_funding_monitor_fail ( true , true , false ) ;
1908+ do_during_funding_monitor_fail ( true , false , false ) ;
1909+ do_during_funding_monitor_fail ( false , false , false ) ;
1910+ do_during_funding_monitor_fail ( false , false , true ) ;
18901911}
18911912
18921913#[ test]
0 commit comments