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

Commit

Permalink
GenesisBuild<T,I> deprecated. BuildGenesisConfig added. (#14306)
Browse files Browse the repository at this point in the history
* frame::support: GenesisConfig types for Runtime enabled

* frame::support: macro generating GenesisBuild::build for RuntimeGenesisConfig

* frame: ambiguity BuildStorage vs GenesisBuild fixed

* fix

* RuntimeGenesisBuild added

* Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed"

This reverts commit 6017dad.

* Revert "fix"

This reverts commit 477d7ad.

* Revert "RuntimeGenesisBuild added"

This reverts commit 3c131b6.

* Revert "Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed""

This reverts commit 2b1ecd4.

* Revert "Revert "fix""

This reverts commit fd7fa62.

* Code review suggestions

* frame: BuildGenesisConfig added, BuildGenesis deprecated

* frame: some pallets updated with BuildGenesisConfig

* constuct_runtime: support for BuildGenesisConfig

* frame::support: genesis_build macro supports BuildGenesisConfig

* frame: BuildGenesisConfig added, BuildGenesis deprecated

* Cargo.lock update

* test-runtime: fixes

* Revert "fix"

This reverts commit 477d7ad.

* Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed"

This reverts commit 6017dad.

* self review

* doc fixed

* ui tests fixed

* fmt

* tests fixed

* genesis_build macrto fixed for non-generic GenesisConfig

* BuildGenesisConfig constraints added

* warning fixed

* some duplication removed

* fmt

* fix

* doc tests fix

* doc fix

* cleanup: remove BuildModuleGenesisStorage

* self review comments

* fix

* Update frame/treasury/src/tests.rs

Co-authored-by: Sebastian Kunert <[email protected]>

* Update frame/support/src/traits/hooks.rs

Co-authored-by: Sebastian Kunert <[email protected]>

* doc fix: GenesisBuild exposed

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

* frame: more serde(skip) + cleanup

* Update frame/support/src/traits/hooks.rs

Co-authored-by: Davide Galassi <[email protected]>

* frame: phantom fields moved to the end of structs

* chain-spec: Default::default cleanup

* test-runtime: phantom at the end

* merge master fixes

* fix

* fix

* fix

* fix

* fix (facepalm)

* Update frame/support/procedural/src/pallet/expand/genesis_build.rs

Co-authored-by: Bastian Köcher <[email protected]>

* fmt

* fix

* fix

---------

Co-authored-by: parity-processbot <>
Co-authored-by: Sebastian Kunert <[email protected]>
Co-authored-by: Davide Galassi <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
4 people authored and EgorPopelyaev committed Jul 18, 2023
1 parent d8e48f4 commit 022f15a
Show file tree
Hide file tree
Showing 165 changed files with 578 additions and 533 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bin/node-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn testnet_genesis(
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
..Default::default()
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
Expand All @@ -146,6 +147,7 @@ fn testnet_genesis(
},
grandpa: GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
..Default::default()
},
sudo: SudoConfig {
// Assign network admin rights.
Expand Down
3 changes: 2 additions & 1 deletion bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down Expand Up @@ -55,5 +56,5 @@ impl pallet_template::Config for Test {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
}
23 changes: 9 additions & 14 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

use grandpa_primitives::AuthorityId as GrandpaId;
use kitchensink_runtime::{
constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig,
BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GluttonConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, MaxNominations, NominationPoolsConfig,
SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig,
SystemConfig, TechnicalCommitteeConfig,
constants::currency::*, wasm_binary_unwrap, BabeConfig, BalancesConfig, Block, CouncilConfig,
DemocracyConfig, ElectionsConfig, ImOnlineConfig, IndicesConfig, MaxNominations,
NominationPoolsConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, TechnicalCommitteeConfig,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec::ChainSpecExtension;
Expand Down Expand Up @@ -295,7 +294,7 @@ pub fn testnet_genesis(
const STASH: Balance = ENDOWMENT / 1000;

RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary_unwrap().to_vec() },
system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() },
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
},
Expand Down Expand Up @@ -340,12 +339,12 @@ pub fn testnet_genesis(
},
sudo: SudoConfig { key: Some(root_key) },
babe: BabeConfig {
authorities: vec![],
epoch_config: Some(kitchensink_runtime::BABE_GENESIS_EPOCH_CONFIG),
..Default::default()
},
im_online: ImOnlineConfig { keys: vec![] },
authority_discovery: AuthorityDiscoveryConfig { keys: vec![] },
grandpa: GrandpaConfig { authorities: vec![] },
authority_discovery: Default::default(),
grandpa: Default::default(),
technical_membership: Default::default(),
treasury: Default::default(),
society: SocietyConfig { pot: 0 },
Expand All @@ -365,11 +364,7 @@ pub fn testnet_genesis(
min_join_bond: 1 * DOLLARS,
..Default::default()
},
glutton: GluttonConfig {
compute: Default::default(),
storage: Default::default(),
trash_data_count: Default::default(),
},
glutton: Default::default(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod multiplier_tests {
use sp_runtime::{
assert_eq_error_rate,
traits::{Convert, One, Zero},
FixedPointNumber,
BuildStorage, FixedPointNumber,
};

use crate::{
Expand Down Expand Up @@ -197,8 +197,8 @@ mod multiplier_tests {
where
F: Fn() -> (),
{
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap()
.into();
t.execute_with(|| {
Expand Down
10 changes: 8 additions & 2 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Run
RuntimeGenesisConfig {
system: SystemConfig {
code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()),
..Default::default()
},
indices: IndicesConfig { indices: vec![] },
balances: BalancesConfig { balances: endowed },
Expand All @@ -76,8 +77,12 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Run
invulnerables: vec![alice(), bob(), charlie()],
..Default::default()
},
babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG) },
grandpa: GrandpaConfig { authorities: vec![] },
babe: BabeConfig {
authorities: vec![],
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
..Default::default()
},
grandpa: GrandpaConfig { authorities: vec![], _config: Default::default() },
im_online: Default::default(),
authority_discovery: Default::default(),
democracy: Default::default(),
Expand All @@ -100,6 +105,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Run
compute: Default::default(),
storage: Default::default(),
trash_data_count: Default::default(),
..Default::default()
},
}
}
3 changes: 2 additions & 1 deletion frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@ pub mod pallet {
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub fellows: Vec<T::AccountId>,
pub allies: Vec<T::AccountId>,
#[serde(skip)]
pub phantom: PhantomData<(T, I)>,
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
for m in self.fellows.iter().chain(self.allies.iter()) {
assert!(Pallet::<T, I>::has_identity(m).is_ok(), "Member does not set identity!");
Expand Down
18 changes: 8 additions & 10 deletions frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sp_std::convert::{TryFrom, TryInto};

pub use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{EitherOfDiverse, GenesisBuild, SortedMembers},
traits::{EitherOfDiverse, SortedMembers},
BoundedVec,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
Expand Down Expand Up @@ -256,7 +256,7 @@ frame_support::construct_runtime!(
);

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> {
balances: vec![
Expand All @@ -274,14 +274,12 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.assimilate_storage(&mut t)
.unwrap();

GenesisBuild::<Test>::assimilate_storage(
&pallet_alliance::GenesisConfig {
fellows: vec![],
allies: vec![],
phantom: Default::default(),
},
&mut t,
)
pallet_alliance::GenesisConfig::<Test> {
fellows: vec![],
allies: vec![],
phantom: Default::default(),
}
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
Expand Down
4 changes: 2 additions & 2 deletions frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

Expand Down Expand Up @@ -183,7 +183,7 @@ impl Config for Test {
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10000), (2, 20000), (3, 30000), (4, 40000)],
Expand Down
3 changes: 2 additions & 1 deletion frame/asset-rate/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down Expand Up @@ -96,5 +97,5 @@ impl pallet_asset_rate::Config for Test {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
}
2 changes: 1 addition & 1 deletion frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
for (id, owner, is_sufficient, min_balance) in &self.assets {
assert!(!Asset::<T, I>::contains_key(id), "Asset id already in use");
Expand Down
7 changes: 4 additions & 3 deletions frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ use crate as pallet_assets;
use codec::Encode;
use frame_support::{
construct_runtime, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, GenesisBuild},
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64},
};
use sp_core::H256;
use sp_io::storage;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand All @@ -41,7 +42,7 @@ construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
}
Expand Down Expand Up @@ -205,7 +206,7 @@ pub(crate) fn take_hooks() -> Vec<Hook> {
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

let config: pallet_assets::GenesisConfig<Test> = pallet_assets::GenesisConfig {
assets: vec![
Expand Down
5 changes: 3 additions & 2 deletions frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand All @@ -19,7 +20,7 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
AtomicSwap: pallet_atomic_swap::{Pallet, Call, Event<T>},
}
Expand Down Expand Up @@ -78,7 +79,7 @@ const A: u64 = 1;
const B: u64 = 2;

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let genesis = pallet_balances::GenesisConfig::<Test> { balances: vec![(A, 100), (B, 200)] };
genesis.assimilate_storage(&mut t).unwrap();
t.into()
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
Pallet::<T>::initialize_authorities(&self.authorities);
}
Expand Down
7 changes: 4 additions & 3 deletions frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
use crate as pallet_aura;
use frame_support::{
parameter_types,
traits::{ConstU32, ConstU64, DisabledValidators, GenesisBuild},
traits::{ConstU32, ConstU64, DisabledValidators},
};
use sp_consensus_aura::{ed25519::AuthorityId, AuthorityIndex};
use sp_core::H256;
use sp_runtime::{
testing::{Header, UintAuthorityId},
traits::IdentityLookup,
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand All @@ -40,7 +41,7 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Aura: pallet_aura::{Pallet, Storage, Config<T>},
}
Expand Down Expand Up @@ -111,7 +112,7 @@ impl pallet_aura::Config for Test {
}

fn build_ext(authorities: Vec<u64>) -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_aura::GenesisConfig::<Test> {
authorities: authorities.into_iter().map(|a| UintAuthorityId(a).to_public_key()).collect(),
}
Expand Down
Loading

0 comments on commit 022f15a

Please sign in to comment.