@@ -20,6 +20,7 @@ use chain::channelmonitor::ChannelMonitor;
20
20
use chain:: transaction:: OutPoint ;
21
21
use chain:: { ChannelMonitorUpdateErr , Listen , Watch } ;
22
22
use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure } ;
23
+ use ln:: channel:: AnnouncementSigsState ;
23
24
use ln:: features:: InitFeatures ;
24
25
use ln:: msgs;
25
26
use ln:: msgs:: { ChannelMessageHandler , RoutingMessageHandler } ;
@@ -1402,6 +1403,11 @@ fn monitor_failed_no_reestablish_response() {
1402
1403
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1403
1404
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1404
1405
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
+ }
1405
1411
1406
1412
// Route the payment and deliver the initial commitment_signed (with a monitor update failure
1407
1413
// on receipt).
@@ -1789,9 +1795,9 @@ fn monitor_update_claim_fail_no_response() {
1789
1795
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2) ;
1790
1796
}
1791
1797
1792
- // confirm_a_first and restore_b_before_conf are wholly unrelated to earlier bools and
1793
1798
// 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 ) {
1795
1801
// Test that if the monitor update generated by funding_transaction_generated fails we continue
1796
1802
// the channel setup happily after the update is restored.
1797
1803
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:
1833
1839
if confirm_a_first {
1834
1840
confirm_transaction ( & nodes[ 0 ] , & funding_tx) ;
1835
1841
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( ) ) ;
1836
1844
} else {
1837
1845
assert ! ( !restore_b_before_conf) ;
1838
1846
confirm_transaction ( & nodes[ 1 ] , & funding_tx) ;
@@ -1851,20 +1859,32 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
1851
1859
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1852
1860
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
1853
1861
}
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
+ }
1854
1868
1855
1869
chanmon_cfgs[ 1 ] . persister . set_update_ret ( Ok ( ( ) ) ) ;
1856
1870
let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
1857
1871
nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
1858
1872
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1859
1873
1860
1874
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
+ }
1866
1884
} else {
1867
1885
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( ) ) ;
1868
1888
confirm_transaction ( & nodes[ 1 ] , & funding_tx) ;
1869
1889
}
1870
1890
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:
1884
1904
1885
1905
#[ test]
1886
1906
fn 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 ) ;
1890
1911
}
1891
1912
1892
1913
#[ test]
0 commit comments