mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-17 12:25:42 +00:00
Collator-side of collator protocol (#351)
* skeleton of collators object * awaiting and handling collations. rename `collators` to CollationPool * add some tests * add tests * implement Collators trait for ConsensusNetwork * plug collators into main polkadot-network * ignore collator role message * add a couple more tests * garbage collection for collations * extract session-key tracking from consensus * add local_collations.rs * finish polish of local_collations * integrate local_collations into network layer * introduce API for adding local collations * mostly finish collator implementation pending service fix * Specialized network() * push collations to the network * grumbles * substrate-service has custom configuration * initialize network in collator mode as necessary
This commit is contained in:
committed by
GitHub
parent
8bcfb16fad
commit
927cb59aaf
@@ -80,6 +80,9 @@ pub type FactoryGenesis<F> = <F as ServiceFactory>::Genesis;
|
||||
/// `Block` type for a factory.
|
||||
pub type FactoryBlock<F> = <F as ServiceFactory>::Block;
|
||||
|
||||
/// Full `Configuration` type for a factory.
|
||||
pub type FactoryFullConfiguration<F> = Configuration<<F as ServiceFactory>::Configuration, FactoryGenesis<F>>;
|
||||
|
||||
/// Client type for `Components`.
|
||||
pub type ComponentClient<C> = Client<
|
||||
<C as Components>::Backend,
|
||||
@@ -102,7 +105,7 @@ pub trait ServiceFactory {
|
||||
/// Block type.
|
||||
type Block: BlockT;
|
||||
/// Network protocol extensions.
|
||||
type NetworkProtocol: network::specialization::Specialization<Self::Block> + Default;
|
||||
type NetworkProtocol: network::specialization::Specialization<Self::Block>;
|
||||
/// Chain runtime.
|
||||
type RuntimeDispatch: NativeExecutionDispatch + Send + Sync + 'static;
|
||||
/// Extrinsic pool type for the full client.
|
||||
@@ -111,6 +114,9 @@ pub trait ServiceFactory {
|
||||
type LightExtrinsicPool: ExtrinsicPool<Self::Block>;
|
||||
/// Genesis configuration for the runtime.
|
||||
type Genesis: RuntimeGenesis;
|
||||
/// Other configuration for service members.
|
||||
type Configuration: Default;
|
||||
|
||||
/// Network protocol id.
|
||||
const NETWORK_PROTOCOL_ID: network::ProtocolId;
|
||||
|
||||
@@ -121,6 +127,10 @@ pub trait ServiceFactory {
|
||||
/// Extrinsic pool constructor for the light client.
|
||||
fn build_light_extrinsic_pool(config: ExtrinsicPoolOptions, client: Arc<LightClient<Self>>)
|
||||
-> Result<Self::LightExtrinsicPool, error::Error>;
|
||||
|
||||
/// Build network protocol.
|
||||
fn build_network_protocol(config: &FactoryFullConfiguration<Self>)
|
||||
-> Result<Self::NetworkProtocol, error::Error>;
|
||||
}
|
||||
|
||||
// TODO: move this to substrate-extrinsic-pool
|
||||
@@ -147,7 +157,7 @@ pub trait Components {
|
||||
|
||||
/// Create client.
|
||||
fn build_client(
|
||||
config: &Configuration<FactoryGenesis<Self::Factory>>,
|
||||
config: &FactoryFullConfiguration<Self::Factory>,
|
||||
executor: CodeExecutor<Self::Factory>,
|
||||
)
|
||||
-> Result<(
|
||||
@@ -172,7 +182,7 @@ impl<Factory: ServiceFactory> Components for FullComponents<Factory> {
|
||||
type ExtrinsicPool = <Factory as ServiceFactory>::FullExtrinsicPool;
|
||||
|
||||
fn build_client(
|
||||
config: &Configuration<FactoryGenesis<Self::Factory>>,
|
||||
config: &FactoryFullConfiguration<Factory>,
|
||||
executor: CodeExecutor<Self::Factory>,
|
||||
)
|
||||
-> Result<(
|
||||
@@ -207,7 +217,7 @@ impl<Factory: ServiceFactory> Components for LightComponents<Factory> {
|
||||
type ExtrinsicPool = <Factory as ServiceFactory>::LightExtrinsicPool;
|
||||
|
||||
fn build_client(
|
||||
config: &Configuration<FactoryGenesis<Self::Factory>>,
|
||||
config: &FactoryFullConfiguration<Factory>,
|
||||
executor: CodeExecutor<Self::Factory>,
|
||||
)
|
||||
-> Result<(
|
||||
|
||||
@@ -26,7 +26,7 @@ use runtime_primitives::BuildStorage;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
|
||||
/// Service configuration.
|
||||
pub struct Configuration<G: Serialize + DeserializeOwned + BuildStorage> {
|
||||
pub struct Configuration<C, G: Serialize + DeserializeOwned + BuildStorage> {
|
||||
/// Node roles.
|
||||
pub roles: Roles,
|
||||
/// Extrinsic pool configuration.
|
||||
@@ -43,6 +43,8 @@ pub struct Configuration<G: Serialize + DeserializeOwned + BuildStorage> {
|
||||
pub keys: Vec<String>,
|
||||
/// Chain configuration.
|
||||
pub chain_spec: ChainSpec<G>,
|
||||
/// Custom configuration.
|
||||
pub custom: C,
|
||||
/// Telemetry server URL, optional - only `Some` if telemetry reporting is enabled
|
||||
pub telemetry: Option<String>,
|
||||
/// Node name.
|
||||
@@ -55,9 +57,9 @@ pub struct Configuration<G: Serialize + DeserializeOwned + BuildStorage> {
|
||||
pub max_heap_pages: usize,
|
||||
}
|
||||
|
||||
impl<G: Serialize + DeserializeOwned + BuildStorage> Configuration<G> {
|
||||
impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C, G> {
|
||||
/// Create default config for given chain spec.
|
||||
pub fn default_with_spec(chain_spec: ChainSpec<G>) -> Configuration<G> {
|
||||
pub fn default_with_spec(chain_spec: ChainSpec<G>) -> Self {
|
||||
let mut configuration = Configuration {
|
||||
chain_spec,
|
||||
name: Default::default(),
|
||||
@@ -67,6 +69,7 @@ impl<G: Serialize + DeserializeOwned + BuildStorage> Configuration<G> {
|
||||
keystore_path: Default::default(),
|
||||
database_path: Default::default(),
|
||||
keys: Default::default(),
|
||||
custom: Default::default(),
|
||||
telemetry: Default::default(),
|
||||
pruning: PruningMode::ArchiveAll,
|
||||
execution_strategy: ExecutionStrategy::Both,
|
||||
|
||||
@@ -68,7 +68,7 @@ pub use extrinsic_pool::api::{ExtrinsicPool as ExtrinsicPoolApi};
|
||||
pub use components::{ServiceFactory, FullBackend, FullExecutor, LightBackend,
|
||||
LightExecutor, ExtrinsicPool, Components, PoolApi, ComponentClient,
|
||||
ComponentBlock, FullClient, LightClient, FullComponents, LightComponents,
|
||||
CodeExecutor, NetworkService, FactoryChainSpec, FactoryBlock, RuntimeGenesis,
|
||||
CodeExecutor, NetworkService, FactoryChainSpec, FactoryBlock, FactoryFullConfiguration, RuntimeGenesis,
|
||||
};
|
||||
|
||||
/// Substrate service.
|
||||
@@ -81,7 +81,7 @@ pub struct Service<Components: components::Components> {
|
||||
}
|
||||
|
||||
/// Creates bare client without any networking.
|
||||
pub fn new_client<Factory: components::ServiceFactory>(config: Configuration<Factory::Genesis>)
|
||||
pub fn new_client<Factory: components::ServiceFactory>(config: FactoryFullConfiguration<Factory>)
|
||||
-> Result<Arc<ComponentClient<components::FullComponents<Factory>>>, error::Error>
|
||||
{
|
||||
let executor = NativeExecutor::with_heap_pages(config.min_heap_pages, config.max_heap_pages);
|
||||
@@ -98,8 +98,8 @@ impl<Components> Service<Components>
|
||||
{
|
||||
/// Creates a new service.
|
||||
pub fn new(
|
||||
config: Configuration<<Components::Factory as ServiceFactory>::Genesis>,
|
||||
task_executor: TaskExecutor
|
||||
config: FactoryFullConfiguration<Components::Factory>,
|
||||
task_executor: TaskExecutor,
|
||||
)
|
||||
-> Result<Self, error::Error>
|
||||
{
|
||||
@@ -124,10 +124,12 @@ impl<Components> Service<Components>
|
||||
info!("Best block: #{}", best_header.number());
|
||||
telemetry!("node.start"; "height" => best_header.number().as_(), "best" => ?best_header.hash());
|
||||
|
||||
let network_protocol = <Components::Factory>::build_network_protocol(&config)?;
|
||||
let extrinsic_pool = Arc::new(
|
||||
Components::build_extrinsic_pool(config.extrinsic_pool, client.clone())?
|
||||
);
|
||||
let extrinsic_pool_adapter = extrinsic_pool.clone();
|
||||
|
||||
let network_params = network::Params {
|
||||
config: network::ProtocolConfig {
|
||||
roles: config.roles,
|
||||
@@ -137,7 +139,7 @@ impl<Components> Service<Components>
|
||||
on_demand: on_demand.clone()
|
||||
.map(|d| d as Arc<network::OnDemandService<ComponentBlock<Components>>>),
|
||||
transaction_pool: extrinsic_pool_adapter,
|
||||
specialization: <Components::Factory as ServiceFactory>::NetworkProtocol::default(),
|
||||
specialization: network_protocol,
|
||||
};
|
||||
|
||||
let network = network::Service::new(network_params, Components::Factory::NETWORK_PROTOCOL_ID)?;
|
||||
|
||||
Reference in New Issue
Block a user