@@ -4183,6 +4183,96 @@ fn mpp_failure() {
4183
4183
fail_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , false , payment_hash) ;
4184
4184
}
4185
4185
4186
+ #[ test]
4187
+ fn mpp_retry ( ) {
4188
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
4189
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
4190
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
4191
+ let nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
4192
+
4193
+ let chan_1_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
4194
+ let chan_2_id = create_announced_chan_between_nodes ( & nodes, 0 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
4195
+ let chan_3_id = create_announced_chan_between_nodes ( & nodes, 1 , 3 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
4196
+ let chan_4_id = create_announced_chan_between_nodes ( & nodes, 3 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
4197
+ let logger = test_utils:: TestLogger :: new ( ) ;
4198
+ // Rebalance
4199
+ send_payment ( & nodes[ 3 ] , & vec ! ( & nodes[ 2 ] ) [ ..] , 1_500_000 ) ;
4200
+
4201
+ let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ! ( & nodes[ 3 ] ) ;
4202
+ let net_graph_msg_handler = & nodes[ 0 ] . net_graph_msg_handler ;
4203
+ let mut route = get_route ( & nodes[ 0 ] . node . get_our_node_id ( ) , & net_graph_msg_handler. network_graph , & nodes[ 3 ] . node . get_our_node_id ( ) , Some ( InvoiceFeatures :: known ( ) ) , None , & [ ] , 1_000_000 , TEST_FINAL_CLTV , & logger) . unwrap ( ) ;
4204
+ let path = route. paths [ 0 ] . clone ( ) ;
4205
+ route. paths . push ( path) ;
4206
+ route. paths [ 0 ] [ 0 ] . pubkey = nodes[ 1 ] . node . get_our_node_id ( ) ;
4207
+ route. paths [ 0 ] [ 0 ] . short_channel_id = chan_1_id;
4208
+ route. paths [ 0 ] [ 1 ] . short_channel_id = chan_3_id;
4209
+ route. paths [ 1 ] [ 0 ] . pubkey = nodes[ 2 ] . node . get_our_node_id ( ) ;
4210
+ route. paths [ 1 ] [ 0 ] . short_channel_id = chan_2_id;
4211
+ route. paths [ 1 ] [ 1 ] . short_channel_id = chan_4_id;
4212
+
4213
+ // Initiate the MPP payment.
4214
+ let payment_id = nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) . unwrap ( ) ;
4215
+ check_added_monitors ! ( nodes[ 0 ] , 2 ) ; // one monitor per path
4216
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
4217
+ assert_eq ! ( events. len( ) , 2 ) ;
4218
+
4219
+ // Pass half of the payment along the success path.
4220
+ let success_path_msgs = events. remove ( 0 ) ;
4221
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 3 ] ] , 2_000_000 , payment_hash, Some ( payment_secret) , success_path_msgs, false , None ) ;
4222
+
4223
+ // Add the HTLC along the first hop.
4224
+ let fail_path_msgs_1 = events. remove ( 0 ) ;
4225
+ let ( update_add, commitment_signed) = match fail_path_msgs_1 {
4226
+ MessageSendEvent :: UpdateHTLCs { 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 } } => {
4227
+ assert_eq ! ( update_add_htlcs. len( ) , 1 ) ;
4228
+ assert ! ( update_fail_htlcs. is_empty( ) ) ;
4229
+ assert ! ( update_fulfill_htlcs. is_empty( ) ) ;
4230
+ assert ! ( update_fail_malformed_htlcs. is_empty( ) ) ;
4231
+ assert ! ( update_fee. is_none( ) ) ;
4232
+ ( update_add_htlcs[ 0 ] . clone ( ) , commitment_signed. clone ( ) )
4233
+ } ,
4234
+ _ => panic ! ( "Unexpected event" ) ,
4235
+ } ;
4236
+ nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & update_add) ;
4237
+ commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 0 ] , commitment_signed, false ) ;
4238
+
4239
+ // Attempt to forward the payment and complete the 2nd path's failure.
4240
+ expect_pending_htlcs_forwardable ! ( & nodes[ 2 ] ) ;
4241
+ expect_pending_htlcs_forwardable ! ( & nodes[ 2 ] ) ;
4242
+ let htlc_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
4243
+ assert ! ( htlc_updates. update_add_htlcs. is_empty( ) ) ;
4244
+ assert_eq ! ( htlc_updates. update_fail_htlcs. len( ) , 1 ) ;
4245
+ assert ! ( htlc_updates. update_fulfill_htlcs. is_empty( ) ) ;
4246
+ assert ! ( htlc_updates. update_fail_malformed_htlcs. is_empty( ) ) ;
4247
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
4248
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & htlc_updates. update_fail_htlcs [ 0 ] ) ;
4249
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 2 ] , htlc_updates. commitment_signed, false ) ;
4250
+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, false ) ;
4251
+
4252
+ // Rebalance the channel so the second half of the payment can succeed.
4253
+ send_payment ( & nodes[ 3 ] , & vec ! ( & nodes[ 2 ] ) [ ..] , 1_500_000 ) ;
4254
+
4255
+ // Make sure it errors as expected given a too-large amount.
4256
+ if let Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError { err } ) ) = nodes[ 0 ] . node . retry_payment ( & route, payment_id) {
4257
+ assert ! ( err. contains( "over total_payment_amt_msat" ) ) ;
4258
+ } else { panic ! ( "Unexpected error" ) ; }
4259
+
4260
+ // Make sure it errors as expected given the wrong payment_id.
4261
+ if let Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError { err } ) ) = nodes[ 0 ] . node . retry_payment ( & route, PaymentId ( [ 0 ; 32 ] ) ) {
4262
+ assert ! ( err. contains( "not found" ) ) ;
4263
+ } else { panic ! ( "Unexpected error" ) ; }
4264
+
4265
+ // Retry the second half of the payment and make sure it succeeds.
4266
+ let mut path = route. clone ( ) ;
4267
+ path. paths . remove ( 0 ) ;
4268
+ nodes[ 0 ] . node . retry_payment ( & path, payment_id) . unwrap ( ) ;
4269
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
4270
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
4271
+ assert_eq ! ( events. len( ) , 1 ) ;
4272
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] , 2_000_000 , payment_hash, Some ( payment_secret) , events. pop ( ) . unwrap ( ) , true , None ) ;
4273
+ claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , false , payment_preimage) ;
4274
+ }
4275
+
4186
4276
#[ test]
4187
4277
fn test_dup_htlc_onchain_fails_on_reload ( ) {
4188
4278
// When a Channel is closed, any outbound HTLCs which were relayed through it are simply
0 commit comments