Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token properties and nesting weights #1007

Merged
merged 13 commits into from
Oct 13, 2023
30 changes: 0 additions & 30 deletions pallets/balances-adapter/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,10 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
Weight::default()
}

fn delete_collection_properties(_amount: u32) -> Weight {
Weight::default()
}

fn set_token_properties(_amount: u32) -> Weight {
Weight::default()
}

fn delete_token_properties(_amount: u32) -> Weight {
Weight::default()
}

fn set_token_property_permissions(_amount: u32) -> Weight {
Weight::default()
}
Expand All @@ -66,18 +58,6 @@ impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
Weight::default()
}

fn burn_recursively_self_raw() -> Weight {
Weight::default()
}

fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
Weight::default()
}

fn token_owner() -> Weight {
Weight::default()
}

fn set_allowance_for_all() -> Weight {
Weight::default()
}
Expand Down Expand Up @@ -128,16 +108,6 @@ impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}

fn burn_item_recursively(
&self,
_sender: <T>::CrossAccountId,
_token: TokenId,
_self_budget: &dyn up_data_structs::budget::Budget,
_breadth_budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}

fn set_collection_properties(
&self,
_sender: <T>::CrossAccountId,
Expand Down
46 changes: 5 additions & 41 deletions pallets/common/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ use sp_runtime::{traits::Zero, DispatchError};
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::{CollectionHandle, Config, Pallet};
use crate::{BenchmarkPropertyWriter, CollectionHandle, Config, Pallet};

const SEED: u32 = 1;

Expand Down Expand Up @@ -126,16 +125,6 @@ fn create_collection<T: Config>(
)
}

pub fn load_is_admin_and_property_permissions<T: Config>(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
) -> (bool, PropertiesPermissionMap) {
(
collection.is_owner_or_admin(sender),
<Pallet<T>>::property_permissions(collection.id),
)
}

/// Helper macros, which handles all benchmarking preparation in semi-declarative way
///
/// `name` is a substrate account
Expand Down Expand Up @@ -205,31 +194,6 @@ mod benchmarks {
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(())
}

#[benchmark]
fn check_accesslist() -> Result<(), BenchmarkError> {
bench_init! {
Expand Down Expand Up @@ -263,7 +227,7 @@ mod benchmarks {
}

#[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;
Expand All @@ -272,7 +236,7 @@ mod benchmarks {

#[block]
{
load_is_admin_and_property_permissions(&collection, &sender);
<BenchmarkPropertyWriter<T>>::load_collection_info(&&collection, &sender);
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions pallets/common/src/erc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where
///
/// @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)
Expand All @@ -139,7 +139,7 @@ where
/// 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
Expand Down
Loading