,
- CIDP: CreateInherentDataProviders,
+ CIDP: CreateInherentDataProviders + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt,
{
- /// Create a new instance of AURA consensus.
- pub fn new(
- para_client: Arc,
- block_import: BI,
- sync_oracle: SO,
- proposer_factory: PF,
- force_authoring: bool,
- backoff_authoring_blocks: Option,
- keystore: SyncCryptoStorePtr,
- create_inherent_data_providers: CIDP,
- polkadot_client: Arc,
- polkadot_backend: Arc,
- slot_duration: SlotDuration,
- telemetry: Option,
- block_proposal_slot_portion: SlotProportion,
- max_block_proposal_slot_portion: Option,
- ) -> Self
+ /// 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
- + ProvideCache
- + AuxStore
- + HeaderBackend
- + Send
- + Sync
- + 'static,
+ Client:
+ ProvideRuntimeApi + BlockOf + AuxStore + HeaderBackend + Send + Sync + 'static,
Client::Api: AuraApi,
BI: BlockImport> + Send + Sync + 'static,
SO: SyncOracle + Send + Sync + Clone + 'static,
@@ -154,13 +138,11 @@ where
},
);
- Self {
+ Box::new(Self {
create_inherent_data_providers: Arc::new(create_inherent_data_providers),
- relay_chain_backend: polkadot_backend,
- relay_chain_client: polkadot_client,
aura_worker: Arc::new(Mutex::new(worker)),
slot_duration,
- }
+ })
}
/// Create the inherent data.
@@ -200,13 +182,10 @@ where
}
#[async_trait::async_trait]
-impl ParachainConsensus for AuraConsensus
+impl ParachainConsensus for AuraConsensus
where
B: BlockT,
- RClient: ProvideRuntimeApi + Send + Sync,
- RClient::Api: ParachainHost,
- RBackend: Backend,
- CIDP: CreateInherentDataProviders + Send + Sync,
+ CIDP: CreateInherentDataProviders + Send + Sync + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
{
async fn produce_candidate(
@@ -238,12 +217,10 @@ where
}
/// Paramaters of [`build_aura_consensus`].
-pub struct BuildAuraConsensusParams {
+pub struct BuildAuraConsensusParams {
pub proposer_factory: PF,
pub create_inherent_data_providers: CIDP,
pub block_import: BI,
- pub relay_chain_client: polkadot_client::Client,
- pub relay_chain_backend: Arc,
pub para_client: Arc,
pub backoff_authoring_blocks: Option,
pub sync_oracle: SO,
@@ -254,250 +231,3 @@ pub struct BuildAuraConsensusParams {
pub block_proposal_slot_portion: SlotProportion,
pub max_block_proposal_slot_portion: Option,
}
-
-/// Build the [`AuraConsensus`].
-///
-/// Returns a boxed [`ParachainConsensus`].
-pub fn build_aura_consensus(
- BuildAuraConsensusParams {
- proposer_factory,
- create_inherent_data_providers,
- block_import,
- relay_chain_client,
- relay_chain_backend,
- 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
- Block: BlockT,
- RBackend: Backend + 'static,
- CIDP: CreateInherentDataProviders
- + Send
- + Sync
- + 'static,
- CIDP::InherentDataProviders: InherentDataProviderExt + Send,
- Client: ProvideRuntimeApi
- + BlockOf
- + ProvideCache
- + AuxStore
- + HeaderBackend
- + Send
- + Sync
- + 'static,
- Client::Api: AuraApi,
- BI: BlockImport>
- + Send
- + Sync
- + 'static,
- SO: SyncOracle + Send + Sync + Clone + 'static,
- BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static,
- PF: Environment + Send + Sync + 'static,
- PF::Proposer: Proposer<
- Block,
- 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,
-{
- AuraConsensusBuilder::::new(
- proposer_factory,
- block_import,
- create_inherent_data_providers,
- relay_chain_client,
- relay_chain_backend,
- para_client,
- backoff_authoring_blocks,
- sync_oracle,
- force_authoring,
- keystore,
- slot_duration,
- telemetry,
- block_proposal_slot_portion,
- max_block_proposal_slot_portion,
- )
- .build()
-}
-
-/// Aura consensus builder.
-///
-/// Builds a [`AuraConsensus`] for a parachain. As this requires
-/// a concrete relay chain client instance, the builder takes a [`polkadot_client::Client`]
-/// that wraps this concrete instance. By using [`polkadot_client::ExecuteWithClient`]
-/// the builder gets access to this concrete instance.
-struct AuraConsensusBuilder
{
- _phantom: PhantomData<(Block, Error, P)>,
- proposer_factory: PF,
- create_inherent_data_providers: CIDP,
- block_import: BI,
- relay_chain_backend: Arc,
- relay_chain_client: polkadot_client::Client,
- para_client: Arc,
- backoff_authoring_blocks: Option,
- sync_oracle: SO,
- force_authoring: bool,
- keystore: SyncCryptoStorePtr,
- slot_duration: SlotDuration,
- telemetry: Option,
- block_proposal_slot_portion: SlotProportion,
- max_block_proposal_slot_portion: Option,
-}
-
-impl
- AuraConsensusBuilder
-where
- Block: BlockT,
- RBackend: Backend + 'static,
- CIDP: CreateInherentDataProviders
- + Send
- + Sync
- + 'static,
- CIDP::InherentDataProviders: InherentDataProviderExt + Send,
- Client: ProvideRuntimeApi
- + BlockOf
- + ProvideCache
- + AuxStore
- + HeaderBackend
- + Send
- + Sync
- + 'static,
- Client::Api: AuraApi,
- BI: BlockImport>
- + Send
- + Sync
- + 'static,
- SO: SyncOracle + Send + Sync + Clone + 'static,
- BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static,
- PF: Environment + Send + Sync + 'static,
- PF::Proposer: Proposer<
- Block,
- 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,
-{
- /// Create a new instance of the builder.
- fn new(
- proposer_factory: PF,
- block_import: BI,
- create_inherent_data_providers: CIDP,
- relay_chain_client: polkadot_client::Client,
- relay_chain_backend: Arc,
- para_client: Arc,
- backoff_authoring_blocks: Option,
- sync_oracle: SO,
- force_authoring: bool,
- keystore: SyncCryptoStorePtr,
- slot_duration: SlotDuration,
- telemetry: Option,
- block_proposal_slot_portion: SlotProportion,
- max_block_proposal_slot_portion: Option,
- ) -> Self {
- Self {
- _phantom: PhantomData,
- proposer_factory,
- block_import,
- create_inherent_data_providers,
- relay_chain_backend,
- relay_chain_client,
- para_client,
- backoff_authoring_blocks,
- sync_oracle,
- force_authoring,
- keystore,
- slot_duration,
- telemetry,
- block_proposal_slot_portion,
- max_block_proposal_slot_portion,
- }
- }
-
- /// Build the relay chain consensus.
- fn build(self) -> Box> {
- self.relay_chain_client.clone().execute_with(self)
- }
-}
-
-impl polkadot_client::ExecuteWithClient
- for AuraConsensusBuilder
-where
- Block: BlockT,
- RBackend: Backend + 'static,
- CIDP: CreateInherentDataProviders
- + Send
- + Sync
- + 'static,
- CIDP::InherentDataProviders: InherentDataProviderExt + Send,
- Client: ProvideRuntimeApi
- + BlockOf
- + ProvideCache
- + AuxStore
- + HeaderBackend
- + Send
- + Sync
- + 'static,
- Client::Api: AuraApi,
- BI: BlockImport>
- + Send
- + Sync
- + 'static,
- SO: SyncOracle + Send + Sync + Clone + 'static,
- BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static,
- PF: Environment + Send + Sync + 'static,
- PF::Proposer: Proposer<
- Block,
- 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,
-{
- type Output = Box>;
-
- fn execute_with_client(self, client: Arc) -> Self::Output
- where
- >::StateBackend: sp_api::StateBackend>,
- PBackend: Backend,
- PBackend::State: sp_api::StateBackend,
- Api: polkadot_client::RuntimeApiCollection,
- PClient: polkadot_client::AbstractClient + 'static,
- {
- Box::new(AuraConsensus::new::(
- self.para_client,
- self.block_import,
- self.sync_oracle,
- self.proposer_factory,
- self.force_authoring,
- self.backoff_authoring_blocks,
- self.keystore,
- self.create_inherent_data_providers,
- client.clone(),
- self.relay_chain_backend,
- self.slot_duration,
- self.telemetry,
- self.block_proposal_slot_portion,
- self.max_block_proposal_slot_portion,
- ))
- }
-}
diff --git a/client/consensus/common/Cargo.toml b/client/consensus/common/Cargo.toml
index e8a66b3f25..057f0b3496 100644
--- a/client/consensus/common/Cargo.toml
+++ b/client/consensus/common/Cargo.toml
@@ -3,7 +3,7 @@ name = "cumulus-client-consensus-common"
description = "Cumulus specific common consensus implementations"
version = "0.1.0"
authors = ["Parity Technologies "]
-edition = "2018"
+edition = "2021"
[dependencies]
# Substrate deps
@@ -18,6 +18,9 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
# Polkadot deps
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
+# Cumulus deps
+cumulus-relay-chain-interface = { path = "../../relay-chain-interface" }
+
# Other deps
futures = { version = "0.3.8", features = ["compat"] }
codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ] }
diff --git a/client/consensus/common/src/parachain_consensus.rs b/client/consensus/common/src/parachain_consensus.rs
index 47a5b4dbaa..224e3e5fd9 100644
--- a/client/consensus/common/src/parachain_consensus.rs
+++ b/client/consensus/common/src/parachain_consensus.rs
@@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see .
+use cumulus_relay_chain_interface::RelayChainInterface;
use sc_client_api::{
Backend, BlockBackend, BlockImportNotification, BlockchainEvents, Finalizer, UsageProvider,
};
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy};
-use sp_api::ProvideRuntimeApi;
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use sp_consensus::{BlockOrigin, BlockStatus};
use sp_runtime::{
@@ -26,9 +26,7 @@ use sp_runtime::{
traits::{Block as BlockT, Header as HeaderT},
};
-use polkadot_primitives::v1::{
- Block as PBlock, Id as ParaId, OccupiedCoreAssumption, ParachainHost,
-};
+use polkadot_primitives::v1::{Block as PBlock, Id as ParaId, OccupiedCoreAssumption};
use codec::Decode;
use futures::{future, select, FutureExt, Stream, StreamExt};
@@ -370,10 +368,9 @@ where
}
}
-impl RelaychainClient for Arc
+impl RelaychainClient for RCInterface
where
- T: sc_client_api::BlockchainEvents + ProvideRuntimeApi + 'static + Send + Sync,
- >::Api: ParachainHost,
+ RCInterface: RelayChainInterface + Clone + 'static,
{
type Error = ClientError;
@@ -410,8 +407,7 @@ where
at: &BlockId,
para_id: ParaId,
) -> ClientResult