difftreelog
fix EVM mint with properties, minor improvements
in: master
9 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -29,9 +29,8 @@
use sp_std::{vec, vec::Vec};
use up_data_structs::{
AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,
- NestingPermissions, PropertiesPermissionMap, Property, PropertyKey, PropertyValue,
- MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM,
- MAX_TOKEN_PREFIX_LENGTH,
+ NestingPermissions, Property, PropertyKey, PropertyValue, MAX_COLLECTION_DESCRIPTION_LENGTH,
+ MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM, MAX_TOKEN_PREFIX_LENGTH,
};
use crate::{BenchmarkPropertyWriter, CollectionHandle, Config, Pallet};
@@ -190,31 +189,6 @@
#[block]
{
<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;
- }
-
- Ok(())
- }
-
- #[benchmark]
- fn delete_collection_properties(
- b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
- ) -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- owner: cross_from_sub;
- };
- let props = (0..b)
- .map(|p| Property {
- key: property_key(p as usize),
- value: property_value(),
- })
- .collect::<Vec<_>>();
- <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;
- let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();
-
- #[block]
- {
- <Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?;
}
Ok(())
@@ -253,7 +227,7 @@
}
#[benchmark]
- fn init_token_properties_common() -> Result<(), BenchmarkError> {
+ fn property_writer_load_collection_info() -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
sender: sub;
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -126,7 +126,7 @@
///
/// @param key Property key.
#[solidity(hide)]
- #[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
+ #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
fn delete_collection_property(&mut self, caller: Caller, key: String) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let key = <Vec<u8>>::from(key)
@@ -139,7 +139,7 @@
/// Delete collection properties.
///
/// @param keys Properties keys.
- #[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]
+ #[weight(<SelfWeightOf<T>>::set_collection_properties(keys.len() as u32))]
fn delete_collection_properties(&mut self, caller: Caller, keys: Vec<String>) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let keys = keys
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2626,8 +2626,8 @@
impl<T: Config> BenchmarkPropertyWriter<T> {
/// Creates a [`PropertyWriter`] for benchmarking tokens properties writing.
pub fn new<'a, Handle>(
- collection: &Handle,
- collection_lazy_info: PropertyWriterLazyCollectionInfo,
+ collection: &'a Handle,
+ collection_lazy_info: PropertyWriterLazyCollectionInfo<'a>,
) -> PropertyWriter<'a, Self, T, Handle>
where
Handle: CommonCollectionOperations<T> + Deref<Target = CollectionHandle<T>>,
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -18,7 +18,6 @@
use pallet_common::{
bench_init,
benchmarking::{create_collection_raw, property_key, property_value},
- CommonCollectionOperations,
};
use sp_std::prelude::*;
use up_data_structs::{
@@ -131,53 +130,12 @@
#[block]
{
<Pallet<T>>::burn(&collection, &burner, item)?;
- }
-
- Ok(())
- }
-
- #[benchmark]
- fn burn_recursively_self_raw() -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- sender: cross_from_sub(owner); burner: cross_sub;
- };
- let item = create_max_item(&collection, &sender, burner.clone())?;
-
- #[block]
- {
- <Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;
}
Ok(())
}
#[benchmark]
- fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(
- b: Linear<0, 200>,
- ) -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- sender: cross_from_sub(owner); burner: cross_sub;
- };
- let item = create_max_item(&collection, &sender, burner.clone())?;
- for _ in 0..b {
- create_max_item(
- &collection,
- &sender,
- T::CrossTokenAddressMapping::token_to_address(collection.id, item),
- )?;
- }
-
- #[block]
- {
- <Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;
- }
-
- Ok(())
- }
-
- #[benchmark]
fn transfer_raw() -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
@@ -262,116 +220,34 @@
{
<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?;
}
- }
- // set_token_properties {
- // let b in 0..MAX_PROPERTIES_PER_ITEM;
- // 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 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())?;
- // }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?}
-
- // load_token_properties {
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
-
- // let item = create_max_item(&collection, &owner, owner.clone())?;
- // }: {
- // pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(
- // &collection,
- // item,
- // )
- // }
-
- // write_token_properties {
- // let b in 0..MAX_PROPERTIES_PER_ITEM;
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
+ Ok(())
+ }
- // 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 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())?;
-
- // let lazy_collection_info = pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(
- // &collection,
- // &owner,
- // );
- // }: {
- // let mut property_writer = pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
-
- // property_writer.write_token_properties(
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?
- // }
-
#[benchmark]
- fn set_token_property_permissions(
- b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
- ) -> Result<(), BenchmarkError> {
+ fn load_token_properties() -> Result<(), BenchmarkError> {
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: false,
- token_owner: false,
- },
- })
- .collect::<Vec<_>>();
+ let item = create_max_item(&collection, &owner, owner.clone())?;
+
#[block]
{
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
+ pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(&collection, item);
}
Ok(())
}
#[benchmark]
- fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
+ fn write_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};
+
let perms = (0..b)
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
@@ -391,71 +267,29 @@
.collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;
+ let lazy_collection_info =
+ pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(&collection, &owner);
+
#[block]
{
- <Pallet<T>>::set_token_properties(
- &collection,
- &owner,
+ let mut property_writer =
+ pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
+
+ property_writer.write_token_properties(
item,
props.into_iter(),
- &Unlimited,
+ crate::erc::ERC721TokenEvent::TokenChanged {
+ token_id: item.into(),
+ }
+ .to_log(T::ContractAddress::get()),
)?;
}
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;
- // };
-
- // 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())?;
-
- // let (is_collection_admin, property_permissions) =
- // load_is_admin_and_property_permissions(&collection, &owner);
- // #[block]
- // {
- // let mut property_writer =
- // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
-
- // property_writer.write_token_properties(
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?;
- // }
-
- Ok(())
- }
-
- #[benchmark]
- fn delete_token_properties(
+ fn set_token_property_permissions(
b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
) -> Result<(), BenchmarkError> {
bench_init! {
@@ -466,54 +300,16 @@
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
permission: PropertyPermission {
- mutable: true,
- collection_admin: true,
- token_owner: true,
+ mutable: false,
+ collection_admin: false,
+ token_owner: false,
},
- })
- .collect::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- 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())?;
- <Pallet<T>>::set_token_properties(
- &collection,
- &owner,
- item,
- props.into_iter(),
- &Unlimited,
- )?;
- let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
#[block]
{
- <Pallet<T>>::delete_token_properties(
- &collection,
- &owner,
- item,
- to_delete.into_iter(),
- &Unlimited,
- )?;
- }
-
- Ok(())
- }
-
- #[benchmark]
- fn token_owner() -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- owner: cross_from_sub;
- };
- let item = create_max_item(&collection, &owner, owner.clone())?;
-
- #[block]
- {
- collection.token_owner(item).unwrap();
+ <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
}
Ok(())
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -39,24 +39,21 @@
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
match data {
- CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32)
- .saturating_add(write_token_properties_total_weight::<T, _>(
- t.iter().map(|t| t.properties.len() as u32),
- <SelfWeightOf<T>>::write_token_properties,
- )),
+ CreateItemExData::NFT(t) => mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),
+ t.iter().map(|t| t.properties.len() as u32),
+ ),
_ => Weight::zero(),
}
}
fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {
- <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(
- write_token_properties_total_weight::<T, _>(
- data.iter().map(|t| match t {
- up_data_structs::CreateItemData::NFT(n) => n.properties.len() as u32,
- _ => 0,
- }),
- <SelfWeightOf<T>>::write_token_properties,
- ),
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(data.len() as u32),
+ data.iter().map(|t| match t {
+ up_data_structs::CreateItemData::NFT(n) => n.properties.len() as u32,
+ _ => 0,
+ }),
)
}
@@ -113,6 +110,16 @@
}
}
+pub(crate) fn mint_with_props_weight<T: Config>(
+ create_no_data_weight: Weight,
+ tokens: impl Iterator<Item = u32> + Clone,
+) -> Weight {
+ create_no_data_weight.saturating_add(write_token_properties_total_weight::<T, _>(
+ tokens,
+ <SelfWeightOf<T>>::write_token_properties,
+ ))
+}
+
fn map_create_data<T: Config>(
data: up_data_structs::CreateItemData,
to: &T::CrossAccountId,
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -49,8 +49,10 @@
};
use crate::{
- common::CommonWeights, weights::WeightInfo, AccountBalance, Config, CreateItemData,
- NonfungibleHandle, Pallet, SelfWeightOf, TokenData, TokenProperties, TokensMinted,
+ common::{mint_with_props_weight, CommonWeights},
+ weights::WeightInfo,
+ AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, SelfWeightOf, TokenData,
+ TokenProperties, TokensMinted,
};
/// Nft events.
@@ -620,7 +622,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() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri(
&mut self,
caller: Caller,
@@ -642,7 +644,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() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri_check_id(
&mut self,
caller: Caller,
@@ -974,7 +976,12 @@
/// @notice Function to mint a token.
/// @param data Array of pairs of token owner and token's properties for minted token
- #[weight(<SelfWeightOf<T>>::create_multiple_items(data.len() as u32) + <SelfWeightOf<T>>::set_token_properties(data.len() as u32))]
+ #[weight(
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex(data.len() as u32),
+ data.iter().map(|d| d.properties.len() as u32),
+ )
+ )]
fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<MintTokenData>) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -1008,7 +1015,12 @@
/// @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) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
+ #[weight(
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32),
+ tokens.iter().map(|_| 1),
+ )
+ )]
fn mint_bulk_with_token_uri(
&mut self,
caller: Caller,
@@ -1056,7 +1068,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() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [properties.len() as u32].into_iter()))]
fn mint_cross(
&mut self,
caller: Caller,
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth1// 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::{convert::TryInto, iter::IntoIterator};1819use frame_benchmarking::v2::*;20use pallet_common::{21 bench_init,22 benchmarking::{create_collection_raw, property_key, property_value},23};24use sp_std::prelude::*;25use up_data_structs::{26 budget::Unlimited, CollectionMode, PropertyPermission, MAX_ITEMS_PER_BATCH,27 MAX_PROPERTIES_PER_ITEM,28};2930use super::*;31use crate::{Config, Pallet, RefungibleHandle};3233const SEED: u32 = 1;3435fn create_max_item_data<T: Config>(36 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,37) -> CreateItemData<T> {38 CreateItemData::<T> {39 users: users40 .into_iter()41 .collect::<BTreeMap<_, _>>()42 .try_into()43 .unwrap(),44 properties: Default::default(),45 }46}4748fn create_max_item<T: Config>(49 collection: &RefungibleHandle<T>,50 sender: &T::CrossAccountId,51 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,52) -> Result<TokenId, DispatchError> {53 let data: CreateItemData<T> = create_max_item_data::<T>(users);54 <Pallet<T>>::create_item(collection, sender, data, &Unlimited)?;55 Ok(TokenId(<TokensMinted<T>>::get(collection.id)))56}5758fn create_collection<T: Config>(59 owner: T::CrossAccountId,60) -> Result<RefungibleHandle<T>, DispatchError> {61 create_collection_raw(62 owner,63 CollectionMode::ReFungible,64 |owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),65 RefungibleHandle::cast,66 )67}6869#[benchmarks]70mod benchmarks {71 use super::*;7273 #[benchmark]74 fn create_item() -> Result<(), BenchmarkError> {75 bench_init! {76 owner: sub; collection: collection(owner);77 sender: cross_from_sub(owner); to: cross_sub;78 };7980 #[block]81 {82 create_max_item(&collection, &sender, [(to, 200)])?;83 }8485 Ok(())86 }8788 #[benchmark]89 fn create_multiple_items(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> {90 bench_init! {91 owner: sub; collection: collection(owner);92 sender: cross_from_sub(owner); to: cross_sub;93 };94 let data = (0..b)95 .map(|_| create_max_item_data::<T>([(to.clone(), 200)]))96 .collect();9798 #[block]99 {100 <Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;101 }102103 Ok(())104 }105 #[benchmark]106 fn create_multiple_items_ex_multiple_items(107 b: Linear<0, MAX_ITEMS_PER_BATCH>,108 ) -> Result<(), BenchmarkError> {109 bench_init! {110 owner: sub; collection: collection(owner);111 sender: cross_from_sub(owner);112 };113 let data = (0..b)114 .map(|t| {115 bench_init!(to: cross_sub(t););116 create_max_item_data::<T>([(to, 200)])117 })118 .collect();119120 #[block]121 {122 <Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;123 }124125 Ok(())126 }127128 #[benchmark]129 fn create_multiple_items_ex_multiple_owners(130 b: Linear<0, MAX_ITEMS_PER_BATCH>,131 ) -> Result<(), BenchmarkError> {132 bench_init! {133 owner: sub; collection: collection(owner);134 sender: cross_from_sub(owner);135 };136 let data = vec![create_max_item_data::<T>((0..b).map(|u| {137 bench_init!(to: cross_sub(u););138 (to, 200)139 }))];140141 #[block]142 {143 <Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;144 }145146 Ok(())147 }148149 // Other user left, token data is kept150 #[benchmark]151 fn burn_item_partial() -> Result<(), BenchmarkError> {152 bench_init! {153 owner: sub; collection: collection(owner);154 sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;155 };156 let item = create_max_item(157 &collection,158 &sender,159 [(burner.clone(), 200), (another_owner, 200)],160 )?;161162 #[block]163 {164 <Pallet<T>>::burn(&collection, &burner, item, 200)?;165 }166167 Ok(())168 }169170 // No users remaining, token is destroyed171 #[benchmark]172 fn burn_item_fully() -> Result<(), BenchmarkError> {173 bench_init! {174 owner: sub; collection: collection(owner);175 sender: cross_from_sub(owner); burner: cross_sub;176 };177 let item = create_max_item(&collection, &sender, [(burner.clone(), 200)])?;178179 #[block]180 {181 <Pallet<T>>::burn(&collection, &burner, item, 200)?;182 }183184 Ok(())185 }186187 #[benchmark]188 fn transfer_normal() -> Result<(), BenchmarkError> {189 bench_init! {190 owner: sub; collection: collection(owner);191 sender: cross_from_sub(owner); receiver: cross_sub;192 };193 let item = create_max_item(194 &collection,195 &sender,196 [(sender.clone(), 200), (receiver.clone(), 200)],197 )?;198199 #[block]200 {201 <Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?;202 }203204 Ok(())205 }206207 // Target account is created208 #[benchmark]209 fn transfer_creating() -> Result<(), BenchmarkError> {210 bench_init! {211 owner: sub; collection: collection(owner);212 sender: cross_from_sub(owner); receiver: cross_sub;213 };214 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;215216 #[block]217 {218 <Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?;219 }220221 Ok(())222 }223224 // Source account is destroyed225 #[benchmark]226 fn transfer_removing() -> Result<(), BenchmarkError> {227 bench_init! {228 owner: sub; collection: collection(owner);229 sender: cross_from_sub(owner); receiver: cross_sub;230 };231 let item = create_max_item(232 &collection,233 &sender,234 [(sender.clone(), 200), (receiver.clone(), 200)],235 )?;236237 #[block]238 {239 <Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?;240 }241242 Ok(())243 }244245 // Source account destroyed, target created246 #[benchmark]247 fn transfer_creating_removing() -> Result<(), BenchmarkError> {248 bench_init! {249 owner: sub; collection: collection(owner);250 sender: cross_from_sub(owner); receiver: cross_sub;251 };252 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;253254 #[block]255 {256 <Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?;257 }258259 Ok(())260 }261262 #[benchmark]263 fn approve() -> Result<(), BenchmarkError> {264 bench_init! {265 owner: sub; collection: collection(owner);266 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;267 };268 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;269270 #[block]271 {272 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;273 }274275 Ok(())276 }277278 #[benchmark]279 fn approve_from() -> Result<(), BenchmarkError> {280 bench_init! {281 owner: sub; collection: collection(owner);282 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;283 };284 let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());285 let item = create_max_item(&collection, &owner, [(owner_eth.clone(), 200)])?;286287 #[block]288 {289 <Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, item, 100)?;290 }291292 Ok(())293 }294295 #[benchmark]296 fn transfer_from_normal() -> Result<(), BenchmarkError> {297 bench_init! {298 owner: sub; collection: collection(owner);299 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;300 };301 let item = create_max_item(302 &collection,303 &owner,304 [(sender.clone(), 200), (receiver.clone(), 200)],305 )?;306 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;307308 #[block]309 {310 <Pallet<T>>::transfer_from(311 &collection,312 &spender,313 &sender,314 &receiver,315 item,316 100,317 &Unlimited,318 )?;319 }320321 Ok(())322 }323324 // Target account is created325 #[benchmark]326 fn transfer_from_creating() -> Result<(), BenchmarkError> {327 bench_init! {328 owner: sub; collection: collection(owner);329 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;330 };331 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;332 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;333334 #[block]335 {336 <Pallet<T>>::transfer_from(337 &collection,338 &spender,339 &sender,340 &receiver,341 item,342 100,343 &Unlimited,344 )?;345 }346347 Ok(())348 }349350 // Source account is destroyed351 #[benchmark]352 fn transfer_from_removing() -> Result<(), BenchmarkError> {353 bench_init! {354 owner: sub; collection: collection(owner);355 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;356 };357 let item = create_max_item(358 &collection,359 &owner,360 [(sender.clone(), 200), (receiver.clone(), 200)],361 )?;362 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;363364 #[block]365 {366 <Pallet<T>>::transfer_from(367 &collection,368 &spender,369 &sender,370 &receiver,371 item,372 200,373 &Unlimited,374 )?;375 }376377 Ok(())378 }379380 // Source account destroyed, target created381 #[benchmark]382 fn transfer_from_creating_removing() -> Result<(), BenchmarkError> {383 bench_init! {384 owner: sub; collection: collection(owner);385 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;386 };387 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;388 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;389390 #[block]391 {392 <Pallet<T>>::transfer_from(393 &collection,394 &spender,395 &sender,396 &receiver,397 item,398 200,399 &Unlimited,400 )?;401 }402403 Ok(())404 }405406 // Both source account and token is destroyed407 #[benchmark]408 fn burn_from() -> Result<(), BenchmarkError> {409 bench_init! {410 owner: sub; collection: collection(owner);411 owner: cross_from_sub; sender: cross_sub; burner: cross_sub;412 };413 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;414 <Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;415416 #[block]417 {418 <Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?;419 }420421 Ok(())422 }423424 #[benchmark]425 fn load_token_properties() -> Result<(), BenchmarkError> {426 bench_init! {427 owner: sub; collection: collection(owner);428 owner: cross_from_sub;429 };430431 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;432433 #[block]434 {435 pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(&collection, item);436 }437438 Ok(())439 }440441 #[benchmark]442 fn write_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {443 bench_init! {444 owner: sub; collection: collection(owner);445 owner: cross_from_sub;446 };447448 let perms = (0..b)449 .map(|k| PropertyKeyPermission {450 key: property_key(k as usize),451 permission: PropertyPermission {452 mutable: false,453 collection_admin: true,454 token_owner: true,455 },456 })457 .collect::<Vec<_>>();458 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;459 let props = (0..b)460 .map(|k| Property {461 key: property_key(k as usize),462 value: property_value(),463 })464 .collect::<Vec<_>>();465 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;466467 let lazy_collection_info =468 pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(&collection, &owner);469470 #[block]471 {472 let mut property_writer =473 pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);474475 property_writer.write_token_properties(476 item,477 props.into_iter(),478 crate::erc::ERC721TokenEvent::TokenChanged {479 token_id: item.into(),480 }481 .to_log(T::ContractAddress::get()),482 )?;483 }484485 Ok(())486 }487488 #[benchmark]489 fn set_token_property_permissions(490 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,491 ) -> Result<(), BenchmarkError> {492 bench_init! {493 owner: sub; collection: collection(owner);494 owner: cross_from_sub;495 };496 let perms = (0..b)497 .map(|k| PropertyKeyPermission {498 key: property_key(k as usize),499 permission: PropertyPermission {500 mutable: false,501 collection_admin: false,502 token_owner: false,503 },504 })505 .collect::<Vec<_>>();506507 #[block]508 {509 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;510 }511512 Ok(())513 }514515 #[benchmark]516 fn repartition_item() -> Result<(), BenchmarkError> {517 bench_init! {518 owner: sub; collection: collection(owner);519 sender: cross_from_sub(owner); owner: cross_sub;520 };521 let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?;522523 #[block]524 {525 <Pallet<T>>::repartition(&collection, &owner, item, 200)?;526 }527528 Ok(())529 }530531 #[benchmark]532 fn set_allowance_for_all() -> Result<(), BenchmarkError> {533 bench_init! {534 owner: sub; collection: collection(owner); owner: cross_from_sub;535 operator: cross_sub;536 };537538 #[block]539 {540 <Pallet<T>>::set_allowance_for_all(&collection, &owner, &operator, true)?;541 }542543 Ok(())544 }545546 #[benchmark]547 fn allowance_for_all() -> Result<(), BenchmarkError> {548 bench_init! {549 owner: sub; collection: collection(owner); owner: cross_from_sub;550 operator: cross_sub;551 };552553 #[block]554 {555 <Pallet<T>>::allowance_for_all(&collection, &owner, &operator);556 }557558 Ok(())559 }560561 #[benchmark]562 fn repair_item() -> Result<(), BenchmarkError> {563 bench_init! {564 owner: sub; collection: collection(owner);565 owner: cross_from_sub;566 };567 let item = create_max_item(&collection, &owner, [(owner.clone(), 100)])?;568569 #[block]570 {571 <Pallet<T>>::repair_item(&collection, item)?;572 }573574 Ok(())575 }576}pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -47,35 +47,27 @@
pub struct CommonWeights<T: Config>(PhantomData<T>);
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {
- <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(
- write_token_properties_total_weight::<T, _>(
- data.iter().map(|data| match data {
- up_data_structs::CreateItemData::ReFungible(rft_data) => {
- rft_data.properties.len() as u32
- }
- _ => 0,
- }),
- <SelfWeightOf<T>>::write_token_properties,
- ),
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(data.len() as u32),
+ data.iter().map(|data| match data {
+ up_data_structs::CreateItemData::ReFungible(rft_data) => {
+ rft_data.properties.len() as u32
+ }
+ _ => 0,
+ }),
)
}
fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {
match call {
- CreateItemExData::RefungibleMultipleOwners(i) => {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)
- .saturating_add(write_token_properties_total_weight::<T, _>(
- [i.properties.len() as u32].into_iter(),
- <SelfWeightOf<T>>::write_token_properties,
- ))
- }
- CreateItemExData::RefungibleMultipleItems(i) => {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)
- .saturating_add(write_token_properties_total_weight::<T, _>(
- i.iter().map(|d| d.properties.len() as u32),
- <SelfWeightOf<T>>::write_token_properties,
- ))
- }
+ CreateItemExData::RefungibleMultipleOwners(i) => mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32),
+ [i.properties.len() as u32].into_iter(),
+ ),
+ CreateItemExData::RefungibleMultipleItems(i) => mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32),
+ i.iter().map(|d| d.properties.len() as u32),
+ ),
_ => Weight::zero(),
}
}
@@ -138,6 +130,16 @@
}
}
+pub(crate) fn mint_with_props_weight<T: Config>(
+ create_no_data_weight: Weight,
+ tokens: impl Iterator<Item = u32> + Clone,
+) -> Weight {
+ create_no_data_weight.saturating_add(write_token_properties_total_weight::<T, _>(
+ tokens,
+ <SelfWeightOf<T>>::write_token_properties,
+ ))
+}
+
fn map_create_data<T: Config>(
data: up_data_structs::CreateItemData,
to: &T::CrossAccountId,
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -50,8 +50,10 @@
};
use crate::{
- common::CommonWeights, weights::WeightInfo, AccountBalance, Balance, Config, CreateItemData,
- Pallet, RefungibleHandle, SelfWeightOf, TokenProperties, TokensMinted, TotalSupply,
+ common::{mint_with_props_weight, CommonWeights},
+ weights::WeightInfo,
+ AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,
+ TokenProperties, TokensMinted, TotalSupply,
};
frontier_contract! {
@@ -661,7 +663,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() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri(
&mut self,
caller: Caller,
@@ -683,7 +685,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() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri_check_id(
&mut self,
caller: Caller,
@@ -1052,22 +1054,26 @@
}
/// @notice Function to mint a token.
- /// @param tokenProperties Properties of minted token
- #[weight(if token_properties.len() == 1 {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_properties.iter().next().unwrap().owners.len() as u32)
+ /// @param tokensData Data of minted token(s)
+ #[weight(if tokens_data.len() == 1 {
+ let token_data = tokens_data.first().unwrap();
+
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_data.owners.len() as u32),
+ [token_data.properties.len() as u32].into_iter(),
+ )
} else {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(token_properties.len() as u32)
- } + <SelfWeightOf<T>>::set_token_properties(token_properties.len() as u32))]
- fn mint_bulk_cross(
- &mut self,
- caller: Caller,
- token_properties: Vec<MintTokenData>,
- ) -> Result<bool> {
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(tokens_data.len() as u32),
+ tokens_data.iter().map(|d| d.properties.len() as u32),
+ )
+ })]
+ fn mint_bulk_cross(&mut self, caller: Caller, tokens_data: Vec<MintTokenData>) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
- let has_multiple_tokens = token_properties.len() > 1;
+ let has_multiple_tokens = tokens_data.len() > 1;
- let mut create_rft_data = Vec::with_capacity(token_properties.len());
- for MintTokenData { owners, properties } in token_properties {
+ let mut create_rft_data = Vec::with_capacity(tokens_data.len());
+ for MintTokenData { owners, properties } in tokens_data {
let has_multiple_owners = owners.len() > 1;
if has_multiple_tokens & has_multiple_owners {
return Err(
@@ -1108,7 +1114,12 @@
/// @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) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
+ #[weight(
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32),
+ tokens.iter().map(|_| 1),
+ )
+ )]
fn mint_bulk_with_token_uri(
&mut self,
caller: Caller,
@@ -1162,7 +1173,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() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [properties.len() as u32].into_iter()))]
fn mint_cross(
&mut self,
caller: Caller,