From 4d76174ac2f60169d093429175d570e6d2c38209 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 9 May 2023 15:26:03 +0200 Subject: [PATCH 1/7] frame: Default for GenesisConfig in no_std `Default` for `GenesisConfig` will be required for no_std in no native runtime world. It must be possible to instantiate default GenesisConfig for pallets and runtime. --- frame/alliance/src/lib.rs | 1 - frame/assets/src/lib.rs | 1 - frame/aura/src/lib.rs | 1 - frame/authority-discovery/src/lib.rs | 2 +- frame/babe/src/lib.rs | 2 +- frame/balances/src/lib.rs | 3 +-- frame/beefy/src/lib.rs | 1 - frame/collective/src/lib.rs | 1 - frame/democracy/src/lib.rs | 1 - frame/elections-phragmen/src/lib.rs | 1 - frame/examples/basic/src/lib.rs | 1 - frame/grandpa/src/lib.rs | 2 +- frame/im-online/src/lib.rs | 1 - frame/indices/src/lib.rs | 1 - frame/membership/src/lib.rs | 1 - frame/node-authorization/src/lib.rs | 1 - frame/nomination-pools/src/lib.rs | 1 - frame/scored-pool/src/lib.rs | 1 - frame/session/src/lib.rs | 1 - frame/society/src/lib.rs | 1 - frame/staking/src/pallet/mod.rs | 1 - frame/sudo/src/lib.rs | 1 - .../procedural/src/pallet/expand/genesis_config.rs | 13 ++++++------- frame/system/src/lib.rs | 5 ++--- frame/transaction-payment/src/lib.rs | 1 - frame/transaction-storage/src/lib.rs | 1 - frame/treasury/src/lib.rs | 1 - frame/vesting/src/lib.rs | 1 - 28 files changed, 12 insertions(+), 37 deletions(-) diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index 86a64caaf8e75..e36116a5c33ff 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -407,7 +407,6 @@ pub mod pallet { pub phantom: PhantomData<(T, I)>, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { fellows: Vec::new(), allies: Vec::new(), phantom: Default::default() } diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index e6b59bba53836..791a7318ba6c3 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -375,7 +375,6 @@ pub mod pallet { pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { diff --git a/frame/aura/src/lib.rs b/frame/aura/src/lib.rs index 108b9303b3071..73b560935a8df 100644 --- a/frame/aura/src/lib.rs +++ b/frame/aura/src/lib.rs @@ -133,7 +133,6 @@ pub mod pallet { pub authorities: Vec, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { authorities: Vec::new() } diff --git a/frame/authority-discovery/src/lib.rs b/frame/authority-discovery/src/lib.rs index 341646b674e48..6365c95359472 100644 --- a/frame/authority-discovery/src/lib.rs +++ b/frame/authority-discovery/src/lib.rs @@ -59,7 +59,7 @@ pub mod pallet { pub(super) type NextKeys = StorageValue<_, WeakBoundedVec, ValueQuery>; - #[cfg_attr(feature = "std", derive(Default))] + #[derive(Default)] #[pallet::genesis_config] pub struct GenesisConfig { pub keys: Vec, diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index 15580457c9810..8001450b43583 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -314,7 +314,7 @@ pub mod pallet { pub(super) type SkippedEpochs = StorageValue<_, BoundedVec<(u64, SessionIndex), ConstU32<100>>, ValueQuery>; - #[cfg_attr(feature = "std", derive(Default))] + #[derive(Default)] #[pallet::genesis_config] pub struct GenesisConfig { pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>, diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index b3dc77a9b879d..7ed725a77df0c 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -456,7 +456,6 @@ pub mod pallet { pub balances: Vec<(T::AccountId, T::Balance)>, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { balances: Default::default() } @@ -483,7 +482,7 @@ pub mod pallet { .iter() .map(|(x, _)| x) .cloned() - .collect::>(); + .collect::>(); assert!( endowed_accounts.len() == self.balances.len(), diff --git a/frame/beefy/src/lib.rs b/frame/beefy/src/lib.rs index 945b32c12fe58..6a248da2bfe97 100644 --- a/frame/beefy/src/lib.rs +++ b/frame/beefy/src/lib.rs @@ -166,7 +166,6 @@ pub mod pallet { pub genesis_block: Option>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { // BEEFY genesis will be first BEEFY-MANDATORY block, diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index fd89a998ad97e..a38e69fc8f8a2 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -229,7 +229,6 @@ pub mod pallet { pub members: Vec, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { phantom: Default::default(), members: Default::default() } diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 69438eba91d8e..8c767e28401b1 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -443,7 +443,6 @@ pub mod pallet { _phantom: sp_std::marker::PhantomData, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { GenesisConfig { _phantom: Default::default() } diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 9c40e542e1c2a..32bdaa0f658c0 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -715,7 +715,6 @@ pub mod pallet { pub members: Vec<(T::AccountId, BalanceOf)>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { members: Default::default() } diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index bbeaac19f809c..aa5e2394f7ace 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -625,7 +625,6 @@ pub mod pallet { } // The default value for the genesis config type. - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { dummy: Default::default(), bar: Default::default(), foo: Default::default() } diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index f01c25e49edd4..8311131e97347 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -333,7 +333,7 @@ pub mod pallet { #[pallet::getter(fn session_for_set)] pub(super) type SetIdSession = StorageMap<_, Twox64Concat, SetId, SessionIndex>; - #[cfg_attr(feature = "std", derive(Default))] + #[derive(Default)] #[pallet::genesis_config] pub struct GenesisConfig { pub authorities: AuthorityList, diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index bc1e541cef125..8440395698d53 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -446,7 +446,6 @@ pub mod pallet { pub keys: Vec, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { GenesisConfig { keys: Default::default() } diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index 74f86abb51914..9c7dfdef13ada 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -267,7 +267,6 @@ pub mod pallet { pub indices: Vec<(T::AccountIndex, T::AccountId)>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { indices: Default::default() } diff --git a/frame/membership/src/lib.rs b/frame/membership/src/lib.rs index e703b88f3657e..96f9a22fd9ccd 100644 --- a/frame/membership/src/lib.rs +++ b/frame/membership/src/lib.rs @@ -110,7 +110,6 @@ pub mod pallet { pub phantom: PhantomData, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { members: Default::default(), phantom: Default::default() } diff --git a/frame/node-authorization/src/lib.rs b/frame/node-authorization/src/lib.rs index eaeda3cade9e9..3935562eb0322 100644 --- a/frame/node-authorization/src/lib.rs +++ b/frame/node-authorization/src/lib.rs @@ -113,7 +113,6 @@ pub mod pallet { pub nodes: Vec<(PeerId, T::AccountId)>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { nodes: Vec::new() } diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 78f0c730ce5dd..cc68f54bd55cf 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1659,7 +1659,6 @@ pub mod pallet { pub global_max_commission: Option, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { diff --git a/frame/scored-pool/src/lib.rs b/frame/scored-pool/src/lib.rs index 8bd44e2ffac8a..b964129842532 100644 --- a/frame/scored-pool/src/lib.rs +++ b/frame/scored-pool/src/lib.rs @@ -254,7 +254,6 @@ pub mod pallet { pub member_count: u32, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { pool: Default::default(), member_count: Default::default() } diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index a9f89412a71c4..afd7b47f69dac 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -418,7 +418,6 @@ pub mod pallet { pub keys: Vec<(T::AccountId, T::ValidatorId, T::Keys)>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { keys: Default::default() } diff --git a/frame/society/src/lib.rs b/frame/society/src/lib.rs index 899b6005af024..766a2c9b9c4e8 100644 --- a/frame/society/src/lib.rs +++ b/frame/society/src/lib.rs @@ -649,7 +649,6 @@ pub mod pallet { pub max_members: u32, } - #[cfg(feature = "std")] impl, I: 'static> Default for GenesisConfig { fn default() -> Self { Self { diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index d8f1855da4bc0..08bbf94c7af47 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -594,7 +594,6 @@ pub mod pallet { pub max_nominator_count: Option, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { GenesisConfig { diff --git a/frame/sudo/src/lib.rs b/frame/sudo/src/lib.rs index 1bc206e0063e4..9f50fe29b3f8f 100644 --- a/frame/sudo/src/lib.rs +++ b/frame/sudo/src/lib.rs @@ -278,7 +278,6 @@ pub mod pallet { pub key: Option, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { key: None } diff --git a/frame/support/procedural/src/pallet/expand/genesis_config.rs b/frame/support/procedural/src/pallet/expand/genesis_config.rs index 85ad20dd45c9e..91c2bad93a131 100644 --- a/frame/support/procedural/src/pallet/expand/genesis_config.rs +++ b/frame/support/procedural/src/pallet/expand/genesis_config.rs @@ -94,15 +94,14 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream { "] )); } - attrs.push(syn::parse_quote!( #[cfg(feature = "std")] )); attrs.push(syn::parse_quote!( - #[derive(#frame_support::Serialize, #frame_support::Deserialize)] + #[cfg_attr(feature = "std", derive(#frame_support::Serialize, #frame_support::Deserialize))] )); - attrs.push(syn::parse_quote!( #[serde(rename_all = "camelCase")] )); - attrs.push(syn::parse_quote!( #[serde(deny_unknown_fields)] )); - attrs.push(syn::parse_quote!( #[serde(bound(serialize = ""))] )); - attrs.push(syn::parse_quote!( #[serde(bound(deserialize = ""))] )); - attrs.push(syn::parse_quote!( #[serde(crate = #serde_crate)] )); + attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] )); + attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(deny_unknown_fields))] )); + attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(serialize = "")))] )); + attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(deserialize = "")))] )); + attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(crate = #serde_crate))] )); }, _ => unreachable!("Checked by genesis_config parser"), } diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 81bead4f849b4..ad00ae9b91c9c 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -635,10 +635,10 @@ pub mod pallet { #[pallet::whitelist_storage] pub(super) type ExecutionPhase = StorageValue<_, Phase>; - #[cfg_attr(feature = "std", derive(Default))] + #[derive(Default)] #[pallet::genesis_config] pub struct GenesisConfig { - #[serde(with = "sp_core::bytes")] + #[cfg_attr(feature = "std", serde(with = "sp_core::bytes"))] pub code: Vec, } @@ -712,7 +712,6 @@ pub struct EventRecord { // Create a Hash with 69 for each byte, // only used to build genesis config. -#[cfg(feature = "std")] fn hash69 + Default>() -> T { let mut h = T::default(); h.as_mut().iter_mut().for_each(|byte| *byte = 69); diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 83ff69428d144..f7bdc23a0b3f0 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -362,7 +362,6 @@ pub mod pallet { pub multiplier: Multiplier, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { multiplier: MULTIPLIER_DEFAULT_VALUE } diff --git a/frame/transaction-storage/src/lib.rs b/frame/transaction-storage/src/lib.rs index 59662ee860541..b99bc49fc5b6f 100644 --- a/frame/transaction-storage/src/lib.rs +++ b/frame/transaction-storage/src/lib.rs @@ -383,7 +383,6 @@ pub mod pallet { pub storage_period: T::BlockNumber, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self { diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 450aee51f2ce8..5fa999c7dce8c 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -236,7 +236,6 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig; - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { Self diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index af3654924914c..822c7e9b631f7 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -218,7 +218,6 @@ pub mod pallet { pub vesting: Vec<(T::AccountId, T::BlockNumber, T::BlockNumber, BalanceOf)>, } - #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { GenesisConfig { vesting: Default::default() } From 6bc30572a2574517e279c6ea2fb74c1786232e8c Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 9 May 2023 15:52:48 +0000 Subject: [PATCH 2/7] ".git/.scripts/commands/fmt/fmt.sh" --- .../src/pallet/expand/genesis_config.rs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/genesis_config.rs b/frame/support/procedural/src/pallet/expand/genesis_config.rs index 91c2bad93a131..0337395ed1227 100644 --- a/frame/support/procedural/src/pallet/expand/genesis_config.rs +++ b/frame/support/procedural/src/pallet/expand/genesis_config.rs @@ -97,11 +97,21 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream { attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", derive(#frame_support::Serialize, #frame_support::Deserialize))] )); - attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] )); - attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(deny_unknown_fields))] )); - attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(serialize = "")))] )); - attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(deserialize = "")))] )); - attrs.push(syn::parse_quote!( #[cfg_attr(feature = "std", serde(crate = #serde_crate))] )); + attrs.push( + syn::parse_quote!( #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] ), + ); + attrs.push( + syn::parse_quote!( #[cfg_attr(feature = "std", serde(deny_unknown_fields))] ), + ); + attrs.push( + syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(serialize = "")))] ), + ); + attrs.push( + syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(deserialize = "")))] ), + ); + attrs.push( + syn::parse_quote!( #[cfg_attr(feature = "std", serde(crate = #serde_crate))] ), + ); }, _ => unreachable!("Checked by genesis_config parser"), } From 8fd0eb35f4cabbb7a801d8caa7f1df1793d896e4 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 10 May 2023 10:56:09 +0200 Subject: [PATCH 3/7] hash69 in no_std reverted --- frame/system/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index ad00ae9b91c9c..c73e726e08131 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -712,6 +712,7 @@ pub struct EventRecord { // Create a Hash with 69 for each byte, // only used to build genesis config. +#[cfg(feature = "std")] fn hash69 + Default>() -> T { let mut h = T::default(); h.as_mut().iter_mut().for_each(|byte| *byte = 69); From 8a21eb158b0c03f2213fd8dfcafcaa9d0710397b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 10 May 2023 16:17:02 +0200 Subject: [PATCH 4/7] derive(DefaultNoBound) for GenesisConfig used when possible --- frame/alliance/src/lib.rs | 7 +------ frame/assets/src/lib.rs | 11 +---------- frame/aura/src/lib.rs | 7 +------ frame/collective/src/lib.rs | 7 +------ frame/democracy/src/lib.rs | 7 +------ frame/elections-phragmen/src/lib.rs | 7 +------ frame/examples/basic/src/lib.rs | 8 +------- frame/im-online/src/lib.rs | 7 +------ frame/indices/src/lib.rs | 7 +------ frame/membership/src/lib.rs | 7 +------ frame/node-authorization/src/lib.rs | 7 +------ frame/scored-pool/src/lib.rs | 7 +------ frame/session/src/lib.rs | 7 +------ frame/society/src/lib.rs | 11 +---------- frame/staking/src/pallet/mod.rs | 19 +------------------ frame/sudo/src/lib.rs | 7 +------ frame/vesting/src/lib.rs | 7 +------ 17 files changed, 17 insertions(+), 123 deletions(-) diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index e36116a5c33ff..6c034454cf7c0 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -401,18 +401,13 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub fellows: Vec, pub allies: Vec, pub phantom: PhantomData<(T, I)>, } - impl, I: 'static> Default for GenesisConfig { - fn default() -> Self { - Self { fellows: Vec::new(), allies: Vec::new(), phantom: Default::default() } - } - } - #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 791a7318ba6c3..881b743023ca4 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -366,6 +366,7 @@ pub mod pallet { >; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { /// Genesis assets: id, owner, is_sufficient, min_balance pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>, @@ -375,16 +376,6 @@ pub mod pallet { pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>, } - impl, I: 'static> Default for GenesisConfig { - fn default() -> Self { - Self { - assets: Default::default(), - metadata: Default::default(), - accounts: Default::default(), - } - } - } - #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/aura/src/lib.rs b/frame/aura/src/lib.rs index 73b560935a8df..12b7ee3f5fedc 100644 --- a/frame/aura/src/lib.rs +++ b/frame/aura/src/lib.rs @@ -129,16 +129,11 @@ pub mod pallet { pub(super) type CurrentSlot = StorageValue<_, Slot, ValueQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub authorities: Vec, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { authorities: Vec::new() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index a38e69fc8f8a2..12917f5bd6e34 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -224,17 +224,12 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub phantom: PhantomData, pub members: Vec, } - impl, I: 'static> Default for GenesisConfig { - fn default() -> Self { - Self { phantom: Default::default(), members: Default::default() } - } - } - #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 8c767e28401b1..370559b10a56a 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -439,16 +439,11 @@ pub mod pallet { pub type MetadataOf = StorageMap<_, Blake2_128Concat, MetadataOwner, PreimageHash>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { _phantom: sp_std::marker::PhantomData, } - impl Default for GenesisConfig { - fn default() -> Self { - GenesisConfig { _phantom: Default::default() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 32bdaa0f658c0..1d7c79fe3ca97 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -711,16 +711,11 @@ pub mod pallet { StorageMap<_, Twox64Concat, T::AccountId, Voter>, ValueQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub members: Vec<(T::AccountId, BalanceOf)>, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { members: Default::default() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index aa5e2394f7ace..af159c0f4bc98 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -618,19 +618,13 @@ pub mod pallet { // The genesis config type. #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub dummy: T::Balance, pub bar: Vec<(T::AccountId, T::Balance)>, pub foo: T::Balance, } - // The default value for the genesis config type. - impl Default for GenesisConfig { - fn default() -> Self { - Self { dummy: Default::default(), bar: Default::default(), foo: Default::default() } - } - } - // The build of genesis for the pallet. #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 8440395698d53..dd3809f8e9a70 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -442,16 +442,11 @@ pub mod pallet { >; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub keys: Vec, } - impl Default for GenesisConfig { - fn default() -> Self { - GenesisConfig { keys: Default::default() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index 9c7dfdef13ada..56e177da3148f 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -263,16 +263,11 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, T::AccountIndex, (T::AccountId, BalanceOf, bool)>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub indices: Vec<(T::AccountIndex, T::AccountId)>, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { indices: Default::default() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/membership/src/lib.rs b/frame/membership/src/lib.rs index 96f9a22fd9ccd..74891186a4e22 100644 --- a/frame/membership/src/lib.rs +++ b/frame/membership/src/lib.rs @@ -105,17 +105,12 @@ pub mod pallet { pub type Prime, I: 'static = ()> = StorageValue<_, T::AccountId, OptionQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub members: BoundedVec, pub phantom: PhantomData, } - impl, I: 'static> Default for GenesisConfig { - fn default() -> Self { - Self { members: Default::default(), phantom: Default::default() } - } - } - #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/node-authorization/src/lib.rs b/frame/node-authorization/src/lib.rs index 3935562eb0322..6ccc142431e61 100644 --- a/frame/node-authorization/src/lib.rs +++ b/frame/node-authorization/src/lib.rs @@ -109,16 +109,11 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, PeerId, BTreeSet, ValueQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub nodes: Vec<(PeerId, T::AccountId)>, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { nodes: Vec::new() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/scored-pool/src/lib.rs b/frame/scored-pool/src/lib.rs index b964129842532..f8fc0fecd492a 100644 --- a/frame/scored-pool/src/lib.rs +++ b/frame/scored-pool/src/lib.rs @@ -249,17 +249,12 @@ pub mod pallet { pub(crate) type MemberCount = StorageValue<_, u32, ValueQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub pool: PoolT, pub member_count: u32, } - impl, I: 'static> Default for GenesisConfig { - fn default() -> Self { - Self { pool: Default::default(), member_count: Default::default() } - } - } - #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index afd7b47f69dac..1219aaaf12a10 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -414,16 +414,11 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub keys: Vec<(T::AccountId, T::ValidatorId, T::Keys)>, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { keys: Default::default() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/society/src/lib.rs b/frame/society/src/lib.rs index 766a2c9b9c4e8..d92bee48d6aa5 100644 --- a/frame/society/src/lib.rs +++ b/frame/society/src/lib.rs @@ -643,22 +643,13 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub pot: BalanceOf, pub members: Vec, pub max_members: u32, } - impl, I: 'static> Default for GenesisConfig { - fn default() -> Self { - Self { - pot: Default::default(), - members: Default::default(), - max_members: Default::default(), - } - } - } - #[pallet::genesis_build] impl, I: 'static> GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index 08bbf94c7af47..9ac354c8614da 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -579,6 +579,7 @@ pub mod pallet { pub(crate) type ChillThreshold = StorageValue<_, Percent, OptionQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub validator_count: u32, pub minimum_validator_count: u32, @@ -594,24 +595,6 @@ pub mod pallet { pub max_nominator_count: Option, } - impl Default for GenesisConfig { - fn default() -> Self { - GenesisConfig { - validator_count: Default::default(), - minimum_validator_count: Default::default(), - invulnerables: Default::default(), - force_era: Default::default(), - slash_reward_fraction: Default::default(), - canceled_payout: Default::default(), - stakers: Default::default(), - min_nominator_bond: Default::default(), - min_validator_bond: Default::default(), - max_validator_count: None, - max_nominator_count: None, - } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/sudo/src/lib.rs b/frame/sudo/src/lib.rs index 9f50fe29b3f8f..257499faf4d41 100644 --- a/frame/sudo/src/lib.rs +++ b/frame/sudo/src/lib.rs @@ -273,17 +273,12 @@ pub mod pallet { pub(super) type Key = StorageValue<_, T::AccountId, OptionQuery>; #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { /// The `AccountId` of the sudo key. pub key: Option, } - impl Default for GenesisConfig { - fn default() -> Self { - Self { key: None } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 822c7e9b631f7..8f98295dd385a 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -214,16 +214,11 @@ pub mod pallet { pub struct Pallet(_); #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub vesting: Vec<(T::AccountId, T::BlockNumber, T::BlockNumber, BalanceOf)>, } - impl Default for GenesisConfig { - fn default() -> Self { - GenesisConfig { vesting: Default::default() } - } - } - #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { From 212255758f71419f2e559e57fb6681314fbe3e6d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 10 May 2023 16:24:47 +0200 Subject: [PATCH 5/7] treasury: derive(Default) --- frame/treasury/src/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 5fa999c7dce8c..847ff96a7a78b 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -234,14 +234,9 @@ pub mod pallet { StorageValue<_, BoundedVec, ValueQuery>; #[pallet::genesis_config] + #[derive(Default)] pub struct GenesisConfig; - impl Default for GenesisConfig { - fn default() -> Self { - Self - } - } - #[cfg(feature = "std")] impl GenesisConfig { /// Direct implementation of `GenesisBuild::assimilate_storage`. From 87ac9dea8c1915d9200a2814e847cc2b282929fe Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 10 May 2023 16:41:25 +0200 Subject: [PATCH 6/7] Cargo.lock update --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 289e0c2c02b8a..0e6e8e847a01b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5516,7 +5516,7 @@ dependencies = [ name = "node-template-release" version = "3.0.0" dependencies = [ - "clap 4.2.5", + "clap 4.2.7", "flate2", "fs_extra", "git2", From 15e9eb99f05950d9db011f6e523e5298d9f74c0f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 12 May 2023 12:50:15 +0200 Subject: [PATCH 7/7] genesis_config: compiler error improved When std feature is not enabled for pallet, the GenesisConfig will be defined, but serde::{Serialize,Deserialize} traits will not be implemented. The compiler error indicates the reason of latter errors. This is temporary and serde traits will be enabled with together with `serde` support in frame. --- .../src/pallet/expand/genesis_config.rs | 2 +- frame/support/test/pallet/src/lib.rs | 2 +- .../no_std_genesis_config.stderr | 109 +++++++++++++++++- .../undefined_genesis_config_part.stderr | 4 +- 4 files changed, 109 insertions(+), 8 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/genesis_config.rs b/frame/support/procedural/src/pallet/expand/genesis_config.rs index 0337395ed1227..3f3e7b731f93b 100644 --- a/frame/support/procedural/src/pallet/expand/genesis_config.rs +++ b/frame/support/procedural/src/pallet/expand/genesis_config.rs @@ -135,7 +135,7 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream { stringify!($pallet_name), "` does not have the std feature enabled, this will cause the `", $pallet_path, - "::GenesisConfig` type to be undefined." + "::GenesisConfig` type to not implement serde traits." )); }; } diff --git a/frame/support/test/pallet/src/lib.rs b/frame/support/test/pallet/src/lib.rs index 2dfc94d83187a..f2d0fd7b80d8d 100644 --- a/frame/support/test/pallet/src/lib.rs +++ b/frame/support/test/pallet/src/lib.rs @@ -37,7 +37,7 @@ pub mod pallet { pub type Value = StorageValue<_, u32>; #[pallet::genesis_config] - #[cfg_attr(feature = "std", derive(Default))] + #[derive(Default)] pub struct GenesisConfig {} #[pallet::genesis_build] diff --git a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr index cfc8c9264eec6..afa210c1ae59d 100644 --- a/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr +++ b/frame/support/test/tests/construct_runtime_ui/no_std_genesis_config.stderr @@ -1,4 +1,4 @@ -error: `Pallet` does not have the std feature enabled, this will cause the `test_pallet::GenesisConfig` type to be undefined. +error: `Pallet` does not have the std feature enabled, this will cause the `test_pallet::GenesisConfig` type to not implement serde traits. --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 | 40 | / construct_runtime! { @@ -12,7 +12,7 @@ error: `Pallet` does not have the std feature enabled, this will cause the `test | = note: this error originates in the macro `test_pallet::__substrate_genesis_config_check::is_std_enabled_for_genesis` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet` +error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Serialize` is not satisfied --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 | 40 | / construct_runtime! { @@ -22,10 +22,109 @@ error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet` ... | 48 | | } 49 | | } - | |_^ not found in `test_pallet` + | |_^ the trait `Serialize` is not implemented for `frame_support_test_pallet::GenesisConfig` | + = help: the following other types implement trait `Serialize`: + &'a T + &'a mut T + () + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) + (T0, T1, T2, T3, T4) + (T0, T1, T2, T3, T4, T5) + and $N others +note: required by a bound in `hidden_include::serde::ser::SerializeStruct::serialize_field` + --> $CARGO/serde-1.0.162/src/ser/mod.rs + | + | T: Serialize; + | ^^^^^^^^^ required by this bound in `SerializeStruct::serialize_field` + = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Deserialize<'_>` is not satisfied + --> tests/construct_runtime_ui/no_std_genesis_config.rs:47:3 + | +47 | Pallet: test_pallet::{Pallet, Config}, + | ^^^^^^ the trait `Deserialize<'_>` is not implemented for `frame_support_test_pallet::GenesisConfig` + | + = help: the following other types implement trait `Deserialize<'de>`: + <&'a [u8] as Deserialize<'de>> + <&'a std::path::Path as Deserialize<'de>> + <&'a str as Deserialize<'de>> + <() as Deserialize<'de>> + <(T0, T1) as Deserialize<'de>> + <(T0, T1, T2) as Deserialize<'de>> + <(T0, T1, T2, T3) as Deserialize<'de>> + <(T0, T1, T2, T3, T4) as Deserialize<'de>> + and $N others +note: required by a bound in `next_element` + --> $CARGO/serde-1.0.162/src/de/mod.rs + | + | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `SeqAccess::next_element` + +error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Deserialize<'_>` is not satisfied + --> tests/construct_runtime_ui/no_std_genesis_config.rs:47:3 + | +47 | Pallet: test_pallet::{Pallet, Config}, + | ^^^^^^ the trait `Deserialize<'_>` is not implemented for `frame_support_test_pallet::GenesisConfig` + | + = help: the following other types implement trait `Deserialize<'de>`: + <&'a [u8] as Deserialize<'de>> + <&'a std::path::Path as Deserialize<'de>> + <&'a str as Deserialize<'de>> + <() as Deserialize<'de>> + <(T0, T1) as Deserialize<'de>> + <(T0, T1, T2) as Deserialize<'de>> + <(T0, T1, T2, T3) as Deserialize<'de>> + <(T0, T1, T2, T3, T4) as Deserialize<'de>> + and $N others +note: required by a bound in `next_value` + --> $CARGO/serde-1.0.162/src/de/mod.rs + | + | V: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value` + +error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Deserialize<'_>` is not satisfied + --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 + | +40 | / construct_runtime! { +41 | | pub struct Runtime where +42 | | Block = Block, +43 | | NodeBlock = Block, +... | +48 | | } +49 | | } + | |_^ the trait `Deserialize<'_>` is not implemented for `frame_support_test_pallet::GenesisConfig` + | + = help: the following other types implement trait `Deserialize<'de>`: + <&'a [u8] as Deserialize<'de>> + <&'a std::path::Path as Deserialize<'de>> + <&'a str as Deserialize<'de>> + <() as Deserialize<'de>> + <(T0, T1) as Deserialize<'de>> + <(T0, T1, T2) as Deserialize<'de>> + <(T0, T1, T2, T3) as Deserialize<'de>> + <(T0, T1, T2, T3, T4) as Deserialize<'de>> + and $N others +note: required by a bound in `hidden_include::serde::__private::de::missing_field` + --> $CARGO/serde-1.0.162/src/private/de.rs + | + | V: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `missing_field` = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing this struct + +error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: BuildModuleGenesisStorage` is not satisfied + --> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1 | -1 | use frame_system::GenesisConfig; +40 | / construct_runtime! { +41 | | pub struct Runtime where +42 | | Block = Block, +43 | | NodeBlock = Block, +... | +48 | | } +49 | | } + | |_^ the trait `BuildModuleGenesisStorage` is not implemented for `frame_support_test_pallet::GenesisConfig` | + = help: the trait `BuildModuleGenesisStorage` is implemented for `frame_system::GenesisConfig` + = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr index f56780c0b0c0d..a5f6b3a1093ea 100644 --- a/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr +++ b/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr @@ -28,7 +28,9 @@ error[E0412]: cannot find type `GenesisConfig` in module `pallet` | |_^ not found in `pallet` | = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing this struct +help: consider importing one of these items | 1 | use frame_system::GenesisConfig; | +1 | use test_pallet::GenesisConfig; + |