Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
enddynayn committed Aug 29, 2024
1 parent c9127fa commit e32ca70
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 104 deletions.
104 changes: 1 addition & 103 deletions node/service/src/chain_spec/frequency_paseo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,108 +68,6 @@ pub fn local_paseo_testnet_config() -> ChainSpec {
.with_protocol_id("frequency-paseo-local")
.with_properties(properties)
.with_chain_type(ChainType::Local)
.with_genesis_config(testnet_genesis(
// initial collators.
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"),
),
],
// Sudo
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
// Endowed Accounts
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(),
],
// Council members
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"),
],
// Technical Committee members
vec![
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
],
// ParaId
2000.into(),
))
.with_genesis_config_preset_name("paseo-testnet")
.build()
}

#[allow(clippy::unwrap_used)]
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
root_key: Option<AccountId>,
endowed_accounts: Vec<AccountId>,
council_members: Vec<AccountId>,
technical_committee_members: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
let genesis = frequency_runtime::RuntimeGenesisConfig {
system: frequency_runtime::SystemConfig { ..Default::default() },
balances: frequency_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: frequency_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
collator_selection: frequency_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
session: frequency_runtime::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: root_key,
},
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()
}
157 changes: 157 additions & 0 deletions runtime/frequency/src/development_genesis.rs
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()
}
10 changes: 9 additions & 1 deletion runtime/frequency/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::development_genesis::*;
use crate::{development_genesis::*, paseo_genesis::*};
/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
let patch = match id.try_into() {
Expand All @@ -10,6 +10,14 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<
development_technical_committee_members(),
1000.into(),
),
Ok("paseo-testnet") => paseo_testnet_genesis(
paseo_invulnerables(),
paseo_root(),
paseo_endowed_accounts(),
paseo_council_members(),
paseo_technical_committee_members(),
2000.into(),
),
_ => return None,
};
Some(
Expand Down
1 change: 1 addition & 0 deletions runtime/frequency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use sp_runtime::{

pub mod development_genesis;
pub mod genesis_config_presets;
pub mod paseo_genesis;

use pallet_collective::Members;

Expand Down
Loading

0 comments on commit e32ca70

Please sign in to comment.