@@ -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
@@ -1483,7 +1492,30 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ScoreUpdate for Prob
14831492 self . payment_path_failed ( path, u64:: max_value ( ) , duration_since_epoch)
14841493 }
14851494
1486- fn decay_liquidity_certainty ( & mut self , _duration_since_epoch : Duration ) { }
1495+ fn decay_liquidity_certainty ( & mut self , _duration_since_epoch : Duration ) {
1496+ let decay_params = self . decay_params ;
1497+ self . channel_liquidities . retain ( |_scid, liquidity| {
1498+ liquidity. min_liquidity_offset_msat = liquidity. decayed_offset ( liquidity. min_liquidity_offset_msat , decay_params) ;
1499+ liquidity. max_liquidity_offset_msat = liquidity. decayed_offset ( liquidity. max_liquidity_offset_msat , decay_params) ;
1500+ liquidity. last_updated = T :: now ( ) ;
1501+ let elapsed_time =
1502+ T :: now ( ) . duration_since ( liquidity. offset_history_last_updated ) ;
1503+ if elapsed_time > decay_params. historical_no_updates_half_life {
1504+ let half_life = decay_params. historical_no_updates_half_life . as_secs ( ) as f64 ;
1505+ let divisor = powf64 ( 2048.0 , ( elapsed_time. as_secs ( ) as f64 ) / half_life) as u64 ;
1506+ for bucket in liquidity. min_liquidity_offset_history . buckets . iter_mut ( ) {
1507+ * bucket = ( ( * bucket as u64 ) * 1024 / divisor) as u16 ;
1508+ }
1509+ for bucket in liquidity. max_liquidity_offset_history . buckets . iter_mut ( ) {
1510+ * bucket = ( ( * bucket as u64 ) * 1024 / divisor) as u16 ;
1511+ }
1512+ liquidity. offset_history_last_updated = T :: now ( ) ;
1513+ }
1514+ liquidity. min_liquidity_offset_msat != 0 || liquidity. max_liquidity_offset_msat != 0 ||
1515+ liquidity. min_liquidity_offset_history . buckets != [ 0 ; 32 ] ||
1516+ liquidity. max_liquidity_offset_history . buckets != [ 0 ; 32 ]
1517+ } ) ;
1518+ }
14871519}
14881520
14891521#[ cfg( c_bindings) ]
@@ -1921,7 +1953,7 @@ mod bucketed_history {
19211953 /// in each of 32 buckets.
19221954 #[ derive( Clone , Copy ) ]
19231955 pub ( super ) struct HistoricalBucketRangeTracker {
1924- buckets : [ u16 ; 32 ] ,
1956+ pub ( super ) buckets : [ u16 ; 32 ] ,
19251957 }
19261958
19271959 /// Buckets are stored in fixed point numbers with a 5 bit fractional part. Thus, the value
0 commit comments