mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
Add nominators option to chain-spec-builder (#8502)
* Add nominators option to chain-spec-builder * Update bin/utils/chain-spec-builder/src/main.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -23,9 +23,9 @@ use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use node_runtime::{
|
||||
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig,
|
||||
DemocracyConfig,GrandpaConfig, ImOnlineConfig, SessionConfig, SessionKeys, StakerStatus,
|
||||
DemocracyConfig, GrandpaConfig, ImOnlineConfig, SessionConfig, SessionKeys, StakerStatus,
|
||||
StakingConfig, ElectionsConfig, IndicesConfig, SocietyConfig, SudoConfig, SystemConfig,
|
||||
TechnicalCommitteeConfig, wasm_binary_unwrap,
|
||||
TechnicalCommitteeConfig, wasm_binary_unwrap, MAX_NOMINATIONS,
|
||||
};
|
||||
use node_runtime::Block;
|
||||
use node_runtime::constants::currency::*;
|
||||
@@ -146,12 +146,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
|
||||
let endowed_accounts: Vec<AccountId> = vec![root_key.clone()];
|
||||
|
||||
testnet_genesis(
|
||||
initial_authorities,
|
||||
root_key,
|
||||
Some(endowed_accounts),
|
||||
false,
|
||||
)
|
||||
testnet_genesis(initial_authorities, vec![], root_key, Some(endowed_accounts), false)
|
||||
}
|
||||
|
||||
/// Staging testnet config.
|
||||
@@ -214,6 +209,7 @@ pub fn testnet_genesis(
|
||||
ImOnlineId,
|
||||
AuthorityDiscoveryId,
|
||||
)>,
|
||||
initial_nominators: Vec<AccountId>,
|
||||
root_key: AccountId,
|
||||
endowed_accounts: Option<Vec<AccountId>>,
|
||||
enable_println: bool,
|
||||
@@ -234,11 +230,31 @@ pub fn testnet_genesis(
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
]
|
||||
});
|
||||
initial_authorities.iter().for_each(|x|
|
||||
if !endowed_accounts.contains(&x.0) {
|
||||
endowed_accounts.push(x.0.clone())
|
||||
// endow all authorities and nominators.
|
||||
initial_authorities.iter().map(|x| &x.0).chain(initial_nominators.iter()).for_each(|x| {
|
||||
if !endowed_accounts.contains(&x) {
|
||||
endowed_accounts.push(x.clone())
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// stakers: all validators and nominators.
|
||||
let mut rng = rand::thread_rng();
|
||||
let stakers = initial_authorities
|
||||
.iter()
|
||||
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
|
||||
.chain(initial_nominators.iter().map(|x| {
|
||||
use rand::{seq::SliceRandom, Rng};
|
||||
let limit = (MAX_NOMINATIONS as usize).min(initial_authorities.len());
|
||||
let count = rng.gen::<usize>() % limit;
|
||||
let nominations = initial_authorities
|
||||
.as_slice()
|
||||
.choose_multiple(&mut rng, count)
|
||||
.into_iter()
|
||||
.map(|choice| choice.0.clone())
|
||||
.collect::<Vec<_>>();
|
||||
(x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations))
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let num_endowed_accounts = endowed_accounts.len();
|
||||
|
||||
@@ -271,11 +287,9 @@ pub fn testnet_genesis(
|
||||
pallet_staking: StakingConfig {
|
||||
validator_count: initial_authorities.len() as u32 * 2,
|
||||
minimum_validator_count: initial_authorities.len() as u32,
|
||||
stakers: initial_authorities.iter().map(|x| {
|
||||
(x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)
|
||||
}).collect(),
|
||||
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
|
||||
slash_reward_fraction: Perbill::from_percent(10),
|
||||
stakers,
|
||||
.. Default::default()
|
||||
},
|
||||
pallet_democracy: DemocracyConfig::default(),
|
||||
@@ -335,6 +349,7 @@ fn development_config_genesis() -> GenesisConfig {
|
||||
vec![
|
||||
authority_keys_from_seed("Alice"),
|
||||
],
|
||||
vec![],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
None,
|
||||
true,
|
||||
@@ -362,6 +377,7 @@ fn local_testnet_genesis() -> GenesisConfig {
|
||||
authority_keys_from_seed("Alice"),
|
||||
authority_keys_from_seed("Bob"),
|
||||
],
|
||||
vec![],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
None,
|
||||
false,
|
||||
@@ -395,6 +411,7 @@ pub(crate) mod tests {
|
||||
vec![
|
||||
authority_keys_from_seed("Alice"),
|
||||
],
|
||||
vec![],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
None,
|
||||
false,
|
||||
|
||||
Reference in New Issue
Block a user