difftreelog
fix benchmarks
in: master
6 files changed
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")]
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.
pallets/app-promotion/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#![cfg(feature = "runtime-benchmarks")]1819use frame_benchmarking::v2::*;20use frame_support::traits::{21 fungible::{Inspect, Mutate, Unbalanced},22 OnInitialize,23};24use frame_system::{pallet_prelude::*, RawOrigin};25use pallet_evm::account::CrossAccountId;26use pallet_evm_migration::Pallet as EvmMigrationPallet;27use pallet_unique::benchmarking::create_nft_collection;28use sp_core::{Get, H160};29use sp_runtime::{30 traits::{BlockNumberProvider, Bounded},31 Perbill,32};33use sp_std::{iter::Sum, vec, vec::Vec};3435use super::{BalanceOf, Call, Config, Pallet, Staked, PENDING_LIMIT_PER_BLOCK};36use crate::{pallet, Pallet as PromototionPallet};3738const SEED: u32 = 0;3940fn set_admin<T>() -> Result<T::AccountId, sp_runtime::DispatchError>41where42 T: Config + pallet_unique::Config + pallet_evm_migration::Config,43 BlockNumberFor<T>: From<u32> + Into<u32>,44 BalanceOf<T>: Sum + From<u128>,45{46 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);4748 <T as Config>::Currency::set_balance(49 &pallet_admin,50 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),51 );5253 PromototionPallet::<T>::set_admin_address(54 RawOrigin::Root.into(),55 T::CrossAccountId::from_sub(pallet_admin.clone()),56 )?;5758 Ok(pallet_admin)59}6061#[benchmarks(62 where T: Config + pallet_unique::Config + pallet_evm_migration::Config ,63 BlockNumberFor<T>: From<u32> + Into<u32>,64 BalanceOf<T>: Sum + From<u128>65)]66mod benchmarks {67 use super::*;6869 #[benchmark]70 fn on_initialize(b: Linear<0, PENDING_LIMIT_PER_BLOCK>) -> Result<(), BenchmarkError> {71 set_admin::<T>()?;7273 (0..b).try_for_each(|index| {74 let staker = account::<T::AccountId>("staker", index, SEED);75 <T as Config>::Currency::write_balance(76 &staker,77 Into::<BalanceOf<T>>::into(10_000u128) * T::Nominal::get(),78 )?;79 PromototionPallet::<T>::stake(80 RawOrigin::Signed(staker.clone()).into(),81 Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get(),82 )?;83 PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker).into())?;84 Result::<(), sp_runtime::DispatchError>::Ok(())85 })?;86 let block_number =87 <frame_system::Pallet<T>>::current_block_number() + T::PendingInterval::get();8889 #[block]90 {91 PromototionPallet::<T>::on_initialize(block_number);92 }9394 Ok(())95 }9697 #[benchmark]98 fn set_admin_address() -> Result<(), BenchmarkError> {99 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);100 let _ = <T as Config>::Currency::set_balance(101 &pallet_admin,102 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),103 );104105 #[extrinsic_call]106 _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin));107108 Ok(())109 }110111 #[benchmark]112 fn payout_stakers(b: Linear<0, 100>) -> Result<(), BenchmarkError> {113 let pallet_admin = account::<T::AccountId>("admin", 1, SEED);114 PromototionPallet::<T>::set_admin_address(115 RawOrigin::Root.into(),116 T::CrossAccountId::from_sub(pallet_admin.clone()),117 )?;118 <T as Config>::Currency::write_balance(119 &pallet_admin,120 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),121 )?;122 <T as Config>::Currency::write_balance(123 &<T as pallet::Config>::TreasuryAccountId::get(),124 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),125 )?;126127 let stakers: Vec<T::AccountId> =128 (0..b).map(|index| account("staker", index, SEED)).collect();129 stakers.iter().try_for_each(|staker| {130 <T as Config>::Currency::write_balance(131 staker,132 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),133 )?;134 Result::<(), sp_runtime::DispatchError>::Ok(())135 })?;136 (1..11).try_for_each(|i| {137 <frame_system::Pallet<T>>::set_block_number(i.into());138 T::RelayBlockNumberProvider::set_block_number((2 * i).into());139 assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());140 assert_eq!(141 T::RelayBlockNumberProvider::current_block_number(),142 (2 * i).into()143 );144 stakers145 .iter()146 .map(|staker| {147 PromototionPallet::<T>::stake(148 RawOrigin::Signed(staker.clone()).into(),149 Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get(),150 )151 })152 .collect::<Result<Vec<_>, _>>()?;153154 Result::<(), sp_runtime::DispatchError>::Ok(())155 })?;156157 let stakes = Staked::<T>::iter_prefix((&stakers[0],)).collect::<Vec<_>>();158 assert_eq!(stakes.len(), 10);159160 <frame_system::Pallet<T>>::set_block_number(15_000.into());161 T::RelayBlockNumberProvider::set_block_number(30_000.into());162163 #[extrinsic_call]164 _(RawOrigin::Signed(pallet_admin.clone()), Some(b as u8));165166 Ok(())167 }168169 #[benchmark]170 fn stake() -> Result<(), BenchmarkError> {171 let caller = account::<T::AccountId>("caller", 0, SEED);172 let share = Perbill::from_rational(1u32, 10);173174 let _ = <T as Config>::Currency::write_balance(175 &caller,176 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),177 );178179 #[extrinsic_call]180 _(181 RawOrigin::Signed(caller.clone()),182 share * <T as Config>::Currency::total_balance(&caller),183 );184185 Ok(())186 }187188 #[benchmark]189 fn unstake_all() -> Result<(), BenchmarkError> {190 let caller = account::<T::AccountId>("caller", 0, SEED);191 let share = Perbill::from_rational(1u32, 20);192 let _ = <T as Config>::Currency::write_balance(193 &caller,194 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),195 );196 (1..11)197 .map(|i| {198 // used to change block number199 <frame_system::Pallet<T>>::set_block_number(i.into());200 T::RelayBlockNumberProvider::set_block_number((2 * i).into());201 assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());202 assert_eq!(203 T::RelayBlockNumberProvider::current_block_number(),204 (2 * i).into()205 );206 PromototionPallet::<T>::stake(207 RawOrigin::Signed(caller.clone()).into(),208 share * <T as Config>::Currency::total_balance(&caller),209 )210 })211 .collect::<Result<Vec<_>, _>>()?;212213 #[extrinsic_call]214 _(RawOrigin::Signed(caller.clone()));215216 Ok(())217 }218219 #[benchmark]220 fn unstake_partial() -> Result<(), BenchmarkError> {221 let caller = account::<T::AccountId>("caller", 0, SEED);222 let _ = <T as Config>::Currency::write_balance(223 &caller,224 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),225 );226 (1..11)227 .map(|i| {228 // used to change block number229 <frame_system::Pallet<T>>::set_block_number(i.into());230 T::RelayBlockNumberProvider::set_block_number((2 * i).into());231 assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());232 assert_eq!(233 T::RelayBlockNumberProvider::current_block_number(),234 (2 * i).into()235 );236 PromototionPallet::<T>::stake(237 RawOrigin::Signed(caller.clone()).into(),238 Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get(),239 )240 })241 .collect::<Result<Vec<_>, _>>()?;242243 #[extrinsic_call]244 _(245 RawOrigin::Signed(caller.clone()),246 Into::<BalanceOf<T>>::into(1000u128) * T::Nominal::get(),247 );248249 Ok(())250 }251252 #[benchmark]253 fn sponsor_collection() -> Result<(), BenchmarkError> {254 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);255 PromototionPallet::<T>::set_admin_address(256 RawOrigin::Root.into(),257 T::CrossAccountId::from_sub(pallet_admin.clone()),258 )?;259 let _ = <T as Config>::Currency::write_balance(260 &pallet_admin,261 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),262 );263 let caller: T::AccountId = account("caller", 0, SEED);264 let _ = <T as Config>::Currency::write_balance(265 &caller,266 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),267 );268 let collection = create_nft_collection::<T>(caller)?;269270 #[extrinsic_call]271 _(RawOrigin::Signed(pallet_admin.clone()), collection);272273 Ok(())274 }275276 #[benchmark]277 fn stop_sponsoring_collection() -> Result<(), BenchmarkError> {278 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);279 PromototionPallet::<T>::set_admin_address(280 RawOrigin::Root.into(),281 T::CrossAccountId::from_sub(pallet_admin.clone()),282 )?;283 let _ = <T as Config>::Currency::write_balance(284 &pallet_admin,285 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),286 );287 let caller: T::AccountId = account("caller", 0, SEED);288 let _ = <T as Config>::Currency::write_balance(289 &caller,290 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),291 );292 let collection = create_nft_collection::<T>(caller)?;293 PromototionPallet::<T>::sponsor_collection(294 RawOrigin::Signed(pallet_admin.clone()).into(),295 collection,296 )?;297298 #[extrinsic_call]299 _(RawOrigin::Signed(pallet_admin.clone()), collection);300301 Ok(())302 }303304 #[benchmark]305 fn sponsor_contract() -> Result<(), BenchmarkError> {306 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);307 PromototionPallet::<T>::set_admin_address(308 RawOrigin::Root.into(),309 T::CrossAccountId::from_sub(pallet_admin.clone()),310 )?;311312 let _ = <T as Config>::Currency::write_balance(313 &pallet_admin,314 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),315 );316 let address = H160::from_low_u64_be(SEED as u64);317 let data: Vec<u8> = (0..20).collect();318 <EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;319 <EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;320321 #[extrinsic_call]322 _(RawOrigin::Signed(pallet_admin.clone()), address);323324 Ok(())325 }326327 #[benchmark]328 fn stop_sponsoring_contract() -> Result<(), BenchmarkError> {329 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);330 PromototionPallet::<T>::set_admin_address(331 RawOrigin::Root.into(),332 T::CrossAccountId::from_sub(pallet_admin.clone()),333 )?;334335 let _ = <T as Config>::Currency::write_balance(336 &pallet_admin,337 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),338 );339 let address = H160::from_low_u64_be(SEED as u64);340 let data: Vec<u8> = (0..20).collect();341 <EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;342 <EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;343 PromototionPallet::<T>::sponsor_contract(344 RawOrigin::Signed(pallet_admin.clone()).into(),345 address,346 )?;347348 #[extrinsic_call]349 _(RawOrigin::Signed(pallet_admin.clone()), address);350351 Ok(())352 }353}pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/benchmarking.rs
+++ b/pallets/collator-selection/src/benchmarking.rs
@@ -171,7 +171,8 @@
// Both invulnerables and candidates count together against MaxCollators.
// Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)
#[benchmark]
- fn add_invulnerable<T>(b: Linear<1, MAX_COLLATORS>) -> Result<(), BenchmarkError> {
+ fn add_invulnerable<T>(b: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ let b = b - 1;
register_validators::<T>(b);
register_invulnerables::<T>(b);
@@ -268,7 +269,8 @@
// worst case is when we have all the max-candidate slots filled except one, and we fill that
// one.
#[benchmark]
- fn onboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ fn onboard(c: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ let c = c - 1;
register_validators::<T>(c);
register_candidates::<T>(c);
@@ -293,9 +295,7 @@
// worst case is the last candidate leaving.
#[benchmark]
- fn offboard(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
- let c = c + 1;
-
+ fn offboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
register_validators::<T>(c);
register_candidates::<T>(c);
@@ -317,8 +317,7 @@
// worst case is the last candidate leaving.
#[benchmark]
- fn release_license(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
- let c = c + 1;
+ fn release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let bond = balance_unit::<T>();
register_validators::<T>(c);
@@ -343,8 +342,7 @@
// worst case is the last candidate leaving.
#[benchmark]
- fn force_release_license(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
- let c = c + 1;
+ fn force_release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let bond = balance_unit::<T>();
register_validators::<T>(c);
@@ -400,12 +398,9 @@
// worst case for new session.
#[benchmark]
fn new_session(
- r: Linear<0, MAX_INVULNERABLES>,
- c: Linear<0, MAX_INVULNERABLES>,
+ r: Linear<1, MAX_INVULNERABLES>,
+ c: Linear<1, MAX_INVULNERABLES>,
) -> Result<(), BenchmarkError> {
- let r = r + 1;
- let c = c + 1;
-
frame_system::Pallet::<T>::set_block_number(0u32.into());
register_validators::<T>(c);
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -17,9 +17,7 @@
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::*;
@@ -334,49 +332,51 @@
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;
- };
+ // 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);
- todo!();
- #[block]
- {
- // let mut property_writer =
- // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
+ // #[block]
+ // {
+ // let mut property_writer =
+ // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
- // property_writer.write_token_properties(
- // 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(())
}
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -490,35 +490,35 @@
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;
- };
+ // 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 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);
-
- #[block]
- {}
- todo!();
+ // 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,