@@ -143,7 +143,7 @@ fn test_monitor_and_persister_update_fail() {
143
143
let mut node_0_per_peer_lock;
144
144
let mut node_0_peer_state_lock;
145
145
let mut channel = get_channel_ref ! ( nodes[ 0 ] , nodes[ 1 ] , node_0_per_peer_lock, node_0_peer_state_lock, chan. 2 ) ;
146
- if let Ok ( ( _ , _ , update) ) = channel. commitment_signed ( & updates. commitment_signed , & node_cfgs[ 0 ] . logger ) {
146
+ if let Ok ( update) = channel. commitment_signed ( & updates. commitment_signed , & node_cfgs[ 0 ] . logger ) {
147
147
// Check that even though the persister is returning a InProgress,
148
148
// because the update is bogus, ultimately the error that's returned
149
149
// should be a PermanentFailure.
@@ -1602,7 +1602,6 @@ fn test_monitor_update_fail_claim() {
1602
1602
1603
1603
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
1604
1604
nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
1605
- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
1606
1605
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1607
1606
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1608
1607
@@ -1628,6 +1627,7 @@ fn test_monitor_update_fail_claim() {
1628
1627
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
1629
1628
assert_eq ! ( events. len( ) , 0 ) ;
1630
1629
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 2 ] , payment_event. commitment_msg, false , true ) ;
1630
+ expect_pending_htlcs_forwardable_ignore ! ( nodes[ 1 ] ) ;
1631
1631
1632
1632
let ( _, payment_hash_3, payment_secret_3) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
1633
1633
nodes[ 2 ] . node . send_payment ( & route, payment_hash_3, & Some ( payment_secret_3) , PaymentId ( payment_hash_3. 0 ) ) . unwrap ( ) ;
@@ -1645,6 +1645,7 @@ fn test_monitor_update_fail_claim() {
1645
1645
let channel_id = chan_1. 2 ;
1646
1646
let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
1647
1647
nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
1648
+ expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
1648
1649
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1649
1650
1650
1651
let bs_fulfill_update = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
@@ -1653,7 +1654,7 @@ fn test_monitor_update_fail_claim() {
1653
1654
expect_payment_sent ! ( nodes[ 0 ] , payment_preimage_1) ;
1654
1655
1655
1656
// Get the payment forwards, note that they were batched into one commitment update.
1656
- expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
1657
+ nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
1657
1658
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1658
1659
let bs_forward_update = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1659
1660
nodes[ 0 ] . node . handle_update_add_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_forward_update. update_add_htlcs [ 0 ] ) ;
@@ -1739,7 +1740,6 @@ fn test_monitor_update_on_pending_forwards() {
1739
1740
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
1740
1741
expect_pending_htlcs_forwardable_and_htlc_handling_failed ! ( nodes[ 1 ] , vec![ HTLCDestination :: NextHopChannel { node_id: Some ( nodes[ 2 ] . node. get_our_node_id( ) ) , channel_id: chan_2. 2 } ] ) ;
1741
1742
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1742
- assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1743
1743
1744
1744
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1745
1745
let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_1. 2 ) . unwrap ( ) . clone ( ) ;
@@ -1753,17 +1753,17 @@ fn test_monitor_update_on_pending_forwards() {
1753
1753
1754
1754
let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
1755
1755
assert_eq ! ( events. len( ) , 3 ) ;
1756
- if let Event :: PaymentPathFailed { payment_hash, payment_failed_permanently, .. } = events[ 0 ] {
1756
+ if let Event :: PaymentPathFailed { payment_hash, payment_failed_permanently, .. } = events[ 1 ] {
1757
1757
assert_eq ! ( payment_hash, payment_hash_1) ;
1758
1758
assert ! ( payment_failed_permanently) ;
1759
1759
} else { panic ! ( "Unexpected event!" ) ; }
1760
- match events[ 1 ] {
1760
+ match events[ 2 ] {
1761
1761
Event :: PaymentFailed { payment_hash, .. } => {
1762
1762
assert_eq ! ( payment_hash, payment_hash_1) ;
1763
1763
} ,
1764
1764
_ => panic ! ( "Unexpected event" ) ,
1765
1765
}
1766
- match events[ 2 ] {
1766
+ match events[ 0 ] {
1767
1767
Event :: PendingHTLCsForwardable { .. } => { } ,
1768
1768
_ => panic ! ( "Unexpected event" ) ,
1769
1769
} ;
@@ -1803,14 +1803,14 @@ fn monitor_update_claim_fail_no_response() {
1803
1803
1804
1804
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
1805
1805
nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
1806
- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
1807
1806
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1808
1807
1809
1808
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1810
1809
1811
1810
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1812
1811
let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
1813
1812
nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
1813
+ expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
1814
1814
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
1815
1815
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1816
1816
@@ -2290,7 +2290,6 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
2290
2290
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
2291
2291
nodes[ 0 ] . node . claim_funds ( payment_preimage_0) ;
2292
2292
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2293
- expect_payment_claimed ! ( nodes[ 0 ] , payment_hash_0, 100_000 ) ;
2294
2293
2295
2294
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & send. msgs [ 0 ] ) ;
2296
2295
nodes[ 1 ] . node . handle_commitment_signed ( & nodes[ 0 ] . node . get_our_node_id ( ) , & send. commitment_msg ) ;
@@ -2353,6 +2352,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
2353
2352
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2354
2353
let ( funding_txo, mon_id, _) = nodes[ 0 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id) . unwrap ( ) . clone ( ) ;
2355
2354
nodes[ 0 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( funding_txo, mon_id) ;
2355
+ expect_payment_claimed ! ( nodes[ 0 ] , payment_hash_0, 100_000 ) ;
2356
2356
2357
2357
// New outbound messages should be generated immediately upon a call to
2358
2358
// get_and_clear_pending_msg_events (but not before).
@@ -2606,7 +2606,15 @@ fn test_permanent_error_during_sending_shutdown() {
2606
2606
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2607
2607
2608
2608
assert ! ( nodes[ 0 ] . node. close_channel( & channel_id, & nodes[ 1 ] . node. get_our_node_id( ) ) . is_ok( ) ) ;
2609
- check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
2609
+
2610
+ // We always send the `shutdown` response when initiating a shutdown, even if we immediately
2611
+ // close the channel thereafter.
2612
+ let msg_events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
2613
+ assert_eq ! ( msg_events. len( ) , 3 ) ;
2614
+ if let MessageSendEvent :: SendShutdown { .. } = msg_events[ 0 ] { } else { panic ! ( ) ; }
2615
+ if let MessageSendEvent :: BroadcastChannelUpdate { .. } = msg_events[ 1 ] { } else { panic ! ( ) ; }
2616
+ if let MessageSendEvent :: HandleError { .. } = msg_events[ 2 ] { } else { panic ! ( ) ; }
2617
+
2610
2618
check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
2611
2619
check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: ProcessingError { err: "ChannelMonitor storage failure" . to_string( ) } ) ;
2612
2620
}
@@ -2629,7 +2637,15 @@ fn test_permanent_error_during_handling_shutdown() {
2629
2637
assert ! ( nodes[ 0 ] . node. close_channel( & channel_id, & nodes[ 1 ] . node. get_our_node_id( ) ) . is_ok( ) ) ;
2630
2638
let shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2631
2639
nodes[ 1 ] . node . handle_shutdown ( & nodes[ 0 ] . node . get_our_node_id ( ) , & shutdown) ;
2632
- check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
2640
+
2641
+ // We always send the `shutdown` response when receiving a shutdown, even if we immediately
2642
+ // close the channel thereafter.
2643
+ let msg_events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
2644
+ assert_eq ! ( msg_events. len( ) , 3 ) ;
2645
+ if let MessageSendEvent :: SendShutdown { .. } = msg_events[ 0 ] { } else { panic ! ( ) ; }
2646
+ if let MessageSendEvent :: BroadcastChannelUpdate { .. } = msg_events[ 1 ] { } else { panic ! ( ) ; }
2647
+ if let MessageSendEvent :: HandleError { .. } = msg_events[ 2 ] { } else { panic ! ( ) ; }
2648
+
2633
2649
check_added_monitors ! ( nodes[ 1 ] , 2 ) ;
2634
2650
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: ProcessingError { err: "ChannelMonitor storage failure" . to_string( ) } ) ;
2635
2651
}
@@ -2651,15 +2667,13 @@ fn double_temp_error() {
2651
2667
// `claim_funds` results in a ChannelMonitorUpdate.
2652
2668
nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
2653
2669
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2654
- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
2655
2670
let ( funding_tx, latest_update_1, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
2656
2671
2657
2672
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
2658
2673
// Previously, this would've panicked due to a double-call to `Channel::monitor_update_failed`,
2659
2674
// which had some asserts that prevented it from being called twice.
2660
2675
nodes[ 1 ] . node . claim_funds ( payment_preimage_2) ;
2661
2676
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2662
- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_2, 1_000_000 ) ;
2663
2677
chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2664
2678
2665
2679
let ( _, latest_update_2, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
@@ -2668,11 +2682,24 @@ fn double_temp_error() {
2668
2682
check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
2669
2683
nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( funding_tx, latest_update_2) ;
2670
2684
2671
- // Complete the first HTLC.
2672
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
2673
- assert_eq ! ( events. len( ) , 1 ) ;
2685
+ // Complete the first HTLC. Note that as a side-effect we handle the monitor update completions
2686
+ // and get both PaymentClaimed events at once.
2687
+ let msg_events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
2688
+
2689
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
2690
+ assert_eq ! ( events. len( ) , 2 ) ;
2691
+ match events[ 0 ] {
2692
+ Event :: PaymentClaimed { amount_msat : 1_000_000 , payment_hash, .. } => assert_eq ! ( payment_hash, payment_hash_1) ,
2693
+ _ => panic ! ( "Unexpected Event: {:?}" , events[ 0 ] ) ,
2694
+ }
2695
+ match events[ 1 ] {
2696
+ Event :: PaymentClaimed { amount_msat : 1_000_000 , payment_hash, .. } => assert_eq ! ( payment_hash, payment_hash_2) ,
2697
+ _ => panic ! ( "Unexpected Event: {:?}" , events[ 1 ] ) ,
2698
+ }
2699
+
2700
+ assert_eq ! ( msg_events. len( ) , 1 ) ;
2674
2701
let ( update_fulfill_1, commitment_signed_b1, node_id) = {
2675
- match & events [ 0 ] {
2702
+ match & msg_events [ 0 ] {
2676
2703
& MessageSendEvent :: UpdateHTLCs { ref node_id, updates : msgs:: CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
2677
2704
assert ! ( update_add_htlcs. is_empty( ) ) ;
2678
2705
assert_eq ! ( update_fulfill_htlcs. len( ) , 1 ) ;
0 commit comments