Skip to content

Commit 7c3623b

Browse files
Update weights template. (#1195)
Co-authored-by: Adam Dossa <[email protected]>
1 parent 87aa976 commit 7c3623b

File tree

1 file changed

+7
-48
lines changed

1 file changed

+7
-48
lines changed

.maintain/frame-weight-template.hbs

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,11 @@
2929
#![allow(unused_parens)]
3030
#![allow(unused_imports)]
3131

32-
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
33-
use sp_std::marker::PhantomData;
34-
35-
/// Weight functions needed for {{pallet}}.
36-
pub trait WeightInfo {
37-
{{~#each benchmarks as |benchmark|}}
38-
fn {{benchmark.name~}}
39-
(
40-
{{~#each benchmark.components as |c| ~}}
41-
{{c.name}}: u32, {{/each~}}
42-
) -> Weight;
43-
{{~/each}}
44-
}
32+
use polymesh_runtime_common::{RocksDbWeight as DbWeight, Weight};
4533

4634
/// Weights for {{pallet}} using the Substrate node and recommended hardware.
47-
pub struct SubstrateWeight<T>(PhantomData<T>);
48-
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
49-
{{~#each benchmarks as |benchmark|}}
50-
fn {{benchmark.name~}}
51-
(
52-
{{~#each benchmark.components as |c| ~}}
53-
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
54-
) -> Weight {
55-
({{underscore benchmark.base_weight}} as Weight)
56-
{{~#each benchmark.component_weight as |cw|}}
57-
// Standard Error: {{underscore cw.error}}
58-
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
59-
{{~/each}}
60-
{{~#if (ne benchmark.base_reads "0")}}
61-
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
62-
{{~/if}}
63-
{{~#each benchmark.component_reads as |cr|}}
64-
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
65-
{{~/each}}
66-
{{~#if (ne benchmark.base_writes "0")}}
67-
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
68-
{{~/if}}
69-
{{~#each benchmark.component_writes as |cw|}}
70-
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
71-
{{~/each}}
72-
}
73-
{{~/each}}
74-
}
75-
76-
// For backwards compatibility and tests
77-
impl WeightInfo for () {
35+
pub struct WeightInfo;
36+
impl {{pallet}}::WeightInfo for WeightInfo {
7837
{{~#each benchmarks as |benchmark|}}
7938
fn {{benchmark.name~}}
8039
(
@@ -87,16 +46,16 @@ impl WeightInfo for () {
8746
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
8847
{{~/each}}
8948
{{~#if (ne benchmark.base_reads "0")}}
90-
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
49+
.saturating_add(DbWeight::get().reads({{benchmark.base_reads}} as Weight))
9150
{{~/if}}
9251
{{~#each benchmark.component_reads as |cr|}}
93-
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
52+
.saturating_add(DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
9453
{{~/each}}
9554
{{~#if (ne benchmark.base_writes "0")}}
96-
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
55+
.saturating_add(DbWeight::get().writes({{benchmark.base_writes}} as Weight))
9756
{{~/if}}
9857
{{~#each benchmark.component_writes as |cw|}}
99-
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
58+
.saturating_add(DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
10059
{{~/each}}
10160
}
10261
{{~/each}}

0 commit comments

Comments
 (0)