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

Commit

Permalink
pallets: implement Default for GenesisConfig in no_std (#7271)
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

* Cargo.lock updated

* update lockfile for {"substrate"}

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
michalkucharczyk committed May 25, 2023
1 parent 3346866 commit b09937a
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 223 deletions.
370 changes: 185 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use frame_support::{
ensure,
traits::{Currency, Get, IsSubType, VestingSchedule},
weights::Weight,
DefaultNoBound,
};
pub use pallet::*;
use parity_scale_codec::{Decode, Encode};
Expand All @@ -28,10 +29,8 @@ use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256};
#[cfg(feature = "std")]
use sp_runtime::traits::Zero;
use sp_runtime::{
traits::{CheckedSub, DispatchInfoOf, SignedExtension},
traits::{CheckedSub, DispatchInfoOf, SignedExtension, Zero},
transaction_validity::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
},
Expand Down Expand Up @@ -229,19 +228,13 @@ pub mod pallet {
pub(super) type Preclaims<T: Config> = StorageMap<_, Identity, T::AccountId, EthereumAddress>;

#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub claims:
Vec<(EthereumAddress, BalanceOf<T>, Option<T::AccountId>, Option<StatementKind>)>,
pub vesting: Vec<(EthereumAddress, (BalanceOf<T>, BalanceOf<T>, T::BlockNumber))>,
}

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

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ pub mod pallet {
pub next_free_para_id: ParaId,
}

#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
GenesisConfig { next_free_para_id: LOWEST_PUBLIC_ID }
Expand Down
10 changes: 2 additions & 8 deletions runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Configuration can change only at session boundaries and is buffered until then.

use crate::{inclusion::MAX_UPWARD_MESSAGE_SIZE_BOUND, shared};
use frame_support::pallet_prelude::*;
use frame_support::{pallet_prelude::*, DefaultNoBound};
use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use polkadot_parachain::primitives::{MAX_HORIZONTAL_MESSAGE_NUM, MAX_UPWARD_MESSAGE_NUM};
Expand Down Expand Up @@ -525,17 +525,11 @@ pub mod pallet {
pub(crate) type BypassConsistencyCheck<T: Config> = StorageValue<_, bool, ValueQuery>;

#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub config: HostConfiguration<T::BlockNumber>,
}

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

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
Expand Down
12 changes: 2 additions & 10 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
configuration::{self, HostConfiguration},
dmp, ensure_parachain, initializer, paras,
};
use frame_support::{pallet_prelude::*, traits::ReservableCurrency};
use frame_support::{pallet_prelude::*, traits::ReservableCurrency, DefaultNoBound};
use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use polkadot_parachain::primitives::HorizontalMessages;
Expand Down Expand Up @@ -435,17 +435,11 @@ pub mod pallet {
/// configuration pallet.
/// 2. `sender` and `recipient` must be valid paras.
#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig {
preopen_hrmp_channels: Vec<(ParaId, ParaId, u32, u32)>,
}

#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
GenesisConfig { preopen_hrmp_channels: Default::default() }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
Expand Down Expand Up @@ -621,7 +615,6 @@ pub mod pallet {
}
}

#[cfg(feature = "std")]
fn initialize_storage<T: Config>(preopen_hrmp_channels: &[(ParaId, ParaId, u32, u32)]) {
let host_config = configuration::Pallet::<T>::config();
for &(sender, recipient, max_capacity, max_message_size) in preopen_hrmp_channels {
Expand All @@ -634,7 +627,6 @@ fn initialize_storage<T: Config>(preopen_hrmp_channels: &[(ParaId, ParaId, u32,
<Pallet<T>>::process_hrmp_open_channel_requests(&host_config);
}

#[cfg(feature = "std")]
fn preopen_hrmp_channel<T: Config>(
sender: ParaId,
recipient: ParaId,
Expand Down
10 changes: 2 additions & 8 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use crate::{
shared,
};
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
use frame_support::{pallet_prelude::*, traits::EstimateNextSessionRotation};
use frame_support::{pallet_prelude::*, traits::EstimateNextSessionRotation, DefaultNoBound};
use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use primitives::{
Expand Down Expand Up @@ -771,17 +771,11 @@ pub mod pallet {
StorageMap<_, Identity, ValidationCodeHash, ValidationCode>;

#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig {
pub paras: Vec<(ParaId, ParaGenesisArgs)>,
}

#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
GenesisConfig { paras: Default::default() }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
Expand Down
1 change: 0 additions & 1 deletion xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ pub mod pallet {
pub safe_xcm_version: Option<XcmVersion>,
}

#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
Self { safe_xcm_version: Some(XCM_VERSION) }
Expand Down

0 comments on commit b09937a

Please sign in to comment.