mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 13:57:58 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user