mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
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:
@@ -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(
|
||||
®istry,
|
||||
&config.network.node_name,
|
||||
&config.impl_version,
|
||||
&config.role,
|
||||
)?;
|
||||
let metrics = MetricsService::with_prometheus(®istry, &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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +181,11 @@ impl Configuration {
|
||||
pub fn display_role(&self) -> String {
|
||||
self.role.to_string()
|
||||
}
|
||||
|
||||
/// Returns the prometheus metrics registry, if available.
|
||||
pub fn prometheus_registry<'a>(&'a self) -> Option<&'a Registry> {
|
||||
self.prometheus_config.as_ref().map(|config| &config.registry)
|
||||
}
|
||||
}
|
||||
|
||||
/// Available RPC methods.
|
||||
|
||||
@@ -577,11 +577,14 @@ mod tests {
|
||||
// given
|
||||
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
|
||||
let client = Arc::new(client);
|
||||
let pool = Arc::new(BasicPool::new(
|
||||
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||
let pool = BasicPool::new_full(
|
||||
Default::default(),
|
||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||
None,
|
||||
).0);
|
||||
spawner,
|
||||
client.clone(),
|
||||
);
|
||||
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
||||
let best = longest_chain.best_chain().unwrap();
|
||||
let transaction = Transfer {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::{convert::TryFrom, time::SystemTime};
|
||||
|
||||
use crate::NetworkStatus;
|
||||
use crate::{NetworkStatus, config::Configuration};
|
||||
use prometheus_endpoint::{register, Gauge, U64, F64, Registry, PrometheusError, Opts, GaugeVec};
|
||||
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
|
||||
use sp_runtime::traits::{NumberFor, Block, SaturatedConversion, UniqueSaturatedInto};
|
||||
@@ -261,17 +261,17 @@ impl MetricsService {
|
||||
|
||||
|
||||
impl MetricsService {
|
||||
pub fn with_prometheus(registry: &Registry, name: &str, version: &str, role: &Role)
|
||||
pub fn with_prometheus(registry: &Registry, config: &Configuration)
|
||||
-> Result<Self, PrometheusError>
|
||||
{
|
||||
let role_bits = match role {
|
||||
let role_bits = match config.role {
|
||||
Role::Full => 1u64,
|
||||
Role::Light => 2u64,
|
||||
Role::Sentry { .. } => 3u64,
|
||||
Role::Authority { .. } => 4u64,
|
||||
};
|
||||
|
||||
PrometheusMetrics::setup(registry, name, version, role_bits).map(|p| {
|
||||
PrometheusMetrics::setup(registry, &config.network.node_name, &config.impl_version, role_bits).map(|p| {
|
||||
Self::inner_new(Some(p))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user