@@ -362,10 +362,12 @@ pub struct ProbabilisticScoringParameters {
362362 /// Default value: 256 msat
363363 pub amount_penalty_multiplier_msat : u64 ,
364364
365- /// A list of nodes that won't be considered during path finding.
365+ /// Manual penalties used for the given nodes. Allows to set a particular penalty for a given
366+ /// node. Note that a manual penalty of `u64::max_value()` means the node would not ever be
367+ /// considered during path finding.
366368 ///
367369 /// (C-not exported)
368- pub banned_nodes : HashSet < NodeId > ,
370+ pub manual_node_penalties : HashMap < NodeId , u64 > ,
369371
370372 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
371373 /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We
@@ -468,17 +470,27 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
468470 /// Marks the node with the given `node_id` as banned, i.e.,
469471 /// it will be avoided during path finding.
470472 pub fn add_banned ( & mut self , node_id : & NodeId ) {
471- self . params . banned_nodes . insert ( * node_id) ;
473+ self . params . manual_node_penalties . insert ( * node_id, u64 :: max_value ( ) ) ;
472474 }
473475
474476 /// Removes the node with the given `node_id` from the list of nodes to avoid.
475477 pub fn remove_banned ( & mut self , node_id : & NodeId ) {
476- self . params . banned_nodes . remove ( node_id) ;
478+ self . params . manual_node_penalties . remove ( node_id) ;
477479 }
478480
479- /// Clears the list of nodes that are avoided during path finding.
480- pub fn clear_banned ( & mut self ) {
481- self . params . banned_nodes = HashSet :: new ( ) ;
481+ /// Sets a manual penalty for the given node.
482+ pub fn set_manual_penalty ( & mut self , node_id : & NodeId , penalty : u64 ) {
483+ self . params . manual_node_penalties . insert ( * node_id, penalty) ;
484+ }
485+
486+ /// Removes the node with the given `node_id` from the list of manual penalties.
487+ pub fn remove_manual_penalty ( & mut self , node_id : & NodeId ) {
488+ self . params . manual_node_penalties . remove ( node_id) ;
489+ }
490+
491+ /// Clears the list of manual penalties that are applied during path finding.
492+ pub fn clear_manual_penalties ( & mut self ) {
493+ self . params . manual_node_penalties = HashMap :: new ( ) ;
482494 }
483495}
484496
@@ -490,7 +502,7 @@ impl ProbabilisticScoringParameters {
490502 liquidity_penalty_multiplier_msat : 0 ,
491503 liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
492504 amount_penalty_multiplier_msat : 0 ,
493- banned_nodes : HashSet :: new ( ) ,
505+ manual_node_penalties : HashMap :: new ( ) ,
494506 anti_probing_penalty_msat : 0 ,
495507 }
496508 }
@@ -499,7 +511,7 @@ impl ProbabilisticScoringParameters {
499511 /// they will be avoided during path finding.
500512 pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
501513 for id in node_ids {
502- self . banned_nodes . insert ( id) ;
514+ self . manual_node_penalties . insert ( id, u64 :: max_value ( ) ) ;
503515 }
504516 }
505517}
@@ -511,7 +523,7 @@ impl Default for ProbabilisticScoringParameters {
511523 liquidity_penalty_multiplier_msat : 40_000 ,
512524 liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
513525 amount_penalty_multiplier_msat : 256 ,
514- banned_nodes : HashSet :: new ( ) ,
526+ manual_node_penalties : HashMap :: new ( ) ,
515527 anti_probing_penalty_msat : 250 ,
516528 }
517529 }
@@ -713,8 +725,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
713725 fn channel_penalty_msat (
714726 & self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
715727 ) -> u64 {
716- if self . params . banned_nodes . contains ( source ) || self . params . banned_nodes . contains ( target) {
717- return u64 :: max_value ( ) ;
728+ if let Some ( penalty ) = self . params . manual_node_penalties . get ( target) {
729+ return * penalty ;
718730 }
719731
720732 let mut anti_probing_penalty_msat = 0 ;
0 commit comments