@@ -779,6 +779,7 @@ struct DummyLiquidity {
779
779
c : HistoricalLiquidityTracker ,
780
780
d : Duration ,
781
781
e : Duration ,
782
+ f : Duration ,
782
783
}
783
784
784
785
/// The amount of padding required to make [`ChannelLiquidity`] (plus a u64) a full 4 cache lines.
@@ -806,6 +807,10 @@ struct ChannelLiquidity {
806
807
/// epoch.
807
808
offset_history_last_updated : Duration ,
808
809
810
+ /// The last time when the liquidity bounds were updated with new payment information (i.e.
811
+ /// ignoring decays).
812
+ last_datapoint : Duration ,
813
+
809
814
_padding : [ u64 ; LIQ_PADDING_LEN ] ,
810
815
}
811
816
@@ -821,7 +826,7 @@ struct ChannelLiquidity {
821
826
//
822
827
// The next two cache lines will have the historical points, which we only access last during
823
828
// scoring, followed by the last_updated `Duration`s (which we do not need during scoring). The
824
- // extra padding brings us up to a clean four cache lines.
829
+ // `last_datapoint` `Duration` and extra padding bring us up to a clean 4 cache lines.
825
830
const _LIQUIDITY_MAP_SIZING_CHECK: usize = 256 - :: core:: mem:: size_of :: < ( u64 , ChannelLiquidity ) > ( ) ;
826
831
const _LIQUIDITY_MAP_SIZING_CHECK_2: usize = :: core:: mem:: size_of :: < ( u64 , ChannelLiquidity ) > ( ) - 256 ;
827
832
@@ -833,6 +838,7 @@ struct DirectedChannelLiquidity<L: Deref<Target = u64>, HT: Deref<Target = Histo
833
838
capacity_msat : u64 ,
834
839
last_updated : T ,
835
840
offset_history_last_updated : T ,
841
+ last_datapoint : T ,
836
842
}
837
843
838
844
impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ProbabilisticScorer < G , L > where L :: Target : Logger {
@@ -1009,6 +1015,7 @@ impl ChannelLiquidity {
1009
1015
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
1010
1016
last_updated,
1011
1017
offset_history_last_updated : last_updated,
1018
+ last_datapoint : last_updated,
1012
1019
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
1013
1020
}
1014
1021
}
@@ -1033,6 +1040,7 @@ impl ChannelLiquidity {
1033
1040
capacity_msat,
1034
1041
last_updated : & self . last_updated ,
1035
1042
offset_history_last_updated : & self . offset_history_last_updated ,
1043
+ last_datapoint : & self . last_datapoint ,
1036
1044
}
1037
1045
}
1038
1046
@@ -1056,6 +1064,7 @@ impl ChannelLiquidity {
1056
1064
capacity_msat,
1057
1065
last_updated : & mut self . last_updated ,
1058
1066
offset_history_last_updated : & mut self . offset_history_last_updated ,
1067
+ last_datapoint : & mut self . last_datapoint ,
1059
1068
}
1060
1069
}
1061
1070
@@ -1335,6 +1344,7 @@ DirectedChannelLiquidity<L, HT, T> {
1335
1344
* self . max_liquidity_offset_msat = 0 ;
1336
1345
}
1337
1346
* self . last_updated = duration_since_epoch;
1347
+ * self . last_datapoint = duration_since_epoch;
1338
1348
}
1339
1349
1340
1350
/// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1344,6 +1354,7 @@ DirectedChannelLiquidity<L, HT, T> {
1344
1354
* self . min_liquidity_offset_msat = 0 ;
1345
1355
}
1346
1356
* self . last_updated = duration_since_epoch;
1357
+ * self . last_datapoint = duration_since_epoch;
1347
1358
}
1348
1359
}
1349
1360
@@ -1953,6 +1964,7 @@ impl Writeable for ChannelLiquidity {
1953
1964
( 5 , self . liquidity_history. writeable_min_offset_history( ) , required) ,
1954
1965
( 7 , self . liquidity_history. writeable_max_offset_history( ) , required) ,
1955
1966
( 9 , self . offset_history_last_updated, required) ,
1967
+ ( 11 , self . last_datapoint, required) ,
1956
1968
} ) ;
1957
1969
Ok ( ( ) )
1958
1970
}
@@ -1969,6 +1981,7 @@ impl Readable for ChannelLiquidity {
1969
1981
let mut max_liquidity_offset_history: Option < HistoricalBucketRangeTracker > = None ;
1970
1982
let mut last_updated = Duration :: from_secs ( 0 ) ;
1971
1983
let mut offset_history_last_updated = None ;
1984
+ let mut last_datapoint = None ;
1972
1985
read_tlv_fields ! ( r, {
1973
1986
( 0 , min_liquidity_offset_msat, required) ,
1974
1987
( 1 , legacy_min_liq_offset_history, option) ,
@@ -1978,6 +1991,7 @@ impl Readable for ChannelLiquidity {
1978
1991
( 5 , min_liquidity_offset_history, option) ,
1979
1992
( 7 , max_liquidity_offset_history, option) ,
1980
1993
( 9 , offset_history_last_updated, option) ,
1994
+ ( 11 , last_datapoint, option) ,
1981
1995
} ) ;
1982
1996
1983
1997
if min_liquidity_offset_history. is_none ( ) {
@@ -2002,6 +2016,7 @@ impl Readable for ChannelLiquidity {
2002
2016
) ,
2003
2017
last_updated,
2004
2018
offset_history_last_updated : offset_history_last_updated. unwrap_or ( last_updated) ,
2019
+ last_datapoint : last_datapoint. unwrap_or ( last_updated) ,
2005
2020
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2006
2021
} )
2007
2022
}
@@ -2175,20 +2190,21 @@ mod tests {
2175
2190
let logger = TestLogger :: new ( ) ;
2176
2191
let last_updated = Duration :: ZERO ;
2177
2192
let offset_history_last_updated = Duration :: ZERO ;
2193
+ let last_datapoint = Duration :: ZERO ;
2178
2194
let network_graph = network_graph ( & logger) ;
2179
2195
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2180
2196
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2181
2197
. with_channel ( 42 ,
2182
2198
ChannelLiquidity {
2183
2199
min_liquidity_offset_msat : 700 , max_liquidity_offset_msat : 100 ,
2184
- last_updated, offset_history_last_updated,
2200
+ last_updated, offset_history_last_updated, last_datapoint ,
2185
2201
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2186
2202
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2187
2203
} )
2188
2204
. with_channel ( 43 ,
2189
2205
ChannelLiquidity {
2190
2206
min_liquidity_offset_msat : 700 , max_liquidity_offset_msat : 100 ,
2191
- last_updated, offset_history_last_updated,
2207
+ last_updated, offset_history_last_updated, last_datapoint ,
2192
2208
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2193
2209
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2194
2210
} ) ;
@@ -2256,13 +2272,14 @@ mod tests {
2256
2272
let logger = TestLogger :: new ( ) ;
2257
2273
let last_updated = Duration :: ZERO ;
2258
2274
let offset_history_last_updated = Duration :: ZERO ;
2275
+ let last_datapoint = Duration :: ZERO ;
2259
2276
let network_graph = network_graph ( & logger) ;
2260
2277
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2261
2278
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2262
2279
. with_channel ( 42 ,
2263
2280
ChannelLiquidity {
2264
2281
min_liquidity_offset_msat : 200 , max_liquidity_offset_msat : 400 ,
2265
- last_updated, offset_history_last_updated,
2282
+ last_updated, offset_history_last_updated, last_datapoint ,
2266
2283
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2267
2284
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2268
2285
} ) ;
@@ -2317,13 +2334,14 @@ mod tests {
2317
2334
let logger = TestLogger :: new ( ) ;
2318
2335
let last_updated = Duration :: ZERO ;
2319
2336
let offset_history_last_updated = Duration :: ZERO ;
2337
+ let last_datapoint = Duration :: ZERO ;
2320
2338
let network_graph = network_graph ( & logger) ;
2321
2339
let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
2322
2340
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
2323
2341
. with_channel ( 42 ,
2324
2342
ChannelLiquidity {
2325
2343
min_liquidity_offset_msat : 200 , max_liquidity_offset_msat : 400 ,
2326
- last_updated, offset_history_last_updated,
2344
+ last_updated, offset_history_last_updated, last_datapoint ,
2327
2345
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2328
2346
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2329
2347
} ) ;
@@ -2430,6 +2448,7 @@ mod tests {
2430
2448
let logger = TestLogger :: new ( ) ;
2431
2449
let last_updated = Duration :: ZERO ;
2432
2450
let offset_history_last_updated = Duration :: ZERO ;
2451
+ let last_datapoint = Duration :: ZERO ;
2433
2452
let network_graph = network_graph ( & logger) ;
2434
2453
let params = ProbabilisticScoringFeeParameters {
2435
2454
liquidity_penalty_multiplier_msat : 1_000 ,
@@ -2443,7 +2462,7 @@ mod tests {
2443
2462
. with_channel ( 42 ,
2444
2463
ChannelLiquidity {
2445
2464
min_liquidity_offset_msat : 40 , max_liquidity_offset_msat : 40 ,
2446
- last_updated, offset_history_last_updated,
2465
+ last_updated, offset_history_last_updated, last_datapoint ,
2447
2466
liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
2448
2467
_padding : [ 0 ; LIQ_PADDING_LEN ] ,
2449
2468
} ) ;
0 commit comments