diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 948959e96495c..dce2529201400 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -669,12 +669,17 @@ impl sc_consensus_slots::SimpleSlotWorker for BabeSlot fn proposing_remaining_duration( &self, - head: &B::Header, + parent_head: &B::Header, slot_info: &SlotInfo, ) -> Option { let slot_remaining = self.slot_remaining_duration(slot_info); - let parent_slot = match find_pre_digest::(head) { + // If parent is genesis block, we don't require any lenience factor. + if parent_head.number().is_zero() { + return Some(slot_remaining) + } + + let parent_slot = match find_pre_digest::(parent_head) { Err(_) => return Some(slot_remaining), Ok(d) => d.slot_number(), }; @@ -682,7 +687,8 @@ impl sc_consensus_slots::SimpleSlotWorker for BabeSlot if let Some(slot_lenience) = sc_consensus_slots::slot_lenience_exponential(parent_slot, slot_info) { - debug!(target: "babe", + debug!( + target: "babe", "No block for {} slots. Applying exponential lenience of {}s", slot_info.number.saturating_sub(parent_slot + 1), slot_lenience.as_secs(), @@ -697,8 +703,7 @@ impl sc_consensus_slots::SimpleSlotWorker for BabeSlot /// Extract the BABE pre digest from the given header. Pre-runtime digests are /// mandatory, the function will return `Err` if none is found. -pub fn find_pre_digest(header: &B::Header) -> Result> -{ +pub fn find_pre_digest(header: &B::Header) -> Result> { // genesis block doesn't contain a pre digest so let's generate a // dummy one to not break any invariants in the rest of the code if header.number().is_zero() {