@@ -494,7 +494,6 @@ where L::Target: Logger {
494494 decay_params : ProbabilisticScoringDecayParameters ,
495495 network_graph : G ,
496496 logger : L ,
497- // TODO: Remove entries of closed channels.
498497 channel_liquidities : HashMap < u64 , ChannelLiquidity < T > > ,
499498}
500499
@@ -1074,6 +1073,16 @@ impl<T: Time> ChannelLiquidity<T> {
10741073 decay_params : decay_params,
10751074 }
10761075 }
1076+
1077+ fn decayed_offset ( & self , offset : u64 , decay_params : ProbabilisticScoringDecayParameters ) -> u64 {
1078+ let half_life = decay_params. liquidity_offset_half_life . as_secs ( ) ;
1079+ if half_life != 0 {
1080+ let elapsed_time = T :: now ( ) . duration_since ( self . last_updated ) . as_secs ( ) as f64 ;
1081+ ( ( offset as f64 ) * powf64 ( 0.5 , elapsed_time / ( half_life as f64 ) ) ) as u64
1082+ } else {
1083+ 0
1084+ }
1085+ }
10771086}
10781087
10791088/// Bounds `-log10` to avoid excessive liquidity penalties for payments with low success
@@ -1484,7 +1493,30 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ScoreUpdate for Prob
14841493 self . payment_path_failed ( path, u64:: max_value ( ) , duration_since_epoch)
14851494 }
14861495
1487- fn decay_liquidity_certainty ( & mut self , _duration_since_epoch : Duration ) { }
1496+ fn decay_liquidity_certainty ( & mut self , _duration_since_epoch : Duration ) {
1497+ let decay_params = self . decay_params ;
1498+ self . channel_liquidities . retain ( |_scid, liquidity| {
1499+ liquidity. min_liquidity_offset_msat = liquidity. decayed_offset ( liquidity. min_liquidity_offset_msat , decay_params) ;
1500+ liquidity. max_liquidity_offset_msat = liquidity. decayed_offset ( liquidity. max_liquidity_offset_msat , decay_params) ;
1501+ liquidity. last_updated = T :: now ( ) ;
1502+ let elapsed_time =
1503+ T :: now ( ) . duration_since ( liquidity. offset_history_last_updated ) ;
1504+ if elapsed_time > decay_params. historical_no_updates_half_life {
1505+ let half_life = decay_params. historical_no_updates_half_life . as_secs ( ) as f64 ;
1506+ let divisor = powf64 ( 2048.0 , ( elapsed_time. as_secs ( ) as f64 ) / half_life) as u64 ;
1507+ for bucket in liquidity. min_liquidity_offset_history . buckets . iter_mut ( ) {
1508+ * bucket = ( ( * bucket as u64 ) * 1024 / divisor) as u16 ;
1509+ }
1510+ for bucket in liquidity. max_liquidity_offset_history . buckets . iter_mut ( ) {
1511+ * bucket = ( ( * bucket as u64 ) * 1024 / divisor) as u16 ;
1512+ }
1513+ liquidity. offset_history_last_updated = T :: now ( ) ;
1514+ }
1515+ liquidity. min_liquidity_offset_msat != 0 || liquidity. max_liquidity_offset_msat != 0 ||
1516+ liquidity. min_liquidity_offset_history . buckets != [ 0 ; 32 ] ||
1517+ liquidity. max_liquidity_offset_history . buckets != [ 0 ; 32 ]
1518+ } ) ;
1519+ }
14881520}
14891521
14901522#[ cfg( c_bindings) ]
@@ -1922,7 +1954,7 @@ mod bucketed_history {
19221954 /// in each of 32 buckets.
19231955 #[ derive( Clone , Copy ) ]
19241956 pub ( super ) struct HistoricalBucketRangeTracker {
1925- buckets : [ u16 ; 32 ] ,
1957+ pub ( super ) buckets : [ u16 ; 32 ] ,
19261958 }
19271959
19281960 /// Buckets are stored in fixed point numbers with a 5 bit fractional part. Thus, the value
0 commit comments