Make block proposing remaining duration configurable (#4215)

* Make proposing remaining duration configurable

* Pass chain_head to proposing_remaining_duration and change default
This commit is contained in:
Wei Tang
2019-11-27 17:44:34 +01:00
committed by GitHub
parent c5a9b504f9
commit f8bf17dc49
2 changed files with 51 additions and 42 deletions
+4 -12
View File
@@ -71,6 +71,8 @@ pub fn time_until_next(now: Duration, slot_duration: u64) -> Duration {
pub struct SlotInfo {
/// The slot number.
pub number: u64,
/// The last slot number produced.
pub last_number: u64,
/// Current timestamp.
pub timestamp: u64,
/// The instant at which the slot ends.
@@ -81,18 +83,6 @@ pub struct SlotInfo {
pub duration: u64,
}
impl SlotInfo {
/// Yields the remaining duration in the slot.
pub fn remaining_duration(&self) -> Duration {
let now = Instant::now();
if now < self.ends_at {
self.ends_at.duration_since(now)
} else {
Duration::from_millis(0)
}
}
}
/// A stream that returns every time there is a new slot.
pub(crate) struct Slots<SC> {
last_slot: u64,
@@ -160,11 +150,13 @@ impl<SC: SlotCompatible + Unpin> Stream for Slots<SC> {
// never yield the same slot twice.
if slot_num > self.last_slot {
let last_slot = self.last_slot;
self.last_slot = slot_num;
break Poll::Ready(Some(Ok(SlotInfo {
number: slot_num,
duration: self.slot_duration,
last_number: last_slot,
timestamp,
ends_at,
inherent_data,