Skip to content

Commit d465e4a

Browse files
committed
f - Make Clock require Sub<Duration, Output = Self>
1 parent 0979044 commit d465e4a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lightning/src/routing/scorer.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub type DefaultClock = AlwaysPresent;
7979
/// [`routing::Score`] implementation parameterized by a [`Clock`].
8080
///
8181
/// See [`Scorer`] for details.
82-
pub struct ScorerUsingClock<C: Clock + Sub<Duration, Output = C>> {
82+
pub struct ScorerUsingClock<C: Clock> {
8383
params: ScoringParameters,
8484
channel_failures: HashMap<u64, ChannelFailure<C>>,
8585
}
@@ -109,7 +109,7 @@ impl_writeable_tlv_based!(ScoringParameters, {
109109
/// Accounting for penalties from channel failures.
110110
///
111111
/// Penalties decay over time, though accumulated as more failures occur.
112-
struct ChannelFailure<C: Clock + Sub<Duration, Output = C>> {
112+
struct ChannelFailure<C: Clock> {
113113
/// Accumulated penalty in msats for the channel as of `last_failed`.
114114
undecayed_penalty_msat: u64,
115115

@@ -118,15 +118,15 @@ struct ChannelFailure<C: Clock + Sub<Duration, Output = C>> {
118118
}
119119

120120
/// A measurement of time.
121-
pub trait Clock {
121+
pub trait Clock: Sub<Duration, Output = Self> {
122122
/// Returns an instance corresponding to "now".
123123
fn now() -> Self;
124124

125125
/// Returns the amount of time elapsed since the clock was created.
126126
fn elapsed(&self) -> Duration;
127127
}
128128

129-
impl<C: Clock + Sub<Duration, Output = C>> ScorerUsingClock<C> {
129+
impl<C: Clock> ScorerUsingClock<C> {
130130
/// Creates a new scorer using the given scoring parameters.
131131
pub fn new(params: ScoringParameters) -> Self {
132132
Self {
@@ -146,7 +146,7 @@ impl<C: Clock + Sub<Duration, Output = C>> ScorerUsingClock<C> {
146146
}
147147
}
148148

149-
impl<C: Clock + Sub<Duration, Output = C>> ChannelFailure<C> {
149+
impl<C: Clock> ChannelFailure<C> {
150150
fn new(failure_penalty_msat: u64) -> Self {
151151
Self {
152152
undecayed_penalty_msat: failure_penalty_msat,
@@ -168,7 +168,7 @@ impl<C: Clock + Sub<Duration, Output = C>> ChannelFailure<C> {
168168
}
169169
}
170170

171-
impl<C: Clock + Sub<Duration, Output = C>> Default for ScorerUsingClock<C> {
171+
impl<C: Clock> Default for ScorerUsingClock<C> {
172172
fn default() -> Self {
173173
Self::new(ScoringParameters::default())
174174
}
@@ -184,7 +184,7 @@ impl Default for ScoringParameters {
184184
}
185185
}
186186

187-
impl<C: Clock + Sub<Duration, Output = C>> routing::Score for ScorerUsingClock<C> {
187+
impl<C: Clock> routing::Score for ScorerUsingClock<C> {
188188
fn channel_penalty_msat(
189189
&self, short_channel_id: u64, _source: &NodeId, _target: &NodeId
190190
) -> u64 {
@@ -237,15 +237,15 @@ impl Sub<Duration> for AlwaysPresent {
237237
}
238238
}
239239

240-
impl<C: Clock + Sub<Duration, Output = C>> Writeable for ScorerUsingClock<C> {
240+
impl<C: Clock> Writeable for ScorerUsingClock<C> {
241241
#[inline]
242242
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
243243
self.params.write(w)?;
244244
self.channel_failures.write(w)
245245
}
246246
}
247247

248-
impl<C: Clock + Sub<Duration, Output = C>> Readable for ScorerUsingClock<C> {
248+
impl<C: Clock> Readable for ScorerUsingClock<C> {
249249
#[inline]
250250
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
251251
Ok(Self {
@@ -255,15 +255,15 @@ impl<C: Clock + Sub<Duration, Output = C>> Readable for ScorerUsingClock<C> {
255255
}
256256
}
257257

258-
impl<C: Clock + Sub<Duration, Output = C>> Writeable for ChannelFailure<C> {
258+
impl<C: Clock> Writeable for ChannelFailure<C> {
259259
#[inline]
260260
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
261261
self.undecayed_penalty_msat.write(w)?;
262262
(duration_since_epoch() - self.last_failed.elapsed()).write(w)
263263
}
264264
}
265265

266-
impl<C: Clock + Sub<Duration, Output = C>> Readable for ChannelFailure<C> {
266+
impl<C: Clock> Readable for ChannelFailure<C> {
267267
#[inline]
268268
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
269269
Ok(Self {

0 commit comments

Comments
 (0)