mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 09:51:02 +00:00
Some changes for Statemint (#448)
* Make Aura and relay chain verifier buildable * AHHH * Ahhh2 * Ahhh3 * Move `ParachainBlockImport` * Updates because of Substrate * Revert "AHHH" This reverts commit 3f7c84327e1036ed71a8e2bd30f6416d32bae5a2. * Fix warning
This commit is contained in:
@@ -17,8 +17,10 @@
|
||||
//! Parachain specific wrapper for the AuRa import queue.
|
||||
|
||||
use codec::Codec;
|
||||
use sc_client_api::{backend::AuxStore, BlockOf};
|
||||
use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
|
||||
use sc_consensus_aura::AuraVerifier;
|
||||
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, ProvideCache};
|
||||
@@ -31,16 +33,15 @@ use sp_inherents::CreateInherentDataProviders;
|
||||
use sp_runtime::traits::{Block as BlockT, DigestItemFor};
|
||||
use std::{fmt::Debug, hash::Hash, sync::Arc};
|
||||
use substrate_prometheus_endpoint::Registry;
|
||||
use sc_telemetry::TelemetryHandle;
|
||||
|
||||
/// Parameters of [`import_queue`].
|
||||
pub struct ImportQueueParams<'a, I, C, IDP, S, CAW> {
|
||||
pub struct ImportQueueParams<'a, I, C, CIDP, S, CAW> {
|
||||
/// The block import to use.
|
||||
pub block_import: I,
|
||||
/// The client to interact with the chain.
|
||||
pub client: Arc<C>,
|
||||
/// The inherent data providers, to create the inherent data.
|
||||
pub create_inherent_data_providers: IDP,
|
||||
pub create_inherent_data_providers: CIDP,
|
||||
/// The spawner to spawn background tasks.
|
||||
pub spawner: &'a S,
|
||||
/// The prometheus registry.
|
||||
@@ -52,7 +53,7 @@ pub struct ImportQueueParams<'a, I, C, IDP, S, CAW> {
|
||||
}
|
||||
|
||||
/// Start an import queue for the Aura consensus algorithm.
|
||||
pub fn import_queue<'a, P, Block, I, C, S, CAW, IDP>(
|
||||
pub fn import_queue<'a, P, Block, I, C, S, CAW, CIDP>(
|
||||
ImportQueueParams {
|
||||
block_import,
|
||||
client,
|
||||
@@ -61,7 +62,7 @@ pub fn import_queue<'a, P, Block, I, C, S, CAW, IDP>(
|
||||
registry,
|
||||
can_author_with,
|
||||
telemetry,
|
||||
}: ImportQueueParams<'a, I, C, IDP, S, CAW>,
|
||||
}: ImportQueueParams<'a, I, C, CIDP, S, CAW>,
|
||||
) -> Result<DefaultImportQueue<Block, C>, sp_consensus::Error>
|
||||
where
|
||||
Block: BlockT,
|
||||
@@ -73,6 +74,7 @@ where
|
||||
+ Send
|
||||
+ Sync
|
||||
+ AuxStore
|
||||
+ UsageProvider<Block>
|
||||
+ HeaderBackend<Block>,
|
||||
I: BlockImport<Block, Error = ConsensusError, Transaction = sp_api::TransactionFor<C, Block>>
|
||||
+ Send
|
||||
@@ -84,11 +86,11 @@ where
|
||||
P::Signature: Codec,
|
||||
S: sp_core::traits::SpawnEssentialNamed,
|
||||
CAW: CanAuthorWith<Block> + Send + Sync + 'static,
|
||||
IDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
|
||||
IDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
|
||||
CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
|
||||
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
|
||||
{
|
||||
sc_consensus_aura::import_queue::<P, _, _, _, _, _, _>(sc_consensus_aura::ImportQueueParams {
|
||||
block_import: crate::ParachainBlockImport(block_import),
|
||||
block_import: cumulus_client_consensus_common::ParachainBlockImport::new(block_import),
|
||||
justification_import: None,
|
||||
client,
|
||||
create_inherent_data_providers,
|
||||
@@ -99,3 +101,33 @@ where
|
||||
telemetry,
|
||||
})
|
||||
}
|
||||
|
||||
/// Parameters of [`build_verifier`].
|
||||
pub struct BuildVerifierParams<C, CIDP, CAW> {
|
||||
/// The client to interact with the chain.
|
||||
pub client: Arc<C>,
|
||||
/// The inherent data providers, to create the inherent data.
|
||||
pub create_inherent_data_providers: CIDP,
|
||||
/// Can we author with the current node?
|
||||
pub can_author_with: CAW,
|
||||
/// The telemetry handle.
|
||||
pub telemetry: Option<TelemetryHandle>,
|
||||
}
|
||||
|
||||
/// Build the [`AuraVerifier`].
|
||||
pub fn build_verifier<P, C, CIDP, CAW>(
|
||||
BuildVerifierParams {
|
||||
client,
|
||||
create_inherent_data_providers,
|
||||
can_author_with,
|
||||
telemetry,
|
||||
}: BuildVerifierParams<C, CIDP, CAW>,
|
||||
) -> AuraVerifier<C, P, CAW, CIDP> {
|
||||
sc_consensus_aura::build_verifier(sc_consensus_aura::BuildVerifierParams {
|
||||
client,
|
||||
create_inherent_data_providers,
|
||||
can_author_with,
|
||||
telemetry,
|
||||
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
//! For more information about AuRa, the Substrate crate should be checked.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use cumulus_client_consensus_common::{ParachainCandidate, ParachainConsensus};
|
||||
use cumulus_client_consensus_common::{
|
||||
ParachainBlockImport, ParachainCandidate, ParachainConsensus,
|
||||
};
|
||||
use cumulus_primitives_core::{
|
||||
relay_chain::v1::{Block as PBlock, Hash as PHash, ParachainHost},
|
||||
PersistedValidationData,
|
||||
@@ -48,9 +50,10 @@ use std::{convert::TryFrom, hash::Hash, marker::PhantomData, sync::Arc};
|
||||
|
||||
mod import_queue;
|
||||
|
||||
pub use import_queue::{import_queue, ImportQueueParams};
|
||||
pub use import_queue::{build_verifier, import_queue, BuildVerifierParams, ImportQueueParams};
|
||||
pub use sc_consensus_aura::{
|
||||
slot_duration, AuraBlockImport, BuildAuraWorkerParams, SlotDuration, SlotProportion,
|
||||
slot_duration, AuraVerifier, BuildAuraWorkerParams, SlotDuration,
|
||||
SlotProportion,
|
||||
};
|
||||
pub use sc_consensus_slots::InherentDataProviderExt;
|
||||
|
||||
@@ -137,7 +140,7 @@ where
|
||||
let worker =
|
||||
sc_consensus_aura::build_aura_worker::<P, _, _, _, _, _, _, _>(BuildAuraWorkerParams {
|
||||
client: para_client,
|
||||
block_import: ParachainBlockImport(block_import),
|
||||
block_import: ParachainBlockImport::new(block_import),
|
||||
proposer_factory,
|
||||
sync_oracle,
|
||||
force_authoring,
|
||||
@@ -234,43 +237,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Parachain specific block import.
|
||||
///
|
||||
/// This is used to set `block_import_params.fork_choice` to `false` as long as the block origin is
|
||||
/// not `NetworkInitialSync`. The best block for parachains is determined by the relay chain. Meaning
|
||||
/// we will update the best block, as it is included by the relay-chain.
|
||||
struct ParachainBlockImport<I>(I);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Block, I> BlockImport<Block> for ParachainBlockImport<I>
|
||||
where
|
||||
Block: BlockT,
|
||||
I: BlockImport<Block> + Send,
|
||||
{
|
||||
type Error = I::Error;
|
||||
type Transaction = I::Transaction;
|
||||
|
||||
async fn check_block(
|
||||
&mut self,
|
||||
block: sp_consensus::BlockCheckParams<Block>,
|
||||
) -> Result<sp_consensus::ImportResult, Self::Error> {
|
||||
self.0.check_block(block).await
|
||||
}
|
||||
|
||||
async fn import_block(
|
||||
&mut self,
|
||||
mut block_import_params: sp_consensus::BlockImportParams<Block, Self::Transaction>,
|
||||
cache: std::collections::HashMap<sp_consensus::import_queue::CacheKeyId, Vec<u8>>,
|
||||
) -> Result<sp_consensus::ImportResult, Self::Error> {
|
||||
// Best block is determined by the relay chain, or if we are doing the intial sync
|
||||
// we import all blocks as new best.
|
||||
block_import_params.fork_choice = Some(sp_consensus::ForkChoiceStrategy::Custom(
|
||||
block_import_params.origin == sp_consensus::BlockOrigin::NetworkInitialSync,
|
||||
));
|
||||
self.0.import_block(block_import_params, cache).await
|
||||
}
|
||||
}
|
||||
|
||||
/// Paramaters of [`build_aura_consensus`].
|
||||
pub struct BuildAuraConsensusParams<PF, BI, RBackend, CIDP, Client, BS, SO> {
|
||||
pub proposer_factory: PF,
|
||||
|
||||
Reference in New Issue
Block a user