@@ -937,42 +937,55 @@ impl cmp::PartialOrd for RouteGraphNode {
937
937
///
938
938
/// Used to construct a [`PathBuildingHop`] and to estimate [`EffectiveCapacity`].
939
939
#[ derive( Clone , Debug ) ]
940
- enum CandidateRouteHop < ' a > {
940
+ pub enum CandidateRouteHop < ' a > {
941
941
/// A hop from the payer, where the outbound liquidity is known.
942
942
FirstHop {
943
+ /// The channel details of the first hop.
943
944
details : & ' a ChannelDetails ,
945
+ /// The node id of the payer.
946
+ node_id : NodeId
944
947
} ,
945
948
/// A hop found in the [`ReadOnlyNetworkGraph`], where the channel capacity may be unknown.
946
949
PublicHop {
950
+ /// The channel info of the hop.
947
951
info : DirectedChannelInfo < ' a > ,
952
+ /// The short_channel_id of the channel.
948
953
short_channel_id : u64 ,
949
954
} ,
950
955
/// A hop to the payee found in the BOLT 11 payment invoice, though not necessarily a direct
951
956
/// channel.
952
957
PrivateHop {
958
+ /// Hint about the the hop
953
959
hint : & ' a RouteHintHop ,
960
+ /// The node id of the payee.
961
+ target_node_id : NodeId
954
962
} ,
955
963
/// The payee's identity is concealed behind blinded paths provided in a BOLT 12 invoice.
956
964
Blinded {
965
+ /// hint is the blinded path to the destination.
957
966
hint : & ' a ( BlindedPayInfo , BlindedPath ) ,
967
+ /// The index of the hint in the original list of blinded hints.
958
968
hint_idx : usize ,
959
969
} ,
960
970
/// Similar to [`Self::Blinded`], but the path here has 1 blinded hop. `BlindedPayInfo` provided
961
971
/// for 1-hop blinded paths is ignored because it is meant to apply to the hops *between* the
962
972
/// introduction node and the destination. Useful for tracking that we need to include a blinded
963
973
/// path at the end of our [`Route`].
964
974
OneHopBlinded {
975
+ /// hint is the blinded path to the destination.
965
976
hint : & ' a ( BlindedPayInfo , BlindedPath ) ,
977
+ /// The index of the hint in the original list of blinded hints.
966
978
hint_idx : usize ,
967
979
} ,
968
980
}
969
981
970
982
impl < ' 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 > {
972
985
match self {
973
- CandidateRouteHop :: FirstHop { details } => Some ( details. get_outbound_payment_scid ( ) . unwrap ( ) ) ,
986
+ CandidateRouteHop :: FirstHop { details, .. } => Some ( details. get_outbound_payment_scid ( ) . unwrap ( ) ) ,
974
987
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 ) ,
976
989
CandidateRouteHop :: Blinded { .. } => None ,
977
990
CandidateRouteHop :: OneHopBlinded { .. } => None ,
978
991
}
@@ -981,7 +994,7 @@ impl<'a> CandidateRouteHop<'a> {
981
994
// NOTE: This may alloc memory so avoid calling it in a hot code path.
982
995
fn features ( & self ) -> ChannelFeatures {
983
996
match self {
984
- CandidateRouteHop :: FirstHop { details } => details. counterparty . features . to_context ( ) ,
997
+ CandidateRouteHop :: FirstHop { details, .. } => details. counterparty . features . to_context ( ) ,
985
998
CandidateRouteHop :: PublicHop { info, .. } => info. channel ( ) . features . clone ( ) ,
986
999
CandidateRouteHop :: PrivateHop { .. } => ChannelFeatures :: empty ( ) ,
987
1000
CandidateRouteHop :: Blinded { .. } => ChannelFeatures :: empty ( ) ,
@@ -993,17 +1006,17 @@ impl<'a> CandidateRouteHop<'a> {
993
1006
match self {
994
1007
CandidateRouteHop :: FirstHop { .. } => 0 ,
995
1008
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 ,
997
1010
CandidateRouteHop :: Blinded { hint, .. } => hint. 0 . cltv_expiry_delta as u32 ,
998
1011
CandidateRouteHop :: OneHopBlinded { .. } => 0 ,
999
1012
}
1000
1013
}
1001
1014
1002
1015
fn htlc_minimum_msat ( & self ) -> u64 {
1003
1016
match self {
1004
- CandidateRouteHop :: FirstHop { details } => details. next_outbound_htlc_minimum_msat ,
1017
+ CandidateRouteHop :: FirstHop { details, .. } => details. next_outbound_htlc_minimum_msat ,
1005
1018
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 ) ,
1007
1020
CandidateRouteHop :: Blinded { hint, .. } => hint. 0 . htlc_minimum_msat ,
1008
1021
CandidateRouteHop :: OneHopBlinded { .. } => 0 ,
1009
1022
}
@@ -1015,7 +1028,7 @@ impl<'a> CandidateRouteHop<'a> {
1015
1028
base_msat : 0 , proportional_millionths : 0 ,
1016
1029
} ,
1017
1030
CandidateRouteHop :: PublicHop { info, .. } => info. direction ( ) . fees ,
1018
- CandidateRouteHop :: PrivateHop { hint } => hint. fees ,
1031
+ CandidateRouteHop :: PrivateHop { hint, .. } => hint. fees ,
1019
1032
CandidateRouteHop :: Blinded { hint, .. } => {
1020
1033
RoutingFees {
1021
1034
base_msat : hint. 0 . fee_base_msat ,
@@ -1029,13 +1042,13 @@ impl<'a> CandidateRouteHop<'a> {
1029
1042
1030
1043
fn effective_capacity ( & self ) -> EffectiveCapacity {
1031
1044
match self {
1032
- CandidateRouteHop :: FirstHop { details } => EffectiveCapacity :: ExactLiquidity {
1045
+ CandidateRouteHop :: FirstHop { details, .. } => EffectiveCapacity :: ExactLiquidity {
1033
1046
liquidity_msat : details. next_outbound_htlc_limit_msat ,
1034
1047
} ,
1035
1048
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) , .. } , .. } =>
1037
1050
EffectiveCapacity :: HintMaxHTLC { amount_msat : * max } ,
1038
- CandidateRouteHop :: PrivateHop { hint : RouteHintHop { htlc_maximum_msat : None , .. } } =>
1051
+ CandidateRouteHop :: PrivateHop { hint : RouteHintHop { htlc_maximum_msat : None , .. } , .. } =>
1039
1052
EffectiveCapacity :: Infinite ,
1040
1053
CandidateRouteHop :: Blinded { hint, .. } =>
1041
1054
EffectiveCapacity :: HintMaxHTLC { amount_msat : hint. 0 . htlc_maximum_msat } ,
@@ -1058,6 +1071,26 @@ impl<'a> CandidateRouteHop<'a> {
1058
1071
_ => None ,
1059
1072
}
1060
1073
}
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
+ }
1061
1094
}
1062
1095
1063
1096
#[ 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)
1101
1134
/// Fee values should be updated only in the context of the whole path, see update_value_and_recompute_fees.
1102
1135
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
1103
1136
#[ derive( Clone ) ]
1104
- struct PathBuildingHop < ' a > {
1137
+ pub struct PathBuildingHop < ' a > {
1105
1138
// Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
1106
1139
// is a larger refactor and will require careful performance analysis.
1107
1140
node_id : NodeId ,
@@ -1917,7 +1950,7 @@ where L::Target: Logger {
1917
1950
if !skip_node {
1918
1951
if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
1919
1952
for details in first_channels {
1920
- let candidate = CandidateRouteHop :: FirstHop { details } ;
1953
+ let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
1921
1954
add_entry!( candidate, our_node_id, $node_id, $fee_to_target_msat,
1922
1955
$next_hops_value_contribution,
1923
1956
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
@@ -1972,7 +2005,7 @@ where L::Target: Logger {
1972
2005
// place where it could be added.
1973
2006
payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
1974
2007
for details in first_channels {
1975
- let candidate = CandidateRouteHop :: FirstHop { details } ;
2008
+ let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
1976
2009
let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
1977
2010
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
1978
2011
log_trace ! ( logger, "{} direct route to payee via {}" ,
@@ -2019,7 +2052,7 @@ where L::Target: Logger {
2019
2052
sort_first_hop_channels ( first_channels, & used_liquidities, recommended_value_msat,
2020
2053
our_node_pubkey) ;
2021
2054
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 } ;
2023
2056
let blinded_path_fee = match compute_fees ( path_contribution_msat, candidate. fees ( ) ) {
2024
2057
Some ( fee) => fee,
2025
2058
None => continue
@@ -2065,7 +2098,7 @@ where L::Target: Logger {
2065
2098
info,
2066
2099
short_channel_id : hop. short_channel_id ,
2067
2100
} )
2068
- . unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop } ) ;
2101
+ . unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
2069
2102
2070
2103
if let Some ( hop_used_msat) = add_entry ! ( candidate, source, target,
2071
2104
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
@@ -2105,7 +2138,7 @@ where L::Target: Logger {
2105
2138
sort_first_hop_channels ( first_channels, & used_liquidities,
2106
2139
recommended_value_msat, our_node_pubkey) ;
2107
2140
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 } ;
2109
2142
add_entry ! ( first_hop_candidate, our_node_id, NodeId :: from_pubkey( & prev_hop_id) ,
2110
2143
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2111
2144
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
@@ -2146,7 +2179,7 @@ where L::Target: Logger {
2146
2179
sort_first_hop_channels ( first_channels, & used_liquidities,
2147
2180
recommended_value_msat, our_node_pubkey) ;
2148
2181
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 } ;
2150
2183
add_entry ! ( first_hop_candidate, our_node_id,
2151
2184
NodeId :: from_pubkey( & hop. src_node_id) ,
2152
2185
aggregate_next_hops_fee_msat,
0 commit comments