diff --git a/.maintain/webb-weight-template.hbs b/.maintain/webb-weight-template.hbs index dad0ec56d..ce388a908 100644 --- a/.maintain/webb-weight-template.hbs +++ b/.maintain/webb-weight-template.hbs @@ -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: @@ -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 { @@ -54,7 +55,7 @@ impl WeightInfo for WebbWeight { {{/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}}]`. @@ -64,22 +65,29 @@ impl WeightInfo for WebbWeight { {{~#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}} @@ -89,7 +97,7 @@ impl WeightInfo for WebbWeight { 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}}]`. @@ -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}} diff --git a/Cargo.lock b/Cargo.lock index 65c883114..cb8142057 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12736,7 +12736,6 @@ dependencies = [ "arkworks-setups", "cfg-if", "color-eyre 0.6.2", - "frame-benchmarking", "frame-support", "frame-system", "hex", diff --git a/client/Cargo.toml b/client/Cargo.toml index 793608105..a0c3df069 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -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" @@ -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"] \ No newline at end of file diff --git a/pallets/anonymity-mining-claims/src/test_utils.rs b/pallets/anonymity-mining-claims/src/test_utils.rs index d702d3b05..6b21f02a4 100644 --- a/pallets/anonymity-mining-claims/src/test_utils.rs +++ b/pallets/anonymity-mining-claims/src/test_utils.rs @@ -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}; diff --git a/pallets/anonymity-mining-claims/src/tests.rs b/pallets/anonymity-mining-claims/src/tests.rs index 42e82197a..732519322 100644 --- a/pallets/anonymity-mining-claims/src/tests.rs +++ b/pallets/anonymity-mining-claims/src/tests.rs @@ -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::{ diff --git a/pallets/claims-verifier/src/benchmarking.rs b/pallets/claims-verifier/src/benchmarking.rs index 5c1ca3c0a..623a98e4b 100644 --- a/pallets/claims-verifier/src/benchmarking.rs +++ b/pallets/claims-verifier/src/benchmarking.rs @@ -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::::parameters((1u8,1u8)), parameters); + assert_eq!(Pallet::::parameters(1u8), parameters); } } diff --git a/pallets/hasher/src/benchmarking.rs b/pallets/hasher/src/benchmarking.rs index a36578fb7..b9a018edb 100644 --- a/pallets/hasher/src/benchmarking.rs +++ b/pallets/hasher/src/benchmarking.rs @@ -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 { diff --git a/pallets/hasher/src/weights.rs b/pallets/hasher/src/weights.rs index fc1cf67c8..32f3c89b2 100644 --- a/pallets/hasher/src/weights.rs +++ b/pallets/hasher/src/weights.rs @@ -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: @@ -28,7 +29,7 @@ // pallet // --chain=dev // --steps=20 -// --repeat=10 +// --repeat=1 // --log=warn // --pallet=pallet-hasher // --extrinsic=* @@ -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 { @@ -52,9 +53,17 @@ pub trait WeightInfo { /// Weights for pallet_hasher using the Substrate node and recommended hardware. pub struct WebbWeight(PhantomData); impl WeightInfo for WebbWeight { - // 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)) } @@ -62,9 +71,17 @@ impl WeightInfo for WebbWeight { // 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)) } diff --git a/pallets/key-storage/src/benchmarking.rs b/pallets/key-storage/src/benchmarking.rs index 4b5fad6d4..db13437cf 100644 --- a/pallets/key-storage/src/benchmarking.rs +++ b/pallets/key-storage/src/benchmarking.rs @@ -27,7 +27,7 @@ fn assert_last_event, I: 'static>(generic_event: >:: frame_system::Pallet::::assert_last_event(generic_event.into()); } -const MAX_PARAMETER_LENGTH: u32 = 20000; +const MAX_PARAMETER_LENGTH: u32 = 10000; benchmarks_instance_pallet! { register { diff --git a/pallets/linkable-tree/rpc/src/lib.rs b/pallets/linkable-tree/rpc/src/lib.rs index 2da5f08f4..ae750d4d3 100644 --- a/pallets/linkable-tree/rpc/src/lib.rs +++ b/pallets/linkable-tree/rpc/src/lib.rs @@ -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; diff --git a/pallets/mixer/src/benchmarking.rs b/pallets/mixer/src/benchmarking.rs index b2a14f30c..38e884a98 100644 --- a/pallets/mixer/src/benchmarking.rs +++ b/pallets/mixer/src/benchmarking.rs @@ -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; @@ -63,8 +62,7 @@ benchmarks_instance_pallet! { let tree_id = as MixerInterface<_,_,_,_,_>>::create(None, deposit_size.into(), depth, asset_id)?; let leaf = >::Element::from_bytes(&[1u8; 32]); - <>::Currency as Currency>::make_free_balance_be(&caller.clone(), 200_000_000u32.into()); - + <>::Currency as Currency>::make_free_balance_be(&caller.clone(), 900_000_000u32.into()); }: _(RawOrigin::Signed(caller.clone()), tree_id, leaf) verify { assert_eq!(<>::Currency as MultiCurrency>::total_balance(asset_id, &Pallet::::account_id()), deposit_size.into()) @@ -136,6 +134,6 @@ benchmarks_instance_pallet! { assert_eq!(<>::Currency as MultiCurrency>::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); +} diff --git a/pallets/mixer/src/mock.rs b/pallets/mixer/src/mock.rs index 2591c14ae..a932a43b7 100644 --- a/pallets/mixer/src/mock.rs +++ b/pallets/mixer/src/mock.rs @@ -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; type Block = frame_system::mocking::MockBlock; @@ -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; diff --git a/pallets/mt/rpc/src/lib.rs b/pallets/mt/rpc/src/lib.rs index 5f87d60b1..1cc44b5cb 100644 --- a/pallets/mt/rpc/src/lib.rs +++ b/pallets/mt/rpc/src/lib.rs @@ -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; diff --git a/pallets/relayer-registry/src/weights.rs b/pallets/relayer-registry/src/weights.rs index 6d9cce878..6ce99af85 100644 --- a/pallets/relayer-registry/src/weights.rs +++ b/pallets/relayer-registry/src/weights.rs @@ -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: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: diff --git a/pallets/signature-bridge/src/benchmarking.rs b/pallets/signature-bridge/src/benchmarking.rs index 03da32c86..232847c32 100644 --- a/pallets/signature-bridge/src/benchmarking.rs +++ b/pallets/signature-bridge/src/benchmarking.rs @@ -45,7 +45,7 @@ pub fn generate_maintainer_signatures, I: 'static>() -> (Vec, V let old_maintainer = ecdsa_generate(DUMMY, None); let old_maintainer_key = set_maintainer_on_chain::(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); diff --git a/pallets/signature-bridge/src/lib.rs b/pallets/signature-bridge/src/lib.rs index 5a3e2e760..456b58450 100644 --- a/pallets/signature-bridge/src/lib.rs +++ b/pallets/signature-bridge/src/lib.rs @@ -614,7 +614,7 @@ impl, I: 'static> SetMaintainer, I: 'static> EnsureOrigin for EnsureBridge T::RuntimeOrigin { - T::RuntimeOrigin::from(frame_system::RawOrigin::Signed( + fn try_successful_origin() -> Result<::RuntimeOrigin, ()> { + Ok(T::RuntimeOrigin::from(frame_system::RawOrigin::Signed( T::BridgeAccountId::get().into_account_truncating(), - )) + ))) } } diff --git a/pallets/vanchor-verifier/Cargo.toml b/pallets/vanchor-verifier/Cargo.toml index 2fe97bf69..e49d8c4c7 100644 --- a/pallets/vanchor-verifier/Cargo.toml +++ b/pallets/vanchor-verifier/Cargo.toml @@ -38,6 +38,7 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] std = [ "codec/std", diff --git a/pallets/vanchor-verifier/src/benchmarking.rs b/pallets/vanchor-verifier/src/benchmarking.rs index 5c1ca3c0a..ba3f108ab 100644 --- a/pallets/vanchor-verifier/src/benchmarking.rs +++ b/pallets/vanchor-verifier/src/benchmarking.rs @@ -27,7 +27,6 @@ use frame_benchmarking::{ }; use frame_support::traits::Currency; use frame_system::RawOrigin; -use sp_runtime::traits::Bounded; use webb_primitives::types::DepositDetails; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { diff --git a/pallets/vanchor/Cargo.toml b/pallets/vanchor/Cargo.toml index 7d1f54480..21838b00c 100644 --- a/pallets/vanchor/Cargo.toml +++ b/pallets/vanchor/Cargo.toml @@ -29,6 +29,11 @@ arkworks-native-gadgets = { version = "1.2.0", default-features = false } ark-std = { version = "^0.3.0", default-features = false } ark-bn254 = { version = "^0.3.0", default-features = false, features = [ "curve" ] } ark-ff = { version = "^0.3.0", default-features = false} +arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true } +pallet-vanchor-verifier = { path = "../vanchor-verifier", default-features = false } +pallet-hasher = { path = "../hasher", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false } [dev-dependencies] hex = "0.4" @@ -40,12 +45,8 @@ sp-runtime = { default-features = false, git = "https://github.com/paritytech/su pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } pallet-treasury = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } pallet-key-storage = {path = "../key-storage"} -pallet-hasher = { path = "../hasher", default-features = false } -pallet-vanchor-verifier = { path = "../vanchor-verifier", default-features = false } circom-proving = { path = "../../circom-proving", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false } 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 } ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false } ark-ff = { version = "0.3.0", default-features = false, features = [ "asm"] } ark-ec = { version = "^0.3.0", default-features = false } @@ -56,7 +57,7 @@ ark-std = { version = "^0.3.0", default-features = false } ark-bn254 = { version = "0.3.0" } ark-circom = { git = "https://github.com/vacp2p/ark-circom", branch = "wasm", default-features = false, features = ["circom-2"] } 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" @@ -81,10 +82,14 @@ std = [ "webb-primitives/std", "frame-benchmarking/std", "pallet-token-wrapper/std", - "ark-std/std" + "ark-std/std", + "arkworks-setups/std", + "pallet-vanchor-verifier/std", + "pallet-hasher/std" ] runtime-benchmarks = [ - "frame-system/runtime-benchmarks", - "frame-support/runtime-benchmarks", + "frame-benchmarking", + "frame-system/runtime-benchmarks", + "frame-support/runtime-benchmarks", ] wasm = ["wasmer/js", "wasmer/std"] diff --git a/pallets/vanchor/src/benchmarking.rs b/pallets/vanchor/src/benchmarking.rs index 6f1149d6f..1fbbb94c8 100644 --- a/pallets/vanchor/src/benchmarking.rs +++ b/pallets/vanchor/src/benchmarking.rs @@ -138,9 +138,9 @@ benchmarks_instance_pallet! { let asset_id = <>::NativeCurrencyId as Get>>::get(); let depth = >::MaxTreeDepth::get(); - let tree_id = as VAnchorInterface>>::create(None, depth, 1u32, asset_id, 1u32.into())?; + let tree_id = as VAnchorInterface>>::create(None, depth, 1u32, asset_id, 1u32.into())?; - as VAnchorInterface>>::set_max_deposit_amount(100u32.into(), 2u32.into())?; + as VAnchorInterface>>::set_max_deposit_amount(100u32.into(), 2u32.into())?; let transactor : T::AccountId = account("", 0, SEED); let recipient : T::AccountId = account("", 1, SEED); @@ -222,9 +222,9 @@ benchmarks_instance_pallet! { let asset_id = <>::NativeCurrencyId as Get>>::get(); let depth = >::MaxTreeDepth::get(); - let tree_id = as VAnchorInterface>>::create(None, depth, 1u32, asset_id, 1u32.into())?; + let tree_id = as VAnchorInterface>>::create(None, depth, 1u32, asset_id, 1u32.into())?; - as VAnchorInterface>>::set_max_deposit_amount(100u32.into(), 2u32.into())?; + as VAnchorInterface>>::set_max_deposit_amount(100u32.into(), 2u32.into())?; let transactor : T::AccountId = account("", 0, SEED); let recipient : T::AccountId = account("", 1, SEED); @@ -311,6 +311,6 @@ benchmarks_instance_pallet! { verify { assert_last_event::(Event::MinWithdrawAmountChanged{ min_withdraw_amount : 1_u32.into() }.into()) } -} -impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/pallets/vanchor/src/mock.rs b/pallets/vanchor/src/mock.rs index f4b23674b..792770954 100644 --- a/pallets/vanchor/src/mock.rs +++ b/pallets/vanchor/src/mock.rs @@ -64,8 +64,8 @@ frame_support::construct_runtime!( LinkableTree1: pallet_linkable_tree::::{Pallet, Call, Storage, Event}, LinkableTree2: pallet_linkable_tree::::{Pallet, Call, Storage, Event}, - VAnchorVerifier1: pallet_vanchor_verifier::::{Pallet, Call, Storage, Event}, - VAnchorVerifier2: pallet_vanchor_verifier::::{Pallet, Call, Storage, Event}, + VAnchorVerifier1: pallet_vanchor_verifier::::{Pallet, Call, Storage, Event, Config}, + VAnchorVerifier2: pallet_vanchor_verifier::::{Pallet, Call, Storage, Event, Config}, VAnchor1: pallet_vanchor::::{Pallet, Call, Storage, Event}, VAnchor2: pallet_vanchor::::{Pallet, Call, Storage, Event}, diff --git a/scripts/generate-weights.sh b/scripts/generate-weights.sh new file mode 100755 index 000000000..0ea844e4b --- /dev/null +++ b/scripts/generate-weights.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +# This script will run the benchmark script and save the results in the weights file of the given pallet +# To run this script, first build the node with the benchmark features, like 'cargo b --features runtime-benchmarks' +# Then execute the script with the name of the pallet to benchmark +# Example : ./generate-weights hasher + +echo "Generate Weights for : $1" + +./target/release/webb-standalone-node benchmark pallet \ + --chain=dev \ + --steps=20 \ + --repeat=1 \ + --log=warn \ + --pallet="pallet-${1}" \ + --extrinsic="*" \ + --execution=wasm \ + --wasm-execution=compiled \ + --output="./pallets/$1/src/weights.rs" \ + --template=./.maintain/webb-weight-template.hbs \ No newline at end of file