Skip to content

Commit

Permalink
Unify Import verifier usage across parachain template and omninode (#…
Browse files Browse the repository at this point in the history
…7195)

Closes #7055

@skunert @bkchr

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: command-bot <>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent 350a6c4 commit 634a17b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
31 changes: 30 additions & 1 deletion cumulus/client/consensus/aura/src/equivocation_import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,43 @@ impl NaiveEquivocationDefender {
}
}

struct Verifier<P, Client, Block, CIDP> {
/// A parachain block import verifier that checks for equivocation limits within each slot.
pub struct Verifier<P, Client, Block, CIDP> {
client: Arc<Client>,
create_inherent_data_providers: CIDP,
defender: Mutex<NaiveEquivocationDefender>,
telemetry: Option<TelemetryHandle>,
_phantom: std::marker::PhantomData<fn() -> (Block, P)>,
}

impl<P, Client, Block, CIDP> Verifier<P, Client, Block, CIDP>
where
P: Pair,
P::Signature: Codec,
P::Public: Codec + Debug,
Block: BlockT,
Client: ProvideRuntimeApi<Block> + Send + Sync,
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block> + AuraApi<Block, P::Public>,

CIDP: CreateInherentDataProviders<Block, ()>,
{
/// Creates a new Verifier instance for handling parachain block import verification in Aura
/// consensus.
pub fn new(
client: Arc<Client>,
inherent_data_provider: CIDP,
telemetry: Option<TelemetryHandle>,
) -> Self {
Self {
client,
create_inherent_data_providers: inherent_data_provider,
defender: Mutex::new(NaiveEquivocationDefender::default()),
telemetry,
_phantom: std::marker::PhantomData,
}
}
}

#[async_trait::async_trait]
impl<P, Client, Block, CIDP> VerifierT<Block> for Verifier<P, Client, Block, CIDP>
where
Expand Down
56 changes: 19 additions & 37 deletions cumulus/polkadot-omni-node/lib/src/nodes/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ use cumulus_client_collator::service::{
use cumulus_client_consensus_aura::collators::slot_based::{
self as slot_based, Params as SlotBasedParams,
};
use cumulus_client_consensus_aura::collators::{
lookahead::{self as aura, Params as AuraParams},
slot_based::{SlotBasedBlockImport, SlotBasedBlockImportHandle},
use cumulus_client_consensus_aura::{
collators::{
lookahead::{self as aura, Params as AuraParams},
slot_based::{SlotBasedBlockImport, SlotBasedBlockImportHandle},
},
equivocation_import_queue::Verifier as EquivocationVerifier,
};
use cumulus_client_consensus_proposer::{Proposer, ProposerInterface};
use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
Expand Down Expand Up @@ -118,49 +121,28 @@ where
telemetry_handle: Option<TelemetryHandle>,
task_manager: &TaskManager,
) -> sc_service::error::Result<DefaultImportQueue<Block>> {
let verifier_client = client.clone();

let aura_verifier = cumulus_client_consensus_aura::build_verifier::<
<AuraId as AppCrypto>::Pair,
_,
_,
_,
>(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,
);

Ok((slot, timestamp))
}
},
telemetry: telemetry_handle,
});
let inherent_data_providers =
move |_, _| async move { Ok(sp_timestamp::InherentDataProvider::from_system_time()) };
let registry = config.prometheus_registry();
let spawner = task_manager.spawn_essential_handle();

let relay_chain_verifier =
Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) }));

let equivocation_aura_verifier =
EquivocationVerifier::<<AuraId as AppCrypto>::Pair, _, _, _>::new(
client.clone(),
inherent_data_providers,
telemetry_handle,
);

let verifier = Verifier {
client,
aura_verifier: Box::new(equivocation_aura_verifier),
relay_chain_verifier,
aura_verifier: Box::new(aura_verifier),
_phantom: PhantomData,
_phantom: Default::default(),
};

let registry = config.prometheus_registry();
let spawner = task_manager.spawn_essential_handle();

Ok(BasicQueue::new(verifier, Box::new(block_import), None, &spawner, registry))
}
}
Expand Down
7 changes: 7 additions & 0 deletions prdoc/pr_7195.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Unify Import verifier usage across parachain template and omninode
doc:
- audience: Node Dev
description: |-
In polkadot-omni-node block import pipeline it uses default aura verifier without checking equivocation,
This Pr replaces the check with full verification with equivocation like in parachain template block import
crates: []

0 comments on commit 634a17b

Please sign in to comment.