Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add special tag to exclude runtime storage items from benchmarking #12205

Merged
merged 72 commits into from
Sep 16, 2022
Merged
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f08d3ae
initial setup
sam0x17 Aug 30, 2022
c381aef
add WhitelistedStorageKeys trait
sam0x17 Aug 30, 2022
1275c42
add (A, B) tuple implementation for whitelisted_storage_keys()
sam0x17 Aug 31, 2022
84beb0f
fix formatting
sam0x17 Aug 31, 2022
3699c19
implement WhitelistedStorageKeys for all tuple combinations
sam0x17 Aug 31, 2022
3056275
impl_for_tuples up to 128 for WhitelistedStorageKeys
sam0x17 Aug 31, 2022
adc7585
refactor to #[benchmarking(cached)]
sam0x17 Aug 31, 2022
f645511
tweak error message and mark BlockNumber as cached
sam0x17 Aug 31, 2022
1b8af15
add benchmarking(cached) to the other default types
sam0x17 Sep 1, 2022
2a1ae01
add docs for benchmarking(cached)
sam0x17 Sep 2, 2022
586bafb
properly parse storage type declaration
sam0x17 Sep 6, 2022
cfcd073
make storage_alias structs public so we can use them in this macro
sam0x17 Sep 6, 2022
8534891
use BTreeMap since TrackedStorageKey missing Ord outside of std
sam0x17 Sep 6, 2022
e2550b4
make WhitelistedStorageKeys accessible
sam0x17 Sep 6, 2022
157fb29
basic detection of benchmarking(cached) :boom:
sam0x17 Sep 6, 2022
5318167
proper parsing of #[benchmarking(cached)] from pallet parse macro
sam0x17 Sep 7, 2022
8cde8fe
store presence of #[benchmarking(cached)] macro on StorageDef
sam0x17 Sep 7, 2022
4cccd8a
compiling blank impl for WhitelistedStorageKeys
sam0x17 Sep 8, 2022
f21315c
move impl to expand_pallet_struct
sam0x17 Sep 8, 2022
faa63a7
use frame_support::sp_std::vec::Vec properly
sam0x17 Sep 8, 2022
73b01f1
successfully compiling with storage info loaded into a variable :boom:
sam0x17 Sep 9, 2022
fc6d239
plausible implementation for whitelisted_storage_keys()
sam0x17 Sep 9, 2022
f920bb9
use Pallet::whitelisted_storage_keys() instead of hard-coded list
sam0x17 Sep 9, 2022
0040a45
AllPallets::whitelisted_storage_keys() properly working :boom:
sam0x17 Sep 9, 2022
4a0fe7f
collect storage names
sam0x17 Sep 9, 2022
8ab6ab3
whitelisted_storage_keys() impl working :boom:
sam0x17 Sep 9, 2022
8ca026e
clean up
sam0x17 Sep 9, 2022
58a6229
fix compiler error
sam0x17 Sep 10, 2022
854a102
just one compiler error
sam0x17 Sep 10, 2022
771202c
fix doc compiler error
sam0x17 Sep 12, 2022
fe856ac
use better import path
sam0x17 Sep 12, 2022
0936ca4
fix comment
sam0x17 Sep 12, 2022
a72a280
whoops
sam0x17 Sep 12, 2022
c4ecb9a
whoops again
sam0x17 Sep 12, 2022
c6fd281
fix macro import issue
sam0x17 Sep 12, 2022
f360944
cargo fmt
sam0x17 Sep 12, 2022
92d5f5e
mark example as ignore
sam0x17 Sep 12, 2022
da51def
use keyword tokens instead of string parsing
sam0x17 Sep 13, 2022
e00420f
fix keyword-based parsing of benchmarking(cached)
sam0x17 Sep 13, 2022
a63acdf
preliminary spec for check_whitelist()
sam0x17 Sep 13, 2022
1a0ba3f
add additional test for benchmarking whitelist
sam0x17 Sep 13, 2022
d0ee2c6
add TODO note
sam0x17 Sep 13, 2022
2d1d637
remove irrelevant line from example
sam0x17 Sep 13, 2022
9ce39d2
use filter_map instead of filter and map
sam0x17 Sep 13, 2022
33828ea
simplify syntax
sam0x17 Sep 13, 2022
49b13ac
clean up
sam0x17 Sep 13, 2022
a2e8185
fix test
sam0x17 Sep 13, 2022
557a0c2
fix tests
sam0x17 Sep 13, 2022
d20bfe9
use keyword parsing instead of string parsing
sam0x17 Sep 14, 2022
1d31abe
use collect() instead of a for loop
sam0x17 Sep 14, 2022
dcb6312
fix compiler error
sam0x17 Sep 15, 2022
6e66eb1
clean up benchmarking(cached) marking code
sam0x17 Sep 15, 2022
dcda735
use cloned()
sam0x17 Sep 15, 2022
3f7bbc5
refactor to not use panic! and remove need for pub types in storage_a…
sam0x17 Sep 15, 2022
975f371
remove unneeded use
sam0x17 Sep 15, 2022
5ff3623
remove unneeded visibility changes
sam0x17 Sep 15, 2022
7214d0f
don't manually hard code hash for treasury account as hex
sam0x17 Sep 16, 2022
6e49069
proper Ord, PartialOrd, and Hash impls for TrackedStorageKey
sam0x17 Sep 16, 2022
4a71bd4
use BTreeSet instead of BTreeMap
sam0x17 Sep 16, 2022
7752321
fix comments
sam0x17 Sep 16, 2022
72a8ac8
cargo fmt
sam0x17 Sep 16, 2022
20e1375
switch to pallet::whitelist and re-do it basti's way :D
sam0x17 Sep 16, 2022
eb46fbb
make PartialOrd for TrackedStorageKey consistent with Ord
sam0x17 Sep 16, 2022
fd23e9e
more correct implementation of hash-related traits for TrackedStorageKey
sam0x17 Sep 16, 2022
d483a7a
fix integration test
sam0x17 Sep 16, 2022
05db4e5
update TODO
sam0x17 Sep 16, 2022
cb4ed97
remove unused keyword
sam0x17 Sep 16, 2022
4faf150
remove more unused keywords
sam0x17 Sep 16, 2022
91f33f0
use into_iter()
sam0x17 Sep 16, 2022
42127fc
Update frame/support/procedural/src/pallet/parse/mod.rs
sam0x17 Sep 16, 2022
cbf5959
add docs for whitelisted
sam0x17 Sep 16, 2022
ae1bf10
fix comment
sam0x17 Sep 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up benchmarking(cached) marking code
  • Loading branch information
sam0x17 committed Sep 15, 2022
commit 6e66eb11c2c6273986db9924c2bbd7a9b95f94c1
43 changes: 22 additions & 21 deletions frame/support/procedural/src/pallet/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use proc_macro2::Group;
use quote::ToTokens;
use syn::{spanned::Spanned, AttrStyle};

use self::storage::StorageDef;

/// Parsed definition of a pallet.
pub struct Def {
/// The module items.
Expand All @@ -64,6 +66,25 @@ pub struct Def {
}

impl Def {
fn mark_benchmarking_cached_calls(storage_def: &mut StorageDef, item: &mut syn::Item) {
if let syn::Item::Type(typ) = item {
for attr in typ.attrs.as_slice() {
if attr.style == AttrStyle::Outer {
if let Some(seg) = attr.path.segments.last() {
if let Ok(_) = syn::parse2::<keyword::benchmarking>(seg.to_token_stream()) {
if let Ok(group) = syn::parse2::<Group>(attr.tokens.clone()) {
if let Ok(_) = syn::parse2::<keyword::cached>(group.stream()) {
storage_def.benchmarking_cached = true;
break
}
}
}
}
}
}
}
}

pub fn try_from(mut item: syn::ItemMod) -> syn::Result<Self> {
let frame_system = generate_crate_access_2018("frame-system")?;
let frame_support = generate_crate_access_2018("frame-support")?;
Expand Down Expand Up @@ -127,27 +148,7 @@ impl Def {
inherent = Some(inherent::InherentDef::try_from(index, item)?),
Some(PalletAttr::Storage(span)) => {
let mut storage_def = storage::StorageDef::try_from(span, index, item)?;
// check for #[benchmarking(cached)] calls
if let syn::Item::Type(typ) = item {
for attr in typ.attrs.as_slice() {
if attr.style == AttrStyle::Outer {
if let Some(seg) = attr.path.segments.last() {
if let Ok(_) =
syn::parse2::<keyword::benchmarking>(seg.to_token_stream())
{
if let Ok(group) = syn::parse2::<Group>(attr.tokens.clone())
{
if let Ok(_) =
syn::parse2::<keyword::cached>(group.stream())
{
storage_def.benchmarking_cached = true;
}
}
}
}
}
}
}
Self::mark_benchmarking_cached_calls(&mut storage_def, item);
storages.push(storage_def);
},
Some(PalletAttr::ValidateUnsigned(_)) if validate_unsigned.is_none() => {
Expand Down