@@ -801,10 +801,10 @@ struct ChannelLiquidity {
801
801
}
802
802
803
803
/// A snapshot of [`ChannelLiquidity`] in one direction assuming a certain channel capacity.
804
- struct DirectedChannelLiquidity < L : Deref < Target = u64 > , BRT : Deref < Target = HistoricalBucketRangeTracker > , T : Deref < Target = Duration > > {
804
+ struct DirectedChannelLiquidity < L : Deref < Target = u64 > , HT : Deref < Target = HistoricalLiquidityTracker > , T : Deref < Target = Duration > > {
805
805
min_liquidity_offset_msat : L ,
806
806
max_liquidity_offset_msat : L ,
807
- liquidity_history : HistoricalMinMaxBuckets < BRT > ,
807
+ liquidity_history : DirectedHistoricalLiquidityTracker < HT > ,
808
808
capacity_msat : u64 ,
809
809
last_updated : T ,
810
810
offset_history_last_updated : T ,
@@ -991,7 +991,7 @@ impl ChannelLiquidity {
991
991
/// `capacity_msat`.
992
992
fn as_directed (
993
993
& self , source : & NodeId , target : & NodeId , capacity_msat : u64 ,
994
- ) -> DirectedChannelLiquidity < & u64 , & HistoricalBucketRangeTracker , & Duration > {
994
+ ) -> DirectedChannelLiquidity < & u64 , & HistoricalLiquidityTracker , & Duration > {
995
995
let source_less_than_target = source < target;
996
996
let ( min_liquidity_offset_msat, max_liquidity_offset_msat) =
997
997
if source_less_than_target {
@@ -1014,7 +1014,7 @@ impl ChannelLiquidity {
1014
1014
/// `capacity_msat`.
1015
1015
fn as_directed_mut (
1016
1016
& mut self , source : & NodeId , target : & NodeId , capacity_msat : u64 ,
1017
- ) -> DirectedChannelLiquidity < & mut u64 , & mut HistoricalBucketRangeTracker , & mut Duration > {
1017
+ ) -> DirectedChannelLiquidity < & mut u64 , & mut HistoricalLiquidityTracker , & mut Duration > {
1018
1018
let source_less_than_target = source < target;
1019
1019
let ( min_liquidity_offset_msat, max_liquidity_offset_msat) =
1020
1020
if source_less_than_target {
@@ -1128,8 +1128,8 @@ fn success_probability(
1128
1128
( numerator, denominator)
1129
1129
}
1130
1130
1131
- impl < L : Deref < Target = u64 > , BRT : Deref < Target = HistoricalBucketRangeTracker > , T : Deref < Target = Duration > >
1132
- DirectedChannelLiquidity < L , BRT , T > {
1131
+ impl < L : Deref < Target = u64 > , HT : Deref < Target = HistoricalLiquidityTracker > , T : Deref < Target = Duration > >
1132
+ DirectedChannelLiquidity < L , HT , T > {
1133
1133
/// Returns a liquidity penalty for routing the given HTLC `amount_msat` through the channel in
1134
1134
/// this direction.
1135
1135
fn penalty_msat ( & self , amount_msat : u64 , score_params : & ProbabilisticScoringFeeParameters ) -> u64 {
@@ -1234,8 +1234,8 @@ DirectedChannelLiquidity< L, BRT, T> {
1234
1234
}
1235
1235
}
1236
1236
1237
- impl < L : DerefMut < Target = u64 > , BRT : DerefMut < Target = HistoricalBucketRangeTracker > , T : DerefMut < Target = Duration > >
1238
- DirectedChannelLiquidity < L , BRT , T > {
1237
+ impl < L : DerefMut < Target = u64 > , HT : DerefMut < Target = HistoricalLiquidityTracker > , T : DerefMut < Target = Duration > >
1238
+ DirectedChannelLiquidity < L , HT , T > {
1239
1239
/// Adjusts the channel liquidity balance bounds when failing to route `amount_msat`.
1240
1240
fn failed_at_channel < Log : Deref > (
1241
1241
& mut self , amount_msat : u64 , duration_since_epoch : Duration , chan_descr : fmt:: Arguments , logger : & Log
@@ -1678,55 +1678,52 @@ mod bucketed_history {
1678
1678
}
1679
1679
1680
1680
pub ( super ) fn as_directed < ' a > ( & ' a self , source_less_than_target : bool )
1681
- -> HistoricalMinMaxBuckets < & ' a HistoricalBucketRangeTracker > {
1682
- let ( min_liquidity_offset_history, max_liquidity_offset_history) =
1683
- if source_less_than_target {
1684
- ( & self . min_liquidity_offset_history , & self . max_liquidity_offset_history )
1685
- } else {
1686
- ( & self . max_liquidity_offset_history , & self . min_liquidity_offset_history )
1687
- } ;
1688
- HistoricalMinMaxBuckets { min_liquidity_offset_history, max_liquidity_offset_history }
1681
+ -> DirectedHistoricalLiquidityTracker < & ' a HistoricalLiquidityTracker > {
1682
+ DirectedHistoricalLiquidityTracker { source_less_than_target, tracker : self }
1689
1683
}
1690
1684
1691
1685
pub ( super ) fn as_directed_mut < ' a > ( & ' a mut self , source_less_than_target : bool )
1692
- -> HistoricalMinMaxBuckets < & ' a mut HistoricalBucketRangeTracker > {
1693
- let ( min_liquidity_offset_history, max_liquidity_offset_history) =
1694
- if source_less_than_target {
1695
- ( & mut self . min_liquidity_offset_history , & mut self . max_liquidity_offset_history )
1696
- } else {
1697
- ( & mut self . max_liquidity_offset_history , & mut self . min_liquidity_offset_history )
1698
- } ;
1699
- HistoricalMinMaxBuckets { min_liquidity_offset_history, max_liquidity_offset_history }
1686
+ -> DirectedHistoricalLiquidityTracker < & ' a mut HistoricalLiquidityTracker > {
1687
+ DirectedHistoricalLiquidityTracker { source_less_than_target, tracker : self }
1700
1688
}
1701
1689
}
1702
1690
1703
1691
/// A set of buckets representing the history of where we've seen the minimum- and maximum-
1704
1692
/// liquidity bounds for a given channel.
1705
- pub ( super ) struct HistoricalMinMaxBuckets < D : Deref < Target = HistoricalBucketRangeTracker > > {
1706
- /// Buckets tracking where and how often we've seen the minimum liquidity bound for a
1707
- /// channel.
1708
- min_liquidity_offset_history : D ,
1709
- /// Buckets tracking where and how often we've seen the maximum liquidity bound for a
1710
- /// channel.
1711
- max_liquidity_offset_history : D ,
1693
+ pub ( super ) struct DirectedHistoricalLiquidityTracker < D : Deref < Target = HistoricalLiquidityTracker > > {
1694
+ source_less_than_target : bool ,
1695
+ tracker : D ,
1712
1696
}
1713
1697
1714
- impl < D : DerefMut < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
1698
+ impl < D : DerefMut < Target = HistoricalLiquidityTracker > > DirectedHistoricalLiquidityTracker < D > {
1715
1699
pub ( super ) fn track_datapoint (
1716
1700
& mut self , min_offset_msat : u64 , max_offset_msat : u64 , capacity_msat : u64 ,
1717
1701
) {
1718
- self . min_liquidity_offset_history . track_datapoint ( min_offset_msat, capacity_msat) ;
1719
- self . max_liquidity_offset_history . track_datapoint ( max_offset_msat, capacity_msat) ;
1702
+ if self . source_less_than_target {
1703
+ self . tracker . min_liquidity_offset_history . track_datapoint ( min_offset_msat, capacity_msat) ;
1704
+ self . tracker . max_liquidity_offset_history . track_datapoint ( max_offset_msat, capacity_msat) ;
1705
+ } else {
1706
+ self . tracker . max_liquidity_offset_history . track_datapoint ( min_offset_msat, capacity_msat) ;
1707
+ self . tracker . min_liquidity_offset_history . track_datapoint ( max_offset_msat, capacity_msat) ;
1708
+ }
1720
1709
}
1721
1710
}
1722
1711
1723
- impl < D : Deref < Target = HistoricalBucketRangeTracker > > HistoricalMinMaxBuckets < D > {
1712
+ impl < D : Deref < Target = HistoricalLiquidityTracker > > DirectedHistoricalLiquidityTracker < D > {
1724
1713
pub ( super ) fn min_liquidity_offset_history_buckets ( & self ) -> & [ u16 ; 32 ] {
1725
- & self . min_liquidity_offset_history . buckets
1714
+ if self . source_less_than_target {
1715
+ & self . tracker . min_liquidity_offset_history . buckets
1716
+ } else {
1717
+ & self . tracker . max_liquidity_offset_history . buckets
1718
+ }
1726
1719
}
1727
1720
1728
1721
pub ( super ) fn max_liquidity_offset_history_buckets ( & self ) -> & [ u16 ; 32 ] {
1729
- & self . max_liquidity_offset_history . buckets
1722
+ if self . source_less_than_target {
1723
+ & self . tracker . max_liquidity_offset_history . buckets
1724
+ } else {
1725
+ & self . tracker . min_liquidity_offset_history . buckets
1726
+ }
1730
1727
}
1731
1728
1732
1729
#[ inline]
@@ -1744,9 +1741,14 @@ mod bucketed_history {
1744
1741
let payment_pos = amount_to_pos ( amount_msat, capacity_msat) ;
1745
1742
if payment_pos >= POSITION_TICKS { return None ; }
1746
1743
1744
+ let min_liquidity_offset_history_buckets =
1745
+ self . min_liquidity_offset_history_buckets ( ) ;
1746
+ let max_liquidity_offset_history_buckets =
1747
+ self . max_liquidity_offset_history_buckets ( ) ;
1748
+
1747
1749
let mut total_valid_points_tracked = 0 ;
1748
- for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1749
- for max_bucket in self . max_liquidity_offset_history . buckets . iter ( ) . take ( 32 - min_idx) {
1750
+ for ( min_idx, min_bucket) in min_liquidity_offset_history_buckets . iter ( ) . enumerate ( ) {
1751
+ for max_bucket in max_liquidity_offset_history_buckets . iter ( ) . take ( 32 - min_idx) {
1750
1752
total_valid_points_tracked += ( * min_bucket as u64 ) * ( * max_bucket as u64 ) ;
1751
1753
}
1752
1754
}
@@ -1766,10 +1768,10 @@ mod bucketed_history {
1766
1768
// datapoint, many of which may have relatively high maximum-available-liquidity
1767
1769
// values, which will result in us thinking we have some nontrivial probability of
1768
1770
// routing up to that amount.
1769
- if self . min_liquidity_offset_history . buckets [ 0 ] != 0 {
1771
+ if min_liquidity_offset_history_buckets [ 0 ] != 0 {
1770
1772
let mut highest_max_bucket_with_points = 0 ; // The highest max-bucket with any data
1771
1773
let mut total_max_points = 0 ; // Total points in max-buckets to consider
1772
- for ( max_idx, max_bucket) in self . max_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1774
+ for ( max_idx, max_bucket) in max_liquidity_offset_history_buckets . iter ( ) . enumerate ( ) {
1773
1775
if * max_bucket >= BUCKET_FIXED_POINT_ONE {
1774
1776
highest_max_bucket_with_points = cmp:: max ( highest_max_bucket_with_points, max_idx) ;
1775
1777
}
@@ -1780,16 +1782,16 @@ mod bucketed_history {
1780
1782
let ( numerator, denominator) = success_probability ( payment_pos as u64 , 0 ,
1781
1783
max_bucket_end_pos as u64 , POSITION_TICKS as u64 - 1 , params, true ) ;
1782
1784
let bucket_prob_times_billion =
1783
- ( self . min_liquidity_offset_history . buckets [ 0 ] as u64 ) * total_max_points
1785
+ ( min_liquidity_offset_history_buckets [ 0 ] as u64 ) * total_max_points
1784
1786
* 1024 * 1024 * 1024 / total_valid_points_tracked;
1785
1787
cumulative_success_prob_times_billion += bucket_prob_times_billion *
1786
1788
numerator / denominator;
1787
1789
}
1788
1790
}
1789
1791
1790
- for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) . skip ( 1 ) {
1792
+ for ( min_idx, min_bucket) in min_liquidity_offset_history_buckets . iter ( ) . enumerate ( ) . skip ( 1 ) {
1791
1793
let min_bucket_start_pos = BUCKET_START_POS [ min_idx] ;
1792
- for ( max_idx, max_bucket) in self . max_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) . take ( 32 - min_idx) {
1794
+ for ( max_idx, max_bucket) in max_liquidity_offset_history_buckets . iter ( ) . enumerate ( ) . take ( 32 - min_idx) {
1793
1795
let max_bucket_end_pos = BUCKET_START_POS [ 32 - max_idx] - 1 ;
1794
1796
// Note that this multiply can only barely not overflow - two 16 bit ints plus
1795
1797
// 30 bits is 62 bits.
@@ -1814,7 +1816,7 @@ mod bucketed_history {
1814
1816
}
1815
1817
}
1816
1818
}
1817
- use bucketed_history:: { LegacyHistoricalBucketRangeTracker , HistoricalBucketRangeTracker , HistoricalMinMaxBuckets , HistoricalLiquidityTracker } ;
1819
+ use bucketed_history:: { LegacyHistoricalBucketRangeTracker , HistoricalBucketRangeTracker , DirectedHistoricalLiquidityTracker , HistoricalLiquidityTracker } ;
1818
1820
1819
1821
impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > Writeable for ProbabilisticScorer < G , L > where L :: Target : Logger {
1820
1822
#[ inline]
0 commit comments