Skip to main content

topsoil_core/weights/
rocksdb_weights.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later WITH Classpath-exception-2.0
6
7pub mod constants {
8	use subsoil::core::parameter_types;
9	use subsoil::weights::RuntimeDbWeight;
10	use topsoil_core::weights::constants;
11
12	parameter_types! {
13		/// By default, Substrate uses RocksDB, so this will be the weight used throughout
14		/// the runtime.
15		pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
16			read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
17			write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
18		};
19	}
20
21	#[cfg(test)]
22	mod test_db_weights {
23		use super::constants::RocksDbWeight as W;
24		use subsoil::weights::constants;
25
26		/// Checks that all weights exist and have sane values.
27		// NOTE: If this test fails but you are sure that the generated values are fine,
28		// you can delete it.
29		#[test]
30		fn sane() {
31			// At least 1 µs.
32			assert!(
33				W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
34				"Read weight should be at least 1 µs."
35			);
36			assert!(
37				W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
38				"Write weight should be at least 1 µs."
39			);
40			// At most 1 ms.
41			assert!(
42				W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
43				"Read weight should be at most 1 ms."
44			);
45			assert!(
46				W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
47				"Write weight should be at most 1 ms."
48			);
49		}
50	}
51}