Skip to content

Commit 8d22fb8

Browse files
committed
return NodeId from CandidateRouteHop::target function
1 parent d9e2704 commit 8d22fb8

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

lightning/src/routing/router.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ pub enum CandidateRouteHop<'a> {
10021002
/// `find_route` method.
10031003
details: &'a ChannelDetails,
10041004
/// The node id of the payer.
1005+
///
10051006
/// Can be accessed via `source` method.
10061007
node_id: NodeId
10071008
},
@@ -1011,9 +1012,9 @@ pub enum CandidateRouteHop<'a> {
10111012
info: DirectedChannelInfo<'a>,
10121013
/// The short_channel_id of the channel.
10131014
short_channel_id: u64,
1014-
/// The node id of the current hop in route.
1015+
/// The node id leading to the current hop in route.
10151016
source_node_id: NodeId,
1016-
/// The node id of next hop in route.
1017+
/// The node id of current hop in route.
10171018
target_node_id: NodeId,
10181019
},
10191020
/// A hop to the payee found in the BOLT 11 payment invoice, though not necessarily a direct
@@ -1022,8 +1023,8 @@ pub enum CandidateRouteHop<'a> {
10221023
/// Hint provides information about a private hop, needed while routing through a private
10231024
/// channel.
10241025
hint: &'a RouteHintHop,
1025-
/// The node id of the next hop in route.
1026-
target_node_id: NodeId
1026+
/// The node id of current hop in route.
1027+
target_node_id: NodeId,
10271028
},
10281029
/// The payee's identity is concealed behind blinded paths provided in a BOLT 12 invoice.
10291030
Blinded {
@@ -1038,6 +1039,10 @@ pub enum CandidateRouteHop<'a> {
10381039
/// Provided to uniquely identify a hop as we are
10391040
/// route building.
10401041
hint_idx: usize,
1042+
/// The node id of current hop in route.
1043+
///
1044+
/// This will always equal to `maybe_dummy_payee_node_id` in `find_route` method.
1045+
target_node_id: NodeId,
10411046
},
10421047
/// Similar to [`Self::Blinded`], but the path here has 1 blinded hop. `BlindedPayInfo` provided
10431048
/// for 1-hop blinded paths is ignored because it is meant to apply to the hops *between* the
@@ -1053,6 +1058,10 @@ pub enum CandidateRouteHop<'a> {
10531058
/// Provided to uniquely identify a hop as we are
10541059
/// route building.
10551060
hint_idx: usize,
1061+
/// The node id of current hop in route.
1062+
///
1063+
/// This will always equal to `maybe_dummy_payee_node_id` in `find_route` method.
1064+
target_node_id: NodeId,
10561065
},
10571066
}
10581067

@@ -1152,6 +1161,11 @@ impl<'a> CandidateRouteHop<'a> {
11521161
}
11531162
}
11541163
/// Returns the source node id of this hop.
1164+
///
1165+
/// Source node id refers to the hop that is previous
1166+
/// to the current examined hop in route finding.
1167+
///
1168+
/// For `FirstHop` we return payer's node id.
11551169
pub fn source(&self) -> NodeId {
11561170
match self {
11571171
CandidateRouteHop::FirstHop { node_id, .. } => *node_id,
@@ -1162,13 +1176,17 @@ impl<'a> CandidateRouteHop<'a> {
11621176
}
11631177
}
11641178
/// Returns the target node id of this hop, if known.
1165-
pub fn target(&self) -> Option<NodeId> {
1179+
///
1180+
/// Target node id refers to the current examined hop in route finding.
1181+
///
1182+
/// For `Blinded` and `OneHopBlinded` we return `maybe_dummy_payee_node_id` because we don't know the target.
1183+
pub fn target(&self) -> NodeId {
11661184
match self {
1167-
CandidateRouteHop::FirstHop { details, .. } => Some(details.counterparty.node_id.into()),
1168-
CandidateRouteHop::PublicHop { info, .. } => Some(info.channel.node_two.into()),
1169-
CandidateRouteHop::PrivateHop { target_node_id, .. } => Some(*target_node_id),
1170-
CandidateRouteHop::Blinded { hint, .. } => Some(hint.1.blinding_point.into()),
1171-
CandidateRouteHop::OneHopBlinded { hint, .. } => Some(hint.1.blinding_point.into())
1185+
CandidateRouteHop::FirstHop { details, .. } => details.counterparty.node_id.into(),
1186+
CandidateRouteHop::PublicHop { target_node_id, .. } => *target_node_id,
1187+
CandidateRouteHop::PrivateHop { target_node_id, .. } => *target_node_id,
1188+
CandidateRouteHop::Blinded { target_node_id, .. } => *target_node_id,
1189+
CandidateRouteHop::OneHopBlinded { target_node_id, .. } => *target_node_id,
11721190
}
11731191
}
11741192
}
@@ -2170,8 +2188,8 @@ where L::Target: Logger {
21702188
network_nodes.get(&intro_node_id).is_some();
21712189
if !have_intro_node_in_graph || our_node_id == intro_node_id { continue }
21722190
let candidate = if hint.1.blinded_hops.len() == 1 {
2173-
CandidateRouteHop::OneHopBlinded { hint, hint_idx }
2174-
} else { CandidateRouteHop::Blinded { hint, hint_idx } };
2191+
CandidateRouteHop::OneHopBlinded { hint, hint_idx, target_node_id: maybe_dummy_payee_node_id }
2192+
} else { CandidateRouteHop::Blinded { hint, hint_idx, target_node_id: maybe_dummy_payee_node_id } };
21752193
let mut path_contribution_msat = path_value_msat;
21762194
if let Some(hop_used_msat) = add_entry!(candidate, intro_node_id, maybe_dummy_payee_node_id,
21772195
0, path_contribution_msat, 0, 0_u64, 0, 0)

0 commit comments

Comments
 (0)