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.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
pallets/refungible/Cargo.tomldiffbeforeafterboth1[package]2edition = "2021"3license = "GPLv3"4name = "pallet-refungible"5version = "0.2.11"67[dependencies]8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }9scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }1011evm-coder = { default-features = false, path = "../../crates/evm-coder" }12frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }13frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }14frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }15pallet-common = { default-features = false, path = "../common" }16pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }17pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }18pallet-structure = { default-features = false, path = "../structure" }19sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }20sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }21sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }2223up-data-structs = { default-features = false, path = "../../primitives/data-structs" }2425[features]26default = ["std"]27runtime-benchmarks = [28 'frame-benchmarking',29 'frame-support/runtime-benchmarks',30 'frame-system/runtime-benchmarks',31 'up-data-structs/runtime-benchmarks',32]33std = [34 "evm-coder/std",35 "frame-support/std",36 "frame-system/std",37 "pallet-common/std",38 "pallet-evm-coder-substrate/std",39 "pallet-evm/std",40 "pallet-structure/std",41 "sp-runtime/std",42 "sp-std/std",43 "up-data-structs/std",44 'frame-benchmarking/std',45]46stubgen = ["evm-coder/stubgen", "pallet-common/stubgen"]47try-runtime = ["frame-support/try-runtime"]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 {