Skip to content

Commit aa3088f

Browse files
committed
f float
1 parent cb55ab2 commit aa3088f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lightning/src/routing/scoring.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -968,16 +968,16 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
968968
None
969969
}
970970

971-
/// Query the probability of payment success (times 2^30) sending the given `amount_msat` over
972-
/// the channel with `scid` towards the given `target` node, based on the historical estimated
973-
/// liquidity bounds.
971+
/// Query the probability of payment success sending the given `amount_msat` over the channel
972+
/// with `scid` towards the given `target` node, based on the historical estimated liquidity
973+
/// bounds.
974974
///
975975
/// These are the same bounds as returned by
976976
/// [`Self::historical_estimated_channel_liquidity_probabilities`] (but not those returned by
977977
/// [`Self::estimated_channel_liquidity_range`]).
978978
pub fn historical_estimated_payment_success_probability(
979979
&self, scid: u64, target: &NodeId, amount_msat: u64)
980-
-> Option<u64> {
980+
-> Option<f64> {
981981
let graph = self.network_graph.read_only();
982982

983983
if let Some(chan) = graph.channels().get(&scid) {
@@ -991,9 +991,10 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
991991
max_liquidity_offset_history: &dir_liq.max_liquidity_offset_history,
992992
};
993993

994-
return buckets.calculate_success_probability_times_billion(T::now(),
994+
let prob_bill = buckets.calculate_success_probability_times_billion(T::now(),
995995
*dir_liq.last_updated, self.decay_params.historical_no_updates_half_life,
996996
amount_msat, directed_info.effective_capacity().as_msat());
997+
return prob_bill.map(|p| p as f64 / (1024 * 1024 * 1024) as f64);
997998
}
998999
}
9991000
}
@@ -2890,9 +2891,9 @@ mod tests {
28902891
assert_eq!(scorer.historical_estimated_channel_liquidity_probabilities(42, &target),
28912892
Some(([32, 0, 0, 0, 0, 0, 0, 0], [32, 0, 0, 0, 0, 0, 0, 0])));
28922893
assert_eq!(scorer.historical_estimated_payment_success_probability(42, &target, 1),
2893-
Some(1024 * 1024 * 1024));
2894+
Some(1.0));
28942895
assert_eq!(scorer.historical_estimated_payment_success_probability(42, &target, 500),
2895-
Some(0));
2896+
Some(0.0));
28962897

28972898
// Even after we tell the scorer we definitely have enough available liquidity, it will
28982899
// still remember that there was some failure in the past, and assign a non-0 penalty.
@@ -2906,12 +2907,12 @@ mod tests {
29062907
// simply check bounds here.
29072908
let five_hundred_prob =
29082909
scorer.historical_estimated_payment_success_probability(42, &target, 500).unwrap();
2909-
assert!(five_hundred_prob > 512 * 1024 * 1024); // 0.5
2910-
assert!(five_hundred_prob < 532 * 1024 * 1024); // ~ 0.52
2910+
assert!(five_hundred_prob > 0.5);
2911+
assert!(five_hundred_prob < 0.52);
29112912
let one_prob =
29122913
scorer.historical_estimated_payment_success_probability(42, &target, 1).unwrap();
2913-
assert!(one_prob < 1024 * 1024 * 1024);
2914-
assert!(one_prob > 1023 * 1024 * 1024);
2914+
assert!(one_prob < 1.0);
2915+
assert!(one_prob > 0.99);
29152916

29162917
// Advance the time forward 16 half-lives (which the docs claim will ensure all data is
29172918
// gone), and check that we're back to where we started.

0 commit comments

Comments
 (0)