@@ -362,10 +362,12 @@ pub struct ProbabilisticScoringParameters {
362
362
/// Default value: 256 msat
363
363
pub amount_penalty_multiplier_msat : u64 ,
364
364
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.
366
368
///
367
369
/// (C-not exported)
368
- pub banned_nodes : HashSet < NodeId > ,
370
+ pub manual_node_penalties : HashMap < NodeId , u64 > ,
369
371
370
372
/// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
371
373
/// 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
468
470
/// Marks the node with the given `node_id` as banned, i.e.,
469
471
/// it will be avoided during path finding.
470
472
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 ( ) ) ;
472
474
}
473
475
474
476
/// Removes the node with the given `node_id` from the list of nodes to avoid.
475
477
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) ;
477
479
}
478
480
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 ( ) ;
482
494
}
483
495
}
484
496
@@ -490,7 +502,7 @@ impl ProbabilisticScoringParameters {
490
502
liquidity_penalty_multiplier_msat : 0 ,
491
503
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
492
504
amount_penalty_multiplier_msat : 0 ,
493
- banned_nodes : HashSet :: new ( ) ,
505
+ manual_node_penalties : HashMap :: new ( ) ,
494
506
anti_probing_penalty_msat : 0 ,
495
507
}
496
508
}
@@ -499,7 +511,7 @@ impl ProbabilisticScoringParameters {
499
511
/// they will be avoided during path finding.
500
512
pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
501
513
for id in node_ids {
502
- self . banned_nodes . insert ( id) ;
514
+ self . manual_node_penalties . insert ( id, u64 :: max_value ( ) ) ;
503
515
}
504
516
}
505
517
}
@@ -511,7 +523,7 @@ impl Default for ProbabilisticScoringParameters {
511
523
liquidity_penalty_multiplier_msat : 40_000 ,
512
524
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
513
525
amount_penalty_multiplier_msat : 256 ,
514
- banned_nodes : HashSet :: new ( ) ,
526
+ manual_node_penalties : HashMap :: new ( ) ,
515
527
anti_probing_penalty_msat : 250 ,
516
528
}
517
529
}
@@ -713,8 +725,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
713
725
fn channel_penalty_msat (
714
726
& self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
715
727
) -> 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 ;
718
730
}
719
731
720
732
let mut anti_probing_penalty_msat = 0 ;
0 commit comments