Simplify a few chain components creation APIs related to the service (#6611)

* Simplify a few chain components creation APIs related to the service

* Fix basic-authorship doc tests

* Remove DefaultQueue

* Update client/service/src/builder.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Move ExecutionExtensions comment around

* Remove unused BlakeTwo256

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Ashley
2020-07-09 15:43:04 +02:00
committed by GitHub
parent 25de5b5c78
commit 234e7d0c3d
19 changed files with 202 additions and 140 deletions
+9 -19
View File
@@ -66,8 +66,6 @@ use sc_client_api::{
use sp_blockchain::{HeaderMetadata, HeaderBackend};
use crate::{ServiceComponents, TelemetryOnConnectSinks, RpcHandlers, NetworkStatusSinks};
pub type BackgroundTask = Pin<Box<dyn Future<Output=()> + Send>>;
/// Aggregator for the components required to build a service.
///
/// # Usage
@@ -518,6 +516,11 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
self.remote_backend.clone()
}
/// Returns a spawn handle created by the task manager.
pub fn spawn_handle(&self) -> SpawnTaskHandle {
self.task_manager.spawn_handle()
}
/// Consume the builder and return the parts needed for chain operations.
pub fn to_chain_ops_parts(self) -> (Arc<TCl>, Arc<Backend>, TImpQu, TaskManager) {
(self.client, self.backend, self.import_queue, self.task_manager)
@@ -728,15 +731,11 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
self,
transaction_pool_builder: impl FnOnce(
&Self,
) -> Result<(UExPool, Option<BackgroundTask>), Error>,
) -> Result<Arc<UExPool>, Error>,
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
UExPool, TRpc, Backend>, Error>
where TSc: Clone, TFchr: Clone {
let (transaction_pool, background_task) = transaction_pool_builder(&self)?;
if let Some(background_task) = background_task{
self.task_manager.spawn_handle().spawn("txpool-background", background_task);
}
let transaction_pool = transaction_pool_builder(&self)?;
Ok(ServiceBuilder {
config: self.config,
@@ -749,7 +748,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
import_queue: self.import_queue,
finality_proof_request_builder: self.finality_proof_request_builder,
finality_proof_provider: self.finality_proof_provider,
transaction_pool: Arc::new(transaction_pool),
transaction_pool: transaction_pool,
rpc_extensions_builder: self.rpc_extensions_builder,
remote_backend: self.remote_backend,
block_announce_validator_builder: self.block_announce_validator_builder,
@@ -978,12 +977,7 @@ ServiceBuilder<
// Prometheus metrics.
let metrics_service = if let Some(PrometheusConfig { port, registry }) = config.prometheus_config.clone() {
// Set static metrics.
let metrics = MetricsService::with_prometheus(
&registry,
&config.network.node_name,
&config.impl_version,
&config.role,
)?;
let metrics = MetricsService::with_prometheus(&registry, &config)?;
spawn_handle.spawn(
"prometheus-endpoint",
prometheus_endpoint::init_prometheus(port, registry).map(drop)
@@ -1122,10 +1116,6 @@ ServiceBuilder<
/// Builds the full service.
pub fn build_full(self) -> Result<ServiceComponents<TBl, TBackend, TSc, TExPool, TCl>, Error> {
// make transaction pool available for off-chain runtime calls.
self.client.execution_extensions()
.register_transaction_pool(Arc::downgrade(&self.transaction_pool) as _);
self.build_common()
}
}