@@ -306,7 +306,7 @@ where L::Target: Logger {
306
306
///
307
307
/// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel
308
308
/// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
309
- #[ derive( Clone , Copy ) ]
309
+ #[ derive( Clone ) ]
310
310
pub struct ProbabilisticScoringParameters {
311
311
/// A fixed penalty in msats to apply to each channel.
312
312
///
@@ -361,6 +361,11 @@ pub struct ProbabilisticScoringParameters {
361
361
///
362
362
/// Default value: 256 msat
363
363
pub amount_penalty_multiplier_msat : u64 ,
364
+
365
+ /// A list of nodes that won't be considered during path finding.
366
+ ///
367
+ /// (C-not exported)
368
+ pub banned_nodes : HashSet < NodeId > ,
364
369
}
365
370
366
371
/// Accounting for channel liquidity balance uncertainty.
@@ -451,6 +456,22 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
451
456
}
452
457
None
453
458
}
459
+
460
+ /// Marks the node with the given `node_id` as banned, i.e.,
461
+ /// it will be avoided during path finding.
462
+ pub fn add_banned ( & mut self , node_id : & NodeId ) {
463
+ self . params . banned_nodes . insert ( * node_id) ;
464
+ }
465
+
466
+ /// Removes the node with the given `node_id` from the list of nodes to avoid.
467
+ pub fn remove_banned ( & mut self , node_id : & NodeId ) {
468
+ self . params . banned_nodes . remove ( node_id) ;
469
+ }
470
+
471
+ /// Clears the list of nodes that are avoided during path finding.
472
+ pub fn clear_banned ( & mut self ) {
473
+ self . params . banned_nodes = HashSet :: new ( ) ;
474
+ }
454
475
}
455
476
456
477
impl ProbabilisticScoringParameters {
@@ -461,6 +482,15 @@ impl ProbabilisticScoringParameters {
461
482
liquidity_penalty_multiplier_msat : 0 ,
462
483
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
463
484
amount_penalty_multiplier_msat : 0 ,
485
+ banned_nodes : HashSet :: new ( ) ,
486
+ }
487
+ }
488
+
489
+ /// Marks all nodes in the given list as banned, i.e.,
490
+ /// they will be avoided during path finding.
491
+ pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
492
+ for id in node_ids {
493
+ self . banned_nodes . insert ( id) ;
464
494
}
465
495
}
466
496
}
@@ -472,6 +502,7 @@ impl Default for ProbabilisticScoringParameters {
472
502
liquidity_penalty_multiplier_msat : 40_000 ,
473
503
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
474
504
amount_penalty_multiplier_msat : 256 ,
505
+ banned_nodes : HashSet :: new ( ) ,
475
506
}
476
507
}
477
508
}
@@ -543,7 +574,7 @@ const AMOUNT_PENALTY_DIVISOR: u64 = 1 << 20;
543
574
impl < L : Deref < Target = u64 > , T : Time , U : Deref < Target = T > > DirectedChannelLiquidity < L , T , U > {
544
575
/// Returns a penalty for routing the given HTLC `amount_msat` through the channel in this
545
576
/// direction.
546
- fn penalty_msat ( & self , amount_msat : u64 , params : ProbabilisticScoringParameters ) -> u64 {
577
+ fn penalty_msat ( & self , amount_msat : u64 , params : & ProbabilisticScoringParameters ) -> u64 {
547
578
let max_liquidity_msat = self . max_liquidity_msat ( ) ;
548
579
let min_liquidity_msat = core:: cmp:: min ( self . min_liquidity_msat ( ) , max_liquidity_msat) ;
549
580
if amount_msat <= min_liquidity_msat {
@@ -580,7 +611,7 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
580
611
#[ inline( always) ]
581
612
fn combined_penalty_msat (
582
613
& self , amount_msat : u64 , negative_log10_times_2048 : u64 ,
583
- params : ProbabilisticScoringParameters
614
+ params : & ProbabilisticScoringParameters
584
615
) -> u64 {
585
616
let liquidity_penalty_msat = {
586
617
// Upper bound the liquidity penalty to ensure some channel is selected.
@@ -672,6 +703,10 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
672
703
fn channel_penalty_msat (
673
704
& self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
674
705
) -> u64 {
706
+ if self . params . banned_nodes . contains ( source) || self . params . banned_nodes . contains ( target) {
707
+ return u64:: max_value ( ) ;
708
+ }
709
+
675
710
if let EffectiveCapacity :: ExactLiquidity { liquidity_msat } = usage. effective_capacity {
676
711
if usage. amount_msat > liquidity_msat {
677
712
return u64:: max_value ( ) ;
@@ -688,7 +723,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
688
723
. get ( & short_channel_id)
689
724
. unwrap_or ( & ChannelLiquidity :: new ( ) )
690
725
. as_directed ( source, target, capacity_msat, liquidity_offset_half_life)
691
- . penalty_msat ( amount_msat, self . params )
726
+ . penalty_msat ( amount_msat, & self . params )
692
727
}
693
728
694
729
fn payment_path_failed ( & mut self , path : & [ & RouteHop ] , short_channel_id : u64 ) {
@@ -1072,7 +1107,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Writeable for Probab
1072
1107
#[ inline]
1073
1108
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
1074
1109
write_tlv_fields ! ( w, {
1075
- ( 0 , self . channel_liquidities, required)
1110
+ ( 0 , self . channel_liquidities, required) ,
1076
1111
} ) ;
1077
1112
Ok ( ( ) )
1078
1113
}
@@ -1087,7 +1122,7 @@ ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsin
1087
1122
let ( params, network_graph, logger) = args;
1088
1123
let mut channel_liquidities = HashMap :: new ( ) ;
1089
1124
read_tlv_fields ! ( r, {
1090
- ( 0 , channel_liquidities, required)
1125
+ ( 0 , channel_liquidities, required) ,
1091
1126
} ) ;
1092
1127
Ok ( Self {
1093
1128
params,
@@ -1862,7 +1897,7 @@ mod tests {
1862
1897
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1863
1898
..ProbabilisticScoringParameters :: zero_penalty ( )
1864
1899
} ;
1865
- let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
1900
+ let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
1866
1901
let source = source_node_id ( ) ;
1867
1902
let target = target_node_id ( ) ;
1868
1903
let usage = ChannelUsage {
@@ -1898,7 +1933,7 @@ mod tests {
1898
1933
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1899
1934
..ProbabilisticScoringParameters :: zero_penalty ( )
1900
1935
} ;
1901
- let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
1936
+ let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
1902
1937
let source = source_node_id ( ) ;
1903
1938
let target = target_node_id ( ) ;
1904
1939
let usage = ChannelUsage {
@@ -2086,7 +2121,7 @@ mod tests {
2086
2121
let logger = TestLogger :: new ( ) ;
2087
2122
let network_graph = network_graph ( & logger) ;
2088
2123
let params = ProbabilisticScoringParameters :: default ( ) ;
2089
- let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2124
+ let scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
2090
2125
let source = source_node_id ( ) ;
2091
2126
let target = target_node_id ( ) ;
2092
2127
0 commit comments