diff --git a/prdoc/pr_12529.prdoc b/prdoc/pr_12529.prdoc new file mode 100644 index 0000000000000..ce47ac4cc0988 --- /dev/null +++ b/prdoc/pr_12529.prdoc @@ -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` / `GenesisBuild` + - 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 GenesisBuild for GenesisConfig { ... } + + // After + impl BuildGenesisConfig for GenesisConfig { ... } + ``` + + `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 diff --git a/substrate/frame/support/procedural/src/pallet/parse/genesis_build.rs b/substrate/frame/support/procedural/src/pallet/parse/genesis_build.rs index c382789ca41b1..f724a6b95b4a9 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/genesis_build.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/genesis_build.rs @@ -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) })? diff --git a/substrate/frame/support/procedural/src/pallet/parse/helper.rs b/substrate/frame/support/procedural/src/pallet/parse/helper.rs index 4001a811a840e..07d45b3830f45 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/helper.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/helper.rs @@ -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); @@ -493,48 +492,25 @@ pub fn check_type_def_gen( Ok(i) } -/// Check the syntax: -/// * either `GenesisBuild` -/// * or `GenesisBuild` -/// * 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> { - let expected = "expected `BuildGenesisConfig` (or the deprecated `GenesisBuild` or `GenesisBuild`)"; - pub struct Checker(Option); + let expected = "expected `BuildGenesisConfig`"; + pub struct Checker; impl syn::parse::Parse for Checker { fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut instance_usage = InstanceUsage { span: input.span(), has_instance: false }; - - if input.peek(keyword::GenesisBuild) { - input.parse::()?; - input.parse::()?; - input.parse::()?; - if input.peek(syn::Token![,]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - } - input.parse::]>()?; - return Ok(Self(Some(instance_usage))); - } else { - input.parse::()?; - return Ok(Self(None)); - } + input.parse::()?; + Ok(Self) } } - let i = syn::parse2::(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::(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: diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 554ebc9fc87a4..c57eba4754b76 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -1928,34 +1928,6 @@ pub mod pallet_macros { /// } /// } /// ``` - /// - /// ## Former Usage - /// - /// Prior to , 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(_); - /// # use frame_support::traits::GenesisBuild; - /// #[pallet::genesis_config] - /// #[derive(frame_support::DefaultNoBound)] - /// pub struct GenesisConfig { - /// foo: Vec - /// } - /// - /// #[pallet::genesis_build] - /// impl GenesisBuild for GenesisConfig { - /// fn build(&self) { - /// todo!() - /// } - /// } - /// } - /// ``` pub use frame_support_procedural::genesis_build; /// Allows adding an associated type trait bounded by diff --git a/substrate/frame/support/src/traits.rs b/substrate/frame/support/src/traits.rs index cb34382c69f07..9dd6b920f5137 100644 --- a/substrate/frame/support/src/traits.rs +++ b/substrate/frame/support/src/traits.rs @@ -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, diff --git a/substrate/frame/support/src/traits/hooks.rs b/substrate/frame/support/src/traits/hooks.rs index 07ad76244c715..c732301abe6a3 100644 --- a/substrate/frame/support/src/traits/hooks.rs +++ b/substrate/frame/support/src/traits/hooks.rs @@ -572,7 +572,7 @@ pub trait Hooks { /// A trait to define the build function of a genesis config for both runtime and pallets. /// -/// Replaces deprecated [`GenesisBuild`]. +/// 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); @@ -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: 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 { - 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 { diff --git a/substrate/frame/support/test/tests/pallet_ui/genesis_inconsistent_build_config.stderr b/substrate/frame/support/test/tests/pallet_ui/genesis_inconsistent_build_config.stderr index d515547ec3a06..91fff55ce0716 100644 --- a/substrate/frame/support/test/tests/pallet_ui/genesis_inconsistent_build_config.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/genesis_inconsistent_build_config.stderr @@ -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 GenesisBuild for GenesisConfig {} + | ^^^^^^^^^^^^ + +error: expected `BuildGenesisConfig` + --> tests/pallet_ui/genesis_inconsistent_build_config.rs:36:18 + | +36 | impl GenesisBuild for GenesisConfig {} + | ^^^^^^^^^^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/genesis_invalid_generic.stderr b/substrate/frame/support/test/tests/pallet_ui/genesis_invalid_generic.stderr index b54a23c91b4ee..22343e8c470f2 100644 --- a/substrate/frame/support/test/tests/pallet_ui/genesis_invalid_generic.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/genesis_invalid_generic.stderr @@ -1,13 +1,11 @@ -error: Invalid genesis builder: expected `BuildGenesisConfig` (or the deprecated `GenesisBuild` or `GenesisBuild`) +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 {} + | ^^^^^^^^^^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/genesis_wrong_name.stderr b/substrate/frame/support/test/tests/pallet_ui/genesis_wrong_name.stderr index 4d1c09ec5edf5..ccf27be0963af 100644 --- a/substrate/frame/support/test/tests/pallet_ui/genesis_wrong_name.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/genesis_wrong_name.stderr @@ -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 {} diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index a432322aed8f1..6ff20ef57eee7 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -1494,8 +1494,8 @@ mod tests { let mut keys = t.into_storages().top.keys().cloned().map(hex).collect::>(); - // following keys are not placed during `::build` - // process, add them `keys` to assert against known keys. + // following keys are not placed during `::build` process, add them `keys` to assert against known keys. keys.push(hex(b":code")); keys.sort();