@@ -53,7 +53,7 @@ use prelude::*;
5353#[ cfg( not( feature = "no-std" ) ) ]
5454use core:: time:: Duration ;
5555#[ cfg( not( feature = "no-std" ) ) ]
56- use std:: time:: SystemTime ;
56+ use std:: time:: Instant ;
5757
5858/// [`routing::Score`] implementation that provides reasonable default behavior.
5959///
@@ -66,7 +66,7 @@ use std::time::SystemTime;
6666pub struct Scorer {
6767 params : ScoringParameters ,
6868 #[ cfg( not( feature = "no-std" ) ) ]
69- channel_failures : HashMap < u64 , ( u64 , SystemTime ) > ,
69+ channel_failures : HashMap < u64 , ( u64 , Instant ) > ,
7070 #[ cfg( feature = "no-std" ) ]
7171 channel_failures : HashMap < u64 , u64 > ,
7272}
@@ -108,7 +108,7 @@ impl Scorer {
108108 }
109109
110110 #[ cfg( not( feature = "no-std" ) ) ]
111- fn decay_from ( & self , penalty_msat : u64 , last_failure : & SystemTime ) -> u64 {
111+ fn decay_from ( & self , penalty_msat : u64 , last_failure : & Instant ) -> u64 {
112112 decay_from ( penalty_msat, last_failure, self . params . failure_penalty_half_life )
113113 }
114114}
@@ -156,9 +156,9 @@ impl routing::Score for Scorer {
156156 . and_modify ( |( penalty_msat, last_failure) | {
157157 let decayed_penalty = decay_from ( * penalty_msat, last_failure, half_life) ;
158158 * penalty_msat = decayed_penalty + failure_penalty_msat;
159- * last_failure = SystemTime :: now ( ) ;
159+ * last_failure = Instant :: now ( ) ;
160160 } )
161- . or_insert_with ( || ( failure_penalty_msat, SystemTime :: now ( ) ) ) ;
161+ . or_insert_with ( || ( failure_penalty_msat, Instant :: now ( ) ) ) ;
162162 }
163163 #[ cfg( feature = "no-std" ) ]
164164 self . channel_failures
@@ -169,11 +169,8 @@ impl routing::Score for Scorer {
169169}
170170
171171#[ cfg( not( feature = "no-std" ) ) ]
172- fn decay_from ( penalty_msat : u64 , last_failure : & SystemTime , half_life : Duration ) -> u64 {
173- let decays = match last_failure. elapsed ( ) . ok ( ) {
174- Some ( elapsed) => elapsed. as_secs ( ) . checked_div ( half_life. as_secs ( ) ) ,
175- None => Some ( 0 ) ,
176- } ;
172+ fn decay_from ( penalty_msat : u64 , last_failure : & Instant , half_life : Duration ) -> u64 {
173+ let decays = last_failure. elapsed ( ) . as_secs ( ) . checked_div ( half_life. as_secs ( ) ) ;
177174 match decays {
178175 Some ( decays) => penalty_msat >> decays,
179176 None => 0 ,
0 commit comments