mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-14 01:35:50 +00:00
6ef1117685
* Update substrate & polkadot * min changes to make async backing compile * (async backing) parachain-system: track limitations for unincluded blocks (#2438) * unincluded segment draft * read para head from storage proof * read_para_head -> read_included_para_head * Provide pub interface * add errors * fix unincluded segment update * BlockTracker -> Ancestor * add a dmp limit * Read para head depending on the storage switch * doc comments * storage items docs * add a sanity check on block initialize * Check watermark * append to the segment on block finalize * Move segment update into set_validation_data * Resolve para head todo * option watermark * fix comment * Drop dmq check * fix weight * doc-comments on inherent invariant * Remove TODO * add todo * primitives tests * pallet tests * doc comments * refactor unincluded segment length into a ConsensusHook (#2501) * refactor unincluded segment length into a ConsensusHook * add docs * refactor bandwidth_out calculation Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com> * test for limits from impl * fmt * make tests compile * update comment * uncomment test * fix collator test by adding parent to state proof * patch HRMP watermark rules for unincluded segment * get consensus-common tests to pass, using unincluded segment * fix unincluded segment tests * get all tests passing * fmt * rustdoc CI * aura-ext: limit the number of authored blocks per slot (#2551) * aura_ext consensus hook * reverse dependency * include weight into hook * fix tests * remove stray println Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com> * fix test warning * fix doc link --------- Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com> Co-authored-by: Chris Sosnin <chris125_@live.com> * parachain-system: ignore go ahead signal once upgrade is processed (#2594) * handle goahead signal for unincluded segment * doc comment * add test * parachain-system: drop processed messages from inherent data (#2590) * implement `drop_processed_messages` * drop messages based on relay parent number * adjust tests * drop changes to mqc * fix comment * drop test * drop more dead code * clippy * aura-ext: check slot in consensus hook and remove all `CheckInherents` logic (#2658) * aura-ext: check slot in consensus hook * convert relay chain slot * Make relay chain slot duration generic * use fixed velocity hook for pallets with aura * purge timestamp inherent * fix warning * adjust runtime tests * fix slots in tests * Make `xcm-emulator` test pass for new consensus hook (#2722) * add pallets on_initialize * tests pass * add AuraExt on_init * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: command-bot <> --------- Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com> * update polkadot git refs * CollationGenerationConfig closure is now optional (#2772) * CollationGenerationConfig closure is now optional * fix test * propagate network-protocol-staging feature (#2899) * Feature Flagging Consensus Hook Type Parameter (#2911) * First pass * fmt * Added as default feature in tomls * Changed to direct dependency feature * Dealing with clippy error * Update pallets/parachain-system/src/lib.rs Co-authored-by: asynchronous rob <rphmeier@gmail.com> --------- Co-authored-by: asynchronous rob <rphmeier@gmail.com> * fmt * bump deps and remove warning * parachain-system: update RelevantMessagingState according to the unincluded segment (#2948) * mostly address 2471 with a bug introduced * adjust relevant messaging state after computing total * fmt * max -> min * fix test implementation of xcmp source * add test * fix test message sending logic * fix + test * add more to unincluded segment test * fmt --------- Co-authored-by: Chris Sosnin <chris125_@live.com> * Integrate new Aura / Parachain Consensus Logic in Parachain-Template / Polkadot-Parachain (#2864) * add a comment * refactor client/service utilities * deprecate start_collator * update parachain-template * update test-service in the same way * update polkadot-parachain crate * fmt * wire up new SubmitCollation message * some runtime utilities for implementing unincluded segment runtime APIs * allow parachains to configure their level of sybil-resistance when starting the network * make aura-ext compile * update to specify sybil resistance levels * fmt * specify relay chain slot duration in milliseconds * update Aura to explicitly produce Send futures also, make relay_chain_slot_duration a Duration * add authoring duration to basic collator and document params * integrate new basic collator into parachain-template * remove assert_send used for testing * basic-aura: only author when parent included * update polkadot-parachain-bin * fmt * some fixes * fixes * add a RelayNumberMonotonicallyIncreases * add a utility function for initializing subsystems * some logging for timestamp adjustment * fmt * some fixes for lookahead collator * add a log * update `find_potential_parents` to account for sessions * bound the loop * restore & deprecate old start_collator and start_full_node functions. * remove unnecessary await calls * fix warning * clippy * more clippy * remove unneeded logic * ci * update comment Co-authored-by: Marcin S. <marcin@bytedude.com> * (async backing) restore `CheckInherents` for backwards-compatibility (#2977) * bring back timestamp * Restore CheckInherents * revert to empty CheckInherents * make CheckInherents optional * attempt * properly end system blocks * add some more comments * ignore failing system parachain tests * update refs after main feature branch merge * comment out the offending tests because CI runs ignored tests * fix warnings * fmt * revert to polkadot master * cargo update -p polkadot-primitives -p sp-io --------- Co-authored-by: asynchronous rob <rphmeier@gmail.com> Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com> Co-authored-by: Bradley Olson <34992650+BradleyOlson64@users.noreply.github.com> Co-authored-by: Marcin S. <marcin@bytedude.com> Co-authored-by: eskimor <eskimor@users.noreply.github.com> Co-authored-by: Andronik <write@reusable.software>
229 lines
7.5 KiB
Rust
229 lines
7.5 KiB
Rust
// Copyright 2021 Parity Technologies (UK) Ltd.
|
|
// This file is part of Cumulus.
|
|
|
|
// Cumulus is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Cumulus is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! The AuRa consensus algorithm for parachains.
|
|
//!
|
|
//! This extends the Substrate provided AuRa consensus implementation to make it compatible for
|
|
//! parachains. The main entry points for of this consensus algorithm are [`AuraConsensus::build`]
|
|
//! and [`fn@import_queue`].
|
|
//!
|
|
//! For more information about AuRa, the Substrate crate should be checked.
|
|
|
|
use codec::Codec;
|
|
use cumulus_client_consensus_common::{
|
|
ParachainBlockImportMarker, ParachainCandidate, ParachainConsensus,
|
|
};
|
|
use cumulus_primitives_core::{relay_chain::Hash as PHash, PersistedValidationData};
|
|
|
|
use futures::lock::Mutex;
|
|
use sc_client_api::{backend::AuxStore, BlockOf};
|
|
use sc_consensus::BlockImport;
|
|
use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, SimpleSlotWorker, SlotInfo};
|
|
use sc_telemetry::TelemetryHandle;
|
|
use sp_api::ProvideRuntimeApi;
|
|
use sp_application_crypto::AppPublic;
|
|
use sp_blockchain::HeaderBackend;
|
|
use sp_consensus::{EnableProofRecording, Environment, ProofRecording, Proposer, SyncOracle};
|
|
use sp_consensus_aura::{AuraApi, SlotDuration};
|
|
use sp_core::crypto::Pair;
|
|
use sp_inherents::CreateInherentDataProviders;
|
|
use sp_keystore::KeystorePtr;
|
|
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, NumberFor};
|
|
use std::{convert::TryFrom, marker::PhantomData, sync::Arc};
|
|
|
|
mod import_queue;
|
|
|
|
pub use import_queue::{build_verifier, import_queue, BuildVerifierParams, ImportQueueParams};
|
|
pub use sc_consensus_aura::{slot_duration, AuraVerifier, BuildAuraWorkerParams, SlotProportion};
|
|
pub use sc_consensus_slots::InherentDataProviderExt;
|
|
|
|
pub mod collator;
|
|
pub mod collators;
|
|
pub mod equivocation_import_queue;
|
|
|
|
const LOG_TARGET: &str = "aura::cumulus";
|
|
|
|
/// The implementation of the AURA consensus for parachains.
|
|
pub struct AuraConsensus<B, CIDP, W> {
|
|
create_inherent_data_providers: Arc<CIDP>,
|
|
aura_worker: Arc<Mutex<W>>,
|
|
slot_duration: SlotDuration,
|
|
_phantom: PhantomData<B>,
|
|
}
|
|
|
|
impl<B, CIDP, W> Clone for AuraConsensus<B, CIDP, W> {
|
|
fn clone(&self) -> Self {
|
|
Self {
|
|
create_inherent_data_providers: self.create_inherent_data_providers.clone(),
|
|
aura_worker: self.aura_worker.clone(),
|
|
slot_duration: self.slot_duration,
|
|
_phantom: PhantomData,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Parameters of [`AuraConsensus::build`].
|
|
#[deprecated = "Use the `aura::collators::basic` collator instead"]
|
|
pub struct BuildAuraConsensusParams<PF, BI, CIDP, Client, BS, SO> {
|
|
pub proposer_factory: PF,
|
|
pub create_inherent_data_providers: CIDP,
|
|
pub block_import: BI,
|
|
pub para_client: Arc<Client>,
|
|
pub backoff_authoring_blocks: Option<BS>,
|
|
pub sync_oracle: SO,
|
|
pub keystore: KeystorePtr,
|
|
pub force_authoring: bool,
|
|
pub slot_duration: SlotDuration,
|
|
pub telemetry: Option<TelemetryHandle>,
|
|
pub block_proposal_slot_portion: SlotProportion,
|
|
pub max_block_proposal_slot_portion: Option<SlotProportion>,
|
|
}
|
|
|
|
impl<B, CIDP> AuraConsensus<B, CIDP, ()>
|
|
where
|
|
B: BlockT,
|
|
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + 'static,
|
|
CIDP::InherentDataProviders: InherentDataProviderExt,
|
|
{
|
|
/// Create a new boxed instance of AURA consensus.
|
|
#[allow(deprecated)]
|
|
#[deprecated = "Use the `aura::collators::basic` collator instead"]
|
|
pub fn build<P, Client, BI, SO, PF, BS, Error>(
|
|
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<PF, BI, CIDP, Client, BS, SO>,
|
|
) -> Box<dyn ParachainConsensus<B>>
|
|
where
|
|
Client:
|
|
ProvideRuntimeApi<B> + BlockOf + AuxStore + HeaderBackend<B> + Send + Sync + 'static,
|
|
Client::Api: AuraApi<B, P::Public>,
|
|
BI: BlockImport<B> + ParachainBlockImportMarker + Send + Sync + 'static,
|
|
SO: SyncOracle + Send + Sync + Clone + 'static,
|
|
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + Sync + 'static,
|
|
PF: Environment<B, Error = Error> + Send + Sync + 'static,
|
|
PF::Proposer: Proposer<
|
|
B,
|
|
Error = Error,
|
|
ProofRecording = EnableProofRecording,
|
|
Proof = <EnableProofRecording as ProofRecording>::Proof,
|
|
>,
|
|
Error: std::error::Error + Send + From<sp_consensus::Error> + 'static,
|
|
P: Pair + 'static,
|
|
P::Public: AppPublic + Member + Codec,
|
|
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
|
|
{
|
|
let worker = sc_consensus_aura::build_aura_worker::<P, _, _, _, _, _, _, _, _>(
|
|
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<B, CIDP, W> AuraConsensus<B, CIDP, W>
|
|
where
|
|
B: BlockT,
|
|
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + '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<CIDP::InherentDataProviders> {
|
|
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<B, CIDP, W> ParachainConsensus<B> for AuraConsensus<B, CIDP, W>
|
|
where
|
|
B: BlockT,
|
|
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + Send + Sync + 'static,
|
|
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
|
|
W: SimpleSlotWorker<B> + Send + Sync,
|
|
W::Proposer: Proposer<B, Proof = <EnableProofRecording as ProofRecording>::Proof>,
|
|
{
|
|
async fn produce_candidate(
|
|
&mut self,
|
|
parent: &B::Header,
|
|
relay_parent: PHash,
|
|
validation_data: &PersistedValidationData,
|
|
) -> Option<ParachainCandidate<B>> {
|
|
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 })
|
|
}
|
|
}
|