Skip to content

Commit ffd7463

Browse files
committed
Consume node_id from CandidateRouteHop
1 parent 66a5446 commit ffd7463

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
@@ -1218,7 +1218,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
12181218
pub struct PathBuildingHop<'a> {
12191219
// Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
12201220
// is a larger refactor and will require careful performance analysis.
1221-
node_id: NodeId,
1221+
// node_id: NodeId,
12221222
candidate: CandidateRouteHop<'a>,
12231223
fee_msat: u64,
12241224

@@ -1256,7 +1256,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
12561256
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
12571257
let mut debug_struct = f.debug_struct("PathBuildingHop");
12581258
debug_struct
1259-
.field("node_id", &self.node_id)
1259+
.field("node_id", &self.candidate.source())
12601260
.field("short_channel_id", &self.candidate.short_channel_id())
12611261
.field("total_fee_msat", &self.total_fee_msat)
12621262
.field("next_hops_fee_msat", &self.next_hops_fee_msat)
@@ -1878,7 +1878,7 @@ where L::Target: Logger {
18781878
// This will affect our decision on selecting short_channel_id
18791879
// as a way to reach the $dest_node_id.
18801880
PathBuildingHop {
1881-
node_id: $dest_node_id.clone(),
1881+
// node_id: $dest_node_id.clone(),
18821882
candidate: $candidate.clone(),
18831883
fee_msat: 0,
18841884
next_hops_fee_msat: u64::max_value(),
@@ -1960,7 +1960,7 @@ where L::Target: Logger {
19601960
old_entry.next_hops_fee_msat = $next_hops_fee_msat;
19611961
old_entry.hop_use_fee_msat = hop_use_fee_msat;
19621962
old_entry.total_fee_msat = total_fee_msat;
1963-
old_entry.node_id = $dest_node_id.clone();
1963+
// old_entry.node_id = $dest_node_id.clone();
19641964
old_entry.candidate = $candidate.clone();
19651965
old_entry.fee_msat = 0; // This value will be later filled with hop_use_fee_msat of the following channel
19661966
old_entry.path_htlc_minimum_msat = path_htlc_minimum_msat;
@@ -2307,7 +2307,11 @@ where L::Target: Logger {
23072307

23082308
'path_walk: loop {
23092309
let mut features_set = false;
2310-
if let Some(first_channels) = first_hop_targets.get(&ordered_hops.last().unwrap().0.node_id) {
2310+
let target = match ordered_hops.last().unwrap().0.candidate.target() {
2311+
Some(target) => target,
2312+
None => break,
2313+
};
2314+
if let Some(first_channels) = first_hop_targets.get(&target) {
23112315
for details in first_channels {
23122316
if let Some(scid) = ordered_hops.last().unwrap().0.candidate.short_channel_id() {
23132317
if details.get_outbound_payment_scid().unwrap() == scid {
@@ -2319,7 +2323,7 @@ where L::Target: Logger {
23192323
}
23202324
}
23212325
if !features_set {
2322-
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.node_id) {
2326+
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.candidate.target().unwrap()) {
23232327
if let Some(node_info) = node.announcement_info.as_ref() {
23242328
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
23252329
} else {
@@ -2336,11 +2340,11 @@ where L::Target: Logger {
23362340
// save this path for the payment route. Also, update the liquidity
23372341
// remaining on the used hops, so that we take them into account
23382342
// while looking for more paths.
2339-
if ordered_hops.last().unwrap().0.node_id == maybe_dummy_payee_node_id {
2343+
if ordered_hops.last().unwrap().0.candidate.target().unwrap() == maybe_dummy_payee_node_id {
23402344
break 'path_walk;
23412345
}
23422346

2343-
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.node_id) {
2347+
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.candidate.target().unwrap()) {
23442348
Some(payment_hop) => payment_hop,
23452349
// We can't arrive at None because, if we ever add an entry to targets,
23462350
// we also fill in the entry in dist (see add_entry!).
@@ -2379,12 +2383,16 @@ where L::Target: Logger {
23792383
// Remember that we used these channels so that we don't rely
23802384
// on the same liquidity in future paths.
23812385
let mut prevented_redundant_path_selection = false;
2382-
let prev_hop_iter = core::iter::once(&our_node_id)
2383-
.chain(payment_path.hops.iter().map(|(hop, _)| &hop.node_id));
2386+
let prev_hop_iter = core::iter::once(our_node_id)
2387+
.chain(payment_path.hops.iter().map(|(hop, _)| hop.candidate.target().unwrap()));
23842388
for (prev_hop, (hop, _)) in prev_hop_iter.zip(payment_path.hops.iter()) {
2389+
let target = match hop.candidate.target() {
2390+
Some(target) => target,
2391+
None => break,
2392+
};
23852393
let spent_on_hop_msat = value_contribution_msat + hop.next_hops_fee_msat;
23862394
let used_liquidity_msat = used_liquidities
2387-
.entry(hop.candidate.id(*prev_hop < hop.node_id))
2395+
.entry(hop.candidate.id(prev_hop < target))
23882396
.and_modify(|used_liquidity_msat| *used_liquidity_msat += spent_on_hop_msat)
23892397
.or_insert(spent_on_hop_msat);
23902398
let hop_capacity = hop.candidate.effective_capacity();
@@ -2548,8 +2556,8 @@ where L::Target: Logger {
25482556
});
25492557
for idx in 0..(selected_route.len() - 1) {
25502558
if idx + 1 >= selected_route.len() { break; }
2551-
if iter_equal(selected_route[idx ].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id)),
2552-
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id))) {
2559+
if iter_equal(selected_route[idx].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target())),
2560+
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target()))) {
25532561
let new_value = selected_route[idx].get_value_msat() + selected_route[idx + 1].get_value_msat();
25542562
selected_route[idx].update_value_and_recompute_fees(new_value);
25552563
selected_route.remove(idx + 1);
@@ -2563,7 +2571,7 @@ where L::Target: Logger {
25632571
.filter(|(h, _)| h.candidate.short_channel_id().is_some())
25642572
{
25652573
hops.push(RouteHop {
2566-
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)})?,
2574+
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)})?,
25672575
node_features: node_features.clone(),
25682576
short_channel_id: hop.candidate.short_channel_id().unwrap(),
25692577
channel_features: hop.candidate.features(),

0 commit comments

Comments
 (0)