Skip to content

Commit

Permalink
f use const
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Apr 10, 2022
1 parent 643e2d8 commit cdaa016
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,10 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
} else {
let numerator = (max_liquidity_msat - amount_msat).saturating_add(1);
let denominator = (max_liquidity_msat - min_liquidity_msat).saturating_add(1);
if amount_msat - min_liquidity_msat < denominator / 64 {
// If the failure probability is < 1.5625%, don't bother trying to use the log
// approximation as it gets too noisy to be particularly helpful, instead just
// round down to 0 and return the base penalty.
if amount_msat - min_liquidity_msat < denominator / approx::PRECISION_LOWER_BOUND_DENOMINATOR {
// If the failure probability is < 1.5625% (in the form of 1 - numerator/denominator < 1/64),
// don't bother trying to use the log approximation as it gets too noisy to be particularly
// helpful, instead just round down to 0 and return the base penalty.
params.base_penalty_msat
} else {
let negative_log10_times_2048 =
Expand Down Expand Up @@ -898,6 +898,9 @@ mod approx {
const LOWER_BITS: u32 = 6;
const LOWER_BITS_BOUND: u64 = 1 << LOWER_BITS;
const LOWER_BITMASK: u64 = (1 << LOWER_BITS) - 1;
/// The rough cutoff at which our precision falls off and we should stop bothering to try to
/// log a ratio, as X in 1/X.
pub(super) const PRECISION_LOWER_BOUND_DENOMINATOR: u64 = LOWER_BITS_BOUND;

/// Look-up table for `log10(x) * 2048` where row `i` is used for each `x` having `i` as the
/// most significant bit. The next 4 bits of `x`, if applicable, are used for the second index.
Expand Down

0 comments on commit cdaa016

Please sign in to comment.