difftreelog
feat(weight) added benchs for decompose weight Changed weight calculation system for `transfer` & `transfer_from` (NFT)
in: master
13 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6262,7 +6262,7 @@
[[package]]
name = "pallet-common"
-version = "0.1.13"
+version = "0.1.14"
dependencies = [
"ethereum",
"evm-coder",
@@ -6814,7 +6814,7 @@
[[package]]
name = "pallet-nonfungible"
-version = "0.1.13"
+version = "0.1.14"
dependencies = [
"evm-coder",
"frame-benchmarking",
pallets/app-promotion/src/lib.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -845,7 +845,6 @@
/// - `staker`: staker account.
pub fn total_staked_by_id(staker: impl EncodeLike<T::AccountId>) -> Option<BalanceOf<T>> {
let staked = Staked::<T>::iter_prefix((staker,))
- .into_iter()
.fold(<BalanceOf<T>>::default(), |acc, (_, (amount, _))| {
acc + amount
});
@@ -864,7 +863,6 @@
staker: impl EncodeLike<T::AccountId>,
) -> Option<Vec<(T::BlockNumber, BalanceOf<T>)>> {
let mut staked = Staked::<T>::iter_prefix((staker,))
- .into_iter()
.map(|(block, (amount, _))| (block, amount))
.collect::<Vec<_>>();
staked.sort_by_key(|(block, _)| *block);
@@ -883,12 +881,6 @@
Self::total_staked_by_id(s.as_sub())
})
}
-
- // pub fn cross_id_locked_balance(staker: T::CrossAccountId) -> BalanceOf<T> {
- // Self::get_locked_balance(staker.as_sub())
- // .map(|l| l.amount)
- // .unwrap_or_default()
- // }
/// Returns all relay block numbers when stake was made,
/// the amount of the stake.
pallets/common/CHANGELOG.mddiffbeforeafterboth1# Change Log23All notable changes to this project will be documented in this file.45<!-- bureaucrate goes here -->67## [0.1.13] - 2023-01-2089### Changed1011- Behavior of the `CommonWeightInfo::create_item` method.1213## [0.1.12] - 2022-11-161415### Changed1617- Behavior of the `setCollectionLimit` method.18 Removed method overload: single signature `(string, uint256)`19 is used for both cases.2021## [0.1.11] - 2022-11-122223### Changed2425- In the `Collection` solidity interface,26 the `allowed` function has been renamed to `allow_listed_cross`.27 Also `EthCrossAccount` type is now used as `user` arg.2829## [0.1.10] - 2022-11-023031### Changed3233- Use named structure `EthCrossAccount` in eth functions.3435## [0.1.9] - 2022-10-133637## Added3839- EVM event for `destroy_collection`.4041## [0.1.8] - 2022-08-244243## Added4445- Eth methods for collection46 - set_collection_sponsor_substrate47 - has_collection_pending_sponsor48 - remove_collection_sponsor49 - get_collection_sponsor50- Add convert function from `uint256` to `CrossAccountId`.5152## [0.1.7] - 2022-08-195354### Added5556- Add convert funtion from `CrossAccountId` to eth `uint256`.5758## [0.1.6] - 2022-08-165960### Added6162- New Ethereum API methods: changeOwner, changeOwner(Substrate) and verifyOwnerOrAdmin(Substrate).6364## [v0.1.5] 2022-08-166566### Other changes6768- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a6970- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf87172- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d9757374New methods allows to call `remove_prefix` with limit multiple times75in the same block76However, we don't use prefix removal limits, so upgrade is77straightforward7879Upstream-Change: https://github.com/paritytech/substrate/pull/114908081- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b8283## [0.1.3] - 2022-07-258485### Add8687- Some static property keys and values.8889## [0.1.2] - 2022-07-209091### Fixed9293- Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid94 mutability modifiers, causing invalid stub/abi generation.9596## [0.1.1] - 2022-07-149798### Added99100- Implementation of RPC method `token_owners` returning 10 owners in no particular order.101 This was an internal request to improve the web interface and support fractionalization event.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.13"
+version = "0.1.14"
[dependencies]
# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -22,8 +22,9 @@
use frame_benchmarking::{benchmarks, account};
use up_data_structs::{
CollectionMode, CollectionFlags, CreateCollectionData, CollectionId, Property, PropertyKey,
- PropertyValue, CollectionPermissions, NestingPermissions, MAX_COLLECTION_NAME_LENGTH,
- MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, MAX_PROPERTIES_PER_ITEM,
+ PropertyValue, CollectionPermissions, NestingPermissions, AccessMode,
+ MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
+ MAX_PROPERTIES_PER_ITEM,
};
use frame_support::{
traits::{Currency, Get},
@@ -193,4 +194,38 @@
<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;
let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();
}: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?}
+
+ check_accesslist{
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ sender: cross_from_sub(owner); receiver: cross_sub;
+ };
+
+ let mut collection_handle = <CollectionHandle<T>>::try_get(collection.id)?;
+ <Pallet<T>>::update_permissions(
+ &sender,
+ &mut collection_handle,
+ CollectionPermissions { access: Some(AccessMode::AllowList), ..Default::default() }
+ )?;
+
+ <Pallet<T>>::toggle_allowlist(
+ &collection,
+ &sender,
+ &sender,
+ true,
+ )?;
+
+ <Pallet<T>>::toggle_allowlist(
+ &collection,
+ &sender,
+ &receiver,
+ true,
+ )?;
+
+ assert_eq!(collection_handle.permissions.access(), AccessMode::AllowList);
+
+ collection_handle.check_allowlist(&sender)?;
+ collection_handle.check_allowlist(&receiver)?;
+
+ }: {collection_handle.check_allowlist(&sender)?;}
}
pallets/common/src/weights.rsdiffbeforeafterboth--- a/pallets/common/src/weights.rs
+++ b/pallets/common/src/weights.rs
@@ -36,6 +36,7 @@
pub trait WeightInfo {
fn set_collection_properties(b: u32, ) -> Weight;
fn delete_collection_properties(b: u32, ) -> Weight;
+ fn check_accesslist() -> Weight;
}
/// Weights for pallet_common using the Substrate node and recommended hardware.
@@ -66,11 +67,8 @@
Weight::from_parts(6_684_000, 43467)
// Standard Error: 67_984
.saturating_add(Weight::from_parts(21_502_829, 0).saturating_mul(b.into()))
- .saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
-}
-
// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: Common CollectionProperties (r:1 w:1)
@@ -98,8 +96,5 @@
Weight::from_parts(6_684_000, 43467)
// Standard Error: 67_984
.saturating_add(Weight::from_parts(21_502_829, 0).saturating_mul(b.into()))
- .saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
-}
-
pallets/nonfungible/CHANGELOG.mddiffbeforeafterboth--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -4,6 +4,12 @@
<!-- bureaucrate goes here -->
+## [0.1.14] - 2023-03-28
+
+### Fixed
+
+- The weight of `transfer` and `transfer_from`.
+
## [0.1.13] - 2023-01-20
### Fixed
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.13"
+version = "0.1.14"
[dependencies]
# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -146,14 +146,14 @@
let item = create_max_item(&collection, &owner, owner_eth.clone())?;
}: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?}
- transfer_from {
+ checks_for_transfer_from {
bench_init!{
owner: sub; collection: collection(owner);
owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;
};
let item = create_max_item(&collection, &owner, sender.clone())?;
<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;
- }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, &Unlimited)?}
+ }: {<Pallet<T>>::check_allowed(&collection, &spender, &sender, item, &Unlimited)?}
burn_from {
bench_init!{
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -23,7 +23,7 @@
};
use pallet_common::{
CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
- weights::WeightInfo as _,
+ weights::WeightInfo as _, SelfWeightOf as PalletCommonWeightOf,
};
use sp_runtime::DispatchError;
use sp_std::{vec::Vec, vec};
@@ -91,7 +91,7 @@
}
fn transfer() -> Weight {
- <SelfWeightOf<T>>::transfer()
+ <SelfWeightOf<T>>::transfer() + <PalletCommonWeightOf<T>>::check_accesslist() * 2
}
fn approve() -> Weight {
@@ -103,7 +103,7 @@
}
fn transfer_from() -> Weight {
- <SelfWeightOf<T>>::transfer_from()
+ Self::transfer() + <SelfWeightOf<T>>::checks_for_transfer_from()
}
fn burn_from() -> Weight {
@@ -325,10 +325,7 @@
) -> DispatchResultWithPostInfo {
ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
if amount == 1 {
- with_weight(
- <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),
- <CommonWeights<T>>::transfer(),
- )
+ <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget)
} else {
<Pallet<T>>::check_token_immediate_ownership(self, token, &from)?;
Ok(().into())
@@ -386,10 +383,7 @@
ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
if amount == 1 {
- with_weight(
- <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),
- <CommonWeights<T>>::transfer_from(),
- )
+ <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget)
} else {
<Pallet<T>>::check_allowed(self, &sender, &from, token, nesting_budget)?;
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -39,6 +39,7 @@
CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
eth::{self, TokenUri},
+ CommonWeightInfo,
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::call;
@@ -47,7 +48,7 @@
use crate::{
AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
- TokenProperties, SelfWeightOf, weights::WeightInfo,
+ TokenProperties, SelfWeightOf, weights::WeightInfo, common::CommonWeights,
};
/// Nft events.
@@ -458,7 +459,7 @@
/// @param from The current owner of the NFT
/// @param to The new owner
/// @param tokenId The NFT to transfer
- #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<CommonWeights<T>>::transfer_from())]
fn transfer_from(
&mut self,
caller: Caller,
@@ -475,7 +476,7 @@
.weight_calls_budget(<StructureWeight<T>>::find_parent());
<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)
- .map_err(dispatch_to_evm::<T>)?;
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(())
}
@@ -824,7 +825,7 @@
/// is the zero address. Throws if `tokenId` is not a valid NFT.
/// @param to The new owner
/// @param tokenId The NFT to transfer
- #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<CommonWeights<T>>::transfer())]
fn transfer(&mut self, caller: Caller, to: Address, token_id: U256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -833,7 +834,8 @@
.recorder
.weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;
+ <Pallet<T>>::transfer(self, &caller, &to, token, &budget)
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(())
}
@@ -842,7 +844,7 @@
/// is the zero address. Throws if `tokenId` is not a valid NFT.
/// @param to The new owner
/// @param tokenId The NFT to transfer
- #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<CommonWeights<T>>::transfer())]
fn transfer_cross(
&mut self,
caller: Caller,
@@ -856,7 +858,8 @@
.recorder
.weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;
+ <Pallet<T>>::transfer(self, &caller, &to, token, &budget)
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(())
}
@@ -866,7 +869,7 @@
/// @param from Cross acccount address of current owner
/// @param to Cross acccount address of new owner
/// @param tokenId The NFT to transfer
- #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<CommonWeights<T>>::transfer_from())]
fn transfer_from_cross(
&mut self,
caller: Caller,
@@ -882,7 +885,7 @@
.recorder
.weight_calls_budget(<StructureWeight<T>>::find_parent());
Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, &budget)
- .map_err(dispatch_to_evm::<T>)?;
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(())
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -108,7 +108,8 @@
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_common::{
Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
- eth::collection_id_to_address,
+ eth::collection_id_to_address, SelfWeightOf as PalletCommonWeightOf,
+ weights::WeightInfo as CommonWeightInfo,
};
use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
@@ -802,7 +803,7 @@
to: &T::CrossAccountId,
token: TokenId,
nesting_budget: &dyn Budget,
- ) -> DispatchResult {
+ ) -> DispatchResultWithPostInfo {
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed
@@ -812,7 +813,8 @@
<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
ensure!(&token_data.owner == from, <CommonError<T>>::NoPermission);
- if collection.permissions.access() == AccessMode::AllowList {
+ let is_allow_list_mode = collection.permissions.access() == AccessMode::AllowList;
+ if is_allow_list_mode {
collection.check_allowlist(from)?;
collection.check_allowlist(to)?;
}
@@ -884,7 +886,18 @@
to.clone(),
1,
));
- Ok(())
+
+ let actual_weight = match is_allow_list_mode {
+ true => Some(
+ <SelfWeightOf<T>>::transfer() + <PalletCommonWeightOf<T>>::check_accesslist() * 2,
+ ),
+ false => Some(<SelfWeightOf<T>>::transfer()),
+ };
+
+ Ok(PostDispatchInfo {
+ actual_weight,
+ pays_fee: Pays::Yes,
+ })
}
/// Batch operation to mint multiple NFT tokens.
@@ -1228,13 +1241,18 @@
to: &T::CrossAccountId,
token: TokenId,
nesting_budget: &dyn Budget,
- ) -> DispatchResult {
+ ) -> DispatchResultWithPostInfo {
Self::check_allowed(collection, spender, from, token, nesting_budget)?;
// =========
// Allowance is reset in [`transfer`]
- Self::transfer(collection, from, to, token, nesting_budget)
+ Self::transfer(collection, from, to, token, nesting_budget).map(|mut p| {
+ p.actual_weight = Some(
+ p.actual_weight.unwrap_or_default() + <SelfWeightOf<T>>::checks_for_transfer_from(),
+ );
+ p
+ })
}
/// Burn NFT token for `from` account.
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -43,7 +43,7 @@
fn transfer() -> Weight;
fn approve() -> Weight;
fn approve_from() -> Weight;
- fn transfer_from() -> Weight;
+ fn checks_for_transfer_from() -> Weight;
fn burn_from() -> Weight;
fn set_token_property_permissions(b: u32, ) -> Weight;
fn set_token_properties(b: u32, ) -> Weight;