Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit 57c2a0f

Browse files
authored
Merge pull request #10 from selendra/saing
Saing
2 parents 0eb58ad + 35c6a2e commit 57c2a0f

File tree

6 files changed

+171
-170
lines changed

6 files changed

+171
-170
lines changed

client/consensus/slots/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// Copyright 2020 Selendra.
2-
// This file is part of Indracore.
1+
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate.
33

4-
// Indracore is free software: you can redistribute it and/or modify
4+
// Substrate is free software: you can redistribute it and/or modify
55
// it under the terms of the GNU General Public License as published by
66
// the Free Software Foundation, either version 3 of the License, or
77
// (at your option) any later version.
88

9-
// Indracore is distributed in the hope that it will be useful,
9+
// Substrate is distributed in the hope that it will be useful,
1010
// but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
// GNU General Public License for more details.
1313

1414
// You should have received a copy of the GNU General Public License
15-
// along with Indracore. If not, see <http://www.gnu.org/licenses/>.
15+
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//! Slots functionality for Indracore.
17+
//! Slots functionality for Substrate.
1818
//!
1919
//! Some consensus algorithms have a concept of *slots*, which are intervals in
2020
//! time during which certain events can and/or must occur. This crate

client/consensus/slots/src/slots.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,29 @@
1919
//! This is used instead of `futures_timer::Interval` because it was unreliable.
2020
2121
use super::SlotCompatible;
22-
use sp_consensus::Error;
2322
use futures::{prelude::*, task::Context, task::Poll};
23+
use sp_consensus::Error;
2424
use sp_inherents::{InherentData, InherentDataProviders};
2525

26-
use std::{pin::Pin, time::{Duration, Instant}};
2726
use futures_timer::Delay;
27+
use std::{
28+
pin::Pin,
29+
time::{Duration, Instant},
30+
};
2831

2932
/// Returns current duration since unix epoch.
3033
pub 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)]
4347
pub struct SignedDuration {
@@ -48,7 +52,10 @@ pub struct SignedDuration {
4852
impl 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

Comments
 (0)