difftreelog
Merge pull request #907 from UniqueNetwork/feature/nft-transfer-correct-weight
in: master
feat(weight): added benchs for decompose weight
23 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",
@@ -6558,7 +6558,7 @@
[[package]]
name = "pallet-fungible"
-version = "0.1.10"
+version = "0.1.11"
dependencies = [
"evm-coder",
"frame-benchmarking",
@@ -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.mddiffbeforeafterboth--- a/pallets/common/CHANGELOG.md
+++ b/pallets/common/CHANGELOG.md
@@ -4,6 +4,12 @@
<!-- bureaucrate goes here -->
+## [0.1.14] - 2023-03-28
+
+### Added
+
+- Added benchmark to check if user is contained in AllowList (`check_accesslist()`).
+
## [0.1.13] - 2023-01-20
### Changed
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.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/>.1617#![allow(missing_docs)]1819use sp_std::vec::Vec;20use crate::{Config, CollectionHandle, Pallet};21use pallet_evm::account::CrossAccountId;22use frame_benchmarking::{benchmarks, account};23use up_data_structs::{24 CollectionMode, CollectionFlags, CreateCollectionData, CollectionId, Property, PropertyKey,25 PropertyValue, CollectionPermissions, NestingPermissions, MAX_COLLECTION_NAME_LENGTH,26 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, MAX_PROPERTIES_PER_ITEM,27};28use frame_support::{29 traits::{Currency, Get},30 pallet_prelude::ConstU32,31 BoundedVec,32};33use core::convert::TryInto;34use sp_runtime::DispatchError;3536const SEED: u32 = 1;3738pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {39 create_var_data::<S>(S)40}41pub fn create_u16_data<const S: u32>() -> BoundedVec<u16, ConstU32<S>> {42 (0..S)43 .map(|v| (v & 0xffff) as u16)44 .collect::<Vec<_>>()45 .try_into()46 .unwrap()47}48pub fn create_var_data<const S: u32>(size: u32) -> BoundedVec<u8, ConstU32<S>> {49 assert!(50 size <= S,51 "size ({}) should be less within bound ({})",52 size,53 S54 );55 (0..size)56 .map(|v| (v & 0xff) as u8)57 .collect::<Vec<_>>()58 .try_into()59 .unwrap()60}61pub fn property_key(id: usize) -> PropertyKey {62 #[cfg(not(feature = "std"))]63 use alloc::string::ToString;64 let mut data = create_data();65 // No DerefMut available for .fill66 for i in 0..data.len() {67 data[i] = b'0';68 }69 let bytes = id.to_string();70 let len = data.len();71 data[len - bytes.len()..].copy_from_slice(&bytes.as_bytes());72 data73}74pub fn property_value() -> PropertyValue {75 create_data()76}7778pub fn create_collection_raw<T: Config, R>(79 owner: T::CrossAccountId,80 mode: CollectionMode,81 handler: impl FnOnce(82 T::CrossAccountId,83 CreateCollectionData<T::AccountId>,84 ) -> Result<CollectionId, DispatchError>,85 cast: impl FnOnce(CollectionHandle<T>) -> R,86) -> Result<R, DispatchError> {87 <T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());88 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();89 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();90 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();91 handler(92 owner,93 CreateCollectionData {94 mode,95 name,96 description,97 token_prefix,98 permissions: Some(CollectionPermissions {99 nesting: Some(NestingPermissions {100 token_owner: false,101 collection_admin: false,102 restricted: None,103 #[cfg(feature = "runtime-benchmarks")]104 permissive: true,105 }),106 mint_mode: Some(true),107 ..Default::default()108 }),109 ..Default::default()110 },111 )112 .and_then(CollectionHandle::try_get)113 .map(cast)114}115fn create_collection<T: Config>(116 owner: T::CrossAccountId,117) -> Result<CollectionHandle<T>, DispatchError> {118 create_collection_raw(119 owner,120 CollectionMode::NFT,121 |owner: T::CrossAccountId, data| {122 <Pallet<T>>::init_collection(owner.clone(), owner, data, CollectionFlags::default())123 },124 |h| h,125 )126}127128/// Helper macros, which handles all benchmarking preparation in semi-declarative way129///130/// `name` is a substrate account131/// - name: sub[(id)]132/// `name` is a collection with owner `owner`133/// - name: collection(owner)134/// `name` is a cross account based on substrate135/// - name: cross_sub[(id)]136/// `name` is a cross account, which maps to substrate account `name`137/// - name: cross_from_sub138/// `name` is a cross account, which maps to substrate account `other_name`139/// - name: cross_from_sub(other_name)140#[macro_export]141macro_rules! bench_init {142 ($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {143 let $name: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);144 bench_init!($($rest)*);145 };146 ($name:ident: collection($owner:ident); $($rest:tt)*) => {147 let $name = create_collection::<T>(T::CrossAccountId::from_sub($owner.clone()))?;148 bench_init!($($rest)*);149 };150 ($name:ident: cross; $($rest:tt)*) => {151 let $name = T::CrossAccountId::from_sub($name);152 bench_init!($($rest)*);153 };154 ($name:ident: cross_sub $(($id:expr))?; $($rest:tt)*) => {155 let account: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);156 let $name = T::CrossAccountId::from_sub(account);157 bench_init!($($rest)*);158 };159 ($name:ident: cross_from_sub; $($rest:tt)*) => {160 let $name = T::CrossAccountId::from_sub($name);161 bench_init!($($rest)*);162 };163 ($name:ident: cross_from_sub($from:ident); $($rest:tt)*) => {164 let $name = T::CrossAccountId::from_sub($from);165 bench_init!($($rest)*);166 };167 () => {}168}169170benchmarks! {171 set_collection_properties {172 let b in 0..MAX_PROPERTIES_PER_ITEM;173 bench_init!{174 owner: sub; collection: collection(owner);175 owner: cross_from_sub;176 };177 let props = (0..b).map(|p| Property {178 key: property_key(p as usize),179 value: property_value(),180 }).collect::<Vec<_>>();181 }: {<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?}182183 delete_collection_properties {184 let b in 0..MAX_PROPERTIES_PER_ITEM;185 bench_init!{186 owner: sub; collection: collection(owner);187 owner: cross_from_sub;188 };189 let props = (0..b).map(|p| Property {190 key: property_key(p as usize),191 value: property_value(),192 }).collect::<Vec<_>>();193 <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;194 let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();195 }: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?}196}1// 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/>.1617#![allow(missing_docs)]1819use sp_std::vec::Vec;20use crate::{Config, CollectionHandle, Pallet};21use pallet_evm::account::CrossAccountId;22use frame_benchmarking::{benchmarks, account};23use up_data_structs::{24 CollectionMode, CollectionFlags, CreateCollectionData, CollectionId, Property, PropertyKey,25 PropertyValue, CollectionPermissions, NestingPermissions, AccessMode,26 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,27 MAX_PROPERTIES_PER_ITEM,28};29use frame_support::{30 traits::{Currency, Get},31 pallet_prelude::ConstU32,32 BoundedVec,33};34use core::convert::TryInto;35use sp_runtime::DispatchError;3637const SEED: u32 = 1;3839pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {40 create_var_data::<S>(S)41}42pub fn create_u16_data<const S: u32>() -> BoundedVec<u16, ConstU32<S>> {43 (0..S)44 .map(|v| (v & 0xffff) as u16)45 .collect::<Vec<_>>()46 .try_into()47 .unwrap()48}49pub fn create_var_data<const S: u32>(size: u32) -> BoundedVec<u8, ConstU32<S>> {50 assert!(51 size <= S,52 "size ({}) should be less within bound ({})",53 size,54 S55 );56 (0..size)57 .map(|v| (v & 0xff) as u8)58 .collect::<Vec<_>>()59 .try_into()60 .unwrap()61}62pub fn property_key(id: usize) -> PropertyKey {63 #[cfg(not(feature = "std"))]64 use alloc::string::ToString;65 let mut data = create_data();66 // No DerefMut available for .fill67 for i in 0..data.len() {68 data[i] = b'0';69 }70 let bytes = id.to_string();71 let len = data.len();72 data[len - bytes.len()..].copy_from_slice(&bytes.as_bytes());73 data74}75pub fn property_value() -> PropertyValue {76 create_data()77}7879pub fn create_collection_raw<T: Config, R>(80 owner: T::CrossAccountId,81 mode: CollectionMode,82 handler: impl FnOnce(83 T::CrossAccountId,84 CreateCollectionData<T::AccountId>,85 ) -> Result<CollectionId, DispatchError>,86 cast: impl FnOnce(CollectionHandle<T>) -> R,87) -> Result<R, DispatchError> {88 <T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());89 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();90 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();91 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();92 handler(93 owner,94 CreateCollectionData {95 mode,96 name,97 description,98 token_prefix,99 permissions: Some(CollectionPermissions {100 nesting: Some(NestingPermissions {101 token_owner: false,102 collection_admin: false,103 restricted: None,104 #[cfg(feature = "runtime-benchmarks")]105 permissive: true,106 }),107 mint_mode: Some(true),108 ..Default::default()109 }),110 ..Default::default()111 },112 )113 .and_then(CollectionHandle::try_get)114 .map(cast)115}116fn create_collection<T: Config>(117 owner: T::CrossAccountId,118) -> Result<CollectionHandle<T>, DispatchError> {119 create_collection_raw(120 owner,121 CollectionMode::NFT,122 |owner: T::CrossAccountId, data| {123 <Pallet<T>>::init_collection(owner.clone(), owner, data, CollectionFlags::default())124 },125 |h| h,126 )127}128129/// Helper macros, which handles all benchmarking preparation in semi-declarative way130///131/// `name` is a substrate account132/// - name: sub[(id)]133/// `name` is a collection with owner `owner`134/// - name: collection(owner)135/// `name` is a cross account based on substrate136/// - name: cross_sub[(id)]137/// `name` is a cross account, which maps to substrate account `name`138/// - name: cross_from_sub139/// `name` is a cross account, which maps to substrate account `other_name`140/// - name: cross_from_sub(other_name)141#[macro_export]142macro_rules! bench_init {143 ($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {144 let $name: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);145 bench_init!($($rest)*);146 };147 ($name:ident: collection($owner:ident); $($rest:tt)*) => {148 let $name = create_collection::<T>(T::CrossAccountId::from_sub($owner.clone()))?;149 bench_init!($($rest)*);150 };151 ($name:ident: cross; $($rest:tt)*) => {152 let $name = T::CrossAccountId::from_sub($name);153 bench_init!($($rest)*);154 };155 ($name:ident: cross_sub $(($id:expr))?; $($rest:tt)*) => {156 let account: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);157 let $name = T::CrossAccountId::from_sub(account);158 bench_init!($($rest)*);159 };160 ($name:ident: cross_from_sub; $($rest:tt)*) => {161 let $name = T::CrossAccountId::from_sub($name);162 bench_init!($($rest)*);163 };164 ($name:ident: cross_from_sub($from:ident); $($rest:tt)*) => {165 let $name = T::CrossAccountId::from_sub($from);166 bench_init!($($rest)*);167 };168 () => {}169}170171benchmarks! {172 set_collection_properties {173 let b in 0..MAX_PROPERTIES_PER_ITEM;174 bench_init!{175 owner: sub; collection: collection(owner);176 owner: cross_from_sub;177 };178 let props = (0..b).map(|p| Property {179 key: property_key(p as usize),180 value: property_value(),181 }).collect::<Vec<_>>();182 }: {<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?}183184 delete_collection_properties {185 let b in 0..MAX_PROPERTIES_PER_ITEM;186 bench_init!{187 owner: sub; collection: collection(owner);188 owner: cross_from_sub;189 };190 let props = (0..b).map(|p| Property {191 key: property_key(p as usize),192 value: property_value(),193 }).collect::<Vec<_>>();194 <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;195 let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();196 }: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?}197198 check_accesslist{199 bench_init!{200 owner: sub; collection: collection(owner);201 sender: cross_from_sub(owner);202 };203204 let mut collection_handle = <CollectionHandle<T>>::try_get(collection.id)?;205 <Pallet<T>>::update_permissions(206 &sender,207 &mut collection_handle,208 CollectionPermissions { access: Some(AccessMode::AllowList), ..Default::default() }209 )?;210211 <Pallet<T>>::toggle_allowlist(212 &collection,213 &sender,214 &sender,215 true,216 )?;217218 assert_eq!(collection_handle.permissions.access(), AccessMode::AllowList);219220 }: {collection_handle.check_allowlist(&sender)?;}221}pallets/common/src/helpers.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/common/src/helpers.rs
@@ -0,0 +1,30 @@
+//! # Helpers module
+//!
+//! The module contains helpers.
+//!
+use frame_support::{
+ pallet_prelude::DispatchResultWithPostInfo,
+ weights::Weight,
+ dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo},
+};
+
+/// Add weight for a `DispatchResultWithPostInfo`
+///
+/// - `target`: DispatchResultWithPostInfo to which weight will be added
+/// - `additional_weight`: Weight to be added
+pub fn add_weight_to_post_info(target: &mut DispatchResultWithPostInfo, additional_weight: Weight) {
+ match target {
+ Ok(PostDispatchInfo {
+ actual_weight: Some(weight),
+ ..
+ })
+ | Err(DispatchErrorWithPostInfo {
+ post_info: PostDispatchInfo {
+ actual_weight: Some(weight),
+ ..
+ },
+ ..
+ }) => *weight += additional_weight,
+ _ => {}
+ }
+}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -92,9 +92,9 @@
pub mod dispatch;
pub mod erc;
pub mod eth;
+pub mod helpers;
#[allow(missing_docs)]
pub mod weights;
-
/// Weight info.
pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
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.
@@ -69,6 +70,16 @@
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
+ /// Storage: Common Allowlist (r:1 w:0)
+ /// Proof: Common Allowlist (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen)
+ fn check_accesslist() -> Weight {
+ // Proof Size summary in bytes:
+ // Measured: `340`
+ // Estimated: `2545`
+ // Minimum execution time: 2_887_000 picoseconds.
+ Weight::from_parts(3_072_000, 2545)
+ .saturating_add(T::DbWeight::get().reads(1_u64))
+ }
}
// For backwards compatibility and tests
@@ -101,5 +112,15 @@
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
+ /// Storage: Common Allowlist (r:1 w:0)
+ /// Proof: Common Allowlist (max_values: None, max_size: Some(70), added: 2545, mode: MaxEncodedLen)
+ fn check_accesslist() -> Weight {
+ // Proof Size summary in bytes:
+ // Measured: `340`
+ // Estimated: `2545`
+ // Minimum execution time: 2_887_000 picoseconds.
+ Weight::from_parts(3_072_000, 2545)
+ .saturating_add(RocksDbWeight::get().reads(1_u64))
+ }
}
pallets/foreign-assets/src/impl_fungibles.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/impl_fungibles.rs
+++ b/pallets/foreign-assets/src/impl_fungibles.rs
@@ -452,7 +452,8 @@
&T::CrossAccountId::from_sub(dest.clone()),
amount.into(),
&Value::new(0),
- )?;
+ )
+ .map_err(|e| e.error)?;
Ok(amount)
}
pallets/fungible/CHANGELOG.mddiffbeforeafterboth--- a/pallets/fungible/CHANGELOG.md
+++ b/pallets/fungible/CHANGELOG.md
@@ -4,6 +4,12 @@
<!-- bureaucrate goes here -->
+## [0.1.11] - 2023-03-28
+
+### Fixed
+
+- The weight of `transfer` and `transfer_from`.
+
## [0.1.10] - 2023-02-01
### Added
pallets/fungible/Cargo.tomldiffbeforeafterboth--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -2,7 +2,7 @@
edition = "2021"
license = "GPLv3"
name = "pallet-fungible"
-version = "0.1.10"
+version = "0.1.11"
[dependencies]
# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -66,7 +66,7 @@
<Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200), &Unlimited)?;
}: {<Pallet<T>>::burn(&collection, &burner, 100)?}
- transfer {
+ transfer_raw {
bench_init!{
owner: sub; collection: collection(owner);
owner: cross_from_sub; sender: cross_sub; to: cross_sub;
@@ -92,14 +92,22 @@
<Pallet<T>>::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?;
}: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?}
- transfer_from {
+ check_allowed_raw {
bench_init!{
owner: sub; collection: collection(owner);
- owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;
+ owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
};
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;
- }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100, &Unlimited)?}
+ }: {<Pallet<T>>::check_allowed(&collection, &spender, &sender, 200, &Unlimited)?;}
+
+ set_allowance_unchecked_raw {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
+ };
+ <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
+ }: {<Pallet<T>>::set_allowance_unchecked(&collection, &sender, &spender, 200);}
burn_from {
bench_init!{
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -22,7 +22,7 @@
};
use pallet_common::{
CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
- weights::WeightInfo as _,
+ weights::WeightInfo as _, SelfWeightOf as PalletCommonWeightOf,
};
use pallet_structure::Error as StructureError;
use sp_runtime::ArithmeticError;
@@ -78,7 +78,7 @@
}
fn transfer() -> Weight {
- <SelfWeightOf<T>>::transfer()
+ <SelfWeightOf<T>>::transfer_raw() + <PalletCommonWeightOf<T>>::check_accesslist() * 2
}
fn approve() -> Weight {
@@ -90,7 +90,9 @@
}
fn transfer_from() -> Weight {
- <SelfWeightOf<T>>::transfer_from()
+ Self::transfer()
+ + <SelfWeightOf<T>>::check_allowed_raw()
+ + <SelfWeightOf<T>>::set_allowance_unchecked_raw()
}
fn burn_from() -> Weight {
@@ -232,10 +234,7 @@
<Error<T>>::FungibleItemsHaveNoId
);
- with_weight(
- <Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget),
- <CommonWeights<T>>::transfer(),
- )
+ <Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget)
}
fn approve(
@@ -289,10 +288,7 @@
<Error<T>>::FungibleItemsHaveNoId
);
- with_weight(
- <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, nesting_budget),
- <CommonWeights<T>>::transfer_from(),
- )
+ <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, nesting_budget)
}
fn burn_from(
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -26,6 +26,7 @@
CollectionHandle,
erc::{CommonEvmHandler, PrecompileResult, CollectionCall},
eth::CrossAddress,
+ CommonWeightInfo as _,
};
use sp_std::vec::Vec;
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
@@ -39,7 +40,7 @@
use crate::{
Allowance, Balance, Config, FungibleHandle, Pallet, TotalSupply, SelfWeightOf,
- weights::WeightInfo,
+ weights::WeightInfo, common::CommonWeights,
};
frontier_contract! {
@@ -99,7 +100,7 @@
let balance = <Balance<T>>::get((self.id, owner));
Ok(balance.into())
}
- #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<CommonWeights<T>>::transfer())]
fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -112,7 +113,7 @@
Ok(true)
}
- #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<CommonWeights<T>>::transfer_from())]
fn transfer_from(
&mut self,
caller: Caller,
@@ -129,7 +130,7 @@
.weight_calls_budget(<StructureWeight<T>>::find_parent());
<Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
- .map_err(dispatch_to_evm::<T>)?;
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(true)
}
#[weight(<SelfWeightOf<T>>::approve())]
@@ -201,7 +202,7 @@
let budget = self
.recorder
.weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::create_item(&self, &caller, (to, amount), &budget)
+ <Pallet<T>>::create_item(self, &caller, (to, amount), &budget)
.map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
@@ -289,7 +290,7 @@
Ok(true)
}
- #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<CommonWeights<T>>::transfer())]
fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
@@ -302,7 +303,7 @@
Ok(true)
}
- #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<CommonWeights<T>>::transfer_from())]
fn transfer_from_cross(
&mut self,
caller: Caller,
@@ -319,7 +320,7 @@
.weight_calls_budget(<StructureWeight<T>>::find_parent());
<Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
- .map_err(dispatch_to_evm::<T>)?;
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
Ok(true)
}
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -80,7 +80,11 @@
use core::ops::Deref;
use evm_coder::ToLog;
-use frame_support::ensure;
+use frame_support::{
+ ensure,
+ pallet_prelude::{DispatchResultWithPostInfo, Pays},
+ dispatch::PostDispatchInfo,
+};
use pallet_evm::account::CrossAccountId;
use up_data_structs::{
AccessMode, CollectionId, CollectionFlags, TokenId, CreateCollectionData,
@@ -88,7 +92,8 @@
};
use pallet_common::{
Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
- eth::collection_id_to_address,
+ eth::collection_id_to_address, SelfWeightOf as PalletCommonWeightOf,
+ weights::WeightInfo as CommonWeightInfo, helpers::add_weight_to_post_info,
};
use pallet_evm::Pallet as PalletEvm;
use pallet_structure::Pallet as PalletStructure;
@@ -96,7 +101,7 @@
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
-
+use weights::WeightInfo;
pub use pallet::*;
use crate::erc::ERC20Events;
@@ -389,18 +394,20 @@
to: &T::CrossAccountId,
amount: u128,
nesting_budget: &dyn Budget,
- ) -> DispatchResult {
+ ) -> DispatchResultWithPostInfo {
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed,
);
+ let mut actual_weight = <SelfWeightOf<T>>::transfer_raw();
+
if collection.permissions.access() == AccessMode::AllowList {
collection.check_allowlist(from)?;
collection.check_allowlist(to)?;
+ actual_weight += <PalletCommonWeightOf<T>>::check_accesslist() * 2;
}
<PalletCommon<T>>::ensure_correct_receiver(to)?;
-
let balance_from = <Balance<T>>::get((collection.id, from))
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
@@ -451,7 +458,11 @@
to.clone(),
amount,
));
- Ok(())
+
+ Ok(PostDispatchInfo {
+ actual_weight: Some(actual_weight),
+ pays_fee: Pays::Yes,
+ })
}
/// Minting tokens for multiple IDs.
@@ -464,8 +475,8 @@
nesting_budget: &dyn Budget,
) -> DispatchResult {
let total_supply = data
- .iter()
- .map(|(_, v)| *v)
+ .values()
+ .copied()
.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {
acc.checked_add(v)
})
@@ -718,7 +729,6 @@
/// Same as the [`transfer`][`Pallet::transfer`] but spender doesn't needs to be an owner of the token pieces.
/// The owner should set allowance for the spender to transfer pieces.
/// See [`set_allowance`][`Pallet::set_allowance`] for more details.
-
pub fn transfer_from(
collection: &FungibleHandle<T>,
spender: &T::CrossAccountId,
@@ -726,16 +736,23 @@
to: &T::CrossAccountId,
amount: u128,
nesting_budget: &dyn Budget,
- ) -> DispatchResult {
+ ) -> DispatchResultWithPostInfo {
let allowance = Self::check_allowed(collection, spender, from, amount, nesting_budget)?;
// =========
- Self::transfer(collection, from, to, amount, nesting_budget)?;
+ let mut result = Self::transfer(collection, from, to, amount, nesting_budget);
+ add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());
+ result?;
+
if let Some(allowance) = allowance {
Self::set_allowance_unchecked(collection, from, spender, allowance);
+ add_weight_to_post_info(
+ &mut result,
+ <SelfWeightOf<T>>::set_allowance_unchecked_raw(),
+ )
}
- Ok(())
+ result
}
/// Burn fungible tokens from the account.
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -37,10 +37,11 @@
fn create_item() -> Weight;
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
- fn transfer() -> Weight;
+ fn transfer_raw() -> Weight;
fn approve() -> Weight;
fn approve_from() -> Weight;
- fn transfer_from() -> Weight;
+ fn check_allowed_raw() -> Weight;
+ fn set_allowance_unchecked_raw() -> Weight;
fn burn_from() -> Weight;
}
@@ -94,12 +95,12 @@
}
/// Storage: Fungible Balance (r:2 w:2)
/// Proof: Fungible Balance (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen)
- fn transfer() -> Weight {
+ fn transfer_raw() -> Weight {
// Proof Size summary in bytes:
// Measured: `182`
// Estimated: `5104`
- // Minimum execution time: 13_832_000 picoseconds.
- Weight::from_parts(14_064_000, 5104)
+ // Minimum execution time: 6_678_000 picoseconds.
+ Weight::from_parts(7_151_000, 5104)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
@@ -129,19 +130,26 @@
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
- /// Storage: Fungible Allowance (r:1 w:1)
+ /// Storage: Fungible Allowance (r:1 w:0)
/// Proof: Fungible Allowance (max_values: None, max_size: Some(93), added: 2568, mode: MaxEncodedLen)
- /// Storage: Fungible Balance (r:2 w:2)
- /// Proof: Fungible Balance (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen)
- fn transfer_from() -> Weight {
+ fn check_allowed_raw() -> Weight {
// Proof Size summary in bytes:
- // Measured: `300`
- // Estimated: `7672`
- // Minimum execution time: 21_667_000 picoseconds.
- Weight::from_parts(22_166_000, 7672)
- .saturating_add(T::DbWeight::get().reads(3_u64))
- .saturating_add(T::DbWeight::get().writes(3_u64))
+ // Measured: `210`
+ // Estimated: `2568`
+ // Minimum execution time: 2_842_000 picoseconds.
+ Weight::from_parts(3_077_000, 2568)
+ .saturating_add(T::DbWeight::get().reads(1_u64))
}
+ /// Storage: Fungible Allowance (r:0 w:1)
+ /// Proof: Fungible Allowance (max_values: None, max_size: Some(93), added: 2568, mode: MaxEncodedLen)
+ fn set_allowance_unchecked_raw() -> Weight {
+ // Proof Size summary in bytes:
+ // Measured: `0`
+ // Estimated: `0`
+ // Minimum execution time: 2_532_000 picoseconds.
+ Weight::from_parts(2_680_000, 0)
+ .saturating_add(T::DbWeight::get().writes(1_u64))
+ }
/// Storage: Fungible Allowance (r:1 w:1)
/// Proof: Fungible Allowance (max_values: None, max_size: Some(93), added: 2568, mode: MaxEncodedLen)
/// Storage: Fungible TotalSupply (r:1 w:1)
@@ -208,12 +216,12 @@
}
/// Storage: Fungible Balance (r:2 w:2)
/// Proof: Fungible Balance (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen)
- fn transfer() -> Weight {
+ fn transfer_raw() -> Weight {
// Proof Size summary in bytes:
// Measured: `182`
// Estimated: `5104`
- // Minimum execution time: 13_832_000 picoseconds.
- Weight::from_parts(14_064_000, 5104)
+ // Minimum execution time: 6_678_000 picoseconds.
+ Weight::from_parts(7_151_000, 5104)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
@@ -243,18 +251,25 @@
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
- /// Storage: Fungible Allowance (r:1 w:1)
+ /// Storage: Fungible Allowance (r:1 w:0)
/// Proof: Fungible Allowance (max_values: None, max_size: Some(93), added: 2568, mode: MaxEncodedLen)
- /// Storage: Fungible Balance (r:2 w:2)
- /// Proof: Fungible Balance (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen)
- fn transfer_from() -> Weight {
+ fn check_allowed_raw() -> Weight {
// Proof Size summary in bytes:
- // Measured: `300`
- // Estimated: `7672`
- // Minimum execution time: 21_667_000 picoseconds.
- Weight::from_parts(22_166_000, 7672)
- .saturating_add(RocksDbWeight::get().reads(3_u64))
- .saturating_add(RocksDbWeight::get().writes(3_u64))
+ // Measured: `210`
+ // Estimated: `2568`
+ // Minimum execution time: 2_842_000 picoseconds.
+ Weight::from_parts(3_077_000, 2568)
+ .saturating_add(RocksDbWeight::get().reads(1_u64))
+ }
+ /// Storage: Fungible Allowance (r:0 w:1)
+ /// Proof: Fungible Allowance (max_values: None, max_size: Some(93), added: 2568, mode: MaxEncodedLen)
+ fn set_allowance_unchecked_raw() -> Weight {
+ // Proof Size summary in bytes:
+ // Measured: `0`
+ // Estimated: `0`
+ // Minimum execution time: 2_532_000 picoseconds.
+ Weight::from_parts(2_680_000, 0)
+ .saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: Fungible Allowance (r:1 w:1)
/// Proof: Fungible Allowance (max_values: None, max_size: Some(93), added: 2568, mode: MaxEncodedLen)
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
@@ -121,7 +121,7 @@
}
}: {<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?}
- transfer {
+ transfer_raw {
bench_init!{
owner: sub; collection: collection(owner);
owner: cross_from_sub; sender: cross_sub; receiver: cross_sub;
@@ -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 {
+ check_allowed_raw {
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_raw() + <PalletCommonWeightOf<T>>::check_accesslist() * 2
}
fn approve() -> Weight {
@@ -103,7 +103,7 @@
}
fn transfer_from() -> Weight {
- <SelfWeightOf<T>>::transfer_from()
+ Self::transfer() + <SelfWeightOf<T>>::check_allowed_raw()
}
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, helpers::add_weight_to_post_info,
};
use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
@@ -802,12 +803,13 @@
to: &T::CrossAccountId,
token: TokenId,
nesting_budget: &dyn Budget,
- ) -> DispatchResult {
+ ) -> DispatchResultWithPostInfo {
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed
);
+ let mut actual_weight = <SelfWeightOf<T>>::transfer_raw();
let token_data =
<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
ensure!(&token_data.owner == from, <CommonError<T>>::NoPermission);
@@ -815,6 +817,7 @@
if collection.permissions.access() == AccessMode::AllowList {
collection.check_allowlist(from)?;
collection.check_allowlist(to)?;
+ actual_weight += <PalletCommonWeightOf<T>>::check_accesslist() * 2;
}
<PalletCommon<T>>::ensure_correct_receiver(to)?;
@@ -884,7 +887,11 @@
to.clone(),
1,
));
- Ok(())
+
+ Ok(PostDispatchInfo {
+ actual_weight: Some(actual_weight),
+ pays_fee: Pays::Yes,
+ })
}
/// Batch operation to mint multiple NFT tokens.
@@ -1228,13 +1235,15 @@
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)
+ let mut result = Self::transfer(collection, from, to, token, nesting_budget);
+ add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::check_allowed_raw());
+ result
}
/// Burn NFT token for `from` account.
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -40,10 +40,10 @@
fn burn_item() -> Weight;
fn burn_recursively_self_raw() -> Weight;
fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;
- fn transfer() -> Weight;
+ fn transfer_raw() -> Weight;
fn approve() -> Weight;
fn approve_from() -> Weight;
- fn transfer_from() -> Weight;
+ fn check_allowed_raw() -> Weight;
fn burn_from() -> Weight;
fn set_token_property_permissions(b: u32, ) -> Weight;
fn set_token_properties(b: u32, ) -> Weight;
@@ -217,12 +217,12 @@
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
/// Storage: Nonfungible Owned (r:0 w:2)
/// Proof: Nonfungible Owned (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen)
- fn transfer() -> Weight {
+ fn transfer_raw() -> Weight {
// Proof Size summary in bytes:
// Measured: `412`
// Estimated: `10144`
- // Minimum execution time: 18_629_000 picoseconds.
- Weight::from_parts(18_997_000, 10144)
+ // Minimum execution time: 9_307_000 picoseconds.
+ Weight::from_parts(10_108_000, 10144)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
@@ -252,22 +252,15 @@
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
- /// Storage: Nonfungible Allowance (r:1 w:1)
+ /// Storage: Nonfungible Allowance (r:1 w:0)
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
- /// Storage: Nonfungible TokenData (r:1 w:1)
- /// Proof: Nonfungible TokenData (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
- /// Storage: Nonfungible AccountBalance (r:2 w:2)
- /// Proof: Nonfungible AccountBalance (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
- /// Storage: Nonfungible Owned (r:0 w:2)
- /// Proof: Nonfungible Owned (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen)
- fn transfer_from() -> Weight {
+ fn check_allowed_raw() -> Weight {
// Proof Size summary in bytes:
- // Measured: `527`
- // Estimated: `10144`
- // Minimum execution time: 24_919_000 picoseconds.
- Weight::from_parts(25_333_000, 10144)
- .saturating_add(T::DbWeight::get().reads(4_u64))
- .saturating_add(T::DbWeight::get().writes(6_u64))
+ // Measured: `394`
+ // Estimated: `2532`
+ // Minimum execution time: 2_668_000 picoseconds.
+ Weight::from_parts(2_877_000, 2532)
+ .saturating_add(T::DbWeight::get().reads(1_u64))
}
/// Storage: Nonfungible Allowance (r:1 w:1)
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
@@ -543,12 +536,12 @@
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
/// Storage: Nonfungible Owned (r:0 w:2)
/// Proof: Nonfungible Owned (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen)
- fn transfer() -> Weight {
+ fn transfer_raw() -> Weight {
// Proof Size summary in bytes:
// Measured: `412`
// Estimated: `10144`
- // Minimum execution time: 18_629_000 picoseconds.
- Weight::from_parts(18_997_000, 10144)
+ // Minimum execution time: 9_307_000 picoseconds.
+ Weight::from_parts(10_108_000, 10144)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
@@ -578,22 +571,15 @@
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
- /// Storage: Nonfungible Allowance (r:1 w:1)
+ /// Storage: Nonfungible Allowance (r:1 w:0)
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
- /// Storage: Nonfungible TokenData (r:1 w:1)
- /// Proof: Nonfungible TokenData (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
- /// Storage: Nonfungible AccountBalance (r:2 w:2)
- /// Proof: Nonfungible AccountBalance (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
- /// Storage: Nonfungible Owned (r:0 w:2)
- /// Proof: Nonfungible Owned (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen)
- fn transfer_from() -> Weight {
+ fn check_allowed_raw() -> Weight {
// Proof Size summary in bytes:
- // Measured: `527`
- // Estimated: `10144`
- // Minimum execution time: 24_919_000 picoseconds.
- Weight::from_parts(25_333_000, 10144)
- .saturating_add(RocksDbWeight::get().reads(4_u64))
- .saturating_add(RocksDbWeight::get().writes(6_u64))
+ // Measured: `394`
+ // Estimated: `2532`
+ // Minimum execution time: 2_668_000 picoseconds.
+ Weight::from_parts(2_877_000, 2532)
+ .saturating_add(RocksDbWeight::get().reads(1_u64))
}
/// Storage: Nonfungible Allowance (r:1 w:1)
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)