difftreelog
feat add benchmarks for burn_from
in: master
12 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -54,7 +54,6 @@
variable_on_chain_schema,
const_on_chain_schema,
meta_update_permission: Default::default(),
- transfers_enabled: true,
})
.and_then(CollectionHandle::try_get)
.map(cast)
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -58,4 +58,13 @@
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;
<Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;
}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100)?}
+
+ burn_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; burner: cross_sub;
+ };
+ <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;
+ <Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;
+ }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, 100)?}
}
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -37,7 +37,7 @@
}
fn burn_from() -> Weight {
- 0
+ <SelfWeightOf<T>>::burn_from()
}
fn set_variable_metadata(_bytes: u32) -> Weight {
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -75,6 +75,14 @@
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
+ // Storage: Fungible Allowance (r:1 w:1)
+ // Storage: Fungible TotalSupply (r:1 w:1)
+ // Storage: Fungible Balance (r:1 w:1)
+ fn burn_from() -> Weight {
+ (55_874_000 as Weight)
+ .saturating_add(T::DbWeight::get().reads(3 as Weight))
+ .saturating_add(T::DbWeight::get().writes(3 as Weight))
+ }
}
// For backwards compatibility and tests
@@ -113,4 +121,12 @@
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
+ // Storage: Fungible Allowance (r:1 w:1)
+ // Storage: Fungible TotalSupply (r:1 w:1)
+ // Storage: Fungible Balance (r:1 w:1)
+ fn burn_from() -> Weight {
+ (55_874_000 as Weight)
+ .saturating_add(RocksDbWeight::get().reads(3 as Weight))
+ .saturating_add(RocksDbWeight::get().writes(3 as Weight))
+ }
}
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -89,6 +89,15 @@
<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;
}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item)?}
+ burn_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; burner: cross_sub;
+ };
+ let item = create_max_item(&collection, &owner, sender.clone())?;
+ <Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;
+ }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item)?}
+
set_variable_metadata {
let b in 0..CUSTOM_DATA_LIMIT;
bench_init!{
pallets/nonfungible/src/common.rsdiffbeforeafterboth1use core::marker::PhantomData;23use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};4use nft_data_structs::TokenId;5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};6use sp_runtime::DispatchError;7use sp_std::vec::Vec;89use crate::{10 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,11 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,12};1314pub struct CommonWeights<T: Config>(PhantomData<T>);15impl<T: Config> CommonWeightInfo for CommonWeights<T> {16 fn create_item() -> Weight {17 <SelfWeightOf<T>>::create_item()18 }1920 fn create_multiple_items(amount: u32) -> Weight {21 <SelfWeightOf<T>>::create_multiple_items(amount)22 }2324 fn burn_item() -> Weight {25 <SelfWeightOf<T>>::burn_item()26 }2728 fn transfer() -> Weight {29 <SelfWeightOf<T>>::transfer()30 }3132 fn approve() -> Weight {33 <SelfWeightOf<T>>::approve()34 }3536 fn transfer_from() -> Weight {37 <SelfWeightOf<T>>::transfer_from()38 }3940 fn burn_from() -> Weight {41 042 }4344 fn set_variable_metadata(bytes: u32) -> Weight {45 <SelfWeightOf<T>>::set_variable_metadata(bytes)46 }47}4849fn map_create_data<T: Config>(50 data: nft_data_structs::CreateItemData,51 to: &T::CrossAccountId,52) -> Result<CreateItemData<T>, DispatchError> {53 match data {54 nft_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData {55 const_data: data.const_data,56 variable_data: data.variable_data,57 owner: to.clone(),58 }),59 _ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),60 }61}6263impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {64 fn create_item(65 &self,66 sender: T::CrossAccountId,67 to: T::CrossAccountId,68 data: nft_data_structs::CreateItemData,69 ) -> DispatchResultWithPostInfo {70 with_weight(71 <Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),72 <CommonWeights<T>>::create_item(),73 )74 }7576 fn create_multiple_items(77 &self,78 sender: T::CrossAccountId,79 to: T::CrossAccountId,80 data: Vec<nft_data_structs::CreateItemData>,81 ) -> DispatchResultWithPostInfo {82 let data = data83 .into_iter()84 .map(|d| map_create_data::<T>(d, &to))85 .collect::<Result<Vec<_>, DispatchError>>()?;8687 let amount = data.len();88 with_weight(89 <Pallet<T>>::create_multiple_items(self, &sender, data),90 <CommonWeights<T>>::create_multiple_items(amount as u32),91 )92 }9394 fn burn_item(95 &self,96 sender: T::CrossAccountId,97 token: TokenId,98 amount: u128,99 ) -> DispatchResultWithPostInfo {100 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);101 if amount == 1 {102 with_weight(103 <Pallet<T>>::burn(&self, &sender, token),104 <CommonWeights<T>>::burn_item(),105 )106 } else {107 Ok(().into())108 }109 }110111 fn transfer(112 &self,113 from: T::CrossAccountId,114 to: T::CrossAccountId,115 token: TokenId,116 amount: u128,117 ) -> DispatchResultWithPostInfo {118 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);119 if amount == 1 {120 with_weight(121 <Pallet<T>>::transfer(&self, &from, &to, token),122 <CommonWeights<T>>::transfer(),123 )124 } else {125 Ok(().into())126 }127 }128129 fn approve(130 &self,131 sender: T::CrossAccountId,132 spender: T::CrossAccountId,133 token: TokenId,134 amount: u128,135 ) -> DispatchResultWithPostInfo {136 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);137138 with_weight(139 if amount == 1 {140 <Pallet<T>>::set_allowance(&self, &sender, token, Some(&spender))141 } else {142 <Pallet<T>>::set_allowance(&self, &sender, token, None)143 },144 <CommonWeights<T>>::approve(),145 )146 }147148 fn transfer_from(149 &self,150 sender: T::CrossAccountId,151 from: T::CrossAccountId,152 to: T::CrossAccountId,153 token: TokenId,154 amount: u128,155 ) -> DispatchResultWithPostInfo {156 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);157158 if amount == 1 {159 with_weight(160 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token),161 <CommonWeights<T>>::transfer_from(),162 )163 } else {164 Ok(().into())165 }166 }167168 fn burn_from(169 &self,170 sender: T::CrossAccountId,171 from: T::CrossAccountId,172 token: TokenId,173 amount: u128,174 ) -> DispatchResultWithPostInfo {175 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);176177 if amount == 1 {178 with_weight(179 <Pallet<T>>::burn_from(&self, &sender, &from, token),180 <CommonWeights<T>>::burn_from(),181 )182 } else {183 Ok(().into())184 }185 }186187 fn set_variable_metadata(188 &self,189 sender: T::CrossAccountId,190 token: TokenId,191 data: Vec<u8>,192 ) -> DispatchResultWithPostInfo {193 let len = data.len();194 with_weight(195 <Pallet<T>>::set_variable_metadata(&self, &sender, token, data),196 <CommonWeights<T>>::set_variable_metadata(len as u32),197 )198 }199200 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {201 <Owned<T>>::iter_prefix((self.id, account))202 .map(|(id, _)| id)203 .collect()204 }205206 fn token_exists(&self, token: TokenId) -> bool {207 <Pallet<T>>::token_exists(self, token)208 }209210 fn last_token_id(&self) -> TokenId {211 TokenId(<TokensMinted<T>>::get(self.id))212 }213214 fn token_owner(&self, token: TokenId) -> T::CrossAccountId {215 <TokenData<T>>::get((self.id, token))216 .map(|t| t.owner)217 .unwrap_or_default()218 }219 fn const_metadata(&self, token: TokenId) -> Vec<u8> {220 <TokenData<T>>::get((self.id, token))221 .map(|t| t.const_data.clone())222 .unwrap_or_default()223 }224 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {225 <TokenData<T>>::get((self.id, token))226 .map(|t| t.variable_data.clone())227 .unwrap_or_default()228 }229230 fn collection_tokens(&self) -> u32 {231 <Pallet<T>>::total_supply(self)232 }233234 fn account_balance(&self, account: T::CrossAccountId) -> u32 {235 <AccountBalance<T>>::get((self.id, account))236 }237238 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {239 if <TokenData<T>>::get((self.id, token))240 .map(|a| a.owner == account)241 .unwrap_or(false)242 {243 1244 } else {245 0246 }247 }248249 fn allowance(250 &self,251 sender: T::CrossAccountId,252 spender: T::CrossAccountId,253 token: TokenId,254 ) -> u128 {255 if <TokenData<T>>::get((self.id, token))256 .map(|a| a.owner != sender)257 .unwrap_or(true)258 {259 0260 } else if <Allowance<T>>::get((self.id, token)) == Some(spender) {261 1262 } else {263 0264 }265 }266}pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -98,6 +98,15 @@
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
+ // Storage: Nonfungible Allowance (r:1 w:1)
+ // Storage: Nonfungible TokenData (r:1 w:1)
+ // Storage: Nonfungible TokensBurnt (r:1 w:1)
+ // Storage: Nonfungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (53_429_000 as Weight)
+ .saturating_add(T::DbWeight::get().reads(3 as Weight))
+ .saturating_add(T::DbWeight::get().writes(4 as Weight))
+ }
// Storage: Nonfungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_380_000 as Weight)
@@ -163,6 +172,15 @@
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(6 as Weight))
}
+ // Storage: Nonfungible Allowance (r:1 w:1)
+ // Storage: Nonfungible TokenData (r:1 w:1)
+ // Storage: Nonfungible TokensBurnt (r:1 w:1)
+ // Storage: Nonfungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (53_429_000 as Weight)
+ .saturating_add(RocksDbWeight::get().reads(3 as Weight))
+ .saturating_add(RocksDbWeight::get().writes(4 as Weight))
+ }
// Storage: Nonfungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_380_000 as Weight)
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -149,6 +149,16 @@
<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;
}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200)?}
+ // Both source account and token is destroyed
+ burn_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; burner: cross_sub;
+ };
+ let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;
+ <Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;
+ }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200)?}
+
set_variable_metadata {
let b in 0..CUSTOM_DATA_LIMIT;
bench_init!{
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -166,6 +166,18 @@
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
+ // Storage: Refungible Allowance (r:1 w:1)
+ // Storage: Refungible TotalSupply (r:1 w:1)
+ // Storage: Refungible Balance (r:1 w:1)
+ // Storage: Refungible AccountBalance (r:1 w:1)
+ // Storage: Refungible TokensBurnt (r:1 w:1)
+ // Storage: Refungible TokenData (r:0 w:1)
+ // Storage: Refungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (60_903_000 as Weight)
+ .saturating_add(T::DbWeight::get().reads(5 as Weight))
+ .saturating_add(T::DbWeight::get().writes(7 as Weight))
+ }
// Storage: Refungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_801_000 as Weight)
@@ -292,6 +304,18 @@
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(7 as Weight))
}
+ // Storage: Refungible Allowance (r:1 w:1)
+ // Storage: Refungible TotalSupply (r:1 w:1)
+ // Storage: Refungible Balance (r:1 w:1)
+ // Storage: Refungible AccountBalance (r:1 w:1)
+ // Storage: Refungible TokensBurnt (r:1 w:1)
+ // Storage: Refungible TokenData (r:0 w:1)
+ // Storage: Refungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (60_903_000 as Weight)
+ .saturating_add(RocksDbWeight::get().reads(5 as Weight))
+ .saturating_add(RocksDbWeight::get().writes(7 as Weight))
+ }
// Storage: Refungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_801_000 as Weight)
pallets/scheduler/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/scheduler/src/benchmarking.rs
+++ b/pallets/scheduler/src/benchmarking.rs
@@ -33,7 +33,7 @@
// Add `n` named items to the schedule
fn fill_schedule<T: Config>(when: T::BlockNumber, n: u32) -> Result<(), &'static str> {
// Essentially a no-op call.
- let call = frame_system::Call::set_storage(vec![]);
+ let call = frame_system::Call::set_storage { items: vec![] };
for i in 0..n {
// Named schedule is strictly heavier than anonymous
Scheduler::<T>::do_schedule_named(
@@ -61,7 +61,7 @@
let periodic = Some((T::BlockNumber::one(), 100));
let priority = 0;
// Essentially a no-op call.
- let call = Box::new(frame_system::Call::set_storage(vec![]).into());
+ let call = Box::new(frame_system::Call::set_storage { items: vec![] }.into());
fill_schedule::<T>(when, s)?;
}: _(RawOrigin::Root, when, periodic, priority, call)
@@ -98,7 +98,7 @@
let periodic = Some((T::BlockNumber::one(), 100));
let priority = 0;
// Essentially a no-op call.
- let call = Box::new(frame_system::Call::set_storage(vec![]).into());
+ let call = Box::new(frame_system::Call::set_storage { items: vec![] }.into());
fill_schedule::<T>(when, s)?;
}: _(RawOrigin::Root, id, when, periodic, priority, call)
runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -23,7 +23,9 @@
'frame-support/runtime-benchmarks',
'frame-system-benchmarking',
'frame-system/runtime-benchmarks',
+ 'pallet-ethereum/runtime-benchmarks',
'pallet-evm-migration/runtime-benchmarks',
+ 'pallet-evm-coder-substrate/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-common/runtime-benchmarks',
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1327,6 +1327,7 @@
list_benchmark!(list, extra, pallet_fungible, Fungible);
list_benchmark!(list, extra, pallet_refungible, Refungible);
list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
+ // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
let storage_info = AllPalletsWithSystem::storage_info();
@@ -1360,6 +1361,7 @@
add_benchmark!(params, batches, pallet_fungible, Fungible);
add_benchmark!(params, batches, pallet_refungible, Refungible);
add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
+ // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)