@@ -62,23 +62,23 @@ use core::time::Duration;
62
62
/// See [module-level documentation] for usage.
63
63
///
64
64
/// [module-level documentation]: crate::routing::scorer
65
- pub type Scorer = ScorerUsingClock :: < DefaultClock > ;
65
+ pub type Scorer = ScorerUsingTime :: < DefaultTime > ;
66
66
67
- /// Clock used by [`Scorer`].
67
+ /// Time used by [`Scorer`].
68
68
#[ cfg( not( feature = "no-std" ) ) ]
69
- pub type DefaultClock = std:: time:: Instant ;
69
+ pub type DefaultTime = std:: time:: Instant ;
70
70
71
- /// Clock used by [`Scorer`].
71
+ /// Time used by [`Scorer`].
72
72
#[ cfg( feature = "no-std" ) ]
73
- pub type DefaultClock = Eternity ;
73
+ pub type DefaultTime = Eternity ;
74
74
75
- /// [`routing::Score`] implementation parameterized by a [`Clock `].
75
+ /// [`routing::Score`] implementation parameterized by [`Time `].
76
76
///
77
77
/// See [`Scorer`] for details.
78
- pub struct ScorerUsingClock < C : Clock > {
78
+ pub struct ScorerUsingTime < T : Time > {
79
79
params : ScoringParameters ,
80
80
// TODO: Remove entries of closed channels.
81
- channel_failures : HashMap < u64 , ChannelFailure < C > > ,
81
+ channel_failures : HashMap < u64 , ChannelFailure < T > > ,
82
82
}
83
83
84
84
/// Parameters for configuring [`Scorer`].
@@ -106,24 +106,24 @@ pub struct ScoringParameters {
106
106
/// Accounting for penalties from channel failures.
107
107
///
108
108
/// Penalties decay over time, though accumulate as more failures occur.
109
- struct ChannelFailure < C : Clock > {
109
+ struct ChannelFailure < T : Time > {
110
110
/// Accumulated penalty in msats for the channel as of `last_failed`.
111
111
undecayed_penalty_msat : u64 ,
112
112
113
113
/// Last time the channel failed. Used to decay `undecayed_penalty_msat`.
114
- last_failed : C ,
114
+ last_failed : T ,
115
115
}
116
116
117
117
/// 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 .
120
120
fn now ( ) -> Self ;
121
121
122
- /// Returns the amount of time elapsed since the clock was created.
122
+ /// Returns the amount of time elapsed since created.
123
123
fn elapsed ( & self ) -> Duration ;
124
124
}
125
125
126
- impl < C : Clock > ScorerUsingClock < C > {
126
+ impl < T : Time > ScorerUsingTime < T > {
127
127
/// Creates a new scorer using the given scoring parameters.
128
128
pub fn new ( params : ScoringParameters ) -> Self {
129
129
Self {
@@ -143,17 +143,17 @@ impl<C: Clock> ScorerUsingClock<C> {
143
143
}
144
144
}
145
145
146
- impl < C : Clock > ChannelFailure < C > {
146
+ impl < T : Time > ChannelFailure < T > {
147
147
fn new ( failure_penalty_msat : u64 ) -> Self {
148
148
Self {
149
149
undecayed_penalty_msat : failure_penalty_msat,
150
- last_failed : C :: now ( ) ,
150
+ last_failed : T :: now ( ) ,
151
151
}
152
152
}
153
153
154
154
fn add_penalty ( & mut self , failure_penalty_msat : u64 , half_life : Duration ) {
155
155
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 ( ) ;
157
157
}
158
158
159
159
fn decayed_penalty_msat ( & self , half_life : Duration ) -> u64 {
@@ -165,7 +165,7 @@ impl<C: Clock> ChannelFailure<C> {
165
165
}
166
166
}
167
167
168
- impl < C : Clock > Default for ScorerUsingClock < C > {
168
+ impl < T : Time > Default for ScorerUsingTime < T > {
169
169
fn default ( ) -> Self {
170
170
Self :: new ( ScoringParameters :: default ( ) )
171
171
}
@@ -181,7 +181,7 @@ impl Default for ScoringParameters {
181
181
}
182
182
}
183
183
184
- impl < C : Clock > routing:: Score for ScorerUsingClock < C > {
184
+ impl < T : Time > routing:: Score for ScorerUsingTime < T > {
185
185
fn channel_penalty_msat (
186
186
& self , short_channel_id : u64 , _source : & NodeId , _target : & NodeId
187
187
) -> u64 {
@@ -203,7 +203,7 @@ impl<C: Clock> routing::Score for ScorerUsingClock<C> {
203
203
}
204
204
205
205
#[ cfg( not( feature = "no-std" ) ) ]
206
- impl Clock for std:: time:: Instant {
206
+ impl Time for std:: time:: Instant {
207
207
fn now ( ) -> Self {
208
208
std:: time:: Instant :: now ( )
209
209
}
@@ -216,7 +216,7 @@ impl Clock for std::time::Instant {
216
216
/// A state in which time has no meaning.
217
217
pub struct Eternity ;
218
218
219
- impl Clock for Eternity {
219
+ impl Time for Eternity {
220
220
fn now ( ) -> Self {
221
221
Self
222
222
}
0 commit comments