@@ -380,10 +380,12 @@ pub struct ProbabilisticScoringParameters {
380380 /// Default value: 256 msat
381381 pub amount_penalty_multiplier_msat : u64 ,
382382
383- /// A list of nodes that won't be considered during path finding.
383+ /// Manual penalties used for the given nodes. Allows to set a particular penalty for a given
384+ /// node. Note that a manual penalty of `u64::max_value()` means the node would not ever be
385+ /// considered during path finding.
384386 ///
385387 /// (C-not exported)
386- pub banned_nodes : HashSet < NodeId > ,
388+ pub manual_node_penalties : HashMap < NodeId , u64 > ,
387389
388390 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
389391 /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We
@@ -486,17 +488,27 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
486488 /// Marks the node with the given `node_id` as banned, i.e.,
487489 /// it will be avoided during path finding.
488490 pub fn add_banned ( & mut self , node_id : & NodeId ) {
489- self . params . banned_nodes . insert ( * node_id) ;
491+ self . params . manual_node_penalties . insert ( * node_id, u64 :: max_value ( ) ) ;
490492 }
491493
492494 /// Removes the node with the given `node_id` from the list of nodes to avoid.
493495 pub fn remove_banned ( & mut self , node_id : & NodeId ) {
494- self . params . banned_nodes . remove ( node_id) ;
496+ self . params . manual_node_penalties . remove ( node_id) ;
495497 }
496498
497- /// Clears the list of nodes that are avoided during path finding.
498- pub fn clear_banned ( & mut self ) {
499- self . params . banned_nodes = HashSet :: new ( ) ;
499+ /// Sets a manual penalty for the given node.
500+ pub fn set_manual_penalty ( & mut self , node_id : & NodeId , penalty : u64 ) {
501+ self . params . manual_node_penalties . insert ( * node_id, penalty) ;
502+ }
503+
504+ /// Removes the node with the given `node_id` from the list of manual penalties.
505+ pub fn remove_manual_penalty ( & mut self , node_id : & NodeId ) {
506+ self . params . manual_node_penalties . remove ( node_id) ;
507+ }
508+
509+ /// Clears the list of manual penalties that are applied during path finding.
510+ pub fn clear_manual_penalties ( & mut self ) {
511+ self . params . manual_node_penalties = HashMap :: new ( ) ;
500512 }
501513}
502514
@@ -508,7 +520,7 @@ impl ProbabilisticScoringParameters {
508520 liquidity_penalty_multiplier_msat : 0 ,
509521 liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
510522 amount_penalty_multiplier_msat : 0 ,
511- banned_nodes : HashSet :: new ( ) ,
523+ manual_node_penalties : HashMap :: new ( ) ,
512524 anti_probing_penalty_msat : 0 ,
513525 }
514526 }
@@ -517,7 +529,7 @@ impl ProbabilisticScoringParameters {
517529 /// they will be avoided during path finding.
518530 pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
519531 for id in node_ids {
520- self . banned_nodes . insert ( id) ;
532+ self . manual_node_penalties . insert ( id, u64 :: max_value ( ) ) ;
521533 }
522534 }
523535}
@@ -529,7 +541,7 @@ impl Default for ProbabilisticScoringParameters {
529541 liquidity_penalty_multiplier_msat : 40_000 ,
530542 liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
531543 amount_penalty_multiplier_msat : 256 ,
532- banned_nodes : HashSet :: new ( ) ,
544+ manual_node_penalties : HashMap :: new ( ) ,
533545 anti_probing_penalty_msat : 250 ,
534546 }
535547 }
@@ -731,8 +743,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
731743 fn channel_penalty_msat (
732744 & self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
733745 ) -> u64 {
734- if self . params . banned_nodes . contains ( source ) || self . params . banned_nodes . contains ( target) {
735- return u64 :: max_value ( ) ;
746+ if let Some ( penalty ) = self . params . manual_node_penalties . get ( target) {
747+ return * penalty ;
736748 }
737749
738750 let mut anti_probing_penalty_msat = 0 ;
0 commit comments