Skip to content

Commit 59f2324

Browse files
committed
Consume node_id from CandidateRouteHop
1 parent 3d7f1d2 commit 59f2324

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

lightning/src/routing/router.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,6 @@ pub enum CandidateRouteHop<'a> {
10311031
/// Provided to uniquely identify a hop as we are
10321032
/// route building.
10331033
hint_idx: usize,
1034-
/// The node id of the payer.
1035-
source_node_id: NodeId,
10361034
},
10371035
/// Similar to [`Self::Blinded`], but the path here has 1 blinded hop. `BlindedPayInfo` provided
10381036
/// for 1-hop blinded paths is ignored because it is meant to apply to the hops *between* the
@@ -1048,8 +1046,6 @@ pub enum CandidateRouteHop<'a> {
10481046
/// Provided to uniquely identify a hop as we are
10491047
/// route building.
10501048
hint_idx: usize,
1051-
/// The node id of the payer.
1052-
source_node_id: NodeId,
10531049
},
10541050
}
10551051

@@ -1162,8 +1158,8 @@ impl<'a> CandidateRouteHop<'a> {
11621158
*source_node_id
11631159
},
11641160
CandidateRouteHop::PrivateHop { hint, .. } => hint.src_node_id.into(),
1165-
CandidateRouteHop::Blinded { source_node_id, .. } => *source_node_id,
1166-
CandidateRouteHop::OneHopBlinded { source_node_id, .. } => *source_node_id,
1161+
CandidateRouteHop::Blinded { hint, .. } => hint.1.introduction_node_id.into(),
1162+
CandidateRouteHop::OneHopBlinded { hint, .. } => hint.1.introduction_node_id.into(),
11671163
}
11681164
}
11691165
/// Returns the target node id of this hop, if known.
@@ -1228,7 +1224,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
12281224
pub struct PathBuildingHop<'a> {
12291225
// Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
12301226
// is a larger refactor and will require careful performance analysis.
1231-
node_id: NodeId,
1227+
// node_id: NodeId,
12321228
candidate: CandidateRouteHop<'a>,
12331229
fee_msat: u64,
12341230

@@ -1266,7 +1262,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
12661262
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
12671263
let mut debug_struct = f.debug_struct("PathBuildingHop");
12681264
debug_struct
1269-
.field("node_id", &self.node_id)
1265+
.field("node_id", &self.candidate.source())
12701266
.field("short_channel_id", &self.candidate.short_channel_id())
12711267
.field("total_fee_msat", &self.total_fee_msat)
12721268
.field("next_hops_fee_msat", &self.next_hops_fee_msat)
@@ -1888,7 +1884,7 @@ where L::Target: Logger {
18881884
// This will affect our decision on selecting short_channel_id
18891885
// as a way to reach the $dest_node_id.
18901886
PathBuildingHop {
1891-
node_id: $dest_node_id.clone(),
1887+
// node_id: $dest_node_id.clone(),
18921888
candidate: $candidate.clone(),
18931889
fee_msat: 0,
18941890
next_hops_fee_msat: u64::max_value(),
@@ -1970,7 +1966,7 @@ where L::Target: Logger {
19701966
old_entry.next_hops_fee_msat = $next_hops_fee_msat;
19711967
old_entry.hop_use_fee_msat = hop_use_fee_msat;
19721968
old_entry.total_fee_msat = total_fee_msat;
1973-
old_entry.node_id = $dest_node_id.clone();
1969+
// old_entry.node_id = $dest_node_id.clone();
19741970
old_entry.candidate = $candidate.clone();
19751971
old_entry.fee_msat = 0; // This value will be later filled with hop_use_fee_msat of the following channel
19761972
old_entry.path_htlc_minimum_msat = path_htlc_minimum_msat;
@@ -2135,8 +2131,8 @@ where L::Target: Logger {
21352131
network_nodes.get(&intro_node_id).is_some();
21362132
if !have_intro_node_in_graph { continue }
21372133
let candidate = if hint.1.blinded_hops.len() == 1 {
2138-
CandidateRouteHop::OneHopBlinded { hint, hint_idx, source_node_id: our_node_id }
2139-
} else { CandidateRouteHop::Blinded { hint, hint_idx, source_node_id: intro_node_id } };
2134+
CandidateRouteHop::OneHopBlinded { hint, hint_idx }
2135+
} else { CandidateRouteHop::Blinded { hint, hint_idx } };
21402136
let mut path_contribution_msat = path_value_msat;
21412137
if let Some(hop_used_msat) = add_entry!(&candidate, intro_node_id, maybe_dummy_payee_node_id,
21422138
0, path_contribution_msat, 0, 0_u64, 0, 0)
@@ -2317,7 +2313,11 @@ where L::Target: Logger {
23172313

23182314
'path_walk: loop {
23192315
let mut features_set = false;
2320-
if let Some(first_channels) = first_hop_targets.get(&ordered_hops.last().unwrap().0.node_id) {
2316+
let target = match ordered_hops.last().unwrap().0.candidate.target() {
2317+
Some(target) => target,
2318+
None => break,
2319+
};
2320+
if let Some(first_channels) = first_hop_targets.get(&target) {
23212321
for details in first_channels {
23222322
if let Some(scid) = ordered_hops.last().unwrap().0.candidate.short_channel_id() {
23232323
if details.get_outbound_payment_scid().unwrap() == scid {
@@ -2329,7 +2329,7 @@ where L::Target: Logger {
23292329
}
23302330
}
23312331
if !features_set {
2332-
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.node_id) {
2332+
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.candidate.target().unwrap()) {
23332333
if let Some(node_info) = node.announcement_info.as_ref() {
23342334
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
23352335
} else {
@@ -2346,11 +2346,11 @@ where L::Target: Logger {
23462346
// save this path for the payment route. Also, update the liquidity
23472347
// remaining on the used hops, so that we take them into account
23482348
// while looking for more paths.
2349-
if ordered_hops.last().unwrap().0.node_id == maybe_dummy_payee_node_id {
2349+
if ordered_hops.last().unwrap().0.candidate.target().unwrap() == maybe_dummy_payee_node_id {
23502350
break 'path_walk;
23512351
}
23522352

2353-
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.node_id) {
2353+
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.candidate.target().unwrap()) {
23542354
Some(payment_hop) => payment_hop,
23552355
// We can't arrive at None because, if we ever add an entry to targets,
23562356
// we also fill in the entry in dist (see add_entry!).
@@ -2389,12 +2389,16 @@ where L::Target: Logger {
23892389
// Remember that we used these channels so that we don't rely
23902390
// on the same liquidity in future paths.
23912391
let mut prevented_redundant_path_selection = false;
2392-
let prev_hop_iter = core::iter::once(&our_node_id)
2393-
.chain(payment_path.hops.iter().map(|(hop, _)| &hop.node_id));
2392+
let prev_hop_iter = core::iter::once(our_node_id)
2393+
.chain(payment_path.hops.iter().map(|(hop, _)| hop.candidate.target().unwrap()));
23942394
for (prev_hop, (hop, _)) in prev_hop_iter.zip(payment_path.hops.iter()) {
2395+
let target = match hop.candidate.target() {
2396+
Some(target) => target,
2397+
None => break,
2398+
};
23952399
let spent_on_hop_msat = value_contribution_msat + hop.next_hops_fee_msat;
23962400
let used_liquidity_msat = used_liquidities
2397-
.entry(hop.candidate.id(*prev_hop < hop.node_id))
2401+
.entry(hop.candidate.id(prev_hop < target))
23982402
.and_modify(|used_liquidity_msat| *used_liquidity_msat += spent_on_hop_msat)
23992403
.or_insert(spent_on_hop_msat);
24002404
let hop_capacity = hop.candidate.effective_capacity();
@@ -2558,8 +2562,8 @@ where L::Target: Logger {
25582562
});
25592563
for idx in 0..(selected_route.len() - 1) {
25602564
if idx + 1 >= selected_route.len() { break; }
2561-
if iter_equal(selected_route[idx ].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id)),
2562-
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id))) {
2565+
if iter_equal(selected_route[idx].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target())),
2566+
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target()))) {
25632567
let new_value = selected_route[idx].get_value_msat() + selected_route[idx + 1].get_value_msat();
25642568
selected_route[idx].update_value_and_recompute_fees(new_value);
25652569
selected_route.remove(idx + 1);
@@ -2584,14 +2588,15 @@ where L::Target: Logger {
25842588
// there are announced channels between the endpoints. If so, the hop might be
25852589
// referring to any of the announced channels, as its `short_channel_id` might be
25862590
// an alias, in which case we don't take any chances here.
2587-
network_graph.node(&hop.node_id).map_or(false, |hop_node|
2591+
let hop_node_id = hop.candidate.source();
2592+
network_graph.node(&hop_node_id).map_or(false, |hop_node|
25882593
hop_node.channels.iter().any(|scid| network_graph.channel(*scid)
2589-
.map_or(false, |c| c.as_directed_from(&prev_hop_node_id).is_some()))
2594+
.map_or(false, |c| c.as_directed_from(&prev_hop_node_id).is_some()))
25902595
)
25912596
};
25922597

25932598
hops.push(RouteHop {
2594-
pubkey: PublicKey::from_slice(hop.node_id.as_slice()).map_err(|_| LightningError{err: format!("Public key {:?} is invalid", &hop.node_id), action: ErrorAction::IgnoreAndLog(Level::Trace)})?,
2599+
pubkey: PublicKey::from_slice(hop.candidate.target().unwrap().as_slice()).map_err(|_| LightningError{err: format!("Public key {:?} is invalid", &hop.candidate.target().unwrap()), action: ErrorAction::IgnoreAndLog(Level::Trace)})?,
25952600
node_features: node_features.clone(),
25962601
short_channel_id: hop.candidate.short_channel_id().unwrap(),
25972602
channel_features: hop.candidate.features(),
@@ -2600,7 +2605,7 @@ where L::Target: Logger {
26002605
maybe_announced_channel,
26012606
});
26022607

2603-
prev_hop_node_id = hop.node_id;
2608+
prev_hop_node_id = hop.candidate.source();
26042609
}
26052610
let mut final_cltv_delta = final_cltv_expiry_delta;
26062611
let blinded_tail = payment_path.hops.last().and_then(|(h, _)| {

0 commit comments

Comments
 (0)