@@ -887,6 +887,7 @@ struct DummyLiquidity {
887
887
c : HistoricalLiquidityTracker ,
888
888
d : Duration ,
889
889
e : Duration ,
890
+ f : Duration ,
890
891
}
891
892
892
893
/// The amount of padding required to make [`ChannelLiquidity`] (plus a u64) a full 4 cache lines.
@@ -915,6 +916,10 @@ struct ChannelLiquidity {
915
916
/// epoch.
916
917
offset_history_last_updated : Duration ,
917
918
919
+ /// The last time when the liquidity bounds were updated with new payment information (i.e.
920
+ /// ignoring decays).
921
+ last_datapoint : Duration ,
922
+
918
923
_padding : [ u64 ; LIQ_PADDING_LEN ] ,
919
924
}
920
925
@@ -930,7 +935,7 @@ struct ChannelLiquidity {
930
935
//
931
936
// The next two cache lines will have the historical points, which we only access last during
932
937
// scoring, followed by the last_updated `Duration`s (which we do not need during scoring). The
933
- // extra padding brings us up to a clean four cache lines.
938
+ // `last_datapoint` `Duration` and extra padding bring us up to a clean 4 cache lines.
934
939
const _LIQUIDITY_MAP_SIZING_CHECK: usize = 256 - :: core:: mem:: size_of :: < ( u64 , ChannelLiquidity ) > ( ) ;
935
940
const _LIQUIDITY_MAP_SIZING_CHECK_2: usize = :: core:: mem:: size_of :: < ( u64 , ChannelLiquidity ) > ( ) - 256 ;
936
941
@@ -942,6 +947,7 @@ struct DirectedChannelLiquidity<L: Deref<Target = u64>, HT: Deref<Target = Histo
942
947
capacity_msat : u64 ,
943
948
last_updated : T ,
944
949
offset_history_last_updated : T ,
950
+ last_datapoint : T ,
945
951
}
946
952
947
953
impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ProbabilisticScorer < G , L > where L :: Target : Logger {
@@ -1184,6 +1190,7 @@ impl ChannelLiquidity {
1184
1190
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
1185
1191
last_updated,
1186
1192
offset_history_last_updated : last_updated,
1193
+ last_datapoint : last_updated,
1187
1194
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
1188
1195
}
1189
1196
}
@@ -1217,6 +1224,7 @@ impl ChannelLiquidity {
1217
1224
capacity_msat,
1218
1225
last_updated : & self . last_updated ,
1219
1226
offset_history_last_updated : & self . offset_history_last_updated ,
1227
+ last_datapoint : & self . last_datapoint ,
1220
1228
}
1221
1229
}
1222
1230
@@ -1240,6 +1248,7 @@ impl ChannelLiquidity {
1240
1248
capacity_msat,
1241
1249
last_updated : & mut self . last_updated ,
1242
1250
offset_history_last_updated : & mut self . offset_history_last_updated ,
1251
+ last_datapoint : & mut self . last_datapoint ,
1243
1252
}
1244
1253
}
1245
1254
@@ -1586,6 +1595,7 @@ DirectedChannelLiquidity<L, HT, T> {
1586
1595
* self . max_liquidity_offset_msat = 0 ;
1587
1596
}
1588
1597
* self . last_updated = duration_since_epoch;
1598
+ * self . last_datapoint = duration_since_epoch;
1589
1599
}
1590
1600
1591
1601
/// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1595,6 +1605,7 @@ DirectedChannelLiquidity<L, HT, T> {
1595
1605
* self . min_liquidity_offset_msat = 0 ;
1596
1606
}
1597
1607
* self . last_updated = duration_since_epoch;
1608
+ * self . last_datapoint = duration_since_epoch;
1598
1609
}
1599
1610
}
1600
1611
@@ -2404,6 +2415,7 @@ impl Writeable for ChannelLiquidity {
2404
2415
( 5 , self . liquidity_history. writeable_min_offset_history( ) , required) ,
2405
2416
( 7 , self . liquidity_history. writeable_max_offset_history( ) , required) ,
2406
2417
( 9 , self . offset_history_last_updated, required) ,
2418
+ ( 11 , self . last_datapoint, required) ,
2407
2419
} ) ;
2408
2420
Ok ( ( ) )
2409
2421
}
@@ -2420,6 +2432,7 @@ impl Readable for ChannelLiquidity {
2420
2432
let mut max_liquidity_offset_history: Option < HistoricalBucketRangeTracker > = None ;
2421
2433
let mut last_updated = Duration :: from_secs ( 0 ) ;
2422
2434
let mut offset_history_last_updated = None ;
2435
+ let mut last_datapoint = None ;
2423
2436
read_tlv_fields ! ( r, {
2424
2437
( 0 , min_liquidity_offset_msat, required) ,
2425
2438
( 1 , legacy_min_liq_offset_history, option) ,
@@ -2429,6 +2442,7 @@ impl Readable for ChannelLiquidity {
2429
2442
( 5 , min_liquidity_offset_history, option) ,
2430
2443
( 7 , max_liquidity_offset_history, option) ,
2431
2444
( 9 , offset_history_last_updated, option) ,
2445
+ ( 11 , last_datapoint, option) ,
2432
2446
} ) ;
2433
2447
2434
2448
if min_liquidity_offset_history. is_none ( ) {
@@ -2453,6 +2467,7 @@ impl Readable for ChannelLiquidity {
2453
2467
) ,
2454
2468
last_updated,
2455
2469
offset_history_last_updated : offset_history_last_updated. unwrap_or ( last_updated) ,
2470
+ last_datapoint : last_datapoint. unwrap_or ( last_updated) ,
2456
2471
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2457
2472
} )
2458
2473
}
@@ -2627,20 +2642,21 @@ mod tests {
2627
2642
let logger = TestLogger :: new ( ) ;
2628
2643
let last_updated = Duration :: ZERO ;
2629
2644
let offset_history_last_updated = Duration :: ZERO ;
2645
+ let last_datapoint = Duration :: ZERO ;
2630
2646
let network_graph = network_graph ( & logger) ;
2631
2647
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2632
2648
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2633
2649
. with_channel ( 42 ,
2634
2650
ChannelLiquidity {
2635
2651
min_liquidity_offset_msat : 700 , max_liquidity_offset_msat : 100 ,
2636
- last_updated, offset_history_last_updated,
2652
+ last_updated, offset_history_last_updated, last_datapoint ,
2637
2653
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2638
2654
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2639
2655
} )
2640
2656
. with_channel ( 43 ,
2641
2657
ChannelLiquidity {
2642
2658
min_liquidity_offset_msat : 700 , max_liquidity_offset_msat : 100 ,
2643
- last_updated, offset_history_last_updated,
2659
+ last_updated, offset_history_last_updated, last_datapoint ,
2644
2660
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2645
2661
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2646
2662
} ) ;
@@ -2708,13 +2724,14 @@ mod tests {
2708
2724
let logger = TestLogger :: new ( ) ;
2709
2725
let last_updated = Duration :: ZERO ;
2710
2726
let offset_history_last_updated = Duration :: ZERO ;
2727
+ let last_datapoint = Duration :: ZERO ;
2711
2728
let network_graph = network_graph ( & logger) ;
2712
2729
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2713
2730
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2714
2731
. with_channel ( 42 ,
2715
2732
ChannelLiquidity {
2716
2733
min_liquidity_offset_msat : 200 , max_liquidity_offset_msat : 400 ,
2717
- last_updated, offset_history_last_updated,
2734
+ last_updated, offset_history_last_updated, last_datapoint ,
2718
2735
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2719
2736
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2720
2737
} ) ;
@@ -2769,13 +2786,14 @@ mod tests {
2769
2786
let logger = TestLogger :: new ( ) ;
2770
2787
let last_updated = Duration :: ZERO ;
2771
2788
let offset_history_last_updated = Duration :: ZERO ;
2789
+ let last_datapoint = Duration :: ZERO ;
2772
2790
let network_graph = network_graph ( & logger) ;
2773
2791
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2774
2792
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2775
2793
. with_channel ( 42 ,
2776
2794
ChannelLiquidity {
2777
2795
min_liquidity_offset_msat : 200 , max_liquidity_offset_msat : 400 ,
2778
- last_updated, offset_history_last_updated,
2796
+ last_updated, offset_history_last_updated, last_datapoint ,
2779
2797
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2780
2798
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2781
2799
} ) ;
@@ -2882,6 +2900,7 @@ mod tests {
2882
2900
let logger = TestLogger :: new ( ) ;
2883
2901
let last_updated = Duration :: ZERO ;
2884
2902
let offset_history_last_updated = Duration :: ZERO ;
2903
+ let last_datapoint = Duration :: ZERO ;
2885
2904
let network_graph = network_graph ( & logger) ;
2886
2905
let params = ProbabilisticScoringFeeParameters {
2887
2906
liquidity_penalty_multiplier_msat : 1_000 ,
@@ -2895,7 +2914,7 @@ mod tests {
2895
2914
. with_channel ( 42 ,
2896
2915
ChannelLiquidity {
2897
2916
min_liquidity_offset_msat : 40 , max_liquidity_offset_msat : 40 ,
2898
- last_updated, offset_history_last_updated,
2917
+ last_updated, offset_history_last_updated, last_datapoint ,
2899
2918
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2900
2919
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2901
2920
} ) ;
0 commit comments