From 6d2502bd6942950338fe24f964151473696605c4 Mon Sep 17 00:00:00 2001 From: amackillop Date: Fri, 15 May 2026 06:28:19 -0700 Subject: [PATCH] Generalize find_route to take RouteParameters 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. --- src/lib.rs | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a1183c1bb..46ea19d07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,8 +144,9 @@ use lightning::ln::channelmanager::PaymentId; use lightning::ln::funding::SpliceContribution; use lightning::ln::msgs::SocketAddress; use lightning::routing::gossip::NodeAlias; -use lightning::routing::router::{PaymentParameters, RouteParameters}; -pub use lightning::routing::router::{Route, RouteParametersConfig}; +pub use lightning::routing::router::{ + PaymentParameters, Route, RouteParameters, RouteParametersConfig, +}; use lightning::util::persist::KVStoreSync; use lightning_background_processor::process_events_async; use liquidity::{LSPS1Liquidity, LiquiditySource}; @@ -1890,41 +1891,23 @@ impl Node { .to_sat_per_kwu() } - /// Finds a route to `payee` for `amount_msat` using the node's internal router. + /// Finds a route for the given [`RouteParameters`] using the node's internal router. /// - /// Intended for callers that need to introspect routing fees ahead of - /// time (e.g. computing a max-sendable estimate by inverting per-hop fees). + /// Intended for callers that need to introspect routing fees ahead of time (e.g. computing + /// a max-sendable estimate). Build the parameters with [`PaymentParameters::from_node_id`] + /// for a clear-network pubkey, [`PaymentParameters::from_bolt11_invoice`] to fold a + /// BOLT11's private route hints into the cost function, or + /// [`PaymentParameters::from_bolt12_invoice`] for blinded payment paths. /// - /// `params` overrides the node-wide [`RouteParametersConfig`] when `Some`; otherwise - /// the value from [`Config::route_parameters`] is used. + /// The node-wide [`RouteParametersConfig`] in [`Config::route_parameters`] is not applied + /// automatically; overlay it onto `route_params` before calling if you want those caps. /// /// [`Config::route_parameters`]: crate::config::Config::route_parameters - pub fn find_route( - &self, payee: PublicKey, amount_msat: u64, params: Option, - ) -> Result { + pub fn find_route(&self, route_params: RouteParameters) -> Result { if !*self.is_running.read().unwrap() { return Err(Error::NotRunning); } - let mut route_params = RouteParameters::from_payment_params_and_value( - PaymentParameters::from_node_id(payee, LDK_DEFAULT_FINAL_CLTV_EXPIRY_DELTA), - amount_msat, - ); - - if let Some(RouteParametersConfig { - max_total_routing_fee_msat, - max_total_cltv_expiry_delta, - max_path_count, - max_channel_saturation_power_of_half, - }) = params.as_ref().or(self.config.route_parameters.as_ref()) - { - route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat; - route_params.payment_params.max_total_cltv_expiry_delta = *max_total_cltv_expiry_delta; - route_params.payment_params.max_path_count = *max_path_count; - route_params.payment_params.max_channel_saturation_power_of_half = - *max_channel_saturation_power_of_half; - } - let payer = self.channel_manager.get_our_node_id(); let first_hops = self.channel_manager.list_usable_channels(); let first_hops_refs: Vec<&LdkChannelDetails> = first_hops.iter().collect(); @@ -1938,7 +1921,7 @@ impl Node { inflight_htlcs, ) .map_err(|e| { - log_debug!(self.logger, "Failed to find route to {}: {}", payee, e); + log_debug!(self.logger, "Failed to find route: {}", e); Error::RouteNotFound }) }