@@ -706,7 +706,7 @@ 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 ( min_buckets, max_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
@@ -788,7 +788,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
788
788
/// in the top and bottom bucket, and roughly with similar (recent) frequency.
789
789
///
790
790
/// Because the datapoints are decayed slowly over time, values will eventually return to
791
- /// `Some(([0 ; 32], [0 ; 32]))`.
791
+ /// `Some(([1 ; 32], [1 ; 32]))` and then to `None` once no datapoints remain .
792
792
///
793
793
/// In order to fetch a single success probability from the buckets provided here, as used in
794
794
/// the scoring model, see [`Self::historical_estimated_payment_success_probability`].
@@ -802,9 +802,18 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
802
802
let amt = directed_info. effective_capacity ( ) . as_msat ( ) ;
803
803
let dir_liq = liq. as_directed ( source, target, 0 , amt, self . decay_params ) ;
804
804
805
- let ( min_buckets, mut max_buckets, _) = dir_liq. liquidity_history
806
- . get_decayed_buckets ( dir_liq. now , * dir_liq. last_updated ,
807
- self . decay_params . historical_no_updates_half_life ) ;
805
+ let ( min_buckets, mut max_buckets, valid_points, required_decays) =
806
+ dir_liq. liquidity_history . get_decayed_buckets (
807
+ dir_liq. now , * dir_liq. last_updated ,
808
+ 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
+
808
817
// Note that the liquidity buckets are an offset from the edge, so we inverse
809
818
// the max order to get the probabilities from zero.
810
819
max_buckets. reverse ( ) ;
@@ -1735,15 +1744,23 @@ mod bucketed_history {
1735
1744
impl < D : Deref < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
1736
1745
#[ inline]
1737
1746
pub ( super ) fn get_decayed_buckets < T : Time > ( & self , now : T , last_updated : T , half_life : Duration )
1738
- -> ( [ u16 ; 32 ] , [ u16 ; 32 ] , u32 ) {
1747
+ -> ( [ u16 ; 32 ] , [ u16 ; 32 ] , u64 , u32 ) {
1739
1748
let required_decays = now. duration_since ( last_updated) . as_secs ( )
1740
1749
. checked_div ( half_life. as_secs ( ) )
1741
1750
. map_or ( u32:: max_value ( ) , |decays| cmp:: min ( decays, u32:: max_value ( ) as u64 ) as u32 ) ;
1751
+
1752
+ let mut total_valid_points_tracked = 0 ;
1753
+ for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1754
+ for max_bucket in self . max_liquidity_offset_history . buckets . iter ( ) . take ( 32 - min_idx) {
1755
+ total_valid_points_tracked += ( * min_bucket as u64 ) * ( * max_bucket as u64 ) ;
1756
+ }
1757
+ }
1758
+
1742
1759
let mut min_buckets = * self . min_liquidity_offset_history ;
1743
1760
min_buckets. time_decay_data ( required_decays) ;
1744
1761
let mut max_buckets = * self . max_liquidity_offset_history ;
1745
1762
max_buckets. time_decay_data ( required_decays) ;
1746
- ( min_buckets. buckets , max_buckets. buckets , required_decays)
1763
+ ( min_buckets. buckets , max_buckets. buckets , total_valid_points_tracked , required_decays)
1747
1764
}
1748
1765
1749
1766
#[ inline]
@@ -1755,24 +1772,14 @@ mod bucketed_history {
1755
1772
// having a minimum above our maximum is an invalid state). For each combination,
1756
1773
// calculate the probability of success given our payment amount, then total the
1757
1774
// weighted average probability of success.
1758
- let mut total_valid_points_tracked = 0 ;
1759
-
1760
1775
let payment_pos = amount_to_pos ( amount_msat, capacity_msat) ;
1761
1776
if payment_pos >= POSITION_TICKS { return None ; }
1762
1777
1763
1778
// Check if all our buckets are zero, once decayed and treat it as if we had no data. We
1764
1779
// don't actually use the decayed buckets, though, as that would lose precision.
1765
- let ( decayed_min_buckets, decayed_max_buckets, required_decays) =
1766
- self . get_decayed_buckets ( now, last_updated, half_life) ;
1767
- if decayed_min_buckets. iter ( ) . all ( |v| * v == 0 ) || decayed_max_buckets. iter ( ) . all ( |v| * v == 0 ) {
1768
- return None ;
1769
- }
1780
+ let ( decayed_min_buckets, decayed_max_buckets, total_valid_points_tracked, required_decays)
1781
+ = self . get_decayed_buckets ( now, last_updated, half_life) ;
1770
1782
1771
- for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1772
- for max_bucket in self . max_liquidity_offset_history . buckets . iter ( ) . take ( 32 - min_idx) {
1773
- total_valid_points_tracked += ( * min_bucket as u64 ) * ( * max_bucket as u64 ) ;
1774
- }
1775
- }
1776
1783
// If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme), treat
1777
1784
// it as if we were fully decayed.
1778
1785
if total_valid_points_tracked. checked_shr ( required_decays) . unwrap_or ( 0 ) < 32 * 32 {
@@ -3100,7 +3107,7 @@ mod tests {
3100
3107
// Once fully decayed we still have data, but its all-0s. In the future we may remove the
3101
3108
// data entirely instead.
3102
3109
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3103
- Some ( ( [ 0 ; 32 ] , [ 0 ; 32 ] ) ) ) ;
3110
+ None ) ;
3104
3111
assert_eq ! ( scorer. historical_estimated_payment_success_probability( 42 , & target, 1 ) , None ) ;
3105
3112
3106
3113
let mut usage = ChannelUsage {
0 commit comments