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

Companion for Substrate#11062 #1113

Merged
merged 11 commits into from
Apr 26, 2022
505 changes: 259 additions & 246 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/relay-chain-inprocess-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sc-network = { 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-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
11 changes: 9 additions & 2 deletions client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ fn build_polkadot_full_node(
config: Configuration,
parachain_config: &Configuration,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
hwbench: Option<sc_sysinfo::HwBench>,
) -> Result<(NewFull<polkadot_client::Client>, Option<CollatorPair>), polkadot_service::Error> {
let is_light = matches!(config.role, Role::Light);
if is_light {
Expand All @@ -348,6 +349,7 @@ fn build_polkadot_full_node(
telemetry_worker_handle,
true,
polkadot_service::RealOverseerGen,
hwbench,
)?;

Ok((relay_chain_full_node, maybe_collator_key))
Expand All @@ -360,9 +362,14 @@ pub fn build_inprocess_relay_chain(
parachain_config: &Configuration,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
task_manager: &mut TaskManager,
hwbench: Option<sc_sysinfo::HwBench>,
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
let (full_node, collator_key) =
build_polkadot_full_node(polkadot_config, parachain_config, telemetry_worker_handle)?;
let (full_node, collator_key) = build_polkadot_full_node(
polkadot_config,
parachain_config,
telemetry_worker_handle,
hwbench,
)?;

let sync_oracle: Box<dyn SyncOracle + Send + Sync> = Box::new(full_node.network.clone());
let sync_oracle = Arc::new(Mutex::new(sync_oracle));
Expand Down
1 change: 1 addition & 0 deletions parachain-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "master
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
sc-sysinfo = { 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-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
10 changes: 10 additions & 0 deletions parachain-template/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ pub struct Cli {
#[clap(flatten)]
pub run: cumulus_client_cli::RunCmd,

/// Disable automatic hardware benchmarks.
///
/// By default these benchmarks are automatically ran at startup and measure
/// the CPU speed, the memory bandwidth and the disk speed.
///
/// The results are then printed out in the logs, and also sent as part of
/// telemetry, if telemetry is enabled.
#[clap(long)]
pub no_hardware_benchmarks: bool,

/// Relay chain arguments
#[clap(raw = true)]
pub relay_chain_args: Vec<String>,
Expand Down
23 changes: 19 additions & 4 deletions parachain-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ pub fn run() -> Result<()> {
let collator_options = cli.run.collator_options();

runner.run_node_until_exit(|config| async move {
let hwbench = if !cli.no_hardware_benchmarks {
config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(&database_path);
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
sc_sysinfo::gather_hwbench(Some(database_path))
})
} else {
None
};

let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or_else(|| "Could not find parachain ID in chain-spec.")?;
Expand Down Expand Up @@ -317,10 +326,16 @@ pub fn run() -> Result<()> {
info!("Parachain genesis state: {}", genesis_state);
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

crate::service::start_parachain_node(config, polkadot_config, collator_options, id)
.await
.map(|r| r.0)
.map_err(Into::into)
crate::service::start_parachain_node(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into)
})
},
}
Expand Down
19 changes: 19 additions & 0 deletions parachain-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async fn build_relay_chain_interface(
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
task_manager: &mut TaskManager,
collator_options: CollatorOptions,
hwbench: Option<sc_sysinfo::HwBench>,
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
match collator_options.relay_chain_rpc_url {
Some(relay_chain_url) =>
Expand All @@ -179,6 +180,7 @@ async fn build_relay_chain_interface(
parachain_config,
telemetry_worker_handle,
task_manager,
hwbench,
),
}
}
Expand All @@ -195,6 +197,7 @@ async fn start_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
_rpc_ext_builder: RB,
build_import_queue: BIQ,
build_consensus: BIC,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(
TaskManager,
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
Expand Down Expand Up @@ -270,6 +273,7 @@ where
telemetry_worker_handle,
&mut task_manager,
collator_options.clone(),
hwbench.clone(),
)
.await
.map_err(|e| match e {
Expand Down Expand Up @@ -325,6 +329,19 @@ where
telemetry: telemetry.as_mut(),
})?;

if let Some(hwbench) = hwbench {
sc_sysinfo::print_hwbench(&hwbench);

if let Some(ref mut telemetry) = telemetry {
let telemetry_handle = telemetry.handle();
task_manager.spawn_handle().spawn(
"telemetry_hwbench",
None,
sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
);
}
}

let announce_block = {
let network = network.clone();
Arc::new(move |hash, data| network.announce_block(hash, data))
Expand Down Expand Up @@ -434,6 +451,7 @@ pub async fn start_parachain_node(
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(
TaskManager,
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<TemplateRuntimeExecutor>>>,
Expand Down Expand Up @@ -508,6 +526,7 @@ pub async fn start_parachain_node(
},
))
},
hwbench,
)
.await
}
1 change: 1 addition & 0 deletions polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
10 changes: 10 additions & 0 deletions polkadot-parachains/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ pub struct Cli {
#[clap(flatten)]
pub run: cumulus_client_cli::RunCmd,

/// Disable automatic hardware benchmarks.
///
/// By default these benchmarks are automatically ran at startup and measure
/// the CPU speed, the memory bandwidth and the disk speed.
///
/// The results are then printed out in the logs, and also sent as part of
/// telemetry, if telemetry is enabled.
#[clap(long)]
pub no_hardware_benchmarks: bool,

/// Relay chain arguments
#[clap(raw = true, conflicts_with = "relay-chain-rpc-url")]
pub relaychain_args: Vec<String>,
Expand Down
17 changes: 16 additions & 1 deletion polkadot-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ pub fn run() -> Result<()> {
let collator_options = cli.run.collator_options();

runner.run_node_until_exit(|config| async move {
let hwbench = if !cli.no_hardware_benchmarks {
config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(&database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
})
} else {
None
};

let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or_else(|| "Could not find parachain extension in chain-spec.")?;
Expand Down Expand Up @@ -581,7 +590,7 @@ pub fn run() -> Result<()> {
crate::service::start_statemint_node::<
statemint_runtime::RuntimeApi,
StatemintAuraId,
>(config, polkadot_config, collator_options, id)
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into)
Expand All @@ -591,6 +600,7 @@ pub fn run() -> Result<()> {
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
Expand All @@ -601,6 +611,7 @@ pub fn run() -> Result<()> {
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
Expand All @@ -611,6 +622,7 @@ pub fn run() -> Result<()> {
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
Expand All @@ -621,6 +633,7 @@ pub fn run() -> Result<()> {
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
Expand All @@ -631,6 +644,7 @@ pub fn run() -> Result<()> {
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
Expand All @@ -641,6 +655,7 @@ pub fn run() -> Result<()> {
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
Expand Down
Loading