@@ -673,8 +673,7 @@ struct ChannelLiquidity<T: Time> {
673673struct DirectedChannelLiquidity < L : Deref < Target = u64 > , BRT : Deref < Target = HistoricalBucketRangeTracker > , T : Time , U : Deref < Target = T > > {
674674 min_liquidity_offset_msat : L ,
675675 max_liquidity_offset_msat : L ,
676- min_liquidity_offset_history : BRT ,
677- max_liquidity_offset_history : BRT ,
676+ liquidity_history : HistoricalMinMaxBuckets < BRT > ,
678677 inflight_htlc_msat : u64 ,
679678 capacity_msat : u64 ,
680679 last_updated : U ,
@@ -715,12 +714,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
715714 let amt = directed_info. effective_capacity ( ) . as_msat ( ) ;
716715 let dir_liq = liq. as_directed ( source, target, 0 , amt, self . decay_params ) ;
717716
718- let buckets = HistoricalMinMaxBuckets {
719- min_liquidity_offset_history : & dir_liq. min_liquidity_offset_history ,
720- max_liquidity_offset_history : & dir_liq. max_liquidity_offset_history ,
721- } ;
722- let ( min_buckets, max_buckets, _) = buckets. get_decayed_buckets ( now,
723- * dir_liq. last_updated , self . decay_params . historical_no_updates_half_life ) ;
717+ let ( min_buckets, max_buckets, _) = dir_liq. liquidity_history
718+ . get_decayed_buckets ( now, * dir_liq. last_updated ,
719+ self . decay_params . historical_no_updates_half_life ) ;
724720
725721 log_debug ! ( self . logger, core:: concat!(
726722 "Liquidity from {} to {} via {} is in the range ({}, {}).\n " ,
@@ -797,12 +793,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
797793 let amt = directed_info. effective_capacity ( ) . as_msat ( ) ;
798794 let dir_liq = liq. as_directed ( source, target, 0 , amt, self . decay_params ) ;
799795
800- let buckets = HistoricalMinMaxBuckets {
801- min_liquidity_offset_history : & dir_liq. min_liquidity_offset_history ,
802- max_liquidity_offset_history : & dir_liq. max_liquidity_offset_history ,
803- } ;
804- let ( min_buckets, mut max_buckets, _) = buckets. get_decayed_buckets ( dir_liq. now ,
805- * dir_liq. last_updated , self . decay_params . historical_no_updates_half_life ) ;
796+ let ( min_buckets, mut max_buckets, _) = dir_liq. liquidity_history
797+ . get_decayed_buckets ( dir_liq. now , * dir_liq. last_updated ,
798+ self . decay_params . historical_no_updates_half_life ) ;
806799 // Note that the liquidity buckets are an offset from the edge, so we inverse
807800 // the max order to get the probabilities from zero.
808801 max_buckets. reverse ( ) ;
@@ -831,14 +824,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
831824 let capacity_msat = directed_info. effective_capacity ( ) . as_msat ( ) ;
832825 let dir_liq = liq. as_directed ( source, target, 0 , capacity_msat, self . decay_params ) ;
833826
834- let buckets = HistoricalMinMaxBuckets {
835- min_liquidity_offset_history : & dir_liq. min_liquidity_offset_history ,
836- max_liquidity_offset_history : & dir_liq. max_liquidity_offset_history ,
837- } ;
838-
839- return buckets. calculate_success_probability_times_billion ( dir_liq. now ,
840- * dir_liq. last_updated , self . decay_params . historical_no_updates_half_life ,
841- amount_msat, capacity_msat
827+ return dir_liq. liquidity_history . calculate_success_probability_times_billion (
828+ dir_liq. now , * dir_liq. last_updated ,
829+ self . decay_params . historical_no_updates_half_life , amount_msat, capacity_msat
842830 ) . map ( |p| p as f64 / ( 1024 * 1024 * 1024 ) as f64 ) ;
843831 }
844832 }
@@ -876,8 +864,10 @@ impl<T: Time> ChannelLiquidity<T> {
876864 DirectedChannelLiquidity {
877865 min_liquidity_offset_msat,
878866 max_liquidity_offset_msat,
879- min_liquidity_offset_history,
880- max_liquidity_offset_history,
867+ liquidity_history : HistoricalMinMaxBuckets {
868+ min_liquidity_offset_history,
869+ max_liquidity_offset_history,
870+ } ,
881871 inflight_htlc_msat,
882872 capacity_msat,
883873 last_updated : & self . last_updated ,
@@ -903,8 +893,10 @@ impl<T: Time> ChannelLiquidity<T> {
903893 DirectedChannelLiquidity {
904894 min_liquidity_offset_msat,
905895 max_liquidity_offset_msat,
906- min_liquidity_offset_history,
907- max_liquidity_offset_history,
896+ liquidity_history : HistoricalMinMaxBuckets {
897+ min_liquidity_offset_history,
898+ max_liquidity_offset_history,
899+ } ,
908900 inflight_htlc_msat,
909901 capacity_msat,
910902 last_updated : & mut self . last_updated ,
@@ -973,11 +965,7 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
973965
974966 if score_params. historical_liquidity_penalty_multiplier_msat != 0 ||
975967 score_params. historical_liquidity_penalty_amount_multiplier_msat != 0 {
976- let buckets = HistoricalMinMaxBuckets {
977- min_liquidity_offset_history : & self . min_liquidity_offset_history ,
978- max_liquidity_offset_history : & self . max_liquidity_offset_history ,
979- } ;
980- if let Some ( cumulative_success_prob_times_billion) = buckets
968+ if let Some ( cumulative_success_prob_times_billion) = self . liquidity_history
981969 . calculate_success_probability_times_billion ( self . now , * self . last_updated ,
982970 self . decay_params . historical_no_updates_half_life , amount_msat, self . capacity_msat )
983971 {
@@ -1087,15 +1075,15 @@ impl<L: DerefMut<Target = u64>, BRT: DerefMut<Target = HistoricalBucketRangeTrac
10871075 let half_lives = self . now . duration_since ( * self . last_updated ) . as_secs ( )
10881076 . checked_div ( self . decay_params . historical_no_updates_half_life . as_secs ( ) )
10891077 . map ( |v| v. try_into ( ) . unwrap_or ( u32:: max_value ( ) ) ) . unwrap_or ( u32:: max_value ( ) ) ;
1090- self . min_liquidity_offset_history . time_decay_data ( half_lives) ;
1091- self . max_liquidity_offset_history . time_decay_data ( half_lives) ;
1078+ self . liquidity_history . min_liquidity_offset_history . time_decay_data ( half_lives) ;
1079+ self . liquidity_history . max_liquidity_offset_history . time_decay_data ( half_lives) ;
10921080
10931081 let min_liquidity_offset_msat = self . decayed_offset_msat ( * self . min_liquidity_offset_msat ) ;
1094- self . min_liquidity_offset_history . track_datapoint (
1082+ self . liquidity_history . min_liquidity_offset_history . track_datapoint (
10951083 min_liquidity_offset_msat, self . capacity_msat
10961084 ) ;
10971085 let max_liquidity_offset_msat = self . decayed_offset_msat ( * self . max_liquidity_offset_msat ) ;
1098- self . max_liquidity_offset_history . track_datapoint (
1086+ self . liquidity_history . max_liquidity_offset_history . track_datapoint (
10991087 max_liquidity_offset_msat, self . capacity_msat
11001088 ) ;
11011089 }
@@ -1607,12 +1595,12 @@ mod bucketed_history {
16071595
16081596 impl_writeable_tlv_based ! ( HistoricalBucketRangeTracker , { ( 0 , buckets, required) } ) ;
16091597
1610- pub ( super ) struct HistoricalMinMaxBuckets < ' a > {
1611- pub ( super ) min_liquidity_offset_history : & ' a HistoricalBucketRangeTracker ,
1612- pub ( super ) max_liquidity_offset_history : & ' a HistoricalBucketRangeTracker ,
1598+ pub ( super ) struct HistoricalMinMaxBuckets < D : Deref < Target = HistoricalBucketRangeTracker > > {
1599+ pub ( super ) min_liquidity_offset_history : D ,
1600+ pub ( super ) max_liquidity_offset_history : D ,
16131601 }
16141602
1615- impl HistoricalMinMaxBuckets < ' _ > {
1603+ impl < D : Deref < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
16161604 #[ inline]
16171605 pub ( super ) fn get_decayed_buckets < T : Time > ( & self , now : T , last_updated : T , half_life : Duration )
16181606 -> ( [ u16 ; 8 ] , [ u16 ; 8 ] , u32 ) {
0 commit comments