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.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// Copyright (C) 2021 Parity Technologies (UK) Ltd.19// SPDX-License-Identifier: Apache-2.02021// Licensed under the Apache License, Version 2.0 (the "License");22// you may not use this file except in compliance with the License.23// You may obtain a copy of the License at24//25// http://www.apache.org/licenses/LICENSE-2.026//27// Unless required by applicable law or agreed to in writing, software28// distributed under the License is distributed on an "AS IS" BASIS,29// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.30// See the License for the specific language governing permissions and31// limitations under the License.3233//! Benchmarking setup for pallet-collator-selection3435use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};36use frame_support::{37 assert_ok,38 traits::{39 fungible::{Inspect, Mutate},40 EnsureOrigin, Get,41 },42};43use frame_system::{pallet_prelude::*, EventRecord, RawOrigin};44use pallet_authorship::EventHandler;45use pallet_session::{self as session, SessionManager};46use parity_scale_codec::Decode;47use sp_std::prelude::*;4849use super::*;50#[allow(unused)]51use crate::{BalanceOf, Pallet as CollatorSelection};5253const SEED: u32 = 0;5455// TODO: remove if this is given in substrate commit.56macro_rules! whitelist {57 ($acc:ident) => {58 frame_benchmarking::benchmarking::add_to_whitelist(59 frame_system::Account::<T>::hashed_key_for(&$acc).into(),60 );61 };62}6364fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {65 let events = frame_system::Pallet::<T>::events();66 let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();67 // compare to the last event record68 let EventRecord { event, .. } = &events[events.len() - 1];69 assert_eq!(event, &system_event);70}7172fn create_funded_user<T: Config>(73 string: &'static str,74 n: u32,75 balance_factor: u32,76) -> T::AccountId {77 let user = account(string, n, SEED);78 let balance = balance_unit::<T>() * balance_factor.into();79 let _ = T::Currency::set_balance(&user, balance);80 user81}8283fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {84 use rand::{RngCore, SeedableRng};8586 let keys = {87 let mut keys = [0u8; 128];8889 if c > 0 {90 let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);91 rng.fill_bytes(&mut keys);92 }9394 keys95 };9697 Decode::decode(&mut &keys[..]).unwrap()98}99100fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {101 (create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))102}103104fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {105 let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();106107 for (who, keys) in validators.clone() {108 <session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();109 }110111 validators.into_iter().map(|(who, _)| who).collect()112}113114fn register_invulnerables<T: Config>(count: u32) {115 let candidates = (0..count)116 .map(|c| account("candidate", c, SEED))117 .collect::<Vec<_>>();118119 for who in candidates {120 <CollatorSelection<T>>::add_invulnerable(121 T::UpdateOrigin::try_successful_origin().unwrap(),122 who,123 )124 .unwrap();125 }126}127128fn register_candidates<T: Config>(count: u32) {129 let candidates = (0..count)130 .map(|c| account("candidate", c, SEED))131 .collect::<Vec<_>>();132 assert!(T::LicenseBond::get() > 0u32.into(), "Bond cannot be zero!");133134 for who in candidates {135 T::Currency::set_balance(&who, T::LicenseBond::get() * 2u32.into());136 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();137 <CollatorSelection<T>>::onboard(RawOrigin::Signed(who).into()).unwrap();138 }139}140141fn get_licenses<T: Config>(count: u32) {142 let candidates = (0..count)143 .map(|c| account("candidate", c, SEED))144 .collect::<Vec<_>>();145 assert!(T::LicenseBond::get() > 0u32.into(), "Bond cannot be zero!");146147 for who in candidates {148 T::Currency::set_balance(&who, T::LicenseBond::get() * 2u32.into());149 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();150 }151}152153/// `Currency::minimum_balance` was used originally, but in unique-chain, we have154/// zero existential deposit, thus triggering zero bond assertion.155fn balance_unit<T: Config>() -> BalanceOf<T> {156 T::LicenseBond::get()157}158159/// Our benchmarking environment already has invulnerables registered.160const INITIAL_INVULNERABLES: u32 = 2;161162benchmarks! {163 where_clause { where164 T: Config + pallet_authorship::Config + session::Config165 }166167 // todo:collator this and all the following do not work for some reason, going all the way up to 10 in length168 // Both invulnerables and candidates count together against MaxCollators.169 // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)170 add_invulnerable {171 let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;172 register_validators::<T>(b);173 register_invulnerables::<T>(b);174175 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);176177 let new_invulnerable: T::AccountId = whitelisted_caller();178 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();179 <T as Config>::Currency::set_balance(&new_invulnerable, bond);180181 <session::Pallet<T>>::set_keys(182 RawOrigin::Signed(new_invulnerable.clone()).into(),183 keys::<T>(b + 1),184 Vec::new()185 ).unwrap();186187 let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();188 }: {189 assert_ok!(190 <CollatorSelection<T>>::add_invulnerable(root_origin, new_invulnerable.clone())191 );192 }193 verify {194 assert_last_event::<T>(Event::InvulnerableAdded{invulnerable: new_invulnerable}.into());195 }196197 remove_invulnerable {198 let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;199 register_validators::<T>(b);200 register_invulnerables::<T>(b);201202 let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();203 let leaving = <Invulnerables<T>>::get().last().unwrap().clone();204 whitelist!(leaving);205 }: {206 assert_ok!(207 <CollatorSelection<T>>::remove_invulnerable(root_origin, leaving.clone())208 );209 }210 verify {211 assert_last_event::<T>(Event::InvulnerableRemoved{invulnerable: leaving}.into());212 }213214 get_license {215 let c in 1 .. T::MaxCollators::get() - 1;216217 register_validators::<T>(c);218 get_licenses::<T>(c);219220 let caller: T::AccountId = whitelisted_caller();221 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();222 T::Currency::set_balance(&caller, bond);223224 <session::Pallet<T>>::set_keys(225 RawOrigin::Signed(caller.clone()).into(),226 keys::<T>(c + 1),227 Vec::new()228 ).unwrap();229230 }: _(RawOrigin::Signed(caller.clone()))231 verify {232 assert_last_event::<T>(Event::LicenseObtained{account_id: caller, deposit: bond / 2u32.into()}.into());233 }234235 // worst case is when we have all the max-candidate slots filled except one, and we fill that236 // one.237 onboard {238 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;239240 register_validators::<T>(c);241 register_candidates::<T>(c);242243 let caller: T::AccountId = whitelisted_caller();244 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();245 T::Currency::set_balance(&caller, bond);246247 let origin = RawOrigin::Signed(caller.clone());248249 <session::Pallet<T>>::set_keys(250 origin.clone().into(),251 keys::<T>(c + 1),252 Vec::new()253 ).unwrap();254255 assert_ok!(256 <CollatorSelection<T>>::get_license(origin.clone().into())257 );258 }: _(origin)259 verify {260 assert_last_event::<T>(Event::CandidateAdded{account_id: caller}.into());261 }262263 // worst case is the last candidate leaving.264 offboard {265 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES;266267 register_validators::<T>(c);268 register_candidates::<T>(c);269270 let leaving = <Candidates<T>>::get().last().unwrap().clone();271 whitelist!(leaving);272 }: _(RawOrigin::Signed(leaving.clone()))273 verify {274 assert_last_event::<T>(Event::CandidateRemoved{account_id: leaving}.into());275 }276277 // worst case is the last candidate leaving.278 release_license {279 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES;280 let bond = balance_unit::<T>();281282 register_validators::<T>(c);283 register_candidates::<T>(c);284285 let leaving = <Candidates<T>>::get().last().unwrap().clone();286 whitelist!(leaving);287 }: _(RawOrigin::Signed(leaving.clone()))288 verify {289 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());290 }291292 // worst case is the last candidate leaving.293 force_release_license {294 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES;295 let bond = balance_unit::<T>();296297 register_validators::<T>(c);298 register_candidates::<T>(c);299300 let leaving = <Candidates<T>>::get().last().unwrap().clone();301 whitelist!(leaving);302 let origin = T::UpdateOrigin::try_successful_origin().unwrap();303 }: {304 assert_ok!(305 <CollatorSelection<T>>::force_release_license(origin, leaving.clone())306 );307 }308 verify {309 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());310 }311312 // worst case is paying a non-existing candidate account.313 note_author {314 T::Currency::set_balance(315 &<CollatorSelection<T>>::account_id(),316 balance_unit::<T>() * 4u32.into(),317 );318 let author = account("author", 0, SEED);319 let new_block: BlockNumberFor<T>= 10u32.into();320321 frame_system::Pallet::<T>::set_block_number(new_block);322 assert!(T::Currency::balance(&author) == 0u32.into());323 }: {324 <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone())325 } verify {326 assert!(T::Currency::balance(&author) > 0u32.into());327 assert_eq!(frame_system::Pallet::<T>::block_number(), new_block);328 }329330 // worst case for new session.331 new_session {332 let r in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES;333 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES;334335 frame_system::Pallet::<T>::set_block_number(0u32.into());336337 register_validators::<T>(c);338 register_candidates::<T>(c);339340 let new_block: BlockNumberFor<T>= 1800u32.into();341 let zero_block: BlockNumberFor<T> = 0u32.into();342 let candidates = <Candidates<T>>::get();343344 let non_removals = c.saturating_sub(r);345346 for i in 0..c {347 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), zero_block);348 }349350 if non_removals > 0 {351 for i in 0..non_removals {352 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);353 }354 } else {355 for i in 0..c {356 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);357 }358 }359360 let pre_length = <Candidates<T>>::get().len();361362 frame_system::Pallet::<T>::set_block_number(new_block);363364 assert!(<Candidates<T>>::get().len() == c as usize);365 }: {366 <CollatorSelection<T> as SessionManager<_>>::new_session(0)367 } verify {368 if c > r {369 assert!(<Candidates<T>>::get().len() < pre_length);370 } else {371 assert!(<Candidates<T>>::get().len() == pre_length);372 }373 }374}375376impl_benchmark_test_suite!(377 CollatorSelection,378 crate::mock::new_test_ext(),379 crate::mock::Test,380);1// 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// Copyright (C) 2021 Parity Technologies (UK) Ltd.19// SPDX-License-Identifier: Apache-2.02021// Licensed under the Apache License, Version 2.0 (the "License");22// you may not use this file except in compliance with the License.23// You may obtain a copy of the License at24//25// http://www.apache.org/licenses/LICENSE-2.026//27// Unless required by applicable law or agreed to in writing, software28// distributed under the License is distributed on an "AS IS" BASIS,29// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.30// See the License for the specific language governing permissions and31// limitations under the License.3233//! Benchmarking setup for pallet-collator-selection3435use frame_benchmarking::v2::{36 account, benchmarks, impl_benchmark_test_suite, whitelisted_caller, BenchmarkError,37};38use frame_support::{39 assert_ok,40 traits::{41 fungible::{Inspect, Mutate},42 EnsureOrigin, Get,43 },44};45use frame_system::{pallet_prelude::*, EventRecord, RawOrigin};46use pallet_authorship::EventHandler;47use pallet_session::{self as session, SessionManager};48use parity_scale_codec::Decode;49use sp_std::prelude::*;5051use super::*;52#[allow(unused)]53use crate::{BalanceOf, Pallet as CollatorSelection};5455const SEED: u32 = 0;5657// TODO: remove if this is given in substrate commit.58macro_rules! whitelist {59 ($acc:ident) => {60 frame_benchmarking::benchmarking::add_to_whitelist(61 frame_system::Account::<T>::hashed_key_for(&$acc).into(),62 );63 };64}6566fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {67 let events = frame_system::Pallet::<T>::events();68 let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();69 // compare to the last event record70 let EventRecord { event, .. } = &events[events.len() - 1];71 assert_eq!(event, &system_event);72}7374fn create_funded_user<T: Config>(75 string: &'static str,76 n: u32,77 balance_factor: u32,78) -> T::AccountId {79 let user = account(string, n, SEED);80 let balance = balance_unit::<T>() * balance_factor.into();81 let _ = T::Currency::set_balance(&user, balance);82 user83}8485fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {86 use rand::{RngCore, SeedableRng};8788 let keys = {89 let mut keys = [0u8; 128];9091 if c > 0 {92 let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);93 rng.fill_bytes(&mut keys);94 }9596 keys97 };9899 Decode::decode(&mut &keys[..]).unwrap()100}101102fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {103 (create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))104}105106fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {107 let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();108109 for (who, keys) in validators.clone() {110 <session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();111 }112113 validators.into_iter().map(|(who, _)| who).collect()114}115116fn register_invulnerables<T: Config>(count: u32) {117 let candidates = (0..count)118 .map(|c| account("candidate", c, SEED))119 .collect::<Vec<_>>();120121 for who in candidates {122 <CollatorSelection<T>>::add_invulnerable(123 T::UpdateOrigin::try_successful_origin().unwrap(),124 who,125 )126 .unwrap();127 }128}129130fn register_candidates<T: Config>(count: u32) {131 let candidates = (0..count)132 .map(|c| account("candidate", c, SEED))133 .collect::<Vec<_>>();134 assert!(T::LicenseBond::get() > 0u32.into(), "Bond cannot be zero!");135136 for who in candidates {137 T::Currency::set_balance(&who, T::LicenseBond::get() * 2u32.into());138 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();139 <CollatorSelection<T>>::onboard(RawOrigin::Signed(who).into()).unwrap();140 }141}142143fn get_licenses<T: Config>(count: u32) {144 let candidates = (0..count)145 .map(|c| account("candidate", c, SEED))146 .collect::<Vec<_>>();147 assert!(T::LicenseBond::get() > 0u32.into(), "Bond cannot be zero!");148149 for who in candidates {150 T::Currency::set_balance(&who, T::LicenseBond::get() * 2u32.into());151 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();152 }153}154155/// `Currency::minimum_balance` was used originally, but in unique-chain, we have156/// zero existential deposit, thus triggering zero bond assertion.157fn balance_unit<T: Config>() -> BalanceOf<T> {158 T::LicenseBond::get()159}160161/// Our benchmarking environment already has invulnerables registered.162const INITIAL_INVULNERABLES: u32 = 2;163164#[benchmarks(where T: Config + pallet_authorship::Config + session::Config)]165mod benchmarks {166 use super::*;167 const MAX_COLLATORS: u32 = 10;168 const MAX_INVULNERABLES: u32 = MAX_COLLATORS - INITIAL_INVULNERABLES;169170 // todo:collator this and all the following do not work for some reason, going all the way up to 10 in length171 // Both invulnerables and candidates count together against MaxCollators.172 // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)173 #[benchmark]174 fn add_invulnerable<T>(b: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {175 let b = b - 1;176 register_validators::<T>(b);177 register_invulnerables::<T>(b);178179 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);180181 let new_invulnerable: T::AccountId = whitelisted_caller();182 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();183 <T as Config>::Currency::set_balance(&new_invulnerable, bond);184185 <session::Pallet<T>>::set_keys(186 RawOrigin::Signed(new_invulnerable.clone()).into(),187 keys::<T>(b + 1),188 Vec::new(),189 )190 .unwrap();191192 let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();193194 #[block]195 {196 assert_ok!(<CollatorSelection<T>>::add_invulnerable(197 root_origin,198 new_invulnerable.clone()199 ));200 }201202 assert_last_event::<T>(203 Event::InvulnerableAdded {204 invulnerable: new_invulnerable,205 }206 .into(),207 );208209 Ok(())210 }211212 #[benchmark]213 fn remove_invulnerable(b: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {214 register_validators::<T>(b);215 register_invulnerables::<T>(b);216217 let root_origin = T::UpdateOrigin::try_successful_origin().unwrap();218 let leaving = <Invulnerables<T>>::get().last().unwrap().clone();219 whitelist!(leaving);220221 #[block]222 {223 assert_ok!(<CollatorSelection<T>>::remove_invulnerable(224 root_origin,225 leaving.clone()226 ));227 }228229 assert_last_event::<T>(230 Event::InvulnerableRemoved {231 invulnerable: leaving,232 }233 .into(),234 );235236 Ok(())237 }238239 #[benchmark]240 fn get_license(c: Linear<1, MAX_COLLATORS>) -> Result<(), BenchmarkError> {241 register_validators::<T>(c);242 get_licenses::<T>(c);243244 let caller: T::AccountId = whitelisted_caller();245 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();246 T::Currency::set_balance(&caller, bond);247248 <session::Pallet<T>>::set_keys(249 RawOrigin::Signed(caller.clone()).into(),250 keys::<T>(c + 1),251 Vec::new(),252 )253 .unwrap();254255 #[extrinsic_call]256 _(RawOrigin::Signed(caller.clone()));257258 assert_last_event::<T>(259 Event::LicenseObtained {260 account_id: caller,261 deposit: bond / 2u32.into(),262 }263 .into(),264 );265266 Ok(())267 }268269 // worst case is when we have all the max-candidate slots filled except one, and we fill that270 // one.271 #[benchmark]272 fn onboard(c: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {273 let c = c - 1;274 register_validators::<T>(c);275 register_candidates::<T>(c);276277 let caller: T::AccountId = whitelisted_caller();278 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();279 T::Currency::set_balance(&caller, bond);280281 let origin = RawOrigin::Signed(caller.clone());282283 <session::Pallet<T>>::set_keys(origin.clone().into(), keys::<T>(c + 1), Vec::new())284 .unwrap();285286 assert_ok!(<CollatorSelection<T>>::get_license(origin.clone().into()));287288 #[extrinsic_call]289 _(origin);290291 assert_last_event::<T>(Event::CandidateAdded { account_id: caller }.into());292293 Ok(())294 }295296 // worst case is the last candidate leaving.297 #[benchmark]298 fn offboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {299 register_validators::<T>(c);300 register_candidates::<T>(c);301302 let leaving = <Candidates<T>>::get().last().unwrap().clone();303 whitelist!(leaving);304305 #[extrinsic_call]306 _(RawOrigin::Signed(leaving.clone()));307308 assert_last_event::<T>(309 Event::CandidateRemoved {310 account_id: leaving,311 }312 .into(),313 );314315 Ok(())316 }317318 // worst case is the last candidate leaving.319 #[benchmark]320 fn release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {321 let bond = balance_unit::<T>();322323 register_validators::<T>(c);324 register_candidates::<T>(c);325326 let leaving = <Candidates<T>>::get().last().unwrap().clone();327 whitelist!(leaving);328329 #[extrinsic_call]330 _(RawOrigin::Signed(leaving.clone()));331332 assert_last_event::<T>(333 Event::LicenseReleased {334 account_id: leaving,335 deposit_returned: bond,336 }337 .into(),338 );339340 Ok(())341 }342343 // worst case is the last candidate leaving.344 #[benchmark]345 fn force_release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {346 let bond = balance_unit::<T>();347348 register_validators::<T>(c);349 register_candidates::<T>(c);350351 let leaving = <Candidates<T>>::get().last().unwrap().clone();352 whitelist!(leaving);353 let origin = T::UpdateOrigin::try_successful_origin().unwrap();354355 #[block]356 {357 assert_ok!(<CollatorSelection<T>>::force_release_license(358 origin,359 leaving.clone()360 ));361 }362363 assert_last_event::<T>(364 Event::LicenseReleased {365 account_id: leaving,366 deposit_returned: bond,367 }368 .into(),369 );370371 Ok(())372 }373374 // worst case is paying a non-existing candidate account.375 #[benchmark]376 fn note_author() -> Result<(), BenchmarkError> {377 T::Currency::set_balance(378 &<CollatorSelection<T>>::account_id(),379 balance_unit::<T>() * 4u32.into(),380 );381 let author = account("author", 0, SEED);382 let new_block: BlockNumberFor<T> = 10u32.into();383384 frame_system::Pallet::<T>::set_block_number(new_block);385 assert!(T::Currency::balance(&author) == 0u32.into());386387 #[block]388 {389 <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone());390 }391392 assert!(T::Currency::balance(&author) > 0u32.into());393 assert_eq!(frame_system::Pallet::<T>::block_number(), new_block);394395 Ok(())396 }397398 // worst case for new session.399 #[benchmark]400 fn new_session(401 r: Linear<1, MAX_INVULNERABLES>,402 c: Linear<1, MAX_INVULNERABLES>,403 ) -> Result<(), BenchmarkError> {404 frame_system::Pallet::<T>::set_block_number(0u32.into());405406 register_validators::<T>(c);407 register_candidates::<T>(c);408409 let new_block: BlockNumberFor<T> = 1800u32.into();410 let zero_block: BlockNumberFor<T> = 0u32.into();411 let candidates = <Candidates<T>>::get();412413 let non_removals = c.saturating_sub(r);414415 for i in 0..c {416 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), zero_block);417 }418419 if non_removals > 0 {420 for i in 0..non_removals {421 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);422 }423 } else {424 for i in 0..c {425 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);426 }427 }428429 let pre_length = <Candidates<T>>::get().len();430431 frame_system::Pallet::<T>::set_block_number(new_block);432433 assert!(<Candidates<T>>::get().len() == c as usize);434435 #[block]436 {437 <CollatorSelection<T> as SessionManager<_>>::new_session(0);438 }439440 if c > r {441 assert!(<Candidates<T>>::get().len() < pre_length);442 } else {443 assert!(<Candidates<T>>::get().len() == pre_length);444 }445446 Ok(())447 }448449 impl_benchmark_test_suite!(450 CollatorSelection,451 crate::mock::new_test_ext(),452 crate::mock::Test,453 );454}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.rsdiffbeforeafterboth--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -37,11 +37,8 @@
#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::no_effect)]
-use frame_benchmarking::{account, benchmarks, whitelisted_caller};
-use frame_support::{
- assert_ok, ensure,
- traits::{EnsureOrigin, Get},
-};
+use frame_benchmarking::v2::*;
+use frame_support::{assert_ok, ensure, traits::EnsureOrigin};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
@@ -145,25 +142,48 @@
200u32.into()
}
-benchmarks! {
- add_registrar {
- let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
- ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
+#[benchmarks]
+mod benchmarks {
+ use super::*;
+
+ const MAX_REGISTRARS: u32 = 20;
+ const MAX_ADDITIONAL_FIELDS: u32 = 100;
+ const MAX_SUB_ACCOUNTS: u32 = 100;
+
+ #[benchmark]
+ fn add_registrar(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {
+ let r = r - 1;
+ add_registrars::<T>(r)?;
+ ensure!(
+ Registrars::<T>::get().len() as u32 == r,
+ "Registrars not set up correctly."
+ );
let origin = T::RegistrarOrigin::try_successful_origin().unwrap();
let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));
- }: _<T::RuntimeOrigin>(origin, account)
- verify {
- ensure!(Registrars::<T>::get().len() as u32 == r + 1, "Registrars not added.");
+
+ #[extrinsic_call]
+ _(origin as T::RuntimeOrigin, account);
+
+ ensure!(
+ Registrars::<T>::get().len() as u32 == r + 1,
+ "Registrars not added."
+ );
+
+ Ok(())
}
- set_identity {
- let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
- let x in 0 .. T::MaxAdditionalFields::get();
+ #[benchmark]
+ fn set_identity(
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ r: Linear<1, MAX_REGISTRARS>,
+ ) -> Result<(), BenchmarkError> {
+ add_registrars::<T>(r)?;
let caller = {
// The target user
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
- let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
+ let caller_origin: <T as frame_system::Config>::RuntimeOrigin =
+ RawOrigin::Signed(caller.clone()).into();
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// Add an initial identity
@@ -173,8 +193,7 @@
// User requests judgement from all the registrars, and they approve
for i in 0..r {
let registrar: T::AccountId = account("registrar", i, SEED);
- let registrar_lookup = T::Lookup::unlookup(registrar.clone());
- let balance_to_use = balance_unit::<T>() * 10u32.into();
+ let balance_to_use = balance_unit::<T>() * 10u32.into();
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
@@ -188,66 +207,91 @@
}
caller
};
- }: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::<T>(x)))
- verify {
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller.clone()),
+ Box::new(create_identity_info::<T>(x)),
+ );
+
assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into());
+
+ Ok(())
}
// We need to split `set_subs` into two benchmarks to accurately isolate the potential
// writes caused by new or old sub accounts. The actual weight should simply be
// the sum of these two weights.
- set_subs_new {
+ #[benchmark]
+ fn set_subs_new(s: Linear<0, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
// Create a new subs vec with s sub accounts
- let s in 0 .. T::MaxSubAccounts::get() => ();
let subs = create_sub_accounts::<T>(&caller, s)?;
- ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Caller already has subs");
- }: set_subs(RawOrigin::Signed(caller.clone()), subs)
- verify {
- ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s, "Subs not added");
+ ensure!(
+ SubsOf::<T>::get(&caller).1.len() == 0,
+ "Caller already has subs"
+ );
+
+ #[extrinsic_call]
+ set_subs(RawOrigin::Signed(caller.clone()), subs);
+
+ ensure!(
+ SubsOf::<T>::get(&caller).1.len() as u32 == s,
+ "Subs not added"
+ );
+
+ Ok(())
}
- set_subs_old {
+ #[benchmark]
+ fn set_subs_old(p: Linear<0, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
// Give them p many previous sub accounts.
- let p in 0 .. T::MaxSubAccounts::get() => {
- let _ = add_sub_accounts::<T>(&caller, p)?;
- };
+ let _ = add_sub_accounts::<T>(&caller, p)?;
// Remove all subs.
let subs = create_sub_accounts::<T>(&caller, 0)?;
ensure!(
SubsOf::<T>::get(&caller).1.len() as u32 == p,
"Caller does have subs",
);
- }: set_subs(RawOrigin::Signed(caller.clone()), subs)
- verify {
+
+ #[extrinsic_call]
+ set_subs(RawOrigin::Signed(caller.clone()), subs);
+
ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Subs not removed");
+
+ Ok(())
}
- clear_identity {
+ #[benchmark]
+ fn clear_identity(
+ r: Linear<1, MAX_REGISTRARS>,
+ s: Linear<0, MAX_SUB_ACCOUNTS>,
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ ) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
- let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
- let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
- let s in 0 .. T::MaxSubAccounts::get() => {
+ add_registrars::<T>(r)?;
+
+ {
// Give them s many sub accounts
let caller: T::AccountId = whitelisted_caller();
let _ = add_sub_accounts::<T>(&caller, s)?;
- };
- let x in 0 .. T::MaxAdditionalFields::get();
+ }
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
- let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
+ let caller_origin =
+ <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?;
// User requests judgement from all the registrars, and they approve
for i in 0..r {
let registrar: T::AccountId = account("registrar", i, SEED);
- let balance_to_use = balance_unit::<T>() * 10u32.into();
+ let balance_to_use = balance_unit::<T>() * 10u32.into();
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
@@ -259,108 +303,199 @@
T::Hashing::hash_of(&info),
)?;
}
- ensure!(IdentityOf::<T>::contains_key(&caller), "Identity does not exist.");
- }: _(RawOrigin::Signed(caller.clone()))
- verify {
- ensure!(!IdentityOf::<T>::contains_key(&caller), "Identity not cleared.");
+ ensure!(
+ IdentityOf::<T>::contains_key(&caller),
+ "Identity does not exist."
+ );
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller.clone()));
+
+ ensure!(
+ !IdentityOf::<T>::contains_key(&caller),
+ "Identity not cleared."
+ );
+
+ Ok(())
}
- request_judgement {
+ #[benchmark]
+ fn request_judgement(
+ r: Linear<1, MAX_REGISTRARS>,
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ ) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
- let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
- let x in 0 .. T::MaxAdditionalFields::get() => {
+ add_registrars::<T>(r)?;
+
+ {
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
- let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
+ let caller_origin =
+ <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, Box::new(info))?;
- };
- }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into())
- verify {
- assert_last_event::<T>(Event::<T>::JudgementRequested { who: caller, registrar_index: r-1 }.into());
+ }
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into());
+
+ assert_last_event::<T>(
+ Event::<T>::JudgementRequested {
+ who: caller,
+ registrar_index: r - 1,
+ }
+ .into(),
+ );
+
+ Ok(())
}
- cancel_request {
+ #[benchmark]
+ fn cancel_request(
+ r: Linear<1, MAX_REGISTRARS>,
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ ) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
- let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
+ let caller_origin =
+ <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
- let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
- let x in 0 .. T::MaxAdditionalFields::get() => {
+ add_registrars::<T>(r)?;
+
+ {
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
- let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
+ let caller_origin =
+ <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, Box::new(info))?;
- };
+ }
Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?;
- }: _(RawOrigin::Signed(caller.clone()), r - 1)
- verify {
- assert_last_event::<T>(Event::<T>::JudgementUnrequested { who: caller, registrar_index: r-1 }.into());
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller.clone()), r - 1);
+
+ assert_last_event::<T>(
+ Event::<T>::JudgementUnrequested {
+ who: caller,
+ registrar_index: r - 1,
+ }
+ .into(),
+ );
+
+ Ok(())
}
- set_fee {
+ #[benchmark]
+ fn set_fee(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {
+ let r = r - 1;
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
- let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+ add_registrars::<T>(r)?;
let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
let registrars = Registrars::<T>::get();
- ensure!(registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), "Fee already set.");
- }: _(RawOrigin::Signed(caller), r, 100u32.into())
- verify {
+ ensure!(
+ registrars[r as usize].as_ref().unwrap().fee == 0u32.into(),
+ "Fee already set."
+ );
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller), r, 100u32.into());
+
let registrars = Registrars::<T>::get();
- ensure!(registrars[r as usize].as_ref().unwrap().fee == 100u32.into(), "Fee not changed.");
+ ensure!(
+ registrars[r as usize].as_ref().unwrap().fee == 100u32.into(),
+ "Fee not changed."
+ );
+
+ Ok(())
}
- set_account_id {
+ #[benchmark]
+ fn set_account_id(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {
+ let r = r - 1;
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
- let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+ add_registrars::<T>(r)?;
let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
let registrars = Registrars::<T>::get();
- ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set.");
+ ensure!(
+ registrars[r as usize].as_ref().unwrap().account == caller,
+ "id not set."
+ );
let new_account = T::Lookup::unlookup(account("new", 0, SEED));
- }: _(RawOrigin::Signed(caller), r, new_account)
- verify {
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller), r, new_account);
+
let registrars = Registrars::<T>::get();
- ensure!(registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), "id not changed.");
+ ensure!(
+ registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED),
+ "id not changed."
+ );
+
+ Ok(())
}
- set_fields {
+ #[benchmark]
+ fn set_fields(r: Linear<2, MAX_REGISTRARS>) -> Result<(), BenchmarkError> {
+ let r = r - 1;
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
- let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
+ add_registrars::<T>(r)?;
let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
let fields = IdentityFields(
- IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot
- | IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter
+ IdentityField::Display
+ | IdentityField::Legal
+ | IdentityField::Web
+ | IdentityField::Riot
+ | IdentityField::Email
+ | IdentityField::PgpFingerprint
+ | IdentityField::Image
+ | IdentityField::Twitter,
);
let registrars = Registrars::<T>::get();
- ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set.");
- }: _(RawOrigin::Signed(caller), r, fields)
- verify {
+ ensure!(
+ registrars[r as usize].as_ref().unwrap().fields == Default::default(),
+ "fields already set."
+ );
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller), r, fields);
+
let registrars = Registrars::<T>::get();
- ensure!(registrars[r as usize].as_ref().unwrap().fields != Default::default(), "fields not set.");
+ ensure!(
+ registrars[r as usize].as_ref().unwrap().fields != Default::default(),
+ "fields not set."
+ );
+
+ Ok(())
}
- provide_judgement {
+ #[benchmark]
+ fn provide_judgement(
+ r: Linear<2, MAX_REGISTRARS>,
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ ) -> Result<(), BenchmarkError> {
+ let r = r - 1;
// The user
let user: T::AccountId = account("user", r, SEED);
- let user_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));
+ let user_origin =
+ <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));
let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());
let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());
@@ -368,8 +503,7 @@
let caller_lookup = T::Lookup::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
- let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
- let x in 0 .. T::MaxAdditionalFields::get();
+ add_registrars::<T>(r)?;
let info = create_identity_info::<T>(x);
let info_hash = T::Hashing::hash_of(&info);
@@ -378,18 +512,38 @@
let registrar_origin = T::RegistrarOrigin::try_successful_origin().unwrap();
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
Identity::<T>::request_judgement(user_origin, r, 10u32.into())?;
- }: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable, info_hash)
- verify {
- assert_last_event::<T>(Event::<T>::JudgementGiven { target: user, registrar_index: r }.into())
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller),
+ r,
+ user_lookup,
+ Judgement::Reasonable,
+ info_hash,
+ );
+
+ assert_last_event::<T>(
+ Event::<T>::JudgementGiven {
+ target: user,
+ registrar_index: r,
+ }
+ .into(),
+ );
+
+ Ok(())
}
- kill_identity {
- let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
- let s in 0 .. T::MaxSubAccounts::get();
- let x in 0 .. T::MaxAdditionalFields::get();
+ #[benchmark]
+ fn kill_identity(
+ r: Linear<1, MAX_REGISTRARS>,
+ s: Linear<0, MAX_SUB_ACCOUNTS>,
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ ) -> Result<(), BenchmarkError> {
+ add_registrars::<T>(r)?;
let target: T::AccountId = account("target", 0, SEED);
- let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into();
+ let target_origin: <T as frame_system::Config>::RuntimeOrigin =
+ RawOrigin::Signed(target.clone()).into();
let target_lookup = T::Lookup::unlookup(target.clone());
let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());
@@ -400,7 +554,7 @@
// User requests judgement from all the registrars, and they approve
for i in 0..r {
let registrar: T::AccountId = account("registrar", i, SEED);
- let balance_to_use = balance_unit::<T>() * 10u32.into();
+ let balance_to_use = balance_unit::<T>() * 10u32.into();
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
Identity::<T>::request_judgement(target_origin.clone(), i, 10u32.into())?;
@@ -414,110 +568,190 @@
}
ensure!(IdentityOf::<T>::contains_key(&target), "Identity not set");
let origin = T::ForceOrigin::try_successful_origin().unwrap();
- }: _<T::RuntimeOrigin>(origin, target_lookup)
- verify {
- ensure!(!IdentityOf::<T>::contains_key(&target), "Identity not removed");
+
+ #[extrinsic_call]
+ _(origin as T::RuntimeOrigin, target_lookup);
+
+ ensure!(
+ !IdentityOf::<T>::contains_key(&target),
+ "Identity not removed"
+ );
+
+ Ok(())
}
- force_insert_identities {
- let x in 0 .. T::MaxAdditionalFields::get();
- let n in 0..600;
+ #[benchmark]
+ fn force_insert_identities(
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ n: Linear<0, 600>,
+ ) -> Result<(), BenchmarkError> {
use frame_benchmarking::account;
- let identities = (0..n).map(|i| (
- account("caller", i, SEED),
- Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
- judgements: Default::default(),
- deposit: Default::default(),
- info: create_identity_info::<T>(x),
- },
- )).collect::<Vec<_>>();
+ let identities = (0..n)
+ .map(|i| {
+ (
+ account("caller", i, SEED),
+ Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
+ judgements: Default::default(),
+ deposit: Default::default(),
+ info: create_identity_info::<T>(x),
+ },
+ )
+ })
+ .collect::<Vec<_>>();
let origin = T::ForceOrigin::try_successful_origin().unwrap();
- }: _<T::RuntimeOrigin>(origin, identities)
- force_remove_identities {
- let x in 0 .. T::MaxAdditionalFields::get();
- let n in 0..600;
+ #[extrinsic_call]
+ _(origin as T::RuntimeOrigin, identities);
+
+ Ok(())
+ }
+
+ #[benchmark]
+ fn force_remove_identities(
+ x: Linear<0, MAX_ADDITIONAL_FIELDS>,
+ n: Linear<0, 600>,
+ ) -> Result<(), BenchmarkError> {
use frame_benchmarking::account;
let origin = T::ForceOrigin::try_successful_origin().unwrap();
- let identities = (0..n).map(|i| (
- account("caller", i, SEED),
- Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
- judgements: Default::default(),
- deposit: Default::default(),
- info: create_identity_info::<T>(x),
- },
- )).collect::<Vec<_>>();
- assert_ok!(
- Identity::<T>::force_insert_identities(origin.clone(), identities.clone()),
- );
- let identities = identities.into_iter().map(|(acc, _)| acc).collect::<Vec<_>>();
- }: _<T::RuntimeOrigin>(origin, identities)
+ let identities = (0..n)
+ .map(|i| {
+ (
+ account("caller", i, SEED),
+ Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
+ judgements: Default::default(),
+ deposit: Default::default(),
+ info: create_identity_info::<T>(x),
+ },
+ )
+ })
+ .collect::<Vec<_>>();
+ assert_ok!(Identity::<T>::force_insert_identities(
+ origin.clone(),
+ identities.clone()
+ ),);
+ let identities = identities
+ .into_iter()
+ .map(|(acc, _)| acc)
+ .collect::<Vec<_>>();
- force_set_subs {
- let s in 0 .. T::MaxSubAccounts::get();
- let n in 0..600;
+ #[extrinsic_call]
+ _(origin as T::RuntimeOrigin, identities);
+
+ Ok(())
+ }
+
+ #[benchmark]
+ fn force_set_subs(
+ s: Linear<0, MAX_SUB_ACCOUNTS>,
+ n: Linear<0, 600>,
+ ) -> Result<(), BenchmarkError> {
use frame_benchmarking::account;
- let identities = (0..n).map(|i| {
- let caller: T::AccountId = account("caller", i, SEED);
- (
- caller.clone(),
+ let identities = (0..n)
+ .map(|i| {
+ let caller: T::AccountId = account("caller", i, SEED);
(
- BalanceOf::<T>::max_value(),
- create_sub_accounts::<T>(&caller, s).unwrap().try_into().unwrap(),
- ),
- )
- }).collect::<Vec<_>>();
+ caller.clone(),
+ (
+ BalanceOf::<T>::max_value(),
+ create_sub_accounts::<T>(&caller, s)
+ .unwrap()
+ .try_into()
+ .unwrap(),
+ ),
+ )
+ })
+ .collect::<Vec<_>>();
let origin = T::ForceOrigin::try_successful_origin().unwrap();
- }: _<T::RuntimeOrigin>(origin, identities)
- add_sub {
- let s in 0 .. T::MaxSubAccounts::get() - 1;
+ #[extrinsic_call]
+ _(origin as T::RuntimeOrigin, identities);
+ Ok(())
+ }
+
+ #[benchmark]
+ fn add_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {
+ let s = s - 1;
let caller: T::AccountId = whitelisted_caller();
let _ = add_sub_accounts::<T>(&caller, s)?;
let sub = account("new_sub", 0, SEED);
let data = Data::Raw(vec![0; 32].try_into().unwrap());
- ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s, "Subs not set.");
- }: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(sub), data)
- verify {
- ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s + 1, "Subs not added.");
- }
+ ensure!(
+ SubsOf::<T>::get(&caller).1.len() as u32 == s,
+ "Subs not set."
+ );
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller.clone()),
+ T::Lookup::unlookup(sub),
+ data,
+ );
+
+ ensure!(
+ SubsOf::<T>::get(&caller).1.len() as u32 == s + 1,
+ "Subs not added."
+ );
- rename_sub {
- let s in 1 .. T::MaxSubAccounts::get();
+ Ok(())
+ }
+ #[benchmark]
+ fn rename_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);
let data = Data::Raw(vec![1; 32].try_into().unwrap());
- ensure!(SuperOf::<T>::get(&sub).unwrap().1 != data, "data already set");
- }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone())
- verify {
+ ensure!(
+ SuperOf::<T>::get(&sub).unwrap().1 != data,
+ "data already set"
+ );
+
+ #[extrinsic_call]
+ _(
+ RawOrigin::Signed(caller),
+ T::Lookup::unlookup(sub.clone()),
+ data.clone(),
+ );
+
ensure!(SuperOf::<T>::get(&sub).unwrap().1 == data, "data not set");
- }
- remove_sub {
- let s in 1 .. T::MaxSubAccounts::get();
+ Ok(())
+ }
+ #[benchmark]
+ fn remove_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);
ensure!(SuperOf::<T>::contains_key(&sub), "Sub doesn't exists");
- }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()))
- verify {
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()));
+
ensure!(!SuperOf::<T>::contains_key(&sub), "Sub not removed");
+
+ Ok(())
}
- quit_sub {
- let s in 0 .. T::MaxSubAccounts::get() - 1;
-
+ #[benchmark]
+ fn quit_sub(s: Linear<1, MAX_SUB_ACCOUNTS>) -> Result<(), BenchmarkError> {
+ let s = s - 1;
let caller: T::AccountId = whitelisted_caller();
let sup = account("super", 0, SEED);
let _ = add_sub_accounts::<T>(&sup, s)?;
let sup_origin = RawOrigin::Signed(sup).into();
- Identity::<T>::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32].try_into().unwrap()))?;
+ Identity::<T>::add_sub(
+ sup_origin,
+ T::Lookup::unlookup(caller.clone()),
+ Data::Raw(vec![0; 32].try_into().unwrap()),
+ )?;
ensure!(SuperOf::<T>::contains_key(&caller), "Sub doesn't exists");
- }: _(RawOrigin::Signed(caller.clone()))
- verify {
+
+ #[extrinsic_call]
+ _(RawOrigin::Signed(caller.clone()));
+
ensure!(!SuperOf::<T>::contains_key(&caller), "Sub not removed");
+
+ Ok(())
}
impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test);
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;