Adapt code to new sc-telemetry (#362)

This commit is contained in:
Cecile Tonglet
2021-03-11 13:45:02 +01:00
committed by GitHub
parent 2b73fcf45d
commit 321b4434ac
9 changed files with 282 additions and 242 deletions
+230 -217
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -84,7 +84,7 @@ impl BlockAnnounceData {
/// ///
/// This will not check the signature, for this you should use [`BlockAnnounceData::check_signature`]. /// This will not check the signature, for this you should use [`BlockAnnounceData::check_signature`].
fn validate(&self, encoded_header: Vec<u8>) -> Result<(), Validation> { fn validate(&self, encoded_header: Vec<u8>) -> Result<(), Validation> {
let candidate_hash = if let CompactStatement::Candidate(h) = self.statement.payload() { let candidate_hash = if let CompactStatement::Seconded(h) = self.statement.payload() {
h h
} else { } else {
tracing::debug!( tracing::debug!(
+1
View File
@@ -14,6 +14,7 @@ cumulus-primitives-core = { path = "../../primitives/core" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
+3
View File
@@ -27,6 +27,7 @@ use sc_client_api::{
Backend as BackendT, BlockBackend, BlockchainEvents, Finalizer, UsageProvider, Backend as BackendT, BlockBackend, BlockchainEvents, Finalizer, UsageProvider,
}; };
use sc_service::{error::Result as ServiceResult, Configuration, Role, TaskManager}; use sc_service::{error::Result as ServiceResult, Configuration, Role, TaskManager};
use sc_telemetry::TelemetryWorkerHandle;
use sp_blockchain::HeaderBackend; use sp_blockchain::HeaderBackend;
use sp_consensus::BlockImport; use sp_consensus::BlockImport;
use sp_core::traits::SpawnNamed; use sp_core::traits::SpawnNamed;
@@ -233,6 +234,7 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration
pub fn build_polkadot_full_node( pub fn build_polkadot_full_node(
config: Configuration, config: Configuration,
collator_id: CollatorId, collator_id: CollatorId,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<RFullNode<PClient>, polkadot_service::Error> { ) -> Result<RFullNode<PClient>, polkadot_service::Error> {
let is_light = matches!(config.role, Role::Light); let is_light = matches!(config.role, Role::Light);
if is_light { if is_light {
@@ -245,6 +247,7 @@ pub fn build_polkadot_full_node(
polkadot_service::IsCollator::Yes(collator_id), polkadot_service::IsCollator::Yes(collator_id),
None, None,
None, None,
telemetry_worker_handle,
) )
} }
} }
+1 -1
View File
@@ -384,7 +384,7 @@ impl_runtime_apis! {
} }
fn random_seed() -> <Block as BlockT>::Hash { fn random_seed() -> <Block as BlockT>::Hash {
RandomnessCollectiveFlip::random_seed() RandomnessCollectiveFlip::random_seed().0
} }
} }
+1 -3
View File
@@ -216,7 +216,6 @@ pub fn run() -> Result<()> {
&polkadot_cli, &polkadot_cli,
&polkadot_cli, &polkadot_cli,
config.task_executor.clone(), config.task_executor.clone(),
None,
) )
.map_err(|err| format!("Relay chain argument error: {}", err))?; .map_err(|err| format!("Relay chain argument error: {}", err))?;
@@ -311,7 +310,6 @@ pub fn run() -> Result<()> {
&polkadot_cli, &polkadot_cli,
&polkadot_cli, &polkadot_cli,
task_executor, task_executor,
config.telemetry_handle.clone(),
) )
.map_err(|err| format!("Relay chain argument error: {}", err))?; .map_err(|err| format!("Relay chain argument error: {}", err))?;
let collator = cli.run.base.validator || cli.collator; let collator = cli.run.base.validator || cli.collator;
@@ -388,7 +386,7 @@ impl CliConfiguration<Self> for RelayChainCli {
self.base.base.prometheus_config(default_listen_port) self.base.base.prometheus_config(default_listen_port)
} }
fn init<C: SubstrateCli>(&self) -> Result<sc_telemetry::TelemetryWorker> { fn init<C: SubstrateCli>(&self) -> Result<()> {
unreachable!("PolkadotCli is never initialized; qed"); unreachable!("PolkadotCli is never initialized; qed");
} }
+40 -15
View File
@@ -28,7 +28,7 @@ use rococo_parachain_primitives::Block;
use sc_executor::native_executor_instance; use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor; pub use sc_executor::NativeExecutor;
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager}; use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
use sc_telemetry::TelemetrySpan; use sc_telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle};
use sp_core::Pair; use sp_core::Pair;
use sp_runtime::traits::BlakeTwo256; use sp_runtime::traits::BlakeTwo256;
use sp_trie::PrefixedMemoryDB; use sp_trie::PrefixedMemoryDB;
@@ -54,16 +54,38 @@ pub fn new_partial(
(), (),
sp_consensus::import_queue::BasicQueue<Block, PrefixedMemoryDB<BlakeTwo256>>, sp_consensus::import_queue::BasicQueue<Block, PrefixedMemoryDB<BlakeTwo256>>,
sc_transaction_pool::FullPool<Block, TFullClient<Block, RuntimeApi, Executor>>, sc_transaction_pool::FullPool<Block, TFullClient<Block, RuntimeApi, Executor>>,
(), (Option<Telemetry>, Option<TelemetryWorkerHandle>),
>, >,
sc_service::Error, sc_service::Error,
> { > {
let inherent_data_providers = sp_inherents::InherentDataProviders::new(); let inherent_data_providers = sp_inherents::InherentDataProviders::new();
let telemetry = config.telemetry_endpoints.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;
let (client, backend, keystore_container, task_manager) = let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?; sc_service::new_full_parts::<Block, RuntimeApi, Executor>(
&config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
)?;
let client = Arc::new(client); let client = Arc::new(client);
let telemetry_worker_handle = telemetry
.as_ref()
.map(|(worker, _)| worker.handle());
let telemetry = telemetry
.map(|(worker, telemetry)| {
task_manager.spawn_handle().spawn("telemetry", worker.run());
telemetry
});
let registry = config.prometheus_registry(); let registry = config.prometheus_registry();
let transaction_pool = sc_transaction_pool::BasicPool::new_full( let transaction_pool = sc_transaction_pool::BasicPool::new_full(
@@ -91,7 +113,7 @@ pub fn new_partial(
transaction_pool, transaction_pool,
inherent_data_providers, inherent_data_providers,
select_chain: (), select_chain: (),
other: (), other: (telemetry, telemetry_worker_handle),
}; };
Ok(params) Ok(params)
@@ -122,18 +144,23 @@ where
let parachain_config = prepare_node_config(parachain_config); let parachain_config = prepare_node_config(parachain_config);
let polkadot_full_node =
cumulus_client_service::build_polkadot_full_node(polkadot_config, collator_key.public())
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let params = new_partial(&parachain_config)?; let params = new_partial(&parachain_config)?;
params params
.inherent_data_providers .inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider) .register_provider(sp_timestamp::InherentDataProvider)
.unwrap(); .unwrap();
let (mut telemetry, telemetry_worker_handle) = params.other;
let polkadot_full_node =
cumulus_client_service::build_polkadot_full_node(
polkadot_config,
collator_key.public(),
telemetry_worker_handle,
)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let client = params.client.clone(); let client = params.client.clone();
let backend = params.backend.clone(); let backend = params.backend.clone();
@@ -162,9 +189,6 @@ where
let rpc_client = client.clone(); let rpc_client = client.clone();
let rpc_extensions_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone())); let rpc_extensions_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone()));
let telemetry_span = TelemetrySpan::new();
let _telemetry_span_entered = telemetry_span.enter();
sc_service::spawn_tasks(sc_service::SpawnTasksParams { sc_service::spawn_tasks(sc_service::SpawnTasksParams {
on_demand: None, on_demand: None,
remote_blockchain: None, remote_blockchain: None,
@@ -178,7 +202,7 @@ where
network: network.clone(), network: network.clone(),
network_status_sinks, network_status_sinks,
system_rpc_tx, system_rpc_tx,
telemetry_span: Some(telemetry_span.clone()), telemetry: telemetry.as_mut(),
})?; })?;
let announce_block = { let announce_block = {
@@ -192,6 +216,7 @@ where
client.clone(), client.clone(),
transaction_pool, transaction_pool,
prometheus_registry.as_ref(), prometheus_registry.as_ref(),
telemetry.as_ref().map(|x| x.handle()),
); );
let spawner = task_manager.spawn_handle(); let spawner = task_manager.spawn_handle();
+1 -1
View File
@@ -333,7 +333,7 @@ impl_runtime_apis! {
} }
fn random_seed() -> <Block as BlockT>::Hash { fn random_seed() -> <Block as BlockT>::Hash {
RandomnessCollectiveFlip::random_seed() RandomnessCollectiveFlip::random_seed().0
} }
} }
+4 -4
View File
@@ -80,7 +80,7 @@ pub fn new_partial(
let inherent_data_providers = sp_inherents::InherentDataProviders::new(); let inherent_data_providers = sp_inherents::InherentDataProviders::new();
let (client, backend, keystore_container, task_manager) = let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, RuntimeExecutor>(&config)?; sc_service::new_full_parts::<Block, RuntimeApi, RuntimeExecutor>(&config, None)?;
let client = Arc::new(client); let client = Arc::new(client);
let registry = config.prometheus_registry(); let registry = config.prometheus_registry();
@@ -194,7 +194,7 @@ where
Box::new(move |_, _| rpc_ext_builder(client.clone())) Box::new(move |_, _| rpc_ext_builder(client.clone()))
}; };
let (rpc_handlers, _) = sc_service::spawn_tasks(sc_service::SpawnTasksParams { let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
on_demand: None, on_demand: None,
remote_blockchain: None, remote_blockchain: None,
rpc_extensions_builder, rpc_extensions_builder,
@@ -207,7 +207,7 @@ where
network: network.clone(), network: network.clone(),
network_status_sinks, network_status_sinks,
system_rpc_tx, system_rpc_tx,
telemetry_span: None, telemetry: None,
})?; })?;
let announce_block = { let announce_block = {
@@ -221,6 +221,7 @@ where
client.clone(), client.clone(),
transaction_pool, transaction_pool,
prometheus_registry.as_ref(), prometheus_registry.as_ref(),
None,
); );
let parachain_consensus = cumulus_client_consensus_relay_chain::RelayChainConsensus::new( let parachain_consensus = cumulus_client_consensus_relay_chain::RelayChainConsensus::new(
para_id, para_id,
@@ -423,7 +424,6 @@ pub fn node_config(
rpc_cors: None, rpc_cors: None,
rpc_methods: Default::default(), rpc_methods: Default::default(),
prometheus_config: None, prometheus_config: None,
telemetry_handle: None,
telemetry_endpoints: None, telemetry_endpoints: None,
telemetry_external_transport: None, telemetry_external_transport: None,
default_heap_pages: None, default_heap_pages: None,