git.delta.rocks / unique-network / refs/commits / 5f71c376196c

difftreelog

fix benchmarks

Grigoriy Simonov2023-10-12parent: #af2b5f4.patch.diff
in: master

6 files changed

modifiednode/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")]
modifiednode/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.
modifiedpallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -109,7 +109,7 @@
 	}
 
 	#[benchmark]
-	fn payout_stakers(b: Linear<0, 100>) -> Result<(), BenchmarkError> {
+	fn payout_stakers(b: Linear<1, 100>) -> Result<(), BenchmarkError> {
 		let pallet_admin = account::<T::AccountId>("admin", 1, SEED);
 		PromototionPallet::<T>::set_admin_address(
 			RawOrigin::Root.into(),
modifiedpallets/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);
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
before · pallets/nonfungible/src/benchmarking.rs
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/>.1617use frame_benchmarking::v2::{account, benchmarks, BenchmarkError};18use pallet_common::{19	bench_init,20	benchmarking::{21		create_collection_raw, load_is_admin_and_property_permissions, property_key, property_value,22	},23	CommonCollectionOperations,24};25use sp_std::prelude::*;26use up_data_structs::{27	budget::Unlimited, CollectionMode, PropertyPermission, MAX_ITEMS_PER_BATCH,28	MAX_PROPERTIES_PER_ITEM,29};3031use super::*;32use crate::{Config, NonfungibleHandle, Pallet};3334const SEED: u32 = 1;3536fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {37	CreateItemData::<T> {38		owner,39		properties: Default::default(),40	}41}42fn create_max_item<T: Config>(43	collection: &NonfungibleHandle<T>,44	sender: &T::CrossAccountId,45	owner: T::CrossAccountId,46) -> Result<TokenId, DispatchError> {47	<Pallet<T>>::create_item(48		collection,49		sender,50		create_max_item_data::<T>(owner),51		&Unlimited,52	)?;53	Ok(TokenId(<TokensMinted<T>>::get(collection.id)))54}5556fn create_collection<T: Config>(57	owner: T::CrossAccountId,58) -> Result<NonfungibleHandle<T>, DispatchError> {59	create_collection_raw(60		owner,61		CollectionMode::NFT,62		|owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),63		NonfungibleHandle::cast,64	)65}6667#[benchmarks]68mod benchmarks {69	use super::*;7071	#[benchmark]72	fn create_item() -> Result<(), BenchmarkError> {73		bench_init! {74			owner: sub; collection: collection(owner);75			sender: cross_from_sub(owner); to: cross_sub;76		};7778		#[block]79		{80			create_max_item(&collection, &sender, to.clone())?;81		}8283		Ok(())84	}8586	#[benchmark]87	fn create_multiple_items(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> {88		bench_init! {89			owner: sub; collection: collection(owner);90			sender: cross_from_sub(owner); to: cross_sub;91		};92		let data = (0..b)93			.map(|_| create_max_item_data::<T>(to.clone()))94			.collect();9596		#[block]97		{98			<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;99		}100101		Ok(())102	}103104	#[benchmark]105	fn create_multiple_items_ex(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> {106		bench_init! {107			owner: sub; collection: collection(owner);108			sender: cross_from_sub(owner);109		};110		let data = (0..b)111			.map(|i| {112				bench_init!(to: cross_sub(i););113				create_max_item_data::<T>(to)114			})115			.collect();116117		#[block]118		{119			<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;120		}121122		Ok(())123	}124125	#[benchmark]126	fn burn_item() -> Result<(), BenchmarkError> {127		bench_init! {128			owner: sub; collection: collection(owner);129			sender: cross_from_sub(owner); burner: cross_sub;130		};131		let item = create_max_item(&collection, &sender, burner.clone())?;132133		#[block]134		{135			<Pallet<T>>::burn(&collection, &burner, item)?;136		}137138		Ok(())139	}140141	#[benchmark]142	fn burn_recursively_self_raw() -> Result<(), BenchmarkError> {143		bench_init! {144			owner: sub; collection: collection(owner);145			sender: cross_from_sub(owner); burner: cross_sub;146		};147		let item = create_max_item(&collection, &sender, burner.clone())?;148149		#[block]150		{151			<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;152		}153154		Ok(())155	}156157	#[benchmark]158	fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(159		b: Linear<0, 200>,160	) -> Result<(), BenchmarkError> {161		bench_init! {162			owner: sub; collection: collection(owner);163			sender: cross_from_sub(owner); burner: cross_sub;164		};165		let item = create_max_item(&collection, &sender, burner.clone())?;166		for _ in 0..b {167			create_max_item(168				&collection,169				&sender,170				T::CrossTokenAddressMapping::token_to_address(collection.id, item),171			)?;172		}173174		#[block]175		{176			<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;177		}178179		Ok(())180	}181182	#[benchmark]183	fn transfer_raw() -> Result<(), BenchmarkError> {184		bench_init! {185			owner: sub; collection: collection(owner);186			owner: cross_from_sub; sender: cross_sub; receiver: cross_sub;187		};188		let item = create_max_item(&collection, &owner, sender.clone())?;189190		#[block]191		{192			<Pallet<T>>::transfer(&collection, &sender, &receiver, item, &Unlimited)?;193		}194195		Ok(())196	}197198	#[benchmark]199	fn approve() -> Result<(), BenchmarkError> {200		bench_init! {201			owner: sub; collection: collection(owner);202			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;203		};204		let item = create_max_item(&collection, &owner, sender.clone())?;205206		#[block]207		{208			<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;209		}210211		Ok(())212	}213214	#[benchmark]215	fn approve_from() -> Result<(), BenchmarkError> {216		bench_init! {217			owner: sub; collection: collection(owner);218			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;219		};220		let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());221		let item = create_max_item(&collection, &owner, owner_eth.clone())?;222223		#[block]224		{225			<Pallet<T>>::set_allowance_from(226				&collection,227				&sender,228				&owner_eth,229				item,230				Some(&spender),231			)?;232		}233234		Ok(())235	}236237	#[benchmark]238	fn check_allowed_raw() -> Result<(), BenchmarkError> {239		bench_init! {240			owner: sub; collection: collection(owner);241			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;242		};243		let item = create_max_item(&collection, &owner, sender.clone())?;244		<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;245246		#[block]247		{248			<Pallet<T>>::check_allowed(&collection, &spender, &sender, item, &Unlimited)?;249		}250251		Ok(())252	}253254	#[benchmark]255	fn burn_from() -> Result<(), BenchmarkError> {256		bench_init! {257			owner: sub; collection: collection(owner);258			owner: cross_from_sub; sender: cross_sub; burner: cross_sub;259		};260		let item = create_max_item(&collection, &owner, sender.clone())?;261		<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;262263		#[block]264		{265			<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?;266		}267268		Ok(())269	}270271	#[benchmark]272	fn set_token_property_permissions(273		b: Linear<0, MAX_PROPERTIES_PER_ITEM>,274	) -> Result<(), BenchmarkError> {275		bench_init! {276			owner: sub; collection: collection(owner);277			owner: cross_from_sub;278		};279		let perms = (0..b)280			.map(|k| PropertyKeyPermission {281				key: property_key(k as usize),282				permission: PropertyPermission {283					mutable: false,284					collection_admin: false,285					token_owner: false,286				},287			})288			.collect::<Vec<_>>();289290		#[block]291		{292			<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;293		}294295		Ok(())296	}297298	#[benchmark]299	fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {300		bench_init! {301			owner: sub; collection: collection(owner);302			owner: cross_from_sub;303		};304		let perms = (0..b)305			.map(|k| PropertyKeyPermission {306				key: property_key(k as usize),307				permission: PropertyPermission {308					mutable: false,309					collection_admin: true,310					token_owner: true,311				},312			})313			.collect::<Vec<_>>();314		<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;315		let props = (0..b)316			.map(|k| Property {317				key: property_key(k as usize),318				value: property_value(),319			})320			.collect::<Vec<_>>();321		let item = create_max_item(&collection, &owner, owner.clone())?;322323		#[block]324		{325			<Pallet<T>>::set_token_properties(326				&collection,327				&owner,328				item,329				props.into_iter(),330				&Unlimited,331			)?;332		}333334		Ok(())335	}336337	#[benchmark]338	fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {339		bench_init! {340			owner: sub; collection: collection(owner);341			owner: cross_from_sub;342		};343344		let perms = (0..b)345			.map(|k| PropertyKeyPermission {346				key: property_key(k as usize),347				permission: PropertyPermission {348					mutable: false,349					collection_admin: true,350					token_owner: true,351				},352			})353			.collect::<Vec<_>>();354		<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;355		let props = (0..b)356			.map(|k| Property {357				key: property_key(k as usize),358				value: property_value(),359			})360			.collect::<Vec<_>>();361		let item = create_max_item(&collection, &owner, owner.clone())?;362363		// let (is_collection_admin, property_permissions) =364		// 	load_is_admin_and_property_permissions(&collection, &owner);365		todo!();366		#[block]367		{368			// let mut property_writer =369			// 	pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);370371			// property_writer.write_token_properties(372			// 	item,373			// 	props.into_iter(),374			// 	crate::erc::ERC721TokenEvent::TokenChanged {375			// 		token_id: item.into(),376			// 	}377			// 	.to_log(T::ContractAddress::get()),378			// )?;379		}380381		Ok(())382	}383384	#[benchmark]385	fn delete_token_properties(386		b: Linear<0, MAX_PROPERTIES_PER_ITEM>,387	) -> Result<(), BenchmarkError> {388		bench_init! {389			owner: sub; collection: collection(owner);390			owner: cross_from_sub;391		};392		let perms = (0..b)393			.map(|k| PropertyKeyPermission {394				key: property_key(k as usize),395				permission: PropertyPermission {396					mutable: true,397					collection_admin: true,398					token_owner: true,399				},400			})401			.collect::<Vec<_>>();402		<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;403		let props = (0..b)404			.map(|k| Property {405				key: property_key(k as usize),406				value: property_value(),407			})408			.collect::<Vec<_>>();409		let item = create_max_item(&collection, &owner, owner.clone())?;410		<Pallet<T>>::set_token_properties(411			&collection,412			&owner,413			item,414			props.into_iter(),415			&Unlimited,416		)?;417		let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();418419		#[block]420		{421			<Pallet<T>>::delete_token_properties(422				&collection,423				&owner,424				item,425				to_delete.into_iter(),426				&Unlimited,427			)?;428		}429430		Ok(())431	}432433	#[benchmark]434	fn token_owner() -> Result<(), BenchmarkError> {435		bench_init! {436			owner: sub; collection: collection(owner);437			owner: cross_from_sub;438		};439		let item = create_max_item(&collection, &owner, owner.clone())?;440441		#[block]442		{443			collection.token_owner(item).unwrap();444		}445446		Ok(())447	}448449	#[benchmark]450	fn set_allowance_for_all() -> Result<(), BenchmarkError> {451		bench_init! {452			owner: sub; collection: collection(owner); owner: cross_from_sub;453			operator: cross_sub;454		};455456		#[block]457		{458			<Pallet<T>>::set_allowance_for_all(&collection, &owner, &operator, true)?;459		}460461		Ok(())462	}463464	#[benchmark]465	fn allowance_for_all() -> Result<(), BenchmarkError> {466		bench_init! {467			owner: sub; collection: collection(owner); owner: cross_from_sub;468			operator: cross_sub;469		};470471		#[block]472		{473			<Pallet<T>>::allowance_for_all(&collection, &owner, &operator);474		}475476		Ok(())477	}478479	#[benchmark]480	fn repair_item() -> Result<(), BenchmarkError> {481		bench_init! {482			owner: sub; collection: collection(owner);483			owner: cross_from_sub;484		};485		let item = create_max_item(&collection, &owner, owner.clone())?;486487		#[block]488		{489			<Pallet<T>>::repair_item(&collection, item)?;490		}491492		Ok(())493	}494}
modifiedpallets/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,