Skip to content

[wip] Xpay limit path length - #9627

Draft
Lagrang3 wants to merge 6 commits into
ElementsProject:masterfrom
Lagrang3:xpay-limit-path-length
Draft

Lagrang3 wants to merge 6 commits into
ElementsProject:masterfrom
Lagrang3:xpay-limit-path-length

Conversation

@Lagrang3

@Lagrang3 Lagrang3 commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Addresses: #9156
Supersedes: #9539

This PR adds a new constraint into askrene: maxhops, to limit the length of the routes.
Hard constraints of path length is not possible under the current implementation, minimum cost flows
do not allow that. Our approach is to add a constant cost per hop (a similar tweak in renepay #7540 was already deployed)
and scale that cost until the computed routes fit the maxhops constraints.
Fewer hops are expected with a base cost per hops and a getroutes failure if no routing solutions
are found satisfying maxhops constraint.

On xpay we compute the onion budget for each payment as the maximum number of hops we can afford to put inside
an onion message given the hard limit of 1300 bytes for the onion package, payment amount, blockheight and tail
(ie. final payload in the case of bolt11 and blinded path plus final payload in the case of bolt12).
The onion budget is passed down to getroutes so that solutions will not exceed it.
No more "Could not create payment onion: path too long!" errors are expected afterwards, instead we might
get an error from getroutes if no solutions can be found with the maxhops limit.

TODO:

  • unit test onion_budget,
  • implement the cost based maxhops constraint into askrene,
  • integration test for maxhops in askrene,
  • integration test for xpay with heavy final payloads bolt11,
  • integration test for xpay with heavy final payloads bolt12,
  • promote maxhops from a developer option to a user option and add documentation for maxhops,

@Lagrang3 Lagrang3 added this to the v26.12 milestone Oct 14, 2026
@Lagrang3
Lagrang3 marked this pull request as draft October 14, 2026 08:40
@Lagrang3
Lagrang3 force-pushed the xpay-limit-path-length branch 2 times, most recently from 8045aef to 4eda748 Compare October 15, 2026 10:12
Add onion budget and payload constructors to the internal xpay API.
Onion budget computation can be used to know a realistic number of hops
that constraints our payment before calling askrene.

Changelog-None

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

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Added an homogeneous and constant cost to every hop in the MCF solver.
We have also added a developer option "maxhops" to limit the length of
routes.  The algorithm is based on the added cost per-hop.  In order to
seek for a solution that satisfies the maxhops constraint the cost per
hops is incremented gradually.

Changelog-Fixed: askrene-getroutes: penalizes every extra hop in every route with an homogeneous and constant probability of failure of 1%, as a consequence askrene will slightly prefer smaller routes.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Changelog-Added: askrene: getroutes: maxhops, a parameter to limit the length of the paths in the solutions.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
Changelog-Fixed: xpay: Clamp the length of the payment routes using askrene's maxhops option aiming at producing routes that fit the data limits in the onion packet.

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

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
@Lagrang3
Lagrang3 force-pushed the xpay-limit-path-length branch from 4eda748 to f79367b Compare October 16, 2026 20:50

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.

1 participant