From 90ad566cc7e8e0293073641fbfb445fff7cda26c Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 12 Oct 2023 18:26:42 +0000 Subject: [PATCH] Merge pull request #1008 from UniqueNetwork/fix/update-benchmarks-to-v2 Update benchmarks to v2 --- --- a/Cargo.lock +++ b/Cargo.lock @@ -6536,6 +6536,7 @@ "sp-runtime", "sp-session", "sp-std", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-xcm", @@ -10144,6 +10145,7 @@ "sp-runtime", "sp-session", "sp-std", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-xcm", @@ -14896,6 +14898,7 @@ "sp-runtime", "sp-session", "sp-std", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-xcm", --- a/Cargo.toml +++ b/Cargo.toml @@ -170,6 +170,7 @@ sp-staking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sp-std = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } --- a/Makefile +++ b/Makefile @@ -88,69 +88,36 @@ evm_stubs: UniqueFungible UniqueNFT UniqueRefungible UniqueRefungibleToken ContractHelpers CollectionHelpers -.PHONY: _bench -_bench: - cargo run --profile production --features runtime-benchmarks,$(RUNTIME) -- \ - benchmark pallet --pallet pallet-$(if $(PALLET),$(PALLET),$(error Must set PALLET)) \ - --wasm-execution compiled --extrinsic '*' \ - $(if $(TEMPLATE),$(TEMPLATE),--template=.maintain/frame-weight-template.hbs) --steps=50 --repeat=80 --heap-pages=4096 \ - --output=$(if $(OUTPUT),$(OUTPUT),./pallets/$(if $(PALLET_DIR),$(PALLET_DIR),$(PALLET))/src/weights.rs) - -.PHONY: bench-evm-migration -bench-evm-migration: - make _bench PALLET=evm-migration - -.PHONY: bench-configuration -bench-configuration: - make _bench PALLET=configuration - -.PHONY: bench-common -bench-common: - make _bench PALLET=common - -.PHONY: bench-unique -bench-unique: - make _bench PALLET=unique - -.PHONY: bench-fungible -bench-fungible: - make _bench PALLET=fungible - -.PHONY: bench-refungible -bench-refungible: - make _bench PALLET=refungible - -.PHONY: bench-nonfungible -bench-nonfungible: - make _bench PALLET=nonfungible - -.PHONY: bench-structure -bench-structure: - make _bench PALLET=structure - -.PHONY: bench-foreign-assets -bench-foreign-assets: - make _bench PALLET=foreign-assets - -.PHONY: bench-collator-selection -bench-collator-selection: - make _bench PALLET=collator-selection +# TODO: Create benchmarking profile, make it a proper dependency +.PHONY: benchmarking-node +benchmarking-node: + cargo build --profile production --features runtime-benchmarks -.PHONY: bench-identity -bench-identity: - make _bench PALLET=identity +define _bench = +.PHONY: bench-$(1) +bench-$(1): benchmarking-node + ./target/production/unique-collator \ + benchmark pallet --pallet pallet-$(1) \ + --wasm-execution compiled --extrinsic '*' \ + $(if $(4),$(4),--template=.maintain/frame-weight-template.hbs) --steps=50 --repeat=80 --heap-pages=4096 \ + --output=$$(if $(3),$(3),./pallets/$(if $(2),$(2),$(1))/src/weights.rs) +endef -.PHONY: bench-app-promotion -bench-app-promotion: - make _bench PALLET=app-promotion - -.PHONY: bench-maintenance -bench-maintenance: - make _bench PALLET=maintenance - -.PHONY: bench-xcm -bench-xcm: - make _bench PALLET=xcm OUTPUT=./runtime/common/weights/xcm.rs TEMPLATE="--template=.maintain/external-weight-template.hbs" +# _bench,pallet,(pallet_dir|),(output|),(extra|) +$(eval $(call _bench,evm-migration)) +$(eval $(call _bench,configuration)) +$(eval $(call _bench,common)) +$(eval $(call _bench,unique)) +$(eval $(call _bench,fungible)) +$(eval $(call _bench,refungible)) +$(eval $(call _bench,nonfungible)) +$(eval $(call _bench,structure)) +$(eval $(call _bench,foreign-assets)) +$(eval $(call _bench,collator-selection)) +$(eval $(call _bench,identity)) +$(eval $(call _bench,app-promotion)) +$(eval $(call _bench,maintenance)) +$(eval $(call _bench,xcm,,./runtime/common/weights/xcm.rs,"--template=.maintain/external-weights/template.hbs")) .PHONY: bench bench: bench-app-promotion bench-common bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-maintenance bench-xcm bench-collator-selection bench-identity --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -238,7 +238,7 @@ vesting: VestingConfig { vesting: vec![] }, parachain_info: ParachainInfoConfig { parachain_id: $id.into(), - Default::default() + ..Default::default() }, aura: AuraConfig { authorities: $initial_invulnerables --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -42,10 +42,6 @@ use sp_runtime::traits::AccountIdConversion; use up_common::types::opaque::RuntimeId; -#[cfg(feature = "runtime-benchmarks")] -use crate::chain_spec::default_runtime; -#[cfg(feature = "runtime-benchmarks")] -use crate::service::DefaultRuntimeExecutor; #[cfg(feature = "quartz-runtime")] use crate::service::QuartzRuntimeExecutor; #[cfg(feature = "unique-runtime")] @@ -355,26 +351,37 @@ #[cfg(feature = "runtime-benchmarks")] Some(Subcommand::Benchmark(cmd)) => { use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; + use polkadot_cli::Block; + use sp_io::SubstrateHostFunctions; + let runner = cli.create_runner(cmd)?; // Switch on the concrete benchmark sub-command- match cmd { BenchmarkCmd::Pallet(cmd) => { - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run::(config)) } BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { let partials = new_partial::< - default_runtime::RuntimeApi, - DefaultRuntimeExecutor, + opal_runtime::Runtime, + opal_runtime::RuntimeApi, + OpalRuntimeExecutor, _, - >(&config, crate::service::parachain_build_import_queue)?; + >( + &config, + crate::service::parachain_build_import_queue::, + )?; cmd.run(partials.client) }), BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let partials = new_partial::< - default_runtime::RuntimeApi, - DefaultRuntimeExecutor, + opal_runtime::Runtime, + opal_runtime::RuntimeApi, + OpalRuntimeExecutor, _, - >(&config, crate::service::parachain_build_import_queue)?; + >( + &config, + crate::service::parachain_build_import_queue::, + )?; let db = partials.backend.expose_db(); let storage = partials.backend.expose_storage(); @@ -392,6 +399,7 @@ Some(Subcommand::TryRuntime(cmd)) => { use std::{future::Future, pin::Pin}; + use polkadot_cli::Block; use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; use try_runtime_cli::block_building_info::timestamp_with_aura_info; --- a/node/cli/src/rpc.rs +++ b/node/cli/src/rpc.rs @@ -67,7 +67,7 @@ } /// Instantiate all Full RPC extensions. -pub fn create_full( +pub fn create_full( io: &mut RpcModule<()>, deps: FullDeps, ) -> Result<(), Box> @@ -244,7 +244,7 @@ EthFilter::new( client.clone(), eth_backend, - graph.clone(), + graph, filter_pool, 500_usize, // max stored filters max_past_logs, --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -93,23 +93,6 @@ /// Opal native executor instance. pub struct OpalRuntimeExecutor; -#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))] -pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor; - -#[cfg(all( - not(feature = "unique-runtime"), - feature = "quartz-runtime", - feature = "runtime-benchmarks" -))] -pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor; - -#[cfg(all( - not(feature = "unique-runtime"), - not(feature = "quartz-runtime"), - feature = "runtime-benchmarks" -))] -pub type DefaultRuntimeExecutor = OpalRuntimeExecutor; - #[cfg(feature = "unique-runtime")] impl NativeExecutionDispatch for UniqueRuntimeExecutor { /// Only enable the benchmarking host functions when we actually want to benchmark. @@ -515,7 +498,7 @@ select_chain, }; - create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?; + create_full::<_, _, _, Runtime, _>(&mut rpc_handle, full_deps)?; let eth_deps = EthDeps { client, @@ -564,7 +547,7 @@ config: parachain_config, keystore: params.keystore_container.keystore(), backend: backend.clone(), - network: network.clone(), + network, sync_service: sync_service.clone(), system_rpc_tx, telemetry: telemetry.as_mut(), @@ -617,19 +600,21 @@ if validator { start_consensus( client.clone(), - backend.clone(), - prometheus_registry.as_ref(), - telemetry.as_ref().map(|t| t.handle()), - &task_manager, - relay_chain_interface.clone(), transaction_pool, - sync_service.clone(), - params.keystore_container.keystore(), - overseer_handle, - relay_chain_slot_duration, - para_id, - collator_key.expect("cli args do not allow this"), - announce_block, + StartConsensusParameters { + backend: backend.clone(), + prometheus_registry: prometheus_registry.as_ref(), + telemetry: telemetry.as_ref().map(|t| t.handle()), + task_manager: &task_manager, + relay_chain_interface: relay_chain_interface.clone(), + sync_oracle: sync_service, + keystore: params.keystore_container.keystore(), + overseer_handle, + relay_chain_slot_duration, + para_id, + collator_key: collator_key.expect("cli args do not allow this"), + announce_block, + }, )?; } @@ -687,16 +672,12 @@ .map_err(Into::into) } -pub fn start_consensus( - client: Arc>, +pub struct StartConsensusParameters<'a> { backend: Arc, - prometheus_registry: Option<&Registry>, + prometheus_registry: Option<&'a Registry>, telemetry: Option, - task_manager: &TaskManager, + task_manager: &'a TaskManager, relay_chain_interface: Arc, - transaction_pool: Arc< - sc_transaction_pool::FullPool>, - >, sync_oracle: Arc>, keystore: KeystorePtr, overseer_handle: OverseerHandle, @@ -704,6 +685,14 @@ para_id: ParaId, collator_key: CollatorPair, announce_block: Arc>) + Send + Sync>, +} + +pub fn start_consensus( + client: Arc>, + transaction_pool: Arc< + sc_transaction_pool::FullPool>, + >, + parameters: StartConsensusParameters<'_>, ) -> Result<(), sc_service::Error> where ExecutorDispatch: NativeExecutionDispatch + 'static, @@ -714,6 +703,20 @@ RuntimeApi::RuntimeApi: RuntimeApiDep + 'static, Runtime: RuntimeInstance, { + let StartConsensusParameters { + backend, + prometheus_registry, + telemetry, + task_manager, + relay_chain_interface, + sync_oracle, + keystore, + overseer_handle, + relay_chain_slot_duration, + para_id, + collator_key, + announce_block, + } = parameters; let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( @@ -721,7 +724,7 @@ client.clone(), transaction_pool, prometheus_registry, - telemetry.clone(), + telemetry, ); let proposer = Proposer::new(proposer_factory); @@ -1060,7 +1063,7 @@ select_chain, }; - create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?; + create_full::<_, _, _, Runtime, _>(&mut rpc_module, full_deps)?; let eth_deps = EthDeps { client, --- a/pallets/app-promotion/src/benchmarking.rs +++ b/pallets/app-promotion/src/benchmarking.rs @@ -16,15 +16,24 @@ #![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::{account, benchmarks}; -use frame_support::traits::{fungible::Unbalanced, OnInitialize}; -use frame_system::RawOrigin; +use frame_benchmarking::v2::*; +use frame_support::traits::{ + fungible::{Inspect, Mutate, Unbalanced}, + OnInitialize, +}; +use frame_system::{pallet_prelude::*, RawOrigin}; +use pallet_evm::account::CrossAccountId; use pallet_evm_migration::Pallet as EvmMigrationPallet; use pallet_unique::benchmarking::create_nft_collection; -use sp_runtime::traits::Bounded; +use sp_core::{Get, H160}; +use sp_runtime::{ + traits::{BlockNumberProvider, Bounded}, + Perbill, +}; +use sp_std::{iter::Sum, vec, vec::Vec}; -use super::*; -use crate::Pallet as PromototionPallet; +use super::{BalanceOf, Call, Config, Pallet, Staked, PENDING_LIMIT_PER_BLOCK}; +use crate::{pallet, Pallet as PromototionPallet}; const SEED: u32 = 0; @@ -49,55 +58,98 @@ Ok(pallet_admin) } -benchmarks! { - where_clause{ - where T: Config + pallet_unique::Config + pallet_evm_migration::Config , +#[benchmarks( + where T: Config + pallet_unique::Config + pallet_evm_migration::Config , BlockNumberFor: From + Into, BalanceOf: Sum + From - } +)] +mod benchmarks { + use super::*; - on_initialize { - let b in 0..PENDING_LIMIT_PER_BLOCK; + #[benchmark] + fn on_initialize(b: Linear<0, PENDING_LIMIT_PER_BLOCK>) -> Result<(), BenchmarkError> { set_admin::()?; (0..b).try_for_each(|index| { let staker = account::("staker", index, SEED); - ::Currency::write_balance(&staker, Into::>::into(10_000u128) * T::Nominal::get())?; - PromototionPallet::::stake(RawOrigin::Signed(staker.clone()).into(), Into::>::into(100u128) * T::Nominal::get())?; + ::Currency::write_balance( + &staker, + Into::>::into(10_000u128) * T::Nominal::get(), + )?; + PromototionPallet::::stake( + RawOrigin::Signed(staker.clone()).into(), + Into::>::into(100u128) * T::Nominal::get(), + )?; PromototionPallet::::unstake_all(RawOrigin::Signed(staker).into())?; Result::<(), sp_runtime::DispatchError>::Ok(()) })?; - let block_number = >::current_block_number() + T::PendingInterval::get(); - }: {PromototionPallet::::on_initialize(block_number)} + let block_number = + >::current_block_number() + T::PendingInterval::get(); + + #[block] + { + PromototionPallet::::on_initialize(block_number); + } + + Ok(()) + } - set_admin_address { + #[benchmark] + fn set_admin_address() -> Result<(), BenchmarkError> { let pallet_admin = account::("admin", 0, SEED); - let _ = ::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); - } : _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin)) + let _ = ::Currency::set_balance( + &pallet_admin, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); + + #[extrinsic_call] + _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin)); - payout_stakers{ - let b in 1..100; + Ok(()) + } + #[benchmark] + fn payout_stakers(b: Linear<1, 100>) -> Result<(), BenchmarkError> { let pallet_admin = account::("admin", 1, SEED); - let share = Perbill::from_rational(1u32, 20); - PromototionPallet::::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?; - ::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value())?; - ::Currency::write_balance(&::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::::max_value())?; + PromototionPallet::::set_admin_address( + RawOrigin::Root.into(), + T::CrossAccountId::from_sub(pallet_admin.clone()), + )?; + ::Currency::write_balance( + &pallet_admin, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + )?; + ::Currency::write_balance( + &::TreasuryAccountId::get(), + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + )?; - let stakers: Vec = (0..b).map(|index| account("staker", index, SEED)).collect(); + let stakers: Vec = + (0..b).map(|index| account("staker", index, SEED)).collect(); stakers.iter().try_for_each(|staker| { - ::Currency::write_balance(staker, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value())?; + ::Currency::write_balance( + staker, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + )?; Result::<(), sp_runtime::DispatchError>::Ok(()) })?; (1..11).try_for_each(|i| { >::set_block_number(i.into()); - T::RelayBlockNumberProvider::set_block_number((2*i).into()); + T::RelayBlockNumberProvider::set_block_number((2 * i).into()); assert_eq!(>::block_number(), i.into()); - assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into()); - stakers.iter() - .map(|staker| { - PromototionPallet::::stake(RawOrigin::Signed(staker.clone()).into(), Into::>::into(100u128) * T::Nominal::get()) - }).collect::, _>>()?; + assert_eq!( + T::RelayBlockNumberProvider::current_block_number(), + (2 * i).into() + ); + stakers + .iter() + .map(|staker| { + PromototionPallet::::stake( + RawOrigin::Signed(staker.clone()).into(), + Into::>::into(100u128) * T::Nominal::get(), + ) + }) + .collect::, _>>()?; Result::<(), sp_runtime::DispatchError>::Ok(()) })?; @@ -107,83 +159,195 @@ >::set_block_number(15_000.into()); T::RelayBlockNumberProvider::set_block_number(30_000.into()); - } : _(RawOrigin::Signed(pallet_admin.clone()), Some(b as u8)) - stake { + #[extrinsic_call] + _(RawOrigin::Signed(pallet_admin), Some(b as u8)); + + Ok(()) + } + + #[benchmark] + fn stake() -> Result<(), BenchmarkError> { let caller = account::("caller", 0, SEED); let share = Perbill::from_rational(1u32, 10); - let _ = ::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); - } : _(RawOrigin::Signed(caller.clone()), share * ::Currency::total_balance(&caller)) - unstake_all { + let _ = ::Currency::write_balance( + &caller, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + share * ::Currency::total_balance(&caller), + ); + + Ok(()) + } + + #[benchmark] + fn unstake_all() -> Result<(), BenchmarkError> { let caller = account::("caller", 0, SEED); let share = Perbill::from_rational(1u32, 20); - let _ = ::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); - (1..11).map(|i| { - // used to change block number - >::set_block_number(i.into()); - T::RelayBlockNumberProvider::set_block_number((2*i).into()); - assert_eq!(>::block_number(), i.into()); - assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into()); - PromototionPallet::::stake(RawOrigin::Signed(caller.clone()).into(), share * ::Currency::total_balance(&caller)) - }).collect::, _>>()?; + let _ = ::Currency::write_balance( + &caller, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); + (1..11) + .map(|i| { + // used to change block number + >::set_block_number(i.into()); + T::RelayBlockNumberProvider::set_block_number((2 * i).into()); + assert_eq!(>::block_number(), i.into()); + assert_eq!( + T::RelayBlockNumberProvider::current_block_number(), + (2 * i).into() + ); + PromototionPallet::::stake( + RawOrigin::Signed(caller.clone()).into(), + share * ::Currency::total_balance(&caller), + ) + }) + .collect::, _>>()?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller)); - } : _(RawOrigin::Signed(caller.clone())) + Ok(()) + } - unstake_partial { + #[benchmark] + fn unstake_partial() -> Result<(), BenchmarkError> { let caller = account::("caller", 0, SEED); - let share = Perbill::from_rational(1u32, 20); - let _ = ::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); - (1..11).map(|i| { - // used to change block number - >::set_block_number(i.into()); - T::RelayBlockNumberProvider::set_block_number((2*i).into()); - assert_eq!(>::block_number(), i.into()); - assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into()); - PromototionPallet::::stake(RawOrigin::Signed(caller.clone()).into(), Into::>::into(100u128) * T::Nominal::get()) - }).collect::, _>>()?; + let _ = ::Currency::write_balance( + &caller, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); + (1..11) + .map(|i| { + // used to change block number + >::set_block_number(i.into()); + T::RelayBlockNumberProvider::set_block_number((2 * i).into()); + assert_eq!(>::block_number(), i.into()); + assert_eq!( + T::RelayBlockNumberProvider::current_block_number(), + (2 * i).into() + ); + PromototionPallet::::stake( + RawOrigin::Signed(caller.clone()).into(), + Into::>::into(100u128) * T::Nominal::get(), + ) + }) + .collect::, _>>()?; + + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + Into::>::into(1000u128) * T::Nominal::get(), + ); - } : _(RawOrigin::Signed(caller.clone()), Into::>::into(1000u128) * T::Nominal::get()) + Ok(()) + } - sponsor_collection { + #[benchmark] + fn sponsor_collection() -> Result<(), BenchmarkError> { let pallet_admin = account::("admin", 0, SEED); - PromototionPallet::::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?; - let _ = ::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + PromototionPallet::::set_admin_address( + RawOrigin::Root.into(), + T::CrossAccountId::from_sub(pallet_admin.clone()), + )?; + let _ = ::Currency::write_balance( + &pallet_admin, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); let caller: T::AccountId = account("caller", 0, SEED); - let _ = ::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + let _ = ::Currency::write_balance( + &caller, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); let collection = create_nft_collection::(caller)?; - } : _(RawOrigin::Signed(pallet_admin.clone()), collection) - stop_sponsoring_collection { + #[extrinsic_call] + _(RawOrigin::Signed(pallet_admin), collection); + + Ok(()) + } + + #[benchmark] + fn stop_sponsoring_collection() -> Result<(), BenchmarkError> { let pallet_admin = account::("admin", 0, SEED); - PromototionPallet::::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?; - let _ = ::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + PromototionPallet::::set_admin_address( + RawOrigin::Root.into(), + T::CrossAccountId::from_sub(pallet_admin.clone()), + )?; + let _ = ::Currency::write_balance( + &pallet_admin, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); let caller: T::AccountId = account("caller", 0, SEED); - let _ = ::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + let _ = ::Currency::write_balance( + &caller, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); let collection = create_nft_collection::(caller)?; - PromototionPallet::::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?; - } : _(RawOrigin::Signed(pallet_admin.clone()), collection) + PromototionPallet::::sponsor_collection( + RawOrigin::Signed(pallet_admin.clone()).into(), + collection, + )?; + + #[extrinsic_call] + _(RawOrigin::Signed(pallet_admin), collection); + + Ok(()) + } - sponsor_contract { + #[benchmark] + fn sponsor_contract() -> Result<(), BenchmarkError> { let pallet_admin = account::("admin", 0, SEED); - PromototionPallet::::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?; + PromototionPallet::::set_admin_address( + RawOrigin::Root.into(), + T::CrossAccountId::from_sub(pallet_admin.clone()), + )?; - let _ = ::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + let _ = ::Currency::write_balance( + &pallet_admin, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); let address = H160::from_low_u64_be(SEED as u64); let data: Vec = (0..20).collect(); >::begin(RawOrigin::Root.into(), address)?; >::finish(RawOrigin::Root.into(), address, data)?; - } : _(RawOrigin::Signed(pallet_admin.clone()), address) - stop_sponsoring_contract { + #[extrinsic_call] + _(RawOrigin::Signed(pallet_admin), address); + + Ok(()) + } + + #[benchmark] + fn stop_sponsoring_contract() -> Result<(), BenchmarkError> { let pallet_admin = account::("admin", 0, SEED); - PromototionPallet::::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?; + PromototionPallet::::set_admin_address( + RawOrigin::Root.into(), + T::CrossAccountId::from_sub(pallet_admin.clone()), + )?; - let _ = ::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::::max_value()); + let _ = ::Currency::write_balance( + &pallet_admin, + Perbill::from_rational(1u32, 2) * BalanceOf::::max_value(), + ); let address = H160::from_low_u64_be(SEED as u64); let data: Vec = (0..20).collect(); >::begin(RawOrigin::Root.into(), address)?; >::finish(RawOrigin::Root.into(), address, data)?; - PromototionPallet::::sponsor_contract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?; - } : _(RawOrigin::Signed(pallet_admin.clone()), address) + PromototionPallet::::sponsor_contract( + RawOrigin::Signed(pallet_admin.clone()).into(), + address, + )?; + + #[extrinsic_call] + _(RawOrigin::Signed(pallet_admin), address); + + Ok(()) + } } --- a/pallets/app-promotion/src/weights.rs +++ b/pallets/app-promotion/src/weights.rs @@ -3,10 +3,10 @@ //! Autogenerated weights for pallet_app_promotion //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-26, STEPS: `50`, REPEAT: `400`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-10-12, STEPS: `50`, REPEAT: `80`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bench-host`, CPU: `Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! HOSTNAME: `ubuntu-11`, CPU: `QEMU Virtual CPU version 2.5+` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // target/production/unique-collator @@ -20,7 +20,7 @@ // * // --template=.maintain/frame-weight-template.hbs // --steps=50 -// --repeat=400 +// --repeat=80 // --heap-pages=4096 // --output=./pallets/app-promotion/src/weights.rs @@ -48,185 +48,185 @@ /// Weights for pallet_app_promotion using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: Maintenance Enabled (r:1 w:0) - /// Proof: Maintenance Enabled (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: AppPromotion PendingUnstake (r:1 w:1) - /// Proof: AppPromotion PendingUnstake (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:3 w:3) - /// Proof: Balances Freezes (max_values: None, max_size: Some(369), added: 2844, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:3) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:3 w:0) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: `Maintenance::Enabled` (r:1 w:0) + /// Proof: `Maintenance::Enabled` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::PendingUnstake` (r:1 w:1) + /// Proof: `AppPromotion::PendingUnstake` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:3 w:3) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(369), added: 2844, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:3 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) /// The range of component `b` is `[0, 3]`. fn on_initialize(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `222 + b * (285 ±0)` // Estimated: `3622 + b * (3774 ±0)` - // Minimum execution time: 4_107_000 picoseconds. - Weight::from_parts(4_751_973, 3622) - // Standard Error: 4_668 - .saturating_add(Weight::from_parts(10_570_330, 0).saturating_mul(b.into())) + // Minimum execution time: 6_031_000 picoseconds. + Weight::from_parts(6_880_848, 3622) + // Standard Error: 18_753 + .saturating_add(Weight::from_parts(22_907_186, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 3774).saturating_mul(b.into())) } - /// Storage: AppPromotion Admin (r:0 w:1) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:0 w:1) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) fn set_admin_address() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_459_000 picoseconds. - Weight::from_parts(3_627_000, 0) + // Minimum execution time: 7_565_000 picoseconds. + Weight::from_parts(7_795_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: ParachainSystem ValidationData (r:1 w:0) - /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AppPromotion PreviousCalculatedRecord (r:1 w:1) - /// Proof: AppPromotion PreviousCalculatedRecord (max_values: Some(1), max_size: Some(36), added: 531, mode: MaxEncodedLen) - /// Storage: AppPromotion Staked (r:1001 w:1000) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: System Account (r:101 w:101) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:100 w:100) - /// Proof: Balances Freezes (max_values: None, max_size: Some(369), added: 2844, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:100 w:0) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AppPromotion::PreviousCalculatedRecord` (r:1 w:1) + /// Proof: `AppPromotion::PreviousCalculatedRecord` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::Staked` (r:1001 w:1000) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:101 w:101) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:100 w:100) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(369), added: 2844, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:100 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// The range of component `b` is `[1, 100]`. fn payout_stakers(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `564 + b * (641 ±0)` // Estimated: `3593 + b * (25550 ±0)` - // Minimum execution time: 73_245_000 picoseconds. - Weight::from_parts(74_196_000, 3593) - // Standard Error: 8_231 - .saturating_add(Weight::from_parts(49_090_053, 0).saturating_mul(b.into())) + // Minimum execution time: 146_577_000 picoseconds. + Weight::from_parts(147_970_000, 3593) + // Standard Error: 59_065 + .saturating_add(Weight::from_parts(115_527_092, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(3_u64)) .saturating_add(T::DbWeight::get().writes((12_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 25550).saturating_mul(b.into())) } - /// Storage: AppPromotion StakesPerAccount (r:1 w:1) - /// Proof: AppPromotion StakesPerAccount (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:1) - /// Proof: Balances Freezes (max_values: None, max_size: Some(369), added: 2844, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:0) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: ParachainSystem ValidationData (r:1 w:0) - /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AppPromotion Staked (r:1 w:1) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: `AppPromotion::StakesPerAccount` (r:1 w:1) + /// Proof: `AppPromotion::StakesPerAccount` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:1) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(369), added: 2844, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AppPromotion::Staked` (r:1 w:1) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn stake() -> Weight { // Proof Size summary in bytes: // Measured: `389` // Estimated: `4764` - // Minimum execution time: 21_088_000 picoseconds. - Weight::from_parts(21_639_000, 4764) + // Minimum execution time: 46_889_000 picoseconds. + Weight::from_parts(47_549_000, 4764) .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: AppPromotion PendingUnstake (r:1 w:1) - /// Proof: AppPromotion PendingUnstake (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: AppPromotion Staked (r:11 w:10) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: AppPromotion StakesPerAccount (r:0 w:1) - /// Proof: AppPromotion StakesPerAccount (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::PendingUnstake` (r:1 w:1) + /// Proof: `AppPromotion::PendingUnstake` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::Staked` (r:11 w:10) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::StakesPerAccount` (r:0 w:1) + /// Proof: `AppPromotion::StakesPerAccount` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn unstake_all() -> Weight { // Proof Size summary in bytes: // Measured: `829` // Estimated: `29095` - // Minimum execution time: 42_086_000 picoseconds. - Weight::from_parts(43_149_000, 29095) + // Minimum execution time: 63_069_000 picoseconds. + Weight::from_parts(64_522_000, 29095) .saturating_add(T::DbWeight::get().reads(14_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: AppPromotion PendingUnstake (r:1 w:1) - /// Proof: AppPromotion PendingUnstake (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: AppPromotion Staked (r:11 w:10) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: AppPromotion StakesPerAccount (r:1 w:1) - /// Proof: AppPromotion StakesPerAccount (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::PendingUnstake` (r:1 w:1) + /// Proof: `AppPromotion::PendingUnstake` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::Staked` (r:11 w:10) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::StakesPerAccount` (r:1 w:1) + /// Proof: `AppPromotion::StakesPerAccount` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn unstake_partial() -> Weight { // Proof Size summary in bytes: // Measured: `829` // Estimated: `29095` - // Minimum execution time: 46_458_000 picoseconds. - Weight::from_parts(47_333_000, 29095) + // Minimum execution time: 84_649_000 picoseconds. + Weight::from_parts(86_173_000, 29095) .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(13_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: Common CollectionById (r:1 w:1) - /// Proof: Common CollectionById (max_values: None, max_size: Some(860), added: 3335, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Common::CollectionById` (r:1 w:1) + /// Proof: `Common::CollectionById` (`max_values`: None, `max_size`: Some(860), added: 3335, mode: `MaxEncodedLen`) fn sponsor_collection() -> Weight { // Proof Size summary in bytes: // Measured: `1060` // Estimated: `4325` - // Minimum execution time: 12_827_000 picoseconds. - Weight::from_parts(13_610_000, 4325) + // Minimum execution time: 24_396_000 picoseconds. + Weight::from_parts(24_917_000, 4325) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: Common CollectionById (r:1 w:1) - /// Proof: Common CollectionById (max_values: None, max_size: Some(860), added: 3335, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Common::CollectionById` (r:1 w:1) + /// Proof: `Common::CollectionById` (`max_values`: None, `max_size`: Some(860), added: 3335, mode: `MaxEncodedLen`) fn stop_sponsoring_collection() -> Weight { // Proof Size summary in bytes: // Measured: `1092` // Estimated: `4325` - // Minimum execution time: 11_899_000 picoseconds. - Weight::from_parts(12_303_000, 4325) + // Minimum execution time: 22_412_000 picoseconds. + Weight::from_parts(23_033_000, 4325) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: EvmContractHelpers Sponsoring (r:0 w:1) - /// Proof: EvmContractHelpers Sponsoring (max_values: None, max_size: Some(62), added: 2537, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `EvmContractHelpers::Sponsoring` (r:0 w:1) + /// Proof: `EvmContractHelpers::Sponsoring` (`max_values`: None, `max_size`: Some(62), added: 2537, mode: `MaxEncodedLen`) fn sponsor_contract() -> Weight { // Proof Size summary in bytes: // Measured: `198` // Estimated: `1517` - // Minimum execution time: 10_226_000 picoseconds. - Weight::from_parts(10_549_000, 1517) + // Minimum execution time: 21_621_000 picoseconds. + Weight::from_parts(22_041_000, 1517) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: EvmContractHelpers Sponsoring (r:1 w:1) - /// Proof: EvmContractHelpers Sponsoring (max_values: None, max_size: Some(62), added: 2537, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `EvmContractHelpers::Sponsoring` (r:1 w:1) + /// Proof: `EvmContractHelpers::Sponsoring` (`max_values`: None, `max_size`: Some(62), added: 2537, mode: `MaxEncodedLen`) fn stop_sponsoring_contract() -> Weight { // Proof Size summary in bytes: // Measured: `396` // Estimated: `3527` - // Minimum execution time: 10_528_000 picoseconds. - Weight::from_parts(10_842_000, 3527) + // Minimum execution time: 19_186_000 picoseconds. + Weight::from_parts(19_616_000, 3527) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -234,185 +234,185 @@ // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: Maintenance Enabled (r:1 w:0) - /// Proof: Maintenance Enabled (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: AppPromotion PendingUnstake (r:1 w:1) - /// Proof: AppPromotion PendingUnstake (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:3 w:3) - /// Proof: Balances Freezes (max_values: None, max_size: Some(369), added: 2844, mode: MaxEncodedLen) - /// Storage: System Account (r:3 w:3) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:3 w:0) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: `Maintenance::Enabled` (r:1 w:0) + /// Proof: `Maintenance::Enabled` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::PendingUnstake` (r:1 w:1) + /// Proof: `AppPromotion::PendingUnstake` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:3 w:3) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(369), added: 2844, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:3 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) /// The range of component `b` is `[0, 3]`. fn on_initialize(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `222 + b * (285 ±0)` // Estimated: `3622 + b * (3774 ±0)` - // Minimum execution time: 4_107_000 picoseconds. - Weight::from_parts(4_751_973, 3622) - // Standard Error: 4_668 - .saturating_add(Weight::from_parts(10_570_330, 0).saturating_mul(b.into())) + // Minimum execution time: 6_031_000 picoseconds. + Weight::from_parts(6_880_848, 3622) + // Standard Error: 18_753 + .saturating_add(Weight::from_parts(22_907_186, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(b.into()))) .saturating_add(RocksDbWeight::get().writes((2_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 3774).saturating_mul(b.into())) } - /// Storage: AppPromotion Admin (r:0 w:1) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:0 w:1) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) fn set_admin_address() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_459_000 picoseconds. - Weight::from_parts(3_627_000, 0) + // Minimum execution time: 7_565_000 picoseconds. + Weight::from_parts(7_795_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: ParachainSystem ValidationData (r:1 w:0) - /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AppPromotion PreviousCalculatedRecord (r:1 w:1) - /// Proof: AppPromotion PreviousCalculatedRecord (max_values: Some(1), max_size: Some(36), added: 531, mode: MaxEncodedLen) - /// Storage: AppPromotion Staked (r:1001 w:1000) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: System Account (r:101 w:101) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:100 w:100) - /// Proof: Balances Freezes (max_values: None, max_size: Some(369), added: 2844, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:100 w:0) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AppPromotion::PreviousCalculatedRecord` (r:1 w:1) + /// Proof: `AppPromotion::PreviousCalculatedRecord` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::Staked` (r:1001 w:1000) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:101 w:101) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:100 w:100) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(369), added: 2844, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:100 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// The range of component `b` is `[1, 100]`. fn payout_stakers(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `564 + b * (641 ±0)` // Estimated: `3593 + b * (25550 ±0)` - // Minimum execution time: 73_245_000 picoseconds. - Weight::from_parts(74_196_000, 3593) - // Standard Error: 8_231 - .saturating_add(Weight::from_parts(49_090_053, 0).saturating_mul(b.into())) + // Minimum execution time: 146_577_000 picoseconds. + Weight::from_parts(147_970_000, 3593) + // Standard Error: 59_065 + .saturating_add(Weight::from_parts(115_527_092, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().reads((13_u64).saturating_mul(b.into()))) .saturating_add(RocksDbWeight::get().writes(3_u64)) .saturating_add(RocksDbWeight::get().writes((12_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 25550).saturating_mul(b.into())) } - /// Storage: AppPromotion StakesPerAccount (r:1 w:1) - /// Proof: AppPromotion StakesPerAccount (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:1) - /// Proof: Balances Freezes (max_values: None, max_size: Some(369), added: 2844, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:0) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: ParachainSystem ValidationData (r:1 w:0) - /// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AppPromotion Staked (r:1 w:1) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: `AppPromotion::StakesPerAccount` (r:1 w:1) + /// Proof: `AppPromotion::StakesPerAccount` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:1) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(369), added: 2844, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AppPromotion::Staked` (r:1 w:1) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn stake() -> Weight { // Proof Size summary in bytes: // Measured: `389` // Estimated: `4764` - // Minimum execution time: 21_088_000 picoseconds. - Weight::from_parts(21_639_000, 4764) + // Minimum execution time: 46_889_000 picoseconds. + Weight::from_parts(47_549_000, 4764) .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: AppPromotion PendingUnstake (r:1 w:1) - /// Proof: AppPromotion PendingUnstake (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: AppPromotion Staked (r:11 w:10) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: AppPromotion StakesPerAccount (r:0 w:1) - /// Proof: AppPromotion StakesPerAccount (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::PendingUnstake` (r:1 w:1) + /// Proof: `AppPromotion::PendingUnstake` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::Staked` (r:11 w:10) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::StakesPerAccount` (r:0 w:1) + /// Proof: `AppPromotion::StakesPerAccount` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn unstake_all() -> Weight { // Proof Size summary in bytes: // Measured: `829` // Estimated: `29095` - // Minimum execution time: 42_086_000 picoseconds. - Weight::from_parts(43_149_000, 29095) + // Minimum execution time: 63_069_000 picoseconds. + Weight::from_parts(64_522_000, 29095) .saturating_add(RocksDbWeight::get().reads(14_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } - /// Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0) - /// Proof: Configuration AppPromomotionConfigurationOverride (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - /// Storage: AppPromotion PendingUnstake (r:1 w:1) - /// Proof: AppPromotion PendingUnstake (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: AppPromotion Staked (r:11 w:10) - /// Proof: AppPromotion Staked (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: AppPromotion TotalStaked (r:1 w:1) - /// Proof: AppPromotion TotalStaked (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: AppPromotion StakesPerAccount (r:1 w:1) - /// Proof: AppPromotion StakesPerAccount (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: `Configuration::AppPromomotionConfigurationOverride` (r:1 w:0) + /// Proof: `Configuration::AppPromomotionConfigurationOverride` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::PendingUnstake` (r:1 w:1) + /// Proof: `AppPromotion::PendingUnstake` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::Staked` (r:11 w:10) + /// Proof: `AppPromotion::Staked` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::TotalStaked` (r:1 w:1) + /// Proof: `AppPromotion::TotalStaked` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `AppPromotion::StakesPerAccount` (r:1 w:1) + /// Proof: `AppPromotion::StakesPerAccount` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn unstake_partial() -> Weight { // Proof Size summary in bytes: // Measured: `829` // Estimated: `29095` - // Minimum execution time: 46_458_000 picoseconds. - Weight::from_parts(47_333_000, 29095) + // Minimum execution time: 84_649_000 picoseconds. + Weight::from_parts(86_173_000, 29095) .saturating_add(RocksDbWeight::get().reads(15_u64)) .saturating_add(RocksDbWeight::get().writes(13_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: Common CollectionById (r:1 w:1) - /// Proof: Common CollectionById (max_values: None, max_size: Some(860), added: 3335, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Common::CollectionById` (r:1 w:1) + /// Proof: `Common::CollectionById` (`max_values`: None, `max_size`: Some(860), added: 3335, mode: `MaxEncodedLen`) fn sponsor_collection() -> Weight { // Proof Size summary in bytes: // Measured: `1060` // Estimated: `4325` - // Minimum execution time: 12_827_000 picoseconds. - Weight::from_parts(13_610_000, 4325) + // Minimum execution time: 24_396_000 picoseconds. + Weight::from_parts(24_917_000, 4325) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: Common CollectionById (r:1 w:1) - /// Proof: Common CollectionById (max_values: None, max_size: Some(860), added: 3335, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Common::CollectionById` (r:1 w:1) + /// Proof: `Common::CollectionById` (`max_values`: None, `max_size`: Some(860), added: 3335, mode: `MaxEncodedLen`) fn stop_sponsoring_collection() -> Weight { // Proof Size summary in bytes: // Measured: `1092` // Estimated: `4325` - // Minimum execution time: 11_899_000 picoseconds. - Weight::from_parts(12_303_000, 4325) + // Minimum execution time: 22_412_000 picoseconds. + Weight::from_parts(23_033_000, 4325) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: EvmContractHelpers Sponsoring (r:0 w:1) - /// Proof: EvmContractHelpers Sponsoring (max_values: None, max_size: Some(62), added: 2537, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `EvmContractHelpers::Sponsoring` (r:0 w:1) + /// Proof: `EvmContractHelpers::Sponsoring` (`max_values`: None, `max_size`: Some(62), added: 2537, mode: `MaxEncodedLen`) fn sponsor_contract() -> Weight { // Proof Size summary in bytes: // Measured: `198` // Estimated: `1517` - // Minimum execution time: 10_226_000 picoseconds. - Weight::from_parts(10_549_000, 1517) + // Minimum execution time: 21_621_000 picoseconds. + Weight::from_parts(22_041_000, 1517) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: AppPromotion Admin (r:1 w:0) - /// Proof: AppPromotion Admin (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: EvmContractHelpers Sponsoring (r:1 w:1) - /// Proof: EvmContractHelpers Sponsoring (max_values: None, max_size: Some(62), added: 2537, mode: MaxEncodedLen) + /// Storage: `AppPromotion::Admin` (r:1 w:0) + /// Proof: `AppPromotion::Admin` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `EvmContractHelpers::Sponsoring` (r:1 w:1) + /// Proof: `EvmContractHelpers::Sponsoring` (`max_values`: None, `max_size`: Some(62), added: 2537, mode: `MaxEncodedLen`) fn stop_sponsoring_contract() -> Weight { // Proof Size summary in bytes: // Measured: `396` // Estimated: `3527` - // Minimum execution time: 10_528_000 picoseconds. - Weight::from_parts(10_842_000, 3527) + // Minimum execution time: 19_186_000 picoseconds. + Weight::from_parts(19_616_000, 3527) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } --- a/pallets/collator-selection/Cargo.toml +++ b/pallets/collator-selection/Cargo.toml @@ -14,7 +14,7 @@ [dependencies] log = { workspace = true } parity-scale-codec = { workspace = true } -rand = { version = "0.8.5", default-features = false } +rand = { version = "0.8.5", default-features = false, features = ["std_rng"] } scale-info = { workspace = true } serde = { workspace = true } --- a/pallets/collator-selection/src/benchmarking.rs +++ b/pallets/collator-selection/src/benchmarking.rs @@ -32,7 +32,9 @@ //! Benchmarking setup for pallet-collator-selection -use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_benchmarking::v2::{ + account, benchmarks, impl_benchmark_test_suite, whitelisted_caller, BenchmarkError, +}; use frame_support::{ assert_ok, traits::{ @@ -159,16 +161,18 @@ /// Our benchmarking environment already has invulnerables registered. const INITIAL_INVULNERABLES: u32 = 2; -benchmarks! { - where_clause { where - T: Config + pallet_authorship::Config + session::Config - } +#[benchmarks(where T: Config + pallet_authorship::Config + session::Config)] +mod benchmarks { + use super::*; + const MAX_COLLATORS: u32 = 10; + const MAX_INVULNERABLES: u32 = MAX_COLLATORS - INITIAL_INVULNERABLES; // todo:collator this and all the following do not work for some reason, going all the way up to 10 in length // Both invulnerables and candidates count together against MaxCollators. // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2) - add_invulnerable { - let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1; + #[benchmark] + fn add_invulnerable(b: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> { + let b = b - 1; register_validators::(b); register_invulnerables::(b); @@ -181,39 +185,59 @@ >::set_keys( RawOrigin::Signed(new_invulnerable.clone()).into(), keys::(b + 1), - Vec::new() - ).unwrap(); + Vec::new(), + ) + .unwrap(); let root_origin = T::UpdateOrigin::try_successful_origin().unwrap(); - }: { - assert_ok!( - >::add_invulnerable(root_origin, new_invulnerable.clone()) + + #[block] + { + assert_ok!(>::add_invulnerable( + root_origin, + new_invulnerable.clone() + )); + } + + assert_last_event::( + Event::InvulnerableAdded { + invulnerable: new_invulnerable, + } + .into(), ); - } - verify { - assert_last_event::(Event::InvulnerableAdded{invulnerable: new_invulnerable}.into()); + + Ok(()) } - remove_invulnerable { - let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1; + #[benchmark] + fn remove_invulnerable(b: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> { register_validators::(b); register_invulnerables::(b); let root_origin = T::UpdateOrigin::try_successful_origin().unwrap(); let leaving = >::get().last().unwrap().clone(); whitelist!(leaving); - }: { - assert_ok!( - >::remove_invulnerable(root_origin, leaving.clone()) + + #[block] + { + assert_ok!(>::remove_invulnerable( + root_origin, + leaving.clone() + )); + } + + assert_last_event::( + Event::InvulnerableRemoved { + invulnerable: leaving, + } + .into(), ); - } - verify { - assert_last_event::(Event::InvulnerableRemoved{invulnerable: leaving}.into()); + + Ok(()) } - get_license { - let c in 1 .. T::MaxCollators::get() - 1; - + #[benchmark] + fn get_license(c: Linear<1, MAX_COLLATORS>) -> Result<(), BenchmarkError> { register_validators::(c); get_licenses::(c); @@ -224,19 +248,29 @@ >::set_keys( RawOrigin::Signed(caller.clone()).into(), keys::(c + 1), - Vec::new() - ).unwrap(); + Vec::new(), + ) + .unwrap(); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone())); + + assert_last_event::( + Event::LicenseObtained { + account_id: caller, + deposit: bond / 2u32.into(), + } + .into(), + ); - }: _(RawOrigin::Signed(caller.clone())) - verify { - assert_last_event::(Event::LicenseObtained{account_id: caller, deposit: bond / 2u32.into()}.into()); + Ok(()) } // worst case is when we have all the max-candidate slots filled except one, and we fill that // one. - onboard { - let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1; - + #[benchmark] + fn onboard(c: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> { + let c = c - 1; register_validators::(c); register_candidates::(c); @@ -246,37 +280,44 @@ let origin = RawOrigin::Signed(caller.clone()); - >::set_keys( - origin.clone().into(), - keys::(c + 1), - Vec::new() - ).unwrap(); + >::set_keys(origin.clone().into(), keys::(c + 1), Vec::new()) + .unwrap(); + + assert_ok!(>::get_license(origin.clone().into())); - assert_ok!( - >::get_license(origin.clone().into()) - ); - }: _(origin) - verify { - assert_last_event::(Event::CandidateAdded{account_id: caller}.into()); + #[extrinsic_call] + _(origin); + + assert_last_event::(Event::CandidateAdded { account_id: caller }.into()); + + Ok(()) } // worst case is the last candidate leaving. - offboard { - let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES; - + #[benchmark] + fn offboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> { register_validators::(c); register_candidates::(c); let leaving = >::get().last().unwrap().clone(); whitelist!(leaving); - }: _(RawOrigin::Signed(leaving.clone())) - verify { - assert_last_event::(Event::CandidateRemoved{account_id: leaving}.into()); + + #[extrinsic_call] + _(RawOrigin::Signed(leaving.clone())); + + assert_last_event::( + Event::CandidateRemoved { + account_id: leaving, + } + .into(), + ); + + Ok(()) } // worst case is the last candidate leaving. - release_license { - let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES; + #[benchmark] + fn release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> { let bond = balance_unit::(); register_validators::(c); @@ -284,14 +325,24 @@ let leaving = >::get().last().unwrap().clone(); whitelist!(leaving); - }: _(RawOrigin::Signed(leaving.clone())) - verify { - assert_last_event::(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into()); + + #[extrinsic_call] + _(RawOrigin::Signed(leaving.clone())); + + assert_last_event::( + Event::LicenseReleased { + account_id: leaving, + deposit_returned: bond, + } + .into(), + ); + + Ok(()) } // worst case is the last candidate leaving. - force_release_license { - let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES; + #[benchmark] + fn force_release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> { let bond = balance_unit::(); register_validators::(c); @@ -300,44 +351,62 @@ let leaving = >::get().last().unwrap().clone(); whitelist!(leaving); let origin = T::UpdateOrigin::try_successful_origin().unwrap(); - }: { - assert_ok!( - >::force_release_license(origin, leaving.clone()) + + #[block] + { + assert_ok!(>::force_release_license( + origin, + leaving.clone() + )); + } + + assert_last_event::( + Event::LicenseReleased { + account_id: leaving, + deposit_returned: bond, + } + .into(), ); - } - verify { - assert_last_event::(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into()); + + Ok(()) } // worst case is paying a non-existing candidate account. - note_author { + #[benchmark] + fn note_author() -> Result<(), BenchmarkError> { T::Currency::set_balance( &>::account_id(), balance_unit::() * 4u32.into(), ); let author = account("author", 0, SEED); - let new_block: BlockNumberFor= 10u32.into(); + let new_block: BlockNumberFor = 10u32.into(); frame_system::Pallet::::set_block_number(new_block); assert!(T::Currency::balance(&author) == 0u32.into()); - }: { - as EventHandler<_, _>>::note_author(author.clone()) - } verify { + + #[block] + { + as EventHandler<_, _>>::note_author(author.clone()); + } + assert!(T::Currency::balance(&author) > 0u32.into()); assert_eq!(frame_system::Pallet::::block_number(), new_block); + + Ok(()) } // worst case for new session. - new_session { - let r in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES; - let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES; - + #[benchmark] + fn new_session( + r: Linear<1, MAX_INVULNERABLES>, + c: Linear<1, MAX_INVULNERABLES>, + ) -> Result<(), BenchmarkError> { frame_system::Pallet::::set_block_number(0u32.into()); register_validators::(c); register_candidates::(c); - let new_block: BlockNumberFor= 1800u32.into(); + let new_block: BlockNumberFor = 1800u32.into(); let zero_block: BlockNumberFor = 0u32.into(); let candidates = >::get(); @@ -362,19 +431,24 @@ frame_system::Pallet::::set_block_number(new_block); assert!(>::get().len() == c as usize); - }: { - as SessionManager<_>>::new_session(0) - } verify { + + #[block] + { + as SessionManager<_>>::new_session(0); + } + if c > r { assert!(>::get().len() < pre_length); } else { assert!(>::get().len() == pre_length); } + + Ok(()) } -} -impl_benchmark_test_suite!( - CollatorSelection, - crate::mock::new_test_ext(), - crate::mock::Test, -); + impl_benchmark_test_suite!( + CollatorSelection, + crate::mock::new_test_ext(), + crate::mock::Test, + ); +} --- a/pallets/common/src/benchmarking.rs +++ b/pallets/common/src/benchmarking.rs @@ -18,7 +18,7 @@ use core::convert::TryInto; -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::{account, v2::*}; use frame_support::{ pallet_prelude::ConstU32, traits::{fungible::Balanced, tokens::Precision, Get, Imbalance}, @@ -26,7 +26,7 @@ }; use pallet_evm::account::CrossAccountId; use sp_runtime::{traits::Zero, DispatchError}; -use sp_std::vec::Vec; +use sp_std::{vec, vec::Vec}; use up_data_structs::{ AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData, NestingPermissions, PropertiesPermissionMap, Property, PropertyKey, PropertyValue, @@ -178,62 +178,103 @@ () => {} } -benchmarks! { - set_collection_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn set_collection_properties( + b: Linear<0, MAX_PROPERTIES_PER_ITEM>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let props = (0..b).map(|p| Property { - key: property_key(p as usize), - value: property_value(), - }).collect::>(); - }: {>::set_collection_properties(&collection, &owner, props.into_iter())?} + let props = (0..b) + .map(|p| Property { + key: property_key(p as usize), + value: property_value(), + }) + .collect::>(); + + #[block] + { + >::set_collection_properties(&collection, &owner, props.into_iter())?; + } + + Ok(()) + } - delete_collection_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[benchmark] + fn delete_collection_properties( + b: Linear<0, MAX_PROPERTIES_PER_ITEM>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let props = (0..b).map(|p| Property { - key: property_key(p as usize), - value: property_value(), - }).collect::>(); + let props = (0..b) + .map(|p| Property { + key: property_key(p as usize), + value: property_value(), + }) + .collect::>(); >::set_collection_properties(&collection, &owner, props.into_iter())?; let to_delete = (0..b).map(|p| property_key(p as usize)).collect::>(); - }: {>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?} - check_accesslist{ - bench_init!{ + #[block] + { + >::delete_collection_properties(&collection, &owner, to_delete.into_iter())?; + } + + Ok(()) + } + + #[benchmark] + fn check_accesslist() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); }; let mut collection_handle = >::try_get(collection.id)?; - >::update_permissions( - &sender, - &mut collection_handle, - CollectionPermissions { access: Some(AccessMode::AllowList), ..Default::default() } - )?; + >::update_permissions( + &sender, + &mut collection_handle, + CollectionPermissions { + access: Some(AccessMode::AllowList), + ..Default::default() + }, + )?; - >::toggle_allowlist( - &collection, - &sender, - &sender, - true, - )?; + >::toggle_allowlist(&collection, &sender, &sender, true)?; - assert_eq!(collection_handle.permissions.access(), AccessMode::AllowList); + assert_eq!( + collection_handle.permissions.access(), + AccessMode::AllowList + ); + + #[block] + { + collection_handle.check_allowlist(&sender)?; + } - }: {collection_handle.check_allowlist(&sender)?;} + Ok(()) + } - init_token_properties_common { - bench_init!{ + #[benchmark] + fn init_token_properties_common() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: sub; sender: cross_from_sub(sender); }; - }: {load_is_admin_and_property_permissions(&collection, &sender);} + + #[block] + { + load_is_admin_and_property_permissions(&collection, &sender); + } + + Ok(()) + } } --- a/pallets/configuration/src/benchmarking.rs +++ b/pallets/configuration/src/benchmarking.rs @@ -16,9 +16,10 @@ //! Benchmarking setup for pallet-configuration -use frame_benchmarking::benchmarks; +use frame_benchmarking::v2::*; use frame_support::assert_ok; use frame_system::{pallet_prelude::*, EventRecord, RawOrigin}; +use sp_std::vec; use super::*; @@ -30,66 +31,117 @@ assert_eq!(event, &system_event); } -benchmarks! { - where_clause { where +#[benchmarks( + where T: Config, T::Balance: From - } +)] +mod benchmarks { + use super::*; - set_weight_to_fee_coefficient_override { + #[benchmark] + fn set_weight_to_fee_coefficient_override() -> Result<(), BenchmarkError> { let coeff: u64 = 999; - }: { - assert_ok!( - >::set_weight_to_fee_coefficient_override(RawOrigin::Root.into(), Some(coeff)) - ); + + #[block] + { + assert_ok!(>::set_weight_to_fee_coefficient_override( + RawOrigin::Root.into(), + Some(coeff) + )); + } + + Ok(()) } - set_min_gas_price_override { + #[benchmark] + fn set_min_gas_price_override() -> Result<(), BenchmarkError> { let coeff: u64 = 999; - }: { - assert_ok!( - >::set_min_gas_price_override(RawOrigin::Root.into(), Some(coeff)) - ); + + #[block] + { + assert_ok!(>::set_min_gas_price_override( + RawOrigin::Root.into(), + Some(coeff) + )); + } + + Ok(()) } - set_app_promotion_configuration_override { + #[benchmark] + fn set_app_promotion_configuration_override() -> Result<(), BenchmarkError> { let configuration: AppPromotionConfiguration> = Default::default(); - }: { - assert_ok!( - >::set_app_promotion_configuration_override(RawOrigin::Root.into(), configuration) - ); + + #[block] + { + assert_ok!(>::set_app_promotion_configuration_override( + RawOrigin::Root.into(), + configuration + )); + } + + Ok(()) } - set_collator_selection_desired_collators { + #[benchmark] + fn set_collator_selection_desired_collators() -> Result<(), BenchmarkError> { let max: u32 = 999; - }: { - assert_ok!( - >::set_collator_selection_desired_collators(RawOrigin::Root.into(), Some(max)) + + #[block] + { + assert_ok!(>::set_collator_selection_desired_collators( + RawOrigin::Root.into(), + Some(max) + )); + } + + assert_last_event::( + Event::NewDesiredCollators { + desired_collators: Some(max), + } + .into(), ); + + Ok(()) } - verify { - assert_last_event::(Event::NewDesiredCollators{desired_collators: Some(max)}.into()); - } - set_collator_selection_license_bond { + #[benchmark] + fn set_collator_selection_license_bond() -> Result<(), BenchmarkError> { let bond_cost: Option = Some(1000u32.into()); - }: { - assert_ok!( - >::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost) - ); - } - verify { - assert_last_event::(Event::NewCollatorLicenseBond{bond_cost}.into()); + + #[block] + { + assert_ok!(>::set_collator_selection_license_bond( + RawOrigin::Root.into(), + bond_cost + )); + } + + assert_last_event::(Event::NewCollatorLicenseBond { bond_cost }.into()); + + Ok(()) } - set_collator_selection_kick_threshold { + #[benchmark] + fn set_collator_selection_kick_threshold() -> Result<(), BenchmarkError> { let threshold: Option> = Some(900u32.into()); - }: { - assert_ok!( - >::set_collator_selection_kick_threshold(RawOrigin::Root.into(), threshold) + + #[block] + { + assert_ok!(>::set_collator_selection_kick_threshold( + RawOrigin::Root.into(), + threshold + )); + } + + assert_last_event::( + Event::NewCollatorKickThreshold { + length_in_blocks: threshold, + } + .into(), ); - } - verify { - assert_last_event::(Event::NewCollatorKickThreshold{length_in_blocks: threshold}.into()); + + Ok(()) } } --- a/pallets/evm-migration/src/benchmarking.rs +++ b/pallets/evm-migration/src/benchmarking.rs @@ -16,21 +16,29 @@ #![allow(missing_docs)] -use frame_benchmarking::benchmarks; +use frame_benchmarking::v2::*; use frame_system::RawOrigin; use sp_core::{H160, H256}; use sp_std::{vec, vec::Vec}; use super::{Call, Config, Pallet}; -benchmarks! { - where_clause { where ::RuntimeEvent: parity_scale_codec::Encode } +#[benchmarks( + where ::RuntimeEvent: parity_scale_codec::Encode +)] +mod benchmarks { + use super::*; + + #[benchmark] + fn begin() -> Result<(), BenchmarkError> { + #[extrinsic_call] + _(RawOrigin::Root, H160::default()); - begin { - }: _(RawOrigin::Root, H160::default()) + Ok(()) + } - set_data { - let b in 0..80; + #[benchmark] + fn set_data(b: Linear<0, 80>) -> Result<(), BenchmarkError> { let address = H160::from_low_u64_be(b as u64); let mut data = Vec::new(); for i in 0..b { @@ -40,27 +48,51 @@ )); } >::begin(RawOrigin::Root.into(), address)?; - }: _(RawOrigin::Root, address, data) - finish { - let b in 0..80; + #[extrinsic_call] + _(RawOrigin::Root, address, data); + + Ok(()) + } + + #[benchmark] + fn finish(b: Linear<0, 80>) -> Result<(), BenchmarkError> { let address = H160::from_low_u64_be(b as u64); let data: Vec = (0..b as u8).collect(); >::begin(RawOrigin::Root.into(), address)?; - }: _(RawOrigin::Root, address, data) - insert_eth_logs { - let b in 0..200; - let logs = (0..b).map(|_| ethereum::Log { - address: H160([b as u8; 20]), - data: vec![b as u8; 128], - topics: vec![H256([b as u8; 32]); 6], - }).collect::>(); - }: _(RawOrigin::Root, logs) + #[extrinsic_call] + _(RawOrigin::Root, address, data); + + Ok(()) + } + + #[benchmark] + fn insert_eth_logs(b: Linear<0, 200>) -> Result<(), BenchmarkError> { + let logs = (0..b) + .map(|_| ethereum::Log { + address: H160([b as u8; 20]), + data: vec![b as u8; 128], + topics: vec![H256([b as u8; 32]); 6], + }) + .collect::>(); - insert_events { - let b in 0..200; + #[extrinsic_call] + _(RawOrigin::Root, logs); + + Ok(()) + } + + #[benchmark] + fn insert_events(b: Linear<0, 200>) -> Result<(), BenchmarkError> { use parity_scale_codec::Encode; - let logs = (0..b).map(|_| ::RuntimeEvent::from(crate::Event::::TestEvent).encode()).collect::>(); - }: _(RawOrigin::Root, logs) + let logs = (0..b) + .map(|_| ::RuntimeEvent::from(crate::Event::::TestEvent).encode()) + .collect::>(); + + #[extrinsic_call] + _(RawOrigin::Root, logs); + + Ok(()) + } } --- a/pallets/foreign-assets/src/benchmarking.rs +++ b/pallets/foreign-assets/src/benchmarking.rs @@ -16,10 +16,10 @@ #![allow(missing_docs)] -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::{account, v2::*}; use frame_support::traits::Currency; use frame_system::RawOrigin; -use sp_std::{boxed::Box, vec::Vec}; +use sp_std::{boxed::Box, vec, vec::Vec}; use staging_xcm::{opaque::latest::Junction::Parachain, v3::Junctions::X1, VersionedMultiLocation}; use super::{Call, Config, Pallet}; @@ -31,42 +31,74 @@ .unwrap() } -benchmarks! { - register_foreign_asset { +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn register_foreign_asset() -> Result<(), BenchmarkError> { let owner: T::AccountId = account("user", 0, 1); let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(1000))); - let metadata: AssetMetadata<<::Currency as Currency<::AccountId>>::Balance> = AssetMetadata{ + let metadata: AssetMetadata< + <::Currency as Currency<::AccountId>>::Balance, + > = AssetMetadata { name: bounded(b"name"), symbol: bounded(b"symbol"), decimals: 18, - minimal_balance: 1u32.into() + minimal_balance: 1u32.into(), }; - let mut balance: <::Currency as Currency<::AccountId>>::Balance = - 4_000_000_000u32.into(); + let mut balance: <::Currency as Currency< + ::AccountId, + >>::Balance = 4_000_000_000u32.into(); balance = balance * balance; - ::Currency::make_free_balance_be(&owner, - balance); - }: _(RawOrigin::Root, owner, Box::new(location), Box::new(metadata)) + ::Currency::make_free_balance_be(&owner, balance); + + #[extrinsic_call] + _( + RawOrigin::Root, + owner, + Box::new(location), + Box::new(metadata), + ); + + Ok(()) + } - update_foreign_asset { + #[benchmark] + fn update_foreign_asset() -> Result<(), BenchmarkError> { let owner: T::AccountId = account("user", 0, 1); let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(2000))); - let metadata: AssetMetadata<<::Currency as Currency<::AccountId>>::Balance> = AssetMetadata{ + let metadata: AssetMetadata< + <::Currency as Currency<::AccountId>>::Balance, + > = AssetMetadata { name: bounded(b"name"), symbol: bounded(b"symbol"), decimals: 18, - minimal_balance: 1u32.into() + minimal_balance: 1u32.into(), }; - let metadata2: AssetMetadata<<::Currency as Currency<::AccountId>>::Balance> = AssetMetadata{ + let metadata2: AssetMetadata< + <::Currency as Currency<::AccountId>>::Balance, + > = AssetMetadata { name: bounded(b"name2"), symbol: bounded(b"symbol2"), decimals: 18, - minimal_balance: 1u32.into() + minimal_balance: 1u32.into(), }; - let mut balance: <::Currency as Currency<::AccountId>>::Balance = - 4_000_000_000u32.into(); + let mut balance: <::Currency as Currency< + ::AccountId, + >>::Balance = 4_000_000_000u32.into(); balance = balance * balance; ::Currency::make_free_balance_be(&owner, balance); - Pallet::::register_foreign_asset(RawOrigin::Root.into(), owner, Box::new(location.clone()), Box::new(metadata))?; - }: _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2)) + Pallet::::register_foreign_asset( + RawOrigin::Root.into(), + owner, + Box::new(location.clone()), + Box::new(metadata), + )?; + + #[extrinsic_call] + _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2)); + + Ok(()) + } } --- a/pallets/fungible/src/benchmarking.rs +++ b/pallets/fungible/src/benchmarking.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::{account, v2::*}; use pallet_common::{bench_init, benchmarking::create_collection_raw}; use sp_std::prelude::*; use up_data_structs::{budget::Unlimited, CollectionMode, MAX_ITEMS_PER_BATCH}; @@ -35,83 +35,159 @@ ) } -benchmarks! { - create_item { - bench_init!{ +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn create_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); to: cross_sub; }; - }: {>::create_item(&collection, &sender, (to, 200), &Unlimited)?} - create_multiple_items_ex { - let b in 0..MAX_ITEMS_PER_BATCH; - bench_init!{ + #[block] + { + >::create_item(&collection, &sender, (to, 200), &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn create_multiple_items_ex(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); }; - let data = (0..b).map(|i| { - bench_init!(to: cross_sub(i);); - (to, 200) - }).collect::>(); - }: {>::create_multiple_items(&collection, &sender, data, &Unlimited)?} + let data = (0..b) + .map(|i| { + bench_init!(to: cross_sub(i);); + (to, 200) + }) + .collect::>(); + + #[block] + { + >::create_multiple_items(&collection, &sender, data, &Unlimited)?; + } + + Ok(()) + } - burn_item { - bench_init!{ + #[benchmark] + fn burn_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; burner: cross_sub; }; >::create_item(&collection, &owner, (burner.clone(), 200), &Unlimited)?; - }: {>::burn(&collection, &burner, 100)?} - transfer_raw { - bench_init!{ + #[block] + { + >::burn(&collection, &burner, 100)?; + } + + Ok(()) + } + + #[benchmark] + fn transfer_raw() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; to: cross_sub; }; >::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?; - }: {>::transfer(&collection, &sender, &to, 200, &Unlimited)?} - approve { - bench_init!{ + #[block] + { + >::transfer(&collection, &sender, &to, 200, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn approve() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; >::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?; - }: {>::set_allowance(&collection, &sender, &spender, 100)?} - approve_from { - bench_init!{ + #[block] + { + >::set_allowance(&collection, &sender, &spender, 100)?; + } + + Ok(()) + } + + #[benchmark] + fn approve_from() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth()); >::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?; - }: {>::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?} - check_allowed_raw { - bench_init!{ + #[block] + { + >::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?; + } + + Ok(()) + } + + #[benchmark] + fn check_allowed_raw() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; >::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?; >::set_allowance(&collection, &sender, &spender, 200)?; - }: {>::check_allowed(&collection, &spender, &sender, 200, &Unlimited)?;} - set_allowance_unchecked_raw { - bench_init!{ + #[block] + { + >::check_allowed(&collection, &spender, &sender, 200, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn set_allowance_unchecked_raw() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; >::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?; - }: {>::set_allowance_unchecked(&collection, &sender, &spender, 200);} - burn_from { - bench_init!{ + #[block] + { + >::set_allowance_unchecked(&collection, &sender, &spender, 200); + } + + Ok(()) + } + + #[benchmark] + fn burn_from() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; burner: cross_sub; }; >::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?; >::set_allowance(&collection, &sender, &burner, 200)?; - }: {>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?} + + #[block] + { + >::burn_from(&collection, &burner, &sender, 100, &Unlimited)? + } + + Ok(()) + } } --- a/pallets/identity/src/benchmarking.rs +++ b/pallets/identity/src/benchmarking.rs @@ -37,11 +37,8 @@ #![cfg(feature = "runtime-benchmarks")] #![allow(clippy::no_effect)] -use frame_benchmarking::{account, benchmarks, whitelisted_caller}; -use frame_support::{ - assert_ok, ensure, - traits::{EnsureOrigin, Get}, -}; +use frame_benchmarking::v2::*; +use frame_support::{assert_ok, ensure, traits::EnsureOrigin}; use frame_system::RawOrigin; use sp_runtime::traits::Bounded; @@ -145,25 +142,48 @@ 200u32.into() } -benchmarks! { - add_registrar { - let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; - ensure!(Registrars::::get().len() as u32 == r, "Registrars not set up correctly."); +#[benchmarks] +mod benchmarks { + use super::*; + + const MAX_REGISTRARS: u32 = 20; + const MAX_ADDITIONAL_FIELDS: u32 = 100; + const MAX_SUB_ACCOUNTS: u32 = 100; + + #[benchmark] + fn add_registrar(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> { + let r = r - 1; + add_registrars::(r)?; + ensure!( + Registrars::::get().len() as u32 == r, + "Registrars not set up correctly." + ); let origin = T::RegistrarOrigin::try_successful_origin().unwrap(); let account = T::Lookup::unlookup(account("registrar", r + 1, SEED)); - }: _(origin, account) - verify { - ensure!(Registrars::::get().len() as u32 == r + 1, "Registrars not added."); + + #[extrinsic_call] + _(origin as T::RuntimeOrigin, account); + + ensure!( + Registrars::::get().len() as u32 == r + 1, + "Registrars not added." + ); + + Ok(()) } - set_identity { - let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let x in 0 .. T::MaxAdditionalFields::get(); + #[benchmark] + fn set_identity( + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + r: Linear<1, MAX_REGISTRARS>, + ) -> Result<(), BenchmarkError> { + add_registrars::(r)?; let caller = { // The target user let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); - let caller_origin: ::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); + let caller_origin: ::RuntimeOrigin = + RawOrigin::Signed(caller.clone()).into(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); // Add an initial identity @@ -173,8 +193,7 @@ // User requests judgement from all the registrars, and they approve for i in 0..r { let registrar: T::AccountId = account("registrar", i, SEED); - let registrar_lookup = T::Lookup::unlookup(registrar.clone()); - let balance_to_use = balance_unit::() * 10u32.into(); + let balance_to_use = balance_unit::() * 10u32.into(); let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use); Identity::::request_judgement(caller_origin.clone(), i, 10u32.into())?; @@ -188,66 +207,91 @@ } caller }; - }: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::(x))) - verify { + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + Box::new(create_identity_info::(x)), + ); + assert_last_event::(Event::::IdentitySet { who: caller }.into()); + + Ok(()) } // We need to split `set_subs` into two benchmarks to accurately isolate the potential // writes caused by new or old sub accounts. The actual weight should simply be // the sum of these two weights. - set_subs_new { + #[benchmark] + fn set_subs_new(s: Linear<0, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); // Create a new subs vec with s sub accounts - let s in 0 .. T::MaxSubAccounts::get() => (); let subs = create_sub_accounts::(&caller, s)?; - ensure!(SubsOf::::get(&caller).1.len() == 0, "Caller already has subs"); - }: set_subs(RawOrigin::Signed(caller.clone()), subs) - verify { - ensure!(SubsOf::::get(&caller).1.len() as u32 == s, "Subs not added"); + ensure!( + SubsOf::::get(&caller).1.len() == 0, + "Caller already has subs" + ); + + #[extrinsic_call] + set_subs(RawOrigin::Signed(caller.clone()), subs); + + ensure!( + SubsOf::::get(&caller).1.len() as u32 == s, + "Subs not added" + ); + + Ok(()) } - set_subs_old { + #[benchmark] + fn set_subs_old(p: Linear<0, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); // Give them p many previous sub accounts. - let p in 0 .. T::MaxSubAccounts::get() => { - let _ = add_sub_accounts::(&caller, p)?; - }; + let _ = add_sub_accounts::(&caller, p)?; // Remove all subs. let subs = create_sub_accounts::(&caller, 0)?; ensure!( SubsOf::::get(&caller).1.len() as u32 == p, "Caller does have subs", ); - }: set_subs(RawOrigin::Signed(caller.clone()), subs) - verify { + + #[extrinsic_call] + set_subs(RawOrigin::Signed(caller.clone()), subs); + ensure!(SubsOf::::get(&caller).1.len() == 0, "Subs not removed"); + + Ok(()) } - clear_identity { + #[benchmark] + fn clear_identity( + r: Linear<1, MAX_REGISTRARS>, + s: Linear<0, MAX_SUB_ACCOUNTS>, + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + ) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); let caller_lookup = ::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let s in 0 .. T::MaxSubAccounts::get() => { + add_registrars::(r)?; + + { // Give them s many sub accounts let caller: T::AccountId = whitelisted_caller(); let _ = add_sub_accounts::(&caller, s)?; - }; - let x in 0 .. T::MaxAdditionalFields::get(); + } // Create their main identity with x additional fields let info = create_identity_info::(x); let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::::set_identity(caller_origin.clone(), Box::new(info.clone()))?; // User requests judgement from all the registrars, and they approve for i in 0..r { let registrar: T::AccountId = account("registrar", i, SEED); - let balance_to_use = balance_unit::() * 10u32.into(); + let balance_to_use = balance_unit::() * 10u32.into(); let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use); Identity::::request_judgement(caller_origin.clone(), i, 10u32.into())?; @@ -259,108 +303,199 @@ T::Hashing::hash_of(&info), )?; } - ensure!(IdentityOf::::contains_key(&caller), "Identity does not exist."); - }: _(RawOrigin::Signed(caller.clone())) - verify { - ensure!(!IdentityOf::::contains_key(&caller), "Identity not cleared."); + ensure!( + IdentityOf::::contains_key(&caller), + "Identity does not exist." + ); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone())); + + ensure!( + !IdentityOf::::contains_key(&caller), + "Identity not cleared." + ); + + Ok(()) } - request_judgement { + #[benchmark] + fn request_judgement( + r: Linear<1, MAX_REGISTRARS>, + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + ) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let x in 0 .. T::MaxAdditionalFields::get() => { + add_registrars::(r)?; + + { // Create their main identity with x additional fields let info = create_identity_info::(x); let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller)); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller)); Identity::::set_identity(caller_origin, Box::new(info))?; - }; - }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into()) - verify { - assert_last_event::(Event::::JudgementRequested { who: caller, registrar_index: r-1 }.into()); + } + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into()); + + assert_last_event::( + Event::::JudgementRequested { + who: caller, + registrar_index: r - 1, + } + .into(), + ); + + Ok(()) } - cancel_request { + #[benchmark] + fn cancel_request( + r: Linear<1, MAX_REGISTRARS>, + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + ) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let x in 0 .. T::MaxAdditionalFields::get() => { + add_registrars::(r)?; + + { // Create their main identity with x additional fields let info = create_identity_info::(x); let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller)); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller)); Identity::::set_identity(caller_origin, Box::new(info))?; - }; + } Identity::::request_judgement(caller_origin, r - 1, 10u32.into())?; - }: _(RawOrigin::Signed(caller.clone()), r - 1) - verify { - assert_last_event::(Event::::JudgementUnrequested { who: caller, registrar_index: r-1 }.into()); + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone()), r - 1); + + assert_last_event::( + Event::::JudgementUnrequested { + who: caller, + registrar_index: r - 1, + } + .into(), + ); + + Ok(()) } - set_fee { + #[benchmark] + fn set_fee(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> { + let r = r - 1; let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); - let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; + add_registrars::(r)?; let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap(); Identity::::add_registrar(registrar_origin, caller_lookup)?; let registrars = Registrars::::get(); - ensure!(registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), "Fee already set."); - }: _(RawOrigin::Signed(caller), r, 100u32.into()) - verify { + ensure!( + registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), + "Fee already set." + ); + + #[extrinsic_call] + _(RawOrigin::Signed(caller), r, 100u32.into()); + let registrars = Registrars::::get(); - ensure!(registrars[r as usize].as_ref().unwrap().fee == 100u32.into(), "Fee not changed."); + ensure!( + registrars[r as usize].as_ref().unwrap().fee == 100u32.into(), + "Fee not changed." + ); + + Ok(()) } - set_account_id { + #[benchmark] + fn set_account_id(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> { + let r = r - 1; let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; + add_registrars::(r)?; let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap(); Identity::::add_registrar(registrar_origin, caller_lookup)?; let registrars = Registrars::::get(); - ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set."); + ensure!( + registrars[r as usize].as_ref().unwrap().account == caller, + "id not set." + ); let new_account = T::Lookup::unlookup(account("new", 0, SEED)); - }: _(RawOrigin::Signed(caller), r, new_account) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller), r, new_account); + let registrars = Registrars::::get(); - ensure!(registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), "id not changed."); + ensure!( + registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), + "id not changed." + ); + + Ok(()) } - set_fields { + #[benchmark] + fn set_fields(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> { + let r = r - 1; let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; + add_registrars::(r)?; let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap(); Identity::::add_registrar(registrar_origin, caller_lookup)?; let fields = IdentityFields( - IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot - | IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter + IdentityField::Display + | IdentityField::Legal + | IdentityField::Web + | IdentityField::Riot + | IdentityField::Email + | IdentityField::PgpFingerprint + | IdentityField::Image + | IdentityField::Twitter, ); let registrars = Registrars::::get(); - ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set."); - }: _(RawOrigin::Signed(caller), r, fields) - verify { + ensure!( + registrars[r as usize].as_ref().unwrap().fields == Default::default(), + "fields already set." + ); + + #[extrinsic_call] + _(RawOrigin::Signed(caller), r, fields); + let registrars = Registrars::::get(); - ensure!(registrars[r as usize].as_ref().unwrap().fields != Default::default(), "fields not set."); + ensure!( + registrars[r as usize].as_ref().unwrap().fields != Default::default(), + "fields not set." + ); + + Ok(()) } - provide_judgement { + #[benchmark] + fn provide_judgement( + r: Linear<2, MAX_REGISTRARS>, + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + ) -> Result<(), BenchmarkError> { + let r = r - 1; // The user let user: T::AccountId = account("user", r, SEED); - let user_origin = ::RuntimeOrigin::from(RawOrigin::Signed(user.clone())); + let user_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(user.clone())); let user_lookup = ::unlookup(user.clone()); let _ = T::Currency::make_free_balance_be(&user, BalanceOf::::max_value()); @@ -368,8 +503,7 @@ let caller_lookup = T::Lookup::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; - let x in 0 .. T::MaxAdditionalFields::get(); + add_registrars::(r)?; let info = create_identity_info::(x); let info_hash = T::Hashing::hash_of(&info); @@ -378,18 +512,38 @@ let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap(); Identity::::add_registrar(registrar_origin, caller_lookup)?; Identity::::request_judgement(user_origin, r, 10u32.into())?; - }: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable, info_hash) - verify { - assert_last_event::(Event::::JudgementGiven { target: user, registrar_index: r }.into()) + + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + r, + user_lookup, + Judgement::Reasonable, + info_hash, + ); + + assert_last_event::( + Event::::JudgementGiven { + target: user, + registrar_index: r, + } + .into(), + ); + + Ok(()) } - kill_identity { - let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let s in 0 .. T::MaxSubAccounts::get(); - let x in 0 .. T::MaxAdditionalFields::get(); + #[benchmark] + fn kill_identity( + r: Linear<1, MAX_REGISTRARS>, + s: Linear<0, MAX_SUB_ACCOUNTS>, + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + ) -> Result<(), BenchmarkError> { + add_registrars::(r)?; let target: T::AccountId = account("target", 0, SEED); - let target_origin: ::RuntimeOrigin = RawOrigin::Signed(target.clone()).into(); + let target_origin: ::RuntimeOrigin = + RawOrigin::Signed(target.clone()).into(); let target_lookup = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); @@ -400,7 +554,7 @@ // User requests judgement from all the registrars, and they approve for i in 0..r { let registrar: T::AccountId = account("registrar", i, SEED); - let balance_to_use = balance_unit::() * 10u32.into(); + let balance_to_use = balance_unit::() * 10u32.into(); let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use); Identity::::request_judgement(target_origin.clone(), i, 10u32.into())?; @@ -414,110 +568,190 @@ } ensure!(IdentityOf::::contains_key(&target), "Identity not set"); let origin = T::ForceOrigin::try_successful_origin().unwrap(); - }: _(origin, target_lookup) - verify { - ensure!(!IdentityOf::::contains_key(&target), "Identity not removed"); + + #[extrinsic_call] + _(origin as T::RuntimeOrigin, target_lookup); + + ensure!( + !IdentityOf::::contains_key(&target), + "Identity not removed" + ); + + Ok(()) } - force_insert_identities { - let x in 0 .. T::MaxAdditionalFields::get(); - let n in 0..600; + #[benchmark] + fn force_insert_identities( + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + n: Linear<0, 600>, + ) -> Result<(), BenchmarkError> { use frame_benchmarking::account; - let identities = (0..n).map(|i| ( - account("caller", i, SEED), - Registration::, T::MaxRegistrars, T::MaxAdditionalFields> { - judgements: Default::default(), - deposit: Default::default(), - info: create_identity_info::(x), - }, - )).collect::>(); + let identities = (0..n) + .map(|i| { + ( + account("caller", i, SEED), + Registration::, T::MaxRegistrars, T::MaxAdditionalFields> { + judgements: Default::default(), + deposit: Default::default(), + info: create_identity_info::(x), + }, + ) + }) + .collect::>(); let origin = T::ForceOrigin::try_successful_origin().unwrap(); - }: _(origin, identities) - force_remove_identities { - let x in 0 .. T::MaxAdditionalFields::get(); - let n in 0..600; + #[extrinsic_call] + _(origin as T::RuntimeOrigin, identities); + + Ok(()) + } + + #[benchmark] + fn force_remove_identities( + x: Linear<0, MAX_ADDITIONAL_FIELDS>, + n: Linear<0, 600>, + ) -> Result<(), BenchmarkError> { use frame_benchmarking::account; let origin = T::ForceOrigin::try_successful_origin().unwrap(); - let identities = (0..n).map(|i| ( - account("caller", i, SEED), - Registration::, T::MaxRegistrars, T::MaxAdditionalFields> { - judgements: Default::default(), - deposit: Default::default(), - info: create_identity_info::(x), - }, - )).collect::>(); - assert_ok!( - Identity::::force_insert_identities(origin.clone(), identities.clone()), - ); - let identities = identities.into_iter().map(|(acc, _)| acc).collect::>(); - }: _(origin, identities) + let identities = (0..n) + .map(|i| { + ( + account("caller", i, SEED), + Registration::, T::MaxRegistrars, T::MaxAdditionalFields> { + judgements: Default::default(), + deposit: Default::default(), + info: create_identity_info::(x), + }, + ) + }) + .collect::>(); + assert_ok!(Identity::::force_insert_identities( + origin.clone(), + identities.clone() + ),); + let identities = identities + .into_iter() + .map(|(acc, _)| acc) + .collect::>(); - force_set_subs { - let s in 0 .. T::MaxSubAccounts::get(); - let n in 0..600; + #[extrinsic_call] + _(origin as T::RuntimeOrigin, identities); + + Ok(()) + } + + #[benchmark] + fn force_set_subs( + s: Linear<0, MAX_SUB_ACCOUNTS>, + n: Linear<0, 600>, + ) -> Result<(), BenchmarkError> { use frame_benchmarking::account; - let identities = (0..n).map(|i| { - let caller: T::AccountId = account("caller", i, SEED); - ( - caller.clone(), + let identities = (0..n) + .map(|i| { + let caller: T::AccountId = account("caller", i, SEED); ( - BalanceOf::::max_value(), - create_sub_accounts::(&caller, s).unwrap().try_into().unwrap(), - ), - ) - }).collect::>(); + caller.clone(), + ( + BalanceOf::::max_value(), + create_sub_accounts::(&caller, s) + .unwrap() + .try_into() + .unwrap(), + ), + ) + }) + .collect::>(); let origin = T::ForceOrigin::try_successful_origin().unwrap(); - }: _(origin, identities) - add_sub { - let s in 0 .. T::MaxSubAccounts::get() - 1; + #[extrinsic_call] + _(origin as T::RuntimeOrigin, identities); + Ok(()) + } + + #[benchmark] + fn add_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> { + let s = s - 1; let caller: T::AccountId = whitelisted_caller(); let _ = add_sub_accounts::(&caller, s)?; let sub = account("new_sub", 0, SEED); let data = Data::Raw(vec![0; 32].try_into().unwrap()); - ensure!(SubsOf::::get(&caller).1.len() as u32 == s, "Subs not set."); - }: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(sub), data) - verify { - ensure!(SubsOf::::get(&caller).1.len() as u32 == s + 1, "Subs not added."); - } + ensure!( + SubsOf::::get(&caller).1.len() as u32 == s, + "Subs not set." + ); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + T::Lookup::unlookup(sub), + data, + ); + + ensure!( + SubsOf::::get(&caller).1.len() as u32 == s + 1, + "Subs not added." + ); - rename_sub { - let s in 1 .. T::MaxSubAccounts::get(); + Ok(()) + } + #[benchmark] + fn rename_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let (sub, _) = add_sub_accounts::(&caller, s)?.remove(0); let data = Data::Raw(vec![1; 32].try_into().unwrap()); - ensure!(SuperOf::::get(&sub).unwrap().1 != data, "data already set"); - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone()) - verify { + ensure!( + SuperOf::::get(&sub).unwrap().1 != data, + "data already set" + ); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + T::Lookup::unlookup(sub.clone()), + data.clone(), + ); + ensure!(SuperOf::::get(&sub).unwrap().1 == data, "data not set"); - } - remove_sub { - let s in 1 .. T::MaxSubAccounts::get(); + Ok(()) + } + #[benchmark] + fn remove_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let (sub, _) = add_sub_accounts::(&caller, s)?.remove(0); ensure!(SuperOf::::contains_key(&sub), "Sub doesn't exists"); - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone())) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone())); + ensure!(!SuperOf::::contains_key(&sub), "Sub not removed"); + + Ok(()) } - quit_sub { - let s in 0 .. T::MaxSubAccounts::get() - 1; - + #[benchmark] + fn quit_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> { + let s = s - 1; let caller: T::AccountId = whitelisted_caller(); let sup = account("super", 0, SEED); let _ = add_sub_accounts::(&sup, s)?; let sup_origin = RawOrigin::Signed(sup).into(); - Identity::::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32].try_into().unwrap()))?; + Identity::::add_sub( + sup_origin, + T::Lookup::unlookup(caller.clone()), + Data::Raw(vec![0; 32].try_into().unwrap()), + )?; ensure!(SuperOf::::contains_key(&caller), "Sub doesn't exists"); - }: _(RawOrigin::Signed(caller.clone())) - verify { + + #[extrinsic_call] + _(RawOrigin::Signed(caller.clone())); + ensure!(!SuperOf::::contains_key(&caller), "Sub not removed"); + + Ok(()) } impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test); --- a/pallets/inflation/src/benchmarking.rs +++ b/pallets/inflation/src/benchmarking.rs @@ -16,18 +16,29 @@ #![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::benchmarks; -use frame_support::{pallet_prelude::*, traits::Hooks}; +use frame_benchmarking::v2::*; +use frame_support::traits::Hooks; +use sp_std::vec; use super::*; use crate::Pallet as Inflation; -benchmarks! { +#[benchmarks] +mod benchmarks { + use super::*; - on_initialize { + #[benchmark] + fn on_initialize() -> Result<(), BenchmarkError> { let block1: BlockNumberFor = 1u32.into(); let block2: BlockNumberFor = 2u32.into(); - as Hooks>::on_initialize(block1); // Create Treasury account - }: { as Hooks>::on_initialize(block2); } // Benchmark deposit_into_existing path + as Hooks<_>>::on_initialize(block1); // Create Treasury account + #[block] + { + as Hooks<_>>::on_initialize(block2); + // Benchmark deposit_into_existing path + } + + Ok(()) + } } --- a/pallets/maintenance/src/benchmarking.rs +++ b/pallets/maintenance/src/benchmarking.rs @@ -14,36 +14,37 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -use frame_benchmarking::benchmarks; -use frame_support::{ensure, pallet_prelude::Weight, traits::StorePreimage}; +use frame_benchmarking::v2::*; +use frame_support::ensure; use frame_system::RawOrigin; -use parity_scale_codec::Encode; +use sp_std::vec; use super::*; use crate::{Config, Pallet as Maintenance}; -benchmarks! { - enable { - }: _(RawOrigin::Root) - verify { +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn enable() -> Result<(), BenchmarkError> { + #[extrinsic_call] + _(RawOrigin::Root); + ensure!(>::get(), "didn't enable the MM"); + + Ok(()) } - disable { + #[benchmark] + fn disable() -> Result<(), BenchmarkError> { Maintenance::::enable(RawOrigin::Root.into())?; - }: _(RawOrigin::Root) - verify { + + #[extrinsic_call] + _(RawOrigin::Root); + ensure!(!>::get(), "didn't disable the MM"); - } - #[pov_mode = MaxEncodedLen { - // PoV size is deducted from weight_bound - Preimage::PreimageFor: Measured - }] - execute_preimage { - let call = ::RuntimeCall::from(frame_system::Call::::remark { remark: 1u32.encode() }); - let hash = T::Preimages::note(call.encode().into())?; - }: _(RawOrigin::Root, hash, Weight::from_parts(100000000000, 100000000000)) - verify { + Ok(()) } } --- a/pallets/maintenance/src/lib.rs +++ b/pallets/maintenance/src/lib.rs @@ -32,7 +32,6 @@ traits::{EnsureOrigin, QueryPreimage, StorePreimage}, }; use frame_system::pallet_prelude::*; - use sp_core::H256; use sp_runtime::traits::Dispatchable; use crate::weights::WeightInfo; @@ -102,50 +101,6 @@ Self::deposit_event(Event::MaintenanceDisabled); Ok(()) - } - - /// Execute a runtime call stored as a preimage. - /// - /// `weight_bound` is the maximum weight that the caller is willing - /// to allow the extrinsic to be executed with. - #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::execute_preimage() + *weight_bound)] - pub fn execute_preimage( - origin: OriginFor, - hash: H256, - weight_bound: Weight, - ) -> DispatchResultWithPostInfo { - use parity_scale_codec::Decode; - - T::PreimageOrigin::ensure_origin(origin.clone())?; - - let data = T::Preimages::fetch(&hash, None)?; - weight_bound.set_proof_size( - weight_bound - .proof_size() - .checked_sub( - data.len() - .try_into() - .map_err(|_| DispatchError::Corruption)?, - ) - .ok_or(DispatchError::Exhausted)?, - ); - - let call = ::RuntimeCall::decode(&mut &data[..]) - .map_err(|_| DispatchError::Corruption)?; - - ensure!( - call.get_dispatch_info().weight.all_lte(weight_bound), - DispatchError::Exhausted - ); - - match call.dispatch(origin) { - Ok(_) => Ok(Pays::No.into()), - Err(error_and_info) => Err(DispatchErrorWithPostInfo { - post_info: Pays::No.into(), - error: error_and_info.error, - }), - } } } } --- a/pallets/maintenance/src/weights.rs +++ b/pallets/maintenance/src/weights.rs @@ -35,7 +35,6 @@ pub trait WeightInfo { fn enable() -> Weight; fn disable() -> Weight; - fn execute_preimage() -> Weight; } /// Weights for pallet_maintenance using the Substrate node and recommended hardware. @@ -60,18 +59,6 @@ // Minimum execution time: 2_976_000 picoseconds. Weight::from_parts(3_111_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: Preimage StatusFor (r:1 w:0) - /// Proof: Preimage StatusFor (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) - /// Storage: Preimage PreimageFor (r:1 w:0) - /// Proof: Preimage PreimageFor (max_values: None, max_size: Some(4194344), added: 4196819, mode: Measured) - fn execute_preimage() -> Weight { - // Proof Size summary in bytes: - // Measured: `209` - // Estimated: `3674` - // Minimum execution time: 7_359_000 picoseconds. - Weight::from_parts(7_613_000, 3674) - .saturating_add(T::DbWeight::get().reads(2_u64)) } } @@ -96,18 +83,6 @@ // Minimum execution time: 2_976_000 picoseconds. Weight::from_parts(3_111_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: Preimage StatusFor (r:1 w:0) - /// Proof: Preimage StatusFor (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) - /// Storage: Preimage PreimageFor (r:1 w:0) - /// Proof: Preimage PreimageFor (max_values: None, max_size: Some(4194344), added: 4196819, mode: Measured) - fn execute_preimage() -> Weight { - // Proof Size summary in bytes: - // Measured: `209` - // Estimated: `3674` - // Minimum execution time: 7_359_000 picoseconds. - Weight::from_parts(7_613_000, 3674) - .saturating_add(RocksDbWeight::get().reads(2_u64)) } } --- a/pallets/nonfungible/src/benchmarking.rs +++ b/pallets/nonfungible/src/benchmarking.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::v2::{account, benchmarks, BenchmarkError}; use pallet_common::{ bench_init, - benchmarking::{ - create_collection_raw, load_is_admin_and_property_permissions, property_key, property_value, - }, + benchmarking::{create_collection_raw, property_key, property_value}, CommonCollectionOperations, }; use sp_std::prelude::*; @@ -64,236 +62,433 @@ ) } -benchmarks! { - create_item { - bench_init!{ +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn create_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); to: cross_sub; }; - }: {create_max_item(&collection, &sender, to.clone())?} - create_multiple_items { - let b in 0..MAX_ITEMS_PER_BATCH; - bench_init!{ + #[block] + { + create_max_item(&collection, &sender, to)?; + } + + Ok(()) + } + + #[benchmark] + fn create_multiple_items(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); to: cross_sub; }; - let data = (0..b).map(|_| create_max_item_data::(to.clone())).collect(); - }: {>::create_multiple_items(&collection, &sender, data, &Unlimited)?} + let data = (0..b) + .map(|_| create_max_item_data::(to.clone())) + .collect(); - create_multiple_items_ex { - let b in 0..MAX_ITEMS_PER_BATCH; - bench_init!{ + #[block] + { + >::create_multiple_items(&collection, &sender, data, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn create_multiple_items_ex(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); }; - let data = (0..b).map(|i| { - bench_init!(to: cross_sub(i);); - create_max_item_data::(to) - }).collect(); - }: {>::create_multiple_items(&collection, &sender, data, &Unlimited)?} + let data = (0..b) + .map(|i| { + bench_init!(to: cross_sub(i);); + create_max_item_data::(to) + }) + .collect(); + + #[block] + { + >::create_multiple_items(&collection, &sender, data, &Unlimited)?; + } - burn_item { - bench_init!{ + Ok(()) + } + + #[benchmark] + fn burn_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); burner: cross_sub; }; let item = create_max_item(&collection, &sender, burner.clone())?; - }: {>::burn(&collection, &burner, item)?} - burn_recursively_self_raw { - bench_init!{ + #[block] + { + >::burn(&collection, &burner, item)?; + } + + Ok(()) + } + + #[benchmark] + fn burn_recursively_self_raw() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); burner: cross_sub; }; let item = create_max_item(&collection, &sender, burner.clone())?; - }: {>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?} - burn_recursively_breadth_plus_self_plus_self_per_each_raw { - let b in 0..200; - bench_init!{ + #[block] + { + >::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn burn_recursively_breadth_plus_self_plus_self_per_each_raw( + b: Linear<0, 200>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); burner: cross_sub; }; let item = create_max_item(&collection, &sender, burner.clone())?; - for i in 0..b { - create_max_item(&collection, &sender, T::CrossTokenAddressMapping::token_to_address(collection.id, item))?; + for _ in 0..b { + create_max_item( + &collection, + &sender, + T::CrossTokenAddressMapping::token_to_address(collection.id, item), + )?; } - }: {>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?} - transfer_raw { - bench_init!{ + #[block] + { + >::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn transfer_raw() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; receiver: cross_sub; }; let item = create_max_item(&collection, &owner, sender.clone())?; - }: {>::transfer(&collection, &sender, &receiver, item, &Unlimited)?} - approve { - bench_init!{ + #[block] + { + >::transfer(&collection, &sender, &receiver, item, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn approve() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; let item = create_max_item(&collection, &owner, sender.clone())?; - }: {>::set_allowance(&collection, &sender, item, Some(&spender))?} - approve_from { - bench_init!{ + #[block] + { + >::set_allowance(&collection, &sender, item, Some(&spender))?; + } + + Ok(()) + } + + #[benchmark] + fn approve_from() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth()); let item = create_max_item(&collection, &owner, owner_eth.clone())?; - }: {>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?} - check_allowed_raw { - bench_init!{ + #[block] + { + >::set_allowance_from( + &collection, + &sender, + &owner_eth, + item, + Some(&spender), + )?; + } + + Ok(()) + } + + #[benchmark] + fn check_allowed_raw() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); - owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub; + owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; let item = create_max_item(&collection, &owner, sender.clone())?; >::set_allowance(&collection, &sender, item, Some(&spender))?; - }: {>::check_allowed(&collection, &spender, &sender, item, &Unlimited)?} - burn_from { - bench_init!{ + #[block] + { + >::check_allowed(&collection, &spender, &sender, item, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn burn_from() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; burner: cross_sub; }; let item = create_max_item(&collection, &owner, sender.clone())?; >::set_allowance(&collection, &sender, item, Some(&burner))?; - }: {>::burn_from(&collection, &burner, &sender, item, &Unlimited)?} - set_token_property_permissions { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[block] + { + >::burn_from(&collection, &burner, &sender, item, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn set_token_property_permissions( + b: Linear<0, MAX_PROPERTIES_PER_ITEM>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: false, - collection_admin: false, - token_owner: false, - }, - }).collect::>(); - }: {>::set_token_property_permissions(&collection, &owner, perms)?} + let perms = (0..b) + .map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: false, + collection_admin: false, + token_owner: false, + }, + }) + .collect::>(); + + #[block] + { + >::set_token_property_permissions(&collection, &owner, perms)?; + } + + Ok(()) + } - set_token_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[benchmark] + fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: false, - collection_admin: true, - token_owner: true, - }, - }).collect::>(); + let perms = (0..b) + .map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: false, + collection_admin: true, + token_owner: true, + }, + }) + .collect::>(); >::set_token_property_permissions(&collection, &owner, perms)?; - let props = (0..b).map(|k| Property { - key: property_key(k as usize), - value: property_value(), - }).collect::>(); + let props = (0..b) + .map(|k| Property { + key: property_key(k as usize), + value: property_value(), + }) + .collect::>(); let item = create_max_item(&collection, &owner, owner.clone())?; - }: {>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?} - init_token_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ - owner: sub; collection: collection(owner); - owner: cross_from_sub; - }; + #[block] + { + >::set_token_properties( + &collection, + &owner, + item, + props.into_iter(), + &Unlimited, + )?; + } + + Ok(()) + } + + // TODO: + #[benchmark] + fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> { + // bench_init! { + // owner: sub; collection: collection(owner); + // owner: cross_from_sub; + // }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: false, - collection_admin: true, - token_owner: true, - }, - }).collect::>(); - >::set_token_property_permissions(&collection, &owner, perms)?; - let props = (0..b).map(|k| Property { - key: property_key(k as usize), - value: property_value(), - }).collect::>(); - let item = create_max_item(&collection, &owner, owner.clone())?; + // let perms = (0..b) + // .map(|k| PropertyKeyPermission { + // key: property_key(k as usize), + // permission: PropertyPermission { + // mutable: false, + // collection_admin: true, + // token_owner: true, + // }, + // }) + // .collect::>(); + // >::set_token_property_permissions(&collection, &owner, perms)?; + #[block] + {} + // let props = (0..b) + // .map(|k| Property { + // key: property_key(k as usize), + // value: property_value(), + // }) + // .collect::>(); + // let item = create_max_item(&collection, &owner, owner.clone())?; - let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner); - }: { - let mut property_writer = pallet_common::collection_info_loaded_property_writer( - &collection, - is_collection_admin, - property_permissions, - ); + // let (is_collection_admin, property_permissions) = + // load_is_admin_and_property_permissions(&collection, &owner); + // #[block] + // { + // let mut property_writer = + // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info); - property_writer.write_token_properties( - true, - item, - props.into_iter(), - crate::erc::ERC721TokenEvent::TokenChanged { - token_id: item.into(), - } - .to_log(T::ContractAddress::get()), - )? + // property_writer.write_token_properties( + // item, + // props.into_iter(), + // crate::erc::ERC721TokenEvent::TokenChanged { + // token_id: item.into(), + // } + // .to_log(T::ContractAddress::get()), + // )?; + // } + + Ok(()) } - delete_token_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[benchmark] + fn delete_token_properties( + b: Linear<0, MAX_PROPERTIES_PER_ITEM>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: true, - collection_admin: true, - token_owner: true, - }, - }).collect::>(); + let perms = (0..b) + .map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: true, + collection_admin: true, + token_owner: true, + }, + }) + .collect::>(); >::set_token_property_permissions(&collection, &owner, perms)?; - let props = (0..b).map(|k| Property { - key: property_key(k as usize), - value: property_value(), - }).collect::>(); + let props = (0..b) + .map(|k| Property { + key: property_key(k as usize), + value: property_value(), + }) + .collect::>(); let item = create_max_item(&collection, &owner, owner.clone())?; - >::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?; + >::set_token_properties( + &collection, + &owner, + item, + props.into_iter(), + &Unlimited, + )?; let to_delete = (0..b).map(|k| property_key(k as usize)).collect::>(); - }: {>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?} - token_owner { - bench_init!{ + #[block] + { + >::delete_token_properties( + &collection, + &owner, + item, + to_delete.into_iter(), + &Unlimited, + )?; + } + + Ok(()) + } + + #[benchmark] + fn token_owner() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; let item = create_max_item(&collection, &owner, owner.clone())?; - }: {collection.token_owner(item).unwrap()} - set_allowance_for_all { - bench_init!{ + #[block] + { + collection.token_owner(item).unwrap(); + } + + Ok(()) + } + + #[benchmark] + fn set_allowance_for_all() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; operator: cross_sub; }; - }: {>::set_allowance_for_all(&collection, &owner, &operator, true)?} - allowance_for_all { - bench_init!{ + #[block] + { + >::set_allowance_for_all(&collection, &owner, &operator, true)?; + } + + Ok(()) + } + + #[benchmark] + fn allowance_for_all() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; operator: cross_sub; }; - }: {>::allowance_for_all(&collection, &owner, &operator)} - repair_item { - bench_init!{ + #[block] + { + >::allowance_for_all(&collection, &owner, &operator); + } + + Ok(()) + } + + #[benchmark] + fn repair_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; let item = create_max_item(&collection, &owner, owner.clone())?; - }: {>::repair_item(&collection, item)?} + + #[block] + { + >::repair_item(&collection, item)?; + } + + Ok(()) + } } --- a/pallets/refungible/src/benchmarking.rs +++ b/pallets/refungible/src/benchmarking.rs @@ -16,11 +16,12 @@ use core::{convert::TryInto, iter::IntoIterator}; -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::v2::*; use pallet_common::{ bench_init, benchmarking::{ - create_collection_raw, load_is_admin_and_property_permissions, property_key, property_value, + create_collection_raw, /*load_is_admin_and_property_permissions,*/ property_key, + property_value, }, }; use sp_std::prelude::*; @@ -68,38 +69,70 @@ ) } -benchmarks! { - create_item { - bench_init!{ +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn create_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); to: cross_sub; }; - }: {create_max_item(&collection, &sender, [(to.clone(), 200)])?} - create_multiple_items { - let b in 0..MAX_ITEMS_PER_BATCH; - bench_init!{ + #[block] + { + create_max_item(&collection, &sender, [(to, 200)])?; + } + + Ok(()) + } + + #[benchmark] + fn create_multiple_items(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); to: cross_sub; }; - let data = (0..b).map(|_| create_max_item_data::([(to.clone(), 200)])).collect(); - }: {>::create_multiple_items(&collection, &sender, data, &Unlimited)?} + let data = (0..b) + .map(|_| create_max_item_data::([(to.clone(), 200)])) + .collect(); + + #[block] + { + >::create_multiple_items(&collection, &sender, data, &Unlimited)?; + } - create_multiple_items_ex_multiple_items { - let b in 0..MAX_ITEMS_PER_BATCH; - bench_init!{ + Ok(()) + } + #[benchmark] + fn create_multiple_items_ex_multiple_items( + b: Linear<0, MAX_ITEMS_PER_BATCH>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); }; - let data = (0..b).map(|t| { - bench_init!(to: cross_sub(t);); - create_max_item_data::([(to, 200)]) - }).collect(); - }: {>::create_multiple_items(&collection, &sender, data, &Unlimited)?} + let data = (0..b) + .map(|t| { + bench_init!(to: cross_sub(t);); + create_max_item_data::([(to, 200)]) + }) + .collect(); + + #[block] + { + >::create_multiple_items(&collection, &sender, data, &Unlimited)?; + } + + Ok(()) + } - create_multiple_items_ex_multiple_owners { - let b in 0..MAX_ITEMS_PER_BATCH; - bench_init!{ + #[benchmark] + fn create_multiple_items_ex_multiple_owners( + b: Linear<0, MAX_ITEMS_PER_BATCH>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); }; @@ -107,258 +140,531 @@ bench_init!(to: cross_sub(u);); (to, 200) }))]; - }: {>::create_multiple_items(&collection, &sender, data, &Unlimited)?} + #[block] + { + >::create_multiple_items(&collection, &sender, data, &Unlimited)?; + } + + Ok(()) + } + // Other user left, token data is kept - burn_item_partial { - bench_init!{ + #[benchmark] + fn burn_item_partial() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub; }; - let item = create_max_item(&collection, &sender, [(burner.clone(), 200), (another_owner, 200)])?; - }: {>::burn(&collection, &burner, item, 200)?} + let item = create_max_item( + &collection, + &sender, + [(burner.clone(), 200), (another_owner, 200)], + )?; + + #[block] + { + >::burn(&collection, &burner, item, 200)?; + } + + Ok(()) + } + // No users remaining, token is destroyed - burn_item_fully { - bench_init!{ + #[benchmark] + fn burn_item_fully() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); - sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub; + sender: cross_from_sub(owner); burner: cross_sub; }; let item = create_max_item(&collection, &sender, [(burner.clone(), 200)])?; - }: {>::burn(&collection, &burner, item, 200)?} - transfer_normal { - bench_init!{ + #[block] + { + >::burn(&collection, &burner, item, 200)?; + } + + Ok(()) + } + + #[benchmark] + fn transfer_normal() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); receiver: cross_sub; }; - let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?; - }: {>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?} + let item = create_max_item( + &collection, + &sender, + [(sender.clone(), 200), (receiver.clone(), 200)], + )?; + + #[block] + { + >::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?; + } + + Ok(()) + } + // Target account is created - transfer_creating { - bench_init!{ + #[benchmark] + fn transfer_creating() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); receiver: cross_sub; }; let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?; - }: {>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?} + + #[block] + { + >::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?; + } + + Ok(()) + } + // Source account is destroyed - transfer_removing { - bench_init!{ + #[benchmark] + fn transfer_removing() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); receiver: cross_sub; }; - let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?; - }: {>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?} + let item = create_max_item( + &collection, + &sender, + [(sender.clone(), 200), (receiver.clone(), 200)], + )?; + + #[block] + { + >::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?; + } + + Ok(()) + } + // Source account destroyed, target created - transfer_creating_removing { - bench_init!{ + #[benchmark] + fn transfer_creating_removing() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); receiver: cross_sub; }; let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?; - }: {>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?} - approve { - bench_init!{ + #[block] + { + >::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn approve() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?; - }: {>::set_allowance(&collection, &sender, &spender, item, 100)?} - approve_from { - bench_init!{ + #[block] + { + >::set_allowance(&collection, &sender, &spender, item, 100)?; + } + + Ok(()) + } + + #[benchmark] + fn approve_from() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; }; let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth()); let item = create_max_item(&collection, &owner, [(owner_eth.clone(), 200)])?; - }: {>::set_allowance_from(&collection, &sender, &owner_eth, &spender, item, 100)?} - transfer_from_normal { - bench_init!{ + #[block] + { + >::set_allowance_from(&collection, &sender, &owner_eth, &spender, item, 100)?; + } + + Ok(()) + } + + #[benchmark] + fn transfer_from_normal() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub; }; - let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?; + let item = create_max_item( + &collection, + &owner, + [(sender.clone(), 200), (receiver.clone(), 200)], + )?; >::set_allowance(&collection, &sender, &spender, item, 100)?; - }: {>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?} + + #[block] + { + >::transfer_from( + &collection, + &spender, + &sender, + &receiver, + item, + 100, + &Unlimited, + )?; + } + + Ok(()) + } + // Target account is created - transfer_from_creating { - bench_init!{ + #[benchmark] + fn transfer_from_creating() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub; }; let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?; >::set_allowance(&collection, &sender, &spender, item, 100)?; - }: {>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?} + + #[block] + { + >::transfer_from( + &collection, + &spender, + &sender, + &receiver, + item, + 100, + &Unlimited, + )?; + } + + Ok(()) + } + // Source account is destroyed - transfer_from_removing { - bench_init!{ + #[benchmark] + fn transfer_from_removing() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub; }; - let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?; + let item = create_max_item( + &collection, + &owner, + [(sender.clone(), 200), (receiver.clone(), 200)], + )?; >::set_allowance(&collection, &sender, &spender, item, 200)?; - }: {>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?} + + #[block] + { + >::transfer_from( + &collection, + &spender, + &sender, + &receiver, + item, + 200, + &Unlimited, + )?; + } + + Ok(()) + } + // Source account destroyed, target created - transfer_from_creating_removing { - bench_init!{ + #[benchmark] + fn transfer_from_creating_removing() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub; }; let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?; >::set_allowance(&collection, &sender, &spender, item, 200)?; - }: {>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?} + #[block] + { + >::transfer_from( + &collection, + &spender, + &sender, + &receiver, + item, + 200, + &Unlimited, + )?; + } + + Ok(()) + } + // Both source account and token is destroyed - burn_from { - bench_init!{ + #[benchmark] + fn burn_from() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; sender: cross_sub; burner: cross_sub; }; let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?; >::set_allowance(&collection, &sender, &burner, item, 200)?; - }: {>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?} - set_token_property_permissions { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[block] + { + >::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?; + } + + Ok(()) + } + + #[benchmark] + fn set_token_property_permissions( + b: Linear<0, MAX_PROPERTIES_PER_ITEM>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: false, - collection_admin: false, - token_owner: false, - }, - }).collect::>(); - }: {>::set_token_property_permissions(&collection, &owner, perms)?} + let perms = (0..b) + .map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: false, + collection_admin: false, + token_owner: false, + }, + }) + .collect::>(); + + #[block] + { + >::set_token_property_permissions(&collection, &owner, perms)?; + } + + Ok(()) + } - set_token_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[benchmark] + fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: false, - collection_admin: true, - token_owner: true, - }, - }).collect::>(); + let perms = (0..b) + .map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: false, + collection_admin: true, + token_owner: true, + }, + }) + .collect::>(); >::set_token_property_permissions(&collection, &owner, perms)?; - let props = (0..b).map(|k| Property { - key: property_key(k as usize), - value: property_value(), - }).collect::>(); + let props = (0..b) + .map(|k| Property { + key: property_key(k as usize), + value: property_value(), + }) + .collect::>(); let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?; - }: {>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?} - init_token_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ - owner: sub; collection: collection(owner); - owner: cross_from_sub; - }; + #[block] + { + >::set_token_properties( + &collection, + &owner, + item, + props.into_iter(), + &Unlimited, + )?; + } - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: false, - collection_admin: true, - token_owner: true, - }, - }).collect::>(); - >::set_token_property_permissions(&collection, &owner, perms)?; - let props = (0..b).map(|k| Property { - key: property_key(k as usize), - value: property_value(), - }).collect::>(); - let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?; + Ok(()) + } - let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner); - }: { - let mut property_writer = pallet_common::collection_info_loaded_property_writer( - &collection, - is_collection_admin, - property_permissions, - ); + // TODO: + #[benchmark] + fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> { + // bench_init! { + // owner: sub; collection: collection(owner); + // owner: cross_from_sub; + // }; - property_writer.write_token_properties( - true, - item, - props.into_iter(), - crate::erc::ERC721TokenEvent::TokenChanged { - token_id: item.into(), - } - .to_log(T::ContractAddress::get()), - )? + // let perms = (0..b) + // .map(|k| PropertyKeyPermission { + // key: property_key(k as usize), + // permission: PropertyPermission { + // mutable: false, + // collection_admin: true, + // token_owner: true, + // }, + // }) + // .collect::>(); + // >::set_token_property_permissions(&collection, &owner, perms)?; + + #[block] + {} + // let props = (0..b).map(|k| Property { + // key: property_key(k as usize), + // value: property_value(), + // }).collect::>(); + // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?; + + // let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner) + // let mut property_writer = pallet_common::collection_info_loaded_property_writer( + // &collection, + // is_collection_admin, + // property_permissions, + // ); + + // #[block] + // { + // property_writer.write_token_properties( + // true, + // item, + // props.into_iter(), + // crate::erc::ERC721TokenEvent::TokenChanged { + // token_id: item.into(), + // } + // .to_log(T::ContractAddress::get()), + // )?; + // } + + Ok(()) } - delete_token_properties { - let b in 0..MAX_PROPERTIES_PER_ITEM; - bench_init!{ + #[benchmark] + fn delete_token_properties( + b: Linear<0, MAX_PROPERTIES_PER_ITEM>, + ) -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; - let perms = (0..b).map(|k| PropertyKeyPermission { - key: property_key(k as usize), - permission: PropertyPermission { - mutable: true, - collection_admin: true, - token_owner: true, - }, - }).collect::>(); + let perms = (0..b) + .map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: true, + collection_admin: true, + token_owner: true, + }, + }) + .collect::>(); >::set_token_property_permissions(&collection, &owner, perms)?; - let props = (0..b).map(|k| Property { - key: property_key(k as usize), - value: property_value(), - }).collect::>(); + let props = (0..b) + .map(|k| Property { + key: property_key(k as usize), + value: property_value(), + }) + .collect::>(); let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?; - >::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?; + >::set_token_properties( + &collection, + &owner, + item, + props.into_iter(), + &Unlimited, + )?; let to_delete = (0..b).map(|k| property_key(k as usize)).collect::>(); - }: {>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?} - repartition_item { - bench_init!{ + #[block] + { + >::delete_token_properties( + &collection, + &owner, + item, + to_delete.into_iter(), + &Unlimited, + )?; + } + + Ok(()) + } + + #[benchmark] + fn repartition_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); owner: cross_sub; }; let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?; - }: {>::repartition(&collection, &owner, item, 200)?} - token_owner { - bench_init!{ + #[block] + { + >::repartition(&collection, &owner, item, 200)?; + } + + Ok(()) + } + + #[benchmark] + fn token_owner() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); sender: cross_from_sub(owner); owner: cross_sub; }; let item = create_max_item(&collection, &sender, [(owner, 100)])?; - }: {>::token_owner(collection.id, item).unwrap()} - set_allowance_for_all { - bench_init!{ + #[block] + { + >::token_owner(collection.id, item).unwrap(); + } + + Ok(()) + } + + #[benchmark] + fn set_allowance_for_all() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; operator: cross_sub; }; - }: {>::set_allowance_for_all(&collection, &owner, &operator, true)?} - allowance_for_all { - bench_init!{ + #[block] + { + >::set_allowance_for_all(&collection, &owner, &operator, true)?; + } + + Ok(()) + } + + #[benchmark] + fn allowance_for_all() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; operator: cross_sub; }; - }: {>::allowance_for_all(&collection, &owner, &operator)} - repair_item { - bench_init!{ + #[block] + { + >::allowance_for_all(&collection, &owner, &operator); + } + + Ok(()) + } + + #[benchmark] + fn repair_item() -> Result<(), BenchmarkError> { + bench_init! { owner: sub; collection: collection(owner); owner: cross_from_sub; }; let item = create_max_item(&collection, &owner, [(owner.clone(), 100)])?; - }: {>::repair_item(&collection, item)?} + + #[block] + { + >::repair_item(&collection, item)?; + } + + Ok(()) + } } --- a/pallets/structure/src/benchmarking.rs +++ b/pallets/structure/src/benchmarking.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::v2::{account, benchmarks, BenchmarkError}; use frame_support::traits::{fungible::Balanced, tokens::Precision, Get}; use pallet_common::Config as CommonConfig; use pallet_evm::account::CrossAccountId; +use sp_std::vec; use up_data_structs::{ budget::Unlimited, CollectionMode, CreateCollectionData, CreateItemData, CreateNftData, }; @@ -26,12 +27,21 @@ const SEED: u32 = 1; -benchmarks! { - find_parent { +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn find_parent() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let caller_cross = T::CrossAccountId::from_sub(caller.clone()); - let _ = ::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap(); + let _ = ::Currency::deposit( + &caller, + T::CollectionCreationPrice::get(), + Precision::Exact, + ) + .unwrap(); T::CollectionDispatch::create( caller_cross.clone(), caller_cross.clone(), @@ -43,9 +53,19 @@ let dispatch = T::CollectionDispatch::dispatch(CollectionId(1))?; let dispatch = dispatch.as_dyn(); - dispatch.create_item(caller_cross.clone(), caller_cross, CreateItemData::NFT(CreateNftData::default()), &Unlimited)?; - }: { - let parent = >::find_parent(CollectionId(1), TokenId(1))?; - assert!(matches!(parent, Parent::User(_))) + dispatch.create_item( + caller_cross.clone(), + caller_cross, + CreateItemData::NFT(CreateNftData::default()), + &Unlimited, + )?; + + #[block] + { + let parent = >::find_parent(CollectionId(1), TokenId(1))?; + assert!(matches!(parent, Parent::User(_))); + } + + Ok(()) } } --- a/pallets/unique/src/benchmarking.rs +++ b/pallets/unique/src/benchmarking.rs @@ -16,7 +16,7 @@ #![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::v2::{account, benchmarks, BenchmarkError}; use frame_support::traits::{fungible::Balanced, tokens::Precision, Get}; use frame_system::RawOrigin; use pallet_common::{ @@ -25,6 +25,7 @@ Config as CommonConfig, }; use sp_runtime::DispatchError; +use sp_std::vec; use up_data_structs::{ CollectionId, CollectionLimits, CollectionMode, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH, @@ -63,81 +64,197 @@ create_collection_helper::(owner, CollectionMode::NFT) } -benchmarks! { - create_collection { - let col_name = create_u16_data::<{MAX_COLLECTION_NAME_LENGTH}>(); - let col_desc = create_u16_data::<{MAX_COLLECTION_DESCRIPTION_LENGTH}>(); - let token_prefix = create_data::<{MAX_TOKEN_PREFIX_LENGTH}>(); +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn create_collection() -> Result<(), BenchmarkError> { + let col_name = create_u16_data::<{ MAX_COLLECTION_NAME_LENGTH }>(); + let col_desc = create_u16_data::<{ MAX_COLLECTION_DESCRIPTION_LENGTH }>(); + let token_prefix = create_data::<{ MAX_TOKEN_PREFIX_LENGTH }>(); let mode: CollectionMode = CollectionMode::NFT; let caller: T::AccountId = account("caller", 0, SEED); - let _ = ::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap(); - }: _(RawOrigin::Signed(caller.clone()), col_name, col_desc, token_prefix, mode) - verify { - assert_eq!(>::get(CollectionId(1)).unwrap().owner, caller); + let _ = ::Currency::deposit( + &caller, + T::CollectionCreationPrice::get(), + Precision::Exact, + ) + .unwrap(); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + col_name, + col_desc, + token_prefix, + mode, + ); + + assert_eq!( + >::get(CollectionId(1)) + .unwrap() + .owner, + caller + ); + + Ok(()) } - destroy_collection { + #[benchmark] + fn destroy_collection() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - }: _(RawOrigin::Signed(caller.clone()), collection) - add_to_allow_list { + #[extrinsic_call] + _(RawOrigin::Signed(caller), collection); + + Ok(()) + } + + #[benchmark] + fn add_to_allow_list() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let allowlist_account: T::AccountId = account("admin", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account)) - remove_from_allow_list { + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + collection, + T::CrossAccountId::from_sub(allowlist_account), + ); + + Ok(()) + } + + #[benchmark] + fn remove_from_allow_list() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let allowlist_account: T::AccountId = account("admin", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - >::add_to_allow_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(allowlist_account.clone()))?; - }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account)) + >::add_to_allow_list( + RawOrigin::Signed(caller.clone()).into(), + collection, + T::CrossAccountId::from_sub(allowlist_account.clone()), + )?; - change_collection_owner { + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + collection, + T::CrossAccountId::from_sub(allowlist_account), + ); + + Ok(()) + } + + #[benchmark] + fn change_collection_owner() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; let new_owner: T::AccountId = account("admin", 0, SEED); - }: _(RawOrigin::Signed(caller.clone()), collection, new_owner) - add_collection_admin { + #[extrinsic_call] + _(RawOrigin::Signed(caller), collection, new_owner); + + Ok(()) + } + + #[benchmark] + fn add_collection_admin() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; let new_admin: T::AccountId = account("admin", 0, SEED); - }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(new_admin)) - remove_collection_admin { + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + collection, + T::CrossAccountId::from_sub(new_admin), + ); + + Ok(()) + } + + #[benchmark] + fn remove_collection_admin() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; let new_admin: T::AccountId = account("admin", 0, SEED); - >::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(new_admin.clone()))?; - }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(new_admin)) + >::add_collection_admin( + RawOrigin::Signed(caller.clone()).into(), + collection, + T::CrossAccountId::from_sub(new_admin.clone()), + )?; - set_collection_sponsor { + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + collection, + T::CrossAccountId::from_sub(new_admin), + ); + + Ok(()) + } + + #[benchmark] + fn set_collection_sponsor() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - }: _(RawOrigin::Signed(caller.clone()), collection, caller.clone()) - confirm_sponsorship { + #[extrinsic_call] + _(RawOrigin::Signed(caller), collection, caller.clone()); + + Ok(()) + } + + #[benchmark] + fn confirm_sponsorship() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - >::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), collection, caller.clone())?; - }: _(RawOrigin::Signed(caller.clone()), collection) + >::set_collection_sponsor( + RawOrigin::Signed(caller.clone()).into(), + collection, + caller.clone(), + )?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller), collection); + + Ok(()) + } - remove_collection_sponsor { + #[benchmark] + fn remove_collection_sponsor() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - >::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), collection, caller.clone())?; + >::set_collection_sponsor( + RawOrigin::Signed(caller.clone()).into(), + collection, + caller.clone(), + )?; >::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), collection)?; - }: _(RawOrigin::Signed(caller.clone()), collection) - set_transfers_enabled_flag { + #[extrinsic_call] + _(RawOrigin::Signed(caller), collection); + + Ok(()) + } + + #[benchmark] + fn set_transfers_enabled_flag() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; - }: _(RawOrigin::Signed(caller.clone()), collection, false) + #[extrinsic_call] + _(RawOrigin::Signed(caller), collection, false); - set_collection_limits { + Ok(()) + } + + #[benchmark] + fn set_collection_limits() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller.clone())?; @@ -152,10 +269,21 @@ sponsored_data_rate_limit: None, transfers_enabled: Some(true), }; - }: set_collection_limits(RawOrigin::Signed(caller.clone()), collection, cl) - force_repair_collection { + #[extrinsic_call] + set_collection_limits(RawOrigin::Signed(caller), collection, cl); + + Ok(()) + } + + #[benchmark] + fn force_repair_collection() -> Result<(), BenchmarkError> { let caller: T::AccountId = account("caller", 0, SEED); let collection = create_nft_collection::(caller)?; - }: _(RawOrigin::Root, collection) + + #[extrinsic_call] + _(RawOrigin::Root, collection); + + Ok(()) + } } --- a/runtime/common/config/xcm/foreignassets.rs +++ b/runtime/common/config/xcm/foreignassets.rs @@ -77,19 +77,18 @@ let here_id = ConvertAssetId::convert(&AssetId::NativeAssetId(NativeCurrency::Here)).unwrap(); - if asset_id.clone() == parent_id { + if *asset_id == parent_id { return Some(MultiLocation::parent()); } - if asset_id.clone() == here_id { + if *asset_id == here_id { return Some(MultiLocation::new( 1, X1(Parachain(ParachainInfo::get().into())), )); } - let fid = - >::try_as_foreign(asset_id.clone())?; + let fid = >::try_as_foreign(*asset_id)?; XcmForeignAssetIdMapping::::get_multi_location(fid) } } --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -569,7 +569,8 @@ fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; + use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark}; + use sp_storage::TrackedStorageKey; let allowlist: Vec = vec![ // Total Issuance --- a/runtime/opal/Cargo.toml +++ b/runtime/opal/Cargo.toml @@ -136,6 +136,7 @@ 'sp-runtime/std', 'sp-session/std', 'sp-std/std', + 'sp-storage/std', 'sp-transaction-pool/std', 'sp-version/std', 'staging-xcm-builder/std', @@ -279,6 +280,7 @@ sp-runtime = { workspace = true } sp-session = { workspace = true } sp-std = { workspace = true } +sp-storage = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } staging-xcm = { workspace = true } --- a/runtime/quartz/Cargo.toml +++ b/runtime/quartz/Cargo.toml @@ -271,6 +271,7 @@ sp-runtime = { workspace = true } sp-session = { workspace = true } sp-std = { workspace = true } +sp-storage = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } staging-xcm = { workspace = true } --- a/runtime/unique/Cargo.toml +++ b/runtime/unique/Cargo.toml @@ -274,6 +274,7 @@ sp-runtime = { workspace = true } sp-session = { workspace = true } sp-std = { workspace = true } +sp-storage = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } staging-xcm = { workspace = true } --- a/tests/src/maintenance.seqtest.ts +++ b/tests/src/maintenance.seqtest.ts @@ -283,87 +283,6 @@ }); }); - describe('Preimage Execution', () => { - const preimageHashes: string[] = []; - - before(async function() { - await usingPlaygrounds(async (helper) => { - requirePalletsOrSkip(this, helper, [Pallets.Preimage, Pallets.Maintenance]); - - // create a preimage to be operated with in the tests - const randomAccounts = await helper.arrange.createCrowd(10, 0n, superuser); - const randomIdentities = randomAccounts.map((acc, i) => [ - acc.address, { - deposit: 0n, - judgements: [], - info: { - display: { - raw: `Random Account #${i}`, - }, - }, - }, - ]); - const preimage = helper.constructApiCall('api.tx.identity.forceInsertIdentities', [randomIdentities]).method.toHex(); - preimageHashes.push(await helper.preimage.notePreimage(bob, preimage, true)); - }); - }); - - itSub('Successfully executes call in a preimage', async ({helper}) => { - const result = await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [ - preimageHashes[0], {refTime: 10000000000, proofSize: 10000}, - ])).to.be.fulfilled; - - // preimage is executed, and an appropriate event is present - const events = result.result.events.filter((x: any) => x.event.method === 'IdentitiesInserted' && x.event.section === 'identity'); - expect(events.length).to.be.equal(1); - - // the preimage goes back to being unrequested - expect(await helper.preimage.getPreimageInfo(preimageHashes[0])).to.have.property('unrequested'); - }); - - itSub('Does not allow execution of a preimage that would fail', async ({helper}) => { - const [zeroAccount] = await helper.arrange.createAccounts([0n], superuser); - - const preimage = helper.constructApiCall('api.tx.balances.forceTransfer', [ - {Id: zeroAccount.address}, {Id: superuser.address}, 1000n, - ]).method.toHex(); - const preimageHash = await helper.preimage.notePreimage(bob, preimage, true); - preimageHashes.push(preimageHash); - - await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [ - preimageHash, {refTime: 10000000000, proofSize: 10000}, - ])).to.be.rejectedWith(/^Token: FundsUnavailable$/); - }); - - itSub('Does not allow preimage execution with non-root', async ({helper}) => { - await expect(helper.executeExtrinsic(bob, 'api.tx.maintenance.executePreimage', [ - preimageHashes[0], {refTime: 10000000000, proofSize: 10000}, - ])).to.be.rejectedWith(/^Misc: BadOrigin$/); - }); - - itSub('Does not allow execution of non-existent preimages', async ({helper}) => { - await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [ - '0x1010101010101010101010101010101010101010101010101010101010101010', {refTime: 10000000000, proofSize: 10000}, - ])).to.be.rejectedWith(/^Misc: Unavailable$/); - }); - - itSub('Does not allow preimage execution with less than minimum weights', async ({helper}) => { - await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [ - preimageHashes[0], {refTime: 1000, proofSize: 100}, - ])).to.be.rejectedWith(/^Misc: Exhausted$/); - }); - - after(async function() { - await usingPlaygrounds(async (helper) => { - if(helper.fetchMissingPalletNames([Pallets.Preimage, Pallets.Maintenance]).length != 0) return; - - for(const hash of preimageHashes) { - await helper.preimage.unnotePreimage(bob, hash); - } - }); - }); - }); - describe('Integration Test: Maintenance mode & App Promo', () => { let superuser: IKeyringPair; -- gitstuff