Skip to content

Commit

Permalink
Adapt code to new sc-telemetry (paritytech#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton authored Mar 11, 2021
1 parent cb5a244 commit a3d50f2
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 242 deletions.
447 changes: 230 additions & 217 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl BlockAnnounceData {
///
/// This will not check the signature, for this you should use [`BlockAnnounceData::check_signature`].
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
} else {
tracing::debug!(
Expand Down
1 change: 1 addition & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cumulus-primitives-core = { path = "../../primitives/core" }
sc-chain-spec = { 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-telemetry = { 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-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
3 changes: 3 additions & 0 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use sc_client_api::{
Backend as BackendT, BlockBackend, BlockchainEvents, Finalizer, UsageProvider,
};
use sc_service::{error::Result as ServiceResult, Configuration, Role, TaskManager};
use sc_telemetry::TelemetryWorkerHandle;
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockImport;
use sp_core::traits::SpawnNamed;
Expand Down Expand Up @@ -233,6 +234,7 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration
pub fn build_polkadot_full_node(
config: Configuration,
collator_id: CollatorId,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<RFullNode<PClient>, polkadot_service::Error> {
let is_light = matches!(config.role, Role::Light);
if is_light {
Expand All @@ -245,6 +247,7 @@ pub fn build_polkadot_full_node(
polkadot_service::IsCollator::Yes(collator_id),
None,
None,
telemetry_worker_handle,
)
}
}
2 changes: 1 addition & 1 deletion rococo-parachains/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl_runtime_apis! {
}

fn random_seed() -> <Block as BlockT>::Hash {
RandomnessCollectiveFlip::random_seed()
RandomnessCollectiveFlip::random_seed().0
}
}

Expand Down
4 changes: 1 addition & 3 deletions rococo-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ pub fn run() -> Result<()> {
&polkadot_cli,
&polkadot_cli,
config.task_executor.clone(),
None,
)
.map_err(|err| format!("Relay chain argument error: {}", err))?;

Expand Down Expand Up @@ -311,7 +310,6 @@ pub fn run() -> Result<()> {
&polkadot_cli,
&polkadot_cli,
task_executor,
config.telemetry_handle.clone(),
)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
let collator = cli.run.base.validator || cli.collator;
Expand Down Expand Up @@ -388,7 +386,7 @@ impl CliConfiguration<Self> for RelayChainCli {
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");
}

Expand Down
55 changes: 40 additions & 15 deletions rococo-parachains/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rococo_parachain_primitives::Block;
use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor;
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_runtime::traits::BlakeTwo256;
use sp_trie::PrefixedMemoryDB;
Expand All @@ -54,16 +54,38 @@ pub fn new_partial(
(),
sp_consensus::import_queue::BasicQueue<Block, PrefixedMemoryDB<BlakeTwo256>>,
sc_transaction_pool::FullPool<Block, TFullClient<Block, RuntimeApi, Executor>>,
(),
(Option<Telemetry>, Option<TelemetryWorkerHandle>),
>,
sc_service::Error,
> {
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) =
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 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 transaction_pool = sc_transaction_pool::BasicPool::new_full(
Expand Down Expand Up @@ -91,7 +113,7 @@ pub fn new_partial(
transaction_pool,
inherent_data_providers,
select_chain: (),
other: (),
other: (telemetry, telemetry_worker_handle),
};

Ok(params)
Expand Down Expand Up @@ -122,18 +144,23 @@ where

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)?;
params
.inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.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 backend = params.backend.clone();
Expand Down Expand Up @@ -162,9 +189,6 @@ where
let rpc_client = 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 {
on_demand: None,
remote_blockchain: None,
Expand All @@ -178,7 +202,7 @@ where
network: network.clone(),
network_status_sinks,
system_rpc_tx,
telemetry_span: Some(telemetry_span.clone()),
telemetry: telemetry.as_mut(),
})?;

let announce_block = {
Expand All @@ -192,6 +216,7 @@ where
client.clone(),
transaction_pool,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|x| x.handle()),
);
let spawner = task_manager.spawn_handle();

Expand Down
2 changes: 1 addition & 1 deletion test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl_runtime_apis! {
}

fn random_seed() -> <Block as BlockT>::Hash {
RandomnessCollectiveFlip::random_seed()
RandomnessCollectiveFlip::random_seed().0
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn new_partial(
let inherent_data_providers = sp_inherents::InherentDataProviders::new();

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 registry = config.prometheus_registry();
Expand Down Expand Up @@ -194,7 +194,7 @@ where
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,
remote_blockchain: None,
rpc_extensions_builder,
Expand All @@ -207,7 +207,7 @@ where
network: network.clone(),
network_status_sinks,
system_rpc_tx,
telemetry_span: None,
telemetry: None,
})?;

let announce_block = {
Expand All @@ -221,6 +221,7 @@ where
client.clone(),
transaction_pool,
prometheus_registry.as_ref(),
None,
);
let parachain_consensus = cumulus_client_consensus_relay_chain::RelayChainConsensus::new(
para_id,
Expand Down Expand Up @@ -423,7 +424,6 @@ pub fn node_config(
rpc_cors: None,
rpc_methods: Default::default(),
prometheus_config: None,
telemetry_handle: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
default_heap_pages: None,
Expand Down

0 comments on commit a3d50f2

Please sign in to comment.