-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(genesis): move development genesis config to runtime
Move Development Genesis Config to the Runtime to support decoupling of client and runtime dependencies. When running `chain-spec-builder`, the following command: ``` chain-spec-builder list-presets –runtime-wasm-path ./target/debug/wbuild/frequency-runtime/frequency_runtime.wasm ``` outputs: ``` {“presets”:[“development”]} ``` issue-2149 issue-2142 #2149
- Loading branch information
Showing
7 changed files
with
202 additions
and
141 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
use common_primitives::node::Verify; | ||
use cumulus_primitives_core::ParaId; | ||
use sp_core::{sr25519, Pair, Public}; | ||
use sp_runtime::traits::IdentifyAccount; | ||
#[cfg(not(feature = "std"))] | ||
use sp_std::alloc::format; | ||
|
||
use crate::*; | ||
// Generate the session keys from individual elements. | ||
// | ||
// The input must be a tuple of individual keys (a single arg for now since we have just one key). | ||
fn template_session_keys(keys: AuraId) -> SessionKeys { | ||
SessionKeys { aura: keys } | ||
} | ||
|
||
#[allow(clippy::unwrap_used)] | ||
fn load_genesis_schemas() -> Vec<crate::pallet_schemas::GenesisSchema> { | ||
serde_json::from_slice(include_bytes!("../../../resources/genesis-schemas.json")).unwrap() | ||
} | ||
|
||
type AccountPublic = <Signature as Verify>::Signer; | ||
|
||
#[allow(clippy::unwrap_used)] | ||
pub fn development_genesis( | ||
invulnerables: Vec<(AccountId, AuraId)>, | ||
root_key: AccountId, | ||
endowed_accounts: Vec<AccountId>, | ||
council_members: Vec<AccountId>, | ||
technical_committee_members: Vec<AccountId>, | ||
id: ParaId, | ||
) -> serde_json::Value { | ||
let genesis = RuntimeGenesisConfig { | ||
system: Default::default(), | ||
balances: BalancesConfig { | ||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), | ||
}, | ||
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, | ||
collator_selection: CollatorSelectionConfig { | ||
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), | ||
candidacy_bond: EXISTENTIAL_DEPOSIT * 16, | ||
..Default::default() | ||
}, | ||
session: SessionConfig { | ||
keys: invulnerables | ||
.into_iter() | ||
.map(|(acc, aura)| { | ||
( | ||
acc.clone(), // account id | ||
acc, // validator id | ||
template_session_keys(aura), // session keys | ||
) | ||
}) | ||
.collect(), | ||
}, | ||
// no need to pass anything to aura, in fact it will panic if we do. Session will take care | ||
// of this. | ||
aura: Default::default(), | ||
aura_ext: Default::default(), | ||
#[cfg(any(not(feature = "frequency-no-relay"), feature = "frequency-lint-check"))] | ||
parachain_system: Default::default(), | ||
sudo: SudoConfig { | ||
// Assign network admin rights. | ||
key: Some(root_key), | ||
}, | ||
schemas: crate::pallet_schemas::GenesisConfig { | ||
initial_schemas: load_genesis_schemas(), | ||
..Default::default() | ||
}, | ||
time_release: Default::default(), | ||
democracy: Default::default(), | ||
treasury: Default::default(), | ||
council: CouncilConfig { phantom: Default::default(), members: council_members }, | ||
technical_committee: TechnicalCommitteeConfig { | ||
phantom: Default::default(), | ||
members: technical_committee_members, | ||
}, | ||
}; | ||
|
||
serde_json::to_value(&genesis).unwrap() | ||
} | ||
|
||
pub fn development_endowed_accounts() -> Vec<AccountId> { | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), | ||
common_runtime::constants::TREASURY_PALLET_ID.into_account_truncating(), | ||
] | ||
} | ||
|
||
pub fn development_invulnerables() -> Vec<(AccountId, AuraId)> { | ||
vec![ | ||
( | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_collator_keys_from_seed("Alice"), | ||
), | ||
(get_account_id_from_seed::<sr25519::Public>("Bob"), get_collator_keys_from_seed("Bob")), | ||
] | ||
} | ||
|
||
pub fn development_root() -> AccountId { | ||
get_account_id_from_seed::<sr25519::Public>("Alice") | ||
} | ||
|
||
pub fn development_council_members() -> Vec<AccountId> { | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve"), | ||
] | ||
} | ||
|
||
pub fn development_technical_committee_members() -> Vec<AccountId> { | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave"), | ||
] | ||
} | ||
|
||
/// Helper function to generate a crypto pair from seed | ||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { | ||
TPublic::Pair::from_string(&format!("//{}", seed), None) | ||
.expect("static values are valid; qed") | ||
.public() | ||
} | ||
|
||
/// Helper function to generate an account ID from seed | ||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId | ||
where | ||
AccountPublic: From<<TPublic::Pair as Pair>::Public>, | ||
{ | ||
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() | ||
} | ||
|
||
/// Generate collator keys from seed. | ||
/// | ||
/// This function's return type must always match the session keys of the chain in tuple format. | ||
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId { | ||
get_public_from_seed::<AuraId>(seed) | ||
} | ||
|
||
#[allow(clippy::expect_used)] | ||
/// Helper function to generate a crypto pair from seed | ||
pub fn get_public_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { | ||
TPublic::Pair::from_string(&format!("//{}", seed), None) | ||
.expect("static values are valid; qed") | ||
.public() | ||
} |
Oops, something went wrong.