@@ -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,
@@ -462,8 +449,33 @@ impl ProbabilisticScoringParameters {
462
449
liquidity_penalty_multiplier_msat : 0 ,
463
450
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
464
451
amount_penalty_multiplier_msat : 0 ,
452
+ banned_nodes : HashSet :: new ( ) ,
453
+ }
454
+ }
455
+
456
+ /// Marks the node with the given `node_id` as banned, i.e.,
457
+ /// it will be avoided during path finding.
458
+ pub fn add_banned ( & mut self , node_id : & NodeId ) {
459
+ self . banned_nodes . insert ( * node_id) ;
460
+ }
461
+
462
+ /// Marks all nodes in the given list as banned, i.e.,
463
+ /// they will be avoided during path finding.
464
+ pub fn add_banned_from_list ( & mut self , node_ids : Vec < NodeId > ) {
465
+ for id in node_ids {
466
+ self . banned_nodes . insert ( id) ;
465
467
}
466
468
}
469
+
470
+ /// Removes the node with the given `node_id` from the list of nodes to avoid.
471
+ pub fn remove_banned ( & mut self , node_id : & NodeId ) {
472
+ self . banned_nodes . remove ( node_id) ;
473
+ }
474
+
475
+ /// Clears the list of nodes that are avoided during path finding.
476
+ pub fn clear_banned ( & mut self ) {
477
+ self . banned_nodes = HashSet :: new ( ) ;
478
+ }
467
479
}
468
480
469
481
impl Default for ProbabilisticScoringParameters {
@@ -473,6 +485,7 @@ impl Default for ProbabilisticScoringParameters {
473
485
liquidity_penalty_multiplier_msat : 40_000 ,
474
486
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
475
487
amount_penalty_multiplier_msat : 256 ,
488
+ banned_nodes : HashSet :: new ( ) ,
476
489
}
477
490
}
478
491
}
@@ -673,7 +686,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
673
686
fn channel_penalty_msat (
674
687
& self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage
675
688
) -> u64 {
676
- if self . banned_nodes . contains ( source) || self . banned_nodes . contains ( target) {
689
+ if self . params . banned_nodes . contains ( source) || self . params . banned_nodes . contains ( target) {
677
690
return u64:: max_value ( ) ;
678
691
}
679
692
@@ -693,7 +706,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
693
706
. get ( & short_channel_id)
694
707
. unwrap_or ( & ChannelLiquidity :: new ( ) )
695
708
. as_directed ( source, target, capacity_msat, liquidity_offset_half_life)
696
- . penalty_msat ( amount_msat, self . params )
709
+ . penalty_msat ( amount_msat, self . params . clone ( ) )
697
710
}
698
711
699
712
fn payment_path_failed ( & mut self , path : & [ & RouteHop ] , short_channel_id : u64 ) {
@@ -1099,7 +1112,6 @@ ReadableArgs<(ProbabilisticScoringParameters, G, L)> for ProbabilisticScorerUsin
1099
1112
network_graph,
1100
1113
logger,
1101
1114
channel_liquidities,
1102
- banned_nodes : HashSet :: new ( ) ,
1103
1115
} )
1104
1116
}
1105
1117
}
@@ -1868,7 +1880,7 @@ mod tests {
1868
1880
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1869
1881
..ProbabilisticScoringParameters :: zero_penalty ( )
1870
1882
} ;
1871
- let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
1883
+ let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
1872
1884
let source = source_node_id ( ) ;
1873
1885
let target = target_node_id ( ) ;
1874
1886
let usage = ChannelUsage {
@@ -1904,7 +1916,7 @@ mod tests {
1904
1916
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1905
1917
..ProbabilisticScoringParameters :: zero_penalty ( )
1906
1918
} ;
1907
- let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
1919
+ let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
1908
1920
let source = source_node_id ( ) ;
1909
1921
let target = target_node_id ( ) ;
1910
1922
let usage = ChannelUsage {
@@ -2092,7 +2104,7 @@ mod tests {
2092
2104
let logger = TestLogger :: new ( ) ;
2093
2105
let network_graph = network_graph ( & logger) ;
2094
2106
let params = ProbabilisticScoringParameters :: default ( ) ;
2095
- let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2107
+ let scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
2096
2108
let source = source_node_id ( ) ;
2097
2109
let target = target_node_id ( ) ;
2098
2110
0 commit comments