@@ -300,7 +300,7 @@ where L::Target: Logger {
300
300
logger : L ,
301
301
// TODO: Remove entries of closed channels.
302
302
channel_liquidities : HashMap < u64 , ChannelLiquidity < T > > ,
303
- banned_nodes : Vec < NodeId > ,
303
+ banned_nodes : HashSet < NodeId > ,
304
304
}
305
305
306
306
/// Parameters for configuring [`ProbabilisticScorer`].
@@ -400,7 +400,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
400
400
network_graph,
401
401
logger,
402
402
channel_liquidities : HashMap :: new ( ) ,
403
- banned_nodes : Vec :: new ( ) ,
403
+ banned_nodes : HashSet :: new ( ) ,
404
404
}
405
405
}
406
406
@@ -413,12 +413,17 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
413
413
/// Marks the node with the given `node_id` as banned, i.e.,
414
414
/// it will be avoided during path finding.
415
415
pub fn set_banned ( & mut self , node_id : & NodeId ) {
416
- self . banned_nodes . push ( * node_id) ;
416
+ self . banned_nodes . insert ( * node_id) ;
417
417
}
418
418
419
419
/// Removes the node with the given `node_id` from the list of nodes to avoid.
420
420
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 ( ) ;
422
427
}
423
428
424
429
/// 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
1073
1078
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1074
1079
write_tlv_fields ! ( w, {
1075
1080
( 0 , self . channel_liquidities, required) ,
1076
- ( 1 , self . banned_nodes, vec_type) ,
1077
1081
} ) ;
1078
1082
Ok ( ( ) )
1079
1083
}
@@ -1087,17 +1091,15 @@ ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsin
1087
1091
) -> Result < Self , DecodeError > {
1088
1092
let ( params, network_graph, logger) = args;
1089
1093
let mut channel_liquidities = HashMap :: new ( ) ;
1090
- init_tlv_field_var ! ( banned_nodes, vec_type) ;
1091
1094
read_tlv_fields ! ( r, {
1092
1095
( 0 , channel_liquidities, required) ,
1093
- ( 1 , banned_nodes, vec_type) ,
1094
1096
} ) ;
1095
1097
Ok ( Self {
1096
1098
params,
1097
1099
network_graph,
1098
1100
logger,
1099
1101
channel_liquidities,
1100
- banned_nodes : init_tlv_based_struct_field ! ( banned_nodes , vec_type ) ,
1102
+ banned_nodes : HashSet :: new ( ) ,
1101
1103
} )
1102
1104
}
1103
1105
}
0 commit comments