+impl Time for std::time::Instant {
+ fn now() -> Self {
+ std::time::Instant::now()
+ }
+
+ fn duration_since_epoch() -> Duration {
+ use std::time::SystemTime;
+ SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap()
+ }
+
+ fn elapsed(&self) -> Duration {
+ std::time::Instant::elapsed(self)
+ }
+}
+
+/// A state in which time has no meaning.
+pub struct Eternity;
+
+impl Time for Eternity {
+ fn now() -> Self {
+ Self
+ }
+
+ fn duration_since_epoch() -> Duration {
+ Duration::from_secs(0)
+ }
+
+ fn elapsed(&self) -> Duration {
+ Duration::from_secs(0)
+ }
+}
+
+impl Sub<Duration> for Eternity {
+ type Output = Self;
+
+ fn sub(self, _other: Duration) -> Self {
+ self
+ }
+}
+
+impl<T: Time> Writeable for ScorerUsingTime<T> {
+ #[inline]
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ self.params.write(w)?;
+ self.channel_failures.write(w)
+ }
+}
+
+impl<T: Time> Readable for ScorerUsingTime<T> {
+ #[inline]
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ Ok(Self {
+ params: Readable::read(r)?,
+ channel_failures: Readable::read(r)?,
+ })
+ }
+}
+
+impl<T: Time> Writeable for ChannelFailure<T> {
+ #[inline]
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ self.undecayed_penalty_msat.write(w)?;
+ (T::duration_since_epoch() - self.last_failed.elapsed()).write(w)
+ }
+}
+
+impl<T: Time> Readable for ChannelFailure<T> {
+ #[inline]
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ Ok(Self {
+ undecayed_penalty_msat: Readable::read(r)?,
+ last_failed: T::now() - (T::duration_since_epoch() - Readable::read(r)?),
+ })