difftreelog
refactor impl of `transfer` `transfer_from` functions, bencmarks for `Common` & `NFT` pallets
in: master
7 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -215,17 +215,9 @@
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/helpers.rsdiffbeforeafterbothno changes
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/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -146,7 +146,7 @@
let item = create_max_item(&collection, &owner, owner_eth.clone())?;
}: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?}
- checks_for_transfer_from {
+ checks_allowed_raw {
bench_init!{
owner: sub; collection: collection(owner);
owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -103,7 +103,7 @@
}
fn transfer_from() -> Weight {
- Self::transfer() + <SelfWeightOf<T>>::checks_for_transfer_from()
+ Self::transfer() + <SelfWeightOf<T>>::checks_allowed_raw()
}
fn burn_from() -> Weight {
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -109,7 +109,7 @@
use pallet_common::{
Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
eth::collection_id_to_address, SelfWeightOf as PalletCommonWeightOf,
- weights::WeightInfo as CommonWeightInfo,
+ 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};
@@ -809,14 +809,15 @@
<CommonError<T>>::TransferNotAllowed
);
+ let mut actual_weight = <SelfWeightOf<T>>::transfer();
let token_data =
<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
ensure!(&token_data.owner == from, <CommonError<T>>::NoPermission);
- let is_allow_list_mode = collection.permissions.access() == AccessMode::AllowList;
- if is_allow_list_mode {
+ 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)?;
@@ -887,15 +888,8 @@
1,
));
- 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,
+ actual_weight: Some(actual_weight),
pays_fee: Pays::Yes,
})
}
@@ -1247,12 +1241,9 @@
// =========
// Allowance is reset in [`transfer`]
- 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
- })
+ let mut result = Self::transfer(collection, from, to, token, nesting_budget);
+ add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::checks_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
@@ -43,7 +43,7 @@
fn transfer() -> Weight;
fn approve() -> Weight;
fn approve_from() -> Weight;
- fn checks_for_transfer_from() -> Weight;
+ fn checks_allowed_raw() -> Weight;
fn burn_from() -> Weight;
fn set_token_property_permissions(b: u32, ) -> Weight;
fn set_token_properties(b: u32, ) -> Weight;
@@ -252,22 +252,10 @@
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
- /// Storage: Nonfungible Allowance (r:1 w:1)
- /// 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 {
- // 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))
+ // Storage: Nonfungible Allowance (r:1 w:0)
+ fn checks_allowed_raw() -> Weight {
+ Weight::from_ref_time(3_341_000 as u64)
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
}
/// Storage: Nonfungible Allowance (r:1 w:1)
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
@@ -578,22 +566,10 @@
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
- /// Storage: Nonfungible Allowance (r:1 w:1)
- /// 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 {
- // 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))
+ // Storage: Nonfungible Allowance (r:1 w:0)
+ fn checks_allowed_raw() -> Weight {
+ Weight::from_ref_time(3_341_000 as u64)
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
}
/// Storage: Nonfungible Allowance (r:1 w:1)
/// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)