Skip to content

Commit 71be677

Browse files
authored
Merge pull request #1007 from UniqueNetwork/fix/token-properties-benchmarks
Fix token properties and nesting weights
2 parents 90ad566 + 478ee33 commit 71be677

File tree

32 files changed

+1659
-2294
lines changed

32 files changed

+1659
-2294
lines changed

pallets/balances-adapter/src/common.rs

-30
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,10 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
3030
Weight::default()
3131
}
3232

33-
fn delete_collection_properties(_amount: u32) -> Weight {
34-
Weight::default()
35-
}
36-
3733
fn set_token_properties(_amount: u32) -> Weight {
3834
Weight::default()
3935
}
4036

41-
fn delete_token_properties(_amount: u32) -> Weight {
42-
Weight::default()
43-
}
44-
4537
fn set_token_property_permissions(_amount: u32) -> Weight {
4638
Weight::default()
4739
}
@@ -66,18 +58,6 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
6658
Weight::default()
6759
}
6860

69-
fn burn_recursively_self_raw() -> Weight {
70-
Weight::default()
71-
}
72-
73-
fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
74-
Weight::default()
75-
}
76-
77-
fn token_owner() -> Weight {
78-
Weight::default()
79-
}
80-
8161
fn set_allowance_for_all() -> Weight {
8262
Weight::default()
8363
}
@@ -128,16 +108,6 @@ impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {
128108
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
129109
}
130110

131-
fn burn_item_recursively(
132-
&self,
133-
_sender: <T>::CrossAccountId,
134-
_token: TokenId,
135-
_self_budget: &dyn up_data_structs::budget::Budget,
136-
_breadth_budget: &dyn up_data_structs::budget::Budget,
137-
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
138-
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
139-
}
140-
141111
fn set_collection_properties(
142112
&self,
143113
_sender: <T>::CrossAccountId,

pallets/common/src/benchmarking.rs

+5-41
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ use sp_runtime::{traits::Zero, DispatchError};
2929
use sp_std::{vec, vec::Vec};
3030
use up_data_structs::{
3131
AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,
32-
NestingPermissions, PropertiesPermissionMap, Property, PropertyKey, PropertyValue,
33-
MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM,
34-
MAX_TOKEN_PREFIX_LENGTH,
32+
NestingPermissions, Property, PropertyKey, PropertyValue, MAX_COLLECTION_DESCRIPTION_LENGTH,
33+
MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM, MAX_TOKEN_PREFIX_LENGTH,
3534
};
3635

37-
use crate::{CollectionHandle, Config, Pallet};
36+
use crate::{BenchmarkPropertyWriter, CollectionHandle, Config, Pallet};
3837

3938
const SEED: u32 = 1;
4039

@@ -126,16 +125,6 @@ fn create_collection<T: Config>(
126125
)
127126
}
128127

129-
pub fn load_is_admin_and_property_permissions<T: Config>(
130-
collection: &CollectionHandle<T>,
131-
sender: &T::CrossAccountId,
132-
) -> (bool, PropertiesPermissionMap) {
133-
(
134-
collection.is_owner_or_admin(sender),
135-
<Pallet<T>>::property_permissions(collection.id),
136-
)
137-
}
138-
139128
/// Helper macros, which handles all benchmarking preparation in semi-declarative way
140129
///
141130
/// `name` is a substrate account
@@ -205,31 +194,6 @@ mod benchmarks {
205194
Ok(())
206195
}
207196

208-
#[benchmark]
209-
fn delete_collection_properties(
210-
b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
211-
) -> Result<(), BenchmarkError> {
212-
bench_init! {
213-
owner: sub; collection: collection(owner);
214-
owner: cross_from_sub;
215-
};
216-
let props = (0..b)
217-
.map(|p| Property {
218-
key: property_key(p as usize),
219-
value: property_value(),
220-
})
221-
.collect::<Vec<_>>();
222-
<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;
223-
let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();
224-
225-
#[block]
226-
{
227-
<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?;
228-
}
229-
230-
Ok(())
231-
}
232-
233197
#[benchmark]
234198
fn check_accesslist() -> Result<(), BenchmarkError> {
235199
bench_init! {
@@ -263,7 +227,7 @@ mod benchmarks {
263227
}
264228

265229
#[benchmark]
266-
fn init_token_properties_common() -> Result<(), BenchmarkError> {
230+
fn property_writer_load_collection_info() -> Result<(), BenchmarkError> {
267231
bench_init! {
268232
owner: sub; collection: collection(owner);
269233
sender: sub;
@@ -272,7 +236,7 @@ mod benchmarks {
272236

273237
#[block]
274238
{
275-
load_is_admin_and_property_permissions(&collection, &sender);
239+
<BenchmarkPropertyWriter<T>>::load_collection_info(&&collection, &sender);
276240
}
277241

278242
Ok(())

pallets/common/src/erc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ where
126126
///
127127
/// @param key Property key.
128128
#[solidity(hide)]
129-
#[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
129+
#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
130130
fn delete_collection_property(&mut self, caller: Caller, key: String) -> Result<()> {
131131
let caller = T::CrossAccountId::from_eth(caller);
132132
let key = <Vec<u8>>::from(key)
@@ -139,7 +139,7 @@ where
139139
/// Delete collection properties.
140140
///
141141
/// @param keys Properties keys.
142-
#[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]
142+
#[weight(<SelfWeightOf<T>>::set_collection_properties(keys.len() as u32))]
143143
fn delete_collection_properties(&mut self, caller: Caller, keys: Vec<String>) -> Result<()> {
144144
let caller = T::CrossAccountId::from_eth(caller);
145145
let keys = keys

0 commit comments

Comments
 (0)