Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions prdoc/pr_12529.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
title: Remove deprecated GenesisBuild trait.
doc:
- audience: Runtime Dev
description: |-
## Summary

- Removed the deprecated `GenesisBuild` trait from `frame_support::traits`
- Dropped the re-export and macro support for `GenesisBuild<T>` / `GenesisBuild<T, I>`
- Pallet `#[pallet::genesis_build]` now only accepts `BuildGenesisConfig`
- Updated docs and UI test expectations accordingly

## Migration

If you still use the old genesis build syntax:

```rust
// Before
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> { ... }

// After
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> { ... }
```

`BuildStorage` / `assimilate_storage` for genesis configs is still generated by the pallet macro only the trait name changes.
crates:
- name: frame-support-procedural
bump: major
- name: frame-support
bump: major
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl GenesisBuildDef {
.trait_
.as_ref()
.ok_or_else(|| {
let msg = "Invalid pallet::genesis_build, expected impl<..> GenesisBuild<..> \
let msg = "Invalid pallet::genesis_build, expected impl<..> BuildGenesisConfig \
for GenesisConfig<..>";
syn::Error::new(item.span(), msg)
})?
Expand Down
48 changes: 12 additions & 36 deletions substrate/frame/support/procedural/src/pallet/parse/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use syn::spanned::Spanned;
mod keyword {
syn::custom_keyword!(I);
syn::custom_keyword!(compact);
syn::custom_keyword!(GenesisBuild);
syn::custom_keyword!(BuildGenesisConfig);
syn::custom_keyword!(Config);
syn::custom_keyword!(T);
Expand Down Expand Up @@ -493,48 +492,25 @@ pub fn check_type_def_gen(
Ok(i)
}

/// Check the syntax:
/// * either `GenesisBuild<T>`
/// * or `GenesisBuild<T, I>`
/// * or `BuildGenesisConfig`
///
/// return the instance if found for `GenesisBuild`
/// return None for BuildGenesisConfig
/// Check the syntax is `BuildGenesisConfig`.
pub fn check_genesis_builder_usage(type_: &syn::Path) -> syn::Result<Option<InstanceUsage>> {
let expected = "expected `BuildGenesisConfig` (or the deprecated `GenesisBuild<T>` or `GenesisBuild<T, I>`)";
pub struct Checker(Option<InstanceUsage>);
let expected = "expected `BuildGenesisConfig`";
pub struct Checker;
impl syn::parse::Parse for Checker {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let mut instance_usage = InstanceUsage { span: input.span(), has_instance: false };

if input.peek(keyword::GenesisBuild) {
input.parse::<keyword::GenesisBuild>()?;
input.parse::<syn::Token![<]>()?;
input.parse::<keyword::T>()?;
if input.peek(syn::Token![,]) {
instance_usage.has_instance = true;
input.parse::<syn::Token![,]>()?;
input.parse::<keyword::I>()?;
}
input.parse::<syn::Token![>]>()?;
return Ok(Self(Some(instance_usage)));
} else {
input.parse::<keyword::BuildGenesisConfig>()?;
return Ok(Self(None));
}
input.parse::<keyword::BuildGenesisConfig>()?;
Ok(Self)
}
}

let i = syn::parse2::<Checker>(type_.to_token_stream())
.map_err(|e| {
let msg = format!("Invalid genesis builder: {}", expected);
let mut err = syn::Error::new(type_.span(), msg);
err.combine(e);
err
})?
.0;
syn::parse2::<Checker>(type_.to_token_stream()).map_err(|e| {
let msg = format!("Invalid genesis builder: {}", expected);
let mut err = syn::Error::new(type_.span(), msg);
err.combine(e);
err
})?;

Ok(i)
Ok(None)
}

/// Check the syntax:
Expand Down
28 changes: 0 additions & 28 deletions substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,34 +1928,6 @@ pub mod pallet_macros {
/// }
/// }
/// ```
///
/// ## Former Usage
///
/// Prior to <https://github.com/paritytech/substrate/pull/14306>, the following syntax was used.
/// This is deprecated and will soon be removed.
///
/// ```
/// #[frame_support::pallet]
/// pub mod pallet {
/// # #[pallet::config]
/// # pub trait Config: frame_system::Config {}
/// # #[pallet::pallet]
/// # pub struct Pallet<T>(_);
/// # use frame_support::traits::GenesisBuild;
/// #[pallet::genesis_config]
/// #[derive(frame_support::DefaultNoBound)]
/// pub struct GenesisConfig<T: Config> {
/// foo: Vec<T::AccountId>
/// }
///
/// #[pallet::genesis_build]
/// impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
/// fn build(&self) {
/// todo!()
/// }
/// }
/// }
/// ```
pub use frame_support_procedural::genesis_build;

/// Allows adding an associated type trait bounded by
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ pub use metadata::{
};

mod hooks;
#[allow(deprecated)]
pub use hooks::GenesisBuild;
pub use hooks::{
BeforeAllRuntimeMigrations, BuildGenesisConfig, Hooks, IntegrityTest, OnFinalize, OnGenesis,
OnIdle, OnInitialize, OnPoll, OnRuntimeUpgrade, OnTimestampSet, PostInherents,
Expand Down
30 changes: 1 addition & 29 deletions substrate/frame/support/src/traits/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ pub trait Hooks<BlockNumber> {

/// A trait to define the build function of a genesis config for both runtime and pallets.
///
/// Replaces deprecated [`GenesisBuild<T,I>`].
/// A trait to define the build function of a genesis config.
pub trait BuildGenesisConfig: sp_runtime::traits::MaybeSerializeDeserialize {
/// The build function puts initial `GenesisConfig` keys/values pairs into the storage.
fn build(&self);
Expand All @@ -582,34 +582,6 @@ impl BuildGenesisConfig for () {
fn build(&self) {}
}

/// A trait to define the build function of a genesis config, T and I are placeholder for pallet
/// trait and pallet instance.
#[deprecated(
note = "GenesisBuild is planned to be removed in December 2023. Use BuildGenesisConfig instead of it."
)]
pub trait GenesisBuild<T, I = ()>: sp_runtime::traits::MaybeSerializeDeserialize {
/// The build function is called within an externalities allowing storage APIs.
/// Thus one can write to storage using regular pallet storages.
fn build(&self);

/// Build the storage using `build` inside default storage.
#[cfg(feature = "std")]
fn build_storage(&self) -> Result<sp_runtime::Storage, String> {
let mut storage = Default::default();
self.assimilate_storage(&mut storage)?;
Ok(storage)
}

/// Assimilate the storage for this module into pre-existing overlays.
#[cfg(feature = "std")]
fn assimilate_storage(&self, storage: &mut sp_runtime::Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
self.build();
Ok(())
})
}
}

impl_for_tuples_attr! {
/// A trait which is called when the timestamp is set in the runtime.
pub trait OnTimestampSet<Moment> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
error: `#[pallet::genesis_config]` and `#[pallet::genesis_build]` attributes must be either both used or both not used, instead genesis_config is unused and genesis_build is used
--> tests/pallet_ui/genesis_inconsistent_build_config.rs:19:1
error: Invalid genesis builder: expected `BuildGenesisConfig`
--> tests/pallet_ui/genesis_inconsistent_build_config.rs:36:18
|
19 | mod pallet {
| ^^^
36 | impl<T: Config> GenesisBuild<T> for GenesisConfig {}
| ^^^^^^^^^^^^

error: expected `BuildGenesisConfig`
--> tests/pallet_ui/genesis_inconsistent_build_config.rs:36:18
|
36 | impl<T: Config> GenesisBuild<T> for GenesisConfig {}
| ^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
error: Invalid genesis builder: expected `BuildGenesisConfig` (or the deprecated `GenesisBuild<T>` or `GenesisBuild<T, I>`)
error: Invalid genesis builder: expected `BuildGenesisConfig`
--> tests/pallet_ui/genesis_invalid_generic.rs:36:7
|
36 | impl GenesisBuild for GenesisConfig {}
| ^^^^^^^^^^^^

error: expected `<`
--> tests/pallet_ui/genesis_invalid_generic.rs:18:1
|
18 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: expected `BuildGenesisConfig`
--> tests/pallet_ui/genesis_invalid_generic.rs:36:7
|
= note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)
36 | impl GenesisBuild for GenesisConfig {}
| ^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Invalid pallet::genesis_build, expected impl<..> GenesisBuild<..> for GenesisConfig<..>
error: Invalid pallet::genesis_build, expected impl<..> BuildGenesisConfig for GenesisConfig<..>
--> tests/pallet_ui/genesis_wrong_name.rs:36:2
|
36 | impl Foo {}
Expand Down
4 changes: 2 additions & 2 deletions substrate/test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,8 +1494,8 @@ mod tests {

let mut keys = t.into_storages().top.keys().cloned().map(hex).collect::<Vec<String>>();

// following keys are not placed during `<RuntimeGenesisConfig as GenesisBuild>::build`
// process, add them `keys` to assert against known keys.
// following keys are not placed during `<RuntimeGenesisConfig as
// BuildGenesisConfig>::build` process, add them `keys` to assert against known keys.
keys.push(hex(b":code"));
keys.sort();

Expand Down
Loading