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

frame: Enable GenesisConfig in no_std #14108

Merged
merged 10 commits into from
May 20, 2023
1 change: 0 additions & 1 deletion frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ pub mod pallet {
pub phantom: PhantomData<(T, I)>,
}

#[cfg(feature = "std")]
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { fellows: Vec::new(), allies: Vec::new(), phantom: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ pub mod pallet {
pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>,
}

#[cfg(feature = "std")]
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ pub mod pallet {
pub authorities: Vec<T::AuthorityId>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { authorities: Vec::new() }
Expand Down
2 changes: 1 addition & 1 deletion frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod pallet {
pub(super) type NextKeys<T: Config> =
StorageValue<_, WeakBoundedVec<AuthorityId, T::MaxAuthorities>, ValueQuery>;

#[cfg_attr(feature = "std", derive(Default))]
#[derive(Default)]
#[pallet::genesis_config]
pub struct GenesisConfig {
pub keys: Vec<AuthorityId>,
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub mod pallet {
pub(super) type SkippedEpochs<T> =
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)>,
Expand Down
3 changes: 1 addition & 2 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ pub mod pallet {
pub balances: Vec<(T::AccountId, T::Balance)>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { balances: Default::default() }
Expand All @@ -483,7 +482,7 @@ pub mod pallet {
.iter()
.map(|(x, _)| x)
.cloned()
.collect::<std::collections::BTreeSet<_>>();
.collect::<sp_std::collections::btree_set::BTreeSet<_>>();

assert!(
endowed_accounts.len() == self.balances.len(),
Expand Down
1 change: 0 additions & 1 deletion frame/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ pub mod pallet {
pub genesis_block: Option<BlockNumberFor<T>>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
// BEEFY genesis will be first BEEFY-MANDATORY block,
Expand Down
1 change: 0 additions & 1 deletion frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ pub mod pallet {
pub members: Vec<T::AccountId>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { phantom: Default::default(), members: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ pub mod pallet {
_phantom: sp_std::marker::PhantomData<T>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig { _phantom: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,6 @@ pub mod pallet {
pub members: Vec<(T::AccountId, BalanceOf<T>)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { members: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/examples/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ pub mod pallet {
}

// The default value for the genesis config type.
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { dummy: Default::default(), bar: Default::default(), foo: Default::default() }
Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ pub mod pallet {
#[pallet::getter(fn session_for_set)]
pub(super) type SetIdSession<T: Config> = StorageMap<_, Twox64Concat, SetId, SessionIndex>;

#[cfg_attr(feature = "std", derive(Default))]
#[derive(Default)]
#[pallet::genesis_config]
pub struct GenesisConfig {
pub authorities: AuthorityList,
Expand Down
1 change: 0 additions & 1 deletion frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ pub mod pallet {
pub keys: Vec<T::AuthorityId>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig { keys: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/indices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ pub mod pallet {
pub indices: Vec<(T::AccountIndex, T::AccountId)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { indices: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ pub mod pallet {
pub phantom: PhantomData<I>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { members: Default::default(), phantom: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/node-authorization/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ pub mod pallet {
pub nodes: Vec<(PeerId, T::AccountId)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { nodes: Vec::new() }
Expand Down
1 change: 0 additions & 1 deletion frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,6 @@ pub mod pallet {
pub global_max_commission: Option<Perbill>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion frame/scored-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ pub mod pallet {
pub member_count: u32,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { pool: Default::default(), member_count: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ pub mod pallet {
pub keys: Vec<(T::AccountId, T::ValidatorId, T::Keys)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { keys: Default::default() }
Expand Down
1 change: 0 additions & 1 deletion frame/society/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ pub mod pallet {
pub max_members: u32,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ pub mod pallet {
pub max_nominator_count: Option<u32>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig {
Expand Down
1 change: 0 additions & 1 deletion frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ pub mod pallet {
pub key: Option<T::AccountId>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { key: None }
Expand Down
23 changes: 16 additions & 7 deletions frame/support/procedural/src/pallet/expand/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,24 @@ 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))] ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can push them all in one quote call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is parse_quote! and will not work.

);
},
_ => unreachable!("Checked by genesis_config parser"),
}
Expand Down
5 changes: 2 additions & 3 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,10 @@ pub mod pallet {
#[pallet::whitelist_storage]
pub(super) type ExecutionPhase<T: Config> = 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<u8>,
}

Expand Down Expand Up @@ -712,7 +712,6 @@ pub struct EventRecord<E: Parameter + Member, T> {

// Create a Hash with 69 for each byte,
// only used to build genesis config.
#[cfg(feature = "std")]
fn hash69<T: AsMut<[u8]> + Default>() -> T {
let mut h = T::default();
h.as_mut().iter_mut().for_each(|byte| *byte = 69);
Expand Down
1 change: 0 additions & 1 deletion frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion frame/transaction-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ pub mod pallet {
pub storage_period: T::BlockNumber,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ pub mod pallet {
#[pallet::genesis_config]
pub struct GenesisConfig;

#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
Self
Expand Down
1 change: 0 additions & 1 deletion frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ pub mod pallet {
pub vesting: Vec<(T::AccountId, T::BlockNumber, T::BlockNumber, BalanceOf<T>)>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig { vesting: Default::default() }
Expand Down