@@ -706,10 +706,17 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
706
706
let amt = directed_info. effective_capacity ( ) . as_msat ( ) ;
707
707
let dir_liq = liq. as_directed ( source, target, 0 , amt, self . decay_params ) ;
708
708
709
- let ( min_buckets , max_buckets , _ , _ ) = dir_liq. liquidity_history
709
+ let decayed_buckets = dir_liq. liquidity_history
710
710
. get_decayed_buckets ( now, * dir_liq. last_updated ,
711
711
self . decay_params . historical_no_updates_half_life ) ;
712
712
713
+ let ( min_buckets, max_buckets, _, _) =
714
+ if let Some ( buckets) = decayed_buckets { buckets } else {
715
+ // If the buckets, once decayed, end up being zero, print them out
716
+ // as zeros.
717
+ ( [ 0 ; 32 ] , [ 0 ; 32 ] , 0 , 0 )
718
+ } ;
719
+
713
720
log_debug ! ( self . logger, core:: concat!(
714
721
"Liquidity from {} to {} via {} is in the range ({}, {}).\n " ,
715
722
"\t Historical min liquidity bucket relative probabilities:\n " ,
@@ -806,13 +813,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
806
813
dir_liq. liquidity_history . get_decayed_buckets (
807
814
dir_liq. now , * dir_liq. last_updated ,
808
815
self . decay_params . historical_no_updates_half_life
809
- ) ;
810
-
811
- // If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point
812
- // scheme), treat it as if we were fully decayed.
813
- if valid_points. checked_shr ( required_decays) . unwrap_or ( 0 ) < 32 * 32 {
814
- return None ;
815
- }
816
+ ) ?;
816
817
817
818
// Note that the liquidity buckets are an offset from the edge, so we inverse
818
819
// the max order to get the probabilities from zero.
@@ -1744,7 +1745,7 @@ mod bucketed_history {
1744
1745
impl < D : Deref < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
1745
1746
#[ inline]
1746
1747
pub ( super ) fn get_decayed_buckets < T : Time > ( & self , now : T , last_updated : T , half_life : Duration )
1747
- -> ( [ u16 ; 32 ] , [ u16 ; 32 ] , u64 , u32 ) {
1748
+ -> Option < ( [ u16 ; 32 ] , [ u16 ; 32 ] , u64 , u32 ) > {
1748
1749
let required_decays = now. duration_since ( last_updated) . as_secs ( )
1749
1750
. checked_div ( half_life. as_secs ( ) )
1750
1751
. map_or ( u32:: max_value ( ) , |decays| cmp:: min ( decays, u32:: max_value ( ) as u64 ) as u32 ) ;
@@ -1756,11 +1757,17 @@ mod bucketed_history {
1756
1757
}
1757
1758
}
1758
1759
1760
+ // If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme),
1761
+ // treat it as if we were fully decayed.
1762
+ if total_valid_points_tracked. checked_shr ( required_decays) . unwrap_or ( 0 ) < 32 * 32 {
1763
+ return None ;
1764
+ }
1765
+
1759
1766
let mut min_buckets = * self . min_liquidity_offset_history ;
1760
1767
min_buckets. time_decay_data ( required_decays) ;
1761
1768
let mut max_buckets = * self . max_liquidity_offset_history ;
1762
1769
max_buckets. time_decay_data ( required_decays) ;
1763
- ( min_buckets. buckets , max_buckets. buckets , total_valid_points_tracked, required_decays)
1770
+ Some ( ( min_buckets. buckets , max_buckets. buckets , total_valid_points_tracked, required_decays) )
1764
1771
}
1765
1772
1766
1773
#[ inline]
@@ -1778,13 +1785,7 @@ mod bucketed_history {
1778
1785
// Check if all our buckets are zero, once decayed and treat it as if we had no data. We
1779
1786
// don't actually use the decayed buckets, though, as that would lose precision.
1780
1787
let ( decayed_min_buckets, decayed_max_buckets, total_valid_points_tracked, required_decays)
1781
- = self . get_decayed_buckets ( now, last_updated, half_life) ;
1782
-
1783
- // If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme), treat
1784
- // it as if we were fully decayed.
1785
- if total_valid_points_tracked. checked_shr ( required_decays) . unwrap_or ( 0 ) < 32 * 32 {
1786
- return None ;
1787
- }
1788
+ = self . get_decayed_buckets ( now, last_updated, half_life) ?;
1788
1789
1789
1790
let mut cumulative_success_prob_times_billion = 0 ;
1790
1791
// Special-case the 0th min bucket - it generally means we failed a payment, so only
0 commit comments