Skip to content

Commit

Permalink
pallets: implement Default for GenesisConfig in no_std (#2624)
Browse files Browse the repository at this point in the history
* pallets: implement Default for GenesisConfig in no_std

This change is follow-up of: paritytech/substrate#14108

It is a step towards: https://github.com/paritytech/substrate/issues/13334

* ".git/.scripts/commands/fmt/fmt.sh"

* update lockfile for {"substrate", "polkadot"}

---------

Co-authored-by: command-bot <>
  • Loading branch information
michalkucharczyk committed May 25, 2023
1 parent 17dd099 commit 54121c3
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions system-parachains/common/pallets/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub mod pallet {
Currency, EnsureOrigin, ExistenceRequirement::KeepAlive, ReservableCurrency,
ValidatorRegistration,
},
BoundedVec, PalletId,
BoundedVec, DefaultNoBound, PalletId,
};
use frame_system::{pallet_prelude::*, Config as SystemConfig};
use pallet_session::SessionManager;
Expand Down Expand Up @@ -203,28 +203,20 @@ pub mod pallet {
pub type CandidacyBond<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;

#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub invulnerables: Vec<T::AccountId>,
pub candidacy_bond: BalanceOf<T>,
pub desired_candidates: u32,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
invulnerables: Default::default(),
candidacy_bond: Default::default(),
desired_candidates: Default::default(),
}
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
let duplicate_invulnerables =
self.invulnerables.iter().collect::<std::collections::BTreeSet<_>>();
let duplicate_invulnerables = self
.invulnerables
.iter()
.collect::<sp_std::collections::btree_set::BTreeSet<_>>();
assert!(
duplicate_invulnerables.len() == self.invulnerables.len(),
"duplicate invulnerables in genesis."
Expand Down

0 comments on commit 54121c3

Please sign in to comment.