From 1e75ee65be38114f87f5802e8b2ba1a6d62f3bca Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 20 Jan 2023 22:52:28 +0100 Subject: [PATCH 1/3] Move slow hardware warning print logic to CLI Signed-off-by: Oliver Tale-Yazdi --- bin/node/cli/src/service.rs | 17 +++++---- client/sysinfo/src/sysinfo.rs | 66 +++++++++++++++-------------------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index ace24f186d4c2..c6a9723602918 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -318,18 +318,12 @@ pub fn new_full_base( &sc_consensus_babe::BabeLink, ), ) -> Result { - let hwbench = if !disable_hardware_benchmarks { + let hwbench = (!disable_hardware_benchmarks).then_some( config.database.path().map(|database_path| { let _ = std::fs::create_dir_all(&database_path); - sc_sysinfo::gather_hwbench( - Some(database_path), - SUBSTRATE_REFERENCE_HARDWARE.clone(), - config.role.is_authority(), - ) + sc_sysinfo::gather_hwbench(Some(database_path)) }) - } else { - None - }; + ).flatten(); let sc_service::PartialComponents { client, @@ -403,6 +397,11 @@ pub fn new_full_base( if let Some(hwbench) = hwbench { sc_sysinfo::print_hwbench(&hwbench); + if !SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench) && role.is_authority() { + log::warn!( + "⚠️ The hardware does not meet the minimal requirements for role 'Authority'." + ); + } if let Some(ref mut telemetry) = telemetry { let telemetry_handle = telemetry.handle(); diff --git a/client/sysinfo/src/sysinfo.rs b/client/sysinfo/src/sysinfo.rs index 800df4b8a41a9..1ee9b398de55b 100644 --- a/client/sysinfo/src/sysinfo.rs +++ b/client/sysinfo/src/sysinfo.rs @@ -591,11 +591,7 @@ pub fn benchmark_sr25519_verify(limit: ExecutionLimit) -> Throughput { /// Optionally accepts a path to a `scratch_directory` to use to benchmark the /// disk. Also accepts the `requirements` for the hardware benchmark and a /// boolean to specify if the node is an authority. -pub fn gather_hwbench( - scratch_directory: Option<&Path>, - requirements: Requirements, - is_authority: bool, -) -> HwBench { +pub fn gather_hwbench(scratch_directory: Option<&Path>) -> HwBench { #[allow(unused_mut)] let mut hwbench = HwBench { cpu_hashrate_score: benchmark_cpu(DEFAULT_CPU_EXECUTION_LIMIT), @@ -625,42 +621,38 @@ pub fn gather_hwbench( }; } - if is_authority { - ensure_requirements(hwbench.clone(), requirements); - } - hwbench } -fn ensure_requirements(hwbench: HwBench, requirements: Requirements) { - let mut failed = 0; - for requirement in requirements.0.iter() { - match requirement.metric { - Metric::Blake2256 => - if requirement.minimum > hwbench.cpu_hashrate_score { - failed += 1; - }, - Metric::MemCopy => - if requirement.minimum > hwbench.memory_memcpy_score { - failed += 1; - }, - Metric::DiskSeqWrite => - if let Some(score) = hwbench.disk_sequential_write_score { - if requirement.minimum > score { - failed += 1; - } - }, - Metric::DiskRndWrite => - if let Some(score) = hwbench.disk_random_write_score { - if requirement.minimum > score { - failed += 1; - } - }, - Metric::Sr25519Verify => {}, +impl Requirements { + /// Whether the hardware requirements are met by the provided benchmark results. + pub fn check_hardware(&self, hwbench: &HwBench) -> bool { + for requirement in self.0.iter() { + match requirement.metric { + Metric::Blake2256 => + if requirement.minimum > hwbench.cpu_hashrate_score { + return false + }, + Metric::MemCopy => + if requirement.minimum > hwbench.memory_memcpy_score { + return false + }, + Metric::DiskSeqWrite => + if let Some(score) = hwbench.disk_sequential_write_score { + if requirement.minimum > score { + return false + } + }, + Metric::DiskRndWrite => + if let Some(score) = hwbench.disk_random_write_score { + if requirement.minimum > score { + return false + } + }, + Metric::Sr25519Verify => {}, + } } - } - if failed != 0 { - log::warn!("⚠️ Your hardware performance score was less than expected for role 'Authority'. See https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#reference-hardware"); + return true } } From 34823faad892f54ae69ad33df8e14c1b3606a700 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 20 Jan 2023 23:07:38 +0100 Subject: [PATCH 2/3] Update client/sysinfo/src/sysinfo.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/sysinfo/src/sysinfo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/sysinfo/src/sysinfo.rs b/client/sysinfo/src/sysinfo.rs index 1ee9b398de55b..1fbca7d37efb7 100644 --- a/client/sysinfo/src/sysinfo.rs +++ b/client/sysinfo/src/sysinfo.rs @@ -652,7 +652,7 @@ impl Requirements { Metric::Sr25519Verify => {}, } } - return true + true } } From 94d6aecdf24179e20902cef3553c96322a848b27 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 20 Jan 2023 23:07:59 +0100 Subject: [PATCH 3/3] fmt Signed-off-by: Oliver Tale-Yazdi --- bin/node/cli/src/service.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index c6a9723602918..d77a333dfa220 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -318,12 +318,12 @@ pub fn new_full_base( &sc_consensus_babe::BabeLink, ), ) -> Result { - let hwbench = (!disable_hardware_benchmarks).then_some( - config.database.path().map(|database_path| { + let hwbench = (!disable_hardware_benchmarks) + .then_some(config.database.path().map(|database_path| { let _ = std::fs::create_dir_all(&database_path); sc_sysinfo::gather_hwbench(Some(database_path)) - }) - ).flatten(); + })) + .flatten(); let sc_service::PartialComponents { client,