X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Frouter.rs;h=ed40f4641a4a0c109683acffd29ead94a007fcd5;hb=22855821327c05775778c5680fc34c0f1dc3c79b;hp=6df36382d33df262433956ab1b23059c70f0de5f;hpb=a41f6a31f5fb82320d1f32e6276146f2784e8be5;p=rust-lightning diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 6df36382..ed40f464 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -18,7 +18,7 @@ use ln::channelmanager::ChannelDetails; use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures}; use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT}; use routing::scoring::Score; -use routing::network_graph::{DirectedChannelInfo, EffectiveCapacity, NetworkGraph, NodeId, RoutingFees}; +use routing::network_graph::{DirectedChannelInfoWithUpdate, EffectiveCapacity, NetworkGraph, NodeId, RoutingFees}; use util::ser::{Writeable, Readable}; use util::logger::{Level, Logger}; @@ -355,8 +355,7 @@ enum CandidateRouteHop<'a> { }, /// A hop found in the [`NetworkGraph`], where the channel capacity may or may not be known. PublicHop { - // `DirectedChannelInfo::direction` MUST NOT be `None`. - info: DirectedChannelInfo<'a, 'a>, + info: DirectedChannelInfoWithUpdate<'a>, short_channel_id: u64, }, /// A hop to the payee found in the payment invoice, though not necessarily a direct channel. @@ -374,6 +373,7 @@ impl<'a> CandidateRouteHop<'a> { } } + // NOTE: This may copy bytes to so avoid calling it in a hot code path. fn features(&self) -> ChannelFeatures { match self { CandidateRouteHop::FirstHop { details } => details.counterparty.features.to_context(), @@ -385,9 +385,7 @@ impl<'a> CandidateRouteHop<'a> { fn cltv_expiry_delta(&self) -> u32 { match self { CandidateRouteHop::FirstHop { .. } => 0, - CandidateRouteHop::PublicHop { info, .. } => { - info.direction().unwrap().cltv_expiry_delta as u32 - }, + CandidateRouteHop::PublicHop { info, .. } => info.direction().cltv_expiry_delta as u32, CandidateRouteHop::PrivateHop { hint } => hint.cltv_expiry_delta as u32, } } @@ -395,9 +393,7 @@ impl<'a> CandidateRouteHop<'a> { fn htlc_minimum_msat(&self) -> u64 { match self { CandidateRouteHop::FirstHop { .. } => 0, - CandidateRouteHop::PublicHop { info, .. } => { - info.direction().unwrap().htlc_minimum_msat - }, + CandidateRouteHop::PublicHop { info, .. } => info.direction().htlc_minimum_msat, CandidateRouteHop::PrivateHop { hint } => hint.htlc_minimum_msat.unwrap_or(0), } } @@ -407,7 +403,7 @@ impl<'a> CandidateRouteHop<'a> { CandidateRouteHop::FirstHop { .. } => RoutingFees { base_msat: 0, proportional_millionths: 0, }, - CandidateRouteHop::PublicHop { info, .. } => info.direction().unwrap().fees, + CandidateRouteHop::PublicHop { info, .. } => info.direction().fees, CandidateRouteHop::PrivateHop { hint } => hint.fees, } } @@ -1076,18 +1072,16 @@ where L::Target: Logger { for chan_id in $node.channels.iter() { let chan = network_channels.get(chan_id).unwrap(); if !chan.features.requires_unknown_bits() { - let directed_channel = + let (directed_channel, source) = chan.as_directed_to(&$node_id).expect("inconsistent NetworkGraph"); - let source = directed_channel.source(); - let target = directed_channel.target(); if first_hops.is_none() || *source != our_node_id { if let Some(direction) = directed_channel.direction() { if direction.enabled { let candidate = CandidateRouteHop::PublicHop { - info: directed_channel, + info: directed_channel.with_update().unwrap(), short_channel_id: *chan_id, }; - add_entry!(candidate, *source, *target, $fee_to_target_msat, $next_hops_value_contribution, $next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat, $next_hops_cltv_delta); + add_entry!(candidate, *source, $node_id, $fee_to_target_msat, $next_hops_value_contribution, $next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat, $next_hops_cltv_delta); } } } @@ -1162,7 +1156,7 @@ where L::Target: Logger { let candidate = network_channels .get(&hop.short_channel_id) .and_then(|channel| channel.as_directed_to(&target)) - .and_then(|channel| channel.direction().map(|_| channel)) + .and_then(|(channel, _)| channel.with_update()) .map(|info| CandidateRouteHop::PublicHop { info, short_channel_id: hop.short_channel_id,