Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip slot before creating inherent data providers during major sync #5344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 6 additions & 7 deletions substrate/client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,16 +517,15 @@ 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
Loading