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

Unify Import verifier usage across parachain template and omninode #7195

Merged
merged 11 commits into from
Jan 22, 2025
24 changes: 23 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,36 @@ impl NaiveEquivocationDefender {
}
}

struct Verifier<P, Client, Block, CIDP> {
pub struct Verifier<P, Client, Block, CIDP> {
MrishoLukamba marked this conversation as resolved.
Show resolved Hide resolved
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, ()>,
{
pub fn new(client: Arc<Client>, inherent_data_provider: CIDP, telemetry: Option<TelemetryHandle>) -> Self {
MrishoLukamba marked this conversation as resolved.
Show resolved Hide resolved
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
52 changes: 15 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,12 +37,13 @@ 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::{
use cumulus_client_consensus_aura::{collators::{
lookahead::{self as aura, Params as AuraParams},
slot_based::{SlotBasedBlockImport, SlotBasedBlockImportHandle},
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;
use cumulus_client_consensus_proposer::{Proposer, ProposerInterface};
#[allow(deprecated)]
use cumulus_client_service::CollatorSybilResistance;
use cumulus_primitives_core::{relay_chain::ValidationCode, ParaId};
Expand Down Expand Up @@ -118,49 +119,26 @@ 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,
});

bkchr marked this conversation as resolved.
Show resolved Hide resolved
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: []
Loading