@@ -901,6 +901,10 @@ struct ChannelLiquidity {
901
901
/// Time when the historical liquidity bounds were last modified as an offset against the unix
902
902
/// epoch.
903
903
offset_history_last_updated : Duration ,
904
+
905
+ /// The last time when the liquidity bounds were updated with new payment information (i.e.
906
+ /// ignoring decays).
907
+ last_datapoint_time : Duration ,
904
908
}
905
909
906
910
/// A snapshot of [`ChannelLiquidity`] in one direction assuming a certain channel capacity.
@@ -911,6 +915,7 @@ struct DirectedChannelLiquidity<L: Deref<Target = u64>, HT: Deref<Target = Histo
911
915
capacity_msat : u64 ,
912
916
last_updated : T ,
913
917
offset_history_last_updated : T ,
918
+ last_datapoint_time : T ,
914
919
}
915
920
916
921
impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ProbabilisticScorer < G , L > where L :: Target : Logger {
@@ -1153,6 +1158,7 @@ impl ChannelLiquidity {
1153
1158
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
1154
1159
last_updated,
1155
1160
offset_history_last_updated : last_updated,
1161
+ last_datapoint_time : last_updated,
1156
1162
}
1157
1163
}
1158
1164
@@ -1185,6 +1191,7 @@ impl ChannelLiquidity {
1185
1191
capacity_msat,
1186
1192
last_updated : & self . last_updated ,
1187
1193
offset_history_last_updated : & self . offset_history_last_updated ,
1194
+ last_datapoint_time : & self . last_datapoint_time ,
1188
1195
}
1189
1196
}
1190
1197
@@ -1208,6 +1215,7 @@ impl ChannelLiquidity {
1208
1215
capacity_msat,
1209
1216
last_updated : & mut self . last_updated ,
1210
1217
offset_history_last_updated : & mut self . offset_history_last_updated ,
1218
+ last_datapoint_time : & mut self . last_datapoint_time ,
1211
1219
}
1212
1220
}
1213
1221
@@ -1554,6 +1562,7 @@ DirectedChannelLiquidity<L, HT, T> {
1554
1562
* self . max_liquidity_offset_msat = 0 ;
1555
1563
}
1556
1564
* self . last_updated = duration_since_epoch;
1565
+ * self . last_datapoint_time = duration_since_epoch;
1557
1566
}
1558
1567
1559
1568
/// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1563,6 +1572,7 @@ DirectedChannelLiquidity<L, HT, T> {
1563
1572
* self . min_liquidity_offset_msat = 0 ;
1564
1573
}
1565
1574
* self . last_updated = duration_since_epoch;
1575
+ * self . last_datapoint_time = duration_since_epoch;
1566
1576
}
1567
1577
}
1568
1578
@@ -2372,6 +2382,7 @@ impl Writeable for ChannelLiquidity {
2372
2382
( 5 , self . liquidity_history. writeable_min_offset_history( ) , required) ,
2373
2383
( 7 , self . liquidity_history. writeable_max_offset_history( ) , required) ,
2374
2384
( 9 , self . offset_history_last_updated, required) ,
2385
+ ( 11 , self . last_datapoint_time, required) ,
2375
2386
} ) ;
2376
2387
Ok ( ( ) )
2377
2388
}
@@ -2388,6 +2399,7 @@ impl Readable for ChannelLiquidity {
2388
2399
let mut max_liquidity_offset_history: Option < HistoricalBucketRangeTracker > = None ;
2389
2400
let mut last_updated = Duration :: from_secs ( 0 ) ;
2390
2401
let mut offset_history_last_updated = None ;
2402
+ let mut last_datapoint_time = None ;
2391
2403
read_tlv_fields ! ( r, {
2392
2404
( 0 , min_liquidity_offset_msat, required) ,
2393
2405
( 1 , legacy_min_liq_offset_history, option) ,
@@ -2397,6 +2409,7 @@ impl Readable for ChannelLiquidity {
2397
2409
( 5 , min_liquidity_offset_history, option) ,
2398
2410
( 7 , max_liquidity_offset_history, option) ,
2399
2411
( 9 , offset_history_last_updated, option) ,
2412
+ ( 11 , last_datapoint_time, option) ,
2400
2413
} ) ;
2401
2414
2402
2415
if min_liquidity_offset_history. is_none ( ) {
@@ -2421,6 +2434,7 @@ impl Readable for ChannelLiquidity {
2421
2434
) ,
2422
2435
last_updated,
2423
2436
offset_history_last_updated : offset_history_last_updated. unwrap_or ( last_updated) ,
2437
+ last_datapoint_time : last_datapoint_time. unwrap_or ( last_updated) ,
2424
2438
} )
2425
2439
}
2426
2440
}
@@ -2594,19 +2608,20 @@ mod tests {
2594
2608
let logger = TestLogger :: new ( ) ;
2595
2609
let last_updated = Duration :: ZERO ;
2596
2610
let offset_history_last_updated = Duration :: ZERO ;
2611
+ let last_datapoint_time = Duration :: ZERO ;
2597
2612
let network_graph = network_graph ( & logger) ;
2598
2613
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2599
2614
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2600
2615
. with_channel ( 42 ,
2601
2616
ChannelLiquidity {
2602
2617
min_liquidity_offset_msat : 700 , max_liquidity_offset_msat : 100 ,
2603
- last_updated, offset_history_last_updated,
2618
+ last_updated, offset_history_last_updated, last_datapoint_time ,
2604
2619
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2605
2620
} )
2606
2621
. with_channel ( 43 ,
2607
2622
ChannelLiquidity {
2608
2623
min_liquidity_offset_msat : 700 , max_liquidity_offset_msat : 100 ,
2609
- last_updated, offset_history_last_updated,
2624
+ last_updated, offset_history_last_updated, last_datapoint_time ,
2610
2625
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2611
2626
} ) ;
2612
2627
let source = source_node_id ( ) ;
@@ -2673,13 +2688,14 @@ mod tests {
2673
2688
let logger = TestLogger :: new ( ) ;
2674
2689
let last_updated = Duration :: ZERO ;
2675
2690
let offset_history_last_updated = Duration :: ZERO ;
2691
+ let last_datapoint_time = Duration :: ZERO ;
2676
2692
let network_graph = network_graph ( & logger) ;
2677
2693
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2678
2694
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2679
2695
. with_channel ( 42 ,
2680
2696
ChannelLiquidity {
2681
2697
min_liquidity_offset_msat : 200 , max_liquidity_offset_msat : 400 ,
2682
- last_updated, offset_history_last_updated,
2698
+ last_updated, offset_history_last_updated, last_datapoint_time ,
2683
2699
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2684
2700
} ) ;
2685
2701
let source = source_node_id ( ) ;
@@ -2733,13 +2749,14 @@ mod tests {
2733
2749
let logger = TestLogger :: new ( ) ;
2734
2750
let last_updated = Duration :: ZERO ;
2735
2751
let offset_history_last_updated = Duration :: ZERO ;
2752
+ let last_datapoint_time = Duration :: ZERO ;
2736
2753
let network_graph = network_graph ( & logger) ;
2737
2754
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2738
2755
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2739
2756
. with_channel ( 42 ,
2740
2757
ChannelLiquidity {
2741
2758
min_liquidity_offset_msat : 200 , max_liquidity_offset_msat : 400 ,
2742
- last_updated, offset_history_last_updated,
2759
+ last_updated, offset_history_last_updated, last_datapoint_time ,
2743
2760
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2744
2761
} ) ;
2745
2762
let source = source_node_id ( ) ;
@@ -2845,6 +2862,7 @@ mod tests {
2845
2862
let logger = TestLogger :: new ( ) ;
2846
2863
let last_updated = Duration :: ZERO ;
2847
2864
let offset_history_last_updated = Duration :: ZERO ;
2865
+ let last_datapoint_time = Duration :: ZERO ;
2848
2866
let network_graph = network_graph ( & logger) ;
2849
2867
let params = ProbabilisticScoringFeeParameters {
2850
2868
liquidity_penalty_multiplier_msat : 1_000 ,
@@ -2858,7 +2876,7 @@ mod tests {
2858
2876
. with_channel ( 42 ,
2859
2877
ChannelLiquidity {
2860
2878
min_liquidity_offset_msat : 40 , max_liquidity_offset_msat : 40 ,
2861
- last_updated, offset_history_last_updated,
2879
+ last_updated, offset_history_last_updated, last_datapoint_time ,
2862
2880
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2863
2881
} ) ;
2864
2882
let source = source_node_id ( ) ;
0 commit comments