mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Plumb polkadot backend into cumulus-collator (#269)
* The problem in the nutshell * Make it compile * make tests pass * Update the parachain-upgrade module * Fix collator tests Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -23,7 +23,7 @@ use futures::{Future, FutureExt};
|
||||
use polkadot_overseer::OverseerHandler;
|
||||
use polkadot_primitives::v1::{Block as PBlock, CollatorId, CollatorPair};
|
||||
use polkadot_service::{AbstractClient, Client as PClient, ClientHandle, RuntimeApiCollection};
|
||||
use sc_client_api::{Backend as BackendT, BlockBackend, Finalizer, UsageProvider};
|
||||
use sc_client_api::{Backend as BackendT, BlockBackend, Finalizer, UsageProvider, StateBackend};
|
||||
use sc_service::{error::Result as ServiceResult, Configuration, Role, TaskManager};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus::{BlockImport, Environment, Error as ConsensusError, Proposer};
|
||||
@@ -36,7 +36,7 @@ use std::{marker::PhantomData, sync::Arc};
|
||||
type PFullNode<C> = polkadot_service::NewFull<C>;
|
||||
|
||||
/// Parameters given to [`start_collator`].
|
||||
pub struct StartCollatorParams<'a, Block: BlockT, PF, BI, BS, Client, Backend, Spawner, PClient> {
|
||||
pub struct StartCollatorParams<'a, Block: BlockT, PF, BI, BS, Client, Backend, Spawner, PClient, PBackend> {
|
||||
pub proposer_factory: PF,
|
||||
pub inherent_data_providers: InherentDataProviders,
|
||||
pub backend: Arc<Backend>,
|
||||
@@ -49,6 +49,7 @@ pub struct StartCollatorParams<'a, Block: BlockT, PF, BI, BS, Client, Backend, S
|
||||
pub collator_key: CollatorPair,
|
||||
pub polkadot_full_node: PFullNode<PClient>,
|
||||
pub task_manager: &'a mut TaskManager,
|
||||
pub polkadot_backend: Arc<PBackend>,
|
||||
}
|
||||
|
||||
/// Start a collator node for a parachain.
|
||||
@@ -56,7 +57,7 @@ pub struct StartCollatorParams<'a, Block: BlockT, PF, BI, BS, Client, Backend, S
|
||||
/// A collator is similar to a validator in a normal blockchain.
|
||||
/// It is responsible for producing blocks and sending the blocks to a
|
||||
/// parachain validator for validation and inclusion into the relay chain.
|
||||
pub async fn start_collator<'a, Block, PF, BI, BS, Client, Backend, Spawner, PClient>(
|
||||
pub async fn start_collator<'a, Block, PF, BI, BS, Client, Backend, Spawner, PClient, PBackend>(
|
||||
StartCollatorParams {
|
||||
proposer_factory,
|
||||
inherent_data_providers,
|
||||
@@ -70,7 +71,8 @@ pub async fn start_collator<'a, Block, PF, BI, BS, Client, Backend, Spawner, PCl
|
||||
collator_key,
|
||||
polkadot_full_node,
|
||||
task_manager,
|
||||
}: StartCollatorParams<'a, Block, PF, BI, BS, Client, Backend, Spawner, PClient>,
|
||||
polkadot_backend,
|
||||
}: StartCollatorParams<'a, Block, PF, BI, BS, Client, Backend, Spawner, PClient, PBackend>,
|
||||
) -> sc_service::error::Result<()>
|
||||
where
|
||||
Block: BlockT,
|
||||
@@ -94,6 +96,8 @@ where
|
||||
Backend: BackendT<Block> + 'static,
|
||||
Spawner: SpawnNamed + Clone + Send + Sync + 'static,
|
||||
PClient: ClientHandle,
|
||||
PBackend: BackendT<PBlock> + 'static,
|
||||
PBackend::State: StateBackend<BlakeTwo256>,
|
||||
{
|
||||
polkadot_full_node
|
||||
.client
|
||||
@@ -111,6 +115,7 @@ where
|
||||
collator_key,
|
||||
block_import,
|
||||
block_status,
|
||||
polkadot_backend,
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -119,7 +124,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct StartCollator<Block: BlockT, Client, Backend, PF, BI, BS, Spawner> {
|
||||
struct StartCollator<Block: BlockT, Client, Backend, PF, BI, BS, Spawner, PBackend> {
|
||||
proposer_factory: PF,
|
||||
inherent_data_providers: InherentDataProviders,
|
||||
backend: Arc<Backend>,
|
||||
@@ -131,10 +136,11 @@ struct StartCollator<Block: BlockT, Client, Backend, PF, BI, BS, Spawner> {
|
||||
spawner: Spawner,
|
||||
para_id: ParaId,
|
||||
collator_key: CollatorPair,
|
||||
polkadot_backend: Arc<PBackend>,
|
||||
}
|
||||
|
||||
impl<Block, Client, Backend, PF, BI, BS, Spawner> polkadot_service::ExecuteWithClient
|
||||
for StartCollator<Block, Client, Backend, PF, BI, BS, Spawner>
|
||||
impl<Block, Client, Backend, PF, BI, BS, Spawner, PBackend2> polkadot_service::ExecuteWithClient
|
||||
for StartCollator<Block, Client, Backend, PF, BI, BS, Spawner, PBackend2>
|
||||
where
|
||||
Block: BlockT,
|
||||
PF: Environment<Block> + Send + 'static,
|
||||
@@ -156,6 +162,8 @@ where
|
||||
for<'b> &'b Client: BlockImport<Block>,
|
||||
Backend: BackendT<Block> + 'static,
|
||||
Spawner: SpawnNamed + Clone + Send + Sync + 'static,
|
||||
PBackend2: sc_client_api::Backend<PBlock> + 'static,
|
||||
PBackend2::State: sp_api::StateBackend<BlakeTwo256>,
|
||||
{
|
||||
type Output = std::pin::Pin<Box<dyn Future<Output = ServiceResult<()>>>>;
|
||||
|
||||
@@ -181,6 +189,7 @@ where
|
||||
para_id: self.para_id,
|
||||
key: self.collator_key,
|
||||
polkadot_client: client,
|
||||
polkadot_backend: self.polkadot_backend,
|
||||
})
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
|
||||
Reference in New Issue
Block a user