Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 01900c0

Browse files
committed
WIP
1 parent 286407c commit 01900c0

File tree

5 files changed

+137
-78
lines changed

5 files changed

+137
-78
lines changed

bin/node/cli/src/service.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use sp_runtime::traits::Block as BlockT;
3434
use futures::prelude::*;
3535
use sc_client_api::{ExecutorProvider, RemoteBackend};
3636
use node_executor::Executor;
37-
use sc_telemetry::Telemetry;
37+
use sc_telemetry::ClientTelemetry;
3838

3939
type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
4040
type FullBackend = sc_service::TFullBackend<Block>;
@@ -74,6 +74,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
7474
client.clone(),
7575
);
7676

77+
let telemetry = client.telemetry();
7778
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
7879
client.clone(),
7980
&(client.clone() as Arc<_>),
@@ -222,6 +223,7 @@ pub fn new_full_base(
222223
);
223224
}
224225

226+
let telemetry = client.telemetry();
225227
let role = config.role.clone();
226228
let force_authoring = config.force_authoring;
227229
let backoff_authoring_blocks =
@@ -230,7 +232,7 @@ pub fn new_full_base(
230232
let enable_grandpa = !config.disable_grandpa;
231233
let prometheus_registry = config.prometheus_registry().cloned();
232234

233-
let (_rpc_handlers, telemetry) = sc_service::spawn_tasks(
235+
let _rpc_handlers = sc_service::spawn_tasks(
234236
sc_service::SpawnTasksParams {
235237
config,
236238
backend: backend.clone(),
@@ -367,7 +369,9 @@ pub fn new_full(config: Configuration)
367369
}
368370

369371
pub fn new_light_base(mut config: Configuration) -> Result<(
370-
TaskManager, RpcHandlers, Option<Telemetry>, Arc<LightClient>,
372+
TaskManager,
373+
RpcHandlers,
374+
Arc<LightClient>,
371375
Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
372376
Arc<sc_transaction_pool::LightPool<Block, LightClient, sc_network::config::OnDemand<Block>>>
373377
), ServiceError> {
@@ -386,11 +390,13 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
386390
on_demand.clone(),
387391
));
388392

393+
let telemetry = client.telemetry();
394+
389395
let (grandpa_block_import, _) = grandpa::block_import(
390396
client.clone(),
391397
&(client.clone() as Arc<_>),
392398
select_chain.clone(),
393-
telemetry.clone(), // TODO hmm how do I get the telemetry here...
399+
telemetry.clone(),
394400
)?;
395401
let justification_import = grandpa_block_import.clone();
396402

@@ -442,7 +448,7 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
442448

443449
let rpc_extensions = node_rpc::create_light(light_deps);
444450

445-
let (rpc_handlers, telemetry) =
451+
let rpc_handlers =
446452
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
447453
on_demand: Some(on_demand),
448454
remote_blockchain: Some(backend.remote_blockchain()),
@@ -458,7 +464,6 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
458464
Ok((
459465
task_manager,
460466
rpc_handlers,
461-
telemetry,
462467
client,
463468
network,
464469
transaction_pool,
@@ -467,7 +472,7 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
467472

468473
/// Builds a new service for a light client.
469474
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
470-
new_light_base(config).map(|(task_manager, _, _, _, _, _)| {
475+
new_light_base(config).map(|(task_manager, _, _, _, _)| {
471476
task_manager
472477
})
473478
}

client/service/src/builder.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ pub fn new_full_parts<TBl, TRtApi, TExecDisp>(
343343
Some(keystore_container.sync_keystore()),
344344
);
345345

346+
let telemetry = match (config.telemetry_handle.clone(), config.telemetry_endpoints.clone()) {
347+
(Some(mut handle), Some(endpoints)) => Some(handle.new_telemetry(endpoints)),
348+
_ => None,
349+
};
350+
346351
new_client(
347352
db_config,
348353
executor,
@@ -352,6 +357,7 @@ pub fn new_full_parts<TBl, TRtApi, TExecDisp>(
352357
extensions,
353358
Box::new(task_manager.spawn_handle()),
354359
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
360+
telemetry,
355361
ClientConfig {
356362
offchain_worker_enabled : config.offchain_worker.enabled,
357363
offchain_indexing_api: config.offchain_worker.indexing_enabled,
@@ -409,12 +415,17 @@ pub fn new_light_parts<TBl, TRtApi, TExecDisp>(
409415
);
410416
let on_demand = Arc::new(sc_network::config::OnDemand::new(fetch_checker));
411417
let backend = sc_light::new_light_backend(light_blockchain);
418+
let telemetry = match (config.telemetry_handle.clone(), config.telemetry_endpoints.clone()) {
419+
(Some(mut handle), Some(endpoints)) => Some(handle.new_telemetry(endpoints)),
420+
_ => None,
421+
};
412422
let client = Arc::new(light::new_light(
413423
backend.clone(),
414424
config.chain_spec.as_storage_builder(),
415425
executor,
416426
Box::new(task_manager.spawn_handle()),
417427
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
428+
telemetry,
418429
)?);
419430

420431
Ok((client, backend, keystore_container, task_manager, on_demand))
@@ -430,6 +441,7 @@ pub fn new_client<E, Block, RA>(
430441
execution_extensions: ExecutionExtensions<Block>,
431442
spawn_handle: Box<dyn SpawnNamed>,
432443
prometheus_registry: Option<Registry>,
444+
telemetry: Option<Telemetry>,
433445
config: ClientConfig,
434446
) -> Result<(
435447
crate::client::Client<
@@ -459,6 +471,7 @@ pub fn new_client<E, Block, RA>(
459471
bad_blocks,
460472
execution_extensions,
461473
prometheus_registry,
474+
telemetry,
462475
config,
463476
)?,
464477
backend,
@@ -538,7 +551,7 @@ pub fn build_offchain_workers<TBl, TBackend, TCl>(
538551
/// Spawn the tasks that are required to run a node.
539552
pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
540553
params: SpawnTasksParams<TBl, TCl, TExPool, TRpc, TBackend>,
541-
) -> Result<(RpcHandlers, Option<Telemetry>), Error>
554+
) -> Result<RpcHandlers, Error>
542555
where
543556
TCl: ProvideRuntimeApi<TBl> + HeaderMetadata<TBl, Error=sp_blockchain::Error> + Chain<TBl> +
544557
BlockBackend<TBl> + BlockIdTo<TBl, Error=sp_blockchain::Error> + ProofProvider<TBl> +
@@ -581,14 +594,15 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
581594
config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default(),
582595
)?;
583596

584-
let telemetry = init_telemetry(
585-
&mut config,
586-
network.clone(),
587-
client.clone(),
588-
);
597+
let telemetry = client.telemetry();
589598

590599
if let Some(telemetry) = telemetry.clone() {
591-
client.set_telemetry(telemetry);
600+
init_telemetry(
601+
&mut config,
602+
network.clone(),
603+
client.clone(),
604+
telemetry.clone(),
605+
);
592606
}
593607

594608
info!("📦 Highest known block at #{}", chain_info.best_number);
@@ -659,7 +673,7 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
659673

660674
task_manager.keep_alive((config.base_path, rpc, rpc_handlers.clone()));
661675

662-
Ok((rpc_handlers, telemetry))
676+
Ok(rpc_handlers)
663677
}
664678

665679
async fn transaction_notifications<TBl, TExPool>(
@@ -691,8 +705,8 @@ fn init_telemetry<TBl: BlockT, TCl: BlockBackend<TBl>>(
691705
config: &mut Configuration,
692706
network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
693707
client: Arc<TCl>,
694-
) -> Option<Telemetry> {
695-
let endpoints = config.telemetry_endpoints.clone()?;
708+
mut telemetry: Telemetry,
709+
) {
696710
let genesis_hash = client.block_hash(Zero::zero()).ok().flatten().unwrap_or_default();
697711
let connection_message = ConnectionMessage {
698712
name: config.network.node_name.to_owned(),
@@ -708,9 +722,7 @@ fn init_telemetry<TBl: BlockT, TCl: BlockBackend<TBl>>(
708722
network_id: network.local_peer_id().to_base58(),
709723
};
710724

711-
config.telemetry_handle
712-
.as_mut()
713-
.map(|handle| handle.start_telemetry(endpoints, connection_message))
725+
telemetry.start_telemetry(connection_message)
714726
}
715727

716728
fn gen_handler<TBl, TBackend, TExPool, TRpc, TCl>(

client/service/src/client/client.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub struct Client<B, E, Block, RA> where Block: BlockT {
115115
block_rules: BlockRules<Block>,
116116
execution_extensions: ExecutionExtensions<Block>,
117117
config: ClientConfig,
118-
telemetry: RwLock<Option<Telemetry>>,
118+
telemetry: Option<Telemetry>,
119119
_phantom: PhantomData<RA>,
120120
}
121121

@@ -153,6 +153,7 @@ pub fn new_in_mem<E, Block, S, RA>(
153153
genesis_storage: &S,
154154
keystore: Option<SyncCryptoStorePtr>,
155155
prometheus_registry: Option<Registry>,
156+
telemetry: Option<Telemetry>,
156157
spawn_handle: Box<dyn SpawnNamed>,
157158
config: ClientConfig,
158159
) -> sp_blockchain::Result<Client<
@@ -172,6 +173,7 @@ pub fn new_in_mem<E, Block, S, RA>(
172173
keystore,
173174
spawn_handle,
174175
prometheus_registry,
176+
telemetry,
175177
config,
176178
)
177179
}
@@ -197,6 +199,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
197199
keystore: Option<SyncCryptoStorePtr>,
198200
spawn_handle: Box<dyn SpawnNamed>,
199201
prometheus_registry: Option<Registry>,
202+
telemetry: Option<Telemetry>,
200203
config: ClientConfig,
201204
) -> sp_blockchain::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>>
202205
where
@@ -215,6 +218,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
215218
Default::default(),
216219
extensions,
217220
prometheus_registry,
221+
telemetry,
218222
config,
219223
)
220224
}
@@ -295,6 +299,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
295299
bad_blocks: BadBlocks<Block>,
296300
execution_extensions: ExecutionExtensions<Block>,
297301
prometheus_registry: Option<Registry>,
302+
telemetry: Option<Telemetry>,
298303
config: ClientConfig,
299304
) -> sp_blockchain::Result<Self> {
300305
if backend.blockchain().header(BlockId::Number(Zero::zero()))?.is_none() {
@@ -327,7 +332,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
327332
block_rules: BlockRules::new(fork_blocks, bad_blocks),
328333
execution_extensions,
329334
config,
330-
telemetry: RwLock::new(None),
335+
telemetry,
331336
_phantom: Default::default(),
332337
})
333338
}
@@ -671,7 +676,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
671676
rand::thread_rng().gen_bool(0.1)
672677
{
673678
telemetry!(
674-
self.telemetry.read().clone(); SUBSTRATE_INFO; "block.import";
679+
self.telemetry.clone(); SUBSTRATE_INFO; "block.import";
675680
"height" => height,
676681
"best" => ?hash,
677682
"origin" => ?origin
@@ -988,11 +993,11 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
988993
let header = self.header(&BlockId::Hash(*last))?
989994
.expect(
990995
"Header already known to exist in DB because it is \
991-
indicated in the tree route; qed"
996+
indicated in the tree route; qed"
992997
);
993998

994999
telemetry!(
995-
self.telemetry.read().clone(); SUBSTRATE_INFO; "notify.finalized";
1000+
self.telemetry.clone(); SUBSTRATE_INFO; "notify.finalized";
9961001
"height" => format!("{}", header.number()),
9971002
"best" => ?last,
9981003
);
@@ -1002,7 +1007,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
10021007
let header = self.header(&BlockId::Hash(finalized_hash))?
10031008
.expect(
10041009
"Header already known to exist in DB because it is \
1005-
indicated in the tree route; qed"
1010+
indicated in the tree route; qed"
10061011
);
10071012

10081013
let notification = FinalityNotification {
@@ -2002,9 +2007,11 @@ impl<BE, E, B, RA> sp_consensus::block_validation::Chain<B> for Client<BE, E, B,
20022007

20032008
impl<BE, E, B, RA> ClientTelemetry for Client<BE, E, B, RA>
20042009
where
2010+
BE: backend::Backend<B>,
2011+
E: CallExecutor<B>,
20052012
B: BlockT,
20062013
{
2007-
fn set_telemetry(&self, telemetry: Telemetry) {
2008-
*self.telemetry.write() = Some(telemetry);
2014+
fn telemetry(&self) -> Option<Telemetry> {
2015+
self.telemetry.clone()
20092016
}
20102017
}

client/service/src/client/light.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::sync::Arc;
2222

2323
use sc_executor::RuntimeInfo;
2424
use sp_core::traits::{CodeExecutor, SpawnNamed};
25+
use sc_telemetry::Telemetry;
2526
use sp_runtime::BuildStorage;
2627
use sp_runtime::traits::{Block as BlockT, HashFor};
2728
use sp_blockchain::Result as ClientResult;
@@ -38,6 +39,7 @@ pub fn new_light<B, S, RA, E>(
3839
code_executor: E,
3940
spawn_handle: Box<dyn SpawnNamed>,
4041
prometheus_registry: Option<Registry>,
42+
telemetry: Option<Telemetry>,
4143
) -> ClientResult<
4244
Client<
4345
Backend<S, HashFor<B>>,
@@ -69,6 +71,7 @@ pub fn new_light<B, S, RA, E>(
6971
Default::default(),
7072
Default::default(),
7173
prometheus_registry,
74+
telemetry,
7275
ClientConfig::default(),
7376
)
7477
}

0 commit comments

Comments
 (0)