1919//! This is used instead of `futures_timer::Interval` because it was unreliable.
2020
2121use super :: SlotCompatible ;
22- use sp_consensus:: Error ;
2322use futures:: { prelude:: * , task:: Context , task:: Poll } ;
23+ use sp_consensus:: Error ;
2424use sp_inherents:: { InherentData , InherentDataProviders } ;
2525
26- use std:: { pin:: Pin , time:: { Duration , Instant } } ;
2726use futures_timer:: Delay ;
27+ use std:: {
28+ pin:: Pin ,
29+ time:: { Duration , Instant } ,
30+ } ;
2831
2932/// Returns current duration since unix epoch.
3033pub fn duration_now ( ) -> Duration {
3134 use std:: time:: SystemTime ;
3235 let now = SystemTime :: now ( ) ;
33- now. duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap_or_else ( |e| panic ! (
34- "Current time {:?} is before unix epoch. Something is wrong: {:?}" ,
35- now,
36- e,
37- ) )
36+ now. duration_since ( SystemTime :: UNIX_EPOCH )
37+ . unwrap_or_else ( |e| {
38+ panic ! (
39+ "Current time {:?} is before unix epoch. Something is wrong: {:?}" ,
40+ now, e,
41+ )
42+ } )
3843}
3944
40-
4145/// A `Duration` with a sign (before or after). Immutable.
4246#[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , Default ) ]
4347pub struct SignedDuration {
@@ -48,7 +52,10 @@ pub struct SignedDuration {
4852impl SignedDuration {
4953 /// Construct a `SignedDuration`
5054 pub fn new ( offset : Duration , is_positive : bool ) -> Self {
51- Self { offset, is_positive }
55+ Self {
56+ offset,
57+ is_positive,
58+ }
5259 }
5360
5461 /// Get the slot for now. Panics if `slot_duration` is 0.
@@ -57,7 +64,9 @@ impl SignedDuration {
5764 duration_now ( ) + self . offset
5865 } else {
5966 duration_now ( ) - self . offset
60- } . as_millis ( ) as u64 ) / slot_duration
67+ }
68+ . as_millis ( ) as u64 )
69+ / slot_duration
6170 }
6271}
6372
@@ -137,14 +146,15 @@ impl<SC: SlotCompatible> Stream for Slots<SC> {
137146 Ok ( id) => id,
138147 Err ( err) => return Poll :: Ready ( Some ( Err ( sp_consensus:: Error :: InherentData ( err) ) ) ) ,
139148 } ;
140- let result = self . timestamp_extractor . extract_timestamp_and_slot ( & inherent_data) ;
149+ let result = self
150+ . timestamp_extractor
151+ . extract_timestamp_and_slot ( & inherent_data) ;
141152 let ( timestamp, slot_num, offset) = match result {
142153 Ok ( v) => v,
143154 Err ( err) => return Poll :: Ready ( Some ( Err ( err) ) ) ,
144155 } ;
145156 // reschedule delay for next slot.
146- let ends_in = offset +
147- time_until_next ( Duration :: from_millis ( timestamp) , slot_duration) ;
157+ let ends_in = offset + time_until_next ( Duration :: from_millis ( timestamp) , slot_duration) ;
148158 let ends_at = Instant :: now ( ) + ends_in;
149159 self . inner_delay = Some ( Delay :: new ( ends_in) ) ;
150160
@@ -160,11 +170,10 @@ impl<SC: SlotCompatible> Stream for Slots<SC> {
160170 timestamp,
161171 ends_at,
162172 inherent_data,
163- } ) ) )
173+ } ) ) ) ;
164174 }
165175 }
166176 }
167177}
168178
169- impl < SC > Unpin for Slots < SC > {
170- }
179+ impl < SC > Unpin for Slots < SC > { }
0 commit comments