Skip to content

Conversation

chuksys
Copy link
Contributor

@chuksys chuksys commented Sep 10, 2025

This PR builds upon the work done here #273

This PR introduces a new PathFinder trait which allows for more flexible pathfinding. Instead of being locked into the LDK pathfinding algorithm, custom pathfinding algorithms can be swapped in. A DefaultPathFinder has been provided to maintain backwards compatibility.

Copy link
Contributor Author

@chuksys chuksys left a comment

Choose a reason for hiding this comment

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

Shared some thoughts.

amount_msat: u64,
pathfinding_graph: &LdkNetworkGraph,
) -> Result<Route, SimulationError> {
let scorer_graph = NetworkGraph::new(bitcoin::Network::Regtest, Arc::new(WrappedLog {}));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes more sense to pass in this graph rather than instantiating it every time.

use super::*;

#[test]
fn test_create_activity() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this helper function is still needed in this PR

Comment on lines 263 to 266
=======
pub async fn create_simulation_with_network<P: for<'a> PathFinder<'a> + Clone + 'static>(
cli: &Cli,
>>>>>>> 59dbbe6 (Add pathfinder trait)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some of the commits in between seem to have these from conflicts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - will fix before taking it out of draft. Thanks!

Comment on lines 573 to 581
let scorer_graph = NetworkGraph::new(bitcoin::Network::Regtest, Arc::new(WrappedLog {}));
let mut scorers = self.scorers.lock().await;
let scorer = scorers.entry(*source).or_insert_with(|| {
ProbabilisticScorer::new(
ProbabilisticScoringDecayParameters::default(),
Arc::new(scorer_graph),
Arc::new(WrappedLog {}),
)
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not following - could you explain why does it need a map and one scorer per sender?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding, having one scorer per node gives us more realistic pathfinding as this is close to the real-world behaviour of the Lightning Network (each node is responsible for its own pathfinding), so simulations would be run under real-world conditions.

Copy link
Collaborator

@elnosh elnosh Sep 11, 2025

Choose a reason for hiding this comment

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

right, I'm wondering because each SimNode has a Pathfinder and each time a node is being instantiated in ln_node_from_graph, the pathfinder is cloned. So IIUC, the entire map with all scorers will be cloned on every SimNode. Perhaps it should be in an Arc?

edit: I'm wrong - I see the map in ScorersMap is behind an Arc

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, here it's creating a new empty graph for each scorer. Shouldn't it use the already existing graph

Copy link
Collaborator

Choose a reason for hiding this comment

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

On a second look, I'm still not sure on why we need a map to keep track of all scorers. If each SimNode has a Pathfinder then I don't see why it's needed for the DefaultPathfinder of every SimNode to have that map. Each Pathfinder for each SimNode would only need its own scorer + the network graph no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, here it's creating a new empty graph for each scorer. Shouldn't it use the already existing graph

Yeah, you are right - left a comment about that above . Still thinking of the best approach as the type needed for the scorer graph is slightly different from the type of network graph we have currently.

On a second look, I'm still not sure on why we need a map to keep track of all scorers. If each SimNode has a Pathfinder then I don't see why it's needed for the DefaultPathfinder of every SimNode to have that map. Each Pathfinder for each SimNode would only need its own scorer + the network graph no?

Yeah this makes sense! If the DefaultPathfinder holds its own scorer, that gives us one scorer per node.

Comment on lines 546 to 549
pub struct DefaultPathFinder {
scorers: ScorersMap,
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

feels like this should have a NetworkGraph

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - thought of that but also considering allowing the user pass in the NetworkGraph (for scoring) directly into the find_route method as an Option or perhaps we could somehow still use the pathfinding_graph already being passed into find_route - What do you think?

Copy link
Collaborator

@elnosh elnosh Sep 11, 2025

Choose a reason for hiding this comment

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

hmmmm API-wise not sure what's best but I'd think that find_route in the Pathfinder could do without having to pass the network graph? A pathfinder impl can have it's own view of the network and based on sender and destination pubkeys and the amount return a Route.

Edit: internally the DefaultPathfinder could use the graph we already have for scoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Edit: internally the DefaultPathfinder could use the graph we already have for scoring.

Yeah! That makes sense.

@chuksys chuksys marked this pull request as ready for review September 16, 2025 17:59
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.

3 participants