Skip to content

Commit 1382696

Browse files
committed
Use HashSet, removed serialization.
1 parent cdf262f commit 1382696

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lightning/src/routing/scoring.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ where L::Target: Logger {
300300
logger: L,
301301
// TODO: Remove entries of closed channels.
302302
channel_liquidities: HashMap<u64, ChannelLiquidity<T>>,
303-
banned_nodes: Vec<NodeId>,
303+
banned_nodes: HashSet<NodeId>,
304304
}
305305

306306
/// Parameters for configuring [`ProbabilisticScorer`].
@@ -400,7 +400,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
400400
network_graph,
401401
logger,
402402
channel_liquidities: HashMap::new(),
403-
banned_nodes: Vec::new(),
403+
banned_nodes: HashSet::new(),
404404
}
405405
}
406406

@@ -413,12 +413,17 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
413413
/// Marks the node with the given `node_id` as banned, i.e.,
414414
/// it will be avoided during path finding.
415415
pub fn set_banned(&mut self, node_id: &NodeId) {
416-
self.banned_nodes.push(*node_id);
416+
self.banned_nodes.insert(*node_id);
417417
}
418418

419419
/// Removes the node with the given `node_id` from the list of nodes to avoid.
420420
pub fn remove_banned(&mut self, node_id: &NodeId) {
421-
self.banned_nodes.retain(|id| *id != *node_id);
421+
self.banned_nodes.remove(node_id);
422+
}
423+
424+
/// Clears the list of nodes that are avoided during path finding.
425+
pub fn clear_banned(&mut self) {
426+
self.banned_nodes = HashSet::new();
422427
}
423428

424429
/// Dump the contents of this scorer into the configured logger.
@@ -1073,7 +1078,6 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Writeable for Probab
10731078
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
10741079
write_tlv_fields!(w, {
10751080
(0, self.channel_liquidities, required),
1076-
(1, self.banned_nodes, vec_type),
10771081
});
10781082
Ok(())
10791083
}
@@ -1087,17 +1091,15 @@ ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsin
10871091
) -> Result<Self, DecodeError> {
10881092
let (params, network_graph, logger) = args;
10891093
let mut channel_liquidities = HashMap::new();
1090-
init_tlv_field_var!(banned_nodes, vec_type);
10911094
read_tlv_fields!(r, {
10921095
(0, channel_liquidities, required),
1093-
(1, banned_nodes, vec_type),
10941096
});
10951097
Ok(Self {
10961098
params,
10971099
network_graph,
10981100
logger,
10991101
channel_liquidities,
1100-
banned_nodes: init_tlv_based_struct_field!(banned_nodes, vec_type),
1102+
banned_nodes: HashSet::new(),
11011103
})
11021104
}
11031105
}

0 commit comments

Comments
 (0)