Skip to content

Commit be2f08a

Browse files
committed
f - Rename decay_interval to half_life
1 parent 6aa5aff commit be2f08a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lightning/src/routing/scorer.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ pub struct ScoringParameters {
7878

7979
/// A penalty in msats to apply to a channel upon failure.
8080
///
81-
/// This may be reduced over time based on [`failure_penalty_decay_interval`].
81+
/// This may be reduced over time based on [`failure_penalty_half_life`].
8282
///
83-
/// [`failure_penalty_decay_interval`]: Self::failure_penalty_decay_interval
83+
/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life
8484
pub failure_penalty_msat: u64,
8585

8686
/// The time needed before any accumulated channel failure penalties are cut in half.
8787
#[cfg(not(feature = "no-std"))]
88-
pub failure_penalty_decay_interval: Duration,
88+
pub failure_penalty_half_life: Duration,
8989
}
9090

9191
impl Scorer {
@@ -103,13 +103,13 @@ impl Scorer {
103103
base_penalty_msat: penalty_msat,
104104
failure_penalty_msat: 0,
105105
#[cfg(not(feature = "no-std"))]
106-
failure_penalty_decay_interval: Duration::from_secs(0),
106+
failure_penalty_half_life: Duration::from_secs(0),
107107
})
108108
}
109109

110110
#[cfg(not(feature = "no-std"))]
111111
fn decay_from(&self, penalty_msat: u64, last_failure: &SystemTime) -> u64 {
112-
decay_from(penalty_msat, last_failure, self.params.failure_penalty_decay_interval)
112+
decay_from(penalty_msat, last_failure, self.params.failure_penalty_half_life)
113113
}
114114
}
115115

@@ -125,7 +125,7 @@ impl Default for ScoringParameters {
125125
base_penalty_msat: 500,
126126
failure_penalty_msat: 1024,
127127
#[cfg(not(feature = "no-std"))]
128-
failure_penalty_decay_interval: Duration::from_secs(3600),
128+
failure_penalty_half_life: Duration::from_secs(3600),
129129
}
130130
}
131131
}
@@ -150,11 +150,11 @@ impl routing::Score for Scorer {
150150
let failure_penalty_msat = self.params.failure_penalty_msat;
151151
#[cfg(not(feature = "no-std"))]
152152
{
153-
let decay_interval = self.params.failure_penalty_decay_interval;
153+
let half_life = self.params.failure_penalty_half_life;
154154
self.channel_failures
155155
.entry(short_channel_id)
156156
.and_modify(|(penalty_msat, last_failure)| {
157-
let decayed_penalty = decay_from(*penalty_msat, last_failure, decay_interval);
157+
let decayed_penalty = decay_from(*penalty_msat, last_failure, half_life);
158158
*penalty_msat = decayed_penalty + failure_penalty_msat;
159159
*last_failure = SystemTime::now();
160160
})
@@ -169,9 +169,9 @@ impl routing::Score for Scorer {
169169
}
170170

171171
#[cfg(not(feature = "no-std"))]
172-
fn decay_from(penalty_msat: u64, last_failure: &SystemTime, decay_interval: Duration) -> u64 {
172+
fn decay_from(penalty_msat: u64, last_failure: &SystemTime, half_life: Duration) -> u64 {
173173
let decays = last_failure.elapsed().ok().map_or(0, |elapsed| {
174-
elapsed.as_secs() / decay_interval.as_secs()
174+
elapsed.as_secs() / half_life.as_secs()
175175
});
176176
penalty_msat >> decays
177177
}

0 commit comments

Comments
 (0)