git.delta.rocks / unique-network / refs/commits / f4c0a8800bca

difftreelog

refactor impl of `transfer` `transfer_from` functions, bencmarks for `Common` & `NFT` pallets

PraetorP2023-03-29parent: #b4ec6cd.patch.diff
in: master

7 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
215 true,215 true,
216 )?;216 )?;
217
218 <Pallet<T>>::toggle_allowlist(
219 &collection,
220 &sender,
221 &receiver,
222 true,
223 )?;
224217
225 assert_eq!(collection_handle.permissions.access(), AccessMode::AllowList);218 assert_eq!(collection_handle.permissions.access(), AccessMode::AllowList);
226219
227 collection_handle.check_allowlist(&sender)?;220 collection_handle.check_allowlist(&sender)?;
228 collection_handle.check_allowlist(&receiver)?;
229221
230 }: {collection_handle.check_allowlist(&sender)?;}222 }: {collection_handle.check_allowlist(&sender)?;}
231}223}
addedpallets/common/src/helpers.rsdiffbeforeafterboth

no changes

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
92pub mod dispatch;92pub mod dispatch;
93pub mod erc;93pub mod erc;
94pub mod eth;94pub mod eth;
95pub mod helpers;
95#[allow(missing_docs)]96#[allow(missing_docs)]
96pub mod weights;97pub mod weights;
97
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
146 let item = create_max_item(&collection, &owner, owner_eth.clone())?;146 let item = create_max_item(&collection, &owner, owner_eth.clone())?;
147 }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?}147 }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?}
148148
149 checks_for_transfer_from {149 checks_allowed_raw {
150 bench_init!{150 bench_init!{
151 owner: sub; collection: collection(owner);151 owner: sub; collection: collection(owner);
152 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;152 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
103 }103 }
104104
105 fn transfer_from() -> Weight {105 fn transfer_from() -> Weight {
106 Self::transfer() + <SelfWeightOf<T>>::checks_for_transfer_from()106 Self::transfer() + <SelfWeightOf<T>>::checks_allowed_raw()
107 }107 }
108108
109 fn burn_from() -> Weight {109 fn burn_from() -> Weight {
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
109use pallet_common::{109use pallet_common::{
110 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,110 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
111 eth::collection_id_to_address, SelfWeightOf as PalletCommonWeightOf,111 eth::collection_id_to_address, SelfWeightOf as PalletCommonWeightOf,
112 weights::WeightInfo as CommonWeightInfo,112 weights::WeightInfo as CommonWeightInfo, helpers::add_weight_to_post_info,
113};113};
114use pallet_structure::{Pallet as PalletStructure, Error as StructureError};114use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
115use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};115use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
809 <CommonError<T>>::TransferNotAllowed809 <CommonError<T>>::TransferNotAllowed
810 );810 );
811811
812 let mut actual_weight = <SelfWeightOf<T>>::transfer();
812 let token_data =813 let token_data =
813 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;814 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
814 ensure!(&token_data.owner == from, <CommonError<T>>::NoPermission);815 ensure!(&token_data.owner == from, <CommonError<T>>::NoPermission);
815816
816 let is_allow_list_mode = collection.permissions.access() == AccessMode::AllowList;817 if collection.permissions.access() == AccessMode::AllowList {
817 if is_allow_list_mode {
818 collection.check_allowlist(from)?;818 collection.check_allowlist(from)?;
819 collection.check_allowlist(to)?;819 collection.check_allowlist(to)?;
820 actual_weight += <PalletCommonWeightOf<T>>::check_accesslist() * 2;
820 }821 }
821 <PalletCommon<T>>::ensure_correct_receiver(to)?;822 <PalletCommon<T>>::ensure_correct_receiver(to)?;
822823
887 1,888 1,
888 ));889 ));
889
890 let actual_weight = match is_allow_list_mode {
891 true => Some(
892 <SelfWeightOf<T>>::transfer() + <PalletCommonWeightOf<T>>::check_accesslist() * 2,
893 ),
894 false => Some(<SelfWeightOf<T>>::transfer()),
895 };
896890
897 Ok(PostDispatchInfo {891 Ok(PostDispatchInfo {
898 actual_weight,892 actual_weight: Some(actual_weight),
899 pays_fee: Pays::Yes,893 pays_fee: Pays::Yes,
900 })894 })
901 }895 }
1247 // =========1241 // =========
12481242
1249 // Allowance is reset in [`transfer`]1243 // Allowance is reset in [`transfer`]
1250 Self::transfer(collection, from, to, token, nesting_budget).map(|mut p| {1244 let mut result = Self::transfer(collection, from, to, token, nesting_budget);
1251 p.actual_weight = Some(1245 add_weight_to_post_info(&mut result, <SelfWeightOf<T>>::checks_allowed_raw());
1252 p.actual_weight.unwrap_or_default() + <SelfWeightOf<T>>::checks_for_transfer_from(),1246 result
1253 );
1254 p
1255 })
1256 }1247 }
12571248
1258 /// Burn NFT token for `from` account.1249 /// Burn NFT token for `from` account.
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
43 fn transfer() -> Weight;43 fn transfer() -> Weight;
44 fn approve() -> Weight;44 fn approve() -> Weight;
45 fn approve_from() -> Weight;45 fn approve_from() -> Weight;
46 fn checks_for_transfer_from() -> Weight;46 fn checks_allowed_raw() -> Weight;
47 fn burn_from() -> Weight;47 fn burn_from() -> Weight;
48 fn set_token_property_permissions(b: u32, ) -> Weight;48 fn set_token_property_permissions(b: u32, ) -> Weight;
49 fn set_token_properties(b: u32, ) -> Weight;49 fn set_token_properties(b: u32, ) -> Weight;
252 .saturating_add(T::DbWeight::get().reads(2_u64))252 .saturating_add(T::DbWeight::get().reads(2_u64))
253 .saturating_add(T::DbWeight::get().writes(1_u64))253 .saturating_add(T::DbWeight::get().writes(1_u64))
254 }254 }
255 /// Storage: Nonfungible Allowance (r:1 w:1)255 // Storage: Nonfungible Allowance (r:1 w:0)
256 /// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
257 /// Storage: Nonfungible TokenData (r:1 w:1)
258 /// Proof: Nonfungible TokenData (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
259 /// Storage: Nonfungible AccountBalance (r:2 w:2)
260 /// Proof: Nonfungible AccountBalance (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
261 /// Storage: Nonfungible Owned (r:0 w:2)
262 /// Proof: Nonfungible Owned (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen)
263 fn transfer_from() -> Weight {256 fn checks_allowed_raw() -> Weight {
264 // Proof Size summary in bytes:
265 // Measured: `527`
266 // Estimated: `10144`
267 // Minimum execution time: 24_919_000 picoseconds.
268 Weight::from_parts(25_333_000, 10144)257 Weight::from_ref_time(3_341_000 as u64)
269 .saturating_add(T::DbWeight::get().reads(4_u64))
270 .saturating_add(T::DbWeight::get().writes(6_u64))258 .saturating_add(T::DbWeight::get().reads(1 as u64))
271 }259 }
272 /// Storage: Nonfungible Allowance (r:1 w:1)260 /// Storage: Nonfungible Allowance (r:1 w:1)
273 /// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)261 /// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
578 .saturating_add(RocksDbWeight::get().reads(2_u64))566 .saturating_add(RocksDbWeight::get().reads(2_u64))
579 .saturating_add(RocksDbWeight::get().writes(1_u64))567 .saturating_add(RocksDbWeight::get().writes(1_u64))
580 }568 }
581 /// Storage: Nonfungible Allowance (r:1 w:1)569 // Storage: Nonfungible Allowance (r:1 w:0)
582 /// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
583 /// Storage: Nonfungible TokenData (r:1 w:1)
584 /// Proof: Nonfungible TokenData (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
585 /// Storage: Nonfungible AccountBalance (r:2 w:2)
586 /// Proof: Nonfungible AccountBalance (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
587 /// Storage: Nonfungible Owned (r:0 w:2)
588 /// Proof: Nonfungible Owned (max_values: None, max_size: Some(74), added: 2549, mode: MaxEncodedLen)
589 fn transfer_from() -> Weight {570 fn checks_allowed_raw() -> Weight {
590 // Proof Size summary in bytes:
591 // Measured: `527`
592 // Estimated: `10144`
593 // Minimum execution time: 24_919_000 picoseconds.
594 Weight::from_parts(25_333_000, 10144)571 Weight::from_ref_time(3_341_000 as u64)
595 .saturating_add(RocksDbWeight::get().reads(4_u64))
596 .saturating_add(RocksDbWeight::get().writes(6_u64))572 .saturating_add(RocksDbWeight::get().reads(1 as u64))
597 }573 }
598 /// Storage: Nonfungible Allowance (r:1 w:1)574 /// Storage: Nonfungible Allowance (r:1 w:1)
599 /// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)575 /// Proof: Nonfungible Allowance (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)