@@ -300,6 +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 : HashSet < NodeId > ,
303
304
}
304
305
305
306
/// Parameters for configuring [`ProbabilisticScorer`].
@@ -399,6 +400,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
399
400
network_graph,
400
401
logger,
401
402
channel_liquidities : HashMap :: new ( ) ,
403
+ banned_nodes : HashSet :: new ( ) ,
402
404
}
403
405
}
404
406
@@ -408,6 +410,22 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
408
410
self
409
411
}
410
412
413
+ /// Marks the node with the given `node_id` as banned, i.e.,
414
+ /// it will be avoided during path finding.
415
+ pub fn add_banned ( & mut self , node_id : & NodeId ) {
416
+ self . banned_nodes . insert ( * node_id) ;
417
+ }
418
+
419
+ /// Removes the node with the given `node_id` from the list of nodes to avoid.
420
+ pub fn remove_banned ( & mut self , node_id : & NodeId ) {
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 ( ) ;
427
+ }
428
+
411
429
/// Dump the contents of this scorer into the configured logger.
412
430
///
413
431
/// Note that this writes roughly one line per channel for which we have a liquidity estimate,
@@ -655,6 +673,10 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
655
673
fn channel_penalty_msat (
656
674
& self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
657
675
) -> u64 {
676
+ if self . banned_nodes . contains ( source) || self . banned_nodes . contains ( target) {
677
+ return u64:: max_value ( ) ;
678
+ }
679
+
658
680
if let EffectiveCapacity :: ExactLiquidity { liquidity_msat } = usage. effective_capacity {
659
681
if usage. amount_msat > liquidity_msat {
660
682
return u64:: max_value ( ) ;
@@ -1055,7 +1077,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Writeable for Probab
1055
1077
#[ inline]
1056
1078
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1057
1079
write_tlv_fields ! ( w, {
1058
- ( 0 , self . channel_liquidities, required)
1080
+ ( 0 , self . channel_liquidities, required) ,
1059
1081
} ) ;
1060
1082
Ok ( ( ) )
1061
1083
}
@@ -1070,13 +1092,14 @@ ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsin
1070
1092
let ( params, network_graph, logger) = args;
1071
1093
let mut channel_liquidities = HashMap :: new ( ) ;
1072
1094
read_tlv_fields ! ( r, {
1073
- ( 0 , channel_liquidities, required)
1095
+ ( 0 , channel_liquidities, required) ,
1074
1096
} ) ;
1075
1097
Ok ( Self {
1076
1098
params,
1077
1099
network_graph,
1078
1100
logger,
1079
1101
channel_liquidities,
1102
+ banned_nodes : HashSet :: new ( ) ,
1080
1103
} )
1081
1104
}
1082
1105
}
0 commit comments