Skip to content

Commit

Permalink
Skip slot before creating inherent data providers during major sync
Browse files Browse the repository at this point in the history
  • Loading branch information
LGLO committed Aug 13, 2024
1 parent 149c709 commit 35ca5f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 10 additions & 0 deletions prdoc/pr_5344.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Fix storage weight reclaim bug.

doc:
- audience: Node Dev
description: |
Improvement in slot worker loop that will not call create inherent data providers if the major sync is in progress. Before it was called every slot and the results were discarded during major sync.

crates:
- name: sc-consensus-slots
bump: minor
8 changes: 1 addition & 7 deletions substrate/client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,16 +517,10 @@ pub async fn start_slot_worker<B, C, W, SO, CIDP, Proof>(
CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
{
let mut slots = Slots::new(slot_duration.as_duration(), create_inherent_data_providers, client);
let mut slots = Slots::new(slot_duration.as_duration(), create_inherent_data_providers, client, sync_oracle);

loop {
let slot_info = slots.next_slot().await;

if sync_oracle.is_major_syncing() {
debug!(target: LOG_TARGET, "Skipping proposal slot due to sync.");
continue
}

let _ = worker.on_slot(slot_info).await;
}
}
Expand Down
17 changes: 13 additions & 4 deletions substrate/client/consensus/slots/src/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! This is used instead of `futures_timer::Interval` because it was unreliable.

use super::{InherentDataProviderExt, Slot, LOG_TARGET};
use sp_consensus::SelectChain;
use sp_consensus::{SelectChain, SyncOracle};
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};

Expand Down Expand Up @@ -87,39 +87,43 @@ impl<B: BlockT> SlotInfo<B> {
}

/// A stream that returns every time there is a new slot.
pub(crate) struct Slots<Block, SC, IDP> {
pub(crate) struct Slots<Block, SC, IDP, SO> {
last_slot: Slot,
slot_duration: Duration,
until_next_slot: Option<Delay>,
create_inherent_data_providers: IDP,
select_chain: SC,
sync_oracle: SO,
_phantom: std::marker::PhantomData<Block>,
}

impl<Block, SC, IDP> Slots<Block, SC, IDP> {
impl<Block, SC, IDP, SO> Slots<Block, SC, IDP, SO> {
/// Create a new `Slots` stream.
pub fn new(
slot_duration: Duration,
create_inherent_data_providers: IDP,
select_chain: SC,
sync_oracle: SO
) -> Self {
Slots {
last_slot: 0.into(),
slot_duration,
until_next_slot: None,
create_inherent_data_providers,
select_chain,
sync_oracle,
_phantom: Default::default(),
}
}
}

impl<Block, SC, IDP> Slots<Block, SC, IDP>
impl<Block, SC, IDP, SO> Slots<Block, SC, IDP, SO>
where
Block: BlockT,
SC: SelectChain<Block>,
IDP: CreateInherentDataProviders<Block, ()> + 'static,
IDP::InherentDataProviders: crate::InherentDataProviderExt,
SO: SyncOracle,
{
/// Returns a future that fires when the next slot starts.
pub async fn next_slot(&mut self) -> SlotInfo<Block> {
Expand All @@ -138,6 +142,11 @@ where
let wait_dur = time_until_next_slot(self.slot_duration);
self.until_next_slot = Some(Delay::new(wait_dur));

if self.sync_oracle.is_major_syncing() {
log::debug!(target: LOG_TARGET, "Skipping slot: major sync is in progress.");
continue;
}

let chain_head = match self.select_chain.best_chain().await {
Ok(x) => x,
Err(e) => {
Expand Down

0 comments on commit 35ca5f7

Please sign in to comment.