Introduce new concept of "slot portion for proposing" (#8280)

* Introduce new concept of "slot portion for proposing"

Currently when building a block we actually give the proposer all of the
time in the slot, while this is wrong. The slot is actually split in at
least two phases proposing and propagation or in the polkadot case into
three phases validating pov's, proposing and propagation. As we don't
want to bring that much polkadot concepts into Substrate, we only
support splitting the slot into proposing and propagation. The portion
can now be passed as parameter to AuRa and BABE to configure this value.
However, this slot portion for propagation doesn't mean that the
proposer can not go over this limit. When we miss slots we still apply
the lenience factor to increase the proposing time, so that we have
enough time to build a heavy block.

Besides all what was said above, this is especially required for
parachains. Parachains have a much more constraint proposing window.
Currently the slot duration is at minimum 12 seconds, but we only have
around 500ms for proposing. So, this slot portion for proposing is
really required to make it working without hacks.

* Offgit feedback

* Cast cast cast
This commit is contained in:
Bastian Köcher
2021-03-09 20:14:54 +01:00
committed by GitHub
parent 7f17082002
commit 7599e0d6e8
7 changed files with 112 additions and 57 deletions
@@ -40,9 +40,11 @@ pub fn duration_now() -> Duration {
}
/// Returns the duration until the next slot, based on current duration since
pub fn time_until_next(now: Duration, slot_duration: u64) -> Duration {
let remaining_full_millis = slot_duration - (now.as_millis() as u64 % slot_duration) - 1;
Duration::from_millis(remaining_full_millis)
pub fn time_until_next(now: Duration, slot_duration: Duration) -> Duration {
let remaining_full_millis = slot_duration.as_millis()
- (now.as_millis() % slot_duration.as_millis())
- 1;
Duration::from_millis(remaining_full_millis as u64)
}
/// Information about a slot.
@@ -56,13 +58,13 @@ pub struct SlotInfo {
/// The inherent data.
pub inherent_data: InherentData,
/// Slot duration.
pub duration: u64,
pub duration: Duration,
}
/// A stream that returns every time there is a new slot.
pub(crate) struct Slots<SC> {
last_slot: Slot,
slot_duration: u64,
slot_duration: Duration,
inner_delay: Option<Delay>,
inherent_data_providers: InherentDataProviders,
timestamp_extractor: SC,
@@ -77,7 +79,7 @@ impl<SC> Slots<SC> {
) -> Self {
Slots {
last_slot: 0.into(),
slot_duration,
slot_duration: Duration::from_millis(slot_duration),
inner_delay: None,
inherent_data_providers,
timestamp_extractor,