Skip to content

Commit

Permalink
simplify shell to aura
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Jul 31, 2024
1 parent d243148 commit fdfc9a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 57 deletions.
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,
}
},
)) 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

0 comments on commit fdfc9a8

Please sign in to comment.