mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Generalize the Consensus Infrastructure (#883)
* Split out Consensus * Supply ImportQueue through network-service - simplify ImportQueue.import_blocks - remove Deadlock on import_block - Adding Verifier-Trait - Implement import_queue provisioning in service; allow cli to import * Allow to actually customize import queue * Consensus Gossip: Cache Message hash per Topic
This commit is contained in:
committed by
GitHub
parent
a24e61cb29
commit
ac4bcf879f
@@ -139,6 +139,8 @@ pub trait ServiceFactory: 'static + Sized {
|
||||
type FullService: Deref<Target = Service<FullComponents<Self>>> + Send + Sync + 'static;
|
||||
/// Extended light service type.
|
||||
type LightService: Deref<Target = Service<LightComponents<Self>>> + Send + Sync + 'static;
|
||||
/// ImportQueue
|
||||
type ImportQueue: network::import_queue::ImportQueue<Self::Block> + 'static;
|
||||
|
||||
//TODO: replace these with a constructor trait. that TransactionPool implements.
|
||||
/// Extrinsic pool constructor for the full client.
|
||||
@@ -158,6 +160,36 @@ pub trait ServiceFactory: 'static + Sized {
|
||||
/// Build light service.
|
||||
fn new_light(config: FactoryFullConfiguration<Self>, executor: TaskExecutor)
|
||||
-> Result<Self::LightService, error::Error>;
|
||||
|
||||
/// ImportQueue for a full client
|
||||
fn build_full_import_queue(
|
||||
config: &FactoryFullConfiguration<Self>,
|
||||
_client: Arc<FullClient<Self>>
|
||||
) -> Result<Self::ImportQueue, error::Error> {
|
||||
if let Some(name) = config.chain_spec.consensus_engine() {
|
||||
match name {
|
||||
_ => Err(format!("Chain Specification defines unknown consensus engine '{}'", name).into())
|
||||
}
|
||||
|
||||
} else {
|
||||
Err("Chain Specification doesn't contain any consensus_engine name".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// ImportQueue for a light client
|
||||
fn build_light_import_queue(
|
||||
config: &FactoryFullConfiguration<Self>,
|
||||
_client: Arc<LightClient<Self>>
|
||||
) -> Result<Self::ImportQueue, error::Error> {
|
||||
if let Some(name) = config.chain_spec.consensus_engine() {
|
||||
match name {
|
||||
_ => Err(format!("Chain Specification defines unknown consensus engine '{}'", name).into())
|
||||
}
|
||||
|
||||
} else {
|
||||
Err("Chain Specification doesn't contain any consensus_engine name".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A collection of types and function to generalise over full / light client type.
|
||||
@@ -187,6 +219,12 @@ pub trait Components: 'static {
|
||||
/// Create extrinsic pool.
|
||||
fn build_transaction_pool(config: TransactionPoolOptions, client: Arc<ComponentClient<Self>>)
|
||||
-> Result<TransactionPool<Self::TransactionPoolApi>, error::Error>;
|
||||
|
||||
/// instance of import queue for clients
|
||||
fn build_import_queue(
|
||||
config: &FactoryFullConfiguration<Self::Factory>,
|
||||
client: Arc<ComponentClient<Self>>
|
||||
) -> Result<<Self::Factory as ServiceFactory>::ImportQueue, error::Error>;
|
||||
}
|
||||
|
||||
/// A struct that implement `Components` for the full client.
|
||||
@@ -228,6 +266,13 @@ impl<Factory: ServiceFactory> Components for FullComponents<Factory> {
|
||||
{
|
||||
Factory::build_full_transaction_pool(config, client)
|
||||
}
|
||||
|
||||
fn build_import_queue(
|
||||
config: &FactoryFullConfiguration<Self::Factory>,
|
||||
client: Arc<ComponentClient<Self>>
|
||||
) -> Result<<Self::Factory as ServiceFactory>::ImportQueue, error::Error> {
|
||||
Factory::build_full_import_queue(config, client)
|
||||
}
|
||||
}
|
||||
|
||||
/// A struct that implement `Components` for the light client.
|
||||
@@ -270,4 +315,11 @@ impl<Factory: ServiceFactory> Components for LightComponents<Factory> {
|
||||
{
|
||||
Factory::build_light_transaction_pool(config, client)
|
||||
}
|
||||
|
||||
fn build_import_queue(
|
||||
config: &FactoryFullConfiguration<Self::Factory>,
|
||||
client: Arc<ComponentClient<Self>>
|
||||
) -> Result<<Self::Factory as ServiceFactory>::ImportQueue, error::Error> {
|
||||
Factory::build_light_import_queue(config, client)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user