use codec::Codec;
use cumulus_client_consensus_common::ParachainBlockImportMarker;
use prometheus_endpoint::Registry;
use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
use sc_consensus::{import_queue::DefaultImportQueue, BlockImport};
use sc_consensus_aura::{AuraVerifier, CompatibilityMode};
use sc_consensus_slots::InherentDataProviderExt;
use sc_telemetry::TelemetryHandle;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::HeaderBackend;
use sp_consensus::Error as ConsensusError;
use sp_consensus_aura::AuraApi;
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::Block as BlockT;
use std::{fmt::Debug, sync::Arc};
pub struct ImportQueueParams<'a, I, C, CIDP, S> {
pub block_import: I,
pub client: Arc<C>,
pub create_inherent_data_providers: CIDP,
pub spawner: &'a S,
pub registry: Option<&'a Registry>,
pub telemetry: Option<TelemetryHandle>,
}
pub fn import_queue<P, Block, I, C, S, CIDP>(
ImportQueueParams {
block_import,
client,
create_inherent_data_providers,
spawner,
registry,
telemetry,
}: ImportQueueParams<'_, I, C, CIDP, S>,
) -> Result<DefaultImportQueue<Block>, sp_consensus::Error>
where
Block: BlockT,
C::Api: BlockBuilderApi<Block> + AuraApi<Block, P::Public> + ApiExt<Block>,
C: 'static
+ ProvideRuntimeApi<Block>
+ BlockOf
+ Send
+ Sync
+ AuxStore
+ UsageProvider<Block>
+ HeaderBackend<Block>,
I: BlockImport<Block, Error = ConsensusError>
+ ParachainBlockImportMarker
+ Send
+ Sync
+ 'static,
P: Pair + 'static,
P::Public: Debug + Codec,
P::Signature: Codec,
S: sp_core::traits::SpawnEssentialNamed,
CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
{
sc_consensus_aura::import_queue::<P, _, _, _, _, _>(sc_consensus_aura::ImportQueueParams {
block_import,
justification_import: None,
client,
create_inherent_data_providers,
spawner,
registry,
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
telemetry,
compatibility_mode: CompatibilityMode::None,
})
}
pub struct BuildVerifierParams<C, CIDP> {
pub client: Arc<C>,
pub create_inherent_data_providers: CIDP,
pub telemetry: Option<TelemetryHandle>,
}
pub fn build_verifier<P, C, CIDP, N>(
BuildVerifierParams { client, create_inherent_data_providers, telemetry }: BuildVerifierParams<
C,
CIDP,
>,
) -> AuraVerifier<C, P, CIDP, N> {
sc_consensus_aura::build_verifier(sc_consensus_aura::BuildVerifierParams {
client,
create_inherent_data_providers,
telemetry,
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
compatibility_mode: CompatibilityMode::None,
})
}