diff --git a/substrate/client/consensus/babe/src/lib.rs b/substrate/client/consensus/babe/src/lib.rs index 9bdc08b883..84b018ac59 100644 --- a/substrate/client/consensus/babe/src/lib.rs +++ b/substrate/client/consensus/babe/src/lib.rs @@ -466,8 +466,11 @@ impl slots::SimpleSlotWorker for BabeWorker Option { - // never give more than 20 times more lenience. - const BACKOFF_CAP: u64 = 20; + // never give more than 2^this times the lenience. + const BACKOFF_CAP: u64 = 8; + + // how many slots it takes before we double the lenience. + const BACKOFF_STEP: u64 = 2; let slot_remaining = self.slot_remaining_duration(slot_info); let parent_slot = match find_pre_digest::(head) { @@ -478,12 +481,22 @@ impl slots::SimpleSlotWorker for BabeWorker= 1 { + debug!(target: "babe", "No block for {} slots. Applying 2^({}/{}) lenience", + slot_lenience, slot_lenience, BACKOFF_STEP); + } + + let slot_duration = slot_info.duration << (slot_lenience / BACKOFF_STEP); + + let slot_lenience = Duration::from_secs(slot_duration); Some(slot_lenience + slot_remaining) } } diff --git a/substrate/frame/support/src/storage/mod.rs b/substrate/frame/support/src/storage/mod.rs index 1d575d0794..4a392affbd 100644 --- a/substrate/frame/support/src/storage/mod.rs +++ b/substrate/frame/support/src/storage/mod.rs @@ -364,8 +364,10 @@ impl Iterator for PrefixIterator { type Item = Value; fn next(&mut self) -> Option { - match sp_io::storage::next_key(&self.previous_key) { - Some(next_key) if next_key.starts_with(&self.prefix[..]) => { + match sp_io::storage::next_key(&self.previous_key) + .filter(|n| n.starts_with(&self.prefix[..])) + { + Some(next_key) => { let value = unhashed::get(&next_key); if value.is_none() {