@@ -300,14 +300,13 @@ where L::Target: Logger {
300
300
logger : L ,
301
301
// TODO: Remove entries of closed channels.
302
302
channel_liquidities : HashMap < u64 , ChannelLiquidity < T > > ,
303
- banned_nodes : HashSet < NodeId > ,
304
303
}
305
304
306
305
/// Parameters for configuring [`ProbabilisticScorer`].
307
306
///
308
307
/// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel
309
308
/// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
310
- #[ derive( Clone , Copy ) ]
309
+ #[ derive( Clone ) ]
311
310
pub struct ProbabilisticScoringParameters {
312
311
/// A fixed penalty in msats to apply to each channel.
313
312
///
@@ -362,6 +361,11 @@ pub struct ProbabilisticScoringParameters {
362
361
///
363
362
/// Default value: 256 msat
364
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 > ,
365
369
}
366
370
367
371
/// Accounting for channel liquidity balance uncertainty.
@@ -400,7 +404,6 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
400
404
network_graph,
401
405
logger,
402
406
channel_liquidities : HashMap :: new ( ) ,
403
- banned_nodes : HashSet :: new ( ) ,
404
407
}
405
408
}
406
409
@@ -410,22 +413,6 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
410
413
self
411
414
}
412
415
413
- /// Marks the node with the given `node_id` as banned, i.e.,
414
- /// it will be avoided during path finding.
415
- pub fn add_banned ( & mut self , node_id : & NodeId ) {
416
- self . banned_nodes . insert ( * node_id) ;
417
- }
418
-
419
- /// Removes the node with the given `node_id` from the list of nodes to avoid.
420
- pub fn remove_banned ( & mut self , node_id : & NodeId ) {
421
- self . banned_nodes . remove ( node_id) ;
422
- }
423
-
424
- /// Clears the list of nodes that are avoided during path finding.
425
- pub fn clear_banned ( & mut self ) {
426
- self . banned_nodes = HashSet :: new ( ) ;
427
- }
428
-
429
416
/// Dump the contents of this scorer into the configured logger.
430
417
///
431
418
/// Note that this writes roughly one line per channel for which we have a liquidity estimate,
@@ -479,8 +466,33 @@ impl ProbabilisticScoringParameters {
479
466
liquidity_penalty_multiplier_msat : 0 ,
480
467
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
481
468
amount_penalty_multiplier_msat : 0 ,
469
+ banned_nodes : HashSet :: new ( ) ,
470
+ }
471
+ }
472
+
473
+ /// Marks the node with the given `node_id` as banned, i.e.,
474
+ /// it will be avoided during path finding.
475
+ pub fn add_banned ( & mut self , node_id : & NodeId ) {
476
+ self . banned_nodes . insert ( * node_id) ;
477
+ }
478
+
479
+ /// Marks all nodes in the given list as banned, i.e.,
480
+ /// they will be avoided during path finding.
481
+ pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
482
+ for id in node_ids {
483
+ self . banned_nodes . insert ( id) ;
482
484
}
483
485
}
486
+
487
+ /// Removes the node with the given `node_id` from the list of nodes to avoid.
488
+ pub fn remove_banned ( & mut self , node_id : & NodeId ) {
489
+ self . banned_nodes . remove ( node_id) ;
490
+ }
491
+
492
+ /// Clears the list of nodes that are avoided during path finding.
493
+ pub fn clear_banned ( & mut self ) {
494
+ self . banned_nodes = HashSet :: new ( ) ;
495
+ }
484
496
}
485
497
486
498
impl Default for ProbabilisticScoringParameters {
@@ -490,6 +502,7 @@ impl Default for ProbabilisticScoringParameters {
490
502
liquidity_penalty_multiplier_msat : 40_000 ,
491
503
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
492
504
amount_penalty_multiplier_msat : 256 ,
505
+ banned_nodes : HashSet :: new ( ) ,
493
506
}
494
507
}
495
508
}
@@ -690,7 +703,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
690
703
fn channel_penalty_msat (
691
704
& self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
692
705
) -> u64 {
693
- if self . banned_nodes . contains ( source) || self . banned_nodes . contains ( target) {
706
+ if self . params . banned_nodes . contains ( source) || self . params . banned_nodes . contains ( target) {
694
707
return u64:: max_value ( ) ;
695
708
}
696
709
@@ -710,7 +723,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
710
723
. get ( & short_channel_id)
711
724
. unwrap_or ( & ChannelLiquidity :: new ( ) )
712
725
. as_directed ( source, target, capacity_msat, liquidity_offset_half_life)
713
- . penalty_msat ( amount_msat, self . params )
726
+ . penalty_msat ( amount_msat, self . params . clone ( ) )
714
727
}
715
728
716
729
fn payment_path_failed ( & mut self , path : & [ & RouteHop ] , short_channel_id : u64 ) {
@@ -1116,7 +1129,6 @@ ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsin
1116
1129
network_graph,
1117
1130
logger,
1118
1131
channel_liquidities,
1119
- banned_nodes : HashSet :: new ( ) ,
1120
1132
} )
1121
1133
}
1122
1134
}
@@ -1885,7 +1897,7 @@ mod tests {
1885
1897
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1886
1898
..ProbabilisticScoringParameters :: zero_penalty ( )
1887
1899
} ;
1888
- let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
1900
+ let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
1889
1901
let source = source_node_id ( ) ;
1890
1902
let target = target_node_id ( ) ;
1891
1903
let usage = ChannelUsage {
@@ -1921,7 +1933,7 @@ mod tests {
1921
1933
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1922
1934
..ProbabilisticScoringParameters :: zero_penalty ( )
1923
1935
} ;
1924
- let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
1936
+ let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
1925
1937
let source = source_node_id ( ) ;
1926
1938
let target = target_node_id ( ) ;
1927
1939
let usage = ChannelUsage {
@@ -2109,7 +2121,7 @@ mod tests {
2109
2121
let logger = TestLogger :: new ( ) ;
2110
2122
let network_graph = network_graph ( & logger) ;
2111
2123
let params = ProbabilisticScoringParameters :: default ( ) ;
2112
- let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2124
+ let scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
2113
2125
let source = source_node_id ( ) ;
2114
2126
let target = target_node_id ( ) ;
2115
2127
0 commit comments