@@ -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) */
@@ -334,6 +336,15 @@ static u32 initial_cltv_delta(const struct attempt *attempt)
334
336
return attempt -> hops [0 ].cltv_value_in ;
335
337
}
336
338
339
+ /* Find the total number of pending attempts */
340
+ static size_t count_current_attempts (const struct payment * payment )
341
+ {
342
+ const struct attempt * i ;
343
+ size_t result = 0 ;
344
+ list_for_each (& payment -> current_attempts , i , list ) { result ++ ; }
345
+ return result ;
346
+ }
347
+
337
348
/* We total up all attempts which succeeded in the past (if we're not
338
349
* in slow mode, that's only the one which just succeeded), and then we
339
350
* assume any others currently-in-flight will also succeed. */
@@ -1296,6 +1307,7 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
1296
1307
struct out_req * req ;
1297
1308
const struct pubkey * dst ;
1298
1309
struct amount_msat maxfee ;
1310
+ size_t count_pending ;
1299
1311
1300
1312
/* I would normally assert here, but we have reports of this happening... */
1301
1313
if (amount_msat_is_zero (deliver )) {
@@ -1356,6 +1368,9 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
1356
1368
json_add_amount_msat (req -> js , "maxfee_msat" , maxfee );
1357
1369
json_add_u32 (req -> js , "final_cltv" , payment -> final_cltv );
1358
1370
json_add_u32 (req -> js , "maxdelay" , * payment -> maxdelay );
1371
+ count_pending = count_current_attempts (payment );
1372
+ assert (* payment -> maxparts > count_pending );
1373
+ json_add_u32 (req -> js , "maxparts" , * payment -> maxparts - count_pending );
1359
1374
1360
1375
return send_payment_req (aux_cmd , payment , req );
1361
1376
}
@@ -1646,8 +1661,12 @@ static struct command_result *json_xpay_core(struct command *cmd,
1646
1661
p_opt_def ("retry_for" , param_number , & retryfor , 60 ),
1647
1662
p_opt ("partial_msat" , param_msat , & partial ),
1648
1663
p_opt_def ("maxdelay" , param_u32 , & payment -> maxdelay , 2016 ),
1664
+ p_opt_dev ("dev_maxparts" , param_u32 , & payment -> maxparts , 100 ),
1649
1665
NULL ))
1650
1666
return command_param_failed ();
1667
+ if (* payment -> maxparts == 0 )
1668
+ return command_fail (cmd , JSONRPC2_INVALID_PARAMS ,
1669
+ "maxparts cannot be zero" );
1651
1670
1652
1671
list_head_init (& payment -> current_attempts );
1653
1672
list_head_init (& payment -> past_attempts );
0 commit comments