Skip to content

Commit f44bcc9

Browse files
michalkucharczyknathanwhit
authored andcommitted
frame: Enable GenesisConfig in no_std (paritytech#14108)
* 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. * ".git/.scripts/commands/fmt/fmt.sh" * hash69 in no_std reverted * derive(DefaultNoBound) for GenesisConfig used when possible * treasury: derive(Default) * Cargo.lock update * 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. --------- Co-authored-by: command-bot <>
1 parent 6291861 commit f44bcc9

File tree

31 files changed

+149
-173
lines changed

31 files changed

+149
-173
lines changed

frame/alliance/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,13 @@ pub mod pallet {
401401
}
402402

403403
#[pallet::genesis_config]
404+
#[derive(frame_support::DefaultNoBound)]
404405
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
405406
pub fellows: Vec<T::AccountId>,
406407
pub allies: Vec<T::AccountId>,
407408
pub phantom: PhantomData<(T, I)>,
408409
}
409410

410-
#[cfg(feature = "std")]
411-
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
412-
fn default() -> Self {
413-
Self { fellows: Vec::new(), allies: Vec::new(), phantom: Default::default() }
414-
}
415-
}
416-
417411
#[pallet::genesis_build]
418412
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
419413
fn build(&self) {

frame/assets/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ pub mod pallet {
369369
>;
370370

371371
#[pallet::genesis_config]
372+
#[derive(frame_support::DefaultNoBound)]
372373
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
373374
/// Genesis assets: id, owner, is_sufficient, min_balance
374375
pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>,
@@ -378,17 +379,6 @@ pub mod pallet {
378379
pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>,
379380
}
380381

381-
#[cfg(feature = "std")]
382-
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
383-
fn default() -> Self {
384-
Self {
385-
assets: Default::default(),
386-
metadata: Default::default(),
387-
accounts: Default::default(),
388-
}
389-
}
390-
}
391-
392382
#[pallet::genesis_build]
393383
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
394384
fn build(&self) {

frame/aura/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,11 @@ pub mod pallet {
129129
pub(super) type CurrentSlot<T: Config> = StorageValue<_, Slot, ValueQuery>;
130130

131131
#[pallet::genesis_config]
132+
#[derive(frame_support::DefaultNoBound)]
132133
pub struct GenesisConfig<T: Config> {
133134
pub authorities: Vec<T::AuthorityId>,
134135
}
135136

136-
#[cfg(feature = "std")]
137-
impl<T: Config> Default for GenesisConfig<T> {
138-
fn default() -> Self {
139-
Self { authorities: Vec::new() }
140-
}
141-
}
142-
143137
#[pallet::genesis_build]
144138
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
145139
fn build(&self) {

frame/authority-discovery/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub mod pallet {
5959
pub(super) type NextKeys<T: Config> =
6060
StorageValue<_, WeakBoundedVec<AuthorityId, T::MaxAuthorities>, ValueQuery>;
6161

62-
#[cfg_attr(feature = "std", derive(Default))]
62+
#[derive(Default)]
6363
#[pallet::genesis_config]
6464
pub struct GenesisConfig {
6565
pub keys: Vec<AuthorityId>,

frame/babe/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub mod pallet {
314314
pub(super) type SkippedEpochs<T> =
315315
StorageValue<_, BoundedVec<(u64, SessionIndex), ConstU32<100>>, ValueQuery>;
316316

317-
#[cfg_attr(feature = "std", derive(Default))]
317+
#[derive(Default)]
318318
#[pallet::genesis_config]
319319
pub struct GenesisConfig {
320320
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,

frame/balances/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ pub mod pallet {
456456
pub balances: Vec<(T::AccountId, T::Balance)>,
457457
}
458458

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

488487
assert!(
489488
endowed_accounts.len() == self.balances.len(),

frame/beefy/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ pub mod pallet {
166166
pub genesis_block: Option<BlockNumberFor<T>>,
167167
}
168168

169-
#[cfg(feature = "std")]
170169
impl<T: Config> Default for GenesisConfig<T> {
171170
fn default() -> Self {
172171
// BEEFY genesis will be first BEEFY-MANDATORY block,

frame/collective/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,12 @@ pub mod pallet {
224224
}
225225

226226
#[pallet::genesis_config]
227+
#[derive(frame_support::DefaultNoBound)]
227228
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
228229
pub phantom: PhantomData<I>,
229230
pub members: Vec<T::AccountId>,
230231
}
231232

232-
#[cfg(feature = "std")]
233-
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
234-
fn default() -> Self {
235-
Self { phantom: Default::default(), members: Default::default() }
236-
}
237-
}
238-
239233
#[pallet::genesis_build]
240234
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
241235
fn build(&self) {

frame/democracy/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,11 @@ pub mod pallet {
439439
pub type MetadataOf<T: Config> = StorageMap<_, Blake2_128Concat, MetadataOwner, PreimageHash>;
440440

441441
#[pallet::genesis_config]
442+
#[derive(frame_support::DefaultNoBound)]
442443
pub struct GenesisConfig<T: Config> {
443444
_phantom: sp_std::marker::PhantomData<T>,
444445
}
445446

446-
#[cfg(feature = "std")]
447-
impl<T: Config> Default for GenesisConfig<T> {
448-
fn default() -> Self {
449-
GenesisConfig { _phantom: Default::default() }
450-
}
451-
}
452-
453447
#[pallet::genesis_build]
454448
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
455449
fn build(&self) {

frame/elections-phragmen/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,11 @@ pub mod pallet {
711711
StorageMap<_, Twox64Concat, T::AccountId, Voter<T::AccountId, BalanceOf<T>>, ValueQuery>;
712712

713713
#[pallet::genesis_config]
714+
#[derive(frame_support::DefaultNoBound)]
714715
pub struct GenesisConfig<T: Config> {
715716
pub members: Vec<(T::AccountId, BalanceOf<T>)>,
716717
}
717718

718-
#[cfg(feature = "std")]
719-
impl<T: Config> Default for GenesisConfig<T> {
720-
fn default() -> Self {
721-
Self { members: Default::default() }
722-
}
723-
}
724-
725719
#[pallet::genesis_build]
726720
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
727721
fn build(&self) {

0 commit comments

Comments
 (0)