@@ -380,10 +380,12 @@ pub struct ProbabilisticScoringParameters {
380
380
/// Default value: 256 msat
381
381
pub amount_penalty_multiplier_msat : u64 ,
382
382
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.
384
386
///
385
387
/// (C-not exported)
386
- pub banned_nodes : HashSet < NodeId > ,
388
+ pub manual_node_penalties : HashMap < NodeId , u64 > ,
387
389
388
390
/// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
389
391
/// 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
486
488
/// Marks the node with the given `node_id` as banned, i.e.,
487
489
/// it will be avoided during path finding.
488
490
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 ( ) ) ;
490
492
}
491
493
492
494
/// Removes the node with the given `node_id` from the list of nodes to avoid.
493
495
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) ;
495
497
}
496
498
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 ( ) ;
500
512
}
501
513
}
502
514
@@ -508,7 +520,7 @@ impl ProbabilisticScoringParameters {
508
520
liquidity_penalty_multiplier_msat : 0 ,
509
521
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
510
522
amount_penalty_multiplier_msat : 0 ,
511
- banned_nodes : HashSet :: new ( ) ,
523
+ manual_node_penalties : HashMap :: new ( ) ,
512
524
anti_probing_penalty_msat : 0 ,
513
525
}
514
526
}
@@ -517,7 +529,7 @@ impl ProbabilisticScoringParameters {
517
529
/// they will be avoided during path finding.
518
530
pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
519
531
for id in node_ids {
520
- self . banned_nodes . insert ( id) ;
532
+ self . manual_node_penalties . insert ( id, u64 :: max_value ( ) ) ;
521
533
}
522
534
}
523
535
}
@@ -529,7 +541,7 @@ impl Default for ProbabilisticScoringParameters {
529
541
liquidity_penalty_multiplier_msat : 40_000 ,
530
542
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
531
543
amount_penalty_multiplier_msat : 256 ,
532
- banned_nodes : HashSet :: new ( ) ,
544
+ manual_node_penalties : HashMap :: new ( ) ,
533
545
anti_probing_penalty_msat : 250 ,
534
546
}
535
547
}
@@ -731,8 +743,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
731
743
fn channel_penalty_msat (
732
744
& self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
733
745
) -> 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 ;
736
748
}
737
749
738
750
let mut anti_probing_penalty_msat = 0 ;
0 commit comments