Skip to content

Commit df37cc4

Browse files
committed
f - Make Time require Sub<Duration, Output = Self>
1 parent 9ef23fe commit df37cc4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lightning/src/routing/scorer.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub type DefaultTime = Eternity;
7979
/// [`routing::Score`] implementation parameterized by [`Time`].
8080
///
8181
/// See [`Scorer`] for details.
82-
pub struct ScorerUsingTime<T: Time + Sub<Duration, Output = T>> {
82+
pub struct ScorerUsingTime<T: Time> {
8383
params: ScoringParameters,
8484
// TODO: Remove entries of closed channels.
8585
channel_failures: HashMap<u64, ChannelFailure<T>>,
@@ -116,7 +116,7 @@ impl_writeable_tlv_based!(ScoringParameters, {
116116
/// Accounting for penalties from channel failures.
117117
///
118118
/// Penalties decay over time, though accumulate as more failures occur.
119-
struct ChannelFailure<T: Time + Sub<Duration, Output = T>> {
119+
struct ChannelFailure<T: Time> {
120120
/// Accumulated penalty in msats for the channel as of `last_failed`.
121121
undecayed_penalty_msat: u64,
122122

@@ -125,15 +125,15 @@ struct ChannelFailure<T: Time + Sub<Duration, Output = T>> {
125125
}
126126

127127
/// A measurement of time.
128-
pub trait Time {
128+
pub trait Time: Sub<Duration, Output = Self> {
129129
/// Returns an instance corresponding to the current moment.
130130
fn now() -> Self;
131131

132132
/// Returns the amount of time elapsed since created.
133133
fn elapsed(&self) -> Duration;
134134
}
135135

136-
impl<T: Time + Sub<Duration, Output = T>> ScorerUsingTime<T> {
136+
impl<T: Time> ScorerUsingTime<T> {
137137
/// Creates a new scorer using the given scoring parameters.
138138
pub fn new(params: ScoringParameters) -> Self {
139139
Self {
@@ -153,7 +153,7 @@ impl<T: Time + Sub<Duration, Output = T>> ScorerUsingTime<T> {
153153
}
154154
}
155155

156-
impl<T: Time + Sub<Duration, Output = T>> ChannelFailure<T> {
156+
impl<T: Time> ChannelFailure<T> {
157157
fn new(failure_penalty_msat: u64) -> Self {
158158
Self {
159159
undecayed_penalty_msat: failure_penalty_msat,
@@ -175,7 +175,7 @@ impl<T: Time + Sub<Duration, Output = T>> ChannelFailure<T> {
175175
}
176176
}
177177

178-
impl<T: Time + Sub<Duration, Output = T>> Default for ScorerUsingTime<T> {
178+
impl<T: Time> Default for ScorerUsingTime<T> {
179179
fn default() -> Self {
180180
Self::new(ScoringParameters::default())
181181
}
@@ -191,7 +191,7 @@ impl Default for ScoringParameters {
191191
}
192192
}
193193

194-
impl<T: Time + Sub<Duration, Output = T>> routing::Score for ScorerUsingTime<T> {
194+
impl<T: Time> routing::Score for ScorerUsingTime<T> {
195195
fn channel_penalty_msat(
196196
&self, short_channel_id: u64, _source: &NodeId, _target: &NodeId
197197
) -> u64 {
@@ -244,15 +244,15 @@ impl Sub<Duration> for Eternity {
244244
}
245245
}
246246

247-
impl<T: Time + Sub<Duration, Output = T>> Writeable for ScorerUsingTime<T> {
247+
impl<T: Time> Writeable for ScorerUsingTime<T> {
248248
#[inline]
249249
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
250250
self.params.write(w)?;
251251
self.channel_failures.write(w)
252252
}
253253
}
254254

255-
impl<T: Time + Sub<Duration, Output = T>> Readable for ScorerUsingTime<T> {
255+
impl<T: Time> Readable for ScorerUsingTime<T> {
256256
#[inline]
257257
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
258258
Ok(Self {
@@ -262,15 +262,15 @@ impl<T: Time + Sub<Duration, Output = T>> Readable for ScorerUsingTime<T> {
262262
}
263263
}
264264

265-
impl<T: Time + Sub<Duration, Output = T>> Writeable for ChannelFailure<T> {
265+
impl<T: Time> Writeable for ChannelFailure<T> {
266266
#[inline]
267267
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
268268
self.undecayed_penalty_msat.write(w)?;
269269
(duration_since_epoch() - self.last_failed.elapsed()).write(w)
270270
}
271271
}
272272

273-
impl<T: Time + Sub<Duration, Output = T>> Readable for ChannelFailure<T> {
273+
impl<T: Time> Readable for ChannelFailure<T> {
274274
#[inline]
275275
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
276276
Ok(Self {

0 commit comments

Comments
 (0)