Skip to content

Commit ad178b2

Browse files
committed
Move add/remove/clear methods back to scorer
1 parent 398a69f commit ad178b2

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
@@ -5722,23 +5722,21 @@ mod tests {
57225722
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
57235723
let random_seed_bytes = keys_manager.get_secure_random_bytes();
57245724

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

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

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

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

lightning/src/routing/scoring.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
456456
}
457457
None
458458
}
459+
460+
/// Marks the node with the given `node_id` as banned, i.e.,
461+
/// it will be avoided during path finding.
462+
pub fn add_banned(&mut self, node_id: &NodeId) {
463+
self.params.banned_nodes.insert(*node_id);
464+
}
465+
466+
/// Removes the node with the given `node_id` from the list of nodes to avoid.
467+
pub fn remove_banned(&mut self, node_id: &NodeId) {
468+
self.params.banned_nodes.remove(node_id);
469+
}
470+
471+
/// Clears the list of nodes that are avoided during path finding.
472+
pub fn clear_banned(&mut self) {
473+
self.params.banned_nodes = HashSet::new();
474+
}
459475
}
460476

461477
impl ProbabilisticScoringParameters {
@@ -470,29 +486,13 @@ impl ProbabilisticScoringParameters {
470486
}
471487
}
472488

473-
/// Marks the node with the given `node_id` as banned, i.e.,
474-
/// it will be avoided during path finding.
475-
pub fn add_banned(&mut self, node_id: &NodeId) {
476-
self.banned_nodes.insert(*node_id);
477-
}
478-
479489
/// Marks all nodes in the given list as banned, i.e.,
480490
/// they will be avoided during path finding.
481491
pub fn add_banned_from_list(&mut self, node_ids: Vec<NodeId>) {
482492
for id in node_ids {
483493
self.banned_nodes.insert(id);
484494
}
485495
}
486-
487-
/// Removes the node with the given `node_id` from the list of nodes to avoid.
488-
pub fn remove_banned(&mut self, node_id: &NodeId) {
489-
self.banned_nodes.remove(node_id);
490-
}
491-
492-
/// Clears the list of nodes that are avoided during path finding.
493-
pub fn clear_banned(&mut self) {
494-
self.banned_nodes = HashSet::new();
495-
}
496496
}
497497

498498
impl Default for ProbabilisticScoringParameters {

0 commit comments

Comments
 (0)