referrerpolicy=no-referrer-when-downgrade

frame_support/weights/
rocksdb_weights.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
18pub mod constants {
19	use frame_support::weights::constants;
20	use sp_core::parameter_types;
21	use sp_weights::RuntimeDbWeight;
22
23	parameter_types! {
24		/// By default, Substrate uses RocksDB, so this will be the weight used throughout
25		/// the runtime.
26		pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
27			read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
28			write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
29		};
30	}
31
32	#[cfg(test)]
33	mod test_db_weights {
34		use super::constants::RocksDbWeight as W;
35		use sp_weights::constants;
36
37		/// Checks that all weights exist and have sane values.
38		// NOTE: If this test fails but you are sure that the generated values are fine,
39		// you can delete it.
40		#[test]
41		fn sane() {
42			// At least 1 µs.
43			assert!(
44				W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
45				"Read weight should be at least 1 µs."
46			);
47			assert!(
48				W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
49				"Write weight should be at least 1 µs."
50			);
51			// At most 1 ms.
52			assert!(
53				W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
54				"Read weight should be at most 1 ms."
55			);
56			assert!(
57				W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
58				"Write weight should be at most 1 ms."
59			);
60		}
61	}
62}