Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define NetworkGraph Trait for Flexible Routing #24

Merged
merged 5 commits into from
Jul 29, 2024
Merged

Conversation

tareknaser
Copy link
Collaborator

Description

This pull request defines the NetworkGraph trait in barq-common, to enhance routing flexibility

Key Changes:

  1. Define NetworkGraph Trait

    • Includes methods for handling network graphs with channels, nodes, and peer-to-peer information.
    • Renames Edge to Channel
    • Adds a strategy field to BarqPayRequest and BarqRouteInfoRequest.
  2. Introduce Modules for Handling Different Network Graph Sources

    • Defines two new modules in barq-plugin:
      • methods::graph::cln: Uses information from CLN's listchannels.
      • methods::graph::p2p: Uses data from the gossip map.
    • Each module provides a function to build the respective graph.
    • Updates pay and routeinfo commands to choose the appropriate graph source based on the specified strategy, defaulting to "direct" if not specified.
  3. Fix Tests

For more detailed information, please refer to the individual commit messages and bodies.

This commit introduces a `NetworkGraph` trait in `barq-common`, to allow for more flexibility in routing algorithms by supporting various graph structures.

The `NetworkGraph` trait includes methods to handle network graphs with channels, nodes, and peer-to-peer information. This update includes:
- Defining a `NetworkGraph` trait with methods to get channels, nodes, individual nodes and channels by ID, and to check for peer-to-peer information.
- Renaming `Edge` to `Channel` to better reflect its role in the network graph.
- Adding a `strategy` field to `BarqPayRequest` and `BarqRouteInfoRequest` to specify routing strategies.

Signed-off-by: Tarek <[email protected]>
…ources

- Introduce two modules in `barq-plugin` to manage network graph data:
    - `methods::graph::cln`: Uses information from CLN's `listchannels`.
    - `methods::graph::p2p`: Uses data from the gossip map.
- Each module exposes a function to return the respective graph.
- Update `barq-plugin` commands (`pay` and `routeinfo`) to select the appropriate graph source based on the specified strategy:
    - If the strategy is "probabilistic", use the `p2p` graph for routing with LDK.
    - Otherwise, use the `cln` graph based on CLN's `listchannels`.
    - Default to the "direct" routing strategy if the user does not specify a strategy.

Signed-off-by: Tarek <[email protected]>
@tareknaser
Copy link
Collaborator Author

Should also fix #10

Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

Ok unfortunatly this need another iteration

barq-common/src/algorithms/direct.rs Outdated Show resolved Hide resolved
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Edge {
pub struct Channel {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like to call this edge, then in the lightning network is a channel, but in a graph is always an edge

assert!(graph.get_edge("channel1").is_some());
assert_eq!(graph.get_node("node1").unwrap().channels.len(), 1);
}
/// Whether or not the network graph has peer-to-peer information (e.g., gossip map).
Copy link
Collaborator

Choose a reason for hiding this comment

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

graph has peer-to-peer network information

// If no strategy can be applied, return None
Ok(None)
// For now, we will just use the direct strategy
Ok(Some(Box::new(Direct::new())))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use the Arc::new()? Arch it is a little bit better to pass around

Comment on lines +16 to +17
nodes: HashMap<String, Node>,
channels: HashMap<String, Channel>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok but I think this si still slow, but in this case we can't do better

barq-plugin/src/methods/pay.rs Outdated Show resolved Hide resolved
barq-plugin/src/methods/pay.rs Outdated Show resolved Hide resolved
barq-plugin/src/methods/route_info.rs Outdated Show resolved Hide resolved
@@ -31,7 +31,7 @@ def test_pay_amounts(node_factory):
l1.rpc.call("barqpay", {"bolt11_invoice": inv})

invoice = only_one(l2.rpc.listinvoices('test_pay_amounts')['invoices'])
assert invoice['amount_received_msat'] >= Millisatoshi(123000)
assert invoice['amount_msat'] >= Millisatoshi(123000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to explain in the commit body why, also for me that I am a contributor of core lightning, this does not make any sense

@vincenzopalazzo vincenzopalazzo merged commit 4fd3ebb into main Jul 29, 2024
1 of 2 checks passed
@vincenzopalazzo vincenzopalazzo deleted the graph_trait branch July 29, 2024 08:03
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