Skip to content

Commit 9d17f55

Browse files
committed
Track node_counter in RouteGraphNode
In a coming commit we'll start calling `add_entries_to_cheapest_to_target_node` without always having a public-graph node entry in order to process last- and first-hops via a common codepath. In order to do so, we always need the `node_counter` for the node, however, and thus we track them in `RouteGraphNode` and pass them through to `add_entries_to_cheapest_to_target_node` here. We also take this opportunity to swap the node preference logic to look at the counters, which is slightly less computational work, though it does require some unrelated test changes.
1 parent 4f2ea60 commit 9d17f55

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lightning/src/ln/reload_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) {
964964

965965
// Ensure that the remaining channel is fully operation and not blocked (and that after a
966966
// cycle of commitment updates the payment preimage is ultimately pruned).
967+
nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id());
967968
send_payment(&nodes[0], &[&nodes[2], &nodes[3]], 100_000);
968969
assert!(!get_monitor!(nodes[3], chan_id_not_persisted).get_stored_preimages().contains_key(&payment_hash));
969970
}

lightning/src/routing/router.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ impl_writeable_tlv_based!(RouteHintHop, {
11641164
#[repr(align(64))] // Force the size to 64 bytes
11651165
struct RouteGraphNode {
11661166
node_id: NodeId,
1167+
node_counter: u32,
11671168
score: u64,
11681169
// The maximum value a yet-to-be-constructed payment path might flow through this node.
11691170
// This value is upper-bounded by us by:
@@ -1178,7 +1179,7 @@ struct RouteGraphNode {
11781179

11791180
impl cmp::Ord for RouteGraphNode {
11801181
fn cmp(&self, other: &RouteGraphNode) -> cmp::Ordering {
1181-
other.score.cmp(&self.score).then_with(|| other.node_id.cmp(&self.node_id))
1182+
other.score.cmp(&self.score).then_with(|| other.node_counter.cmp(&self.node_counter))
11821183
}
11831184
}
11841185

@@ -2625,6 +2626,7 @@ where L::Target: Logger {
26252626
if !old_entry.was_processed && new_cost < old_cost {
26262627
let new_graph_node = RouteGraphNode {
26272628
node_id: src_node_id,
2629+
node_counter: src_node_counter,
26282630
score: cmp::max(total_fee_msat, path_htlc_minimum_msat).saturating_add(path_penalty_msat),
26292631
total_cltv_delta: hop_total_cltv_delta,
26302632
value_contribution_msat,
@@ -2703,7 +2705,7 @@ where L::Target: Logger {
27032705
// meaning how much will be paid in fees after this node (to the best of our knowledge).
27042706
// This data can later be helpful to optimize routing (pay lower fees).
27052707
macro_rules! add_entries_to_cheapest_to_target_node {
2706-
( $node: expr, $node_id: expr, $next_hops_value_contribution: expr,
2708+
( $node: expr, $node_counter: expr, $node_id: expr, $next_hops_value_contribution: expr,
27072709
$next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => {
27082710
let fee_to_target_msat;
27092711
let next_hops_path_htlc_minimum_msat;
@@ -2843,7 +2845,9 @@ where L::Target: Logger {
28432845
// If not, targets.pop() will not even let us enter the loop in step 2.
28442846
None => {},
28452847
Some(node) => {
2846-
add_entries_to_cheapest_to_target_node!(node, payee, path_value_msat, 0, 0);
2848+
add_entries_to_cheapest_to_target_node!(
2849+
node, node.node_counter, payee, path_value_msat, 0, 0
2850+
);
28472851
},
28482852
});
28492853

@@ -3071,7 +3075,7 @@ where L::Target: Logger {
30713075
// Both these cases (and other cases except reaching recommended_value_msat) mean that
30723076
// paths_collection will be stopped because found_new_path==false.
30733077
// This is not necessarily a routing failure.
3074-
'path_construction: while let Some(RouteGraphNode { node_id, total_cltv_delta, mut value_contribution_msat, path_length_to_node, .. }) = targets.pop() {
3078+
'path_construction: while let Some(RouteGraphNode { node_id, node_counter, total_cltv_delta, mut value_contribution_msat, path_length_to_node, .. }) = targets.pop() {
30753079

30763080
// Since we're going payee-to-payer, hitting our node as a target means we should stop
30773081
// traversing the graph and arrange the path out of what we found.
@@ -3209,7 +3213,8 @@ where L::Target: Logger {
32093213
match network_nodes.get(&node_id) {
32103214
None => {},
32113215
Some(node) => {
3212-
add_entries_to_cheapest_to_target_node!(node, node_id,
3216+
add_entries_to_cheapest_to_target_node!(
3217+
node, node_counter, node_id,
32133218
value_contribution_msat,
32143219
total_cltv_delta, path_length_to_node);
32153220
},

0 commit comments

Comments
 (0)