1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

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

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

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

            
17
//! Genesis configs presets for the Starlight runtime
18

            
19
#[cfg(not(feature = "std"))]
20
use sp_std::alloc::format;
21
use {
22
    crate::{SessionKeys, BABE_GENESIS_EPOCH_CONFIG},
23
    authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId,
24
    babe_primitives::AuthorityId as BabeId,
25
    beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId,
26
    grandpa_primitives::AuthorityId as GrandpaId,
27
    primitives::{vstaging::SchedulerParams, AccountId, AccountPublic, AssignmentId, ValidatorId},
28
    sp_core::{sr25519, Pair, Public},
29
    sp_runtime::traits::IdentifyAccount,
30
    sp_std::vec::Vec,
31
    starlight_runtime_constants::currency::UNITS as STAR,
32
};
33

            
34
/// Helper function to generate a crypto pair from seed
35
fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
36
    TPublic::Pair::from_string(&format!("//{}", seed), None)
37
        .expect("static values are valid; qed")
38
        .public()
39
}
40

            
41
/// Helper function to generate an account ID from seed
42
fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
43
where
44
    AccountPublic: From<<TPublic::Pair as Pair>::Public>,
45
{
46
    AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
47
}
48

            
49
/// Helper function to generate stash, controller and session key from seed
50
fn get_authority_keys_from_seed(
51
    seed: &str,
52
) -> (
53
    AccountId,
54
    AccountId,
55
    BabeId,
56
    GrandpaId,
57
    ValidatorId,
58
    AssignmentId,
59
    AuthorityDiscoveryId,
60
    BeefyId,
61
) {
62
    let keys = get_authority_keys_from_seed_no_beefy(seed);
63
    (
64
        keys.0,
65
        keys.1,
66
        keys.2,
67
        keys.3,
68
        keys.4,
69
        keys.5,
70
        keys.6,
71
        get_from_seed::<BeefyId>(seed),
72
    )
73
}
74

            
75
/// Helper function to generate stash, controller and session key from seed
76
fn get_authority_keys_from_seed_no_beefy(
77
    seed: &str,
78
) -> (
79
    AccountId,
80
    AccountId,
81
    BabeId,
82
    GrandpaId,
83
    ValidatorId,
84
    AssignmentId,
85
    AuthorityDiscoveryId,
86
) {
87
    (
88
        get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
89
        get_account_id_from_seed::<sr25519::Public>(seed),
90
        get_from_seed::<BabeId>(seed),
91
        get_from_seed::<GrandpaId>(seed),
92
        get_from_seed::<ValidatorId>(seed),
93
        get_from_seed::<AssignmentId>(seed),
94
        get_from_seed::<AuthorityDiscoveryId>(seed),
95
    )
96
}
97

            
98
fn testnet_accounts() -> Vec<AccountId> {
99
    Vec::from([
100
        get_account_id_from_seed::<sr25519::Public>("Alice"),
101
        get_account_id_from_seed::<sr25519::Public>("Bob"),
102
        get_account_id_from_seed::<sr25519::Public>("Charlie"),
103
        get_account_id_from_seed::<sr25519::Public>("Dave"),
104
        get_account_id_from_seed::<sr25519::Public>("Eve"),
105
        get_account_id_from_seed::<sr25519::Public>("Ferdie"),
106
        get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
107
        get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
108
        get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
109
        get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
110
        get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
111
        get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
112
    ])
113
}
114

            
115
fn starlight_session_keys(
116
    babe: BabeId,
117
    grandpa: GrandpaId,
118
    para_validator: ValidatorId,
119
    para_assignment: AssignmentId,
120
    authority_discovery: AuthorityDiscoveryId,
121
    beefy: BeefyId,
122
) -> SessionKeys {
123
    SessionKeys {
124
        babe,
125
        grandpa,
126
        para_validator,
127
        para_assignment,
128
        authority_discovery,
129
        beefy,
130
    }
131
}
132

            
133
1
fn default_parachains_host_configuration(
134
1
) -> runtime_parachains::configuration::HostConfiguration<primitives::BlockNumber> {
135
1
    use primitives::{
136
1
        node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE,
137
1
    };
138
1

            
139
1
    runtime_parachains::configuration::HostConfiguration {
140
1
        validation_upgrade_cooldown: 2u32,
141
1
        validation_upgrade_delay: 2,
142
1
        code_retention_period: 1200,
143
1
        max_code_size: MAX_CODE_SIZE,
144
1
        max_pov_size: MAX_POV_SIZE,
145
1
        max_head_data_size: 32 * 1024,
146
1
        max_upward_queue_count: 8,
147
1
        max_upward_queue_size: 1024 * 1024,
148
1
        max_downward_message_size: 1024 * 1024,
149
1
        max_upward_message_size: 50 * 1024,
150
1
        max_upward_message_num_per_candidate: 5,
151
1
        hrmp_sender_deposit: 0,
152
1
        hrmp_recipient_deposit: 0,
153
1
        hrmp_channel_max_capacity: 8,
154
1
        hrmp_channel_max_total_size: 8 * 1024,
155
1
        hrmp_max_parachain_inbound_channels: 4,
156
1
        hrmp_channel_max_message_size: 1024 * 1024,
157
1
        hrmp_max_parachain_outbound_channels: 4,
158
1
        hrmp_max_message_num_per_candidate: 5,
159
1
        dispute_period: 6,
160
1
        no_show_slots: 2,
161
1
        n_delay_tranches: 25,
162
1
        needed_approvals: 2,
163
1
        relay_vrf_modulo_samples: 2,
164
1
        zeroth_delay_tranche_width: 0,
165
1
        minimum_validation_upgrade_delay: 5,
166
1
        async_backing_params: AsyncBackingParams {
167
1
            max_candidate_depth: 3,
168
1
            allowed_ancestry_len: 2,
169
1
        },
170
1
        node_features: bitvec::vec::BitVec::from_element(
171
1
            1u8 << (FeatureIndex::ElasticScalingMVP as usize),
172
1
        ),
173
1
        scheduler_params: SchedulerParams {
174
1
            lookahead: 2,
175
1
            group_rotation_frequency: 20,
176
1
            paras_availability_period: 4,
177
1
            ..Default::default()
178
1
        },
179
1
        ..Default::default()
180
1
    }
181
1
}
182

            
183
#[test]
184
1
fn default_parachains_host_configuration_is_consistent() {
185
1
    default_parachains_host_configuration().panic_if_not_consistent();
186
1
}
187

            
188
fn starlight_testnet_genesis(
189
    initial_authorities: Vec<(
190
        AccountId,
191
        AccountId,
192
        BabeId,
193
        GrandpaId,
194
        ValidatorId,
195
        AssignmentId,
196
        AuthorityDiscoveryId,
197
        BeefyId,
198
    )>,
199
    root_key: AccountId,
200
    endowed_accounts: Option<Vec<AccountId>>,
201
) -> serde_json::Value {
202
    let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);
203

            
204
    const ENDOWMENT: u128 = 1_000_000 * STAR;
205

            
206
    serde_json::json!({
207
        "balances": {
208
            "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
209
        },
210
        "session": {
211
            "keys": initial_authorities
212
                .iter()
213
                .map(|x| {
214
                    (
215
                        x.0.clone(),
216
                        x.0.clone(),
217
                        starlight_session_keys(
218
                            x.2.clone(),
219
                            x.3.clone(),
220
                            x.4.clone(),
221
                            x.5.clone(),
222
                            x.6.clone(),
223
                            x.7.clone(),
224
                        ),
225
                    )
226
                })
227
                .collect::<Vec<_>>(),
228
        },
229
        "babe": {
230
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG),
231
        },
232
        "sudo": { "key": Some(root_key.clone()) },
233
        "configuration": {
234
            "config": runtime_parachains::configuration::HostConfiguration {
235
                scheduler_params: SchedulerParams {
236
                    max_validators_per_core: Some(1),
237
                    ..default_parachains_host_configuration().scheduler_params
238
                },
239
                ..default_parachains_host_configuration()
240
            },
241
        },
242
        "registrar": {
243
            "nextFreeParaId": primitives::LOWEST_PUBLIC_ID,
244
        }
245
    })
246
}
247

            
248
// staging_testnet
249
fn starlight_staging_testnet_config_genesis() -> serde_json::Value {
250
    use {hex_literal::hex, sp_core::crypto::UncheckedInto};
251

            
252
    // subkey inspect "$SECRET"
253
    let endowed_accounts = Vec::from([
254
        // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs
255
        hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(),
256
    ]);
257

            
258
    // ./scripts/prepare-test-net.sh 8
259
    let initial_authorities: Vec<(
260
        AccountId,
261
        AccountId,
262
        BabeId,
263
        GrandpaId,
264
        ValidatorId,
265
        AssignmentId,
266
        AuthorityDiscoveryId,
267
        BeefyId,
268
    )> = Vec::from([
269
        (
270
            //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei
271
            hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(),
272
            //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd
273
            hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(),
274
            //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H
275
            hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"]
276
                .unchecked_into(),
277
            //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87
278
            hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"]
279
                .unchecked_into(),
280
            //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz
281
            hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"]
282
                .unchecked_into(),
283
            //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b
284
            hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"]
285
                .unchecked_into(),
286
            //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq
287
            hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"]
288
                .unchecked_into(),
289
            //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu
290
            hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"]
291
                .unchecked_into(),
292
        ),
293
        (
294
            //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG
295
            hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(),
296
            //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3
297
            hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(),
298
            //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM
299
            hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"]
300
                .unchecked_into(),
301
            //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao
302
            hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"]
303
                .unchecked_into(),
304
            //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF
305
            hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"]
306
                .unchecked_into(),
307
            //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ
308
            hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"]
309
                .unchecked_into(),
310
            //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw
311
            hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"]
312
                .unchecked_into(),
313
            //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5
314
            hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"]
315
                .unchecked_into(),
316
        ),
317
        (
318
            //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S
319
            hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(),
320
            //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx
321
            hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(),
322
            //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY
323
            hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"]
324
                .unchecked_into(),
325
            //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP
326
            hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"]
327
                .unchecked_into(),
328
            //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU
329
            hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"]
330
                .unchecked_into(),
331
            //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV
332
            hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"]
333
                .unchecked_into(),
334
            //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa
335
            hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"]
336
                .unchecked_into(),
337
            //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF
338
            hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"]
339
                .unchecked_into(),
340
        ),
341
        (
342
            //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR
343
            hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(),
344
            //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v
345
            hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(),
346
            //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1
347
            hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"]
348
                .unchecked_into(),
349
            //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte
350
            hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"]
351
                .unchecked_into(),
352
            //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA
353
            hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"]
354
                .unchecked_into(),
355
            //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP
356
            hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"]
357
                .unchecked_into(),
358
            //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA
359
            hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"]
360
                .unchecked_into(),
361
            //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz
362
            hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"]
363
                .unchecked_into(),
364
        ),
365
        (
366
            //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N
367
            hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(),
368
            //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa
369
            hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(),
370
            //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7
371
            hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"]
372
                .unchecked_into(),
373
            //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG
374
            hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"]
375
                .unchecked_into(),
376
            //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N
377
            hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"]
378
                .unchecked_into(),
379
            //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG
380
            hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"]
381
                .unchecked_into(),
382
            //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ
383
            hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"]
384
                .unchecked_into(),
385
            //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ
386
            hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"]
387
                .unchecked_into(),
388
        ),
389
        (
390
            //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF
391
            hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(),
392
            //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM
393
            hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(),
394
            //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD
395
            hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"]
396
                .unchecked_into(),
397
            //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB
398
            hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"]
399
                .unchecked_into(),
400
            //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE
401
            hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"]
402
                .unchecked_into(),
403
            //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS
404
            hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"]
405
                .unchecked_into(),
406
            //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd
407
            hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"]
408
                .unchecked_into(),
409
            //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT
410
            hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"]
411
                .unchecked_into(),
412
        ),
413
        (
414
            //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM
415
            hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(),
416
            //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7
417
            hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(),
418
            //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96
419
            hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"]
420
                .unchecked_into(),
421
            //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N
422
            hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"]
423
                .unchecked_into(),
424
            //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT
425
            hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"]
426
                .unchecked_into(),
427
            //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa
428
            hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"]
429
                .unchecked_into(),
430
            //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7
431
            hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"]
432
                .unchecked_into(),
433
            //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx
434
            hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"]
435
                .unchecked_into(),
436
        ),
437
        (
438
            //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di
439
            hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(),
440
            //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV
441
            hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(),
442
            //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8
443
            hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"]
444
                .unchecked_into(),
445
            //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF
446
            hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"]
447
                .unchecked_into(),
448
            //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F
449
            hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"]
450
                .unchecked_into(),
451
            //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx
452
            hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"]
453
                .unchecked_into(),
454
            //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T
455
            hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"]
456
                .unchecked_into(),
457
            //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7
458
            hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"]
459
                .unchecked_into(),
460
        ),
461
    ]);
462

            
463
    const ENDOWMENT: u128 = 1_000_000 * STAR;
464
    const STASH: u128 = 100 * STAR;
465

            
466
    serde_json::json!({
467
        "balances": {
468
            "balances": endowed_accounts
469
                .iter()
470
                .map(|k: &AccountId| (k.clone(), ENDOWMENT))
471
                .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
472
                .collect::<Vec<_>>(),
473
        },
474
        "session": {
475
            "keys": initial_authorities
476
                .into_iter()
477
                .map(|x| {
478
                    (
479
                        x.0.clone(),
480
                        x.0,
481
                        starlight_session_keys(
482
                            x.2,
483
                            x.3,
484
                            x.4,
485
                            x.5,
486
                            x.6,
487
                            x.7,
488
                        ),
489
                    )
490
                })
491
                .collect::<Vec<_>>(),
492
        },
493
        "babe": {
494
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG),
495
        },
496
        "sudo": { "key": Some(endowed_accounts[0].clone()) },
497
        "configuration": {
498
            "config": default_parachains_host_configuration(),
499
        },
500
        "registrar": {
501
            "nextFreeParaId": primitives::LOWEST_PUBLIC_ID,
502
        },
503
    })
504
}
505

            
506
//development
507
fn starlight_development_config_genesis() -> serde_json::Value {
508
    starlight_testnet_genesis(
509
        Vec::from([get_authority_keys_from_seed("Alice")]),
510
        get_account_id_from_seed::<sr25519::Public>("Alice"),
511
        None,
512
    )
513
}
514

            
515
//local_testnet
516
fn starlight_local_testnet_genesis() -> serde_json::Value {
517
    starlight_testnet_genesis(
518
        Vec::from([
519
            get_authority_keys_from_seed("Alice"),
520
            get_authority_keys_from_seed("Bob"),
521
        ]),
522
        get_account_id_from_seed::<sr25519::Public>("Alice"),
523
        None,
524
    )
525
}
526

            
527
/// `Versi` is a temporary testnet that uses the same runtime as starlight.
528
// versi_local_testnet
529
fn versi_local_testnet_genesis() -> serde_json::Value {
530
    starlight_testnet_genesis(
531
        Vec::from([
532
            get_authority_keys_from_seed("Alice"),
533
            get_authority_keys_from_seed("Bob"),
534
            get_authority_keys_from_seed("Charlie"),
535
            get_authority_keys_from_seed("Dave"),
536
        ]),
537
        get_account_id_from_seed::<sr25519::Public>("Alice"),
538
        None,
539
    )
540
}
541

            
542
/// Wococo is a temporary testnet that uses almost the same runtime as starlight.
543
//wococo_local_testnet
544
fn wococo_local_testnet_genesis() -> serde_json::Value {
545
    starlight_testnet_genesis(
546
        Vec::from([
547
            get_authority_keys_from_seed("Alice"),
548
            get_authority_keys_from_seed("Bob"),
549
            get_authority_keys_from_seed("Charlie"),
550
            get_authority_keys_from_seed("Dave"),
551
        ]),
552
        get_account_id_from_seed::<sr25519::Public>("Alice"),
553
        None,
554
    )
555
}
556

            
557
/// Provides the JSON representation of predefined genesis config for given `id`.
558
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
559
    let patch = match id.try_into() {
560
        Ok("local_testnet") => starlight_local_testnet_genesis(),
561
        Ok("development") => starlight_development_config_genesis(),
562
        Ok("staging_testnet") => starlight_staging_testnet_config_genesis(),
563
        Ok("wococo_local_testnet") => wococo_local_testnet_genesis(),
564
        Ok("versi_local_testnet") => versi_local_testnet_genesis(),
565
        _ => return None,
566
    };
567
    Some(
568
        serde_json::to_string(&patch)
569
            .expect("serialization to json is expected to work. qed.")
570
            .into_bytes(),
571
    )
572
}