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 // set_token_properties {425 // let b in 0..MAX_PROPERTIES_PER_ITEM;426 // bench_init!{427 // owner: sub; collection: collection(owner);428 // owner: cross_from_sub;429 // };430 // let perms = (0..b).map(|k| PropertyKeyPermission {431 // key: property_key(k as usize),432 // permission: PropertyPermission {433 // mutable: false,434 // collection_admin: true,435 // token_owner: true,436 // },437 // }).collect::<Vec<_>>();438 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;439 // let props = (0..b).map(|k| Property {440 // key: property_key(k as usize),441 // value: property_value(),442 // }).collect::<Vec<_>>();443 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;444 // }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?}445446 // load_token_properties {447 // bench_init!{448 // owner: sub; collection: collection(owner);449 // owner: cross_from_sub;450 // };451452 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;453 // }: {454 // pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(455 // &collection,456 // item,457 // )458 // }459460 // write_token_properties {461 // let b in 0..MAX_PROPERTIES_PER_ITEM;462 // bench_init!{463 // owner: sub; collection: collection(owner);464 // owner: cross_from_sub;465 // };466467 // let perms = (0..b).map(|k| PropertyKeyPermission {468 // key: property_key(k as usize),469 // permission: PropertyPermission {470 // mutable: false,471 // collection_admin: true,472 // token_owner: true,473 // },474 // }).collect::<Vec<_>>();475 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;476 // let props = (0..b).map(|k| Property {477 // key: property_key(k as usize),478 // value: property_value(),479 // }).collect::<Vec<_>>();480 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;481482 // let lazy_collection_info = pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(483 // &collection,484 // &owner,485 // );486 // }: {487 // let mut property_writer = pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);488489 // property_writer.write_token_properties(490 // item,491 // props.into_iter(),492 // crate::erc::ERC721TokenEvent::TokenChanged {493 // token_id: item.into(),494 // }495 // .to_log(T::ContractAddress::get()),496 // )?497 // }498499 #[benchmark]500 fn set_token_property_permissions(501 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,502 ) -> Result<(), BenchmarkError> {503 bench_init! {504 owner: sub; collection: collection(owner);505 owner: cross_from_sub;506 };507 let perms = (0..b)508 .map(|k| PropertyKeyPermission {509 key: property_key(k as usize),510 permission: PropertyPermission {511 mutable: false,512 collection_admin: false,513 token_owner: false,514 },515 })516 .collect::<Vec<_>>();517518 #[block]519 {520 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;521 }522523 Ok(())524 }525526 #[benchmark]527 fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {528 bench_init! {529 owner: sub; collection: collection(owner);530 owner: cross_from_sub;531 };532 let perms = (0..b)533 .map(|k| PropertyKeyPermission {534 key: property_key(k as usize),535 permission: PropertyPermission {536 mutable: false,537 collection_admin: true,538 token_owner: true,539 },540 })541 .collect::<Vec<_>>();542 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;543 let props = (0..b)544 .map(|k| Property {545 key: property_key(k as usize),546 value: property_value(),547 })548 .collect::<Vec<_>>();549 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;550551 #[block]552 {553 <Pallet<T>>::set_token_properties(554 &collection,555 &owner,556 item,557 props.into_iter(),558 &Unlimited,559 )?;560 }561562 Ok(())563 }564565 // TODO:566 #[benchmark]567 fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {568 // bench_init! {569 // owner: sub; collection: collection(owner);570 // owner: cross_from_sub;571 // };572573 // let perms = (0..b)574 // .map(|k| PropertyKeyPermission {575 // key: property_key(k as usize),576 // permission: PropertyPermission {577 // mutable: false,578 // collection_admin: true,579 // token_owner: true,580 // },581 // })582 // .collect::<Vec<_>>();583 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;584585 #[block]586 {}587 // let props = (0..b).map(|k| Property {588 // key: property_key(k as usize),589 // value: property_value(),590 // }).collect::<Vec<_>>();591 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;592593 // let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner)594 // let mut property_writer = pallet_common::collection_info_loaded_property_writer(595 // &collection,596 // is_collection_admin,597 // property_permissions,598 // );599600 // #[block]601 // {602 // property_writer.write_token_properties(603 // true,604 // item,605 // props.into_iter(),606 // crate::erc::ERC721TokenEvent::TokenChanged {607 // token_id: item.into(),608 // }609 // .to_log(T::ContractAddress::get()),610 // )?;611 // }612613 Ok(())614 }615616 #[benchmark]617 fn delete_token_properties(618 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,619 ) -> Result<(), BenchmarkError> {620 bench_init! {621 owner: sub; collection: collection(owner);622 owner: cross_from_sub;623 };624 let perms = (0..b)625 .map(|k| PropertyKeyPermission {626 key: property_key(k as usize),627 permission: PropertyPermission {628 mutable: true,629 collection_admin: true,630 token_owner: true,631 },632 })633 .collect::<Vec<_>>();634 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;635 let props = (0..b)636 .map(|k| Property {637 key: property_key(k as usize),638 value: property_value(),639 })640 .collect::<Vec<_>>();641 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;642 <Pallet<T>>::set_token_properties(643 &collection,644 &owner,645 item,646 props.into_iter(),647 &Unlimited,648 )?;649 let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();650651 #[block]652 {653 <Pallet<T>>::delete_token_properties(654 &collection,655 &owner,656 item,657 to_delete.into_iter(),658 &Unlimited,659 )?;660 }661662 Ok(())663 }664665 #[benchmark]666 fn repartition_item() -> Result<(), BenchmarkError> {667 bench_init! {668 owner: sub; collection: collection(owner);669 sender: cross_from_sub(owner); owner: cross_sub;670 };671 let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?;672673 #[block]674 {675 <Pallet<T>>::repartition(&collection, &owner, item, 200)?;676 }677678 Ok(())679 }680681 #[benchmark]682 fn token_owner() -> Result<(), BenchmarkError> {683 bench_init! {684 owner: sub; collection: collection(owner);685 sender: cross_from_sub(owner); owner: cross_sub;686 };687 let item = create_max_item(&collection, &sender, [(owner, 100)])?;688689 #[block]690 {691 <Pallet<T>>::token_owner(collection.id, item).unwrap();692 }693694 Ok(())695 }696697 #[benchmark]698 fn set_allowance_for_all() -> Result<(), BenchmarkError> {699 bench_init! {700 owner: sub; collection: collection(owner); owner: cross_from_sub;701 operator: cross_sub;702 };703704 #[block]705 {706 <Pallet<T>>::set_allowance_for_all(&collection, &owner, &operator, true)?;707 }708709 Ok(())710 }711712 #[benchmark]713 fn allowance_for_all() -> Result<(), BenchmarkError> {714 bench_init! {715 owner: sub; collection: collection(owner); owner: cross_from_sub;716 operator: cross_sub;717 };718719 #[block]720 {721 <Pallet<T>>::allowance_for_all(&collection, &owner, &operator);722 }723724 Ok(())725 }726727 #[benchmark]728 fn repair_item() -> Result<(), BenchmarkError> {729 bench_init! {730 owner: sub; collection: collection(owner);731 owner: cross_from_sub;732 };733 let item = create_max_item(&collection, &owner, [(owner.clone(), 100)])?;734735 #[block]736 {737 <Pallet<T>>::repair_item(&collection, item)?;738 }739740 Ok(())741 }742}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,