@@ -78,6 +78,8 @@ struct payment {
78
78
struct amount_msat maxfee ;
79
79
/* Maximum delay on the route we're ok with */
80
80
u32 * maxdelay ;
81
+ /* Maximum number of payment routes that can be pending. */
82
+ u32 * maxparts ;
81
83
/* Do we have to do it all in a single part? */
82
84
bool disable_mpp ;
83
85
/* BOLT11 payment secret (NULL for BOLT12, it uses blinded paths) */
@@ -113,6 +115,9 @@ struct payment {
113
115
* call outstanding). */
114
116
struct amount_msat amount_being_routed ;
115
117
118
+ /* Number of routes attempted and pending */
119
+ u32 pending_attempts ;
120
+
116
121
/* Useful information from prior attempts if any. */
117
122
char * prior_results ;
118
123
@@ -334,6 +339,15 @@ static u32 initial_cltv_delta(const struct attempt *attempt)
334
339
return attempt -> hops [0 ].cltv_value_in ;
335
340
}
336
341
342
+ /* Find the total number of pending attempts */
343
+ static size_t count_current_attempts (const struct payment * payment )
344
+ {
345
+ const struct attempt * i ;
346
+ size_t result = 0 ;
347
+ list_for_each (& payment -> current_attempts , i , list ) { result ++ ; }
348
+ return result ;
349
+ }
350
+
337
351
/* We total up all attempts which succeeded in the past (if we're not
338
352
* in slow mode, that's only the one which just succeeded), and then we
339
353
* assume any others currently-in-flight will also succeed. */
@@ -1296,6 +1310,7 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
1296
1310
struct out_req * req ;
1297
1311
const struct pubkey * dst ;
1298
1312
struct amount_msat maxfee ;
1313
+ size_t count_pending ;
1299
1314
1300
1315
/* I would normally assert here, but we have reports of this happening... */
1301
1316
if (amount_msat_is_zero (deliver )) {
@@ -1356,6 +1371,9 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
1356
1371
json_add_amount_msat (req -> js , "maxfee_msat" , maxfee );
1357
1372
json_add_u32 (req -> js , "final_cltv" , payment -> final_cltv );
1358
1373
json_add_u32 (req -> js , "maxdelay" , * payment -> maxdelay );
1374
+ count_pending = count_current_attempts (payment );
1375
+ assert (* payment -> maxparts > count_pending );
1376
+ json_add_u32 (req -> js , "maxparts" , * payment -> maxparts - count_pending );
1359
1377
1360
1378
return send_payment_req (aux_cmd , payment , req );
1361
1379
}
@@ -1646,14 +1664,19 @@ static struct command_result *json_xpay_core(struct command *cmd,
1646
1664
p_opt_def ("retry_for" , param_number , & retryfor , 60 ),
1647
1665
p_opt ("partial_msat" , param_msat , & partial ),
1648
1666
p_opt_def ("maxdelay" , param_u32 , & payment -> maxdelay , 2016 ),
1667
+ p_opt_dev ("dev_maxparts" , param_u32 , & payment -> maxparts , 100 ),
1649
1668
NULL ))
1650
1669
return command_param_failed ();
1670
+ if (* payment -> maxparts == 0 )
1671
+ return command_fail (cmd , JSONRPC2_INVALID_PARAMS ,
1672
+ "maxparts cannot be zero" );
1651
1673
1652
1674
list_head_init (& payment -> current_attempts );
1653
1675
list_head_init (& payment -> past_attempts );
1654
1676
payment -> plugin = cmd -> plugin ;
1655
1677
payment -> cmd = cmd ;
1656
1678
payment -> amount_being_routed = AMOUNT_MSAT (0 );
1679
+ payment -> pending_attempts = 0 ;
1657
1680
payment -> group_id = pseudorand (INT64_MAX );
1658
1681
payment -> total_num_attempts = payment -> num_failures = 0 ;
1659
1682
payment -> requests = tal_arr (payment , struct out_req * , 0 );
0 commit comments