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

Commit 76c06c9

Browse files
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
1 parent 014ce4b commit 76c06c9

5 files changed

Lines changed: 9 additions & 45 deletions

File tree

bridges/modules/grandpa/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use bp_header_chain::{
4444
};
4545
use bp_runtime::{BlockNumberOf, HashOf, HasherOf, HeaderId, HeaderOf, OwnedBridgeModule};
4646
use finality_grandpa::voter_set::VoterSet;
47-
use frame_support::{dispatch::PostDispatchInfo, ensure};
47+
use frame_support::{DefaultNoBound,dispatch::PostDispatchInfo, ensure};
4848
use sp_consensus_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
4949
use sp_runtime::{
5050
traits::{Header as HeaderT, Zero},
@@ -370,20 +370,14 @@ pub mod pallet {
370370
StorageValue<_, BasicOperatingMode, ValueQuery>;
371371

372372
#[pallet::genesis_config]
373+
#[derive(DefaultNoBound)]
373374
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
374375
/// Optional module owner account.
375376
pub owner: Option<T::AccountId>,
376377
/// Optional module initialization data.
377378
pub init_data: Option<super::InitializationData<BridgedHeader<T, I>>>,
378379
}
379380

380-
#[cfg(feature = "std")]
381-
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
382-
fn default() -> Self {
383-
Self { owner: None, init_data: None }
384-
}
385-
}
386-
387381
#[pallet::genesis_build]
388382
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
389383
fn build(&self) {

bridges/modules/messages/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use bp_messages::{
6565
};
6666
use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, PreComputedSize, Size};
6767
use codec::{Decode, Encode, MaxEncodedLen};
68-
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get};
68+
use frame_support::{DefaultNoBound, dispatch::PostDispatchInfo, ensure, fail, traits::Get};
6969
use sp_runtime::traits::UniqueSaturatedFrom;
7070
use sp_std::{marker::PhantomData, prelude::*};
7171

@@ -586,6 +586,7 @@ pub mod pallet {
586586
StorageMap<_, Blake2_128Concat, MessageKey, StoredMessagePayload<T, I>>;
587587

588588
#[pallet::genesis_config]
589+
#[derive(DefaultNoBound)]
589590
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
590591
/// Initial pallet operating mode.
591592
pub operating_mode: MessagesOperatingMode,
@@ -595,17 +596,6 @@ pub mod pallet {
595596
pub phantom: sp_std::marker::PhantomData<I>,
596597
}
597598

598-
#[cfg(feature = "std")]
599-
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
600-
fn default() -> Self {
601-
Self {
602-
operating_mode: Default::default(),
603-
owner: Default::default(),
604-
phantom: Default::default(),
605-
}
606-
}
607-
}
608-
609599
#[pallet::genesis_build]
610600
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
611601
fn build(&self) {

bridges/modules/parachains/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use bp_header_chain::{HeaderChain, HeaderChainError};
3030
use bp_parachains::{parachain_head_storage_key_at_source, ParaInfo, ParaStoredHeaderData};
3131
use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId};
3232
use bp_runtime::{Chain, HashOf, HeaderId, HeaderIdOf, Parachain, StorageProofError};
33-
use frame_support::dispatch::PostDispatchInfo;
33+
use frame_support::{DefaultNoBound, dispatch::PostDispatchInfo};
3434
use sp_std::{marker::PhantomData, vec::Vec};
3535

3636
#[cfg(feature = "runtime-benchmarks")]
@@ -611,6 +611,7 @@ pub mod pallet {
611611
}
612612

613613
#[pallet::genesis_config]
614+
#[derive(DefaultNoBound)]
614615
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
615616
/// Initial pallet operating mode.
616617
pub operating_mode: BasicOperatingMode,
@@ -620,17 +621,6 @@ pub mod pallet {
620621
pub phantom: sp_std::marker::PhantomData<I>,
621622
}
622623

623-
#[cfg(feature = "std")]
624-
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
625-
fn default() -> Self {
626-
Self {
627-
operating_mode: Default::default(),
628-
owner: Default::default(),
629-
phantom: Default::default(),
630-
}
631-
}
632-
}
633-
634624
#[pallet::genesis_build]
635625
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
636626
fn build(&self) {

pallets/collator-selection/src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub mod pallet {
7777
pub use crate::weights::WeightInfo;
7878
use core::ops::Div;
7979
use frame_support::{
80+
DefaultNoBound,
8081
dispatch::{DispatchClass, DispatchResultWithPostInfo},
8182
inherent::Vec,
8283
pallet_prelude::*,
@@ -203,28 +204,18 @@ pub mod pallet {
203204
pub type CandidacyBond<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;
204205

205206
#[pallet::genesis_config]
207+
#[derive(DefaultNoBound)]
206208
pub struct GenesisConfig<T: Config> {
207209
pub invulnerables: Vec<T::AccountId>,
208210
pub candidacy_bond: BalanceOf<T>,
209211
pub desired_candidates: u32,
210212
}
211213

212-
#[cfg(feature = "std")]
213-
impl<T: Config> Default for GenesisConfig<T> {
214-
fn default() -> Self {
215-
Self {
216-
invulnerables: Default::default(),
217-
candidacy_bond: Default::default(),
218-
desired_candidates: Default::default(),
219-
}
220-
}
221-
}
222-
223214
#[pallet::genesis_build]
224215
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
225216
fn build(&self) {
226217
let duplicate_invulnerables =
227-
self.invulnerables.iter().collect::<std::collections::BTreeSet<_>>();
218+
self.invulnerables.iter().collect::<sp_std::collections::btree_set::BTreeSet<_>>();
228219
assert!(
229220
duplicate_invulnerables.len() == self.invulnerables.len(),
230221
"duplicate invulnerables in genesis."

parachains/pallets/parachain-info/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub mod pallet {
4343
pub parachain_id: ParaId,
4444
}
4545

46-
#[cfg(feature = "std")]
4746
impl Default for GenesisConfig {
4847
fn default() -> Self {
4948
Self { parachain_id: 100.into() }

0 commit comments

Comments
 (0)