Skip to content

xpay: add maxparts option - #9692

Open
Lagrang3 wants to merge 1 commit into
ElementsProject:masterfrom
Lagrang3:xpay-add-maxparts
Open

Lagrang3 wants to merge 1 commit into
ElementsProject:masterfrom
Lagrang3:xpay-add-maxparts

Conversation

@Lagrang3

@Lagrang3 Lagrang3 commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Adds maxparts option to xpay and some tests.
It is straightforward now that we have maxparts in getroutes.
Fixes issue #9691

@Lagrang3
Lagrang3 requested a review from cdecker as a code owner November 4, 2026 16:37
@Lagrang3 Lagrang3 added this to the v26.12 milestone Nov 4, 2026
@Lagrang3
Lagrang3 requested review from Andezion and nGoline November 4, 2026 16:38
Comment thread plugins/xpay/xpay.c Outdated
}

if (disable_mpp) {
payment->maxparts = 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe payment->maxparts = payment->user_maxparts = 1; in that branch. That also covers sendamount, because includefees_msat already sets disable_mpp = true

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set user_maxparts = 1 here? Are you worried that I might fallback to a higher maxparts at

	if (payment->maxparts && (payment->user_maxparts == 0 ||
				  payment->user_maxparts > payment->maxparts)) {

		if (payment->user_maxparts)
			payment_log(payment, LOG_INFORM,
				    "getroute failed with maxparts=%u, so "
				    "retrying with maxparts=%" PRIu32,
				    payment->maxparts, payment->user_maxparts);
		else
			payment_log(payment, LOG_INFORM,
				    "getroute failed with maxparts=%u, so "
				    "retrying without that restriction",
				    payment->maxparts);
		payment->maxparts = payment->user_maxparts;
		return getroutes_for(aux_cmd, payment, payment->amount_being_routed);
	}

?

Comment thread plugins/xpay/xpay.c Outdated
if (!gossmap_find_node(gossmap, &dstid)) {
if (payment->maxparts == 0 || payment->maxparts > 6)
payment->maxparts = 6;
payment_log(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe log the real value ("... limiting maxparts to %u"), or log only when the value is actually lowered to 6, because the test hint_small waits for this exact line while asserting num_flows() <= 3

@cdecker cdecker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be much simpler, as in the desired user value just gets assigned to the maxparts on the payment, we try with that, and if it fails we report a failure, no need to triple the MCF calls to try with a limit the user has never asked for.

Comment thread plugins/xpay/xpay.c Outdated
payment->maxparts = 0;
/* If we were restricting the number of parts, we relax it up to the
* user's provided maxparts (if any) and try again. */
if (payment->maxparts && (payment->user_maxparts == 0 ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not go with user_maxparts right away? I think setting payment->maxparts = payment->user_maxpart and then relaxing if it does not work out is likely simpler, and more in line with what users want. It doesn't make much sense to me to try with a smaller maxparts first adn then try with user_maxparts and then unconstrained when we could implement the user's desired limit right away.

@Lagrang3 Lagrang3 Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had issues with Phoenix not accepting more than 6 parts.
The user sets maxparts = 10 could lead to failed payment, while maxparts = 5 a success.
But this is counter intuitive because the first case is less restrictive.
maxparts should be interpreted as: "whatever you do, I don't care as long as the number of parts does not exceed my user set maxparts".

Therefore, if the user sets maxparts = 10, the solver will try do its best to find a solution that satisfies that constraint.
We know that Phoenix wallet will not like more than 6, so we first try with 6, when 6 is less than 10, we are honoring the user's request.

@nGoline nGoline left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things before it can go in:

  • if the user sets maxparts, that should be the limit;
  • passing 1 as the user limit means keysend can no longer fall back to multiple parts when no single path exists;
  • disable_mpp sets maxparts = 1 but leaves user_maxparts alone, so after a getroutes failure we widen to the user's value and send a multi-part payment to a node that didn't advertise basic_mpp;
  • The ASan and Valgrind failures aren't flakes. On all three attempts the runner is killed for running out of memory while test_xpay_maxparts_receiver_limit is running;
  • nit: the comment at tests/test_xpay.py:1953 says xpay drops the restriction and retries, but the test (correctly) expects it to fail.

Comment thread plugins/xpay/xpay.c Outdated
payment = new_payment(cmd, cmd,
*retryfor,
*maxdelay,
/* maxparts = */ 1,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xkeysend now passes maxparts = 1 as the user limit. On master keysend starts at maxparts = 1 (line 3472) but getroutes_done_err relaxes it to 0 if no single path works. With user_maxparts = 1 the relax condition at 1910 is false, so any keysend that needs more than one path now fails outright.
This is an undocumented behaviour change for an existing command. Pass 0 here (keeping the internal payment->maxparts = 1 start), or make it a deliberate, changelogged change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we can allow xkeysend to use MPP. I'll check.

Comment thread plugins/xpay/xpay.c Outdated
Comment on lines +3057 to +3065
payment->maxparts = payment->user_maxparts;
node_id_from_pubkey(&dstid, &payment->destination);
if (!gossmap_find_node(gossmap, &dstid))
payment->maxparts = 6;
else
payment->maxparts = 0;
if (!gossmap_find_node(gossmap, &dstid)) {
if (payment->maxparts == 0 || payment->maxparts > 6)
payment->maxparts = 6;
payment_log(
payment, LOG_INFORM,
"The destination is unannounced, limiting maxparts to 6");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user gives maxparts, it should be the limit, full stop: skip the unannounced-destination 6-part heuristic and do not relax on failure. Apply the heuristic (and the relax-to-unconstrained fallback) only when user_maxparts == 0. That also fixes the misleading log line (Andezion), and makes the test case "a larger maxparts does not override that" (tests/test_xpay.py:1977-1983) go away: with maxparts=10 the user asked for 10.

Suggested change
payment->maxparts = payment->user_maxparts;
node_id_from_pubkey(&dstid, &payment->destination);
if (!gossmap_find_node(gossmap, &dstid))
payment->maxparts = 6;
else
payment->maxparts = 0;
if (!gossmap_find_node(gossmap, &dstid)) {
if (payment->maxparts == 0 || payment->maxparts > 6)
payment->maxparts = 6;
payment_log(
payment, LOG_INFORM,
"The destination is unannounced, limiting maxparts to 6");
}
payment->maxparts = payment->user_maxparts;
node_id_from_pubkey(&dstid, &payment->destination);
if (!payment->maxparts && !gossmap_find_node(gossmap, &dstid)) {
payment_log(payment, LOG_INFORM,
"The destination is unannounced, limiting maxparts to 6");
payment->maxparts = 6;
}

Comment thread plugins/xpay/xpay.c Outdated
Comment on lines +1910 to +1911
if (payment->maxparts && (payment->user_maxparts == 0 ||
payment->user_maxparts > payment->maxparts)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make user's maxparts final this could be:

Suggested change
if (payment->maxparts && (payment->user_maxparts == 0 ||
payment->user_maxparts > payment->maxparts)) {
if (payment->maxparts && !payment->user_maxparts) {

Comment thread plugins/xpay/xpay.c Outdated
Comment on lines 3067 to 3069

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an invoice without basic_mpp, payment->maxparts = 1 is set but user_maxparts is left as given. After a getroutes failure the new relax step widens the limit to the user's value (e.g. maxparts=5) and sends a multi-part payment to a node that did not advertise MPP. The unconstrained case was already like this on master, but the PR rewrote that condition and is the place to pin it: set payment->user_maxparts = 1 too (@Andezion suggestion). With finding 2's shape this also stops the relax-to-0 for non-MPP invoices.

Comment thread tests/test_xpay.py
wait_xpay_done()

l3.rpc.askrene_age('xpay', int(time.time()))
# Impossible with only 2 parts: xpay drops the restriction and retries.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment says "xpay drops the restriction and retries" but the assertion (correctly) expects failure with the user's limit; fix the comment. Once finding 2 is applied, the three wait_for_log("The destination is unannounced, limiting maxparts to 6") calls at 1973/1982/1991 need adjusting (only the default case logs it).

Comment thread plugins/xpay/xpay.c
xparams->layers = layers;
xparams->retryfor = *retryfor;
xparams->maxdelay = *maxdelay;
xparams->maxparts = 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendamount passing maxparts = 1 as the user limit also incidentally stops the relax-to-0 that could hit assert(attempt->payment->maxparts == 1) in attempt_mpp_amount() (xpay.c:418) for includefees payments, which is a good thing; worth a sentence in the commit message.

Comment thread plugins/xpay/xpay.c
xparams->layers = layers;
xparams->retryfor = *retryfor;
xparams->maxdelay = *maxdelay;
xparams->maxparts = 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: sendamount passing maxparts = 1 as the user limit also incidentally stops the relax-to-0 that could hit assert(attempt->payment->maxparts == 1) in attempt_mpp_amount() (xpay.c:418) for includefees payments, which is a good thing; worth a sentence in the commit message.

Comment thread plugins/xpay/xpay.c Outdated
&invoice_msat, maxfee, layers, *retryfor, NULL, *maxdelay,
label, NULL, false, false, send_msat);
return xpay_core(cmd, invstring, &invoice_msat, maxfee, layers,
*retryfor, NULL, *maxdelay, /* maxparts = */ 1, label,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: sendamount passing maxparts = 1 as the user limit also incidentally stops the relax-to-0 that could hit assert(attempt->payment->maxparts == 1) in attempt_mpp_amount() (xpay.c:418) for includefees payments, which is a good thing; worth a sentence in the commit message.

@Lagrang3 Lagrang3 modified the milestones: v26.12, v27.03 Nov 16, 2026
Changelog-Added: xpay: option maxparts to limit the number of concurrent payment parts in Multi-Path-Payments

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
@Lagrang3

Copy link
Copy Markdown
Collaborator Author

I have changed this a little bit to avoid some the issues raised in the comments:

  • payment keeps a disable_mpp flag,
  • on getroutes failure we cannot relax maxpart if disable_mpp is set,
  • instead of abusing use_maxparts, we only set it to a number different from zero if actually set by the user,
  • payment keeps a payment_type variable, it could be one of the following XPAY, XKEYSEND and SENDAMOUNT, each one has its own decision matrix for the final value of maxparts and disable_mpp,

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants