pallet_staking_async_rc_runtime/
genesis_config_presets.rs1use crate::{
20 BabeConfig, BalancesConfig, ConfigurationConfig, RegistrarConfig, RuntimeGenesisConfig,
21 SessionConfig, SessionKeys, StakingAhClientConfig, SudoConfig, BABE_GENESIS_EPOCH_CONFIG,
22};
23#[cfg(not(feature = "std"))]
24use alloc::format;
25use alloc::{string::ToString, vec, vec::Vec};
26use core::panic;
27use frame_support::build_struct_json_patch;
28use pallet_staking_async_rc_runtime_constants::currency::UNITS as WND;
29use polkadot_primitives::{AccountId, AssignmentId, SchedulerParams, ValidatorId};
30use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
31use sp_consensus_babe::AuthorityId as BabeId;
32use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId;
33use sp_consensus_grandpa::AuthorityId as GrandpaId;
34use sp_core::{crypto::get_public_from_string_or_panic, sr25519};
35use sp_genesis_builder::PresetId;
36use sp_keyring::Sr25519Keyring;
37
38fn get_authority_keys_from_seed(
40 seed: &str,
41) -> (
42 AccountId,
43 AccountId,
44 BabeId,
45 GrandpaId,
46 ValidatorId,
47 AssignmentId,
48 AuthorityDiscoveryId,
49 BeefyId,
50) {
51 let keys = get_authority_keys_from_seed_no_beefy(seed);
52 (
53 keys.0,
54 keys.1,
55 keys.2,
56 keys.3,
57 keys.4,
58 keys.5,
59 keys.6,
60 get_public_from_string_or_panic::<BeefyId>(seed),
61 )
62}
63
64fn get_authority_keys_from_seed_no_beefy(
66 seed: &str,
67) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) {
68 (
69 get_public_from_string_or_panic::<sr25519::Public>(&format!("{}//stash", seed)).into(),
70 get_public_from_string_or_panic::<sr25519::Public>(seed).into(),
71 get_public_from_string_or_panic::<BabeId>(seed),
72 get_public_from_string_or_panic::<GrandpaId>(seed),
73 get_public_from_string_or_panic::<ValidatorId>(seed),
74 get_public_from_string_or_panic::<AssignmentId>(seed),
75 get_public_from_string_or_panic::<AuthorityDiscoveryId>(seed),
76 )
77}
78
79fn westend_session_keys(
80 babe: BabeId,
81 grandpa: GrandpaId,
82 para_validator: ValidatorId,
83 para_assignment: AssignmentId,
84 authority_discovery: AuthorityDiscoveryId,
85 beefy: BeefyId,
86) -> SessionKeys {
87 SessionKeys { babe, grandpa, para_validator, para_assignment, authority_discovery, beefy }
88}
89
90fn default_parachains_host_configuration(
91) -> polkadot_runtime_parachains::configuration::HostConfiguration<polkadot_primitives::BlockNumber>
92{
93 use polkadot_primitives::{
94 node_features::FeatureIndex, ApprovalVotingParams, AsyncBackingParams, MAX_CODE_SIZE,
95 MAX_POV_SIZE,
96 };
97
98 polkadot_runtime_parachains::configuration::HostConfiguration {
99 max_downward_message_size: 51200,
102 max_upward_message_size: 65531,
103 max_upward_message_num_per_candidate: 16,
104 max_upward_queue_count: 174762,
105 max_upward_queue_size: 1048576,
106
107 validation_upgrade_cooldown: 2u32,
108 validation_upgrade_delay: 2,
109 code_retention_period: 1200,
110 max_code_size: MAX_CODE_SIZE,
111 max_pov_size: MAX_POV_SIZE,
112 max_head_data_size: 32 * 1024,
113 hrmp_sender_deposit: 0,
114 hrmp_recipient_deposit: 0,
115 hrmp_channel_max_capacity: 8,
116 hrmp_channel_max_total_size: 8 * 1024,
117 hrmp_max_parachain_inbound_channels: 4,
118 hrmp_channel_max_message_size: 1024 * 1024,
119 hrmp_max_parachain_outbound_channels: 4,
120 hrmp_max_message_num_per_candidate: 5,
121 dispute_period: 6,
122 no_show_slots: 2,
123 n_delay_tranches: 25,
124 needed_approvals: 2,
125 relay_vrf_modulo_samples: 2,
126 zeroth_delay_tranche_width: 0,
127 minimum_validation_upgrade_delay: 5,
128 async_backing_params: AsyncBackingParams {
129 max_candidate_depth: 0,
130 allowed_ancestry_len: 0,
131 },
132 node_features: bitvec::vec::BitVec::from_element(
133 (1u8 << (FeatureIndex::ElasticScalingMVP as usize)) |
134 (1u8 << (FeatureIndex::EnableAssignmentsV2 as usize)) |
135 (1u8 << (FeatureIndex::CandidateReceiptV2 as usize)),
136 ),
137 scheduler_params: SchedulerParams {
138 lookahead: 3,
139 group_rotation_frequency: 20,
140 paras_availability_period: 4,
141 ..Default::default()
142 },
143 approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 5 },
144 ..Default::default()
145 }
146}
147
148#[test]
149fn default_parachains_host_configuration_is_consistent() {
150 default_parachains_host_configuration().panic_if_not_consistent();
151}
152
153fn westend_testnet_genesis(
155 initial_authorities: Vec<(
156 AccountId,
157 AccountId,
158 BabeId,
159 GrandpaId,
160 ValidatorId,
161 AssignmentId,
162 AuthorityDiscoveryId,
163 BeefyId,
164 )>,
165 root_key: AccountId,
166 preset: alloc::string::String,
167) -> serde_json::Value {
168 let endowed_accounts =
169 Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect::<Vec<_>>();
170
171 const ENDOWMENT: u128 = 1_000_000 * WND;
172
173 build_struct_json_patch!(RuntimeGenesisConfig {
174 balances: BalancesConfig {
175 balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
176 },
177 session: SessionConfig {
178 keys: initial_authorities
179 .iter()
180 .map(|x| {
181 (
182 x.0.clone(),
183 x.0.clone(),
184 westend_session_keys(
185 x.2.clone(),
186 x.3.clone(),
187 x.4.clone(),
188 x.5.clone(),
189 x.6.clone(),
190 x.7.clone(),
191 ),
192 )
193 })
194 .collect::<Vec<_>>(),
195 },
196 babe: BabeConfig { epoch_config: BABE_GENESIS_EPOCH_CONFIG },
197 sudo: SudoConfig { key: Some(root_key) },
198 configuration: ConfigurationConfig { config: default_parachains_host_configuration() },
199 registrar: RegistrarConfig { next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID },
200 preset_store: crate::PresetStoreConfig { preset, ..Default::default() },
201 staking_ah_client: StakingAhClientConfig {
202 operating_mode: pallet_staking_async_ah_client::OperatingMode::Active,
203 ..Default::default()
204 }
205 })
206}
207
208pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
210 let patch = match id.as_ref() {
211 "real-m" => westend_testnet_genesis(
212 vec![
213 get_authority_keys_from_seed("Alice"),
214 get_authority_keys_from_seed("Bob"),
215 get_authority_keys_from_seed("Eve"),
216 get_authority_keys_from_seed("Dave"),
217 ],
218 Sr25519Keyring::Alice.to_account_id(),
219 id.to_string(),
220 ),
221 "real-s" => westend_testnet_genesis(
222 vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")],
223 Sr25519Keyring::Alice.to_account_id(),
224 id.to_string(),
225 ),
226 "fake-s" => westend_testnet_genesis(
227 vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")],
228 Sr25519Keyring::Alice.to_account_id(),
229 id.to_string(),
230 ),
231 _ => panic!("Unknown preset ID: {}", id),
232 };
233 Some(
234 serde_json::to_string(&patch)
235 .expect("serialization to json is expected to work. qed.")
236 .into_bytes(),
237 )
238}
239
240pub fn preset_names() -> Vec<PresetId> {
242 vec![PresetId::from("real-m"), PresetId::from("real-s"), PresetId::from("fake-s")]
243}