Skip to content

Commit 3aa2ad0

Browse files
committed
Fix for issue paritytech#11090
1 parent 77c15d2 commit 3aa2ad0

8 files changed

+345
-0
lines changed

Cargo.lock

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
resolver = "2"
33

44
members = [
5+
"bin/node-template/weights",
56
"bin/node-template/node",
67
"bin/node-template/pallets/template",
78
"bin/node-template/runtime",

bin/node-template/weights/Cargo.toml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[package]
2+
name = "node-template-weights"
3+
version = "4.0.0-dev"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2021"
6+
license = "Apache-2.0"
7+
homepage = "https://substrate.io"
8+
repository = "https://github.com/paritytech/substrate/"
9+
description = "Weights"
10+
11+
[package.metadata.docs.rs]
12+
targets = ["x86_64-unknown-linux-gnu"]
13+
14+
[dependencies]
15+
serde = { version = "1.0.136", optional = true, features = ["derive"] }
16+
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
17+
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
18+
frame-metadata = { version = "15.0.0", default-features = false, features = ["v14"] }
19+
sp-std = { version = "4.0.0", default-features = false, path = "../../../primitives/std" }
20+
sp-io = { version = "6.0.0", default-features = false, path = "../../../primitives/io" }
21+
sp-runtime = { version = "6.0.0", default-features = false, path = "../../../primitives/runtime" }
22+
sp-tracing = { version = "5.0.0", default-features = false, path = "../../../primitives/tracing" }
23+
sp-core = { version = "6.0.0", default-features = false, path = "../../../primitives/core" }
24+
sp-arithmetic = { version = "5.0.0", default-features = false, path = "../../../primitives/arithmetic" }
25+
sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/inherents" }
26+
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/staking" }
27+
tt-call = "1.0.8"
28+
frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support/procedural" }
29+
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support" }
30+
paste = "1.0"
31+
once_cell = { version = "1", default-features = false, optional = true }
32+
sp-state-machine = { version = "0.12.0", optional = true, path = "../../../primitives/state-machine" }
33+
bitflags = "1.3"
34+
impl-trait-for-tuples = "0.2.1"
35+
smallvec = "1.8.0"
36+
log = { version = "0.4.14", default-features = false }
37+
sp-core-hashing-proc-macro = { version = "5.0.0", path = "../../../primitives/core/hashing/proc-macro" }
38+
39+
[dev-dependencies]
40+
assert_matches = "1.3.0"
41+
pretty_assertions = "1.0.0"
42+
frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
43+
parity-util-mem = { version = "0.11.0", default-features = false, features = ["primitive-types"] }
44+
45+
[features]
46+
default = ["std"]
47+
std = [
48+
"frame-support/std",
49+
"once_cell",
50+
"serde",
51+
"sp-io/std",
52+
"codec/std",
53+
"scale-info/std",
54+
"sp-std/std",
55+
"sp-runtime/std",
56+
"sp-tracing/std",
57+
"sp-arithmetic/std",
58+
"frame-metadata/std",
59+
"sp-inherents/std",
60+
"sp-staking/std",
61+
"sp-state-machine",
62+
"frame-support-procedural/std",
63+
"log/std",
64+
]
65+
runtime-benchmarks = []
66+
try-runtime = []
67+
# By default some types have documentation, `no-metadata-docs` allows to reduce the documentation
68+
# in the metadata.
69+
no-metadata-docs = ["frame-support-procedural/no-metadata-docs"]
70+
# By default some types have documentation, `full-metadata-docs` allows to add documentation to
71+
# more types in the metadata.
72+
full-metadata-docs = ["scale-info/docs"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2022 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+
pub mod constants {
19+
use frame_support::{
20+
parameter_types,
21+
weights::{constants, Weight},
22+
};
23+
24+
parameter_types! {
25+
/// Importing a block with 0 Extrinsics.
26+
pub const BlockExecutionWeight: Weight = 5_000_000 * constants::WEIGHT_PER_NANOS;
27+
}
28+
29+
#[cfg(test)]
30+
mod test_weights {
31+
use frame_support::weights::constants;
32+
33+
/// Checks that the weight exists and is sane.
34+
// NOTE: If this test fails but you are sure that the generated values are fine,
35+
// you can delete it.
36+
#[test]
37+
fn sane() {
38+
let w = super::constants::BlockExecutionWeight::get();
39+
40+
// At least 100 µs.
41+
assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
42+
// At most 50 ms.
43+
assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2022 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+
pub mod constants {
19+
use frame_support::{
20+
parameter_types,
21+
weights::{constants, Weight},
22+
};
23+
24+
parameter_types! {
25+
/// Executing a NO-OP `System::remarks` Extrinsic.
26+
pub const ExtrinsicBaseWeight: Weight = 125_000 * constants::WEIGHT_PER_NANOS;
27+
}
28+
29+
#[cfg(test)]
30+
mod test_weights {
31+
use frame_support::weights::constants;
32+
33+
/// Checks that the weight exists and is sane.
34+
// NOTE: If this test fails but you are sure that the generated values are fine,
35+
// you can delete it.
36+
#[test]
37+
fn sane() {
38+
let w = super::constants::ExtrinsicBaseWeight::get();
39+
40+
// At least 10 µs.
41+
assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
42+
// At most 1 ms.
43+
assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms.");
44+
}
45+
}
46+
}

bin/node-template/weights/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2017-2022 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+
pub mod block_weights;
19+
pub mod extrinsic_weights;
20+
pub mod paritydb_weights;
21+
pub mod rocksdb_weights;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2022 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+
pub mod constants {
19+
use frame_support::{
20+
parameter_types,
21+
weights::{constants, RuntimeDbWeight},
22+
};
23+
24+
parameter_types! {
25+
/// ParityDB can be enabled with a feature flag, but is still experimental. These weights
26+
/// are available for brave runtime engineers who may want to try this out as default.
27+
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
28+
read: 8_000 * constants::WEIGHT_PER_NANOS,
29+
write: 50_000 * constants::WEIGHT_PER_NANOS,
30+
};
31+
}
32+
33+
#[cfg(test)]
34+
mod test_db_weights {
35+
use super::constants::ParityDbWeight as W;
36+
use frame_support::weights::constants;
37+
38+
/// Checks that all weights exist and have sane values.
39+
// NOTE: If this test fails but you are sure that the generated values are fine,
40+
// you can delete it.
41+
#[test]
42+
fn sane() {
43+
// At least 1 µs.
44+
assert!(
45+
W::get().reads(1) >= constants::WEIGHT_PER_MICROS,
46+
"Read weight should be at least 1 µs."
47+
);
48+
assert!(
49+
W::get().writes(1) >= constants::WEIGHT_PER_MICROS,
50+
"Write weight should be at least 1 µs."
51+
);
52+
// At most 1 ms.
53+
assert!(
54+
W::get().reads(1) <= constants::WEIGHT_PER_MILLIS,
55+
"Read weight should be at most 1 ms."
56+
);
57+
assert!(
58+
W::get().writes(1) <= constants::WEIGHT_PER_MILLIS,
59+
"Write weight should be at most 1 ms."
60+
);
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2022 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+
pub mod constants {
19+
use frame_support::{
20+
parameter_types,
21+
weights::{constants, RuntimeDbWeight},
22+
};
23+
24+
parameter_types! {
25+
/// By default, Substrate uses RocksDB, so this will be the weight used throughout
26+
/// the runtime.
27+
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
28+
read: 25_000 * constants::WEIGHT_PER_NANOS,
29+
write: 100_000 * constants::WEIGHT_PER_NANOS,
30+
};
31+
}
32+
33+
#[cfg(test)]
34+
mod test_db_weights {
35+
use super::constants::RocksDbWeight as W;
36+
use frame_support::weights::constants;
37+
38+
/// Checks that all weights exist and have sane values.
39+
// NOTE: If this test fails but you are sure that the generated values are fine,
40+
// you can delete it.
41+
#[test]
42+
fn sane() {
43+
// At least 1 µs.
44+
assert!(
45+
W::get().reads(1) >= constants::WEIGHT_PER_MICROS,
46+
"Read weight should be at least 1 µs."
47+
);
48+
assert!(
49+
W::get().writes(1) >= constants::WEIGHT_PER_MICROS,
50+
"Write weight should be at least 1 µs."
51+
);
52+
// At most 1 ms.
53+
assert!(
54+
W::get().reads(1) <= constants::WEIGHT_PER_MILLIS,
55+
"Read weight should be at most 1 ms."
56+
);
57+
assert!(
58+
W::get().writes(1) <= constants::WEIGHT_PER_MILLIS,
59+
"Write weight should be at most 1 ms."
60+
);
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)