Skip to content

Parallel pathfinding and other things - #319

Merged
elnosh merged 7 commits into
bitcoin-dev-project:mainfrom
elnosh:parallel-pathfinding
Sep 16, 2026
Merged

elnosh merged 7 commits into
bitcoin-dev-project:mainfrom
elnosh:parallel-pathfinding

Conversation

@elnosh

@elnosh elnosh commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

I was running with a simulated network of ~26k channels and it was very slow. From looking at perf results it seems majority of time is spent on pathfinding. Not that pathfinding is slow but in a network with ~26k channels and default simulation values (send multiplier), the simulation will generate a lot of payments making majority of time spent on pathfinding. The payment volume increases a lot because each node is set to send some multiplier of its capacity per certain period. With high channel count, this will spike the payment generation.

Some things done here:

  • I didn't know this but even on a current_thread runtime, spawn_blocking will spawn additional threads for blocking operations. So use that to parallelize pathfinding.
  • Some mutex changes and unnecessary locks taken for the scorer and LightningNode.
  • Bumped ldk to 0.2. We were on 0.0.123 which was a bit old. Pathfinder is a bit faster since then so bumped that dep.

And just reducing the multiplier to generate less payments helped.

elnosh and others added 6 commits September 15, 2026 17:34
…e sync

The scorer is only ever accessed under the node's outer lock (both
send_payment and track_payment run with it held), so a tokio mutex buys
nothing.

A read-write lock rather than a mutex because LDK splits its scorer traits
along the same line. Pathfinding goes through ScoreLookUp, which only takes
&self, while ScoreUpdate needs &mut self and is only used to feed payment
results back in. Routes for one node can therefore be computed concurrently
under a shared read guard.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Move pathfinding for each payment to a spawn_blocking task.
Routes for different payments are then computed in parallel, under
a shared read guard on the node's scorer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…..>>

Every LightningNode method already takes &self, and every implementation is
internally sync. The real backends keep their RPC clients behind a
mutex, and SimNode guards its in-flight, network and scorer behing a mutex.
The outer mutex therefore protected nothing.

Drop the mutex and add Sync to the trait bound, which every implementation
already satisfies. Nodes are now shared as Arc<dyn LightningNode> and their
methods called directly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@elnosh
elnosh force-pushed the parallel-pathfinding branch from 2e58c74 to 5f88c81 Compare September 15, 2026 21:36
@elnosh
elnosh force-pushed the parallel-pathfinding branch from 5f88c81 to d3c2575 Compare September 15, 2026 21:38

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

Nice clean up! Haven't looked deeply into the paused runtime workings but will take your/claude's word for it!

@elnosh
elnosh merged commit ed9a51a into bitcoin-dev-project:main Sep 16, 2026
2 checks passed
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.

2 participants