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.

@decodekush
decodekush force-pushed the fix-askrene-single-path-quadratic-lag branch from 0801e06 to 99003a2 Compare November 19, 2026 12:51

@Andezion Andezion 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.

Impressions can raise the limit above capacity. In layer_apply_constraints() (look at layer.c at line 1169to 1173), an impression in the opposite direction increases max. That path is used when capacities[idx] == 0 (channels with layer intel or reservations). So maxcap can exceed the channel s real capacity. The old layer disabled the channel based on raw capacity no matter what, and now the solver may pick it

also later rounds use a smaller amount. In linear_routes() (at file mcf.c at line 1567), if refine_flows() trims the first path, the next round calls single_path_flow() with a smaller amount_to_deliver. small channels the layer used to block can now be chosen. reduce_num_flows() still enforces one part, so i expect the same outcome, but possibly a different error message?

Comment thread tests/test_askrene.py Resolved
Comment thread tests/test_askrene.py Resolved
@decodekush
decodekush force-pushed the fix-askrene-single-path-quadratic-lag branch from 99003a2 to bb5d6a5 Compare November 19, 2026 19:27
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. 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:
- Explicitly check gossmap_chan_get_capacity in init_linear_network_single_path
  to skip insufficient capacity channels in O(1) time.
- In route_query:get_constraints(), cap max liquidity at the channel's
  on-chain capacity to ensure reverse impressions cannot inflate the bound
  past physical capacity.
- In test_getroutes_single_path, verify deterministic capacity shortfall
  reporting and test that reverse impressions cannot bypass capacity bounds.
- In test_single_part_setup_time, mark as slow_test, drop unused bitcoind
  fixture and secondary node, narrow broken_log, and benchmark relative
  to default getroutes setup and search duration.

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 bb5d6a5 to 4edaad5 Compare November 19, 2026 19:42
@decodekush

Copy link
Copy Markdown
Author

Thanks for the review @Andezion. I've addressed all the feedback and pushed an updated commit with the following changes:

  1. Impressions exceeding capacity:

    • Clamped *max to gossmap_chan_get_capacity in route_query.c:get_constraints(), so reverse impressions can't inflate liquidity past real on-chain capacity.
    • Also added an explicit capacity < amount check in init_linear_network_single_path() to skip small channels in O(1) upfront.
    • Added an assertion in test_getroutes_single_path to verify reverse impressions don't bypass capacity limits.
  2. Later solver rounds:

    • If refine_flows() trims the first flow, reduce_num_flows() at line 1846 still enforces maxparts=1 and fails if everything can't fit into one part.
  3. Test cleanups (test_single_part_setup_time):

    • Added @pytest.mark.slow_test.
    • Dropped the unused bitcoind fixture and second node (l2), querying nodes directly from the gossip store with a single node.
    • Narrowed broken_log to 'Throttling (incoming|outgoing) peer'.
    • Used searches to verify call setup overhead is small (times[maxparts] - searches[-1]/1000 < 1.0).
    • Compared against default getroutes (times[1] < times[None] * 5 + 1) instead of the hardcoded 2s limit.

Also rebased cleanly onto latest master. All unit and integration tests are passing.

@decodekush
decodekush requested a review from Andezion November 19, 2026 20:12

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)

3 participants