Skip to content

Commit

Permalink
Update pallet-benchmarks to weights-v2 (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj authored Apr 24, 2023
1 parent 5af2ca9 commit b98fb70
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 81 deletions.
49 changes: 32 additions & 17 deletions .maintain/webb-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

{{header}}
//! Autogenerated weights for {{pallet}}
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}`
//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}

// Executed Command:
Expand All @@ -32,7 +33,7 @@
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
use core::marker::PhantomData;

/// Weight functions needed for {{pallet}}.
pub trait WeightInfo {
Expand All @@ -54,7 +55,7 @@ impl<T: frame_system::Config> WeightInfo for WebbWeight<T> {
{{/if}}
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
// {{comment}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
Expand All @@ -64,22 +65,29 @@ impl<T: frame_system::Config> WeightInfo for WebbWeight<T> {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as Weight)
// Proof Size summary in bytes:
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
Expand All @@ -89,7 +97,7 @@ impl<T: frame_system::Config> WeightInfo for WebbWeight<T> {
impl WeightInfo for () {
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
// {{comment}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
Expand All @@ -99,22 +107,29 @@ impl WeightInfo for () {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as Weight)
// Proof Size summary in bytes:
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-li
orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false }
num-bigint = { version = "0.4", default-features = false, features = ["rand"] }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
# For ark-circom
once_cell = "1.14.0"
cfg-if = "1.0"
Expand All @@ -58,10 +57,5 @@ default = ["std", "wasmer/sys-default"]
std = [
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
]
runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
wasm = ["wasmer/js", "wasmer/std"]
7 changes: 2 additions & 5 deletions pallets/anonymity-mining-claims/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ use ark_relations::r1cs::ConstraintMatrices;
use ark_serialize::CanonicalSerialize;
use circom_proving::circom_from_folder;
use frame_benchmarking::account;
use frame_support::{assert_err, assert_ok};
use frame_support::assert_ok;
use num_bigint::{BigInt, Sign};
use webb_primitives::{
webb_proposals::{ResourceId, SubstrateTargetSystem, TargetSystem, TypedChainId},
ElementTrait,
};
use webb_primitives::ElementTrait;

use std::{convert::TryInto, fs::File, str::FromStr, sync::Mutex};

Expand Down
1 change: 0 additions & 1 deletion pallets/anonymity-mining-claims/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ark_serialize::CanonicalSerialize;
use frame_support::{assert_err, assert_ok};
// use sp_runtime::traits::Zero;

use ark_bn254::{Bn254, Fr};
use circom_proving::{generate_proof, verify_proof};
// use num_bigint::{BigInt, Sign};
use webb_primitives::webb_proposals::{
Expand Down
4 changes: 2 additions & 2 deletions pallets/claims-verifier/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ benchmarks_instance_pallet! {
let c in 0..MAX_VERIFIER_LENGTH;
let depositor: T::AccountId = account("depositor", 0, SEED);
let parameters = vec![0u8;c as usize];
}: _(RawOrigin::Root, (1u8,1u8), parameters.clone().try_into().unwrap())
}: _(RawOrigin::Root, 1u8, parameters.clone().try_into().unwrap())
verify {
assert_eq!(Pallet::<T, I>::parameters((1u8,1u8)), parameters);
assert_eq!(Pallet::<T, I>::parameters(1u8), parameters);
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/hasher/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const SEED: u32 = 0;
// poseidon_bls381_x3_5
// poseidon_circom_bn254_x5_5
// poseidon_circom_bn254_x5_3
const MAX_PARAMETER_LENGTH: u32 = 20000;
const MAX_PARAMETER_LENGTH: u32 = 10000;

benchmarks_instance_pallet! {
force_set_parameters {
Expand Down
37 changes: 27 additions & 10 deletions pallets/hasher/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.


//! Autogenerated weights for pallet_hasher
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-06-14, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: ``, CPU: ``
//! DATE: 2023-04-24, STEPS: `20`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
Expand All @@ -28,7 +29,7 @@
// pallet
// --chain=dev
// --steps=20
// --repeat=10
// --repeat=1
// --log=warn
// --pallet=pallet-hasher
// --extrinsic=*
Expand All @@ -42,7 +43,7 @@
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
use core::marker::PhantomData;

/// Weight functions needed for pallet_hasher.
pub trait WeightInfo {
Expand All @@ -52,19 +53,35 @@ pub trait WeightInfo {
/// Weights for pallet_hasher using the Substrate node and recommended hardware.
pub struct WebbWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for WebbWeight<T> {
// Storage: HasherBn254 Parameters (r:1 w:1)
fn force_set_parameters(_c: u32, ) -> Weight {
Weight::from_ref_time(8_102_000)
/// Storage: HasherBn254 Parameters (r:1 w:1)
/// Proof: HasherBn254 Parameters (max_values: Some(1), max_size: Some(10002), added: 10497, mode: MaxEncodedLen)
/// The range of component `c` is `[0, 10000]`.
fn force_set_parameters(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `6604`
// Estimated: `10497`
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(18_214_525, 10497)
// Standard Error: 186
.saturating_add(Weight::from_parts(527, 0).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: HasherBn254 Parameters (r:1 w:1)
fn force_set_parameters(_c: u32, ) -> Weight {
Weight::from_ref_time(8_102_000)
/// Storage: HasherBn254 Parameters (r:1 w:1)
/// Proof: HasherBn254 Parameters (max_values: Some(1), max_size: Some(10002), added: 10497, mode: MaxEncodedLen)
/// The range of component `c` is `[0, 10000]`.
fn force_set_parameters(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `6604`
// Estimated: `10497`
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(18_214_525, 10497)
// Standard Error: 186
.saturating_add(Weight::from_parts(527, 0).saturating_mul(c.into()))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/key-storage/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

const MAX_PARAMETER_LENGTH: u32 = 20000;
const MAX_PARAMETER_LENGTH: u32 = 10000;

benchmarks_instance_pallet! {
register {
Expand Down
2 changes: 1 addition & 1 deletion pallets/linkable-tree/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use sc_rpc::DenyUnsafe;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use sp_runtime::traits::Block as BlockT;

use pallet_linkable_tree::types::EdgeMetadata;
use pallet_linkable_tree_rpc_runtime_api::LinkableTreeApi;
Expand Down
10 changes: 4 additions & 6 deletions pallets/mixer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
use super::*;

use frame_benchmarking::{
account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelist_account,
whitelisted_caller,
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
};
use frame_system::RawOrigin;
use orml_traits::MultiCurrency;
Expand Down Expand Up @@ -63,8 +62,7 @@ benchmarks_instance_pallet! {

let tree_id = <Mixer<T, I> as MixerInterface<_,_,_,_,_>>::create(None, deposit_size.into(), depth, asset_id)?;
let leaf = <T as pallet_mt::Config<I>>::Element::from_bytes(&[1u8; 32]);
<<T as pallet_mt::Config<I>>::Currency as Currency<T::AccountId>>::make_free_balance_be(&caller.clone(), 200_000_000u32.into());

<<T as pallet_mt::Config<I>>::Currency as Currency<T::AccountId>>::make_free_balance_be(&caller.clone(), 900_000_000u32.into());
}: _(RawOrigin::Signed(caller.clone()), tree_id, leaf)
verify {
assert_eq!(<<T as Config<I>>::Currency as MultiCurrency<T::AccountId>>::total_balance(asset_id, &Pallet::<T, I>::account_id()), deposit_size.into())
Expand Down Expand Up @@ -136,6 +134,6 @@ benchmarks_instance_pallet! {
assert_eq!(<<T as Config<I>>::Currency as MultiCurrency<T::AccountId>>::total_balance(asset_id, &recipient_account_id), (100_000_000u32 + deposit_size).into())
}

}
impl_benchmark_test_suite!(Mixer, crate::mock::new_bench_ext(), crate::mock::Test);

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
21 changes: 15 additions & 6 deletions pallets/mixer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
use super::*;
use crate as pallet_mixer;
use codec::Decode;
use frame_support::traits::GenesisBuild;
use sp_core::H256;
use webb_primitives::verifying::ArkworksVerifierBn254;

use frame_support::{parameter_types, traits::Nothing};
use frame_support::{
parameter_types,
traits::{GenesisBuild, Nothing},
};
use frame_system as system;
use orml_currencies::{BasicCurrencyAdapter, NativeCurrencyOf};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, ConstU32, IdentityLookup},
BuildStorage,
};
use sp_std::convert::{TryFrom, TryInto};
pub use webb_primitives::hasher::{HasherModule, InstanceHasher};
use webb_primitives::{hashing::ethereum::Keccak256HasherBn254, types::ElementTrait, AccountId};
use webb_primitives::{
hashing::ethereum::Keccak256HasherBn254, types::ElementTrait, verifying::ArkworksVerifierBn254,
AccountId,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -255,6 +259,11 @@ parameter_types! {
pub const NativeCurrencyId: AssetId = 0;
}

#[cfg(feature = "runtime-benchmarks")]
pub fn new_bench_ext() -> sp_io::TestExternalities {
GenesisConfig::default().build_storage().unwrap().into()
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
use sp_runtime::traits::Zero;
Expand Down
2 changes: 1 addition & 1 deletion pallets/mt/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use sc_rpc::DenyUnsafe;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use sp_runtime::traits::Block as BlockT;
use std::sync::Arc;

use pallet_mt_rpc_runtime_api::MerkleTreeApi;
Expand Down
1 change: 0 additions & 1 deletion pallets/relayer-registry/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-08-01, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `Stanlys-MacBook-Air.local`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
Expand Down
2 changes: 1 addition & 1 deletion pallets/signature-bridge/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn generate_maintainer_signatures<T: Config<I>, I: 'static>() -> (Vec<u8>, V
let old_maintainer = ecdsa_generate(DUMMY, None);
let old_maintainer_key = set_maintainer_on_chain::<T, I>(old_maintainer);
let mut message = vec![];
let nonce = 1u32.to_be_bytes;
let nonce = 1u32.to_be_bytes();
message.extend_from_slice(&nonce);
message.extend_from_slice(&new_maintainer.encode());
let hash = keccak_256(&message);
Expand Down
Loading

0 comments on commit b98fb70

Please sign in to comment.