mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
Companion for https://github.com/paritytech/substrate/pull/8143
This commit is contained in:
@@ -54,7 +54,7 @@ use std::sync::Arc;
|
||||
use prometheus_endpoint::Registry;
|
||||
use sc_executor::native_executor_instance;
|
||||
use service::RpcHandlers;
|
||||
use telemetry::{TelemetryConnectionNotifier, TelemetrySpan};
|
||||
use telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle};
|
||||
|
||||
pub use self::client::{AbstractClient, Client, ClientHandle, ExecuteWithClient, RuntimeApiCollection};
|
||||
pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec, RococoChainSpec};
|
||||
@@ -129,6 +129,9 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
Prometheus(#[from] prometheus_endpoint::PrometheusError),
|
||||
|
||||
#[error(transparent)]
|
||||
Telemetry(#[from] telemetry::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Jaeger(#[from] polkadot_subsystem::jaeger::JaegerError),
|
||||
|
||||
@@ -206,7 +209,11 @@ type LightClient<RuntimeApi, Executor> =
|
||||
service::TLightClientWithBackend<Block, RuntimeApi, Executor, LightBackend>;
|
||||
|
||||
#[cfg(feature = "full-node")]
|
||||
fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: Option<std::net::SocketAddr>) -> Result<
|
||||
fn new_partial<RuntimeApi, Executor>(
|
||||
config: &mut Configuration,
|
||||
jaeger_agent: Option<std::net::SocketAddr>,
|
||||
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
||||
) -> Result<
|
||||
service::PartialComponents<
|
||||
FullClient<RuntimeApi, Executor>, FullBackend, FullSelectChain,
|
||||
consensus_common::DefaultImportQueue<Block, FullClient<RuntimeApi, Executor>>,
|
||||
@@ -225,6 +232,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
|
||||
),
|
||||
grandpa::SharedVoterState,
|
||||
u64, // slot-duration
|
||||
Option<Telemetry>,
|
||||
)
|
||||
>,
|
||||
Error
|
||||
@@ -240,10 +248,36 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
|
||||
|
||||
let inherent_data_providers = inherents::InherentDataProviders::new();
|
||||
|
||||
let telemetry = config.telemetry_endpoints.clone()
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(move |endpoints| -> Result<_, telemetry::Error> {
|
||||
let (worker, mut worker_handle) = if let Some(worker_handle) = telemetry_worker_handle {
|
||||
(None, worker_handle)
|
||||
} else {
|
||||
let worker = TelemetryWorker::new(16)?;
|
||||
let worker_handle = worker.handle();
|
||||
(Some(worker), worker_handle)
|
||||
};
|
||||
let telemetry = worker_handle.new_telemetry(endpoints);
|
||||
Ok((worker, telemetry))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let (client, backend, keystore_container, task_manager) =
|
||||
service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
|
||||
service::new_full_parts::<Block, RuntimeApi, Executor>(
|
||||
&config,
|
||||
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
||||
)?;
|
||||
let client = Arc::new(client);
|
||||
|
||||
let telemetry = telemetry
|
||||
.map(|(worker, telemetry)| {
|
||||
if let Some(worker) = worker {
|
||||
task_manager.spawn_handle().spawn("telemetry", worker.run());
|
||||
}
|
||||
telemetry
|
||||
});
|
||||
|
||||
jaeger_launch_collector_with_agent(task_manager.spawn_handle(), &*config, jaeger_agent)?;
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
@@ -268,6 +302,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
|
||||
&(client.clone() as Arc<_>),
|
||||
select_chain.clone(),
|
||||
grandpa_hard_forks,
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
)?;
|
||||
|
||||
let justification_import = grandpa_block_import.clone();
|
||||
@@ -289,6 +324,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
|
||||
&task_manager.spawn_essential_handle(),
|
||||
config.prometheus_registry(),
|
||||
consensus_common::CanAuthorWithNativeVersion::new(client.executor().clone()),
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
)?;
|
||||
|
||||
let justification_stream = grandpa_link.justification_stream();
|
||||
@@ -346,7 +382,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
|
||||
import_queue,
|
||||
transaction_pool,
|
||||
inherent_data_providers,
|
||||
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration)
|
||||
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration, telemetry)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -566,6 +602,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
grandpa_pause: Option<(u32, u32)>,
|
||||
jaeger_agent: Option<std::net::SocketAddr>,
|
||||
isolation_strategy: IsolationStrategy,
|
||||
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
||||
) -> Result<NewFull<Arc<FullClient<RuntimeApi, Executor>>>, Error>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
|
||||
@@ -576,9 +613,6 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
#[cfg(feature = "real-overseer")]
|
||||
info!("real-overseer feature is ENABLED");
|
||||
|
||||
let telemetry_span = TelemetrySpan::new();
|
||||
let _telemetry_span_entered = telemetry_span.enter();
|
||||
|
||||
let role = config.role.clone();
|
||||
let force_authoring = config.force_authoring;
|
||||
let backoff_authoring_blocks =
|
||||
@@ -600,8 +634,8 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
import_queue,
|
||||
transaction_pool,
|
||||
inherent_data_providers,
|
||||
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration)
|
||||
} = new_partial::<RuntimeApi, Executor>(&mut config, jaeger_agent)?;
|
||||
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration, mut telemetry)
|
||||
} = new_partial::<RuntimeApi, Executor>(&mut config, jaeger_agent, telemetry_worker_handle)?;
|
||||
|
||||
let prometheus_registry = config.prometheus_registry().cloned();
|
||||
|
||||
@@ -705,7 +739,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
cache_size: None, // default is fine.
|
||||
};
|
||||
|
||||
let (rpc_handlers, telemetry_connection_notifier) = service::spawn_tasks(service::SpawnTasksParams {
|
||||
let rpc_handlers = service::spawn_tasks(service::SpawnTasksParams {
|
||||
config,
|
||||
backend: backend.clone(),
|
||||
client: client.clone(),
|
||||
@@ -718,7 +752,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
remote_blockchain: None,
|
||||
network_status_sinks: network_status_sinks.clone(),
|
||||
system_rpc_tx,
|
||||
telemetry_span: Some(telemetry_span.clone()),
|
||||
telemetry: telemetry.as_mut(),
|
||||
})?;
|
||||
|
||||
let (block_import, link_half, babe_link) = import_setup;
|
||||
@@ -830,6 +864,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
transaction_pool,
|
||||
overseer_handler.as_ref().ok_or(Error::AuthoritiesRequireRealOverseer)?.clone(),
|
||||
prometheus_registry.as_ref(),
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
);
|
||||
|
||||
let babe_config = babe::BabeParams {
|
||||
@@ -845,6 +880,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
babe_link,
|
||||
can_author_with,
|
||||
block_proposal_slot_portion: babe::SlotProportion::new(2f32 / 3f32),
|
||||
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
||||
};
|
||||
|
||||
let babe = babe::start_babe(babe_config)?;
|
||||
@@ -867,6 +903,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
observer_enabled: false,
|
||||
keystore: keystore_opt,
|
||||
is_authority: role.is_authority(),
|
||||
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
||||
};
|
||||
|
||||
let enable_grandpa = !disable_grandpa;
|
||||
@@ -914,10 +951,10 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
config,
|
||||
link: link_half,
|
||||
network: network.clone(),
|
||||
telemetry_on_connect: telemetry_connection_notifier.map(|x| x.on_connect_stream()),
|
||||
voting_rule,
|
||||
prometheus_registry: prometheus_registry.clone(),
|
||||
shared_voter_state,
|
||||
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
||||
};
|
||||
|
||||
task_manager.spawn_essential_handle().spawn_blocking(
|
||||
@@ -943,7 +980,6 @@ pub fn new_full<RuntimeApi, Executor>(
|
||||
fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
|
||||
TaskManager,
|
||||
RpcHandlers,
|
||||
Option<TelemetryConnectionNotifier>,
|
||||
), Error>
|
||||
where
|
||||
Runtime: 'static + Send + Sync + ConstructRuntimeApi<Block, LightClient<Runtime, Dispatch>>,
|
||||
@@ -954,8 +990,26 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
|
||||
set_prometheus_registry(&mut config)?;
|
||||
use sc_client_api::backend::RemoteBackend;
|
||||
|
||||
let telemetry = config.telemetry_endpoints.clone()
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|endpoints| -> Result<_, telemetry::Error> {
|
||||
let worker = TelemetryWorker::new(16)?;
|
||||
let telemetry = worker.handle().new_telemetry(endpoints);
|
||||
Ok((worker, telemetry))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let (client, backend, keystore_container, mut task_manager, on_demand) =
|
||||
service::new_light_parts::<Block, Runtime, Dispatch>(&config)?;
|
||||
service::new_light_parts::<Block, Runtime, Dispatch>(
|
||||
&config,
|
||||
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
||||
)?;
|
||||
|
||||
let mut telemetry = telemetry
|
||||
.map(|(worker, telemetry)| {
|
||||
task_manager.spawn_handle().spawn("telemetry", worker.run());
|
||||
telemetry
|
||||
});
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
|
||||
@@ -971,6 +1025,7 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
|
||||
client.clone(),
|
||||
&(client.clone() as Arc<_>),
|
||||
select_chain.clone(),
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
)?;
|
||||
let justification_import = grandpa_block_import.clone();
|
||||
|
||||
@@ -993,6 +1048,7 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
|
||||
&task_manager.spawn_essential_handle(),
|
||||
config.prometheus_registry(),
|
||||
consensus_common::NeverCanAuthor,
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
)?;
|
||||
|
||||
let (network, network_status_sinks, system_rpc_tx, network_starter) =
|
||||
@@ -1024,10 +1080,7 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
|
||||
|
||||
let rpc_extensions = polkadot_rpc::create_light(light_deps);
|
||||
|
||||
let telemetry_span = TelemetrySpan::new();
|
||||
let _telemetry_span_entered = telemetry_span.enter();
|
||||
|
||||
let (rpc_handlers, telemetry_connection_notifier) = service::spawn_tasks(service::SpawnTasksParams {
|
||||
let rpc_handlers = service::spawn_tasks(service::SpawnTasksParams {
|
||||
on_demand: Some(on_demand),
|
||||
remote_blockchain: Some(backend.remote_blockchain()),
|
||||
rpc_extensions_builder: Box::new(service::NoopRpcExtensionBuilder(rpc_extensions)),
|
||||
@@ -1040,17 +1093,20 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
|
||||
network,
|
||||
network_status_sinks,
|
||||
system_rpc_tx,
|
||||
telemetry_span: Some(telemetry_span.clone()),
|
||||
telemetry: telemetry.as_mut(),
|
||||
})?;
|
||||
|
||||
network_starter.start_network();
|
||||
|
||||
Ok((task_manager, rpc_handlers, telemetry_connection_notifier))
|
||||
Ok((task_manager, rpc_handlers))
|
||||
}
|
||||
|
||||
/// Builds a new object suitable for chain operations.
|
||||
#[cfg(feature = "full-node")]
|
||||
pub fn new_chain_ops(mut config: &mut Configuration, jaeger_agent: Option<std::net::SocketAddr>) -> Result<
|
||||
pub fn new_chain_ops(
|
||||
mut config: &mut Configuration,
|
||||
jaeger_agent: Option<std::net::SocketAddr>,
|
||||
) -> Result<
|
||||
(
|
||||
Arc<Client>,
|
||||
Arc<FullBackend>,
|
||||
@@ -1063,19 +1119,19 @@ pub fn new_chain_ops(mut config: &mut Configuration, jaeger_agent: Option<std::n
|
||||
config.keystore = service::config::KeystoreConfig::InMemory;
|
||||
if config.chain_spec.is_rococo() {
|
||||
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
|
||||
= new_partial::<rococo_runtime::RuntimeApi, RococoExecutor>(config, jaeger_agent)?;
|
||||
= new_partial::<rococo_runtime::RuntimeApi, RococoExecutor>(config, jaeger_agent, None)?;
|
||||
Ok((Arc::new(Client::Rococo(client)), backend, import_queue, task_manager))
|
||||
} else if config.chain_spec.is_kusama() {
|
||||
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
|
||||
= new_partial::<kusama_runtime::RuntimeApi, KusamaExecutor>(config, jaeger_agent)?;
|
||||
= new_partial::<kusama_runtime::RuntimeApi, KusamaExecutor>(config, jaeger_agent, None)?;
|
||||
Ok((Arc::new(Client::Kusama(client)), backend, import_queue, task_manager))
|
||||
} else if config.chain_spec.is_westend() {
|
||||
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
|
||||
= new_partial::<westend_runtime::RuntimeApi, WestendExecutor>(config, jaeger_agent)?;
|
||||
= new_partial::<westend_runtime::RuntimeApi, WestendExecutor>(config, jaeger_agent, None)?;
|
||||
Ok((Arc::new(Client::Westend(client)), backend, import_queue, task_manager))
|
||||
} else {
|
||||
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
|
||||
= new_partial::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config, jaeger_agent)?;
|
||||
= new_partial::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config, jaeger_agent, None)?;
|
||||
Ok((Arc::new(Client::Polkadot(client)), backend, import_queue, task_manager))
|
||||
}
|
||||
}
|
||||
@@ -1084,7 +1140,6 @@ pub fn new_chain_ops(mut config: &mut Configuration, jaeger_agent: Option<std::n
|
||||
pub fn build_light(config: Configuration) -> Result<(
|
||||
TaskManager,
|
||||
RpcHandlers,
|
||||
Option<TelemetryConnectionNotifier>,
|
||||
), Error> {
|
||||
if config.chain_spec.is_rococo() {
|
||||
new_light::<rococo_runtime::RuntimeApi, RococoExecutor>(config)
|
||||
@@ -1103,6 +1158,7 @@ pub fn build_full(
|
||||
is_collator: IsCollator,
|
||||
grandpa_pause: Option<(u32, u32)>,
|
||||
jaeger_agent: Option<std::net::SocketAddr>,
|
||||
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
||||
) -> Result<NewFull<Client>, Error> {
|
||||
let isolation_strategy = {
|
||||
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
|
||||
@@ -1124,6 +1180,7 @@ pub fn build_full(
|
||||
grandpa_pause,
|
||||
jaeger_agent,
|
||||
isolation_strategy,
|
||||
telemetry_worker_handle,
|
||||
).map(|full| full.with_client(Client::Rococo))
|
||||
} else if config.chain_spec.is_kusama() {
|
||||
new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
|
||||
@@ -1132,6 +1189,7 @@ pub fn build_full(
|
||||
grandpa_pause,
|
||||
jaeger_agent,
|
||||
isolation_strategy,
|
||||
telemetry_worker_handle,
|
||||
).map(|full| full.with_client(Client::Kusama))
|
||||
} else if config.chain_spec.is_westend() {
|
||||
new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
|
||||
@@ -1140,6 +1198,7 @@ pub fn build_full(
|
||||
grandpa_pause,
|
||||
jaeger_agent,
|
||||
isolation_strategy,
|
||||
telemetry_worker_handle,
|
||||
).map(|full| full.with_client(Client::Westend))
|
||||
} else {
|
||||
new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
|
||||
@@ -1148,6 +1207,7 @@ pub fn build_full(
|
||||
grandpa_pause,
|
||||
jaeger_agent,
|
||||
isolation_strategy,
|
||||
telemetry_worker_handle,
|
||||
).map(|full| full.with_client(Client::Polkadot))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user