git.delta.rocks / unique-network / refs/commits / befa82f13fdb

difftreelog

fix weight for `createItem`

PraetorP2023-01-23parent: #1154c05.patch.diff
in: master
Chnaged behaviour for `CommonWeightInfo` trait.

15 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5783,7 +5783,7 @@
 
 [[package]]
 name = "pallet-common"
-version = "0.1.12"
+version = "0.1.13"
 dependencies = [
  "ethereum 0.14.0",
  "evm-coder",
@@ -6340,7 +6340,7 @@
 
 [[package]]
 name = "pallet-nonfungible"
-version = "0.1.12"
+version = "0.1.13"
 dependencies = [
  "evm-coder",
  "frame-benchmarking",
@@ -6499,7 +6499,7 @@
 
 [[package]]
 name = "pallet-refungible"
-version = "0.2.11"
+version = "0.2.12"
 dependencies = [
  "evm-coder",
  "frame-benchmarking",
modifiedpallets/common/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/common/CHANGELOG.md
+++ b/pallets/common/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 <!-- bureaucrate goes here -->
 
+## [0.1.13] - 2023-01-20
+
+### Changed
+
+- Behavior of the `CommonWeightInfo::create_item` method.
+
 ## [0.1.12] - 2022-11-16
 
 ### Changed
modifiedpallets/common/Cargo.tomldiffbeforeafterboth
--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -2,7 +2,7 @@
 edition = "2021"
 license = "GPLv3"
 name = "pallet-common"
-version = "0.1.12"
+version = "0.1.13"
 
 [dependencies]
 codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -53,7 +53,10 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 extern crate alloc;
 
-use core::ops::{Deref, DerefMut};
+use core::{
+	ops::{Deref, DerefMut},
+	slice::from_ref,
+};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
 use sp_std::vec::Vec;
 use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
@@ -1780,7 +1783,9 @@
 /// Return weights for various worst-case operations.
 pub trait CommonWeightInfo<CrossAccountId> {
 	/// Weight of item creation.
-	fn create_item() -> Weight;
+	fn create_item(data: &CreateItemData) -> Weight {
+		Self::create_multiple_items(from_ref(data))
+	}
 
 	/// Weight of items creation.
 	fn create_multiple_items(amount: &[CreateItemData]) -> Weight;
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -36,13 +36,9 @@
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
 impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
-	fn create_item() -> Weight {
-		<SelfWeightOf<T>>::create_item()
-	}
-
 	fn create_multiple_items(_data: &[CreateItemData]) -> Weight {
 		// All items minted for the same user, so it works same as create_item
-		Self::create_item()
+		<SelfWeightOf<T>>::create_item()
 	}
 
 	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
@@ -134,10 +130,10 @@
 		data: up_data_structs::CreateItemData,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResultWithPostInfo {
-		match data {
-			up_data_structs::CreateItemData::Fungible(data) => with_weight(
-				<Pallet<T>>::create_item(self, &sender, (to, data.value), nesting_budget),
-				<CommonWeights<T>>::create_item(),
+		match &data {
+			up_data_structs::CreateItemData::Fungible(fungible_data) => with_weight(
+				<Pallet<T>>::create_item(self, &sender, (to, fungible_data.value), nesting_budget),
+				<CommonWeights<T>>::create_item(&data),
 			),
 			_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
 		}
@@ -151,8 +147,8 @@
 		nesting_budget: &dyn Budget,
 	) -> DispatchResultWithPostInfo {
 		let mut sum: u128 = 0;
-		for data in data {
-			match data {
+		for data in &data {
+			match &data {
 				up_data_structs::CreateItemData::Fungible(data) => {
 					sum = sum
 						.checked_add(data.value)
@@ -164,7 +160,7 @@
 
 		with_weight(
 			<Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),
-			<CommonWeights<T>>::create_item(),
+			<CommonWeights<T>>::create_multiple_items(&data),
 		)
 	}
 
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 <!-- bureaucrate goes here -->
 
+## [0.1.13] - 2023-01-20
+
+### Fixed
+
+- The weight of properties when creating an item.
+
 ## [0.1.12] - 2022-12-16
 
 ### Added
modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/nonfungible/Cargo.toml
+++ b/pallets/nonfungible/Cargo.toml
@@ -2,7 +2,7 @@
 edition = "2021"
 license = "GPLv3"
 name = "pallet-nonfungible"
-version = "0.1.12"
+version = "0.1.13"
 
 [dependencies]
 codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -35,10 +35,6 @@
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
 impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
-	fn create_item() -> Weight {
-		<SelfWeightOf<T>>::create_item()
-	}
-
 	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
 		match data {
 			CreateItemExData::NFT(t) => {
@@ -159,6 +155,7 @@
 		data: up_data_structs::CreateItemData,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResultWithPostInfo {
+		let weight = <CommonWeights<T>>::create_item(&data);
 		with_weight(
 			<Pallet<T>>::create_item(
 				self,
@@ -166,7 +163,7 @@
 				map_create_data::<T>(data, &to)?,
 				nesting_budget,
 			),
-			<CommonWeights<T>>::create_item(),
+			weight,
 		)
 	}
 
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -994,7 +994,7 @@
 	/// @param to The new owner crossAccountId
 	/// @param properties Properties of minted token
 	/// @return uint256 The id of the newly minted token
-	#[weight(<SelfWeightOf<T>>::create_item())]
+	#[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]
 	fn mint_cross(
 		&mut self,
 		caller: Caller,
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/refungible/CHANGELOG.md
+++ b/pallets/refungible/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 <!-- bureaucrate goes here -->
 
+## [0.2.12] - 2023-01-20
+
+### Fixed
+
+- The weight of properties when creating an item.
+
 ## [0.2.11] - 2022-12-16
 
 ### Added
modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -2,7 +2,7 @@
 edition = "2021"
 license = "GPLv3"
 name = "pallet-refungible"
-version = "0.2.11"
+version = "0.2.12"
 
 [dependencies]
 codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -55,10 +55,6 @@
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
 impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
-	fn create_item() -> Weight {
-		<SelfWeightOf<T>>::create_item()
-	}
-
 	fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {
 		<SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(
 			data.iter()
@@ -193,6 +189,7 @@
 		data: up_data_structs::CreateItemData,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResultWithPostInfo {
+		let weight = <CommonWeights<T>>::create_item(&data);
 		with_weight(
 			<Pallet<T>>::create_item(
 				self,
@@ -200,7 +197,7 @@
 				map_create_data::<T>(data, &to)?,
 				nesting_budget,
 			),
-			<CommonWeights<T>>::create_item(),
+			weight,
 		)
 	}
 
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -1051,7 +1051,7 @@
 	/// @param to The new owner crossAccountId
 	/// @param properties Properties of minted token
 	/// @return uint256 The id of the newly minted token
-	#[weight(<SelfWeightOf<T>>::create_item())]
+	#[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]
 	fn mint_cross(
 		&mut self,
 		caller: Caller,
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -518,7 +518,7 @@
 		/// * `collection_id`: ID of the collection to which an item would belong.
 		/// * `owner`: Address of the initial owner of the item.
 		/// * `data`: Token data describing the item to store on chain.
-		#[weight = T::CommonWeightInfo::create_item()]
+		#[weight = T::CommonWeightInfo::create_item(&data)]
 		pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let budget = budget::Value::new(NESTING_BUDGET);
modifiedruntime/common/weights.rsdiffbeforeafterboth
before · runtime/common/weights.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 core::marker::PhantomData;18use frame_support::{weights::Weight};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};2021use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};2324#[cfg(feature = "refungible")]25use pallet_refungible::{26	Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,27};28use up_data_structs::{CreateItemExData, CreateItemData};2930macro_rules! max_weight_of {31	($method:ident ( $($args:tt)* )) => {{32		let max_weight = <FungibleWeights<T>>::$method($($args)*)33			.max(<NonfungibleWeights<T>>::$method($($args)*));3435		#[cfg(feature = "refungible")]36		let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));3738		max_weight39	}};40}4142#[cfg(not(feature = "refungible"))]43pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}4445#[cfg(not(feature = "refungible"))]46impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}4748#[cfg(feature = "refungible")]49pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}5051#[cfg(feature = "refungible")]52impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}5354pub struct CommonWeights<T>(PhantomData<T>);5556impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>57where58	T: CommonWeightConfigs,59{60	fn create_item() -> Weight {61		dispatch_weight::<T>() + max_weight_of!(create_item())62	}6364	fn create_multiple_items(data: &[CreateItemData]) -> Weight {65		dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))66	}6768	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {69		dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))70	}7172	fn burn_item() -> Weight {73		dispatch_weight::<T>() + max_weight_of!(burn_item())74	}7576	fn set_collection_properties(amount: u32) -> Weight {77		dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))78	}7980	fn delete_collection_properties(amount: u32) -> Weight {81		dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))82	}8384	fn set_token_properties(amount: u32) -> Weight {85		dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))86	}8788	fn delete_token_properties(amount: u32) -> Weight {89		dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))90	}9192	fn set_token_property_permissions(amount: u32) -> Weight {93		dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))94	}9596	fn transfer() -> Weight {97		dispatch_weight::<T>() + max_weight_of!(transfer())98	}99100	fn approve() -> Weight {101		dispatch_weight::<T>() + max_weight_of!(approve())102	}103104	fn approve_from() -> Weight {105		dispatch_weight::<T>() + max_weight_of!(approve_from())106	}107108	fn transfer_from() -> Weight {109		dispatch_weight::<T>() + max_weight_of!(transfer_from())110	}111112	fn burn_from() -> Weight {113		dispatch_weight::<T>() + max_weight_of!(burn_from())114	}115116	fn burn_recursively_self_raw() -> Weight {117		max_weight_of!(burn_recursively_self_raw())118	}119120	fn burn_recursively_breadth_raw(amount: u32) -> Weight {121		max_weight_of!(burn_recursively_breadth_raw(amount))122	}123124	fn token_owner() -> Weight {125		max_weight_of!(token_owner())126	}127128	fn set_allowance_for_all() -> Weight {129		max_weight_of!(set_allowance_for_all())130	}131132	fn force_repair_item() -> Weight {133		max_weight_of!(force_repair_item())134	}135}136137#[cfg(feature = "refungible")]138impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>139where140	T: FungibleConfig + NonfungibleConfig + RefungibleConfig,141{142	fn repartition() -> Weight {143		dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()144	}145}146147#[cfg(not(feature = "refungible"))]148impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>149where150	T: FungibleConfig + NonfungibleConfig,151{152	fn repartition() -> Weight {153		dispatch_weight::<T>()154	}155}