Skip to content

Commit f13fcea

Browse files
authored
Generalize find_route to take RouteParameters (#32)
The previous find_route(payee, amount_msat, params) signature built PaymentParameters::from_node_id internally, throwing away the private route hints carried in BOLT11 invoices and the blinded payment paths carried in BOLT12 invoices. The underlying router handles both shapes fine; the API was hiding them. Callers now build RouteParameters themselves with the appropriate PaymentParameters::from_* constructor and pass it in. The node-wide RouteParametersConfig is no longer overlaid implicitly. Different destination shapes want different caps, and overlaying the clear- pubkey defaults onto invoice-derived params would clobber the hint and blinded-path data the new API is meant to preserve. PaymentParameters and RouteParameters are re-exported from lightning::routing::router so callers do not pull in rust-lightning directly.
1 parent 6e4b518 commit f13fcea

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

src/lib.rs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ use lightning::ln::channelmanager::PaymentId;
144144
use lightning::ln::funding::SpliceContribution;
145145
use lightning::ln::msgs::SocketAddress;
146146
use lightning::routing::gossip::NodeAlias;
147-
use lightning::routing::router::{PaymentParameters, RouteParameters};
148-
pub use lightning::routing::router::{Route, RouteParametersConfig};
147+
pub use lightning::routing::router::{
148+
PaymentParameters, Route, RouteParameters, RouteParametersConfig,
149+
};
149150
use lightning::util::persist::KVStoreSync;
150151
use lightning_background_processor::process_events_async;
151152
use liquidity::{LSPS1Liquidity, LiquiditySource};
@@ -1890,41 +1891,23 @@ impl Node {
18901891
.to_sat_per_kwu()
18911892
}
18921893

1893-
/// Finds a route to `payee` for `amount_msat` using the node's internal router.
1894+
/// Finds a route for the given [`RouteParameters`] using the node's internal router.
18941895
///
1895-
/// Intended for callers that need to introspect routing fees ahead of
1896-
/// time (e.g. computing a max-sendable estimate by inverting per-hop fees).
1896+
/// Intended for callers that need to introspect routing fees ahead of time (e.g. computing
1897+
/// a max-sendable estimate). Build the parameters with [`PaymentParameters::from_node_id`]
1898+
/// for a clear-network pubkey, [`PaymentParameters::from_bolt11_invoice`] to fold a
1899+
/// BOLT11's private route hints into the cost function, or
1900+
/// [`PaymentParameters::from_bolt12_invoice`] for blinded payment paths.
18971901
///
1898-
/// `params` overrides the node-wide [`RouteParametersConfig`] when `Some`; otherwise
1899-
/// the value from [`Config::route_parameters`] is used.
1902+
/// The node-wide [`RouteParametersConfig`] in [`Config::route_parameters`] is not applied
1903+
/// automatically; overlay it onto `route_params` before calling if you want those caps.
19001904
///
19011905
/// [`Config::route_parameters`]: crate::config::Config::route_parameters
1902-
pub fn find_route(
1903-
&self, payee: PublicKey, amount_msat: u64, params: Option<RouteParametersConfig>,
1904-
) -> Result<Route, Error> {
1906+
pub fn find_route(&self, route_params: RouteParameters) -> Result<Route, Error> {
19051907
if !*self.is_running.read().unwrap() {
19061908
return Err(Error::NotRunning);
19071909
}
19081910

1909-
let mut route_params = RouteParameters::from_payment_params_and_value(
1910-
PaymentParameters::from_node_id(payee, LDK_DEFAULT_FINAL_CLTV_EXPIRY_DELTA),
1911-
amount_msat,
1912-
);
1913-
1914-
if let Some(RouteParametersConfig {
1915-
max_total_routing_fee_msat,
1916-
max_total_cltv_expiry_delta,
1917-
max_path_count,
1918-
max_channel_saturation_power_of_half,
1919-
}) = params.as_ref().or(self.config.route_parameters.as_ref())
1920-
{
1921-
route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat;
1922-
route_params.payment_params.max_total_cltv_expiry_delta = *max_total_cltv_expiry_delta;
1923-
route_params.payment_params.max_path_count = *max_path_count;
1924-
route_params.payment_params.max_channel_saturation_power_of_half =
1925-
*max_channel_saturation_power_of_half;
1926-
}
1927-
19281911
let payer = self.channel_manager.get_our_node_id();
19291912
let first_hops = self.channel_manager.list_usable_channels();
19301913
let first_hops_refs: Vec<&LdkChannelDetails> = first_hops.iter().collect();
@@ -1938,7 +1921,7 @@ impl Node {
19381921
inflight_htlcs,
19391922
)
19401923
.map_err(|e| {
1941-
log_debug!(self.logger, "Failed to find route to {}: {}", payee, e);
1924+
log_debug!(self.logger, "Failed to find route: {}", e);
19421925
Error::RouteNotFound
19431926
})
19441927
}

0 commit comments

Comments
 (0)