mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Companion for paritytech/substrate#12764 (#1930)
* Companion for paritytech/substrate#12764 * Remove `async-trait` * Fix trait * update lockfile for {"substrate", "polkadot"} Co-authored-by: parity-processbot <>
This commit is contained in:
+10
-52
@@ -25,23 +25,16 @@ use polkadot_primitives::v2::CollatorPair;
|
||||
use sc_client_api::{
|
||||
Backend as BackendT, BlockBackend, BlockchainEvents, Finalizer, UsageProvider,
|
||||
};
|
||||
use sc_consensus::{
|
||||
import_queue::{ImportQueue, IncomingBlock, Link, RuntimeOrigin},
|
||||
BlockImport,
|
||||
};
|
||||
use sc_consensus::{import_queue::ImportQueueService, BlockImport};
|
||||
use sc_service::{Configuration, TaskManager};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_core::traits::SpawnNamed;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
Justifications,
|
||||
};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
/// Parameters given to [`start_collator`].
|
||||
pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawner, IQ> {
|
||||
pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawner> {
|
||||
pub block_status: Arc<BS>,
|
||||
pub client: Arc<Client>,
|
||||
pub announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
|
||||
@@ -50,7 +43,7 @@ pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawn
|
||||
pub relay_chain_interface: RCInterface,
|
||||
pub task_manager: &'a mut TaskManager,
|
||||
pub parachain_consensus: Box<dyn ParachainConsensus<Block>>,
|
||||
pub import_queue: IQ,
|
||||
pub import_queue: Box<dyn ImportQueueService<Block>>,
|
||||
pub collator_key: CollatorPair,
|
||||
pub relay_chain_slot_duration: Duration,
|
||||
}
|
||||
@@ -60,7 +53,7 @@ pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, RCInterface, Spawn
|
||||
/// 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, BS, Client, Backend, RCInterface, Spawner, IQ>(
|
||||
pub async fn start_collator<'a, Block, BS, Client, Backend, RCInterface, Spawner>(
|
||||
StartCollatorParams {
|
||||
block_status,
|
||||
client,
|
||||
@@ -73,7 +66,7 @@ pub async fn start_collator<'a, Block, BS, Client, Backend, RCInterface, Spawner
|
||||
import_queue,
|
||||
collator_key,
|
||||
relay_chain_slot_duration,
|
||||
}: StartCollatorParams<'a, Block, BS, Client, RCInterface, Spawner, IQ>,
|
||||
}: StartCollatorParams<'a, Block, BS, Client, RCInterface, Spawner>,
|
||||
) -> sc_service::error::Result<()>
|
||||
where
|
||||
Block: BlockT,
|
||||
@@ -92,7 +85,6 @@ where
|
||||
Spawner: SpawnNamed + Clone + Send + Sync + 'static,
|
||||
RCInterface: RelayChainInterface + Clone + 'static,
|
||||
Backend: BackendT<Block> + 'static,
|
||||
IQ: ImportQueue<Block> + 'static,
|
||||
{
|
||||
let consensus = cumulus_client_consensus_common::run_parachain_consensus(
|
||||
para_id,
|
||||
@@ -139,21 +131,21 @@ where
|
||||
}
|
||||
|
||||
/// Parameters given to [`start_full_node`].
|
||||
pub struct StartFullNodeParams<'a, Block: BlockT, Client, RCInterface, IQ> {
|
||||
pub struct StartFullNodeParams<'a, Block: BlockT, Client, RCInterface> {
|
||||
pub para_id: ParaId,
|
||||
pub client: Arc<Client>,
|
||||
pub relay_chain_interface: RCInterface,
|
||||
pub task_manager: &'a mut TaskManager,
|
||||
pub announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
|
||||
pub relay_chain_slot_duration: Duration,
|
||||
pub import_queue: IQ,
|
||||
pub import_queue: Box<dyn ImportQueueService<Block>>,
|
||||
}
|
||||
|
||||
/// Start a full node for a parachain.
|
||||
///
|
||||
/// A full node will only sync the given parachain and will follow the
|
||||
/// tip of the chain.
|
||||
pub fn start_full_node<Block, Client, Backend, RCInterface, IQ>(
|
||||
pub fn start_full_node<Block, Client, Backend, RCInterface>(
|
||||
StartFullNodeParams {
|
||||
client,
|
||||
announce_block,
|
||||
@@ -162,7 +154,7 @@ pub fn start_full_node<Block, Client, Backend, RCInterface, IQ>(
|
||||
para_id,
|
||||
relay_chain_slot_duration,
|
||||
import_queue,
|
||||
}: StartFullNodeParams<Block, Client, RCInterface, IQ>,
|
||||
}: StartFullNodeParams<Block, Client, RCInterface>,
|
||||
) -> sc_service::error::Result<()>
|
||||
where
|
||||
Block: BlockT,
|
||||
@@ -176,7 +168,6 @@ where
|
||||
for<'a> &'a Client: BlockImport<Block>,
|
||||
Backend: BackendT<Block> + 'static,
|
||||
RCInterface: RelayChainInterface + Clone + 'static,
|
||||
IQ: ImportQueue<Block> + 'static,
|
||||
{
|
||||
let consensus = cumulus_client_consensus_common::run_parachain_consensus(
|
||||
para_id,
|
||||
@@ -226,36 +217,3 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration
|
||||
|
||||
parachain_config
|
||||
}
|
||||
|
||||
/// A shared import queue
|
||||
///
|
||||
/// This is basically a hack until the Substrate side is implemented properly.
|
||||
#[derive(Clone)]
|
||||
pub struct SharedImportQueue<Block: BlockT>(Arc<parking_lot::Mutex<dyn ImportQueue<Block>>>);
|
||||
|
||||
impl<Block: BlockT> SharedImportQueue<Block> {
|
||||
/// Create a new instance of the shared import queue.
|
||||
pub fn new<IQ: ImportQueue<Block> + 'static>(import_queue: IQ) -> Self {
|
||||
Self(Arc::new(parking_lot::Mutex::new(import_queue)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT> ImportQueue<Block> for SharedImportQueue<Block> {
|
||||
fn import_blocks(&mut self, origin: BlockOrigin, blocks: Vec<IncomingBlock<Block>>) {
|
||||
self.0.lock().import_blocks(origin, blocks)
|
||||
}
|
||||
|
||||
fn import_justifications(
|
||||
&mut self,
|
||||
who: RuntimeOrigin,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
justifications: Justifications,
|
||||
) {
|
||||
self.0.lock().import_justifications(who, hash, number, justifications)
|
||||
}
|
||||
|
||||
fn poll_actions(&mut self, cx: &mut std::task::Context, link: &mut dyn Link<Block>) {
|
||||
self.0.lock().poll_actions(cx, link)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user