@@ -779,6 +779,7 @@ struct DummyLiquidity {
779779 c : HistoricalLiquidityTracker ,
780780 d : Duration ,
781781 e : Duration ,
782+ f : Duration ,
782783}
783784
784785/// The amount of padding required to make [`ChannelLiquidity`] (plus a u64) a full 4 cache lines.
@@ -806,6 +807,10 @@ struct ChannelLiquidity {
806807 /// epoch.
807808 offset_history_last_updated : Duration ,
808809
810+ /// The last time when the liquidity bounds were updated with new payment information (i.e.
811+ /// ignoring decays).
812+ last_datapoint : Duration ,
813+
809814 _padding : [ u64 ; LIQ_PADDING_LEN ] ,
810815}
811816
@@ -821,7 +826,7 @@ struct ChannelLiquidity {
821826//
822827// The next two cache lines will have the historical points, which we only access last during
823828// 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.
825830const _LIQUIDITY_MAP_SIZING_CHECK: usize = 256 - :: core:: mem:: size_of :: < ( u64 , ChannelLiquidity ) > ( ) ;
826831const _LIQUIDITY_MAP_SIZING_CHECK_2: usize = :: core:: mem:: size_of :: < ( u64 , ChannelLiquidity ) > ( ) - 256 ;
827832
@@ -833,6 +838,7 @@ struct DirectedChannelLiquidity<L: Deref<Target = u64>, HT: Deref<Target = Histo
833838 capacity_msat : u64 ,
834839 last_updated : T ,
835840 offset_history_last_updated : T ,
841+ last_datapoint : T ,
836842}
837843
838844impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ProbabilisticScorer < G , L > where L :: Target : Logger {
@@ -1009,6 +1015,7 @@ impl ChannelLiquidity {
10091015 liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
10101016 last_updated,
10111017 offset_history_last_updated : last_updated,
1018+ last_datapoint : last_updated,
10121019 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
10131020 }
10141021 }
@@ -1033,6 +1040,7 @@ impl ChannelLiquidity {
10331040 capacity_msat,
10341041 last_updated : & self . last_updated ,
10351042 offset_history_last_updated : & self . offset_history_last_updated ,
1043+ last_datapoint : & self . last_datapoint ,
10361044 }
10371045 }
10381046
@@ -1056,6 +1064,7 @@ impl ChannelLiquidity {
10561064 capacity_msat,
10571065 last_updated : & mut self . last_updated ,
10581066 offset_history_last_updated : & mut self . offset_history_last_updated ,
1067+ last_datapoint : & mut self . last_datapoint ,
10591068 }
10601069 }
10611070
@@ -1335,6 +1344,7 @@ DirectedChannelLiquidity<L, HT, T> {
13351344 * self . max_liquidity_offset_msat = 0 ;
13361345 }
13371346 * self . last_updated = duration_since_epoch;
1347+ * self . last_datapoint = duration_since_epoch;
13381348 }
13391349
13401350 /// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1344,6 +1354,7 @@ DirectedChannelLiquidity<L, HT, T> {
13441354 * self . min_liquidity_offset_msat = 0 ;
13451355 }
13461356 * self . last_updated = duration_since_epoch;
1357+ * self . last_datapoint = duration_since_epoch;
13471358 }
13481359}
13491360
@@ -1953,6 +1964,7 @@ impl Writeable for ChannelLiquidity {
19531964 ( 5 , self . liquidity_history. writeable_min_offset_history( ) , required) ,
19541965 ( 7 , self . liquidity_history. writeable_max_offset_history( ) , required) ,
19551966 ( 9 , self . offset_history_last_updated, required) ,
1967+ ( 11 , self . last_datapoint, required) ,
19561968 } ) ;
19571969 Ok ( ( ) )
19581970 }
@@ -1969,6 +1981,7 @@ impl Readable for ChannelLiquidity {
19691981 let mut max_liquidity_offset_history: Option < HistoricalBucketRangeTracker > = None ;
19701982 let mut last_updated = Duration :: from_secs ( 0 ) ;
19711983 let mut offset_history_last_updated = None ;
1984+ let mut last_datapoint = None ;
19721985 read_tlv_fields ! ( r, {
19731986 ( 0 , min_liquidity_offset_msat, required) ,
19741987 ( 1 , legacy_min_liq_offset_history, option) ,
@@ -1978,6 +1991,7 @@ impl Readable for ChannelLiquidity {
19781991 ( 5 , min_liquidity_offset_history, option) ,
19791992 ( 7 , max_liquidity_offset_history, option) ,
19801993 ( 9 , offset_history_last_updated, option) ,
1994+ ( 11 , last_datapoint, option) ,
19811995 } ) ;
19821996
19831997 if min_liquidity_offset_history. is_none ( ) {
@@ -2002,6 +2016,7 @@ impl Readable for ChannelLiquidity {
20022016 ) ,
20032017 last_updated,
20042018 offset_history_last_updated : offset_history_last_updated. unwrap_or ( last_updated) ,
2019+ last_datapoint : last_datapoint. unwrap_or ( last_updated) ,
20052020 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
20062021 } )
20072022 }
@@ -2175,20 +2190,21 @@ mod tests {
21752190 let logger = TestLogger :: new ( ) ;
21762191 let last_updated = Duration :: ZERO ;
21772192 let offset_history_last_updated = Duration :: ZERO ;
2193+ let last_datapoint = Duration :: ZERO ;
21782194 let network_graph = network_graph ( & logger) ;
21792195 let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
21802196 let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
21812197 . with_channel ( 42 ,
21822198 ChannelLiquidity {
21832199 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 ,
21852201 liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
21862202 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
21872203 } )
21882204 . with_channel ( 43 ,
21892205 ChannelLiquidity {
21902206 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 ,
21922208 liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
21932209 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
21942210 } ) ;
@@ -2256,13 +2272,14 @@ mod tests {
22562272 let logger = TestLogger :: new ( ) ;
22572273 let last_updated = Duration :: ZERO ;
22582274 let offset_history_last_updated = Duration :: ZERO ;
2275+ let last_datapoint = Duration :: ZERO ;
22592276 let network_graph = network_graph ( & logger) ;
22602277 let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
22612278 let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
22622279 . with_channel ( 42 ,
22632280 ChannelLiquidity {
22642281 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 ,
22662283 liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
22672284 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
22682285 } ) ;
@@ -2317,13 +2334,14 @@ mod tests {
23172334 let logger = TestLogger :: new ( ) ;
23182335 let last_updated = Duration :: ZERO ;
23192336 let offset_history_last_updated = Duration :: ZERO ;
2337+ let last_datapoint = Duration :: ZERO ;
23202338 let network_graph = network_graph ( & logger) ;
23212339 let decay_params = ProbabilisticScoringDecayParameters :: default ( ) ;
23222340 let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger)
23232341 . with_channel ( 42 ,
23242342 ChannelLiquidity {
23252343 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 ,
23272345 liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
23282346 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
23292347 } ) ;
@@ -2430,6 +2448,7 @@ mod tests {
24302448 let logger = TestLogger :: new ( ) ;
24312449 let last_updated = Duration :: ZERO ;
24322450 let offset_history_last_updated = Duration :: ZERO ;
2451+ let last_datapoint = Duration :: ZERO ;
24332452 let network_graph = network_graph ( & logger) ;
24342453 let params = ProbabilisticScoringFeeParameters {
24352454 liquidity_penalty_multiplier_msat : 1_000 ,
@@ -2443,7 +2462,7 @@ mod tests {
24432462 . with_channel ( 42 ,
24442463 ChannelLiquidity {
24452464 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 ,
24472466 liquidity_history : HistoricalLiquidityTracker :: new ( ) ,
24482467 _padding : [ 0 ; LIQ_PADDING_LEN ] ,
24492468 } ) ;
0 commit comments