@@ -55,6 +55,8 @@ use sync::{Arc, Mutex};
5555use ln:: functional_test_utils:: * ;
5656use ln:: chan_utils:: CommitmentTransaction ;
5757
58+ use crate :: ln:: channelmanager:: MPP_TIMEOUT_TICKS ;
59+
5860#[ test]
5961fn test_insane_channel_opens ( ) {
6062 // Stand up a network of 2 nodes
@@ -9689,3 +9691,46 @@ fn test_max_dust_htlc_exposure() {
96899691 do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtUpdateFeeOutbound , false ) ;
96909692 do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtUpdateFeeOutbound , true ) ;
96919693}
9694+
9695+ #[ test]
9696+ fn test_mpp_receive_timeout ( ) {
9697+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
9698+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
9699+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
9700+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
9701+
9702+ let chan_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
9703+
9704+ let ( mut route, payment_hash, _payment_preimage, payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 1 ] , 100000 ) ;
9705+ let path = route. paths [ 0 ] . clone ( ) ;
9706+ route. paths . push ( path) ;
9707+ route. paths [ 0 ] [ 0 ] . pubkey = nodes[ 1 ] . node . get_our_node_id ( ) ;
9708+ route. paths [ 0 ] [ 0 ] . short_channel_id = chan_id;
9709+
9710+ let cur_height = CHAN_CONFIRM_DEPTH + 1 ; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
9711+ let payment_id = PaymentId ( [ 42 ; 32 ] ) ;
9712+
9713+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payment_params , & payment_hash, & Some ( payment_secret) , 200000 , cur_height, payment_id, & None ) . unwrap ( ) ;
9714+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
9715+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
9716+ assert_eq ! ( events. len( ) , 1 ) ;
9717+
9718+ // Now do the relevant commitment_signed/RAA dances along the path, noting that the final
9719+ // hop should *not* yet generate any PaymentReceived event(s).
9720+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100000 , payment_hash, Some ( payment_secret) , events. drain ( ..) . next ( ) . unwrap ( ) , false , None ) ;
9721+
9722+ for _ in 0 ..MPP_TIMEOUT_TICKS {
9723+ nodes[ 1 ] . node . timer_tick_occurred ( ) ;
9724+ }
9725+
9726+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
9727+
9728+ let htlc_fail_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
9729+ assert_eq ! ( htlc_fail_updates. update_fail_htlcs. len( ) , 1 ) ;
9730+
9731+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_fail_updates. update_fail_htlcs [ 0 ] ) ;
9732+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
9733+
9734+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_fail_updates. commitment_signed, true , true ) ;
9735+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, false , 23 , & [ ] [ ..] ) ;
9736+ }
0 commit comments