parachain_template_runtime/weights/paritydb_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 polkadot_sdk::*;
20
21 use frame_support::{
22 parameter_types,
23 weights::{constants, RuntimeDbWeight},
24 };
25
26 parameter_types! {
27 /// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights
28 /// are available for brave runtime engineers who may want to try this out as default.
29 pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
30 read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
31 write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
32 };
33 }
34
35 #[cfg(test)]
36 mod test_db_weights {
37 use polkadot_sdk::*;
38
39 use super::constants::ParityDbWeight as W;
40 use frame_support::weights::constants;
41
42 /// Checks that all weights exist and have sane values.
43 // NOTE: If this test fails but you are sure that the generated values are fine,
44 // you can delete it.
45 #[test]
46 fn sane() {
47 // At least 1 µs.
48 assert!(
49 W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
50 "Read weight should be at least 1 µs."
51 );
52 assert!(
53 W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
54 "Write weight should be at least 1 µs."
55 );
56 // At most 1 ms.
57 assert!(
58 W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
59 "Read weight should be at most 1 ms."
60 );
61 assert!(
62 W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
63 "Write weight should be at most 1 ms."
64 );
65 }
66 }
67}