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

Commit 355e4a9

Browse files
ggwpezbkchr
andauthored
Move slow hardware warning print logic to CLI (#13198)
* Move slow hardware warning print logic to CLI Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Update client/sysinfo/src/sysinfo.rs Co-authored-by: Bastian Köcher <[email protected]> * fmt Signed-off-by: Oliver Tale-Yazdi <[email protected]> Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 2c16842 commit 355e4a9

File tree

2 files changed

+39
-48
lines changed

2 files changed

+39
-48
lines changed

bin/node/cli/src/service.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,12 @@ pub fn new_full_base(
318318
&sc_consensus_babe::BabeLink<Block>,
319319
),
320320
) -> Result<NewFullBase, ServiceError> {
321-
let hwbench = if !disable_hardware_benchmarks {
322-
config.database.path().map(|database_path| {
321+
let hwbench = (!disable_hardware_benchmarks)
322+
.then_some(config.database.path().map(|database_path| {
323323
let _ = std::fs::create_dir_all(&database_path);
324-
sc_sysinfo::gather_hwbench(
325-
Some(database_path),
326-
SUBSTRATE_REFERENCE_HARDWARE.clone(),
327-
config.role.is_authority(),
328-
)
329-
})
330-
} else {
331-
None
332-
};
324+
sc_sysinfo::gather_hwbench(Some(database_path))
325+
}))
326+
.flatten();
333327

334328
let sc_service::PartialComponents {
335329
client,
@@ -403,6 +397,11 @@ pub fn new_full_base(
403397

404398
if let Some(hwbench) = hwbench {
405399
sc_sysinfo::print_hwbench(&hwbench);
400+
if !SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench) && role.is_authority() {
401+
log::warn!(
402+
"⚠️ The hardware does not meet the minimal requirements for role 'Authority'."
403+
);
404+
}
406405

407406
if let Some(ref mut telemetry) = telemetry {
408407
let telemetry_handle = telemetry.handle();

client/sysinfo/src/sysinfo.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,7 @@ pub fn benchmark_sr25519_verify(limit: ExecutionLimit) -> Throughput {
591591
/// Optionally accepts a path to a `scratch_directory` to use to benchmark the
592592
/// disk. Also accepts the `requirements` for the hardware benchmark and a
593593
/// boolean to specify if the node is an authority.
594-
pub fn gather_hwbench(
595-
scratch_directory: Option<&Path>,
596-
requirements: Requirements,
597-
is_authority: bool,
598-
) -> HwBench {
594+
pub fn gather_hwbench(scratch_directory: Option<&Path>) -> HwBench {
599595
#[allow(unused_mut)]
600596
let mut hwbench = HwBench {
601597
cpu_hashrate_score: benchmark_cpu(DEFAULT_CPU_EXECUTION_LIMIT),
@@ -625,42 +621,38 @@ pub fn gather_hwbench(
625621
};
626622
}
627623

628-
if is_authority {
629-
ensure_requirements(hwbench.clone(), requirements);
630-
}
631-
632624
hwbench
633625
}
634626

635-
fn ensure_requirements(hwbench: HwBench, requirements: Requirements) {
636-
let mut failed = 0;
637-
for requirement in requirements.0.iter() {
638-
match requirement.metric {
639-
Metric::Blake2256 =>
640-
if requirement.minimum > hwbench.cpu_hashrate_score {
641-
failed += 1;
642-
},
643-
Metric::MemCopy =>
644-
if requirement.minimum > hwbench.memory_memcpy_score {
645-
failed += 1;
646-
},
647-
Metric::DiskSeqWrite =>
648-
if let Some(score) = hwbench.disk_sequential_write_score {
649-
if requirement.minimum > score {
650-
failed += 1;
651-
}
652-
},
653-
Metric::DiskRndWrite =>
654-
if let Some(score) = hwbench.disk_random_write_score {
655-
if requirement.minimum > score {
656-
failed += 1;
657-
}
658-
},
659-
Metric::Sr25519Verify => {},
627+
impl Requirements {
628+
/// Whether the hardware requirements are met by the provided benchmark results.
629+
pub fn check_hardware(&self, hwbench: &HwBench) -> bool {
630+
for requirement in self.0.iter() {
631+
match requirement.metric {
632+
Metric::Blake2256 =>
633+
if requirement.minimum > hwbench.cpu_hashrate_score {
634+
return false
635+
},
636+
Metric::MemCopy =>
637+
if requirement.minimum > hwbench.memory_memcpy_score {
638+
return false
639+
},
640+
Metric::DiskSeqWrite =>
641+
if let Some(score) = hwbench.disk_sequential_write_score {
642+
if requirement.minimum > score {
643+
return false
644+
}
645+
},
646+
Metric::DiskRndWrite =>
647+
if let Some(score) = hwbench.disk_random_write_score {
648+
if requirement.minimum > score {
649+
return false
650+
}
651+
},
652+
Metric::Sr25519Verify => {},
653+
}
660654
}
661-
}
662-
if failed != 0 {
663-
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");
655+
true
664656
}
665657
}
666658

0 commit comments

Comments
 (0)