Skip to content

Commit d9b9854

Browse files
committed
Drop now-unused methods on Time
We no longer use `Time` during scoring, which makes several of its methods now useless. We remove those here.
1 parent ae0d825 commit d9b9854

File tree

1 file changed

+3
-52
lines changed

1 file changed

+3
-52
lines changed

lightning/src/util/time.rs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,8 @@ pub trait Time: Copy + Sub<Duration, Output = Self> where Self: Sized {
1616
/// Returns an instance corresponding to the current moment.
1717
fn now() -> Self;
1818

19-
/// Returns the amount of time elapsed since `self` was created.
20-
fn elapsed(&self) -> Duration;
21-
2219
/// Returns the amount of time passed between `earlier` and `self`.
2320
fn duration_since(&self, earlier: Self) -> Duration;
24-
25-
/// Returns the amount of time passed since the beginning of [`Time`].
26-
///
27-
/// Used during (de-)serialization.
28-
fn duration_since_epoch() -> Duration;
2921
}
3022

3123
/// A state in which time has no meaning.
@@ -40,14 +32,6 @@ impl Time for Eternity {
4032
fn duration_since(&self, _earlier: Self) -> Duration {
4133
Duration::from_secs(0)
4234
}
43-
44-
fn duration_since_epoch() -> Duration {
45-
Duration::from_secs(0)
46-
}
47-
48-
fn elapsed(&self) -> Duration {
49-
Duration::from_secs(0)
50-
}
5135
}
5236

5337
impl Sub<Duration> for Eternity {
@@ -82,15 +66,6 @@ impl Time for MonotonicTime {
8266
let now = Self::now();
8367
if now.0 > earlier.0 { now.0 - earlier.0 } else { Duration::from_secs(0) }
8468
}
85-
86-
fn duration_since_epoch() -> Duration {
87-
use std::time::SystemTime;
88-
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap()
89-
}
90-
91-
fn elapsed(&self) -> Duration {
92-
Self::now().0 - self.0
93-
}
9469
}
9570

9671
#[cfg(feature = "std")]
@@ -127,20 +102,12 @@ pub mod tests {
127102

128103
impl Time for SinceEpoch {
129104
fn now() -> Self {
130-
Self(Self::duration_since_epoch())
105+
Self(Self::ELAPSED.with(|elapsed| elapsed.get()))
131106
}
132107

133108
fn duration_since(&self, earlier: Self) -> Duration {
134109
self.0 - earlier.0
135110
}
136-
137-
fn duration_since_epoch() -> Duration {
138-
Self::ELAPSED.with(|elapsed| elapsed.get())
139-
}
140-
141-
fn elapsed(&self) -> Duration {
142-
Self::duration_since_epoch() - self.0
143-
}
144111
}
145112

146113
impl Sub<Duration> for SinceEpoch {
@@ -154,36 +121,20 @@ pub mod tests {
154121
#[test]
155122
fn time_passes_when_advanced() {
156123
let now = SinceEpoch::now();
157-
assert_eq!(now.elapsed(), Duration::from_secs(0));
158124

159125
SinceEpoch::advance(Duration::from_secs(1));
160126
SinceEpoch::advance(Duration::from_secs(1));
161127

162-
let elapsed = now.elapsed();
163128
let later = SinceEpoch::now();
164129

165-
assert_eq!(elapsed, Duration::from_secs(2));
166-
assert_eq!(later - elapsed, now);
130+
assert_eq!(now.0 + Duration::from_secs(2), later.0);
167131
}
168132

169133
#[test]
170134
fn time_never_passes_in_an_eternity() {
171135
let now = Eternity::now();
172-
let elapsed = now.elapsed();
173136
let later = Eternity::now();
174137

175-
assert_eq!(now.elapsed(), Duration::from_secs(0));
176-
assert_eq!(later - elapsed, now);
177-
}
178-
179-
#[test]
180-
#[cfg(feature = "std")]
181-
fn monotonic_time_subtracts() {
182-
let now = super::MonotonicTime::now();
183-
assert!(now.elapsed() < Duration::from_secs(10));
184-
185-
let ten_years = Duration::from_secs(10 * 365 * 24 * 60 * 60);
186-
let past = now - ten_years;
187-
assert!(past.elapsed() >= ten_years);
138+
assert_eq!(later, now);
188139
}
189140
}

0 commit comments

Comments
 (0)