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

simplify shell to aura #1312

Merged
merged 1 commit into from
Aug 1, 2024
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
42 changes: 21 additions & 21 deletions bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,32 +950,32 @@ where
sc_client_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static,
{
let client_for_aura = client.clone();

let aura_verifier = move || {
let slot_duration =
cumulus_client_consensus_aura::slot_duration(&*client_for_aura).unwrap();

Box::new(sc_consensus_aura::build_verifier::<AuraPair, _, _, _>(
sc_consensus_aura::BuildVerifierParams {
client: client_for_aura.clone(),
create_inherent_data_providers: move |_, _| async move {
let verifier_client = client.clone();

let aura_verifier = cumulus_client_consensus_aura::build_verifier::<AuraPair, _, _, _>(
cumulus_client_consensus_aura::BuildVerifierParams {
client: verifier_client.clone(),
create_inherent_data_providers: move |parent_hash, _| {
let cidp_client = verifier_client.clone();
async move {
let slot_duration = cumulus_client_consensus_aura::slot_duration_at(
&*cidp_client,
parent_hash,
)?;
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
telemetry: telemetry_handle,
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::Yes,
compatibility_mode: sc_consensus_aura::CompatibilityMode::None,
Dinonard marked this conversation as resolved.
Show resolved Hide resolved
}
},
)) as Box<_>
};
telemetry: telemetry_handle,
},
);

let relay_chain_verifier = Box::new(RelayChainVerifier::new(client.clone(), |_, _| async {
Ok(())
Expand All @@ -984,7 +984,7 @@ where
let verifier = Verifier {
client,
relay_chain_verifier,
aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))),
aura_verifier: Box::new(aura_verifier),
};

let registry = config.prometheus_registry();
Expand Down
41 changes: 5 additions & 36 deletions bin/collator/src/parachain/shell_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use cumulus_primitives_core::relay_chain::PersistedValidationData;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use fc_rpc::pending::ConsensusDataProvider;
use sc_client_api::{AuxStore, UsageProvider};
use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams, ForkChoiceStrategy};
use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_consensus_aura::{
digests::CompatibleDigestItem,
Expand All @@ -37,27 +37,9 @@ use sp_runtime::{
use sp_timestamp::TimestampInherentData;
use std::{marker::PhantomData, sync::Arc};

pub enum BuildOnAccess<R> {
Uninitialized(Option<Box<dyn FnOnce() -> R + Send + Sync>>),
Initialized(R),
}

impl<R> BuildOnAccess<R> {
fn get_mut(&mut self) -> &mut R {
loop {
match self {
Self::Uninitialized(f) => {
*self = Self::Initialized((f.take().unwrap())());
}
Self::Initialized(ref mut r) => return r,
}
}
}
}

pub struct Verifier<Client> {
pub client: Arc<Client>,
pub aura_verifier: BuildOnAccess<Box<dyn VerifierT<Block>>>,
pub aura_verifier: Box<dyn VerifierT<Block>>,
pub relay_chain_verifier: Box<dyn VerifierT<Block>>,
}

Expand All @@ -69,28 +51,15 @@ where
{
async fn verify(
&mut self,
mut block_import: BlockImportParams<Block>,
block_import: BlockImportParams<Block>,
) -> Result<BlockImportParams<Block>, String> {
// Skip checks that include execution, if being told so or when importing only state.
//
// This is done for example when gap syncing and it is expected that the block after the gap
// was checked/chosen properly, e.g. by warp syncing to this block using a finality proof.
// Or when we are importing state only and can not verify the seal.
if block_import.with_state() || block_import.state_action.skip_execution_checks() {
// When we are importing only the state of a block, it will be the best block.
block_import.fork_choice = Some(ForkChoiceStrategy::Custom(block_import.with_state()));
return Ok(block_import);
}

let block_hash = *block_import.header.parent_hash();

if self
.client
.runtime_api()
.has_api::<dyn AuraApi<Block, AuraId>>(block_hash)
.has_api::<dyn AuraApi<Block, AuraId>>(*block_import.header.parent_hash())
.unwrap_or(false)
{
self.aura_verifier.get_mut().verify(block_import).await
self.aura_verifier.verify(block_import).await
} else {
self.relay_chain_verifier.verify(block_import).await
}
Expand Down
Loading