Skip to content

Commit

Permalink
Fix warp sync (paritytech#12281)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored and ark0f committed Feb 27, 2023
1 parent a800e96 commit 80a8a5b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
19 changes: 10 additions & 9 deletions client/consensus/aura/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ where

inherent_data.aura_replace_inherent_data(slot);

// skip the inherents verification if the runtime API is old.
if self
.client
.runtime_api()
.has_api_with::<dyn BlockBuilderApi<B>, _>(
&BlockId::Hash(parent_hash),
|v| v >= 2,
)
.map_err(|e| e.to_string())?
// skip the inherents verification if the runtime API is old or not expected to
// exist.
if !block.state_action.skip_execution_checks() &&
self.client
.runtime_api()
.has_api_with::<dyn BlockBuilderApi<B>, _>(
&BlockId::Hash(parent_hash),
|v| v >= 2,
)
.map_err(|e| e.to_string())?
{
self.check_inherents(
new_block.clone(),
Expand Down
34 changes: 18 additions & 16 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,24 +1237,26 @@ where
warn!(target: "babe", "Error checking/reporting BABE equivocation: {}", err);
}

// if the body is passed through, we need to use the runtime
// to check that the internally-set timestamp in the inherents
// actually matches the slot set in the seal.
if let Some(inner_body) = block.body {
let mut inherent_data = create_inherent_data_providers
.create_inherent_data()
.map_err(Error::<Block>::CreateInherents)?;
inherent_data.babe_replace_inherent_data(slot);
let new_block = Block::new(pre_header.clone(), inner_body);

self.check_inherents(
new_block.clone(),
BlockId::Hash(parent_hash),
inherent_data,
create_inherent_data_providers,
block.origin.into(),
)
.await?;
if !block.state_action.skip_execution_checks() {
// if the body is passed through and the block was executed,
// we need to use the runtime to check that the internally-set
// timestamp in the inherents actually matches the slot set in the seal.
let mut inherent_data = create_inherent_data_providers
.create_inherent_data()
.map_err(Error::<Block>::CreateInherents)?;
inherent_data.babe_replace_inherent_data(slot);

self.check_inherents(
new_block.clone(),
BlockId::Hash(parent_hash),
inherent_data,
create_inherent_data_providers,
block.origin.into(),
)
.await?;
}

let (_, inner_body) = new_block.deconstruct();
block.body = Some(inner_body);
Expand Down
12 changes: 12 additions & 0 deletions client/consensus/common/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ pub enum StateAction<Block: BlockT, Transaction> {
Skip,
}

impl<Block: BlockT, Transaction> StateAction<Block, Transaction> {
/// Check if execution checks that require runtime calls should be skipped.
pub fn skip_execution_checks(&self) -> bool {
match self {
StateAction::ApplyChanges(_) |
StateAction::Execute |
StateAction::ExecuteIfPossible => false,
StateAction::Skip => true,
}
}
}

/// Data required to import a Block.
#[non_exhaustive]
pub struct BlockImportParams<Block: BlockT, Transaction> {
Expand Down
20 changes: 11 additions & 9 deletions client/consensus/pow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,17 @@ where
if let Some(inner_body) = block.body.take() {
let check_block = B::new(block.header.clone(), inner_body);

self.check_inherents(
check_block.clone(),
BlockId::Hash(parent_hash),
self.create_inherent_data_providers
.create_inherent_data_providers(parent_hash, ())
.await?,
block.origin.into(),
)
.await?;
if !block.state_action.skip_execution_checks() {
self.check_inherents(
check_block.clone(),
BlockId::Hash(parent_hash),
self.create_inherent_data_providers
.create_inherent_data_providers(parent_hash, ())
.await?,
block.origin.into(),
)
.await?;
}

block.body = Some(check_block.deconstruct().1);
}
Expand Down

0 comments on commit 80a8a5b

Please sign in to comment.