difftreelog
fix weight for `createItem`
in: master
Chnaged behaviour for `CommonWeightInfo` trait.
15 files changed
Cargo.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",
pallets/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
pallets/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" }
pallets/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;
pallets/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),
)
}
pallets/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
pallets/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" }
pallets/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,
)
}
pallets/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,
pallets/refungible/CHANGELOG.mddiffbeforeafterboth1# Change Log23All notable changes to this project will be documented in this file.45<!-- bureaucrate goes here -->67## [0.2.11] - 2022-12-1689### Added1011- The function `tokenPropertyPermissions` and `setTokenPropertyPermissions` to `TokenProperties` interface.1213### Changed1415- Hide `setTokenPropertyPermission` function in `TokenProperties` interface.1617## [0.2.10] - 2022-12-011819### Added2021- The functions `mintCross` to `ERC721UniqueExtensions` interface.2223## [0.2.9] - 2022-11-182425### Added2627- The functions `description`, `crossOwnerOf`, `tokenProperties` to `ERC721UniqueExtensions` interface.2829## [0.2.8] - 2022-11-143031### Changed3233- Added `transfer_cross` in eth functions.3435## [v0.2.7] - 2022-11-113637### Changed3839- Added `delete_properties` in eth functions. The `delete_property` function is now deprecated.4041## [v0.2.6] - 2022-11-024243### Changed4445- Use named structure `EthCrossAccount` in eth functions.4647## [v0.2.5] - 2022-20-104849### Change5051- Added `set_properties` method for `TokenProperties` interface.5253## [v0.2.4] - 2022-08-245455### Change5657- Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.5859## [v0.2.3] 2022-08-166061### Other changes6263- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a6465- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf86667- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d9756869New methods allows to call `remove_prefix` with limit multiple times70in the same block71However, we don't use prefix removal limits, so upgrade is72straightforward7374Upstream-Change: https://github.com/paritytech/substrate/pull/114907576- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b7778## [v0.2.2] 2022-08-047980### Product changes8182- Now RefungibleMultipleItems may only receive single user on type level.8384### Added features8586- Implement property RPC 7bf45b532e32daa91f03c157b58874d21b42ae1f8788### Other changes8990- refactor: Disallow invalid bulk mints 53fec71cf728dddd012257b407ea30441e699f889192`create_multiple_items_ex` was allowing invalid (that will be always93rejected at runtime level) refungible mint extrinsics, by passing94multiple users into `RefungibleMultipleItems` call.9596## [v0.2.1] - 2022-07-279798### New features99100Implementation of ERC-721 EVM API ([#452](https://github.com/UniqueNetwork/unique-chain/pull/452))101102## [v0.2.0] - 2022-08-01103104### Deprecated105106`const_data` field is removed107108- `ItemData`109- `TokenData`110111## [v0.1.2] - 2022-07-14112113### Other changes114115feat(refungible-pallet): add ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))116test(refungible-pallet): add tests for ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))117118## [v0.1.1] - 2022-07-14119120### Added features121122- Support for properties for RFT collections and tokens.123124### Other changes125126- feat: RPC method `token_owners` returning 10 owners in no particular order.127128This was an internal request to improve the web interface and support fractionalization event.pallets/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" }
pallets/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,
)
}
pallets/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,
pallets/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);
runtime/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 {