X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Frouter.rs;h=0ad307cdf2f17bf1a347b535ebf5009e9a000c14;hb=13a33409b519e57b7d14cd9e440223d3495d55eb;hp=c53e46157d5dc74941bb0dee94886a06f3d5f83f;hpb=bb62420b0f020d539944c8df8799b65a93f7cf7f;p=rust-lightning diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index c53e4615..0ad307cd 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -249,14 +249,12 @@ impl<'a> PaymentPath<'a> { // If the amount transferred by the path is updated, the fees should be adjusted. Any other way // to change fees may result in an inconsistency. // - // Sometimes we call this function right after constructing a path which has inconsistent - // (in terms of reaching htlc_minimum_msat), so that this function puts the fees in order. - // In that case we call it on the "same" amount we initially allocated for this path, and which - // could have been reduced on the way. In that case, there is also a risk of exceeding - // available_liquidity inside this function, because the function is unaware of this bound. - // In our specific recomputation cases where we never increase the value the risk is pretty low. - // This function, however, does not support arbitrarily increasing the value being transferred, - // and the exception will be triggered. + // Sometimes we call this function right after constructing a path which is inconsistent in + // that it the value being transferred has decreased while we were doing path finding, leading + // to the fees being paid not lining up with the actual limits. + // + // Note that this function is not aware of the available_liquidity limit, and thus does not + // support increasing the value being transferred. fn update_value_and_recompute_fees(&mut self, value_msat: u64) { assert!(value_msat <= self.hops.last().unwrap().0.fee_msat); @@ -478,7 +476,13 @@ pub fn get_route(our_node_id: &PublicKey, network: &NetworkGraph, paye let empty_channel_features = ChannelFeatures::empty(); - let mut targets = BinaryHeap::new(); //TODO: Do we care about switching to eg Fibbonaci heap? + // The main heap containing all candidate next-hops sorted by their score (max(A* fee, + // htlc_minimum)). Ideally this would be a heap which allowed cheap score reduction instead of + // adding duplicate entries when we find a better path to a given node. + let mut targets = BinaryHeap::new(); + + // Map from node_id to information about the best current path to that node, including feerate + // information. let mut dist = HashMap::with_capacity(network.get_nodes().len()); // During routing, if we ignore a path due to an htlc_minimum_msat limit, we set this, @@ -3847,7 +3851,8 @@ mod tests { }); #[cfg(require_route_graph_test)] return Ok(res.expect("Didn't have route graph and was configured to require it")); - res + #[cfg(not(require_route_graph_test))] + return res; } pub(super) fn random_init_seed() -> u64 { @@ -3918,7 +3923,6 @@ mod benches { use super::*; use util::logger::{Logger, Record}; - use std::fs::File; use test::Bencher; struct DummyLogger {}