Skip to content

Commit 58bca11

Browse files
committed
Move add/remove/clear methods back to scorer
1 parent 0bef91a commit 58bca11

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

lightning/src/routing/router.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,23 +5721,21 @@ mod tests {
57215721
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
57225722
let random_seed_bytes = keys_manager.get_secure_random_bytes();
57235723

5724-
let payment_params = PaymentParameters::from_node_id(nodes[10]);
5725-
let mut scorer_params = ProbabilisticScoringParameters::default();
5724+
let scorer_params = ProbabilisticScoringParameters::default();
5725+
let mut scorer = ProbabilisticScorer::new(scorer_params.clone(), Arc::clone(&network_graph), Arc::clone(&logger));
57265726

57275727
// First check we can get a route.
5728-
let scorer = ProbabilisticScorer::new(scorer_params.clone(), Arc::clone(&network_graph), Arc::clone(&logger));
5728+
let payment_params = PaymentParameters::from_node_id(nodes[10]);
57295729
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes);
57305730
assert!(route.is_ok());
57315731

57325732
// Then check that we can't get a route if we ban an intermediate node.
5733-
scorer_params.add_banned(&NodeId::from_pubkey(&nodes[3]));
5734-
let scorer = ProbabilisticScorer::new(scorer_params.clone(), Arc::clone(&network_graph), Arc::clone(&logger));
5733+
scorer.add_banned(&NodeId::from_pubkey(&nodes[3]));
57355734
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes);
57365735
assert!(route.is_err());
57375736

57385737
// Finally make sure we can route again, when we remove the ban.
5739-
scorer_params.remove_banned(&NodeId::from_pubkey(&nodes[3]));
5740-
let scorer = ProbabilisticScorer::new(scorer_params.clone(), Arc::clone(&network_graph), Arc::clone(&logger));
5738+
scorer.remove_banned(&NodeId::from_pubkey(&nodes[3]));
57415739
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes);
57425740
assert!(route.is_ok());
57435741
}

lightning/src/routing/scoring.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,22 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
439439
}
440440
}
441441
}
442+
443+
/// Marks the node with the given `node_id` as banned, i.e.,
444+
/// it will be avoided during path finding.
445+
pub fn add_banned(&mut self, node_id: &NodeId) {
446+
self.params.banned_nodes.insert(*node_id);
447+
}
448+
449+
/// Removes the node with the given `node_id` from the list of nodes to avoid.
450+
pub fn remove_banned(&mut self, node_id: &NodeId) {
451+
self.params.banned_nodes.remove(node_id);
452+
}
453+
454+
/// Clears the list of nodes that are avoided during path finding.
455+
pub fn clear_banned(&mut self) {
456+
self.params.banned_nodes = HashSet::new();
457+
}
442458
}
443459

444460
impl ProbabilisticScoringParameters {
@@ -453,29 +469,13 @@ impl ProbabilisticScoringParameters {
453469
}
454470
}
455471

456-
/// Marks the node with the given `node_id` as banned, i.e.,
457-
/// it will be avoided during path finding.
458-
pub fn add_banned(&mut self, node_id: &NodeId) {
459-
self.banned_nodes.insert(*node_id);
460-
}
461-
462472
/// Marks all nodes in the given list as banned, i.e.,
463473
/// they will be avoided during path finding.
464474
pub fn add_banned_from_list(&mut self, node_ids: Vec<NodeId>) {
465475
for id in node_ids {
466476
self.banned_nodes.insert(id);
467477
}
468478
}
469-
470-
/// Removes the node with the given `node_id` from the list of nodes to avoid.
471-
pub fn remove_banned(&mut self, node_id: &NodeId) {
472-
self.banned_nodes.remove(node_id);
473-
}
474-
475-
/// Clears the list of nodes that are avoided during path finding.
476-
pub fn clear_banned(&mut self) {
477-
self.banned_nodes = HashSet::new();
478-
}
479479
}
480480

481481
impl Default for ProbabilisticScoringParameters {

0 commit comments

Comments
 (0)