referrerpolicy=no-referrer-when-downgrade

frame_benchmarking_cli/machine/
hardware.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Contains types to define hardware requirements.
19
20use sc_sysinfo::Requirements;
21use std::sync::LazyLock;
22
23/// The hardware requirements as measured on reference hardware.
24///
25/// These values are provided by Parity, however it is possible
26/// to use your own requirements if you are running a custom chain.
27pub static SUBSTRATE_REFERENCE_HARDWARE: LazyLock<Requirements> = LazyLock::new(|| {
28	let raw = include_bytes!("reference_hardware.json").as_slice();
29	serde_json::from_slice(raw).expect("Hardcoded data is known good; qed")
30});
31
32#[cfg(test)]
33mod tests {
34	use super::*;
35	use sc_sysinfo::{Metric, Requirement, Requirements, Throughput};
36
37	/// `SUBSTRATE_REFERENCE_HARDWARE` can be decoded.
38	#[test]
39	fn json_static_data() {
40		let raw = serde_json::to_string(&*SUBSTRATE_REFERENCE_HARDWARE).unwrap();
41		let decoded: Requirements = serde_json::from_str(&raw).unwrap();
42
43		assert_eq!(decoded, SUBSTRATE_REFERENCE_HARDWARE.clone());
44	}
45
46	/// The hard-coded values are correct.
47	#[test]
48	fn json_static_data_is_correct() {
49		assert_eq!(
50			*SUBSTRATE_REFERENCE_HARDWARE,
51			Requirements(vec![
52				Requirement {
53					metric: Metric::Blake2256,
54					minimum: Throughput::from_mibs(1000.00),
55					validator_only: false
56				},
57				Requirement {
58					metric: Metric::Blake2256Parallel { num_cores: 8 },
59					minimum: Throughput::from_mibs(1000.00),
60					validator_only: true,
61				},
62				Requirement {
63					metric: Metric::Sr25519Verify,
64					minimum: Throughput::from_kibs(637.619999744),
65					validator_only: false
66				},
67				Requirement {
68					metric: Metric::MemCopy,
69					minimum: Throughput::from_gibs(11.4925205078125003),
70					validator_only: false,
71				},
72				Requirement {
73					metric: Metric::DiskSeqWrite,
74					minimum: Throughput::from_mibs(950.0),
75					validator_only: false,
76				},
77				Requirement {
78					metric: Metric::DiskRndWrite,
79					minimum: Throughput::from_mibs(420.0),
80					validator_only: false
81				},
82			])
83		);
84	}
85}