Skip to content

Commit 4bd2037

Browse files
committed
Consume node_id from CandidateRouteHop
1 parent fdb2bb7 commit 4bd2037

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

lightning/src/routing/router.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
12151215
pub struct PathBuildingHop<'a> {
12161216
// Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
12171217
// is a larger refactor and will require careful performance analysis.
1218-
node_id: NodeId,
1218+
// node_id: NodeId,
12191219
candidate: CandidateRouteHop<'a>,
12201220
fee_msat: u64,
12211221

@@ -1253,7 +1253,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
12531253
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
12541254
let mut debug_struct = f.debug_struct("PathBuildingHop");
12551255
debug_struct
1256-
.field("node_id", &self.node_id)
1256+
.field("node_id", &self.candidate.source())
12571257
.field("short_channel_id", &self.candidate.short_channel_id())
12581258
.field("total_fee_msat", &self.total_fee_msat)
12591259
.field("next_hops_fee_msat", &self.next_hops_fee_msat)
@@ -1875,7 +1875,7 @@ where L::Target: Logger {
18751875
// This will affect our decision on selecting short_channel_id
18761876
// as a way to reach the $dest_node_id.
18771877
PathBuildingHop {
1878-
node_id: $dest_node_id.clone(),
1878+
// node_id: $dest_node_id.clone(),
18791879
candidate: $candidate.clone(),
18801880
fee_msat: 0,
18811881
next_hops_fee_msat: u64::max_value(),
@@ -1957,7 +1957,7 @@ where L::Target: Logger {
19571957
old_entry.next_hops_fee_msat = $next_hops_fee_msat;
19581958
old_entry.hop_use_fee_msat = hop_use_fee_msat;
19591959
old_entry.total_fee_msat = total_fee_msat;
1960-
old_entry.node_id = $dest_node_id.clone();
1960+
// old_entry.node_id = $dest_node_id.clone();
19611961
old_entry.candidate = $candidate.clone();
19621962
old_entry.fee_msat = 0; // This value will be later filled with hop_use_fee_msat of the following channel
19631963
old_entry.path_htlc_minimum_msat = path_htlc_minimum_msat;
@@ -2304,7 +2304,11 @@ where L::Target: Logger {
23042304

23052305
'path_walk: loop {
23062306
let mut features_set = false;
2307-
if let Some(first_channels) = first_hop_targets.get(&ordered_hops.last().unwrap().0.node_id) {
2307+
let target = match ordered_hops.last().unwrap().0.candidate.target() {
2308+
Some(target) => target,
2309+
None => break,
2310+
};
2311+
if let Some(first_channels) = first_hop_targets.get(&target) {
23082312
for details in first_channels {
23092313
if let Some(scid) = ordered_hops.last().unwrap().0.candidate.short_channel_id() {
23102314
if details.get_outbound_payment_scid().unwrap() == scid {
@@ -2316,7 +2320,7 @@ where L::Target: Logger {
23162320
}
23172321
}
23182322
if !features_set {
2319-
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.node_id) {
2323+
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.candidate.target().unwrap()) {
23202324
if let Some(node_info) = node.announcement_info.as_ref() {
23212325
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
23222326
} else {
@@ -2333,11 +2337,11 @@ where L::Target: Logger {
23332337
// save this path for the payment route. Also, update the liquidity
23342338
// remaining on the used hops, so that we take them into account
23352339
// while looking for more paths.
2336-
if ordered_hops.last().unwrap().0.node_id == maybe_dummy_payee_node_id {
2340+
if ordered_hops.last().unwrap().0.candidate.target().unwrap() == maybe_dummy_payee_node_id {
23372341
break 'path_walk;
23382342
}
23392343

2340-
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.node_id) {
2344+
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.candidate.target().unwrap()) {
23412345
Some(payment_hop) => payment_hop,
23422346
// We can't arrive at None because, if we ever add an entry to targets,
23432347
// we also fill in the entry in dist (see add_entry!).
@@ -2376,12 +2380,16 @@ where L::Target: Logger {
23762380
// Remember that we used these channels so that we don't rely
23772381
// on the same liquidity in future paths.
23782382
let mut prevented_redundant_path_selection = false;
2379-
let prev_hop_iter = core::iter::once(&our_node_id)
2380-
.chain(payment_path.hops.iter().map(|(hop, _)| &hop.node_id));
2383+
let prev_hop_iter = core::iter::once(our_node_id)
2384+
.chain(payment_path.hops.iter().map(|(hop, _)| hop.candidate.target().unwrap()));
23812385
for (prev_hop, (hop, _)) in prev_hop_iter.zip(payment_path.hops.iter()) {
2386+
let target = match hop.candidate.target() {
2387+
Some(target) => target,
2388+
None => break,
2389+
};
23822390
let spent_on_hop_msat = value_contribution_msat + hop.next_hops_fee_msat;
23832391
let used_liquidity_msat = used_liquidities
2384-
.entry(hop.candidate.id(*prev_hop < hop.node_id))
2392+
.entry(hop.candidate.id(prev_hop < target))
23852393
.and_modify(|used_liquidity_msat| *used_liquidity_msat += spent_on_hop_msat)
23862394
.or_insert(spent_on_hop_msat);
23872395
let hop_capacity = hop.candidate.effective_capacity();
@@ -2545,8 +2553,8 @@ where L::Target: Logger {
25452553
});
25462554
for idx in 0..(selected_route.len() - 1) {
25472555
if idx + 1 >= selected_route.len() { break; }
2548-
if iter_equal(selected_route[idx ].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id)),
2549-
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id))) {
2556+
if iter_equal(selected_route[idx].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target())),
2557+
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target()))) {
25502558
let new_value = selected_route[idx].get_value_msat() + selected_route[idx + 1].get_value_msat();
25512559
selected_route[idx].update_value_and_recompute_fees(new_value);
25522560
selected_route.remove(idx + 1);
@@ -2560,7 +2568,7 @@ where L::Target: Logger {
25602568
.filter(|(h, _)| h.candidate.short_channel_id().is_some())
25612569
{
25622570
hops.push(RouteHop {
2563-
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)})?,
2571+
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)})?,
25642572
node_features: node_features.clone(),
25652573
short_channel_id: hop.candidate.short_channel_id().unwrap(),
25662574
channel_features: hop.candidate.features(),

0 commit comments

Comments
 (0)