Skip to content

Commit 9584dbd

Browse files
kianenigmagui1117re-giusseadandashawntabrizi
authored
Use frame umbrella crate in pallet-proxy and pallet-multisig (#5995)
A step towards #4782 In order to nail down the right preludes in `polkadot-sdk-frame`, we need to migrate a number of pallets to be written with it. Moreover, migrating our pallets to this simpler patter will encourage the ecosystem to also follow along. If this PR is approved and has no unwanted negative consequences, I will make a tracking issue to migrate all pallets to this umbrella crate. TODO: - [x] fix frame benchmarking template. Can we detect the umbrella crate in there and have an `if else`? cc @ggwpez - [x] Migrate benchmarking to v2 @re-gius a good candidate for you, you can open a PR against my branch. - [x] tracking issue with follow-ups --------- Co-authored-by: Guillaume Thiolliere <[email protected]> Co-authored-by: Giuseppe Re <[email protected]> Co-authored-by: Dónal Murray <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]>
1 parent 35535ef commit 9584dbd

File tree

21 files changed

+735
-337
lines changed

21 files changed

+735
-337
lines changed

.github/scripts/cmd/cmd.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import argparse
77
import _help
88
import importlib.util
9+
import re
910

1011
_HelpAction = _help._HelpAction
1112

@@ -40,20 +41,20 @@ def setup_logging():
4041
setup_logging()
4142

4243
"""
43-
BENCH
44+
BENCH
4445
"""
4546

4647
bench_example = '''**Examples**:
47-
Runs all benchmarks
48+
Runs all benchmarks
4849
%(prog)s
4950
5051
Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions
5152
%(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
52-
53+
5354
Runs bench for all pallets for westend runtime and fails fast on first failed benchmark
5455
%(prog)s --runtime westend --fail-fast
55-
56-
Does not output anything and cleans up the previous bot's & author command triggering comments in PR
56+
57+
Does not output anything and cleans up the previous bot's & author command triggering comments in PR
5758
%(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean
5859
'''
5960

@@ -67,14 +68,14 @@ def setup_logging():
6768
parser_bench.add_argument('--fail-fast', help='Fail fast on first failed benchmark', action='store_true')
6869

6970
"""
70-
FMT
71+
FMT
7172
"""
7273
parser_fmt = subparsers.add_parser('fmt', help='Formats code (cargo +nightly-VERSION fmt) and configs (taplo format)')
7374
for arg, config in common_args.items():
7475
parser_fmt.add_argument(arg, **config)
7576

7677
"""
77-
Update UI
78+
Update UI
7879
"""
7980
parser_ui = subparsers.add_parser('update-ui', help='Updates UI tests')
8081
for arg, config in common_args.items():
@@ -175,7 +176,15 @@ def main():
175176
print(f'-- package_dir: {package_dir}')
176177
print(f'-- manifest_path: {manifest_path}')
177178
output_path = os.path.join(package_dir, "src", "weights.rs")
179+
# TODO: we can remove once all pallets in dev runtime are migrated to polkadot-sdk-frame
180+
try:
181+
uses_polkadot_sdk_frame = "true" in os.popen(f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \"{pallet.replace('_', '-')}\") | .dependencies | any(.name == \"polkadot-sdk-frame\")'").read()
182+
# Empty output from the previous os.popen command
183+
except StopIteration:
184+
uses_polkadot_sdk_frame = False
178185
template = config['template']
186+
if uses_polkadot_sdk_frame and re.match(r"frame-(:?umbrella-)?weight-template\.hbs", os.path.normpath(template).split(os.path.sep)[-1]):
187+
template = "substrate/.maintain/frame-umbrella-weight-template.hbs"
179188
else:
180189
default_path = f"./{config['path']}/src/weights"
181190
xcm_path = f"./{config['path']}/src/weights/xcm"
@@ -251,4 +260,4 @@ def main():
251260
print('🚀 Done')
252261

253262
if __name__ == '__main__':
254-
main()
263+
main()

Cargo.lock

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prdoc/pr_5995.prdoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Use frame umbrella crate in pallet-proxy and pallet-multisig
5+
6+
doc:
7+
- audience: Runtime Dev
8+
description: |
9+
Extends the FRAME umbrella crate and uses it in pallet-proxy and pallet-multisig.
10+
Migrates benchmarking from v1 to v2 for pallet-proxy and pallet-multisig.
11+
Allows CI to pick the umbrella crate weights template to run benchmarks.
12+
13+
crates:
14+
- name: pallet-multisig
15+
bump: minor
16+
- name: pallet-proxy
17+
bump: minor
18+
- name: polkadot-sdk-frame
19+
bump: major
20+
- name: pallet-migrations
21+
bump: patch
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{{header}}
2+
//! Autogenerated weights for `{{pallet}}`
3+
//!
4+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
5+
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
6+
//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}`
7+
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
8+
//! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: `{{cmd.db_cache}}`
9+
10+
// Executed Command:
11+
{{#each args as |arg|}}
12+
// {{arg}}
13+
{{/each}}
14+
15+
#![cfg_attr(rustfmt, rustfmt_skip)]
16+
#![allow(unused_parens)]
17+
#![allow(unused_imports)]
18+
#![allow(missing_docs)]
19+
20+
use frame::weights_prelude::*;
21+
22+
/// Weight functions needed for `{{pallet}}`.
23+
pub trait WeightInfo {
24+
{{#each benchmarks as |benchmark|}}
25+
fn {{benchmark.name~}}
26+
(
27+
{{~#each benchmark.components as |c| ~}}
28+
{{c.name}}: u32, {{/each~}}
29+
) -> Weight;
30+
{{/each}}
31+
}
32+
33+
/// Weights for `{{pallet}}` using the Substrate node and recommended hardware.
34+
pub struct SubstrateWeight<T>(PhantomData<T>);
35+
{{#if (eq pallet "frame_system")}}
36+
impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
37+
{{else}}
38+
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
39+
{{/if}}
40+
{{#each benchmarks as |benchmark|}}
41+
{{#each benchmark.comments as |comment|}}
42+
/// {{comment}}
43+
{{/each}}
44+
{{#each benchmark.component_ranges as |range|}}
45+
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
46+
{{/each}}
47+
fn {{benchmark.name~}}
48+
(
49+
{{~#each benchmark.components as |c| ~}}
50+
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
51+
) -> Weight {
52+
// Proof Size summary in bytes:
53+
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
54+
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
55+
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
56+
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
57+
{{#each benchmark.component_weight as |cw|}}
58+
// Standard Error: {{underscore cw.error}}
59+
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
60+
{{/each}}
61+
{{#if (ne benchmark.base_reads "0")}}
62+
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64))
63+
{{/if}}
64+
{{#each benchmark.component_reads as |cr|}}
65+
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
66+
{{/each}}
67+
{{#if (ne benchmark.base_writes "0")}}
68+
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64))
69+
{{/if}}
70+
{{#each benchmark.component_writes as |cw|}}
71+
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
72+
{{/each}}
73+
{{#each benchmark.component_calculated_proof_size as |cp|}}
74+
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
75+
{{/each}}
76+
}
77+
{{/each}}
78+
}
79+
80+
// For backwards compatibility and tests.
81+
impl WeightInfo for () {
82+
{{#each benchmarks as |benchmark|}}
83+
{{#each benchmark.comments as |comment|}}
84+
/// {{comment}}
85+
{{/each}}
86+
{{#each benchmark.component_ranges as |range|}}
87+
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
88+
{{/each}}
89+
fn {{benchmark.name~}}
90+
(
91+
{{~#each benchmark.components as |c| ~}}
92+
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
93+
) -> Weight {
94+
// Proof Size summary in bytes:
95+
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
96+
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
97+
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
98+
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
99+
{{#each benchmark.component_weight as |cw|}}
100+
// Standard Error: {{underscore cw.error}}
101+
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
102+
{{/each}}
103+
{{#if (ne benchmark.base_reads "0")}}
104+
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64))
105+
{{/if}}
106+
{{#each benchmark.component_reads as |cr|}}
107+
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
108+
{{/each}}
109+
{{#if (ne benchmark.base_writes "0")}}
110+
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64))
111+
{{/if}}
112+
{{#each benchmark.component_writes as |cw|}}
113+
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
114+
{{/each}}
115+
{{#each benchmark.component_calculated_proof_size as |cp|}}
116+
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
117+
{{/each}}
118+
}
119+
{{/each}}
120+
}

substrate/frame/migrations/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mod benches {
158158
fn on_init_loop() {
159159
T::Migrations::set_fail_after(0); // Should not be called anyway.
160160
System::<T>::set_block_number(1u32.into());
161-
Pallet::<T>::on_runtime_upgrade();
161+
<Pallet<T> as Hooks<BlockNumberFor<T>>>::on_runtime_upgrade();
162162

163163
#[block]
164164
{

substrate/frame/multisig/Cargo.toml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1818
[dependencies]
1919
codec = { workspace = true }
2020
scale-info = { features = ["derive"], workspace = true }
21-
frame-benchmarking = { optional = true, workspace = true }
22-
frame-support = { workspace = true }
23-
frame-system = { workspace = true }
24-
sp-io = { workspace = true }
25-
sp-runtime = { workspace = true }
21+
frame = { workspace = true, features = ["experimental", "runtime"] }
2622

2723
# third party
2824
log = { workspace = true }
@@ -34,25 +30,15 @@ pallet-balances = { workspace = true, default-features = true }
3430
default = ["std"]
3531
std = [
3632
"codec/std",
37-
"frame-benchmarking?/std",
38-
"frame-support/std",
39-
"frame-system/std",
33+
"frame/std",
4034
"log/std",
41-
"pallet-balances/std",
4235
"scale-info/std",
43-
"sp-io/std",
44-
"sp-runtime/std",
4536
]
4637
runtime-benchmarks = [
47-
"frame-benchmarking/runtime-benchmarks",
48-
"frame-support/runtime-benchmarks",
49-
"frame-system/runtime-benchmarks",
38+
"frame/runtime-benchmarks",
5039
"pallet-balances/runtime-benchmarks",
51-
"sp-runtime/runtime-benchmarks",
5240
]
5341
try-runtime = [
54-
"frame-support/try-runtime",
55-
"frame-system/try-runtime",
42+
"frame/try-runtime",
5643
"pallet-balances/try-runtime",
57-
"sp-runtime/try-runtime",
5844
]

0 commit comments

Comments
 (0)