Skip to content

Commit c4f7c3d

Browse files
committed
remove node_id from PathBuildingHop
use `CandidateRouteHop::target` function instead of `node_id`
1 parent 7ff66a7 commit c4f7c3d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

lightning/src/routing/router.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,6 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
12521252
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
12531253
#[derive(Clone)]
12541254
pub struct PathBuildingHop<'a> {
1255-
// Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
1256-
// is a larger refactor and will require careful performance analysis.
1257-
node_id: NodeId,
12581255
candidate: CandidateRouteHop<'a>,
12591256
fee_msat: u64,
12601257

@@ -1292,7 +1289,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
12921289
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
12931290
let mut debug_struct = f.debug_struct("PathBuildingHop");
12941291
debug_struct
1295-
.field("node_id", &self.node_id)
1292+
.field("node_id", &self.candidate.target())
12961293
.field("short_channel_id", &self.candidate.short_channel_id())
12971294
.field("total_fee_msat", &self.total_fee_msat)
12981295
.field("next_hops_fee_msat", &self.next_hops_fee_msat)
@@ -1945,7 +1942,6 @@ where L::Target: Logger {
19451942
// This will affect our decision on selecting short_channel_id
19461943
// as a way to reach the $dest_node_id.
19471944
PathBuildingHop {
1948-
node_id: $dest_node_id.clone(),
19491945
candidate: $candidate.clone(),
19501946
fee_msat: 0,
19511947
next_hops_fee_msat: u64::max_value(),
@@ -2035,7 +2031,6 @@ where L::Target: Logger {
20352031
old_entry.next_hops_fee_msat = $next_hops_fee_msat;
20362032
old_entry.hop_use_fee_msat = hop_use_fee_msat;
20372033
old_entry.total_fee_msat = total_fee_msat;
2038-
old_entry.node_id = $dest_node_id.clone();
20392034
old_entry.candidate = $candidate.clone();
20402035
old_entry.fee_msat = 0; // This value will be later filled with hop_use_fee_msat of the following channel
20412036
old_entry.path_htlc_minimum_msat = path_htlc_minimum_msat;
@@ -2405,7 +2400,7 @@ where L::Target: Logger {
24052400

24062401
'path_walk: loop {
24072402
let mut features_set = false;
2408-
if let Some(first_channels) = first_hop_targets.get(&ordered_hops.last().unwrap().0.node_id) {
2403+
if let Some(first_channels) = first_hop_targets.get(&ordered_hops.last().unwrap().0.candidate.target()) {
24092404
for details in first_channels {
24102405
if let Some(scid) = ordered_hops.last().unwrap().0.candidate.short_channel_id() {
24112406
if details.get_outbound_payment_scid().unwrap() == scid {
@@ -2417,7 +2412,7 @@ where L::Target: Logger {
24172412
}
24182413
}
24192414
if !features_set {
2420-
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.node_id) {
2415+
if let Some(node) = network_nodes.get(&ordered_hops.last().unwrap().0.candidate.target()) {
24212416
if let Some(node_info) = node.announcement_info.as_ref() {
24222417
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
24232418
} else {
@@ -2434,11 +2429,11 @@ where L::Target: Logger {
24342429
// save this path for the payment route. Also, update the liquidity
24352430
// remaining on the used hops, so that we take them into account
24362431
// while looking for more paths.
2437-
if ordered_hops.last().unwrap().0.node_id == maybe_dummy_payee_node_id {
2432+
if ordered_hops.last().unwrap().0.candidate.target() == maybe_dummy_payee_node_id {
24382433
break 'path_walk;
24392434
}
24402435

2441-
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.node_id) {
2436+
new_entry = match dist.remove(&ordered_hops.last().unwrap().0.candidate.target()) {
24422437
Some(payment_hop) => payment_hop,
24432438
// We can't arrive at None because, if we ever add an entry to targets,
24442439
// we also fill in the entry in dist (see add_entry!).
@@ -2477,12 +2472,13 @@ where L::Target: Logger {
24772472
// Remember that we used these channels so that we don't rely
24782473
// on the same liquidity in future paths.
24792474
let mut prevented_redundant_path_selection = false;
2480-
let prev_hop_iter = core::iter::once(&our_node_id)
2481-
.chain(payment_path.hops.iter().map(|(hop, _)| &hop.node_id));
2475+
let prev_hop_iter = core::iter::once(our_node_id)
2476+
.chain(payment_path.hops.iter().map(|(hop, _)| hop.candidate.target()));
24822477
for (prev_hop, (hop, _)) in prev_hop_iter.zip(payment_path.hops.iter()) {
2478+
let target = hop.candidate.target();
24832479
let spent_on_hop_msat = value_contribution_msat + hop.next_hops_fee_msat;
24842480
let used_liquidity_msat = used_liquidities
2485-
.entry(hop.candidate.id(*prev_hop < hop.node_id))
2481+
.entry(hop.candidate.id(prev_hop < target))
24862482
.and_modify(|used_liquidity_msat| *used_liquidity_msat += spent_on_hop_msat)
24872483
.or_insert(spent_on_hop_msat);
24882484
let hop_capacity = hop.candidate.effective_capacity();
@@ -2657,8 +2653,8 @@ where L::Target: Logger {
26572653
});
26582654
for idx in 0..(selected_route.len() - 1) {
26592655
if idx + 1 >= selected_route.len() { break; }
2660-
if iter_equal(selected_route[idx ].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id)),
2661-
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.node_id))) {
2656+
if iter_equal(selected_route[idx ].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target())),
2657+
selected_route[idx + 1].hops.iter().map(|h| (h.0.candidate.id(true), h.0.candidate.target()))) {
26622658
let new_value = selected_route[idx].get_value_msat() + selected_route[idx + 1].get_value_msat();
26632659
selected_route[idx].update_value_and_recompute_fees(new_value);
26642660
selected_route.remove(idx + 1);
@@ -2683,14 +2679,14 @@ where L::Target: Logger {
26832679
// there are announced channels between the endpoints. If so, the hop might be
26842680
// referring to any of the announced channels, as its `short_channel_id` might be
26852681
// an alias, in which case we don't take any chances here.
2686-
network_graph.node(&hop.node_id).map_or(false, |hop_node|
2682+
network_graph.node(&hop.candidate.target()).map_or(false, |hop_node|
26872683
hop_node.channels.iter().any(|scid| network_graph.channel(*scid)
26882684
.map_or(false, |c| c.as_directed_from(&prev_hop_node_id).is_some()))
26892685
)
26902686
};
26912687

26922688
hops.push(RouteHop {
2693-
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)})?,
2689+
pubkey: PublicKey::from_slice(hop.candidate.target().as_slice()).map_err(|_| LightningError{err: format!("Public key {:?} is invalid", &hop.candidate.target()), action: ErrorAction::IgnoreAndLog(Level::Trace)})?,
26942690
node_features: node_features.clone(),
26952691
short_channel_id: hop.candidate.short_channel_id().unwrap(),
26962692
channel_features: hop.candidate.features(),
@@ -2699,7 +2695,7 @@ where L::Target: Logger {
26992695
maybe_announced_channel,
27002696
});
27012697

2702-
prev_hop_node_id = hop.node_id;
2698+
prev_hop_node_id = hop.candidate.target();
27032699
}
27042700
let mut final_cltv_delta = final_cltv_expiry_delta;
27052701
let blinded_tail = payment_path.hops.last().and_then(|(h, _)| {

0 commit comments

Comments
 (0)