@@ -4317,6 +4317,9 @@ fn retry_single_path_payment() {
43174317 // Rebalance the channel so the retry succeeds.
43184318 send_payment ( & nodes[ 2 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3_000_000 ) ;
43194319
4320+ // Mine two blocks (we expire retries after 3, so this will check that we don't expire early)
4321+ connect_blocks ( & nodes[ 0 ] , 2 ) ;
4322+
43204323 // Retry the payment and make sure it succeeds.
43214324 nodes[ 0 ] . node . retry_payment ( & route, payment_id) . unwrap ( ) ;
43224325 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
@@ -4326,6 +4329,58 @@ fn retry_single_path_payment() {
43264329 claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , false , payment_preimage) ;
43274330}
43284331
4332+ #[ test]
4333+ fn retry_expired_payment ( ) {
4334+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
4335+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
4336+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
4337+ let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
4338+
4339+ let _chan_0 = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
4340+ let _chan_1 = create_announced_chan_between_nodes ( & nodes, 2 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
4341+ // Rebalance to find a route
4342+ send_payment ( & nodes[ 2 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3_000_000 ) ;
4343+
4344+ let logger = test_utils:: TestLogger :: new ( ) ;
4345+ let ( _payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ! ( nodes[ 2 ] ) ;
4346+ let net_graph_msg_handler = & nodes[ 0 ] . net_graph_msg_handler ;
4347+ let route = get_route ( & nodes[ 0 ] . node . get_our_node_id ( ) , & net_graph_msg_handler. network_graph , & nodes[ 2 ] . node . get_our_node_id ( ) , Some ( InvoiceFeatures :: known ( ) ) , None , & Vec :: new ( ) , 100_000 , TEST_FINAL_CLTV , & logger) . unwrap ( ) ;
4348+
4349+ // Rebalance so that the first hop fails.
4350+ send_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 2 ] ) [ ..] , 2_000_000 ) ;
4351+
4352+ // Make sure the payment fails on the first hop.
4353+ let payment_id = nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) . unwrap ( ) ;
4354+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
4355+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
4356+ assert_eq ! ( events. len( ) , 1 ) ;
4357+ let mut payment_event = SendEvent :: from_event ( events. pop ( ) . unwrap ( ) ) ;
4358+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
4359+ check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
4360+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
4361+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
4362+ expect_pending_htlcs_forwardable ! ( & nodes[ 1 ] ) ;
4363+ let htlc_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
4364+ assert ! ( htlc_updates. update_add_htlcs. is_empty( ) ) ;
4365+ assert_eq ! ( htlc_updates. update_fail_htlcs. len( ) , 1 ) ;
4366+ assert ! ( htlc_updates. update_fulfill_htlcs. is_empty( ) ) ;
4367+ assert ! ( htlc_updates. update_fail_malformed_htlcs. is_empty( ) ) ;
4368+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
4369+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_updates. update_fail_htlcs [ 0 ] ) ;
4370+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_updates. commitment_signed, false ) ;
4371+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, false ) ;
4372+
4373+ // Mine blocks so the payment will have expired.
4374+ connect_blocks ( & nodes[ 0 ] , 3 ) ;
4375+
4376+ // Retry the payment and make sure it errors as expected.
4377+ if let Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError { err } ) ) = nodes[ 0 ] . node . retry_payment ( & route, payment_id) {
4378+ assert ! ( err. contains( "not found" ) ) ;
4379+ } else {
4380+ panic ! ( "Unexpected error" ) ;
4381+ }
4382+ }
4383+
43294384#[ test]
43304385fn test_dup_htlc_onchain_fails_on_reload ( ) {
43314386 // When a Channel is closed, any outbound HTLCs which were relayed through it are simply
0 commit comments