@@ -143,7 +143,7 @@ fn test_monitor_and_persister_update_fail() {
143143 let mut node_0_per_peer_lock;
144144 let mut node_0_peer_state_lock;
145145 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 ) {
147147 // Check that even though the persister is returning a InProgress,
148148 // because the update is bogus, ultimately the error that's returned
149149 // should be a PermanentFailure.
@@ -1602,7 +1602,6 @@ fn test_monitor_update_fail_claim() {
16021602
16031603 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
16041604 nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
1605- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
16061605 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
16071606 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
16081607
@@ -1628,6 +1627,7 @@ fn test_monitor_update_fail_claim() {
16281627 let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
16291628 assert_eq ! ( events. len( ) , 0 ) ;
16301629 commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 2 ] , payment_event. commitment_msg, false , true ) ;
1630+ expect_pending_htlcs_forwardable_ignore ! ( nodes[ 1 ] ) ;
16311631
16321632 let ( _, payment_hash_3, payment_secret_3) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
16331633 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() {
16451645 let channel_id = chan_1. 2 ;
16461646 let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
16471647 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 ) ;
16481649 check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
16491650
16501651 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() {
16531654 expect_payment_sent ! ( nodes[ 0 ] , payment_preimage_1) ;
16541655
16551656 // 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 ( ) ;
16571658 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
16581659 let bs_forward_update = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
16591660 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() {
17391740 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
17401741 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 } ] ) ;
17411742 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1742- assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
17431743
17441744 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
17451745 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() {
17531753
17541754 let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
17551755 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 ] {
17571757 assert_eq ! ( payment_hash, payment_hash_1) ;
17581758 assert ! ( payment_failed_permanently) ;
17591759 } else { panic ! ( "Unexpected event!" ) ; }
1760- match events[ 1 ] {
1760+ match events[ 2 ] {
17611761 Event :: PaymentFailed { payment_hash, .. } => {
17621762 assert_eq ! ( payment_hash, payment_hash_1) ;
17631763 } ,
17641764 _ => panic ! ( "Unexpected event" ) ,
17651765 }
1766- match events[ 2 ] {
1766+ match events[ 0 ] {
17671767 Event :: PendingHTLCsForwardable { .. } => { } ,
17681768 _ => panic ! ( "Unexpected event" ) ,
17691769 } ;
@@ -1803,14 +1803,14 @@ fn monitor_update_claim_fail_no_response() {
18031803
18041804 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
18051805 nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
1806- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
18071806 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
18081807
18091808 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
18101809
18111810 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
18121811 let ( outpoint, latest_update, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
18131812 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 ) ;
18141814 check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
18151815 assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
18161816
@@ -2290,7 +2290,6 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
22902290 chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
22912291 nodes[ 0 ] . node . claim_funds ( payment_preimage_0) ;
22922292 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2293- expect_payment_claimed ! ( nodes[ 0 ] , payment_hash_0, 100_000 ) ;
22942293
22952294 nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & send. msgs [ 0 ] ) ;
22962295 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) {
23532352 chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
23542353 let ( funding_txo, mon_id, _) = nodes[ 0 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id) . unwrap ( ) . clone ( ) ;
23552354 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 ) ;
23562356
23572357 // New outbound messages should be generated immediately upon a call to
23582358 // get_and_clear_pending_msg_events (but not before).
@@ -2606,7 +2606,15 @@ fn test_permanent_error_during_sending_shutdown() {
26062606 chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
26072607
26082608 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+
26102618 check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
26112619 check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: ProcessingError { err: "ChannelMonitor storage failure" . to_string( ) } ) ;
26122620}
@@ -2629,7 +2637,15 @@ fn test_permanent_error_during_handling_shutdown() {
26292637 assert ! ( nodes[ 0 ] . node. close_channel( & channel_id, & nodes[ 1 ] . node. get_our_node_id( ) ) . is_ok( ) ) ;
26302638 let shutdown = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendShutdown , nodes[ 1 ] . node. get_our_node_id( ) ) ;
26312639 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+
26332649 check_added_monitors ! ( nodes[ 1 ] , 2 ) ;
26342650 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: ProcessingError { err: "ChannelMonitor storage failure" . to_string( ) } ) ;
26352651}
@@ -2651,15 +2667,13 @@ fn double_temp_error() {
26512667 // `claim_funds` results in a ChannelMonitorUpdate.
26522668 nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
26532669 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2654- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_1, 1_000_000 ) ;
26552670 let ( funding_tx, latest_update_1, _) = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & channel_id) . unwrap ( ) . clone ( ) ;
26562671
26572672 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
26582673 // Previously, this would've panicked due to a double-call to `Channel::monitor_update_failed`,
26592674 // which had some asserts that prevented it from being called twice.
26602675 nodes[ 1 ] . node . claim_funds ( payment_preimage_2) ;
26612676 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2662- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash_2, 1_000_000 ) ;
26632677 chanmon_cfgs[ 1 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
26642678
26652679 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() {
26682682 check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
26692683 nodes[ 1 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( funding_tx, latest_update_2) ;
26702684
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 ) ;
26742701 let ( update_fulfill_1, commitment_signed_b1, node_id) = {
2675- match & events [ 0 ] {
2702+ match & msg_events [ 0 ] {
26762703 & 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 } } => {
26772704 assert ! ( update_add_htlcs. is_empty( ) ) ;
26782705 assert_eq ! ( update_fulfill_htlcs. len( ) , 1 ) ;
0 commit comments