Skip to content

Commit 506f178

Browse files
committed
f - Rename Clock trait to Time which is more accurate
1 parent bb9c49e commit 506f178

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

lightning/src/routing/scorer.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ use core::time::Duration;
6262
/// See [module-level documentation] for usage.
6363
///
6464
/// [module-level documentation]: crate::routing::scorer
65-
pub type Scorer = ScorerUsingClock::<DefaultClock>;
65+
pub type Scorer = ScorerUsingTime::<DefaultTime>;
6666

67-
/// Clock used by [`Scorer`].
67+
/// Time used by [`Scorer`].
6868
#[cfg(not(feature = "no-std"))]
69-
pub type DefaultClock = std::time::Instant;
69+
pub type DefaultTime = std::time::Instant;
7070

71-
/// Clock used by [`Scorer`].
71+
/// Time used by [`Scorer`].
7272
#[cfg(feature = "no-std")]
73-
pub type DefaultClock = Eternity;
73+
pub type DefaultTime = Eternity;
7474

75-
/// [`routing::Score`] implementation parameterized by a [`Clock`].
75+
/// [`routing::Score`] implementation parameterized by [`Time`].
7676
///
7777
/// See [`Scorer`] for details.
78-
pub struct ScorerUsingClock<C: Clock> {
78+
pub struct ScorerUsingTime<T: Time> {
7979
params: ScoringParameters,
8080
// TODO: Remove entries of closed channels.
81-
channel_failures: HashMap<u64, ChannelFailure<C>>,
81+
channel_failures: HashMap<u64, ChannelFailure<T>>,
8282
}
8383

8484
/// Parameters for configuring [`Scorer`].
@@ -106,24 +106,24 @@ pub struct ScoringParameters {
106106
/// Accounting for penalties from channel failures.
107107
///
108108
/// Penalties decay over time, though accumulate as more failures occur.
109-
struct ChannelFailure<C: Clock> {
109+
struct ChannelFailure<T: Time> {
110110
/// Accumulated penalty in msats for the channel as of `last_failed`.
111111
undecayed_penalty_msat: u64,
112112

113113
/// Last time the channel failed. Used to decay `undecayed_penalty_msat`.
114-
last_failed: C,
114+
last_failed: T,
115115
}
116116

117117
/// A measurement of time.
118-
pub trait Clock {
119-
/// Returns an instance corresponding to "now".
118+
pub trait Time {
119+
/// Returns an instance corresponding to the current moment.
120120
fn now() -> Self;
121121

122-
/// Returns the amount of time elapsed since the clock was created.
122+
/// Returns the amount of time elapsed since created.
123123
fn elapsed(&self) -> Duration;
124124
}
125125

126-
impl<C: Clock> ScorerUsingClock<C> {
126+
impl<T: Time> ScorerUsingTime<T> {
127127
/// Creates a new scorer using the given scoring parameters.
128128
pub fn new(params: ScoringParameters) -> Self {
129129
Self {
@@ -143,17 +143,17 @@ impl<C: Clock> ScorerUsingClock<C> {
143143
}
144144
}
145145

146-
impl<C: Clock> ChannelFailure<C> {
146+
impl<T: Time> ChannelFailure<T> {
147147
fn new(failure_penalty_msat: u64) -> Self {
148148
Self {
149149
undecayed_penalty_msat: failure_penalty_msat,
150-
last_failed: C::now(),
150+
last_failed: T::now(),
151151
}
152152
}
153153

154154
fn add_penalty(&mut self, failure_penalty_msat: u64, half_life: Duration) {
155155
self.undecayed_penalty_msat = self.decayed_penalty_msat(half_life) + failure_penalty_msat;
156-
self.last_failed = C::now();
156+
self.last_failed = T::now();
157157
}
158158

159159
fn decayed_penalty_msat(&self, half_life: Duration) -> u64 {
@@ -165,7 +165,7 @@ impl<C: Clock> ChannelFailure<C> {
165165
}
166166
}
167167

168-
impl<C: Clock> Default for ScorerUsingClock<C> {
168+
impl<T: Time> Default for ScorerUsingTime<T> {
169169
fn default() -> Self {
170170
Self::new(ScoringParameters::default())
171171
}
@@ -181,7 +181,7 @@ impl Default for ScoringParameters {
181181
}
182182
}
183183

184-
impl<C: Clock> routing::Score for ScorerUsingClock<C> {
184+
impl<T: Time> routing::Score for ScorerUsingTime<T> {
185185
fn channel_penalty_msat(
186186
&self, short_channel_id: u64, _source: &NodeId, _target: &NodeId
187187
) -> u64 {
@@ -203,7 +203,7 @@ impl<C: Clock> routing::Score for ScorerUsingClock<C> {
203203
}
204204

205205
#[cfg(not(feature = "no-std"))]
206-
impl Clock for std::time::Instant {
206+
impl Time for std::time::Instant {
207207
fn now() -> Self {
208208
std::time::Instant::now()
209209
}
@@ -216,7 +216,7 @@ impl Clock for std::time::Instant {
216216
/// A state in which time has no meaning.
217217
pub struct Eternity;
218218

219-
impl Clock for Eternity {
219+
impl Time for Eternity {
220220
fn now() -> Self {
221221
Self
222222
}

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use ln::features::{ChannelFeatures, InitFeatures};
2121
use ln::msgs;
2222
use ln::msgs::OptionalField;
2323
use ln::script::ShutdownScript;
24-
use routing::scorer::{Eternity, ScorerUsingClock};
24+
use routing::scorer::{Eternity, ScorerUsingTime};
2525
use util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
2626
use util::events;
2727
use util::logger::{Logger, Level, Record};
@@ -693,4 +693,4 @@ impl core::fmt::Debug for OnRegisterOutput {
693693
}
694694

695695
/// A scorer useful in testing, when the passage of time isn't a concern.
696-
pub type TestScorer = ScorerUsingClock<Eternity>;
696+
pub type TestScorer = ScorerUsingTime<Eternity>;

0 commit comments

Comments
 (0)