Skip to content

Commit

Permalink
Implement conversion from LDK route to Barq Route Output
Browse files Browse the repository at this point in the history
  • Loading branch information
raehat authored and vincenzopalazzo committed Aug 4, 2024
1 parent ce2d58f commit 409b4fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion barq-common/src/algorithms/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;

use crate::strategy::{RouteHop, RouteInput, RouteOutput, Strategy};

const DEFAULT_DELAY: u64 = 9;
const DEFAULT_DELAY: u32 = 9;

/// A routing strategy that attempts to find a direct route from the source to
/// the destination.
Expand Down
30 changes: 25 additions & 5 deletions barq-common/src/algorithms/probabilistic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lampo_common::ldk::util::logger::Logger;
use lampo_common::utils::logger::LampoLogger;

use crate::graph::NetworkGraph;
use crate::strategy::{RouteInput, RouteOutput, Strategy};
use crate::strategy::{RouteHop, RouteInput, RouteOutput, Strategy};

/// A routing strategy that uses the LDK crates to find the best route.
pub struct LDKRoutingStrategy<L>
Expand Down Expand Up @@ -54,10 +54,30 @@ where
}

fn convert_route_to_output(route: Route) -> RouteOutput {
let _route = route;
// TODO: Implement the logic to convert the LDK Route to RouteOutput

unimplemented!("convert_route_to_output not implemented yet.")
let path = route.paths.first().expect("No LDK path available");
let mut amt_to_forward = 0;
let mut delay = 0;

let output_path: Vec<RouteHop> = path
.hops
.iter()
.rev()
.map(|hop| {
amt_to_forward += hop.fee_msat;
delay += hop.cltv_expiry_delta;

RouteHop::new(
hop.pubkey.to_string(),
hop.short_channel_id.to_string(),
delay,
amt_to_forward,
)
})
.collect();

RouteOutput {
path: output_path.into_iter().rev().collect(),
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions barq-common/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ pub trait Strategy {
pub struct RouteHop {
pub id: String,
pub channel: String,
pub delay: u64,
pub delay: u32,
pub amount_msat: u64,
}

impl RouteHop {
/// Create a new `RouteHop` instance with the provided fields
pub fn new(id: String, channel: String, delay: u64, amount_msat: u64) -> Self {
pub fn new(id: String, channel: String, delay: u32, amount_msat: u64) -> Self {
RouteHop {
id,
channel,
Expand Down

0 comments on commit 409b4fe

Please sign in to comment.