referrerpolicy=no-referrer-when-downgrade

polkadot_parachain/chain_spec/
yet_another_parachain.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! ChainSpecs dedicated to parachain setups for testing and example purposes
17use parachains_common::AccountId;
18use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
19use sc_chain_spec::ChainType;
20use sp_core::{hex2array, sr25519::Pair as SrPair, Pair};
21use sp_keyring::Sr25519Keyring as Keyring;
22
23const NUM_ACCOUNT_PAIRS: usize = 16000;
24
25fn derive_accounts(n: usize, seed: String) -> Vec<SrPair> {
26	let t = std::cmp::min(
27		n,
28		std::thread::available_parallelism().unwrap_or(1usize.try_into().unwrap()).get(),
29	);
30
31	let mut tn = (0..t).cycle();
32	let mut tranges: Vec<_> = (0..t).map(|_| Vec::new()).collect();
33	(0..n).for_each(|i| tranges[tn.next().unwrap()].push(i));
34	let mut threads = Vec::new();
35
36	tranges.into_iter().for_each(|chunk| {
37		let seed = seed.clone();
38		threads.push(std::thread::spawn(move || {
39			chunk
40				.into_iter()
41				.map(move |i| {
42					let derivation = format!("{seed}/{i}");
43					<SrPair as Pair>::from_string(&derivation, None).unwrap()
44				})
45				.collect::<Vec<_>>()
46		}));
47	});
48
49	threads.into_iter().flat_map(|h| h.join().unwrap()).collect()
50}
51
52pub fn yet_another_parachain_config(
53	relay: impl Into<String>,
54	chain_type: ChainType,
55	para_id: u32,
56) -> GenericChainSpec {
57	// 	> subkey inspect --network kusama --public \
58	// 6205a2a2aecb71c13d8ad3197e12c10bcdcaa0c9f176997bc236c6b39143aa15
59	//
60	// Network ID/Version: kusama
61	//   Public key (hex):   0x6205a2a2aecb71c13d8ad3197e12c10bcdcaa0c9f176997bc236c6b39143aa15
62	//   Account ID:         0x6205a2a2aecb71c13d8ad3197e12c10bcdcaa0c9f176997bc236c6b39143aa15
63	//   Public key (SS58):  EnqtFmsXcGdSnWk5JWUMXyPVamjiFQurXxcNgJEg1C3sw6W
64	//   SS58 Address:       EnqtFmsXcGdSnWk5JWUMXyPVamjiFQurXxcNgJEg1C3sw6W
65	let yap_sudo: AccountId =
66		hex2array!("6205a2a2aecb71c13d8ad3197e12c10bcdcaa0c9f176997bc236c6b39143aa15").into();
67	let mut endowed_accounts = vec![
68		yap_sudo.clone(),
69		Keyring::Alice.to_account_id(),
70		Keyring::Bob.to_account_id(),
71		Keyring::AliceStash.to_account_id(),
72		Keyring::BobStash.to_account_id(),
73	];
74
75	endowed_accounts.extend(
76		derive_accounts(NUM_ACCOUNT_PAIRS, "//Sender".into())
77			.into_iter()
78			.map(|k| k.public().into()),
79	);
80	endowed_accounts.extend(
81		derive_accounts(NUM_ACCOUNT_PAIRS, "//Receiver".into())
82			.into_iter()
83			.map(|k| k.public().into()),
84	);
85
86	GenericChainSpec::builder(
87		yet_another_parachain_runtime::WASM_BINARY
88			.expect("WASM binary was not built, please build it!"),
89		Extensions::new_with_relay_chain(relay.into()),
90	)
91	.with_name("Yet Another Parachain")
92	.with_id("yet_another_parachain")
93	.with_chain_type(chain_type)
94	.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
95	.with_genesis_config_patch(serde_json::json!({
96		"balances": {
97			"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
98		},
99		"sudo": { "key": Some(yap_sudo) },
100		"parachainInfo": {
101			"parachainId": para_id,
102		},
103	}))
104	.build()
105}