Skip to content

askrene: skip redundant small-channel layer for single-path routing - #9750

Open
decodekush wants to merge 1 commit into
ElementsProject:masterfrom
decodekush:fix-askrene-single-path-quadratic-lag
Open

decodekush wants to merge 1 commit into
ElementsProject:masterfrom
decodekush:fix-askrene-single-path-quadratic-lag

Conversation

@decodekush

Copy link
Copy Markdown

Problem

As reported in #9739 by @ksedgwic, calling getroutes with maxparts=1 freezes the askrene plugin before the route search even begins.

When maxparts == 1, do_getroutes() builds the temporary layer auto.remove_small_channels to disable every channel smaller than the requested amount. Applying this layer calls find_localmod(), which does a linear scan from the start of localmods->mods for each update. On mainnet gossip (~50,000 channels), this triggers an $O(N^2)$ scan of ~40,000 updates that stalls the main plugin process synchronously for up to 42 seconds before forking the child router.

Solution

Skip constructing the small-channel layer for single-path routing.

remove_small_channel_layer() was originally added in #8059 as a workaround to force the old MCF solver to find single paths. The dedicated single-path Dijkstra solver added in #8299 (init_linear_network_single_path()) already checks channel capacities in $O(1)$ time during graph construction, making the artificial disabling layer redundant.

Removing this layer drops setup time on real gossip data from 13.9s to 0.017s for 2,000,000 sat calls. It also resolves the longstanding # FIXME: the explanation for the failure is wrong in test_getroutes_single_path, accurately reporting that a channel isn't big enough rather than claiming it was disabled by an internal layer.

Fixes #9739

Checklist

@decodekush
decodekush requested a review from Lagrang3 as a code owner November 19, 2026 12:39
Copilot AI balanced review requested due to automatic review settings November 19, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

When maxparts == 1, do_getroutes() previously built and applied
the temporary layer auto.remove_small_channels, adding disabling updates
for every channel whose capacity was below the payment amount. On a
typical network graph with tens of thousands of channels, applying this
layer triggered an O(N^2) scan in gossmap_local_updatechan() via
find_localmod(), blocking askrene's main event loop for seconds to tens
of seconds before the search even began.

The single-path Dijkstra solver (init_linear_network_single_path)
already excludes channels with insufficient capacity during graph
initialization in O(1) time per channel. The small-channel layer was an
artifact of the original MCF solver (ElementsProject#8059) before the single-path
solver existed (ElementsProject#8299).

Remove remove_small_channel_layer and avoid constructing this layer.
Also update test_getroutes_single_path failure assertions now that
askrene accurately reports capacity shortfall rather than an artificial
layer disablement, and add a regression test verifying sub-second
getroutes setup with maxparts=1 on real gossip data.

Fixes: ElementsProject#9739
Changelog-Fixed: askrene: eliminate quadratic setup lag on single-path getroutes calls
Signed-off-by: decodekush <kushagraagarwal1612@gmail.com>
@decodekush
decodekush force-pushed the fix-askrene-single-path-quadratic-lag branch from 0801e06 to 99003a2 Compare November 19, 2026 12:51

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.

askrene: getroutes with maxparts=1 spends seconds before the search starts (quadratic in the channels below the amount)

2 participants