@@ -673,8 +673,7 @@ struct ChannelLiquidity<T: Time> {
673
673
struct DirectedChannelLiquidity < L : Deref < Target = u64 > , BRT : Deref < Target = HistoricalBucketRangeTracker > , T : Time , U : Deref < Target = T > > {
674
674
min_liquidity_offset_msat : L ,
675
675
max_liquidity_offset_msat : L ,
676
- min_liquidity_offset_history : BRT ,
677
- max_liquidity_offset_history : BRT ,
676
+ liquidity_history : HistoricalMinMaxBuckets < BRT > ,
678
677
inflight_htlc_msat : u64 ,
679
678
capacity_msat : u64 ,
680
679
last_updated : U ,
@@ -715,12 +714,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
715
714
let amt = directed_info. effective_capacity ( ) . as_msat ( ) ;
716
715
let dir_liq = liq. as_directed ( source, target, 0 , amt, self . decay_params ) ;
717
716
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 ) ;
724
720
725
721
log_debug ! ( self . logger, core:: concat!(
726
722
"Liquidity from {} to {} via {} is in the range ({}, {}).\n " ,
@@ -797,12 +793,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
797
793
let amt = directed_info. effective_capacity ( ) . as_msat ( ) ;
798
794
let dir_liq = liq. as_directed ( source, target, 0 , amt, self . decay_params ) ;
799
795
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 ) ;
806
799
// Note that the liquidity buckets are an offset from the edge, so we inverse
807
800
// the max order to get the probabilities from zero.
808
801
max_buckets. reverse ( ) ;
@@ -831,14 +824,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
831
824
let capacity_msat = directed_info. effective_capacity ( ) . as_msat ( ) ;
832
825
let dir_liq = liq. as_directed ( source, target, 0 , capacity_msat, self . decay_params ) ;
833
826
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
842
830
) . map ( |p| p as f64 / ( 1024 * 1024 * 1024 ) as f64 ) ;
843
831
}
844
832
}
@@ -876,8 +864,10 @@ impl<T: Time> ChannelLiquidity<T> {
876
864
DirectedChannelLiquidity {
877
865
min_liquidity_offset_msat,
878
866
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
+ } ,
881
871
inflight_htlc_msat,
882
872
capacity_msat,
883
873
last_updated : & self . last_updated ,
@@ -903,8 +893,10 @@ impl<T: Time> ChannelLiquidity<T> {
903
893
DirectedChannelLiquidity {
904
894
min_liquidity_offset_msat,
905
895
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
+ } ,
908
900
inflight_htlc_msat,
909
901
capacity_msat,
910
902
last_updated : & mut self . last_updated ,
@@ -973,11 +965,7 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
973
965
974
966
if score_params. historical_liquidity_penalty_multiplier_msat != 0 ||
975
967
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
981
969
. calculate_success_probability_times_billion ( self . now , * self . last_updated ,
982
970
self . decay_params . historical_no_updates_half_life , amount_msat, self . capacity_msat )
983
971
{
@@ -1087,15 +1075,15 @@ impl<L: DerefMut<Target = u64>, BRT: DerefMut<Target = HistoricalBucketRangeTrac
1087
1075
let half_lives = self . now . duration_since ( * self . last_updated ) . as_secs ( )
1088
1076
. checked_div ( self . decay_params . historical_no_updates_half_life . as_secs ( ) )
1089
1077
. 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) ;
1092
1080
1093
1081
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 (
1095
1083
min_liquidity_offset_msat, self . capacity_msat
1096
1084
) ;
1097
1085
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 (
1099
1087
max_liquidity_offset_msat, self . capacity_msat
1100
1088
) ;
1101
1089
}
@@ -1607,12 +1595,12 @@ mod bucketed_history {
1607
1595
1608
1596
impl_writeable_tlv_based ! ( HistoricalBucketRangeTracker , { ( 0 , buckets, required) } ) ;
1609
1597
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 ,
1613
1601
}
1614
1602
1615
- impl HistoricalMinMaxBuckets < ' _ > {
1603
+ impl < D : Deref < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
1616
1604
#[ inline]
1617
1605
pub ( super ) fn get_decayed_buckets < T : Time > ( & self , now : T , last_updated : T , half_life : Duration )
1618
1606
-> ( [ u16 ; 8 ] , [ u16 ; 8 ] , u32 ) {
0 commit comments