mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Add linear back-off for aura slot workers (#4293)
* Add linear back-off for aura slot workers * logging * Use slot from header
This commit is contained in:
committed by
Robert Habermeier
parent
3c04635176
commit
03a3993541
@@ -302,6 +302,32 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
|
||||
consensus_common::Error::ClientImport(format!("{:?}", e)).into()
|
||||
})
|
||||
}
|
||||
|
||||
fn proposing_remaining_duration(
|
||||
&self,
|
||||
head: &B::Header,
|
||||
slot_info: &SlotInfo
|
||||
) -> Option<std::time::Duration> {
|
||||
// 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::<B, P>(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<H, B: BlockT, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I, P, SO> where
|
||||
@@ -357,6 +383,10 @@ fn find_pre_digest<B: BlockT, P: Pair>(header: &B::Header) -> Result<u64, Error<
|
||||
P::Signature: Decode,
|
||||
P::Public: Encode + Decode + PartialEq + Clone,
|
||||
{
|
||||
if header.number().is_zero() {
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
let mut pre_digest: Option<u64> = None;
|
||||
for log in header.digest().logs() {
|
||||
trace!(target: "aura", "Checking log {:?}", log);
|
||||
|
||||
Reference in New Issue
Block a user