@@ -53,7 +53,7 @@ use prelude::*;
53
53
#[ cfg( not( feature = "no-std" ) ) ]
54
54
use core:: time:: Duration ;
55
55
#[ cfg( not( feature = "no-std" ) ) ]
56
- use std:: time:: SystemTime ;
56
+ use std:: time:: Instant ;
57
57
58
58
/// [`routing::Score`] implementation that provides reasonable default behavior.
59
59
///
@@ -66,7 +66,7 @@ use std::time::SystemTime;
66
66
pub struct Scorer {
67
67
params : ScoringParameters ,
68
68
#[ cfg( not( feature = "no-std" ) ) ]
69
- channel_failures : HashMap < u64 , ( u64 , SystemTime ) > ,
69
+ channel_failures : HashMap < u64 , ( u64 , Instant ) > ,
70
70
#[ cfg( feature = "no-std" ) ]
71
71
channel_failures : HashMap < u64 , u64 > ,
72
72
}
@@ -108,7 +108,7 @@ impl Scorer {
108
108
}
109
109
110
110
#[ 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 {
112
112
decay_from ( penalty_msat, last_failure, self . params . failure_penalty_half_life )
113
113
}
114
114
}
@@ -156,9 +156,9 @@ impl routing::Score for Scorer {
156
156
. and_modify ( |( penalty_msat, last_failure) | {
157
157
let decayed_penalty = decay_from ( * penalty_msat, last_failure, half_life) ;
158
158
* penalty_msat = decayed_penalty + failure_penalty_msat;
159
- * last_failure = SystemTime :: now ( ) ;
159
+ * last_failure = Instant :: now ( ) ;
160
160
} )
161
- . or_insert_with ( || ( failure_penalty_msat, SystemTime :: now ( ) ) ) ;
161
+ . or_insert_with ( || ( failure_penalty_msat, Instant :: now ( ) ) ) ;
162
162
}
163
163
#[ cfg( feature = "no-std" ) ]
164
164
self . channel_failures
@@ -169,11 +169,8 @@ impl routing::Score for Scorer {
169
169
}
170
170
171
171
#[ 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 ( ) ) ;
177
174
match decays {
178
175
Some ( decays) => penalty_msat >> decays,
179
176
None => 0 ,
0 commit comments