From 03a3993541872873b02491de5bb5c17be23f3b29 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Thu, 5 Dec 2019 11:07:58 +0200 Subject: [PATCH] Add linear back-off for aura slot workers (#4293) * Add linear back-off for aura slot workers * logging * Use slot from header --- substrate/client/consensus/aura/src/lib.rs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/substrate/client/consensus/aura/src/lib.rs b/substrate/client/consensus/aura/src/lib.rs index 7653be7259..e07ab5f99a 100644 --- a/substrate/client/consensus/aura/src/lib.rs +++ b/substrate/client/consensus/aura/src/lib.rs @@ -302,6 +302,32 @@ impl slots::SimpleSlotWorker for AuraWorker Option { + // never give more than 20 times more lenience. + const BACKOFF_CAP: u64 = 20; + + let slot_remaining = self.slot_remaining_duration(slot_info); + let parent_slot = match find_pre_digest::(head) { + Err(_) => return Some(slot_remaining), + Ok(d) => d, + }; + + // we allow a lenience of the number of slots since the head of the + // chain was produced, minus 1 (since there is always a difference of at least 1) + // + // linear back-off. + // in normal cases we only attempt to issue blocks up to the end of the slot. + // when the chain has been stalled for a few slots, we give more lenience. + let slot_lenience = slot_info.number.saturating_sub(parent_slot + 1); + let slot_lenience = std::cmp::min(slot_lenience, BACKOFF_CAP); + let slot_lenience = Duration::from_secs(slot_lenience * slot_info.duration); + Some(slot_lenience + slot_remaining) + } } impl SlotWorker for AuraWorker where @@ -357,6 +383,10 @@ fn find_pre_digest(header: &B::Header) -> Result = None; for log in header.digest().logs() { trace!(target: "aura", "Checking log {:?}", log);