/// Returns the node id for the target.
pub fn target(&self) -> &'b NodeId { self.target }
- /// Returns the [`EffectiveCapacity`] of the channel in a specific direction.
+ /// Returns the [`EffectiveCapacity`] of the channel in the direction.
///
/// This is either the total capacity from the funding transaction, if known, or the
/// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
EffectiveCapacity::Total { capacity_msat }))
.unwrap_or(EffectiveCapacity::Unknown)
}
+
+ /// Returns `Some` if [`ChannelUpdateInfo`] is available in the direction.
+ pub(super) fn with_update(self) -> Option<DirectedChannelInfoWithUpdate<'a, 'b>> {
+ match self.direction {
+ Some(_) => Some(DirectedChannelInfoWithUpdate { inner: self }),
+ None => None,
+ }
+ }
+}
+
+/// A [`DirectedChannelInfo`] with [`ChannelUpdateInfo`] available in its the direction.
+#[derive(Clone, Debug)]
+pub(super) struct DirectedChannelInfoWithUpdate<'a: 'b, 'b> {
+ inner: DirectedChannelInfo<'a, 'b>,
+}
+
+impl<'a: 'b, 'b> DirectedChannelInfoWithUpdate<'a, 'b> {
+ /// Returns the underlying [`DirectedChannelInfo`].
+ pub(super) fn inner(&self) -> &DirectedChannelInfo<'a, 'b> {
+ &self.inner
+ }
}
/// The effective capacity of a channel for routing purposes.
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};
},
/// 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, 'a>,
short_channel_id: u64,
},
/// A hop to the payee found in the payment invoice, though not necessarily a direct channel.
fn features(&self) -> ChannelFeatures {
match self {
CandidateRouteHop::FirstHop { details } => details.counterparty.features.to_context(),
- CandidateRouteHop::PublicHop { info, .. } => info.channel().features.clone(),
+ CandidateRouteHop::PublicHop { info, .. } => info.inner().channel().features.clone(),
CandidateRouteHop::PrivateHop { .. } => ChannelFeatures::empty(),
}
}
match self {
CandidateRouteHop::FirstHop { .. } => 0,
CandidateRouteHop::PublicHop { info, .. } => {
- info.direction().unwrap().cltv_expiry_delta as u32
+ info.inner().direction().unwrap().cltv_expiry_delta as u32
},
CandidateRouteHop::PrivateHop { hint } => hint.cltv_expiry_delta as u32,
}
match self {
CandidateRouteHop::FirstHop { .. } => 0,
CandidateRouteHop::PublicHop { info, .. } => {
- info.direction().unwrap().htlc_minimum_msat
+ info.inner().direction().unwrap().htlc_minimum_msat
},
CandidateRouteHop::PrivateHop { hint } => hint.htlc_minimum_msat.unwrap_or(0),
}
CandidateRouteHop::FirstHop { .. } => RoutingFees {
base_msat: 0, proportional_millionths: 0,
},
- CandidateRouteHop::PublicHop { info, .. } => info.direction().unwrap().fees,
+ CandidateRouteHop::PublicHop { info, .. } => info.inner().direction().unwrap().fees,
CandidateRouteHop::PrivateHop { hint } => hint.fees,
}
}
CandidateRouteHop::FirstHop { details } => EffectiveCapacity::ExactLiquidity {
liquidity_msat: details.outbound_capacity_msat,
},
- CandidateRouteHop::PublicHop { info, .. } => info.effective_capacity(),
+ CandidateRouteHop::PublicHop { info, .. } => info.inner().effective_capacity(),
CandidateRouteHop::PrivateHop { .. } => EffectiveCapacity::Infinite,
}
}
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);
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,