Skip to content

Commit 1830c0e

Browse files
Lagrang3rustyrussell
authored andcommitted
xpay: add developer option dev_maxparts
dev_maxparts limits the number of pending routes allowed at any given time. Changelog-None Signed-off-by: Lagrang3 <[email protected]>
1 parent 0c5c7a5 commit 1830c0e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

plugins/xpay/xpay.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct payment {
7878
struct amount_msat maxfee;
7979
/* Maximum delay on the route we're ok with */
8080
u32 *maxdelay;
81+
/* Maximum number of payment routes that can be pending. */
82+
u32 *maxparts;
8183
/* Do we have to do it all in a single part? */
8284
bool disable_mpp;
8385
/* BOLT11 payment secret (NULL for BOLT12, it uses blinded paths) */
@@ -334,6 +336,15 @@ static u32 initial_cltv_delta(const struct attempt *attempt)
334336
return attempt->hops[0].cltv_value_in;
335337
}
336338

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+
337348
/* We total up all attempts which succeeded in the past (if we're not
338349
* in slow mode, that's only the one which just succeeded), and then we
339350
* assume any others currently-in-flight will also succeed. */
@@ -1296,6 +1307,7 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
12961307
struct out_req *req;
12971308
const struct pubkey *dst;
12981309
struct amount_msat maxfee;
1310+
size_t count_pending;
12991311

13001312
/* I would normally assert here, but we have reports of this happening... */
13011313
if (amount_msat_is_zero(deliver)) {
@@ -1356,6 +1368,9 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
13561368
json_add_amount_msat(req->js, "maxfee_msat", maxfee);
13571369
json_add_u32(req->js, "final_cltv", payment->final_cltv);
13581370
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);
13591374

13601375
return send_payment_req(aux_cmd, payment, req);
13611376
}
@@ -1646,8 +1661,12 @@ static struct command_result *json_xpay_core(struct command *cmd,
16461661
p_opt_def("retry_for", param_number, &retryfor, 60),
16471662
p_opt("partial_msat", param_msat, &partial),
16481663
p_opt_def("maxdelay", param_u32, &payment->maxdelay, 2016),
1664+
p_opt_dev("dev_maxparts", param_u32, &payment->maxparts, 100),
16491665
NULL))
16501666
return command_param_failed();
1667+
if (*payment->maxparts == 0)
1668+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1669+
"maxparts cannot be zero");
16511670

16521671
list_head_init(&payment->current_attempts);
16531672
list_head_init(&payment->past_attempts);

0 commit comments

Comments
 (0)