difftreelog
Merge pull request #1008 from UniqueNetwork/fix/update-benchmarks-to-v2
in: master
Update benchmarks to v2
31 files changed
Cargo.lockdiffbeforeafterboth--- 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",
Cargo.tomldiffbeforeafterboth--- 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" }
Makefilediffbeforeafterboth--- 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
node/cli/src/chain_spec.rsdiffbeforeafterboth--- 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
node/cli/src/command.rsdiffbeforeafterboth--- 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::<Block, DefaultRuntimeExecutor>(config))
+ runner.sync_run(|config| cmd.run::<Block, SubstrateHostFunctions>(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::<opal_runtime::Runtime, _, _>,
+ )?;
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::<opal_runtime::Runtime, _, _>,
+ )?;
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;
node/cli/src/rpc.rsdiffbeforeafterboth--- 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<C, P, SC, R, A, B>(
+pub fn create_full<C, P, SC, R, B>(
io: &mut RpcModule<()>,
deps: FullDeps<C, P, SC>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
@@ -244,7 +244,7 @@
EthFilter::new(
client.clone(),
eth_backend,
- graph.clone(),
+ graph,
filter_pool,
500_usize, // max stored filters
max_past_logs,
node/cli/src/service.rsdiffbeforeafterboth--- 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<ExecutorDispatch, RuntimeApi, Runtime>(
- client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
+pub struct StartConsensusParameters<'a> {
backend: Arc<FullBackend>,
- prometheus_registry: Option<&Registry>,
+ prometheus_registry: Option<&'a Registry>,
telemetry: Option<TelemetryHandle>,
- task_manager: &TaskManager,
+ task_manager: &'a TaskManager,
relay_chain_interface: Arc<dyn RelayChainInterface>,
- transaction_pool: Arc<
- sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
- >,
sync_oracle: Arc<SyncingService<Block>>,
keystore: KeystorePtr,
overseer_handle: OverseerHandle,
@@ -704,6 +685,14 @@
para_id: ParaId,
collator_key: CollatorPair,
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
+}
+
+pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(
+ client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
+ transaction_pool: Arc<
+ sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
+ >,
+ parameters: StartConsensusParameters<'_>,
) -> Result<(), sc_service::Error>
where
ExecutorDispatch: NativeExecutionDispatch + 'static,
@@ -714,6 +703,20 @@
RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + '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,
pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- 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<T>: From<u32> + Into<u32>,
BalanceOf<T>: Sum + From<u128>
- }
+)]
+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::<T>()?;
(0..b).try_for_each(|index| {
let staker = account::<T::AccountId>("staker", index, SEED);
- <T as Config>::Currency::write_balance(&staker, Into::<BalanceOf<T>>::into(10_000u128) * T::Nominal::get())?;
- PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())?;
+ <T as Config>::Currency::write_balance(
+ &staker,
+ Into::<BalanceOf<T>>::into(10_000u128) * T::Nominal::get(),
+ )?;
+ PromototionPallet::<T>::stake(
+ RawOrigin::Signed(staker.clone()).into(),
+ Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get(),
+ )?;
PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker).into())?;
Result::<(), sp_runtime::DispatchError>::Ok(())
})?;
- let block_number = <frame_system::Pallet<T>>::current_block_number() + T::PendingInterval::get();
- }: {PromototionPallet::<T>::on_initialize(block_number)}
+ let block_number =
+ <frame_system::Pallet<T>>::current_block_number() + T::PendingInterval::get();
+
+ #[block]
+ {
+ PromototionPallet::<T>::on_initialize(block_number);
+ }
+
+ Ok(())
+ }
- set_admin_address {
+ #[benchmark]
+ fn set_admin_address() -> Result<(), BenchmarkError> {
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
- let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- } : _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin))
+ let _ = <T as Config>::Currency::set_balance(
+ &pallet_admin,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::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::<T::AccountId>("admin", 1, SEED);
- let share = Perbill::from_rational(1u32, 20);
- PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- <T as Config>::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value())?;
- <T as Config>::Currency::write_balance(&<T as pallet::Config>::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value())?;
+ PromototionPallet::<T>::set_admin_address(
+ RawOrigin::Root.into(),
+ T::CrossAccountId::from_sub(pallet_admin.clone()),
+ )?;
+ <T as Config>::Currency::write_balance(
+ &pallet_admin,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ )?;
+ <T as Config>::Currency::write_balance(
+ &<T as pallet::Config>::TreasuryAccountId::get(),
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ )?;
- let stakers: Vec<T::AccountId> = (0..b).map(|index| account("staker", index, SEED)).collect();
+ let stakers: Vec<T::AccountId> =
+ (0..b).map(|index| account("staker", index, SEED)).collect();
stakers.iter().try_for_each(|staker| {
- <T as Config>::Currency::write_balance(staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value())?;
+ <T as Config>::Currency::write_balance(
+ staker,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ )?;
Result::<(), sp_runtime::DispatchError>::Ok(())
})?;
(1..11).try_for_each(|i| {
<frame_system::Pallet<T>>::set_block_number(i.into());
- T::RelayBlockNumberProvider::set_block_number((2*i).into());
+ T::RelayBlockNumberProvider::set_block_number((2 * i).into());
assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
- assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());
- stakers.iter()
- .map(|staker| {
- PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())
- }).collect::<Result<Vec<_>, _>>()?;
+ assert_eq!(
+ T::RelayBlockNumberProvider::current_block_number(),
+ (2 * i).into()
+ );
+ stakers
+ .iter()
+ .map(|staker| {
+ PromototionPallet::<T>::stake(
+ RawOrigin::Signed(staker.clone()).into(),
+ Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get(),
+ )
+ })
+ .collect::<Result<Vec<_>, _>>()?;
Result::<(), sp_runtime::DispatchError>::Ok(())
})?;
@@ -107,83 +159,195 @@
<frame_system::Pallet<T>>::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::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 10);
- let _ = <T as Config>::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- } : _(RawOrigin::Signed(caller.clone()), share * <T as Config>::Currency::total_balance(&caller))
- unstake_all {
+ let _ = <T as Config>::Currency::write_balance(
+ &caller,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller),
+ share * <T as Config>::Currency::total_balance(&caller),
+ );
+
+ Ok(())
+ }
+
+ #[benchmark]
+ fn unstake_all() -> Result<(), BenchmarkError> {
let caller = account::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 20);
- let _ = <T as Config>::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- (1..11).map(|i| {
- // used to change block number
- <frame_system::Pallet<T>>::set_block_number(i.into());
- T::RelayBlockNumberProvider::set_block_number((2*i).into());
- assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
- assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());
- PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))
- }).collect::<Result<Vec<_>, _>>()?;
+ let _ = <T as Config>::Currency::write_balance(
+ &caller,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
+ (1..11)
+ .map(|i| {
+ // used to change block number
+ <frame_system::Pallet<T>>::set_block_number(i.into());
+ T::RelayBlockNumberProvider::set_block_number((2 * i).into());
+ assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
+ assert_eq!(
+ T::RelayBlockNumberProvider::current_block_number(),
+ (2 * i).into()
+ );
+ PromototionPallet::<T>::stake(
+ RawOrigin::Signed(caller.clone()).into(),
+ share * <T as Config>::Currency::total_balance(&caller),
+ )
+ })
+ .collect::<Result<Vec<_>, _>>()?;
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller));
- } : _(RawOrigin::Signed(caller.clone()))
+ Ok(())
+ }
- unstake_partial {
+ #[benchmark]
+ fn unstake_partial() -> Result<(), BenchmarkError> {
let caller = account::<T::AccountId>("caller", 0, SEED);
- let share = Perbill::from_rational(1u32, 20);
- let _ = <T as Config>::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- (1..11).map(|i| {
- // used to change block number
- <frame_system::Pallet<T>>::set_block_number(i.into());
- T::RelayBlockNumberProvider::set_block_number((2*i).into());
- assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
- assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());
- PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())
- }).collect::<Result<Vec<_>, _>>()?;
+ let _ = <T as Config>::Currency::write_balance(
+ &caller,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
+ (1..11)
+ .map(|i| {
+ // used to change block number
+ <frame_system::Pallet<T>>::set_block_number(i.into());
+ T::RelayBlockNumberProvider::set_block_number((2 * i).into());
+ assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
+ assert_eq!(
+ T::RelayBlockNumberProvider::current_block_number(),
+ (2 * i).into()
+ );
+ PromototionPallet::<T>::stake(
+ RawOrigin::Signed(caller.clone()).into(),
+ Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get(),
+ )
+ })
+ .collect::<Result<Vec<_>, _>>()?;
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller),
+ Into::<BalanceOf<T>>::into(1000u128) * T::Nominal::get(),
+ );
- } : _(RawOrigin::Signed(caller.clone()), Into::<BalanceOf<T>>::into(1000u128) * T::Nominal::get())
+ Ok(())
+ }
- sponsor_collection {
+ #[benchmark]
+ fn sponsor_collection() -> Result<(), BenchmarkError> {
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
- PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ PromototionPallet::<T>::set_admin_address(
+ RawOrigin::Root.into(),
+ T::CrossAccountId::from_sub(pallet_admin.clone()),
+ )?;
+ let _ = <T as Config>::Currency::write_balance(
+ &pallet_admin,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
let caller: T::AccountId = account("caller", 0, SEED);
- let _ = <T as Config>::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::write_balance(
+ &caller,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
let collection = create_nft_collection::<T>(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::<T::AccountId>("admin", 0, SEED);
- PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ PromototionPallet::<T>::set_admin_address(
+ RawOrigin::Root.into(),
+ T::CrossAccountId::from_sub(pallet_admin.clone()),
+ )?;
+ let _ = <T as Config>::Currency::write_balance(
+ &pallet_admin,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
let caller: T::AccountId = account("caller", 0, SEED);
- let _ = <T as Config>::Currency::write_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::write_balance(
+ &caller,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
let collection = create_nft_collection::<T>(caller)?;
- PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?;
- } : _(RawOrigin::Signed(pallet_admin.clone()), collection)
+ PromototionPallet::<T>::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::<T::AccountId>("admin", 0, SEED);
- PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
+ PromototionPallet::<T>::set_admin_address(
+ RawOrigin::Root.into(),
+ T::CrossAccountId::from_sub(pallet_admin.clone()),
+ )?;
- let _ = <T as Config>::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::write_balance(
+ &pallet_admin,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
let address = H160::from_low_u64_be(SEED as u64);
let data: Vec<u8> = (0..20).collect();
<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;
<EvmMigrationPallet<T>>::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::<T::AccountId>("admin", 0, SEED);
- PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
+ PromototionPallet::<T>::set_admin_address(
+ RawOrigin::Root.into(),
+ T::CrossAccountId::from_sub(pallet_admin.clone()),
+ )?;
- let _ = <T as Config>::Currency::write_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::write_balance(
+ &pallet_admin,
+ Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
+ );
let address = H160::from_low_u64_be(SEED as u64);
let data: Vec<u8> = (0..20).collect();
<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;
<EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;
- PromototionPallet::<T>::sponsor_contract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?;
- } : _(RawOrigin::Signed(pallet_admin.clone()), address)
+ PromototionPallet::<T>::sponsor_contract(
+ RawOrigin::Signed(pallet_admin.clone()).into(),
+ address,
+ )?;
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(pallet_admin), address);
+
+ Ok(())
+ }
}
pallets/app-promotion/src/weights.rsdiffbeforeafterboth--- 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<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
- /// 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))
}
pallets/collator-selection/Cargo.tomldiffbeforeafterboth--- 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 }
pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth--- 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<T>(b: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ let b = b - 1;
register_validators::<T>(b);
register_invulnerables::<T>(b);
@@ -181,39 +185,59 @@
<session::Pallet<T>>::set_keys(
RawOrigin::Signed(new_invulnerable.clone()).into(),
keys::<T>(b + 1),
- Vec::new()
- ).unwrap();
+ Vec::new(),
+ )
+ .unwrap();
let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();
- }: {
- assert_ok!(
- <CollatorSelection<T>>::add_invulnerable(root_origin, new_invulnerable.clone())
+
+ #[block]
+ {
+ assert_ok!(<CollatorSelection<T>>::add_invulnerable(
+ root_origin,
+ new_invulnerable.clone()
+ ));
+ }
+
+ assert_last_event::<T>(
+ Event::InvulnerableAdded {
+ invulnerable: new_invulnerable,
+ }
+ .into(),
);
- }
- verify {
- assert_last_event::<T>(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::<T>(b);
register_invulnerables::<T>(b);
let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();
let leaving = <Invulnerables<T>>::get().last().unwrap().clone();
whitelist!(leaving);
- }: {
- assert_ok!(
- <CollatorSelection<T>>::remove_invulnerable(root_origin, leaving.clone())
+
+ #[block]
+ {
+ assert_ok!(<CollatorSelection<T>>::remove_invulnerable(
+ root_origin,
+ leaving.clone()
+ ));
+ }
+
+ assert_last_event::<T>(
+ Event::InvulnerableRemoved {
+ invulnerable: leaving,
+ }
+ .into(),
);
- }
- verify {
- assert_last_event::<T>(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::<T>(c);
get_licenses::<T>(c);
@@ -224,19 +248,29 @@
<session::Pallet<T>>::set_keys(
RawOrigin::Signed(caller.clone()).into(),
keys::<T>(c + 1),
- Vec::new()
- ).unwrap();
+ Vec::new(),
+ )
+ .unwrap();
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller.clone()));
+
+ assert_last_event::<T>(
+ Event::LicenseObtained {
+ account_id: caller,
+ deposit: bond / 2u32.into(),
+ }
+ .into(),
+ );
- }: _(RawOrigin::Signed(caller.clone()))
- verify {
- assert_last_event::<T>(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::<T>(c);
register_candidates::<T>(c);
@@ -246,37 +280,44 @@
let origin = RawOrigin::Signed(caller.clone());
- <session::Pallet<T>>::set_keys(
- origin.clone().into(),
- keys::<T>(c + 1),
- Vec::new()
- ).unwrap();
+ <session::Pallet<T>>::set_keys(origin.clone().into(), keys::<T>(c + 1), Vec::new())
+ .unwrap();
+
+ assert_ok!(<CollatorSelection<T>>::get_license(origin.clone().into()));
- assert_ok!(
- <CollatorSelection<T>>::get_license(origin.clone().into())
- );
- }: _(origin)
- verify {
- assert_last_event::<T>(Event::CandidateAdded{account_id: caller}.into());
+ #[extrinsic_call]
+ _(origin);
+
+ assert_last_event::<T>(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::<T>(c);
register_candidates::<T>(c);
let leaving = <Candidates<T>>::get().last().unwrap().clone();
whitelist!(leaving);
- }: _(RawOrigin::Signed(leaving.clone()))
- verify {
- assert_last_event::<T>(Event::CandidateRemoved{account_id: leaving}.into());
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(leaving.clone()));
+
+ assert_last_event::<T>(
+ 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::<T>();
register_validators::<T>(c);
@@ -284,14 +325,24 @@
let leaving = <Candidates<T>>::get().last().unwrap().clone();
whitelist!(leaving);
- }: _(RawOrigin::Signed(leaving.clone()))
- verify {
- assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(leaving.clone()));
+
+ assert_last_event::<T>(
+ 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::<T>();
register_validators::<T>(c);
@@ -300,44 +351,62 @@
let leaving = <Candidates<T>>::get().last().unwrap().clone();
whitelist!(leaving);
let origin = T::UpdateOrigin::try_successful_origin().unwrap();
- }: {
- assert_ok!(
- <CollatorSelection<T>>::force_release_license(origin, leaving.clone())
+
+ #[block]
+ {
+ assert_ok!(<CollatorSelection<T>>::force_release_license(
+ origin,
+ leaving.clone()
+ ));
+ }
+
+ assert_last_event::<T>(
+ Event::LicenseReleased {
+ account_id: leaving,
+ deposit_returned: bond,
+ }
+ .into(),
);
- }
- verify {
- assert_last_event::<T>(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(
&<CollatorSelection<T>>::account_id(),
balance_unit::<T>() * 4u32.into(),
);
let author = account("author", 0, SEED);
- let new_block: BlockNumberFor<T>= 10u32.into();
+ let new_block: BlockNumberFor<T> = 10u32.into();
frame_system::Pallet::<T>::set_block_number(new_block);
assert!(T::Currency::balance(&author) == 0u32.into());
- }: {
- <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone())
- } verify {
+
+ #[block]
+ {
+ <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone());
+ }
+
assert!(T::Currency::balance(&author) > 0u32.into());
assert_eq!(frame_system::Pallet::<T>::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::<T>::set_block_number(0u32.into());
register_validators::<T>(c);
register_candidates::<T>(c);
- let new_block: BlockNumberFor<T>= 1800u32.into();
+ let new_block: BlockNumberFor<T> = 1800u32.into();
let zero_block: BlockNumberFor<T> = 0u32.into();
let candidates = <Candidates<T>>::get();
@@ -362,19 +431,24 @@
frame_system::Pallet::<T>::set_block_number(new_block);
assert!(<Candidates<T>>::get().len() == c as usize);
- }: {
- <CollatorSelection<T> as SessionManager<_>>::new_session(0)
- } verify {
+
+ #[block]
+ {
+ <CollatorSelection<T> as SessionManager<_>>::new_session(0);
+ }
+
if c > r {
assert!(<Candidates<T>>::get().len() < pre_length);
} else {
assert!(<Candidates<T>>::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,
+ );
+}
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- 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::<Vec<_>>();
- }: {<Pallet<T>>::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::<Vec<_>>();
+
+ #[block]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
+ let props = (0..b)
+ .map(|p| Property {
+ key: property_key(p as usize),
+ value: property_value(),
+ })
+ .collect::<Vec<_>>();
<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;
let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();
- }: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?}
- check_accesslist{
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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 = <CollectionHandle<T>>::try_get(collection.id)?;
- <Pallet<T>>::update_permissions(
- &sender,
- &mut collection_handle,
- CollectionPermissions { access: Some(AccessMode::AllowList), ..Default::default() }
- )?;
+ <Pallet<T>>::update_permissions(
+ &sender,
+ &mut collection_handle,
+ CollectionPermissions {
+ access: Some(AccessMode::AllowList),
+ ..Default::default()
+ },
+ )?;
- <Pallet<T>>::toggle_allowlist(
- &collection,
- &sender,
- &sender,
- true,
- )?;
+ <Pallet<T>>::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(())
+ }
}
pallets/configuration/src/benchmarking.rsdiffbeforeafterboth--- 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<u32>
- }
+)]
+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!(
- <Pallet<T>>::set_weight_to_fee_coefficient_override(RawOrigin::Root.into(), Some(coeff))
- );
+
+ #[block]
+ {
+ assert_ok!(<Pallet<T>>::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!(
- <Pallet<T>>::set_min_gas_price_override(RawOrigin::Root.into(), Some(coeff))
- );
+
+ #[block]
+ {
+ assert_ok!(<Pallet<T>>::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<BlockNumberFor<T>> = Default::default();
- }: {
- assert_ok!(
- <Pallet<T>>::set_app_promotion_configuration_override(RawOrigin::Root.into(), configuration)
- );
+
+ #[block]
+ {
+ assert_ok!(<Pallet<T>>::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!(
- <Pallet<T>>::set_collator_selection_desired_collators(RawOrigin::Root.into(), Some(max))
+
+ #[block]
+ {
+ assert_ok!(<Pallet<T>>::set_collator_selection_desired_collators(
+ RawOrigin::Root.into(),
+ Some(max)
+ ));
+ }
+
+ assert_last_event::<T>(
+ Event::NewDesiredCollators {
+ desired_collators: Some(max),
+ }
+ .into(),
);
+
+ Ok(())
}
- verify {
- assert_last_event::<T>(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<T::Balance> = Some(1000u32.into());
- }: {
- assert_ok!(
- <Pallet<T>>::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost)
- );
- }
- verify {
- assert_last_event::<T>(Event::NewCollatorLicenseBond{bond_cost}.into());
+
+ #[block]
+ {
+ assert_ok!(<Pallet<T>>::set_collator_selection_license_bond(
+ RawOrigin::Root.into(),
+ bond_cost
+ ));
+ }
+
+ assert_last_event::<T>(Event::NewCollatorLicenseBond { bond_cost }.into());
+
+ Ok(())
}
- set_collator_selection_kick_threshold {
+ #[benchmark]
+ fn set_collator_selection_kick_threshold() -> Result<(), BenchmarkError> {
let threshold: Option<BlockNumberFor<T>> = Some(900u32.into());
- }: {
- assert_ok!(
- <Pallet<T>>::set_collator_selection_kick_threshold(RawOrigin::Root.into(), threshold)
+
+ #[block]
+ {
+ assert_ok!(<Pallet<T>>::set_collator_selection_kick_threshold(
+ RawOrigin::Root.into(),
+ threshold
+ ));
+ }
+
+ assert_last_event::<T>(
+ Event::NewCollatorKickThreshold {
+ length_in_blocks: threshold,
+ }
+ .into(),
);
- }
- verify {
- assert_last_event::<T>(Event::NewCollatorKickThreshold{length_in_blocks: threshold}.into());
+
+ Ok(())
}
}
pallets/evm-migration/src/benchmarking.rsdiffbeforeafterboth--- 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 <T as Config>::RuntimeEvent: parity_scale_codec::Encode }
+#[benchmarks(
+ where <T as Config>::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 @@
));
}
<Pallet<T>>::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<u8> = (0..b as u8).collect();
<Pallet<T>>::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::<Vec<_>>();
- }: _(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::<Vec<_>>();
- 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(|_| <T as Config>::RuntimeEvent::from(crate::Event::<T>::TestEvent).encode()).collect::<Vec<_>>();
- }: _(RawOrigin::Root, logs)
+ let logs = (0..b)
+ .map(|_| <T as Config>::RuntimeEvent::from(crate::Event::<T>::TestEvent).encode())
+ .collect::<Vec<_>>();
+
+ #[extrinsic_call]
+ _(RawOrigin::Root, logs);
+
+ Ok(())
+ }
}
pallets/foreign-assets/src/benchmarking.rsdiffbeforeafterboth--- 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<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{
+ let metadata: AssetMetadata<
+ <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
+ > = AssetMetadata {
name: bounded(b"name"),
symbol: bounded(b"symbol"),
decimals: 18,
- minimal_balance: 1u32.into()
+ minimal_balance: 1u32.into(),
};
- let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =
- 4_000_000_000u32.into();
+ let mut balance: <<T as Config>::Currency as Currency<
+ <T as frame_system::Config>::AccountId,
+ >>::Balance = 4_000_000_000u32.into();
balance = balance * balance;
- <T as Config>::Currency::make_free_balance_be(&owner,
- balance);
- }: _(RawOrigin::Root, owner, Box::new(location), Box::new(metadata))
+ <T as Config>::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<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{
+ let metadata: AssetMetadata<
+ <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
+ > = AssetMetadata {
name: bounded(b"name"),
symbol: bounded(b"symbol"),
decimals: 18,
- minimal_balance: 1u32.into()
+ minimal_balance: 1u32.into(),
};
- let metadata2: AssetMetadata<<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance> = AssetMetadata{
+ let metadata2: AssetMetadata<
+ <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
+ > = AssetMetadata {
name: bounded(b"name2"),
symbol: bounded(b"symbol2"),
decimals: 18,
- minimal_balance: 1u32.into()
+ minimal_balance: 1u32.into(),
};
- let mut balance: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance =
- 4_000_000_000u32.into();
+ let mut balance: <<T as Config>::Currency as Currency<
+ <T as frame_system::Config>::AccountId,
+ >>::Balance = 4_000_000_000u32.into();
balance = balance * balance;
<T as Config>::Currency::make_free_balance_be(&owner, balance);
- Pallet::<T>::register_foreign_asset(RawOrigin::Root.into(), owner, Box::new(location.clone()), Box::new(metadata))?;
- }: _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2))
+ Pallet::<T>::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(())
+ }
}
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- 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 <http://www.gnu.org/licenses/>.
-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;
};
- }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200), &Unlimited)?}
- create_multiple_items_ex {
- let b in 0..MAX_ITEMS_PER_BATCH;
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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::<BTreeMap<_, _>>();
- }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
+ let data = (0..b)
+ .map(|i| {
+ bench_init!(to: cross_sub(i););
+ (to, 200)
+ })
+ .collect::<BTreeMap<_, _>>();
+
+ #[block]
+ {
+ <Pallet<T>>::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;
};
<Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200), &Unlimited)?;
- }: {<Pallet<T>>::burn(&collection, &burner, 100)?}
- transfer_raw {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
- }: {<Pallet<T>>::transfer(&collection, &sender, &to, 200, &Unlimited)?}
- approve {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
- }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}
- approve_from {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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());
<Pallet<T>>::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?;
- }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?}
- check_allowed_raw {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;
- }: {<Pallet<T>>::check_allowed(&collection, &spender, &sender, 200, &Unlimited)?;}
- set_allowance_unchecked_raw {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
- }: {<Pallet<T>>::set_allowance_unchecked(&collection, &sender, &spender, 200);}
- burn_from {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
<Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;
- }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?}
+
+ #[block]
+ {
+ <Pallet<T>>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?
+ }
+
+ Ok(())
+ }
}
pallets/identity/src/benchmarking.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2020-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435//! Identity pallet benchmarking.3637#![cfg(feature = "runtime-benchmarks")]38#![allow(clippy::no_effect)]3940use frame_benchmarking::v2::*;41use frame_support::{assert_ok, ensure, traits::EnsureOrigin};42use frame_system::RawOrigin;43use sp_runtime::traits::Bounded;4445use super::*;46use crate::Pallet as Identity;4748const SEED: u32 = 0;4950fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {51 frame_system::Pallet::<T>::assert_last_event(generic_event.into());52}5354// Adds `r` registrars to the Identity Pallet. These registrars will have set fees and fields.55fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> {56 for i in 0..r {57 let registrar: T::AccountId = account("registrar", i, SEED);58 let registrar_lookup = T::Lookup::unlookup(registrar.clone());59 let _ = T::Currency::make_free_balance_be(®istrar, BalanceOf::<T>::max_value());60 let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();61 Identity::<T>::add_registrar(registrar_origin, registrar_lookup)?;62 Identity::<T>::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?;63 let fields = IdentityFields(64 IdentityField::Display65 | IdentityField::Legal66 | IdentityField::Web67 | IdentityField::Riot68 | IdentityField::Email69 | IdentityField::PgpFingerprint70 | IdentityField::Image71 | IdentityField::Twitter,72 );73 Identity::<T>::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields)?;74 }7576 assert_eq!(Registrars::<T>::get().len(), r as usize);77 Ok(())78}7980// Create `s` sub-accounts for the identity of `who` and return them.81// Each will have 32 bytes of raw data added to it.82fn create_sub_accounts<T: Config>(83 who: &T::AccountId,84 s: u32,85) -> Result<Vec<(T::AccountId, Data)>, &'static str> {86 let mut subs = Vec::new();87 let who_origin = RawOrigin::Signed(who.clone());88 let data = Data::Raw(vec![0; 32].try_into().unwrap());8990 for i in 0..s {91 let sub_account = account("sub", i, SEED);92 subs.push((sub_account, data.clone()));93 }9495 // Set identity so `set_subs` does not fail.96 if IdentityOf::<T>::get(who).is_none() {97 let _ = T::Currency::make_free_balance_be(who, BalanceOf::<T>::max_value() / 2u32.into());98 let info = create_identity_info::<T>(1);99 Identity::<T>::set_identity(who_origin.into(), Box::new(info))?;100 }101102 Ok(subs)103}104105// Adds `s` sub-accounts to the identity of `who`. Each will have 32 bytes of raw data added to it.106// This additionally returns the vector of sub-accounts so it can be modified if needed.107fn add_sub_accounts<T: Config>(108 who: &T::AccountId,109 s: u32,110) -> Result<Vec<(T::AccountId, Data)>, &'static str> {111 let who_origin = RawOrigin::Signed(who.clone());112 let subs = create_sub_accounts::<T>(who, s)?;113114 Identity::<T>::set_subs(who_origin.into(), subs.clone())?;115116 Ok(subs)117}118119// This creates an `IdentityInfo` object with `num_fields` extra fields.120// All data is pre-populated with some arbitrary bytes.121fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo<T::MaxAdditionalFields> {122 let data = Data::Raw(vec![0; 32].try_into().unwrap());123124 IdentityInfo {125 additional: vec![(data.clone(), data.clone()); num_fields as usize]126 .try_into()127 .unwrap(),128 display: data.clone(),129 legal: data.clone(),130 web: data.clone(),131 riot: data.clone(),132 email: data.clone(),133 pgp_fingerprint: Some([0; 20]),134 image: data.clone(),135 twitter: data,136 }137}138139/// `Currency::minimum_balance` was used originally, but in unique-chain, we have140/// zero existential deposit, thus triggering zero bond assertion.141fn balance_unit<T: Config>() -> <T::Currency as Currency<T::AccountId>>::Balance {142 200u32.into()143}144145#[benchmarks]146mod benchmarks {147 use super::*;148149 const MAX_REGISTRARS: u32 = 20;150 const MAX_ADDITIONAL_FIELDS: u32 = 100;151 const MAX_SUB_ACCOUNTS: u32 = 100;152153 #[benchmark]154 fn add_registrar(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {155 let r = r - 1;156 add_registrars::<T>(r)?;157 ensure!(158 Registrars::<T>::get().len() as u32 == r,159 "Registrars not set up correctly."160 );161 let origin = T::RegistrarOrigin::try_successful_origin().unwrap();162 let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));163164 #[extrinsic_call]165 _(origin as T::RuntimeOrigin, account);166167 ensure!(168 Registrars::<T>::get().len() as u32 == r + 1,169 "Registrars not added."170 );171172 Ok(())173 }174175 #[benchmark]176 fn set_identity(177 x: Linear<0, MAX_ADDITIONAL_FIELDS>,178 r: Linear<1, MAX_REGISTRARS>,179 ) -> Result<(), BenchmarkError> {180 add_registrars::<T>(r)?;181 let caller = {182 // The target user183 let caller: T::AccountId = whitelisted_caller();184 let caller_lookup = T::Lookup::unlookup(caller.clone());185 let caller_origin: <T as frame_system::Config>::RuntimeOrigin =186 RawOrigin::Signed(caller.clone()).into();187 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());188189 // Add an initial identity190 let initial_info = create_identity_info::<T>(1);191 Identity::<T>::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?;192193 // User requests judgement from all the registrars, and they approve194 for i in 0..r {195 let registrar: T::AccountId = account("registrar", i, SEED);196 let balance_to_use = balance_unit::<T>() * 10u32.into();197 let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);198199 Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;200 Identity::<T>::provide_judgement(201 RawOrigin::Signed(registrar).into(),202 i,203 caller_lookup.clone(),204 Judgement::Reasonable,205 T::Hashing::hash_of(&initial_info),206 )?;207 }208 caller209 };210211 #[extrinsic_call]212 _(213 RawOrigin::Signed(caller.clone()),214 Box::new(create_identity_info::<T>(x)),215 );216217 assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into());218219 Ok(())220 }221222 // We need to split `set_subs` into two benchmarks to accurately isolate the potential223 // writes caused by new or old sub accounts. The actual weight should simply be224 // the sum of these two weights.225 #[benchmark]226 fn set_subs_new(s: Linear<0, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {227 let caller: T::AccountId = whitelisted_caller();228 // Create a new subs vec with s sub accounts229 let subs = create_sub_accounts::<T>(&caller, s)?;230 ensure!(231 SubsOf::<T>::get(&caller).1.len() == 0,232 "Caller already has subs"233 );234235 #[extrinsic_call]236 set_subs(RawOrigin::Signed(caller.clone()), subs);237238 ensure!(239 SubsOf::<T>::get(&caller).1.len() as u32 == s,240 "Subs not added"241 );242243 Ok(())244 }245246 #[benchmark]247 fn set_subs_old(p: Linear<0, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {248 let caller: T::AccountId = whitelisted_caller();249 // Give them p many previous sub accounts.250 let _ = add_sub_accounts::<T>(&caller, p)?;251 // Remove all subs.252 let subs = create_sub_accounts::<T>(&caller, 0)?;253 ensure!(254 SubsOf::<T>::get(&caller).1.len() as u32 == p,255 "Caller does have subs",256 );257258 #[extrinsic_call]259 set_subs(RawOrigin::Signed(caller.clone()), subs);260261 ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Subs not removed");262263 Ok(())264 }265266 #[benchmark]267 fn clear_identity(268 r: Linear<1, MAX_REGISTRARS>,269 s: Linear<0, MAX_SUB_ACCOUNTS>,270 x: Linear<0, MAX_ADDITIONAL_FIELDS>,271 ) -> Result<(), BenchmarkError> {272 let caller: T::AccountId = whitelisted_caller();273 let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());274 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());275276 add_registrars::<T>(r)?;277278 {279 // Give them s many sub accounts280 let caller: T::AccountId = whitelisted_caller();281 let _ = add_sub_accounts::<T>(&caller, s)?;282 }283284 // Create their main identity with x additional fields285 let info = create_identity_info::<T>(x);286 let caller: T::AccountId = whitelisted_caller();287 let caller_origin =288 <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));289 Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?;290291 // User requests judgement from all the registrars, and they approve292 for i in 0..r {293 let registrar: T::AccountId = account("registrar", i, SEED);294 let balance_to_use = balance_unit::<T>() * 10u32.into();295 let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);296297 Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;298 Identity::<T>::provide_judgement(299 RawOrigin::Signed(registrar).into(),300 i,301 caller_lookup.clone(),302 Judgement::Reasonable,303 T::Hashing::hash_of(&info),304 )?;305 }306 ensure!(307 IdentityOf::<T>::contains_key(&caller),308 "Identity does not exist."309 );310311 #[extrinsic_call]312 _(RawOrigin::Signed(caller.clone()));313314 ensure!(315 !IdentityOf::<T>::contains_key(&caller),316 "Identity not cleared."317 );318319 Ok(())320 }321322 #[benchmark]323 fn request_judgement(324 r: Linear<1, MAX_REGISTRARS>,325 x: Linear<0, MAX_ADDITIONAL_FIELDS>,326 ) -> Result<(), BenchmarkError> {327 let caller: T::AccountId = whitelisted_caller();328 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());329330 add_registrars::<T>(r)?;331332 {333 // Create their main identity with x additional fields334 let info = create_identity_info::<T>(x);335 let caller: T::AccountId = whitelisted_caller();336 let caller_origin =337 <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));338 Identity::<T>::set_identity(caller_origin, Box::new(info))?;339 }340341 #[extrinsic_call]342 _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into());343344 assert_last_event::<T>(345 Event::<T>::JudgementRequested {346 who: caller,347 registrar_index: r - 1,348 }349 .into(),350 );351352 Ok(())353 }354355 #[benchmark]356 fn cancel_request(357 r: Linear<1, MAX_REGISTRARS>,358 x: Linear<0, MAX_ADDITIONAL_FIELDS>,359 ) -> Result<(), BenchmarkError> {360 let caller: T::AccountId = whitelisted_caller();361 let caller_origin =362 <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));363 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());364365 add_registrars::<T>(r)?;366367 {368 // Create their main identity with x additional fields369 let info = create_identity_info::<T>(x);370 let caller: T::AccountId = whitelisted_caller();371 let caller_origin =372 <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));373 Identity::<T>::set_identity(caller_origin, Box::new(info))?;374 }375376 Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?;377378 #[extrinsic_call]379 _(RawOrigin::Signed(caller.clone()), r - 1);380381 assert_last_event::<T>(382 Event::<T>::JudgementUnrequested {383 who: caller,384 registrar_index: r - 1,385 }386 .into(),387 );388389 Ok(())390 }391392 #[benchmark]393 fn set_fee(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {394 let r = r - 1;395 let caller: T::AccountId = whitelisted_caller();396 let caller_lookup = T::Lookup::unlookup(caller.clone());397398 add_registrars::<T>(r)?;399400 let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();401 Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;402 let registrars = Registrars::<T>::get();403 ensure!(404 registrars[r as usize].as_ref().unwrap().fee == 0u32.into(),405 "Fee already set."406 );407408 #[extrinsic_call]409 _(RawOrigin::Signed(caller), r, 100u32.into());410411 let registrars = Registrars::<T>::get();412 ensure!(413 registrars[r as usize].as_ref().unwrap().fee == 100u32.into(),414 "Fee not changed."415 );416417 Ok(())418 }419420 #[benchmark]421 fn set_account_id(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {422 let r = r - 1;423 let caller: T::AccountId = whitelisted_caller();424 let caller_lookup = T::Lookup::unlookup(caller.clone());425 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());426427 add_registrars::<T>(r)?;428429 let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();430 Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;431 let registrars = Registrars::<T>::get();432 ensure!(433 registrars[r as usize].as_ref().unwrap().account == caller,434 "id not set."435 );436 let new_account = T::Lookup::unlookup(account("new", 0, SEED));437438 #[extrinsic_call]439 _(RawOrigin::Signed(caller), r, new_account);440441 let registrars = Registrars::<T>::get();442 ensure!(443 registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED),444 "id not changed."445 );446447 Ok(())448 }449450 #[benchmark]451 fn set_fields(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {452 let r = r - 1;453 let caller: T::AccountId = whitelisted_caller();454 let caller_lookup = T::Lookup::unlookup(caller.clone());455 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());456457 add_registrars::<T>(r)?;458459 let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();460 Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;461 let fields = IdentityFields(462 IdentityField::Display463 | IdentityField::Legal464 | IdentityField::Web465 | IdentityField::Riot466 | IdentityField::Email467 | IdentityField::PgpFingerprint468 | IdentityField::Image469 | IdentityField::Twitter,470 );471 let registrars = Registrars::<T>::get();472 ensure!(473 registrars[r as usize].as_ref().unwrap().fields == Default::default(),474 "fields already set."475 );476477 #[extrinsic_call]478 _(RawOrigin::Signed(caller), r, fields);479480 let registrars = Registrars::<T>::get();481 ensure!(482 registrars[r as usize].as_ref().unwrap().fields != Default::default(),483 "fields not set."484 );485486 Ok(())487 }488489 #[benchmark]490 fn provide_judgement(491 r: Linear<2, MAX_REGISTRARS>,492 x: Linear<0, MAX_ADDITIONAL_FIELDS>,493 ) -> Result<(), BenchmarkError> {494 let r = r - 1;495 // The user496 let user: T::AccountId = account("user", r, SEED);497 let user_origin =498 <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));499 let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());500 let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());501502 let caller: T::AccountId = whitelisted_caller();503 let caller_lookup = T::Lookup::unlookup(caller.clone());504 let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());505506 add_registrars::<T>(r)?;507508 let info = create_identity_info::<T>(x);509 let info_hash = T::Hashing::hash_of(&info);510 Identity::<T>::set_identity(user_origin.clone(), Box::new(info))?;511512 let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();513 Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;514 Identity::<T>::request_judgement(user_origin, r, 10u32.into())?;515516 #[extrinsic_call]517 _(518 RawOrigin::Signed(caller),519 r,520 user_lookup,521 Judgement::Reasonable,522 info_hash,523 );524525 assert_last_event::<T>(526 Event::<T>::JudgementGiven {527 target: user,528 registrar_index: r,529 }530 .into(),531 );532533 Ok(())534 }535536 #[benchmark]537 fn kill_identity(538 r: Linear<1, MAX_REGISTRARS>,539 s: Linear<0, MAX_SUB_ACCOUNTS>,540 x: Linear<0, MAX_ADDITIONAL_FIELDS>,541 ) -> Result<(), BenchmarkError> {542 add_registrars::<T>(r)?;543544 let target: T::AccountId = account("target", 0, SEED);545 let target_origin: <T as frame_system::Config>::RuntimeOrigin =546 RawOrigin::Signed(target.clone()).into();547 let target_lookup = T::Lookup::unlookup(target.clone());548 let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());549550 let info = create_identity_info::<T>(x);551 Identity::<T>::set_identity(target_origin.clone(), Box::new(info.clone()))?;552 let _ = add_sub_accounts::<T>(&target, s)?;553554 // User requests judgement from all the registrars, and they approve555 for i in 0..r {556 let registrar: T::AccountId = account("registrar", i, SEED);557 let balance_to_use = balance_unit::<T>() * 10u32.into();558 let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);559560 Identity::<T>::request_judgement(target_origin.clone(), i, 10u32.into())?;561 Identity::<T>::provide_judgement(562 RawOrigin::Signed(registrar).into(),563 i,564 target_lookup.clone(),565 Judgement::Reasonable,566 T::Hashing::hash_of(&info),567 )?;568 }569 ensure!(IdentityOf::<T>::contains_key(&target), "Identity not set");570 let origin = T::ForceOrigin::try_successful_origin().unwrap();571572 #[extrinsic_call]573 _(origin as T::RuntimeOrigin, target_lookup);574575 ensure!(576 !IdentityOf::<T>::contains_key(&target),577 "Identity not removed"578 );579580 Ok(())581 }582583 #[benchmark]584 fn force_insert_identities(585 x: Linear<0, MAX_ADDITIONAL_FIELDS>,586 n: Linear<0, 600>,587 ) -> Result<(), BenchmarkError> {588 use frame_benchmarking::account;589 let identities = (0..n)590 .map(|i| {591 (592 account("caller", i, SEED),593 Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {594 judgements: Default::default(),595 deposit: Default::default(),596 info: create_identity_info::<T>(x),597 },598 )599 })600 .collect::<Vec<_>>();601 let origin = T::ForceOrigin::try_successful_origin().unwrap();602603 #[extrinsic_call]604 _(origin as T::RuntimeOrigin, identities);605606 Ok(())607 }608609 #[benchmark]610 fn force_remove_identities(611 x: Linear<0, MAX_ADDITIONAL_FIELDS>,612 n: Linear<0, 600>,613 ) -> Result<(), BenchmarkError> {614 use frame_benchmarking::account;615 let origin = T::ForceOrigin::try_successful_origin().unwrap();616 let identities = (0..n)617 .map(|i| {618 (619 account("caller", i, SEED),620 Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {621 judgements: Default::default(),622 deposit: Default::default(),623 info: create_identity_info::<T>(x),624 },625 )626 })627 .collect::<Vec<_>>();628 assert_ok!(Identity::<T>::force_insert_identities(629 origin.clone(),630 identities.clone()631 ),);632 let identities = identities633 .into_iter()634 .map(|(acc, _)| acc)635 .collect::<Vec<_>>();636637 #[extrinsic_call]638 _(origin as T::RuntimeOrigin, identities);639640 Ok(())641 }642643 #[benchmark]644 fn force_set_subs(645 s: Linear<0, MAX_SUB_ACCOUNTS>,646 n: Linear<0, 600>,647 ) -> Result<(), BenchmarkError> {648 use frame_benchmarking::account;649 let identities = (0..n)650 .map(|i| {651 let caller: T::AccountId = account("caller", i, SEED);652 (653 caller.clone(),654 (655 BalanceOf::<T>::max_value(),656 create_sub_accounts::<T>(&caller, s)657 .unwrap()658 .try_into()659 .unwrap(),660 ),661 )662 })663 .collect::<Vec<_>>();664 let origin = T::ForceOrigin::try_successful_origin().unwrap();665666 #[extrinsic_call]667 _(origin as T::RuntimeOrigin, identities);668669 Ok(())670 }671672 #[benchmark]673 fn add_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {674 let s = s - 1;675 let caller: T::AccountId = whitelisted_caller();676 let _ = add_sub_accounts::<T>(&caller, s)?;677 let sub = account("new_sub", 0, SEED);678 let data = Data::Raw(vec![0; 32].try_into().unwrap());679 ensure!(680 SubsOf::<T>::get(&caller).1.len() as u32 == s,681 "Subs not set."682 );683684 #[extrinsic_call]685 _(686 RawOrigin::Signed(caller.clone()),687 T::Lookup::unlookup(sub),688 data,689 );690691 ensure!(692 SubsOf::<T>::get(&caller).1.len() as u32 == s + 1,693 "Subs not added."694 );695696 Ok(())697 }698699 #[benchmark]700 fn rename_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {701 let caller: T::AccountId = whitelisted_caller();702 let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);703 let data = Data::Raw(vec![1; 32].try_into().unwrap());704 ensure!(705 SuperOf::<T>::get(&sub).unwrap().1 != data,706 "data already set"707 );708709 #[extrinsic_call]710 _(711 RawOrigin::Signed(caller),712 T::Lookup::unlookup(sub.clone()),713 data.clone(),714 );715716 ensure!(SuperOf::<T>::get(&sub).unwrap().1 == data, "data not set");717718 Ok(())719 }720721 #[benchmark]722 fn remove_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {723 let caller: T::AccountId = whitelisted_caller();724 let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);725 ensure!(SuperOf::<T>::contains_key(&sub), "Sub doesn't exists");726727 #[extrinsic_call]728 _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()));729730 ensure!(!SuperOf::<T>::contains_key(&sub), "Sub not removed");731732 Ok(())733 }734735 #[benchmark]736 fn quit_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {737 let s = s - 1;738 let caller: T::AccountId = whitelisted_caller();739 let sup = account("super", 0, SEED);740 let _ = add_sub_accounts::<T>(&sup, s)?;741 let sup_origin = RawOrigin::Signed(sup).into();742 Identity::<T>::add_sub(743 sup_origin,744 T::Lookup::unlookup(caller.clone()),745 Data::Raw(vec![0; 32].try_into().unwrap()),746 )?;747 ensure!(SuperOf::<T>::contains_key(&caller), "Sub doesn't exists");748749 #[extrinsic_call]750 _(RawOrigin::Signed(caller.clone()));751752 ensure!(!SuperOf::<T>::contains_key(&caller), "Sub not removed");753754 Ok(())755 }756757 impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test);758}pallets/inflation/src/benchmarking.rsdiffbeforeafterboth--- 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<T> = 1u32.into();
let block2: BlockNumberFor<T> = 2u32.into();
- <Inflation<T> as Hooks>::on_initialize(block1); // Create Treasury account
- }: { <Inflation<T> as Hooks>::on_initialize(block2); } // Benchmark deposit_into_existing path
+ <Inflation<T> as Hooks<_>>::on_initialize(block1); // Create Treasury account
+ #[block]
+ {
+ <Inflation<T> as Hooks<_>>::on_initialize(block2);
+ // Benchmark deposit_into_existing path
+ }
+
+ Ok(())
+ }
}
pallets/maintenance/src/benchmarking.rsdiffbeforeafterboth--- 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 <http://www.gnu.org/licenses/>.
-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!(<Enabled<T>>::get(), "didn't enable the MM");
+
+ Ok(())
}
- disable {
+ #[benchmark]
+ fn disable() -> Result<(), BenchmarkError> {
Maintenance::<T>::enable(RawOrigin::Root.into())?;
- }: _(RawOrigin::Root)
- verify {
+
+ #[extrinsic_call]
+ _(RawOrigin::Root);
+
ensure!(!<Enabled<T>>::get(), "didn't disable the MM");
- }
- #[pov_mode = MaxEncodedLen {
- // PoV size is deducted from weight_bound
- Preimage::PreimageFor: Measured
- }]
- execute_preimage {
- let call = <T as Config>::RuntimeCall::from(frame_system::Call::<T>::remark { remark: 1u32.encode() });
- let hash = T::Preimages::note(call.encode().into())?;
- }: _(RawOrigin::Root, hash, Weight::from_parts(100000000000, 100000000000))
- verify {
+ Ok(())
}
}
pallets/maintenance/src/lib.rsdiffbeforeafterboth--- 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(<T as Config>::WeightInfo::execute_preimage() + *weight_bound)]
- pub fn execute_preimage(
- origin: OriginFor<T>,
- 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 = <T as Config>::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,
- }),
- }
}
}
}
pallets/maintenance/src/weights.rsdiffbeforeafterboth--- 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))
}
}
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- 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 <http://www.gnu.org/licenses/>.
-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::<T>(to.clone())).collect();
- }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
+ let data = (0..b)
+ .map(|_| create_max_item_data::<T>(to.clone()))
+ .collect();
- create_multiple_items_ex {
- let b in 0..MAX_ITEMS_PER_BATCH;
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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::<T>(to)
- }).collect();
- }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
+ let data = (0..b)
+ .map(|i| {
+ bench_init!(to: cross_sub(i););
+ create_max_item_data::<T>(to)
+ })
+ .collect();
+
+ #[block]
+ {
+ <Pallet<T>>::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())?;
- }: {<Pallet<T>>::burn(&collection, &burner, item)?}
- burn_recursively_self_raw {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
- }: {<Pallet<T>>::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]
+ {
+ <Pallet<T>>::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),
+ )?;
}
- }: {<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?}
- transfer_raw {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
- }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, &Unlimited)?}
- approve {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
- }: {<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?}
- approve_from {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
- }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?}
- check_allowed_raw {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;
- }: {<Pallet<T>>::check_allowed(&collection, &spender, &sender, item, &Unlimited)?}
- burn_from {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;
- }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?}
- set_token_property_permissions {
- let b in 0..MAX_PROPERTIES_PER_ITEM;
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
- }: {<Pallet<T>>::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::<Vec<_>>();
+
+ #[block]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
+ let perms = (0..b)
+ .map(|k| PropertyKeyPermission {
+ key: property_key(k as usize),
+ permission: PropertyPermission {
+ mutable: false,
+ collection_admin: true,
+ token_owner: true,
+ },
+ })
+ .collect::<Vec<_>>();
<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b).map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- }).collect::<Vec<_>>();
+ let props = (0..b)
+ .map(|k| Property {
+ key: property_key(k as usize),
+ value: property_value(),
+ })
+ .collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;
- }: {<Pallet<T>>::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]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b).map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- }).collect::<Vec<_>>();
- 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::<Vec<_>>();
+ // <Pallet<T>>::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::<Vec<_>>();
+ // 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::<Vec<_>>();
+ let perms = (0..b)
+ .map(|k| PropertyKeyPermission {
+ key: property_key(k as usize),
+ permission: PropertyPermission {
+ mutable: true,
+ collection_admin: true,
+ token_owner: true,
+ },
+ })
+ .collect::<Vec<_>>();
<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b).map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- }).collect::<Vec<_>>();
+ let props = (0..b)
+ .map(|k| Property {
+ key: property_key(k as usize),
+ value: property_value(),
+ })
+ .collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;
- <Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?;
+ <Pallet<T>>::set_token_properties(
+ &collection,
+ &owner,
+ item,
+ props.into_iter(),
+ &Unlimited,
+ )?;
let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
- }: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?}
- token_owner {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
- }: {<Pallet<T>>::set_allowance_for_all(&collection, &owner, &operator, true)?}
- allowance_for_all {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
- }: {<Pallet<T>>::allowance_for_all(&collection, &owner, &operator)}
- repair_item {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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())?;
- }: {<Pallet<T>>::repair_item(&collection, item)?}
+
+ #[block]
+ {
+ <Pallet<T>>::repair_item(&collection, item)?;
+ }
+
+ Ok(())
+ }
}
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- 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::<T>([(to.clone(), 200)])).collect();
- }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
+ let data = (0..b)
+ .map(|_| create_max_item_data::<T>([(to.clone(), 200)]))
+ .collect();
+
+ #[block]
+ {
+ <Pallet<T>>::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::<T>([(to, 200)])
- }).collect();
- }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
+ let data = (0..b)
+ .map(|t| {
+ bench_init!(to: cross_sub(t););
+ create_max_item_data::<T>([(to, 200)])
+ })
+ .collect();
+
+ #[block]
+ {
+ <Pallet<T>>::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)
}))];
- }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}
+ let item = create_max_item(
+ &collection,
+ &sender,
+ [(burner.clone(), 200), (another_owner, 200)],
+ )?;
+
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}
- transfer_normal {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}
+ let item = create_max_item(
+ &collection,
+ &sender,
+ [(sender.clone(), 200), (receiver.clone(), 200)],
+ )?;
+
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}
+
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}
+ let item = create_max_item(
+ &collection,
+ &sender,
+ [(sender.clone(), 200), (receiver.clone(), 200)],
+ )?;
+
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}
- approve {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}
- approve_from {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, item, 100)?}
- transfer_from_normal {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)],
+ )?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;
- }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}
+
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;
- }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}
+
+ #[block]
+ {
+ <Pallet<T>>::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)],
+ )?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;
- }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}
+
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;
- }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
<Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;
- }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?}
- set_token_property_permissions {
- let b in 0..MAX_PROPERTIES_PER_ITEM;
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
- }: {<Pallet<T>>::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::<Vec<_>>();
+
+ #[block]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
+ let perms = (0..b)
+ .map(|k| PropertyKeyPermission {
+ key: property_key(k as usize),
+ permission: PropertyPermission {
+ mutable: false,
+ collection_admin: true,
+ token_owner: true,
+ },
+ })
+ .collect::<Vec<_>>();
<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b).map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- }).collect::<Vec<_>>();
+ let props = (0..b)
+ .map(|k| Property {
+ key: property_key(k as usize),
+ value: property_value(),
+ })
+ .collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
- }: {<Pallet<T>>::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]
+ {
+ <Pallet<T>>::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::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b).map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- }).collect::<Vec<_>>();
- 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::<Vec<_>>();
+ // <Pallet<T>>::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::<Vec<_>>();
+ // 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::<Vec<_>>();
+ let perms = (0..b)
+ .map(|k| PropertyKeyPermission {
+ key: property_key(k as usize),
+ permission: PropertyPermission {
+ mutable: true,
+ collection_admin: true,
+ token_owner: true,
+ },
+ })
+ .collect::<Vec<_>>();
<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b).map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- }).collect::<Vec<_>>();
+ let props = (0..b)
+ .map(|k| Property {
+ key: property_key(k as usize),
+ value: property_value(),
+ })
+ .collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
- <Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?;
+ <Pallet<T>>::set_token_properties(
+ &collection,
+ &owner,
+ item,
+ props.into_iter(),
+ &Unlimited,
+ )?;
let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
- }: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?}
- repartition_item {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::repartition(&collection, &owner, item, 200)?}
- token_owner {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::token_owner(collection.id, item).unwrap()}
- set_allowance_for_all {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
- }: {<Pallet<T>>::set_allowance_for_all(&collection, &owner, &operator, true)?}
- allowance_for_all {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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;
};
- }: {<Pallet<T>>::allowance_for_all(&collection, &owner, &operator)}
- repair_item {
- bench_init!{
+ #[block]
+ {
+ <Pallet<T>>::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)])?;
- }: {<Pallet<T>>::repair_item(&collection, item)?}
+
+ #[block]
+ {
+ <Pallet<T>>::repair_item(&collection, item)?;
+ }
+
+ Ok(())
+ }
}
pallets/structure/src/benchmarking.rsdiffbeforeafterboth--- 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 <http://www.gnu.org/licenses/>.
-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 _ = <T as CommonConfig>::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap();
+ let _ = <T as CommonConfig>::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 = <Pallet<T>>::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 = <Pallet<T>>::find_parent(CollectionId(1), TokenId(1))?;
+ assert!(matches!(parent, Parent::User(_)));
+ }
+
+ Ok(())
}
}
pallets/unique/src/benchmarking.rsdiffbeforeafterboth--- 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::<T>(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 _ = <T as CommonConfig>::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap();
- }: _(RawOrigin::Signed(caller.clone()), col_name, col_desc, token_prefix, mode)
- verify {
- assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);
+ let _ = <T as CommonConfig>::Currency::deposit(
+ &caller,
+ T::CollectionCreationPrice::get(),
+ Precision::Exact,
+ )
+ .unwrap();
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller.clone()),
+ col_name,
+ col_desc,
+ token_prefix,
+ mode,
+ );
+
+ assert_eq!(
+ <pallet_common::CollectionById<T>>::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::<T>(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::<T>(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::<T>(caller.clone())?;
- <Pallet<T>>::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))
+ <Pallet<T>>::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::<T>(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::<T>(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::<T>(caller.clone())?;
let new_admin: T::AccountId = account("admin", 0, SEED);
- <Pallet<T>>::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))
+ <Pallet<T>>::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::<T>(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::<T>(caller.clone())?;
- <Pallet<T>>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), collection, caller.clone())?;
- }: _(RawOrigin::Signed(caller.clone()), collection)
+ <Pallet<T>>::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::<T>(caller.clone())?;
- <Pallet<T>>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), collection, caller.clone())?;
+ <Pallet<T>>::set_collection_sponsor(
+ RawOrigin::Signed(caller.clone()).into(),
+ collection,
+ caller.clone(),
+ )?;
<Pallet<T>>::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::<T>(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::<T>(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::<T>(caller)?;
- }: _(RawOrigin::Root, collection)
+
+ #[extrinsic_call]
+ _(RawOrigin::Root, collection);
+
+ Ok(())
+ }
}
runtime/common/config/xcm/foreignassets.rsdiffbeforeafterboth--- 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 =
- <AssetId as TryAsForeign<AssetId, ForeignAssetId>>::try_as_foreign(asset_id.clone())?;
+ let fid = <AssetId as TryAsForeign<AssetId, ForeignAssetId>>::try_as_foreign(*asset_id)?;
XcmForeignAssetIdMapping::<Runtime>::get_multi_location(fid)
}
}
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -569,7 +569,8 @@
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, 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<TrackedStorageKey> = vec![
// Total Issuance
runtime/opal/Cargo.tomldiffbeforeafterboth--- 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 }
runtime/quartz/Cargo.tomldiffbeforeafterboth--- 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 }
runtime/unique/Cargo.tomldiffbeforeafterboth--- 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 }
tests/src/maintenance.seqtest.tsdiffbeforeafterboth--- 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;