@@ -493,7 +493,6 @@ where L::Target: Logger {
493
493
decay_params : ProbabilisticScoringDecayParameters ,
494
494
network_graph : G ,
495
495
logger : L ,
496
- // TODO: Remove entries of closed channels.
497
496
channel_liquidities : HashMap < u64 , ChannelLiquidity < T > > ,
498
497
}
499
498
@@ -1073,6 +1072,16 @@ impl<T: Time> ChannelLiquidity<T> {
1073
1072
decay_params : decay_params,
1074
1073
}
1075
1074
}
1075
+
1076
+ fn decayed_offset ( & self , offset : u64 , decay_params : ProbabilisticScoringDecayParameters ) -> u64 {
1077
+ let half_life = decay_params. liquidity_offset_half_life . as_secs_f64 ( ) ;
1078
+ if half_life != 0.0 {
1079
+ let elapsed_time = T :: now ( ) . duration_since ( self . last_updated ) . as_secs_f64 ( ) ;
1080
+ ( ( offset as f64 ) * powf64 ( 0.5 , elapsed_time / half_life) ) as u64
1081
+ } else {
1082
+ 0
1083
+ }
1084
+ }
1076
1085
}
1077
1086
1078
1087
/// Bounds `-log10` to avoid excessive liquidity penalties for payments with low success
@@ -1490,7 +1499,32 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ScoreUpdate for Prob
1490
1499
self . payment_path_failed ( path, u64:: max_value ( ) , duration_since_epoch)
1491
1500
}
1492
1501
1493
- fn time_passed ( & mut self , _duration_since_epoch : Duration ) { }
1502
+ fn time_passed ( & mut self , _duration_since_epoch : Duration ) {
1503
+ let decay_params = self . decay_params ;
1504
+ self . channel_liquidities . retain ( |_scid, liquidity| {
1505
+ liquidity. min_liquidity_offset_msat = liquidity. decayed_offset ( liquidity. min_liquidity_offset_msat , decay_params) ;
1506
+ liquidity. max_liquidity_offset_msat = liquidity. decayed_offset ( liquidity. max_liquidity_offset_msat , decay_params) ;
1507
+ liquidity. last_updated = T :: now ( ) ;
1508
+ let elapsed_time =
1509
+ T :: now ( ) . duration_since ( liquidity. offset_history_last_updated ) ;
1510
+ if elapsed_time > decay_params. historical_no_updates_half_life {
1511
+ let half_life = decay_params. historical_no_updates_half_life . as_secs_f64 ( ) ;
1512
+ if half_life != 0.0 {
1513
+ let divisor = powf64 ( 2048.0 , elapsed_time. as_secs_f64 ( ) / half_life) as u64 ;
1514
+ for bucket in liquidity. min_liquidity_offset_history . buckets . iter_mut ( ) {
1515
+ * bucket = ( ( * bucket as u64 ) * 1024 / divisor) as u16 ;
1516
+ }
1517
+ for bucket in liquidity. max_liquidity_offset_history . buckets . iter_mut ( ) {
1518
+ * bucket = ( ( * bucket as u64 ) * 1024 / divisor) as u16 ;
1519
+ }
1520
+ liquidity. offset_history_last_updated = T :: now ( ) ;
1521
+ }
1522
+ }
1523
+ liquidity. min_liquidity_offset_msat != 0 || liquidity. max_liquidity_offset_msat != 0 ||
1524
+ liquidity. min_liquidity_offset_history . buckets != [ 0 ; 32 ] ||
1525
+ liquidity. max_liquidity_offset_history . buckets != [ 0 ; 32 ]
1526
+ } ) ;
1527
+ }
1494
1528
}
1495
1529
1496
1530
#[ cfg( c_bindings) ]
@@ -1928,7 +1962,7 @@ mod bucketed_history {
1928
1962
/// in each of 32 buckets.
1929
1963
#[ derive( Clone , Copy ) ]
1930
1964
pub ( super ) struct HistoricalBucketRangeTracker {
1931
- buckets : [ u16 ; 32 ] ,
1965
+ pub ( super ) buckets : [ u16 ; 32 ] ,
1932
1966
}
1933
1967
1934
1968
/// Buckets are stored in fixed point numbers with a 5 bit fractional part. Thus, the value
0 commit comments