Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
13 changes: 3 additions & 10 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.

use node_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{BlockBackend, ExecutorProvider};
use sc_client_api::BlockBackend;
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
pub use sc_executor::NativeElseWasmExecutor;
use sc_finality_grandpa::SharedVoterState;
Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn new_partial(
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;

let import_queue =
sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _, _>(ImportQueueParams {
sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _>(ImportQueueParams {
block_import: grandpa_block_import.clone(),
justification_import: Some(Box::new(grandpa_block_import.clone())),
client: client.clone(),
Expand All @@ -129,9 +129,6 @@ pub fn new_partial(
Ok((timestamp, slot))
},
spawner: &task_manager.spawn_essential_handle(),
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(
client.executor().clone(),
),
registry: config.prometheus_registry(),
check_for_equivocation: Default::default(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand Down Expand Up @@ -254,12 +251,9 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
telemetry.as_ref().map(|x| x.handle()),
);

let can_author_with =
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;

let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _, _>(
let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _>(
StartAuraParams {
slot_duration,
client,
Expand All @@ -280,7 +274,6 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
can_author_with,
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
Expand Down
7 changes: 1 addition & 6 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use futures::prelude::*;
use kitchensink_runtime::RuntimeApi;
use node_executor::ExecutorDispatch;
use node_primitives::Block;
use sc_client_api::{BlockBackend, ExecutorProvider};
use sc_client_api::BlockBackend;
use sc_consensus_babe::{self, SlotProportion};
use sc_executor::NativeElseWasmExecutor;
use sc_network::NetworkService;
Expand Down Expand Up @@ -227,7 +227,6 @@ pub fn new_partial(
},
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
telemetry.as_ref().map(|x| x.handle()),
)?;

Expand Down Expand Up @@ -422,9 +421,6 @@ pub fn new_full_base(
telemetry.as_ref().map(|x| x.handle()),
);

let can_author_with =
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());

let client_clone = client.clone();
let slot_duration = babe_link.config().slot_duration();
let babe_config = sc_consensus_babe::BabeParams {
Expand Down Expand Up @@ -463,7 +459,6 @@ pub fn new_full_base(
force_authoring,
backoff_authoring_blocks,
babe_link,
can_author_with,
block_proposal_slot_portion: SlotProportion::new(0.5),
max_block_proposal_slot_portion: None,
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand Down
53 changes: 14 additions & 39 deletions client/consensus/aura/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sp_blockchain::{
well_known_cache_keys::{self, Id as CacheKeyId},
HeaderBackend,
};
use sp_consensus::{CanAuthorWith, Error as ConsensusError};
use sp_consensus::Error as ConsensusError;
use sp_consensus_aura::{
digests::CompatibleDigestItem, inherents::AuraInherentData, AuraApi, ConsensusLog,
AURA_ENGINE_ID,
Expand Down Expand Up @@ -109,38 +109,34 @@ where
}

/// A verifier for Aura blocks.
pub struct AuraVerifier<C, P, CAW, CIDP> {
pub struct AuraVerifier<C, P, CIDP> {
client: Arc<C>,
phantom: PhantomData<P>,
create_inherent_data_providers: CIDP,
can_author_with: CAW,
check_for_equivocation: CheckForEquivocation,
telemetry: Option<TelemetryHandle>,
}

impl<C, P, CAW, CIDP> AuraVerifier<C, P, CAW, CIDP> {
impl<C, P, CIDP> AuraVerifier<C, P, CIDP> {
pub(crate) fn new(
client: Arc<C>,
create_inherent_data_providers: CIDP,
can_author_with: CAW,
check_for_equivocation: CheckForEquivocation,
telemetry: Option<TelemetryHandle>,
) -> Self {
Self {
client,
create_inherent_data_providers,
can_author_with,
check_for_equivocation,
telemetry,
phantom: PhantomData,
}
}
}

impl<C, P, CAW, CIDP> AuraVerifier<C, P, CAW, CIDP>
impl<C, P, CIDP> AuraVerifier<C, P, CIDP>
where
P: Send + Sync + 'static,
CAW: Send + Sync + 'static,
CIDP: Send,
{
async fn check_inherents<B: BlockT>(
Expand All @@ -154,19 +150,8 @@ where
where
C: ProvideRuntimeApi<B>,
C::Api: BlockBuilderApi<B>,
CAW: CanAuthorWith<B>,
CIDP: CreateInherentDataProviders<B, ()>,
{
if let Err(e) = self.can_author_with.can_author_with(&block_id) {
debug!(
target: "aura",
"Skipping `check_inherents` as authoring version is not compatible: {}",
e,
);

return Ok(())
}

let inherent_res = self
.client
.runtime_api()
Expand All @@ -187,14 +172,13 @@ where
}

#[async_trait::async_trait]
impl<B: BlockT, C, P, CAW, CIDP> Verifier<B> for AuraVerifier<C, P, CAW, CIDP>
impl<B: BlockT, C, P, CIDP> Verifier<B> for AuraVerifier<C, P, CIDP>
where
C: ProvideRuntimeApi<B> + Send + Sync + sc_client_api::backend::AuxStore + BlockOf,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B>,
P: Pair + Send + Sync + 'static,
P::Public: Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + 'static,
P::Signature: Encode + Decode,
CAW: CanAuthorWith<B> + Send + Sync + 'static,
CIDP: CreateInherentDataProviders<B, ()> + Send + Sync,
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
{
Expand Down Expand Up @@ -338,7 +322,7 @@ impl Default for CheckForEquivocation {
}

/// Parameters of [`import_queue`].
pub struct ImportQueueParams<'a, Block, I, C, S, CAW, CIDP> {
pub struct ImportQueueParams<'a, Block, I, C, S, CIDP> {
/// The block import to use.
pub block_import: I,
/// The justification import.
Expand All @@ -351,27 +335,24 @@ pub struct ImportQueueParams<'a, Block, I, C, S, CAW, CIDP> {
pub spawner: &'a S,
/// The prometheus registry.
pub registry: Option<&'a Registry>,
/// Can we author with the current node?
pub can_author_with: CAW,
/// Should we check for equivocation?
pub check_for_equivocation: CheckForEquivocation,
/// Telemetry instance used to report telemetry metrics.
pub telemetry: Option<TelemetryHandle>,
}

/// Start an import queue for the Aura consensus algorithm.
pub fn import_queue<P, Block, I, C, S, CAW, CIDP>(
pub fn import_queue<P, Block, I, C, S, CIDP>(
ImportQueueParams {
block_import,
justification_import,
client,
create_inherent_data_providers,
spawner,
registry,
can_author_with,
check_for_equivocation,
telemetry,
}: ImportQueueParams<Block, I, C, S, CAW, CIDP>,
}: ImportQueueParams<Block, I, C, S, CIDP>,
) -> Result<DefaultImportQueue<Block, C>, sp_consensus::Error>
where
Block: BlockT,
Expand All @@ -392,14 +373,12 @@ where
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode,
P::Signature: Encode + Decode,
S: sp_core::traits::SpawnEssentialNamed,
CAW: CanAuthorWith<Block> + Send + Sync + 'static,
CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
{
let verifier = build_verifier::<P, _, _, _>(BuildVerifierParams {
let verifier = build_verifier::<P, _, _>(BuildVerifierParams {
client,
create_inherent_data_providers,
can_author_with,
check_for_equivocation,
telemetry,
});
Expand All @@ -408,33 +387,29 @@ where
}

/// Parameters of [`build_verifier`].
pub struct BuildVerifierParams<C, CIDP, CAW> {
pub struct BuildVerifierParams<C, CIDP> {
/// The client to interact with the chain.
pub client: Arc<C>,
/// Something that can create the inherent data providers.
pub create_inherent_data_providers: CIDP,
/// Can we author with the current node?
pub can_author_with: CAW,
/// Should we check for equivocation?
pub check_for_equivocation: CheckForEquivocation,
/// Telemetry instance used to report telemetry metrics.
pub telemetry: Option<TelemetryHandle>,
}

/// Build the [`AuraVerifier`]
pub fn build_verifier<P, C, CIDP, CAW>(
pub fn build_verifier<P, C, CIDP>(
BuildVerifierParams {
client,
create_inherent_data_providers,
can_author_with,
check_for_equivocation,
telemetry,
}: BuildVerifierParams<C, CIDP, CAW>,
) -> AuraVerifier<C, P, CAW, CIDP> {
AuraVerifier::<_, P, _, _>::new(
}: BuildVerifierParams<C, CIDP>,
) -> AuraVerifier<C, P, CIDP> {
AuraVerifier::<_, P, _>::new(
client,
create_inherent_data_providers,
can_author_with,
check_for_equivocation,
telemetry,
)
Expand Down
24 changes: 6 additions & 18 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ use sc_telemetry::TelemetryHandle;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::{AppKey, AppPublic};
use sp_blockchain::{HeaderBackend, Result as CResult};
use sp_consensus::{
BlockOrigin, CanAuthorWith, Environment, Error as ConsensusError, Proposer, SelectChain,
};
use sp_consensus::{BlockOrigin, Environment, Error as ConsensusError, Proposer, SelectChain};
use sp_consensus_slots::Slot;
use sp_core::crypto::{ByteArray, Pair, Public};
use sp_inherents::CreateInherentDataProviders;
Expand Down Expand Up @@ -108,7 +106,7 @@ fn slot_author<P: Pair>(slot: Slot, authorities: &[AuthorityId<P>]) -> Option<&A
}

/// Parameters of [`start_aura`].
pub struct StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS, CAW> {
pub struct StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS> {
/// The duration of a slot.
pub slot_duration: SlotDuration,
/// The client to interact with the chain.
Expand All @@ -131,8 +129,6 @@ pub struct StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS, CAW> {
pub backoff_authoring_blocks: Option<BS>,
/// The keystore used by the node.
pub keystore: SyncCryptoStorePtr,
/// Can we author a block with this node?
pub can_author_with: CAW,
/// The proportion of the slot dedicated to proposing.
///
/// The block proposing will be limited to this proportion of the slot from the starting of the
Expand All @@ -147,7 +143,7 @@ pub struct StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS, CAW> {
}

/// Start the aura worker. The returned future should be run in a futures executor.
pub fn start_aura<P, B, C, SC, I, PF, SO, L, CIDP, BS, CAW, Error>(
pub fn start_aura<P, B, C, SC, I, PF, SO, L, CIDP, BS, Error>(
StartAuraParams {
slot_duration,
client,
Expand All @@ -160,11 +156,10 @@ pub fn start_aura<P, B, C, SC, I, PF, SO, L, CIDP, BS, CAW, Error>(
force_authoring,
backoff_authoring_blocks,
keystore,
can_author_with,
block_proposal_slot_portion,
max_block_proposal_slot_portion,
telemetry,
}: StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS, CAW>,
}: StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS>,
) -> Result<impl Future<Output = ()>, sp_consensus::Error>
where
P: Pair + Send + Sync,
Expand All @@ -182,7 +177,6 @@ where
CIDP: CreateInherentDataProviders<B, ()> + Send,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + Sync + 'static,
CAW: CanAuthorWith<B> + Send,
Error: std::error::Error + Send + From<sp_consensus::Error> + 'static,
{
let worker = build_aura_worker::<P, _, _, _, _, _, _, _, _>(BuildAuraWorkerParams {
Expand All @@ -205,7 +199,6 @@ where
SimpleSlotWorkerToSlotWorker(worker),
sync_oracle,
create_inherent_data_providers,
can_author_with,
))
}

Expand Down Expand Up @@ -568,9 +561,7 @@ mod tests {
use sc_keystore::LocalKeystore;
use sc_network_test::{Block as TestBlock, *};
use sp_application_crypto::key_types::AURA;
use sp_consensus::{
AlwaysCanAuthor, DisableProofRecording, NoNetwork as DummyOracle, Proposal,
};
use sp_consensus::{DisableProofRecording, NoNetwork as DummyOracle, Proposal};
use sp_consensus_aura::sr25519::AuthorityPair;
use sp_inherents::InherentData;
use sp_keyring::sr25519::Keyring;
Expand Down Expand Up @@ -633,7 +624,6 @@ mod tests {
type AuraVerifier = import_queue::AuraVerifier<
PeersFullClient,
AuthorityPair,
AlwaysCanAuthor,
Box<
dyn CreateInherentDataProviders<
TestBlock,
Expand Down Expand Up @@ -670,7 +660,6 @@ mod tests {

Ok((timestamp, slot))
}),
AlwaysCanAuthor,
CheckForEquivocation::Yes,
None,
)
Expand Down Expand Up @@ -738,7 +727,7 @@ mod tests {
let slot_duration = slot_duration(&*client).expect("slot duration available");

aura_futures.push(
start_aura::<AuthorityPair, _, _, _, _, _, _, _, _, _, _, _>(StartAuraParams {
start_aura::<AuthorityPair, _, _, _, _, _, _, _, _, _, _>(StartAuraParams {
slot_duration,
block_import: client.clone(),
select_chain,
Expand All @@ -760,7 +749,6 @@ mod tests {
BackoffAuthoringOnFinalizedHeadLagging::default(),
),
keystore,
can_author_with: sp_consensus::AlwaysCanAuthor,
block_proposal_slot_portion: SlotProportion::new(0.5),
max_block_proposal_slot_portion: None,
telemetry: None,
Expand Down
Loading