git.delta.rocks / unique-network / refs/commits / 40455c4cbe68

difftreelog

Merge pull request #854 from UniqueNetwork/fix/createItemWeight

Yaroslav Bolyukin2023-01-25parents: #35f818f #c3d6374.patch.diff
in: master

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
before · pallets/common/CHANGELOG.md
1# Change Log23All notable changes to this project will be documented in this file.45<!-- bureaucrate goes here -->67## [0.1.12] - 2022-11-1689### Changed1011- Behavior of the `setCollectionLimit` method.12  Removed method overload: single signature `(string, uint256)`13  is used for both cases.1415## [0.1.11] - 2022-11-121617### Changed1819- In the `Collection` solidity interface,20  the `allowed` function has been renamed to `allow_listed_cross`.21  Also `EthCrossAccount` type is now used as `user` arg.2223## [0.1.10] - 2022-11-022425### Changed2627- Use named structure `EthCrossAccount` in eth functions.2829## [0.1.9] - 2022-10-133031## Added3233- EVM event for `destroy_collection`.3435## [0.1.8] - 2022-08-243637## Added3839- Eth methods for collection40  - set_collection_sponsor_substrate41  - has_collection_pending_sponsor42  - remove_collection_sponsor43  - get_collection_sponsor44- Add convert function from `uint256` to `CrossAccountId`.4546## [0.1.7] - 2022-08-194748### Added4950- Add convert funtion from `CrossAccountId` to eth `uint256`.5152## [0.1.6] - 2022-08-165354### Added5556- New Ethereum API methods: changeOwner, changeOwner(Substrate) and verifyOwnerOrAdmin(Substrate).5758## [v0.1.5] 2022-08-165960### Other changes6162- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a6364- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf86566- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d9756768New methods allows to call `remove_prefix` with limit multiple times69in the same block70However, we don't use prefix removal limits, so upgrade is71straightforward7273Upstream-Change: https://github.com/paritytech/substrate/pull/114907475- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b7677## [0.1.3] - 2022-07-257879### Add8081- Some static property keys and values.8283## [0.1.2] - 2022-07-208485### Fixed8687- Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid88  mutability modifiers, causing invalid stub/abi generation.8990## [0.1.1] - 2022-07-149192### Added9394- Implementation of RPC method `token_owners` returning 10 owners in no particular order.95  This was an internal request to improve the web interface and support fractionalization event.
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
@@ -590,7 +590,7 @@
 	/// @param tokenUri Token URI that would be stored in the NFT properties
 	/// @return uint256 The id of the newly minted token
 	#[solidity(rename_selector = "mintWithTokenURI")]
-	#[weight(<SelfWeightOf<T>>::create_item())]
+	#[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
 	fn mint_with_token_uri(
 		&mut self,
 		caller: Caller,
@@ -612,7 +612,7 @@
 	/// @param tokenId ID of the minted NFT
 	/// @param tokenUri Token URI that would be stored in the NFT properties
 	#[solidity(hide, rename_selector = "mintWithTokenURI")]
-	#[weight(<SelfWeightOf<T>>::create_item())]
+	#[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
 	fn mint_with_token_uri_check_id(
 		&mut self,
 		caller: Caller,
@@ -943,7 +943,7 @@
 	/// @param to The new owner
 	/// @param tokens array of pairs of token ID and token URI for minted tokens
 	#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
-	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]
+	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32)  + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
 	fn mint_bulk_with_token_uri(
 		&mut self,
 		caller: Caller,
@@ -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
@@ -629,7 +629,7 @@
 	/// @param tokenUri Token URI that would be stored in the NFT properties
 	/// @return uint256 The id of the newly minted token
 	#[solidity(rename_selector = "mintWithTokenURI")]
-	#[weight(<SelfWeightOf<T>>::create_item())]
+	#[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
 	fn mint_with_token_uri(
 		&mut self,
 		caller: Caller,
@@ -651,7 +651,7 @@
 	/// @param tokenId ID of the minted RFT
 	/// @param tokenUri Token URI that would be stored in the RFT properties
 	#[solidity(hide, rename_selector = "mintWithTokenURI")]
-	#[weight(<SelfWeightOf<T>>::create_item())]
+	#[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
 	fn mint_with_token_uri_check_id(
 		&mut self,
 		caller: Caller,
@@ -994,7 +994,7 @@
 	/// @param to The new owner
 	/// @param tokens array of pairs of token ID and token URI for minted tokens
 	#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
-	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]
+	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
 	fn mint_bulk_with_token_uri(
 		&mut self,
 		caller: Caller,
@@ -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
--- a/runtime/common/weights.rs
+++ b/runtime/common/weights.rs
@@ -57,8 +57,8 @@
 where
 	T: CommonWeightConfigs,
 {
-	fn create_item() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(create_item())
+	fn create_item(data: &CreateItemData) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(create_item(data))
 	}
 
 	fn create_multiple_items(data: &[CreateItemData]) -> Weight {