Skip to content

Commit c7544ed

Browse files
TheBlueMattcarlaKC
authored andcommitted
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 e98d400 commit c7544ed

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

@@ -2394,6 +2404,7 @@ impl Writeable for ChannelLiquidity {
23942404
(5, self.liquidity_history.writeable_min_offset_history(), required),
23952405
(7, self.liquidity_history.writeable_max_offset_history(), required),
23962406
(9, self.offset_history_last_updated, required),
2407+
(11, self.last_datapoint_time, required),
23972408
});
23982409
Ok(())
23992410
}
@@ -2410,6 +2421,7 @@ impl Readable for ChannelLiquidity {
24102421
let mut max_liquidity_offset_history: Option<HistoricalBucketRangeTracker> = None;
24112422
let mut last_updated = Duration::from_secs(0);
24122423
let mut offset_history_last_updated = None;
2424+
let mut last_datapoint_time = None;
24132425
read_tlv_fields!(r, {
24142426
(0, min_liquidity_offset_msat, required),
24152427
(1, legacy_min_liq_offset_history, option),
@@ -2419,6 +2431,7 @@ impl Readable for ChannelLiquidity {
24192431
(5, min_liquidity_offset_history, option),
24202432
(7, max_liquidity_offset_history, option),
24212433
(9, offset_history_last_updated, option),
2434+
(11, last_datapoint_time, option),
24222435
});
24232436

24242437
if min_liquidity_offset_history.is_none() {
@@ -2443,6 +2456,7 @@ impl Readable for ChannelLiquidity {
24432456
),
24442457
last_updated,
24452458
offset_history_last_updated: offset_history_last_updated.unwrap_or(last_updated),
2459+
last_datapoint_time: last_datapoint_time.unwrap_or(last_updated),
24462460
})
24472461
}
24482462
}
@@ -2616,19 +2630,20 @@ mod tests {
26162630
let logger = TestLogger::new();
26172631
let last_updated = Duration::ZERO;
26182632
let offset_history_last_updated = Duration::ZERO;
2633+
let last_datapoint_time = Duration::ZERO;
26192634
let network_graph = network_graph(&logger);
26202635
let decay_params = ProbabilisticScoringDecayParameters::default();
26212636
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger)
26222637
.with_channel(42,
26232638
ChannelLiquidity {
26242639
min_liquidity_offset_msat: 700, max_liquidity_offset_msat: 100,
2625-
last_updated, offset_history_last_updated,
2640+
last_updated, offset_history_last_updated, last_datapoint_time,
26262641
liquidity_history: HistoricalLiquidityTracker::new(),
26272642
})
26282643
.with_channel(43,
26292644
ChannelLiquidity {
26302645
min_liquidity_offset_msat: 700, max_liquidity_offset_msat: 100,
2631-
last_updated, offset_history_last_updated,
2646+
last_updated, offset_history_last_updated, last_datapoint_time,
26322647
liquidity_history: HistoricalLiquidityTracker::new(),
26332648
});
26342649
let source = source_node_id();
@@ -2695,13 +2710,14 @@ mod tests {
26952710
let logger = TestLogger::new();
26962711
let last_updated = Duration::ZERO;
26972712
let offset_history_last_updated = Duration::ZERO;
2713+
let last_datapoint_time = Duration::ZERO;
26982714
let network_graph = network_graph(&logger);
26992715
let decay_params = ProbabilisticScoringDecayParameters::default();
27002716
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger)
27012717
.with_channel(42,
27022718
ChannelLiquidity {
27032719
min_liquidity_offset_msat: 200, max_liquidity_offset_msat: 400,
2704-
last_updated, offset_history_last_updated,
2720+
last_updated, offset_history_last_updated, last_datapoint_time,
27052721
liquidity_history: HistoricalLiquidityTracker::new(),
27062722
});
27072723
let source = source_node_id();
@@ -2755,13 +2771,14 @@ mod tests {
27552771
let logger = TestLogger::new();
27562772
let last_updated = Duration::ZERO;
27572773
let offset_history_last_updated = Duration::ZERO;
2774+
let last_datapoint_time = Duration::ZERO;
27582775
let network_graph = network_graph(&logger);
27592776
let decay_params = ProbabilisticScoringDecayParameters::default();
27602777
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger)
27612778
.with_channel(42,
27622779
ChannelLiquidity {
27632780
min_liquidity_offset_msat: 200, max_liquidity_offset_msat: 400,
2764-
last_updated, offset_history_last_updated,
2781+
last_updated, offset_history_last_updated, last_datapoint_time,
27652782
liquidity_history: HistoricalLiquidityTracker::new(),
27662783
});
27672784
let source = source_node_id();
@@ -2867,6 +2884,7 @@ mod tests {
28672884
let logger = TestLogger::new();
28682885
let last_updated = Duration::ZERO;
28692886
let offset_history_last_updated = Duration::ZERO;
2887+
let last_datapoint_time = Duration::ZERO;
28702888
let network_graph = network_graph(&logger);
28712889
let params = ProbabilisticScoringFeeParameters {
28722890
liquidity_penalty_multiplier_msat: 1_000,
@@ -2880,7 +2898,7 @@ mod tests {
28802898
.with_channel(42,
28812899
ChannelLiquidity {
28822900
min_liquidity_offset_msat: 40, max_liquidity_offset_msat: 40,
2883-
last_updated, offset_history_last_updated,
2901+
last_updated, offset_history_last_updated, last_datapoint_time,
28842902
liquidity_history: HistoricalLiquidityTracker::new(),
28852903
});
28862904
let source = source_node_id();

0 commit comments

Comments
 (0)