@@ -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_offset_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_offset_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_offset_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_offset_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_offset_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_offset_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 ,
@@ -974,11 +966,7 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
974966
975967 if score_params. historical_liquidity_penalty_multiplier_msat != 0 ||
976968 score_params. historical_liquidity_penalty_amount_multiplier_msat != 0 {
977- let buckets = HistoricalMinMaxBuckets {
978- min_liquidity_offset_history : & self . min_liquidity_offset_history ,
979- max_liquidity_offset_history : & self . max_liquidity_offset_history ,
980- } ;
981- if let Some ( cumulative_success_prob_times_billion) = buckets
969+ if let Some ( cumulative_success_prob_times_billion) = self . liquidity_offset_history
982970 . calculate_success_probability_times_billion ( self . now , * self . last_updated ,
983971 self . decay_params . historical_no_updates_half_life , amount_msat, self . capacity_msat )
984972 {
@@ -1085,15 +1073,15 @@ impl<L: DerefMut<Target = u64>, BRT: DerefMut<Target = HistoricalBucketRangeTrac
10851073 let half_lives = self . now . duration_since ( * self . last_updated ) . as_secs ( )
10861074 . checked_div ( self . decay_params . historical_no_updates_half_life . as_secs ( ) )
10871075 . map ( |v| v. try_into ( ) . unwrap_or ( u32:: max_value ( ) ) ) . unwrap_or ( u32:: max_value ( ) ) ;
1088- self . min_liquidity_offset_history . time_decay_data ( half_lives) ;
1089- self . max_liquidity_offset_history . time_decay_data ( half_lives) ;
1076+ self . liquidity_offset_history . min_liquidity_offset_history . time_decay_data ( half_lives) ;
1077+ self . liquidity_offset_history . max_liquidity_offset_history . time_decay_data ( half_lives) ;
10901078
10911079 let min_liquidity_offset_msat = self . decayed_offset_msat ( * self . min_liquidity_offset_msat ) ;
1092- self . min_liquidity_offset_history . track_datapoint (
1080+ self . liquidity_offset_history . min_liquidity_offset_history . track_datapoint (
10931081 min_liquidity_offset_msat, self . capacity_msat
10941082 ) ;
10951083 let max_liquidity_offset_msat = self . decayed_offset_msat ( * self . max_liquidity_offset_msat ) ;
1096- self . max_liquidity_offset_history . track_datapoint (
1084+ self . liquidity_offset_history . max_liquidity_offset_history . track_datapoint (
10971085 max_liquidity_offset_msat, self . capacity_msat
10981086 ) ;
10991087 }
@@ -1605,12 +1593,12 @@ mod bucketed_history {
16051593
16061594 impl_writeable_tlv_based ! ( HistoricalBucketRangeTracker , { ( 0 , buckets, required) } ) ;
16071595
1608- pub ( super ) struct HistoricalMinMaxBuckets < ' a > {
1609- pub ( super ) min_liquidity_offset_history : & ' a HistoricalBucketRangeTracker ,
1610- pub ( super ) max_liquidity_offset_history : & ' a HistoricalBucketRangeTracker ,
1596+ pub ( super ) struct HistoricalMinMaxBuckets < D : Deref < Target = HistoricalBucketRangeTracker > > {
1597+ pub ( super ) min_liquidity_offset_history : D ,
1598+ pub ( super ) max_liquidity_offset_history : D ,
16111599 }
16121600
1613- impl HistoricalMinMaxBuckets < ' _ > {
1601+ impl < D : Deref < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
16141602 #[ inline]
16151603 pub ( super ) fn get_decayed_buckets < T : Time > ( & self , now : T , last_updated : T , half_life : Duration )
16161604 -> ( [ u16 ; 8 ] , [ u16 ; 8 ] , u32 ) {
0 commit comments