,
}
impl AuraConsensus
where
B: BlockT,
CIDP: CreateInherentDataProviders + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt,
{
/// Create a new boxed instance of AURA consensus.
pub fn build(
BuildAuraConsensusParams {
proposer_factory,
create_inherent_data_providers,
block_import,
para_client,
backoff_authoring_blocks,
sync_oracle,
keystore,
force_authoring,
slot_duration,
telemetry,
block_proposal_slot_portion,
max_block_proposal_slot_portion,
}: BuildAuraConsensusParams,
) -> Box>
where
Client:
ProvideRuntimeApi + BlockOf + AuxStore + HeaderBackend + Send + Sync + 'static,
Client::Api: AuraApi,
BI: BlockImport>
+ ParachainBlockImportMarker
+ Send
+ Sync
+ 'static,
SO: SyncOracle + Send + Sync + Clone + 'static,
BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static,
PF: Environment + Send + Sync + 'static,
PF::Proposer: Proposer<
B,
Error = Error,
Transaction = sp_api::TransactionFor,
ProofRecording = EnableProofRecording,
Proof = ::Proof,
>,
Error: std::error::Error + Send + From + 'static,
P: Pair + Send + Sync,
P::Public: AppPublic + Hash + Member + Encode + Decode,
P::Signature: TryFrom> + Hash + Member + Encode + Decode,
{
let worker = sc_consensus_aura::build_aura_worker::(
BuildAuraWorkerParams {
client: para_client,
block_import,
justification_sync_link: (),
proposer_factory,
sync_oracle,
force_authoring,
backoff_authoring_blocks,
keystore,
telemetry,
block_proposal_slot_portion,
max_block_proposal_slot_portion,
compatibility_mode: sc_consensus_aura::CompatibilityMode::None,
},
);
Box::new(AuraConsensus {
create_inherent_data_providers: Arc::new(create_inherent_data_providers),
aura_worker: Arc::new(Mutex::new(worker)),
slot_duration,
_phantom: PhantomData,
})
}
}
impl AuraConsensus
where
B: BlockT,
CIDP: CreateInherentDataProviders + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt,
{
/// Create the inherent data.
///
/// Returns the created inherent data and the inherent data providers used.
async fn inherent_data(
&self,
parent: B::Hash,
validation_data: &PersistedValidationData,
relay_parent: PHash,
) -> Option {
self.create_inherent_data_providers
.create_inherent_data_providers(parent, (relay_parent, validation_data.clone()))
.await
.map_err(|e| {
tracing::error!(
target: LOG_TARGET,
error = ?e,
"Failed to create inherent data providers.",
)
})
.ok()
}
}
#[async_trait::async_trait]
impl ParachainConsensus for AuraConsensus
where
B: BlockT,
CIDP: CreateInherentDataProviders + Send + Sync + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
W: SimpleSlotWorker + Send + Sync,
W::Proposer: Proposer::Proof>,
{
async fn produce_candidate(
&mut self,
parent: &B::Header,
relay_parent: PHash,
validation_data: &PersistedValidationData,
) -> Option> {
let inherent_data_providers =
self.inherent_data(parent.hash(), validation_data, relay_parent).await?;
let info = SlotInfo::new(
inherent_data_providers.slot(),
Box::new(inherent_data_providers),
self.slot_duration.as_duration(),
parent.clone(),
// Set the block limit to 50% of the maximum PoV size.
//
// TODO: If we got benchmarking that includes the proof size,
// we should be able to use the maximum pov size.
Some((validation_data.max_pov_size / 2) as usize),
);
let res = self.aura_worker.lock().await.on_slot(info).await?;
Some(ParachainCandidate { block: res.block, proof: res.storage_proof })
}
}