Skip to content

Commit af60d48

Browse files
TheBlueMattadi2011
authored andcommitted
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 de5c43f commit af60d48

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
@@ -1196,6 +1196,7 @@ impl_writeable_tlv_based!(RouteHintHop, {
11961196
#[repr(align(64))] // Force the size to 64 bytes
11971197
struct RouteGraphNode {
11981198
node_id: NodeId,
1199+
node_counter: u32,
11991200
score: u64,
12001201
// The maximum value a yet-to-be-constructed payment path might flow through this node.
12011202
// This value is upper-bounded by us by:
@@ -1210,7 +1211,7 @@ struct RouteGraphNode {
12101211

12111212
impl cmp::Ord for RouteGraphNode {
12121213
fn cmp(&self, other: &RouteGraphNode) -> cmp::Ordering {
1213-
other.score.cmp(&self.score).then_with(|| other.node_id.cmp(&self.node_id))
1214+
other.score.cmp(&self.score).then_with(|| other.node_counter.cmp(&self.node_counter))
12141215
}
12151216
}
12161217

@@ -2657,6 +2658,7 @@ where L::Target: Logger {
26572658
if !old_entry.was_processed && new_cost < old_cost {
26582659
let new_graph_node = RouteGraphNode {
26592660
node_id: src_node_id,
2661+
node_counter: src_node_counter,
26602662
score: cmp::max(total_fee_msat, path_htlc_minimum_msat).saturating_add(path_penalty_msat),
26612663
total_cltv_delta: hop_total_cltv_delta,
26622664
value_contribution_msat,
@@ -2735,7 +2737,7 @@ where L::Target: Logger {
27352737
// meaning how much will be paid in fees after this node (to the best of our knowledge).
27362738
// This data can later be helpful to optimize routing (pay lower fees).
27372739
macro_rules! add_entries_to_cheapest_to_target_node {
2738-
( $node: expr, $node_id: expr, $next_hops_value_contribution: expr,
2740+
( $node: expr, $node_counter: expr, $node_id: expr, $next_hops_value_contribution: expr,
27392741
$next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => {
27402742
let fee_to_target_msat;
27412743
let next_hops_path_htlc_minimum_msat;
@@ -2875,7 +2877,9 @@ where L::Target: Logger {
28752877
// If not, targets.pop() will not even let us enter the loop in step 2.
28762878
None => {},
28772879
Some(node) => {
2878-
add_entries_to_cheapest_to_target_node!(node, payee, path_value_msat, 0, 0);
2880+
add_entries_to_cheapest_to_target_node!(
2881+
node, node.node_counter, payee, path_value_msat, 0, 0
2882+
);
28792883
},
28802884
});
28812885

@@ -3103,7 +3107,7 @@ where L::Target: Logger {
31033107
// Both these cases (and other cases except reaching recommended_value_msat) mean that
31043108
// paths_collection will be stopped because found_new_path==false.
31053109
// This is not necessarily a routing failure.
3106-
'path_construction: while let Some(RouteGraphNode { node_id, total_cltv_delta, mut value_contribution_msat, path_length_to_node, .. }) = targets.pop() {
3110+
'path_construction: while let Some(RouteGraphNode { node_id, node_counter, total_cltv_delta, mut value_contribution_msat, path_length_to_node, .. }) = targets.pop() {
31073111

31083112
// Since we're going payee-to-payer, hitting our node as a target means we should stop
31093113
// traversing the graph and arrange the path out of what we found.
@@ -3241,7 +3245,8 @@ where L::Target: Logger {
32413245
match network_nodes.get(&node_id) {
32423246
None => {},
32433247
Some(node) => {
3244-
add_entries_to_cheapest_to_target_node!(node, node_id,
3248+
add_entries_to_cheapest_to_target_node!(
3249+
node, node_counter, node_id,
32453250
value_contribution_msat,
32463251
total_cltv_delta, path_length_to_node);
32473252
},

0 commit comments

Comments
 (0)