Skip to content

Commit cbffd8f

Browse files
committed
Track the last time we received new information about a channel
In the next commit we'll enable users to assign a penalty to channels which we don't have any recent information for to better enable probing diversity. In order to do so, we need to actually track the last time we received new information for a channel, which we do here.
1 parent 25df9f1 commit cbffd8f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

lightning/src/routing/scoring.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,10 @@ struct ChannelLiquidity {
901901
/// Time when the historical liquidity bounds were last modified as an offset against the unix
902902
/// epoch.
903903
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,
904908
}
905909

906910
/// 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
911915
capacity_msat: u64,
912916
last_updated: T,
913917
offset_history_last_updated: T,
918+
last_datapoint_time: T,
914919
}
915920

916921
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> where L::Target: Logger {
@@ -1153,6 +1158,7 @@ impl ChannelLiquidity {
11531158
liquidity_history: HistoricalLiquidityTracker::new(),
11541159
last_updated,
11551160
offset_history_last_updated: last_updated,
1161+
last_datapoint_time: last_updated,
11561162
}
11571163
}
11581164

@@ -1185,6 +1191,7 @@ impl ChannelLiquidity {
11851191
capacity_msat,
11861192
last_updated: &self.last_updated,
11871193
offset_history_last_updated: &self.offset_history_last_updated,
1194+
last_datapoint_time: &self.last_datapoint_time,
11881195
}
11891196
}
11901197

@@ -1208,6 +1215,7 @@ impl ChannelLiquidity {
12081215
capacity_msat,
12091216
last_updated: &mut self.last_updated,
12101217
offset_history_last_updated: &mut self.offset_history_last_updated,
1218+
last_datapoint_time: &mut self.last_datapoint_time,
12111219
}
12121220
}
12131221

@@ -1554,6 +1562,7 @@ DirectedChannelLiquidity<L, HT, T> {
15541562
*self.max_liquidity_offset_msat = 0;
15551563
}
15561564
*self.last_updated = duration_since_epoch;
1565+
*self.last_datapoint_time = duration_since_epoch;
15571566
}
15581567

15591568
/// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1563,6 +1572,7 @@ DirectedChannelLiquidity<L, HT, T> {
15631572
*self.min_liquidity_offset_msat = 0;
15641573
}
15651574
*self.last_updated = duration_since_epoch;
1575+
*self.last_datapoint_time = duration_since_epoch;
15661576
}
15671577
}
15681578

@@ -2372,6 +2382,7 @@ impl Writeable for ChannelLiquidity {
23722382
(5, self.liquidity_history.writeable_min_offset_history(), required),
23732383
(7, self.liquidity_history.writeable_max_offset_history(), required),
23742384
(9, self.offset_history_last_updated, required),
2385+
(11, self.last_datapoint_time, required),
23752386
});
23762387
Ok(())
23772388
}
@@ -2388,6 +2399,7 @@ impl Readable for ChannelLiquidity {
23882399
let mut max_liquidity_offset_history: Option<HistoricalBucketRangeTracker> = None;
23892400
let mut last_updated = Duration::from_secs(0);
23902401
let mut offset_history_last_updated = None;
2402+
let mut last_datapoint_time = None;
23912403
read_tlv_fields!(r, {
23922404
(0, min_liquidity_offset_msat, required),
23932405
(1, legacy_min_liq_offset_history, option),
@@ -2397,6 +2409,7 @@ impl Readable for ChannelLiquidity {
23972409
(5, min_liquidity_offset_history, option),
23982410
(7, max_liquidity_offset_history, option),
23992411
(9, offset_history_last_updated, option),
2412+
(11, last_datapoint_time, option),
24002413
});
24012414

24022415
if min_liquidity_offset_history.is_none() {
@@ -2421,6 +2434,7 @@ impl Readable for ChannelLiquidity {
24212434
),
24222435
last_updated,
24232436
offset_history_last_updated: offset_history_last_updated.unwrap_or(last_updated),
2437+
last_datapoint_time: last_datapoint_time.unwrap_or(last_updated),
24242438
})
24252439
}
24262440
}
@@ -2594,19 +2608,20 @@ mod tests {
25942608
let logger = TestLogger::new();
25952609
let last_updated = Duration::ZERO;
25962610
let offset_history_last_updated = Duration::ZERO;
2611+
let last_datapoint_time = Duration::ZERO;
25972612
let network_graph = network_graph(&logger);
25982613
let decay_params = ProbabilisticScoringDecayParameters::default();
25992614
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger)
26002615
.with_channel(42,
26012616
ChannelLiquidity {
26022617
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,
26042619
liquidity_history: HistoricalLiquidityTracker::new(),
26052620
})
26062621
.with_channel(43,
26072622
ChannelLiquidity {
26082623
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,
26102625
liquidity_history: HistoricalLiquidityTracker::new(),
26112626
});
26122627
let source = source_node_id();
@@ -2673,13 +2688,14 @@ mod tests {
26732688
let logger = TestLogger::new();
26742689
let last_updated = Duration::ZERO;
26752690
let offset_history_last_updated = Duration::ZERO;
2691+
let last_datapoint_time = Duration::ZERO;
26762692
let network_graph = network_graph(&logger);
26772693
let decay_params = ProbabilisticScoringDecayParameters::default();
26782694
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger)
26792695
.with_channel(42,
26802696
ChannelLiquidity {
26812697
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,
26832699
liquidity_history: HistoricalLiquidityTracker::new(),
26842700
});
26852701
let source = source_node_id();
@@ -2733,13 +2749,14 @@ mod tests {
27332749
let logger = TestLogger::new();
27342750
let last_updated = Duration::ZERO;
27352751
let offset_history_last_updated = Duration::ZERO;
2752+
let last_datapoint_time = Duration::ZERO;
27362753
let network_graph = network_graph(&logger);
27372754
let decay_params = ProbabilisticScoringDecayParameters::default();
27382755
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger)
27392756
.with_channel(42,
27402757
ChannelLiquidity {
27412758
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,
27432760
liquidity_history: HistoricalLiquidityTracker::new(),
27442761
});
27452762
let source = source_node_id();
@@ -2845,6 +2862,7 @@ mod tests {
28452862
let logger = TestLogger::new();
28462863
let last_updated = Duration::ZERO;
28472864
let offset_history_last_updated = Duration::ZERO;
2865+
let last_datapoint_time = Duration::ZERO;
28482866
let network_graph = network_graph(&logger);
28492867
let params = ProbabilisticScoringFeeParameters {
28502868
liquidity_penalty_multiplier_msat: 1_000,
@@ -2858,7 +2876,7 @@ mod tests {
28582876
.with_channel(42,
28592877
ChannelLiquidity {
28602878
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,
28622880
liquidity_history: HistoricalLiquidityTracker::new(),
28632881
});
28642882
let source = source_node_id();

0 commit comments

Comments
 (0)