chain_spec.rs 22 KB
Newer Older
Shawn Tabrizi's avatar
Shawn Tabrizi committed
1
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
Gav Wood's avatar
Gav Wood committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.

//! Polkadot chain configurations.

19
use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519};
20
use polkadot_primitives::{AccountId, AccountPublic, parachain::ValidatorId};
21
use polkadot_runtime as polkadot;
Gavin Wood's avatar
Gavin Wood committed
22
23
24
use kusama_runtime as kusama;
use polkadot::constants::currency::DOTS;
use kusama::constants::currency::DOTS as KSM;
25
use sc_chain_spec::ChainSpecExtension;
26
use sp_runtime::{traits::IdentifyAccount, Perbill};
27
use serde::{Serialize, Deserialize};
28
use telemetry::TelemetryEndpoints;
29
use hex_literal::hex;
30
31
use babe_primitives::AuthorityId as BabeId;
use grandpa::AuthorityId as GrandpaId;
thiolliere's avatar
thiolliere committed
32
use im_online::sr25519::{AuthorityId as ImOnlineId};
Gavin Wood's avatar
Gavin Wood committed
33
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
34
use pallet_staking::Forcing;
Gav Wood's avatar
Gav Wood committed
35

Gavin Wood's avatar
Gavin Wood committed
36
37
const POLKADOT_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
const KUSAMA_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
38
const DEFAULT_PROTOCOL_ID: &str = "dot";
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
39

40
41
42
43
44
45
46
47
/// Node `ChainSpec` extensions.
///
/// Additional parameters for some Substrate core modules,
/// customizable from the chain spec.
#[derive(Default, Clone, Serialize, Deserialize, ChainSpecExtension)]
#[serde(rename_all = "camelCase")]
pub struct Extensions {
	/// Block numbers with known hashes.
48
	pub fork_blocks: sc_client::ForkBlocks<polkadot_primitives::Block>,
Gavin Wood's avatar
Gavin Wood committed
49
	/// Known bad block hashes.
50
	pub bad_blocks: sc_client::BadBlocks<polkadot_primitives::Block>,
51
52
}

Gavin Wood's avatar
Gavin Wood committed
53
54
/// The `ChainSpec parametrised for polkadot runtime`.
pub type PolkadotChainSpec = service::GenericChainSpec<
55
56
57
	polkadot::GenesisConfig,
	Extensions,
>;
58

Gavin Wood's avatar
Gavin Wood committed
59
60
61
62
63
64
65
66
/// The `ChainSpec parametrised for kusama runtime`.
pub type KusamaChainSpec = service::GenericChainSpec<
	kusama::GenesisConfig,
	Extensions,
>;

pub fn kusama_config() -> Result<KusamaChainSpec, String> {
	KusamaChainSpec::from_json_bytes(&include_bytes!("../res/kusama.json")[..])
67
68
}

Gavin Wood's avatar
Gavin Wood committed
69
70
pub fn westend_config() -> Result<PolkadotChainSpec, String> {
	PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/westend.json")[..])
ddorgan's avatar
ddorgan committed
71
72
}

Gavin Wood's avatar
Gavin Wood committed
73
fn polkadot_session_keys(
74
75
76
	babe: BabeId,
	grandpa: GrandpaId,
	im_online: ImOnlineId,
Gavin Wood's avatar
Gavin Wood committed
77
78
	parachain_validator: ValidatorId,
	authority_discovery: AuthorityDiscoveryId
79
80
) -> polkadot::SessionKeys {
	polkadot::SessionKeys { babe, grandpa, im_online, parachain_validator, authority_discovery }
Gav Wood's avatar
Gav Wood committed
81
82
}

Gavin Wood's avatar
Gavin Wood committed
83
84
85
86
87
88
89
90
91
92
93
fn kusama_session_keys(
	babe: BabeId,
	grandpa: GrandpaId,
	im_online: ImOnlineId,
	parachain_validator: ValidatorId,
	authority_discovery: AuthorityDiscoveryId
) -> kusama::SessionKeys {
	kusama::SessionKeys { babe, grandpa, im_online, parachain_validator, authority_discovery }
}

fn polkadot_staging_testnet_config_genesis() -> polkadot::GenesisConfig {
Gav Wood's avatar
Gav Wood committed
94
	// subkey inspect "$SECRET"
Gavin Wood's avatar
Gavin Wood committed
95
	let endowed_accounts = vec![];
Gav Wood's avatar
Gav Wood committed
96

Gavin Wood's avatar
Gavin Wood committed
97
98
99
100
101
102
103
104
	let initial_authorities: Vec<(
		AccountId,
		AccountId,
		BabeId,
		GrandpaId,
		ImOnlineId,
		ValidatorId,
		AuthorityDiscoveryId
Gavin Wood's avatar
Gavin Wood committed
105
	)> = vec![];
Gav Wood's avatar
Gav Wood committed
106

107
108
	const ENDOWMENT: u128 = 1_000_000 * DOTS;
	const STASH: u128 = 100 * DOTS;
109

110
111
112
	polkadot::GenesisConfig {
		system: Some(polkadot::SystemConfig {
			code: polkadot::WASM_BINARY.to_vec(),
113
			changes_trie_config: Default::default(),
114
		}),
115
		balances: Some(polkadot::BalancesConfig {
116
			balances: endowed_accounts.iter()
Gav Wood's avatar
Gav Wood committed
117
				.map(|k: &AccountId| (k.clone(), ENDOWMENT))
118
119
				.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
				.collect(),
Gav's avatar
Gav committed
120
		}),
121
		indices: Some(polkadot::IndicesConfig {
122
			indices: vec![],
123
		}),
124
		session: Some(polkadot::SessionConfig {
125
			keys: initial_authorities.iter().map(|x| (
126
				x.0.clone(),
127
				x.0.clone(),
Gavin Wood's avatar
Gavin Wood committed
128
				polkadot_session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()),
129
			)).collect::<Vec<_>>(),
130
		}),
131
		staking: Some(polkadot::StakingConfig {
132
			validator_count: 50,
Gav's avatar
Gav committed
133
			minimum_validator_count: 4,
134
135
136
137
			stakers: initial_authorities
				.iter()
				.map(|x| (x.0.clone(), x.1.clone(), STASH, polkadot::StakerStatus::Validator))
				.collect(),
138
			invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
139
			force_era: Forcing::ForceNone,
140
141
			slash_reward_fraction: Perbill::from_percent(10),
			.. Default::default()
142
		}),
143
		democracy: Some(Default::default()),
144
		collective_Instance1: Some(polkadot::CouncilConfig {
145
146
147
			members: vec![],
			phantom: Default::default(),
		}),
148
		collective_Instance2: Some(polkadot::TechnicalCommitteeConfig {
149
150
151
			members: vec![],
			phantom: Default::default(),
		}),
152
		membership_Instance1: Some(Default::default()),
Gavin Wood's avatar
Gavin Wood committed
153
154
155
		babe: Some(Default::default()),
		grandpa: Some(Default::default()),
		im_online: Some(Default::default()),
156
		authority_discovery: Some(polkadot::AuthorityDiscoveryConfig {
Gavin Wood's avatar
Gavin Wood committed
157
158
			keys: vec![],
		}),
159
		parachains: Some(polkadot::ParachainsConfig {
Gavin Wood's avatar
Gavin Wood committed
160
			authorities: vec![],
161
		}),
162
		registrar: Some(polkadot::RegistrarConfig {
163
164
165
			parachains: vec![],
			_phdata: Default::default(),
		}),
166
		claims: Some(polkadot::ClaimsConfig {
167
			claims: vec![],
168
			vesting: vec![],
169
		}),
Gavin Wood's avatar
Gavin Wood committed
170
171
172
		vesting: Some(polkadot::VestingConfig {
			vesting: vec![],
		}),
173
174
		sudo: Some(polkadot::SudoConfig {
			key: endowed_accounts[0].clone(),
Gavin Wood's avatar
Gavin Wood committed
175
		}),
176
	}
Gav Wood's avatar
Gav Wood committed
177
178
}

Gavin Wood's avatar
Gavin Wood committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
fn kusama_staging_testnet_config_genesis() -> kusama::GenesisConfig {
	// subkey inspect "$SECRET"
	let endowed_accounts = vec![
		// 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz
		hex!["12b782529c22032ed4694e0f6e7d486be7daa6d12088f6bc74d593b3900b8438"].into(),
	];

	// for i in 1 2 3 4; do for j in stash controller; do subkey inspect "$SECRET//$i//$j"; done; done
	// for i in 1 2 3 4; do for j in babe; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done
	// for i in 1 2 3 4; do for j in grandpa; do subkey --ed25519 inspect "$SECRET//$i//$j"; done; done
	// for i in 1 2 3 4; do for j in im_online; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done
	// for i in 1 2 3 4; do for j in parachains; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done
	let initial_authorities: Vec<(
		AccountId,
		AccountId,
		BabeId,
		GrandpaId,
		ImOnlineId,
		ValidatorId,
		AuthorityDiscoveryId
	)> = vec![(
	// 5DD7Q4VEfPTLEdn11CnThoHT5f9xKCrnofWJL5SsvpTghaAT
	hex!["32a5718e87d16071756d4b1370c411bbbb947eb62f0e6e0b937d5cbfc0ea633b"].into(),
	// 5GNzaEqhrZAtUQhbMe2gn9jBuNWfamWFZHULryFwBUXyd1cG
	hex!["bee39fe862c85c91aaf343e130d30b643c6ea0b4406a980206f1df8331f7093b"].into(),
	// 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
	hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(),
	// 5EjvdwATjyFFikdZibVvx1q5uBHhphS2Mnsq5c7yfaYK25vm
	hex!["76620f7c98bce8619979c2b58cf2b0aff71824126d2b039358729dad993223db"].unchecked_into(),
	// 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
	hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(),
	// 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
	hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(),
	// 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
	hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(),
	),(
	// 5G9VGb8ESBeS8Ca4or43RfhShzk9y7T5iTmxHk5RJsjZwsRx
	hex!["b496c98a405ceab59b9e970e59ef61acd7765a19b704e02ab06c1cdfe171e40f"].into(),
	// 5F7V9Y5FcxKXe1aroqvPeRiUmmeQwTFcL3u9rrPXcMuMiCNx
	hex!["86d3a7571dd60139d297e55d8238d0c977b2e208c5af088f7f0136b565b0c103"].into(),
	// 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
	hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(),
	// 5HBDAaybNqjmY7ww8ZcZZY1L5LHxvpnyfqJwoB7HhR6raTmG
	hex!["e2234d661bee4a04c38392c75d1566200aa9e6ae44dd98ee8765e4cc9af63cb7"].unchecked_into(),
	// 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
	hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(),
	// 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
	hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(),
	// 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
	hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(),
	),(
	// 5FzwpgGvk2kk9agow6KsywLYcPzjYc8suKej2bne5G5b9YU3
	hex!["ae12f70078a22882bf5135d134468f77301927aa67c376e8c55b7ff127ace115"].into(),
	// 5EqoZhVC2BcsM4WjvZNidu2muKAbu5THQTBKe3EjvxXkdP7A
	hex!["7addb914ec8486bbc60643d2647685dcc06373401fa80e09813b630c5831d54b"].into(),
	// 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
	hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(),
	// 5E8ULLQrDAtWhfnVfZmX41Yux86zNAwVJYguWJZVWrJvdhBe
	hex!["5b57ed1443c8967f461db1f6eb2ada24794d163a668f1cf9d9ce3235dfad8799"].unchecked_into(),
	// 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
	hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(),
	// 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
	hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(),
	// 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
	hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(),
	),(
	// 5CFj6Kg9rmVn1vrqpyjau2ztyBzKeVdRKwNPiA3tqhB5HPqq
	hex!["0867dbb49721126df589db100dda728dc3b475cbf414dad8f72a1d5e84897252"].into(),
	// 5CwQXP6nvWzigFqNhh2jvCaW9zWVzkdveCJY3tz2MhXMjTon
	hex!["26ab2b4b2eba2263b1e55ceb48f687bb0018130a88df0712fbdaf6a347d50e2a"].into(),
	// 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
	hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(),
	// 5HGLmrZsiTFTPp3QoS1W8w9NxByt8PVq79reqvdxNcQkByqK
	hex!["e60d23f49e93c1c1f2d7c115957df5bbd7faf5ebf138d1e9d02e8b39a1f63df0"].unchecked_into(),
	// 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
	hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(),
	// 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
	hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(),
	// 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
	hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(),
	)];

	const ENDOWMENT: u128 = 1_000_000 * KSM;
	const STASH: u128 = 100 * KSM;

	kusama::GenesisConfig {
		system: Some(kusama::SystemConfig {
			code: kusama::WASM_BINARY.to_vec(),
			changes_trie_config: Default::default(),
		}),
		balances: Some(kusama::BalancesConfig {
			balances: endowed_accounts.iter()
				.map(|k: &AccountId| (k.clone(), ENDOWMENT))
				.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
				.collect(),
		}),
		indices: Some(kusama::IndicesConfig {
			indices: vec![],
		}),
		session: Some(kusama::SessionConfig {
			keys: initial_authorities.iter().map(|x| (
						  x.0.clone(),
						  x.0.clone(),
						  kusama_session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()),
				  )).collect::<Vec<_>>(),
		}),
		staking: Some(kusama::StakingConfig {
			validator_count: 50,
			minimum_validator_count: 4,
			stakers: initial_authorities
				.iter()
				.map(|x| (x.0.clone(), x.1.clone(), STASH, kusama::StakerStatus::Validator))
				.collect(),
				invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
				force_era: Forcing::ForceNone,
				slash_reward_fraction: Perbill::from_percent(10),
				.. Default::default()
		}),
		democracy: Some(Default::default()),
		collective_Instance1: Some(kusama::CouncilConfig {
			members: vec![],
			phantom: Default::default(),
		}),
		collective_Instance2: Some(kusama::TechnicalCommitteeConfig {
			members: vec![],
			phantom: Default::default(),
		}),
		membership_Instance1: Some(Default::default()),
		babe: Some(Default::default()),
		grandpa: Some(Default::default()),
		im_online: Some(Default::default()),
		authority_discovery: Some(kusama::AuthorityDiscoveryConfig {
			keys: vec![],
		}),
		parachains: Some(kusama::ParachainsConfig {
			authorities: vec![],
		}),
		registrar: Some(kusama::RegistrarConfig {
			parachains: vec![],
			_phdata: Default::default(),
		}),
		claims: Some(kusama::ClaimsConfig {
			claims: vec![],
			vesting: vec![],
		}),
		vesting: Some(kusama::VestingConfig {
			vesting: vec![],
		}),
	}
}

/// Polkadot staging testnet config.
pub fn polkadot_staging_testnet_config() -> PolkadotChainSpec {
	let boot_nodes = vec![];
	PolkadotChainSpec::from_genesis(
		"Polkadot Staging Testnet",
		"polkadot_staging_testnet",
		polkadot_staging_testnet_config_genesis,
		boot_nodes,
338
339
		Some(TelemetryEndpoints::new(vec![(POLKADOT_STAGING_TELEMETRY_URL.to_string(), 0)])
			.expect("Polkadot Staging telemetry url is valid; qed")),
Gavin Wood's avatar
Gavin Wood committed
340
341
342
343
344
345
		Some(DEFAULT_PROTOCOL_ID),
		None,
		Default::default(),
	)
}

346
/// Staging testnet config.
Gavin Wood's avatar
Gavin Wood committed
347
pub fn kusama_staging_testnet_config() -> KusamaChainSpec {
348
	let boot_nodes = vec![];
Gavin Wood's avatar
Gavin Wood committed
349
350
351
352
	KusamaChainSpec::from_genesis(
		"Kusama Staging Testnet",
		"kusama_staging_testnet",
		kusama_staging_testnet_config_genesis,
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
353
		boot_nodes,
354
355
		Some(TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)])
			.expect("Kusama Staging telemetry url is valid; qed")),
356
357
		Some(DEFAULT_PROTOCOL_ID),
		None,
358
		Default::default(),
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
359
	)
Gav Wood's avatar
Gav Wood committed
360
361
}

362
363
364
/// 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)
Gav Wood's avatar
Gav Wood committed
365
366
367
368
		.expect("static values are valid; qed")
		.public()
}

369

370
371
372
373
374
375
376
/// 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()
}

377
/// Helper function to generate stash, controller and session key from seed
378
379
380
381
382
383
pub fn get_authority_keys_from_seed(seed: &str) -> (
	AccountId,
	AccountId,
	BabeId,
	GrandpaId,
	ImOnlineId,
Gavin Wood's avatar
Gavin Wood committed
384
385
	ValidatorId,
	AuthorityDiscoveryId
386
) {
387
	(
388
389
		get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
		get_account_id_from_seed::<sr25519::Public>(seed),
390
391
392
393
		get_from_seed::<BabeId>(seed),
		get_from_seed::<GrandpaId>(seed),
		get_from_seed::<ImOnlineId>(seed),
		get_from_seed::<ValidatorId>(seed),
Gavin Wood's avatar
Gavin Wood committed
394
		get_from_seed::<AuthorityDiscoveryId>(seed),
395
396
397
	)
}

Gavin Wood's avatar
Gavin Wood committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
fn testnet_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"),
	]
}

/// Helper function to create polkadot GenesisConfig for testing
pub fn polkadot_testnet_genesis(
Gavin Wood's avatar
Gavin Wood committed
417
	initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId, AuthorityDiscoveryId)>,
418
	root_key: AccountId,
419
	endowed_accounts: Option<Vec<AccountId>>,
420
) -> polkadot::GenesisConfig {
Gavin Wood's avatar
Gavin Wood committed
421
	let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);
422

423
424
	const ENDOWMENT: u128 = 1_000_000 * DOTS;
	const STASH: u128 = 100 * DOTS;
425

426
427
428
	polkadot::GenesisConfig {
		system: Some(polkadot::SystemConfig {
			code: polkadot::WASM_BINARY.to_vec(),
429
			changes_trie_config: Default::default(),
430
		}),
431
		indices: Some(polkadot::IndicesConfig {
432
			indices: vec![],
Gav Wood's avatar
Gav Wood committed
433
		}),
434
		balances: Some(polkadot::BalancesConfig {
Gav Wood's avatar
Gav Wood committed
435
			balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(),
Gav's avatar
Gav committed
436
		}),
437
		session: Some(polkadot::SessionConfig {
438
			keys: initial_authorities.iter().map(|x| (
Gavin Wood's avatar
Gavin Wood committed
439
440
441
442
						  x.0.clone(),
						  x.0.clone(),
						  polkadot_session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()),
				  )).collect::<Vec<_>>(),
Gav's avatar
Gav committed
443
		}),
444
		staking: Some(polkadot::StakingConfig {
Gav's avatar
Gav committed
445
			minimum_validator_count: 1,
446
			validator_count: 2,
Gavin Wood's avatar
Gavin Wood committed
447
			stakers: initial_authorities.iter()
448
				.map(|x| (x.0.clone(), x.1.clone(), STASH, polkadot::StakerStatus::Validator))
Gavin Wood's avatar
Gavin Wood committed
449
				.collect(),
Gavin Wood's avatar
Gavin Wood committed
450
451
452
453
				invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
				force_era: Forcing::NotForcing,
				slash_reward_fraction: Perbill::from_percent(10),
				.. Default::default()
454
		}),
455
456
		democracy: Some(polkadot::DemocracyConfig::default()),
		collective_Instance1: Some(polkadot::CouncilConfig {
457
458
459
			members: vec![],
			phantom: Default::default(),
		}),
460
		collective_Instance2: Some(polkadot::TechnicalCommitteeConfig {
461
462
463
			members: vec![],
			phantom: Default::default(),
		}),
464
		membership_Instance1: Some(Default::default()),
Gavin Wood's avatar
Gavin Wood committed
465
466
467
		babe: Some(Default::default()),
		grandpa: Some(Default::default()),
		im_online: Some(Default::default()),
468
		authority_discovery: Some(polkadot::AuthorityDiscoveryConfig {
Gavin Wood's avatar
Gavin Wood committed
469
470
			keys: vec![],
		}),
471
		parachains: Some(polkadot::ParachainsConfig {
Gavin Wood's avatar
Gavin Wood committed
472
			authorities: vec![],
473
		}),
474
		registrar: Some(polkadot::RegistrarConfig{
475
476
			parachains: vec![],
			_phdata: Default::default(),
477
		}),
478
		claims: Some(polkadot::ClaimsConfig {
479
			claims: vec![],
480
			vesting: vec![],
481
		}),
Gavin Wood's avatar
Gavin Wood committed
482
483
484
		vesting: Some(polkadot::VestingConfig {
			vesting: vec![],
		}),
485
486
487
		sudo: Some(polkadot::SudoConfig {
			key: root_key,
		}),
488
	}
489
490
}

Gavin Wood's avatar
Gavin Wood committed
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/// Helper function to create kusama GenesisConfig for testing
pub fn kusama_testnet_genesis(
	initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId, AuthorityDiscoveryId)>,
	_root_key: AccountId,
	endowed_accounts: Option<Vec<AccountId>>,
) -> kusama::GenesisConfig {
	let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);

	const ENDOWMENT: u128 = 1_000_000 * KSM;
	const STASH: u128 = 100 * KSM;

	kusama::GenesisConfig {
		system: Some(kusama::SystemConfig {
			code: kusama::WASM_BINARY.to_vec(),
			changes_trie_config: Default::default(),
		}),
		indices: Some(kusama::IndicesConfig {
			indices: vec![],
		}),
		balances: Some(kusama::BalancesConfig {
			balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(),
		}),
		session: Some(kusama::SessionConfig {
			keys: initial_authorities.iter().map(|x| (
				x.0.clone(),
				x.0.clone(),
				kusama_session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()),
			)).collect::<Vec<_>>(),
		}),
		staking: Some(kusama::StakingConfig {
			minimum_validator_count: 1,
			validator_count: 2,
			stakers: initial_authorities.iter()
				.map(|x| (x.0.clone(), x.1.clone(), STASH, kusama::StakerStatus::Validator))
				.collect(),
			invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
			force_era: Forcing::NotForcing,
			slash_reward_fraction: Perbill::from_percent(10),
			.. Default::default()
		}),
		democracy: Some(kusama::DemocracyConfig::default()),
		collective_Instance1: Some(kusama::CouncilConfig {
			members: vec![],
			phantom: Default::default(),
		}),
		collective_Instance2: Some(kusama::TechnicalCommitteeConfig {
			members: vec![],
			phantom: Default::default(),
		}),
		membership_Instance1: Some(Default::default()),
		babe: Some(Default::default()),
		grandpa: Some(Default::default()),
		im_online: Some(Default::default()),
		authority_discovery: Some(kusama::AuthorityDiscoveryConfig {
			keys: vec![],
		}),
		parachains: Some(kusama::ParachainsConfig {
			authorities: vec![],
		}),
		registrar: Some(kusama::RegistrarConfig{
			parachains: vec![],
			_phdata: Default::default(),
		}),
		claims: Some(kusama::ClaimsConfig {
			claims: vec![],
			vesting: vec![],
		}),
		vesting: Some(kusama::VestingConfig {
			vesting: vec![],
		}),
	}
}

fn polkadot_development_config_genesis() -> polkadot::GenesisConfig {
	polkadot_testnet_genesis(
Gav Wood's avatar
Gav Wood committed
566
		vec![
567
			get_authority_keys_from_seed("Alice"),
Gav Wood's avatar
Gav Wood committed
568
		],
569
		get_account_id_from_seed::<sr25519::Public>("Alice"),
570
		None,
Gav Wood's avatar
Gav Wood committed
571
	)
572
573
}

Gavin Wood's avatar
Gavin Wood committed
574
575
576
577
578
579
580
581
582
583
584
585
586
fn kusama_development_config_genesis() -> kusama::GenesisConfig {
	kusama_testnet_genesis(
		vec![
		get_authority_keys_from_seed("Alice"),
		],
		get_account_id_from_seed::<sr25519::Public>("Alice"),
		None,
	)
}

/// Polkadot development config (single validator Alice)
pub fn polkadot_development_config() -> PolkadotChainSpec {
	PolkadotChainSpec::from_genesis(
587
588
		"Development",
		"dev",
Gavin Wood's avatar
Gavin Wood committed
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
		polkadot_development_config_genesis,
		vec![],
		None,
		Some(DEFAULT_PROTOCOL_ID),
		None,
		Default::default(),
	)
}

/// Kusama development config (single validator Alice)
pub fn kusama_development_config() -> KusamaChainSpec {
	KusamaChainSpec::from_genesis(
		"Development",
		"kusama_dev",
		kusama_development_config_genesis,
604
605
606
607
		vec![],
		None,
		Some(DEFAULT_PROTOCOL_ID),
		None,
608
		Default::default(),
609
	)
610
611
}

Gavin Wood's avatar
Gavin Wood committed
612
613
fn polkadot_local_testnet_genesis() -> polkadot::GenesisConfig {
	polkadot_testnet_genesis(
Gav Wood's avatar
Gav Wood committed
614
		vec![
615
616
			get_authority_keys_from_seed("Alice"),
			get_authority_keys_from_seed("Bob"),
Gav Wood's avatar
Gav Wood committed
617
		],
618
		get_account_id_from_seed::<sr25519::Public>("Alice"),
619
		None,
Gav Wood's avatar
Gav Wood committed
620
	)
621
}
622

Gavin Wood's avatar
Gavin Wood committed
623
624
625
/// Polkadot local testnet config (multivalidator Alice + Bob)
pub fn polkadot_local_testnet_config() -> PolkadotChainSpec {
	PolkadotChainSpec::from_genesis(
626
627
		"Local Testnet",
		"local_testnet",
Gavin Wood's avatar
Gavin Wood committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
		polkadot_local_testnet_genesis,
		vec![],
		None,
		Some(DEFAULT_PROTOCOL_ID),
		None,
		Default::default(),
	)
}

fn kusama_local_testnet_genesis() -> kusama::GenesisConfig {
	kusama_testnet_genesis(
		vec![
			get_authority_keys_from_seed("Alice"),
			get_authority_keys_from_seed("Bob"),
		],
		get_account_id_from_seed::<sr25519::Public>("Alice"),
		None,
	)
}

/// Kusama local testnet config (multivalidator Alice + Bob)
pub fn kusama_local_testnet_config() -> KusamaChainSpec {
	KusamaChainSpec::from_genesis(
		"Kusama Local Testnet",
		"kusama_local_testnet",
		kusama_local_testnet_genesis,
654
655
656
657
		vec![],
		None,
		Some(DEFAULT_PROTOCOL_ID),
		None,
658
		Default::default(),
659
	)
Gav Wood's avatar
Gav Wood committed
660
}