@@ -937,42 +937,55 @@ impl cmp::PartialOrd for RouteGraphNode {
937937///
938938/// Used to construct a [`PathBuildingHop`] and to estimate [`EffectiveCapacity`].
939939#[ derive( Clone , Debug ) ]
940- enum CandidateRouteHop < ' a > {
940+ pub enum CandidateRouteHop < ' a > {
941941 /// A hop from the payer, where the outbound liquidity is known.
942942 FirstHop {
943+ /// The channel details of the first hop.
943944 details : & ' a ChannelDetails ,
945+ /// The node id of the payer.
946+ node_id : NodeId
944947 } ,
945948 /// A hop found in the [`ReadOnlyNetworkGraph`], where the channel capacity may be unknown.
946949 PublicHop {
950+ /// The channel info of the hop.
947951 info : DirectedChannelInfo < ' a > ,
952+ /// The short_channel_id of the channel.
948953 short_channel_id : u64 ,
949954 } ,
950955 /// A hop to the payee found in the BOLT 11 payment invoice, though not necessarily a direct
951956 /// channel.
952957 PrivateHop {
958+ /// Hint about the the hop
953959 hint : & ' a RouteHintHop ,
960+ /// The node id of the payee.
961+ target_node_id : NodeId
954962 } ,
955963 /// The payee's identity is concealed behind blinded paths provided in a BOLT 12 invoice.
956964 Blinded {
965+ /// hint is the blinded path to the destination.
957966 hint : & ' a ( BlindedPayInfo , BlindedPath ) ,
967+ /// The index of the hint in the original list of blinded hints.
958968 hint_idx : usize ,
959969 } ,
960970 /// Similar to [`Self::Blinded`], but the path here has 1 blinded hop. `BlindedPayInfo` provided
961971 /// for 1-hop blinded paths is ignored because it is meant to apply to the hops *between* the
962972 /// introduction node and the destination. Useful for tracking that we need to include a blinded
963973 /// path at the end of our [`Route`].
964974 OneHopBlinded {
975+ /// hint is the blinded path to the destination.
965976 hint : & ' a ( BlindedPayInfo , BlindedPath ) ,
977+ /// The index of the hint in the original list of blinded hints.
966978 hint_idx : usize ,
967979 } ,
968980}
969981
970982impl < ' a > CandidateRouteHop < ' a > {
971- fn short_channel_id ( & self ) -> Option < u64 > {
983+ /// Returns short_channel_id if known.
984+ pub fn short_channel_id ( & self ) -> Option < u64 > {
972985 match self {
973- CandidateRouteHop :: FirstHop { details } => Some ( details. get_outbound_payment_scid ( ) . unwrap ( ) ) ,
986+ CandidateRouteHop :: FirstHop { details, .. } => Some ( details. get_outbound_payment_scid ( ) . unwrap ( ) ) ,
974987 CandidateRouteHop :: PublicHop { short_channel_id, .. } => Some ( * short_channel_id) ,
975- CandidateRouteHop :: PrivateHop { hint } => Some ( hint. short_channel_id ) ,
988+ CandidateRouteHop :: PrivateHop { hint, .. } => Some ( hint. short_channel_id ) ,
976989 CandidateRouteHop :: Blinded { .. } => None ,
977990 CandidateRouteHop :: OneHopBlinded { .. } => None ,
978991 }
@@ -981,7 +994,7 @@ impl<'a> CandidateRouteHop<'a> {
981994 // NOTE: This may alloc memory so avoid calling it in a hot code path.
982995 fn features ( & self ) -> ChannelFeatures {
983996 match self {
984- CandidateRouteHop :: FirstHop { details } => details. counterparty . features . to_context ( ) ,
997+ CandidateRouteHop :: FirstHop { details, .. } => details. counterparty . features . to_context ( ) ,
985998 CandidateRouteHop :: PublicHop { info, .. } => info. channel ( ) . features . clone ( ) ,
986999 CandidateRouteHop :: PrivateHop { .. } => ChannelFeatures :: empty ( ) ,
9871000 CandidateRouteHop :: Blinded { .. } => ChannelFeatures :: empty ( ) ,
@@ -993,17 +1006,17 @@ impl<'a> CandidateRouteHop<'a> {
9931006 match self {
9941007 CandidateRouteHop :: FirstHop { .. } => 0 ,
9951008 CandidateRouteHop :: PublicHop { info, .. } => info. direction ( ) . cltv_expiry_delta as u32 ,
996- CandidateRouteHop :: PrivateHop { hint } => hint. cltv_expiry_delta as u32 ,
1009+ CandidateRouteHop :: PrivateHop { hint, .. } => hint. cltv_expiry_delta as u32 ,
9971010 CandidateRouteHop :: Blinded { hint, .. } => hint. 0 . cltv_expiry_delta as u32 ,
9981011 CandidateRouteHop :: OneHopBlinded { .. } => 0 ,
9991012 }
10001013 }
10011014
10021015 fn htlc_minimum_msat ( & self ) -> u64 {
10031016 match self {
1004- CandidateRouteHop :: FirstHop { details } => details. next_outbound_htlc_minimum_msat ,
1017+ CandidateRouteHop :: FirstHop { details, .. } => details. next_outbound_htlc_minimum_msat ,
10051018 CandidateRouteHop :: PublicHop { info, .. } => info. direction ( ) . htlc_minimum_msat ,
1006- CandidateRouteHop :: PrivateHop { hint } => hint. htlc_minimum_msat . unwrap_or ( 0 ) ,
1019+ CandidateRouteHop :: PrivateHop { hint, .. } => hint. htlc_minimum_msat . unwrap_or ( 0 ) ,
10071020 CandidateRouteHop :: Blinded { hint, .. } => hint. 0 . htlc_minimum_msat ,
10081021 CandidateRouteHop :: OneHopBlinded { .. } => 0 ,
10091022 }
@@ -1015,7 +1028,7 @@ impl<'a> CandidateRouteHop<'a> {
10151028 base_msat : 0 , proportional_millionths : 0 ,
10161029 } ,
10171030 CandidateRouteHop :: PublicHop { info, .. } => info. direction ( ) . fees ,
1018- CandidateRouteHop :: PrivateHop { hint } => hint. fees ,
1031+ CandidateRouteHop :: PrivateHop { hint, .. } => hint. fees ,
10191032 CandidateRouteHop :: Blinded { hint, .. } => {
10201033 RoutingFees {
10211034 base_msat : hint. 0 . fee_base_msat ,
@@ -1029,13 +1042,13 @@ impl<'a> CandidateRouteHop<'a> {
10291042
10301043 fn effective_capacity ( & self ) -> EffectiveCapacity {
10311044 match self {
1032- CandidateRouteHop :: FirstHop { details } => EffectiveCapacity :: ExactLiquidity {
1045+ CandidateRouteHop :: FirstHop { details, .. } => EffectiveCapacity :: ExactLiquidity {
10331046 liquidity_msat : details. next_outbound_htlc_limit_msat ,
10341047 } ,
10351048 CandidateRouteHop :: PublicHop { info, .. } => info. effective_capacity ( ) ,
1036- CandidateRouteHop :: PrivateHop { hint : RouteHintHop { htlc_maximum_msat : Some ( max) , .. } } =>
1049+ CandidateRouteHop :: PrivateHop { hint : RouteHintHop { htlc_maximum_msat : Some ( max) , .. } , .. } =>
10371050 EffectiveCapacity :: HintMaxHTLC { amount_msat : * max } ,
1038- CandidateRouteHop :: PrivateHop { hint : RouteHintHop { htlc_maximum_msat : None , .. } } =>
1051+ CandidateRouteHop :: PrivateHop { hint : RouteHintHop { htlc_maximum_msat : None , .. } , .. } =>
10391052 EffectiveCapacity :: Infinite ,
10401053 CandidateRouteHop :: Blinded { hint, .. } =>
10411054 EffectiveCapacity :: HintMaxHTLC { amount_msat : hint. 0 . htlc_maximum_msat } ,
@@ -1058,6 +1071,26 @@ impl<'a> CandidateRouteHop<'a> {
10581071 _ => None ,
10591072 }
10601073 }
1074+ /// Returns the source node id of this hop.
1075+ pub fn source ( & self ) -> NodeId {
1076+ match self {
1077+ CandidateRouteHop :: FirstHop { node_id, .. } => * node_id,
1078+ CandidateRouteHop :: PublicHop { info, .. } => info. channel . node_one . into ( ) ,
1079+ CandidateRouteHop :: PrivateHop { hint, .. } => hint. src_node_id . into ( ) ,
1080+ CandidateRouteHop :: Blinded { hint, .. } => hint. 1 . introduction_node_id . into ( ) ,
1081+ CandidateRouteHop :: OneHopBlinded { hint, .. } => hint. 1 . introduction_node_id . into ( )
1082+ }
1083+ }
1084+ /// Returns the target node id of this hop, if known.
1085+ pub fn target ( & self ) -> Option < NodeId > {
1086+ match self {
1087+ CandidateRouteHop :: FirstHop { details, .. } => Some ( details. counterparty . node_id . into ( ) ) ,
1088+ CandidateRouteHop :: PublicHop { info, .. } => Some ( info. channel . node_two . into ( ) ) ,
1089+ CandidateRouteHop :: PrivateHop { target_node_id, .. } => Some ( * target_node_id) ,
1090+ CandidateRouteHop :: Blinded { hint, .. } => Some ( hint. 1 . blinding_point . into ( ) ) ,
1091+ CandidateRouteHop :: OneHopBlinded { hint, .. } => Some ( hint. 1 . blinding_point . into ( ) )
1092+ }
1093+ }
10611094}
10621095
10631096#[ derive( Clone , Copy , Eq , Hash , Ord , PartialOrd , PartialEq ) ]
@@ -1101,7 +1134,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
11011134/// Fee values should be updated only in the context of the whole path, see update_value_and_recompute_fees.
11021135/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
11031136#[ derive( Clone ) ]
1104- struct PathBuildingHop < ' a > {
1137+ pub struct PathBuildingHop < ' a > {
11051138 // Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
11061139 // is a larger refactor and will require careful performance analysis.
11071140 node_id : NodeId ,
@@ -1917,7 +1950,7 @@ where L::Target: Logger {
19171950 if !skip_node {
19181951 if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
19191952 for details in first_channels {
1920- let candidate = CandidateRouteHop :: FirstHop { details } ;
1953+ let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
19211954 add_entry!( candidate, our_node_id, $node_id, $fee_to_target_msat,
19221955 $next_hops_value_contribution,
19231956 $next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
@@ -1972,7 +2005,7 @@ where L::Target: Logger {
19722005 // place where it could be added.
19732006 payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
19742007 for details in first_channels {
1975- let candidate = CandidateRouteHop :: FirstHop { details } ;
2008+ let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
19762009 let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
19772010 0 , 0u64 , 0 , 0 ) . is_some ( ) ;
19782011 log_trace ! ( logger, "{} direct route to payee via {}" ,
@@ -2019,7 +2052,7 @@ where L::Target: Logger {
20192052 sort_first_hop_channels ( first_channels, & used_liquidities, recommended_value_msat,
20202053 our_node_pubkey) ;
20212054 for details in first_channels {
2022- let first_hop_candidate = CandidateRouteHop :: FirstHop { details } ;
2055+ let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
20232056 let blinded_path_fee = match compute_fees ( path_contribution_msat, candidate. fees ( ) ) {
20242057 Some ( fee) => fee,
20252058 None => continue
@@ -2065,7 +2098,7 @@ where L::Target: Logger {
20652098 info,
20662099 short_channel_id : hop. short_channel_id ,
20672100 } )
2068- . unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop } ) ;
2101+ . unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
20692102
20702103 if let Some ( hop_used_msat) = add_entry ! ( candidate, source, target,
20712104 aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
@@ -2105,7 +2138,7 @@ where L::Target: Logger {
21052138 sort_first_hop_channels ( first_channels, & used_liquidities,
21062139 recommended_value_msat, our_node_pubkey) ;
21072140 for details in first_channels {
2108- let first_hop_candidate = CandidateRouteHop :: FirstHop { details } ;
2141+ let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
21092142 add_entry ! ( first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
21102143 aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
21112144 aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
@@ -2146,7 +2179,7 @@ where L::Target: Logger {
21462179 sort_first_hop_channels ( first_channels, & used_liquidities,
21472180 recommended_value_msat, our_node_pubkey) ;
21482181 for details in first_channels {
2149- let first_hop_candidate = CandidateRouteHop :: FirstHop { details } ;
2182+ let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
21502183 add_entry ! ( first_hop_candidate, our_node_id,
21512184 NodeId :: from_pubkey( & hop. src_node_id) ,
21522185 aggregate_next_hops_fee_msat,
0 commit comments