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 Dancelight 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
    cumulus_primitives_core::relay_chain::{
27
        SchedulerParams, ASSIGNMENT_KEY_TYPE_ID, PARACHAIN_KEY_TYPE_ID,
28
    },
29
    dancelight_runtime_constants::currency::UNITS as STAR,
30
    dp_container_chain_genesis_data::ContainerChainGenesisData,
31
    grandpa_primitives::AuthorityId as GrandpaId,
32
    nimbus_primitives::NimbusId,
33
    pallet_configuration::HostConfiguration,
34
    primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId},
35
    scale_info::prelude::string::String,
36
    sp_arithmetic::{traits::Saturating, Perbill},
37
    sp_core::{
38
        crypto::{key_types, KeyTypeId},
39
        sr25519, ByteArray, Pair, Public,
40
    },
41
    sp_keystore::{Keystore, KeystorePtr},
42
    sp_runtime::traits::IdentifyAccount,
43
    sp_std::{cmp::max, vec::Vec},
44
    tp_traits::ParaId,
45
};
46

            
47
// import macro, separate due to rustfmt thinking it's the module with the
48
// same name ^^'
49
use sp_std::vec;
50

            
51
/// Helper function to generate a crypto pair from seed
52
6266
fn get_from_seed<TPublic: Public>(
53
6266
    seed: &str,
54
6266
    add_to_keystore: Option<(&KeystorePtr, KeyTypeId)>,
55
6266
) -> <TPublic::Pair as Pair>::Public {
56
6266
    let secret_uri = format!("//{}", seed);
57
6266
    let pair = TPublic::Pair::from_string(&secret_uri, None).expect("static values are valid; qed");
58
6266

            
59
6266
    let public = pair.public();
60

            
61
6266
    if let Some((keystore, key_type)) = add_to_keystore {
62
80
        keystore
63
80
            .insert(key_type, &secret_uri, &public.to_raw_vec())
64
80
            .unwrap();
65
6186
    }
66
6266
    public
67
6266
}
68

            
69
/// Helper function to generate an account ID from seed
70
2018
fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
71
2018
where
72
2018
    AccountPublic: From<<TPublic::Pair as Pair>::Public>,
73
2018
{
74
2018
    AccountPublic::from(get_from_seed::<TPublic>(seed, None)).into_account()
75
2018
}
76

            
77
#[derive(Clone, Debug)]
78
pub struct AuthorityKeys {
79
    pub stash: AccountId,
80
    pub controller: AccountId,
81
    pub babe: BabeId,
82
    pub grandpa: GrandpaId,
83
    pub para_validator: ValidatorId,
84
    pub para_assignment: AssignmentId,
85
    pub authority_discovery: AuthorityDiscoveryId,
86
    pub beefy: BeefyId,
87
    pub nimbus: NimbusId,
88
}
89

            
90
/// Helper function to generate stash, controller and session key from seed
91
708
pub fn get_authority_keys_from_seed(seed: &str, keystore: Option<&KeystorePtr>) -> AuthorityKeys {
92
708
    let keys = get_authority_keys_from_seed_no_beefy(seed, keystore);
93
708

            
94
708
    AuthorityKeys {
95
708
        stash: keys.0,
96
708
        controller: keys.1,
97
708
        babe: keys.2,
98
708
        grandpa: keys.3,
99
708
        para_validator: keys.4,
100
708
        para_assignment: keys.5,
101
708
        authority_discovery: keys.6,
102
708
        beefy: get_from_seed::<BeefyId>(seed, None),
103
708
        nimbus: get_aura_id_from_seed(seed),
104
708
    }
105
708
}
106

            
107
/// Helper function to generate a crypto pair from seed
108
708
pub fn get_aura_id_from_seed(seed: &str) -> NimbusId {
109
708
    sp_core::sr25519::Pair::from_string(&format!("//{}", seed), None)
110
708
        .expect("static values are valid; qed")
111
708
        .public()
112
708
        .into()
113
708
}
114

            
115
/// Helper function to generate stash, controller and session key from seed
116
708
fn get_authority_keys_from_seed_no_beefy(
117
708
    seed: &str,
118
708
    keystore: Option<&KeystorePtr>,
119
708
) -> (
120
708
    AccountId,
121
708
    AccountId,
122
708
    BabeId,
123
708
    GrandpaId,
124
708
    ValidatorId,
125
708
    AssignmentId,
126
708
    AuthorityDiscoveryId,
127
708
) {
128
708
    (
129
708
        get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
130
708
        get_account_id_from_seed::<sr25519::Public>(seed),
131
708
        get_from_seed::<BabeId>(seed, keystore.map(|k| (k, key_types::BABE))),
132
708
        get_from_seed::<GrandpaId>(seed, keystore.map(|k| (k, key_types::GRANDPA))),
133
708
        get_from_seed::<ValidatorId>(seed, keystore.map(|k| (k, PARACHAIN_KEY_TYPE_ID))),
134
708
        get_from_seed::<AssignmentId>(seed, keystore.map(|k| (k, ASSIGNMENT_KEY_TYPE_ID))),
135
708
        get_from_seed::<AuthorityDiscoveryId>(
136
708
            seed,
137
708
            keystore.map(|k| (k, key_types::AUTHORITY_DISCOVERY)),
138
708
        ),
139
708
    )
140
708
}
141

            
142
42
fn testnet_accounts() -> Vec<AccountId> {
143
42
    Vec::from([
144
42
        get_account_id_from_seed::<sr25519::Public>("Alice"),
145
42
        get_account_id_from_seed::<sr25519::Public>("Bob"),
146
42
        get_account_id_from_seed::<sr25519::Public>("Charlie"),
147
42
        get_account_id_from_seed::<sr25519::Public>("Dave"),
148
42
        get_account_id_from_seed::<sr25519::Public>("Eve"),
149
42
        get_account_id_from_seed::<sr25519::Public>("Ferdie"),
150
42
        get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
151
42
        get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
152
42
        get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
153
42
        get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
154
42
        get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
155
42
        get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
156
42
    ])
157
42
}
158

            
159
126
fn dancelight_session_keys(
160
126
    babe: BabeId,
161
126
    grandpa: GrandpaId,
162
126
    para_validator: ValidatorId,
163
126
    para_assignment: AssignmentId,
164
126
    authority_discovery: AuthorityDiscoveryId,
165
126
    beefy: BeefyId,
166
126
    nimbus: NimbusId,
167
126
) -> SessionKeys {
168
126
    SessionKeys {
169
126
        babe,
170
126
        grandpa,
171
126
        para_validator,
172
126
        para_assignment,
173
126
        authority_discovery,
174
126
        beefy,
175
126
        nimbus,
176
126
    }
177
126
}
178

            
179
85
fn default_parachains_host_configuration(
180
85
) -> runtime_parachains::configuration::HostConfiguration<primitives::BlockNumber> {
181
    use primitives::{
182
        node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE,
183
    };
184

            
185
85
    runtime_parachains::configuration::HostConfiguration {
186
85
        validation_upgrade_cooldown: 2u32,
187
85
        validation_upgrade_delay: 2,
188
85
        code_retention_period: 1200,
189
85
        max_code_size: MAX_CODE_SIZE,
190
85
        max_pov_size: MAX_POV_SIZE,
191
85
        max_head_data_size: 32 * 1024,
192
85
        max_upward_queue_count: 8,
193
85
        max_upward_queue_size: 1024 * 1024,
194
85
        max_downward_message_size: 1024 * 1024,
195
85
        max_upward_message_size: 50 * 1024,
196
85
        max_upward_message_num_per_candidate: 5,
197
85
        hrmp_sender_deposit: 0,
198
85
        hrmp_recipient_deposit: 0,
199
85
        hrmp_channel_max_capacity: 8,
200
85
        hrmp_channel_max_total_size: 8 * 1024,
201
85
        hrmp_max_parachain_inbound_channels: 4,
202
85
        hrmp_channel_max_message_size: 1024 * 1024,
203
85
        hrmp_max_parachain_outbound_channels: 4,
204
85
        hrmp_max_message_num_per_candidate: 5,
205
85
        dispute_period: 6,
206
85
        no_show_slots: 2,
207
85
        n_delay_tranches: 25,
208
85
        needed_approvals: 2,
209
85
        relay_vrf_modulo_samples: 2,
210
85
        zeroth_delay_tranche_width: 0,
211
85
        minimum_validation_upgrade_delay: 5,
212
85
        async_backing_params: AsyncBackingParams {
213
85
            max_candidate_depth: 3,
214
85
            allowed_ancestry_len: 2,
215
85
        },
216
85
        node_features: bitvec::vec::BitVec::from_element(
217
85
            (1u8 << (FeatureIndex::ElasticScalingMVP as usize)) |
218
85
            // TODO: this may not be needed, we could still support v1 only
219
85
                           (1u8 << (FeatureIndex::CandidateReceiptV2 as usize)),
220
85
        ),
221
85
        scheduler_params: SchedulerParams {
222
85
            lookahead: 2,
223
85
            group_rotation_frequency: 20,
224
85
            paras_availability_period: 4,
225
85
            ..Default::default()
226
85
        },
227
85
        ..Default::default()
228
85
    }
229
85
}
230

            
231
#[test]
232
1
fn default_parachains_host_configuration_is_consistent() {
233
1
    default_parachains_host_configuration().panic_if_not_consistent();
234
1
}
235

            
236
42
fn dancelight_testnet_genesis(
237
42
    initial_authorities: Vec<AuthorityKeys>,
238
42
    root_key: AccountId,
239
42
    endowed_accounts: Option<Vec<AccountId>>,
240
42
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
241
42
    invulnerables: Vec<String>,
242
42
    host_configuration: HostConfiguration,
243
42
) -> serde_json::Value {
244
42
    let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);
245
42

            
246
42
    let invulnerable_keys: Vec<_> = invulnerables
247
42
        .iter()
248
56
        .map(|seed| get_authority_keys_from_seed(seed, None))
249
42
        .collect();
250
42

            
251
42
    let invulnerable_accounts: Vec<_> = invulnerables
252
42
        .iter()
253
56
        .map(|seed| get_account_id_from_seed::<sr25519::Public>(seed))
254
42
        .collect();
255
42

            
256
42
    let data_preservers_bootnodes: Vec<_> = container_chains
257
42
        .iter()
258
84
        .flat_map(|(para_id, _genesis_data, bootnodes)| {
259
84
            bootnodes.clone().into_iter().map(|bootnode| {
260
                (
261
                    *para_id,
262
                    AccountId::from([0u8; 32]),
263
                    bootnode,
264
                    crate::PreserversAssignmentPaymentRequest::Free,
265
                    crate::PreserversAssignmentPaymentWitness::Free,
266
                )
267
84
            })
268
84
        })
269
42
        .collect();
270
42

            
271
42
    let para_ids: Vec<_> = container_chains
272
42
        .iter()
273
42
        .cloned()
274
84
        .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None))
275
42
        .collect();
276
42

            
277
42
    // In order to register container-chains from genesis, we need to register their
278
42
    // head on the relay registrar. However there is no easy way to do that unless we touch all the code
279
42
    // so we generate a dummy head state for it. This can be then overriden (as zombienet does) and everything would work
280
42
    // TODO: make this cleaner
281
42
    let registrar_para_ids_info: Vec<_> = container_chains
282
42
        .into_iter()
283
84
        .filter_map(|(para_id, genesis_data, _boot_nodes)| {
284
            // Check if the wasm code is present in storage
285
            // If not present, we ignore it
286
84
            let validation_code = match genesis_data
287
84
                .storage
288
84
                .into_iter()
289
84
                .find(|item| item.key == crate::StorageWellKnownKeys::CODE)
290
            {
291
84
                Some(item) => Some(crate::ValidationCode(item.value.clone())),
292
                None => None,
293
            }?;
294
84
            let genesis_args = runtime_parachains::paras::ParaGenesisArgs {
295
84
                genesis_head: vec![0x01].into(),
296
84
                validation_code,
297
84
                para_kind: runtime_parachains::paras::ParaKind::Parachain,
298
84
            };
299
84

            
300
84
            Some((
301
84
                para_id,
302
84
                (
303
84
                    genesis_args.genesis_head,
304
84
                    genesis_args.validation_code,
305
84
                    genesis_args.para_kind,
306
84
                ),
307
84
            ))
308
84
        })
309
42
        .collect();
310
42

            
311
42
    // Assign 1000 block credits to all container chains registered in genesis
312
42
    // Assign 100 collator assignment credits to all container chains registered in genesis
313
42
    let para_id_credits: Vec<_> = para_ids
314
42
        .iter()
315
84
        .map(|(para_id, _genesis_data, _boot_nodes)| (*para_id, 1000, 100).into())
316
42
        .collect();
317

            
318
    const ENDOWMENT: u128 = 1_000_000 * STAR;
319

            
320
42
    let core_percentage_for_pool_paras = Perbill::from_percent(100).saturating_sub(
321
42
        host_configuration
322
42
            .max_parachain_cores_percentage
323
42
            .unwrap_or(Perbill::from_percent(50)),
324
42
    );
325
42

            
326
42
    // don't go below 4 cores
327
42
    let num_cores = max(
328
42
        para_ids.len() as u32 + core_percentage_for_pool_paras.mul_ceil(para_ids.len() as u32),
329
42
        4,
330
42
    );
331
42

            
332
42
    // Initialize nextFreeParaId to a para id that is greater than all registered para ids.
333
42
    // This is needed for Registrar::reserve.
334
42
    let max_para_id = para_ids
335
42
        .iter()
336
84
        .map(|(para_id, _genesis_data, _boot_nodes)| para_id)
337
42
        .max();
338
42
    let next_free_para_id = max_para_id
339
42
        .map(|x| ParaId::from(u32::from(*x) + 1))
340
42
        .unwrap_or(primitives::LOWEST_PUBLIC_ID);
341
42
    let accounts_with_ed = [
342
42
        crate::StakingAccount::get(),
343
42
        crate::DancelightBondAccount::get(),
344
42
        crate::PendingRewardsAccount::get(),
345
42
        crate::EthereumSovereignAccount::get(),
346
42
    ];
347
42

            
348
42
    serde_json::json!({
349
42
        "balances": {
350
42
            "balances": endowed_accounts
351
42
                .iter()
352
42
                .cloned()
353
504
                .map(|k| (k, ENDOWMENT))
354
42
                .chain(
355
42
                    accounts_with_ed
356
42
                        .iter()
357
42
                        .cloned()
358
168
                        .map(|k| (k, crate::EXISTENTIAL_DEPOSIT)),
359
42
                )
360
42
                .collect::<Vec<_>>(),
361
42
        },
362
42
        "session": {
363
42
            "keys": initial_authorities
364
42
                .iter()
365
70
                .map(|x| {
366
70
                    (
367
70
                        x.stash.clone(),
368
70
                        x.stash.clone(),
369
70
                        dancelight_session_keys(
370
70
                            x.babe.clone(),
371
70
                            x.grandpa.clone(),
372
70
                            x.para_validator.clone(),
373
70
                            x.para_assignment.clone(),
374
70
                            x.authority_discovery.clone(),
375
70
                            x.beefy.clone(),
376
70
                            x.nimbus.clone(),
377
70
                        ),
378
70
                    )
379
70
                })
380
42
                .collect::<Vec<_>>(),
381
42
            "nonAuthorityKeys": invulnerable_keys
382
42
                .into_iter()
383
42
                .enumerate()
384
56
                .map(|(i, x)| {
385
56
                    (
386
56
                        invulnerable_accounts[i].clone(),
387
56
                        invulnerable_accounts[i].clone(),
388
56
                        dancelight_session_keys(
389
56
                            x.babe.clone(),
390
56
                            x.grandpa.clone(),
391
56
                            x.para_validator.clone(),
392
56
                            x.para_assignment.clone(),
393
56
                            x.authority_discovery.clone(),
394
56
                            x.beefy.clone(),
395
56
                            x.nimbus.clone(),
396
56
                        ),
397
56
                    )
398
56
                })
399
42
                .collect::<Vec<_>>(),
400
42
        },
401
42
        "babe": {
402
42
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG)
403
42
        },
404
42
        "sudo": { "key": Some(root_key.clone()) },
405
42
        "configuration": {
406
42
            "config": runtime_parachains::configuration::HostConfiguration {
407
42
                scheduler_params: SchedulerParams {
408
42
                    max_validators_per_core: Some(1),
409
42
                    num_cores,
410
42
                    ..default_parachains_host_configuration().scheduler_params
411
42
                },
412
42
                ..default_parachains_host_configuration()
413
42
            },
414
42
        },
415
42
        "registrar": {
416
42
            "nextFreeParaId": next_free_para_id,
417
42
        },
418
42
        "tanssiInvulnerables": crate::TanssiInvulnerablesConfig {
419
42
            invulnerables: invulnerable_accounts,
420
42
        },
421
42
        "containerRegistrar": crate::ContainerRegistrarConfig { para_ids, ..Default::default() },
422
42
        "paras": {
423
42
            "paras": registrar_para_ids_info,
424
42
        },
425
42
        "servicesPayment": crate::ServicesPaymentConfig { para_id_credits },
426
42
            "dataPreservers": crate::DataPreserversConfig {
427
42
                bootnodes: data_preservers_bootnodes,
428
42
                ..Default::default()
429
42
        },
430
42
        "collatorConfiguration": crate::CollatorConfigurationConfig {
431
42
            config: host_configuration,
432
42
            ..Default::default()
433
42
        },
434
42
        "externalValidators": crate::ExternalValidatorsConfig {
435
42
            skip_external_validators: false,
436
42
            whitelisted_validators: initial_authorities
437
42
                .iter()
438
70
                .map(|x| {
439
70
                    x.stash.clone()
440
70
                })
441
42
                .collect::<Vec<_>>(),
442
42
            ..Default::default()
443
42
        },
444
42
    })
445
42
}
446

            
447
// staging_testnet
448
fn dancelight_staging_testnet_config_genesis() -> serde_json::Value {
449
    use {hex_literal::hex, sp_core::crypto::UncheckedInto};
450

            
451
    // subkey inspect "$SECRET"
452
    let endowed_accounts = Vec::from([
453
        // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs
454
        hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(),
455
    ]);
456

            
457
    let initial_authorities = Vec::from([
458
        AuthorityKeys {
459
            stash: //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei
460
                hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(),
461
                controller: //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd
462
                hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(),
463
                babe: //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H
464
                hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"].unchecked_into(),
465
                grandpa: //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87
466
                hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"].unchecked_into(),
467
                para_validator: //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz
468
                hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"].unchecked_into(),
469
                para_assignment: //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b
470
                hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"].unchecked_into(),
471
                authority_discovery: //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq
472
                hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"].unchecked_into(),
473
                beefy: //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu
474
                hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"].unchecked_into(),
475
                nimbus: //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H
476
                hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"].unchecked_into(),
477
            },
478
        AuthorityKeys {
479
                stash: //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG
480
                hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(),
481
                controller: //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3
482
                hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(),
483
                babe: //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM
484
                hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"].unchecked_into(),
485
                grandpa: //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao
486
                hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"].unchecked_into(),
487
                para_validator: //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF
488
                hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"].unchecked_into(),
489
                para_assignment: //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ
490
                hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"].unchecked_into(),
491
                authority_discovery: //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw
492
                hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"].unchecked_into(),
493
                beefy: //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5
494
                hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"].unchecked_into(),
495
                nimbus: //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM
496
                hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"].unchecked_into(),
497
            },
498
        AuthorityKeys {
499
                stash: //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S
500
                hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(),
501
                controller: //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx
502
                hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(),
503
                babe: //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY
504
                hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"].unchecked_into(),
505
                grandpa: //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP
506
                hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"].unchecked_into(),
507
                para_validator: //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU
508
                hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"].unchecked_into(),
509
                para_assignment: //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV
510
                hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"].unchecked_into(),
511
                authority_discovery: //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa
512
                hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"].unchecked_into(),
513
                beefy: //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF
514
                hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"].unchecked_into(),
515
                nimbus: hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"].unchecked_into(),
516
            },
517
        AuthorityKeys {
518
                stash: //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR
519
                hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(),
520
                controller: //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v
521
                hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(),
522
                babe: //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1
523
                hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"]
524
                    .unchecked_into(),
525
                grandpa: //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte
526
                hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"]
527
                    .unchecked_into(),
528
                para_validator: //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA
529
                hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"]
530
                    .unchecked_into(),
531
                para_assignment: //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP
532
                hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"]
533
                    .unchecked_into(),
534
                authority_discovery: //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA
535
                hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"]
536
                    .unchecked_into(),
537
                beefy: //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz
538
                hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"]
539
                    .unchecked_into(),
540
                nimbus: hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"]
541
                    .unchecked_into(),
542
            },
543
        AuthorityKeys {
544
                stash: //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N
545
                hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(),
546
                controller: //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa
547
                hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(),
548
                babe: //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7
549
            hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"]
550
                .unchecked_into(),
551
            grandpa: //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG
552
            hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"]
553
                .unchecked_into(),
554
            para_validator: //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N
555
            hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"]
556
                .unchecked_into(),
557
            para_assignment: //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG
558
            hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"]
559
                .unchecked_into(),
560
            authority_discovery: //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ
561
            hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"]
562
                .unchecked_into(),
563
            beefy: //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ
564
            hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"]
565
                .unchecked_into(),
566
            nimbus: hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"]
567
                .unchecked_into(),
568
        },
569
        AuthorityKeys {
570
            stash: //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF
571
            hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(),
572
            controller: //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM
573
            hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(),
574
            babe: //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD
575
            hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"]
576
                .unchecked_into(),
577
            grandpa: //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB
578
            hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"]
579
                .unchecked_into(),
580
            para_validator: //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE
581
            hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"]
582
                .unchecked_into(),
583
            para_assignment: //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS
584
            hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"]
585
                .unchecked_into(),
586
            authority_discovery: //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd
587
            hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"]
588
                .unchecked_into(),
589
            beefy: //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT
590
            hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"]
591
                .unchecked_into(),
592
            nimbus: //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD
593
            hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"]
594
                .unchecked_into(),
595
        },
596
        AuthorityKeys {
597
            stash: //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM
598
            hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(),
599
            controller: //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7
600
            hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(),
601
            babe: //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96
602
            hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"]
603
                .unchecked_into(),
604
            grandpa: //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N
605
            hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"]
606
                .unchecked_into(),
607
            para_validator: //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT
608
            hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"]
609
                .unchecked_into(),
610
            para_assignment: //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa
611
            hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"]
612
                .unchecked_into(),
613
            authority_discovery: //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7
614
            hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"]
615
                .unchecked_into(),
616
            beefy: //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx
617
            hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"]
618
                .unchecked_into(),
619
            nimbus: hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"]
620
                .unchecked_into(),
621
        },
622
        AuthorityKeys {
623
            stash: //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di
624
            hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(),
625
            controller: //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV
626
            hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(),
627
            babe: //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8
628
            hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"]
629
                .unchecked_into(),
630
            grandpa: //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF
631
            hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"]
632
                .unchecked_into(),
633
            para_validator: //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F
634
            hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"]
635
                .unchecked_into(),
636
            para_assignment: //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx
637
            hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"]
638
                .unchecked_into(),
639
            authority_discovery: //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T
640
            hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"]
641
                .unchecked_into(),
642
            beefy: //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7
643
            hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"]
644
                .unchecked_into(),
645
            nimbus: hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"]
646
                .unchecked_into(),
647
        },
648
    ]);
649

            
650
    const ENDOWMENT: u128 = 1_000_000 * STAR;
651
    const STASH: u128 = 100 * STAR;
652

            
653
    serde_json::json!({
654
        "balances": {
655
            "balances": endowed_accounts
656
                .iter()
657
                .map(|k: &AccountId| (k.clone(), ENDOWMENT))
658
                .chain(initial_authorities.iter().map(|x| (x.stash.clone(), STASH)))
659
                .collect::<Vec<_>>(),
660
        },
661
        "session": {
662
            "keys": initial_authorities
663
                .into_iter()
664
                .map(|x| {
665
                    (
666
                        x.stash.clone(),
667
                        x.stash,
668
                        dancelight_session_keys(
669
                            x.babe,
670
                            x.grandpa,
671
                            x.para_validator,
672
                            x.para_assignment,
673
                            x.authority_discovery,
674
                            x.beefy,
675
                            x.nimbus,
676
                        ),
677
                    )
678
                })
679
                .collect::<Vec<_>>(),
680
        },
681
        "babe": {
682
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG),
683
        },
684
        "sudo": { "key": Some(endowed_accounts[0].clone()) },
685
        "configuration": {
686
            "config": default_parachains_host_configuration(),
687
        },
688
        "registrar": {
689
            "nextFreeParaId": primitives::LOWEST_PUBLIC_ID,
690
        },
691
    })
692
}
693

            
694
//development
695
14
pub fn dancelight_development_config_genesis(
696
14
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
697
14
    invulnerables: Vec<String>,
698
14
) -> serde_json::Value {
699
14
    dancelight_testnet_genesis(
700
14
        Vec::from([get_authority_keys_from_seed("Alice", None)]),
701
14
        get_account_id_from_seed::<sr25519::Public>("Alice"),
702
14
        None,
703
14
        container_chains,
704
14
        invulnerables,
705
14
        HostConfiguration {
706
14
            max_collators: 100u32,
707
14
            min_orchestrator_collators: 0u32,
708
14
            max_orchestrator_collators: 0u32,
709
14
            collators_per_container: 2u32,
710
14
            full_rotation_period: runtime_common::prod_or_fast!(24u32, 5u32),
711
14
            max_parachain_cores_percentage: Some(Perbill::from_percent(60)),
712
14
            ..Default::default()
713
14
        },
714
14
    )
715
14
}
716

            
717
//local_testnet
718
28
pub fn dancelight_local_testnet_genesis(
719
28
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
720
28
    invulnerables: Vec<String>,
721
28
) -> serde_json::Value {
722
28
    dancelight_testnet_genesis(
723
28
        Vec::from([
724
28
            get_authority_keys_from_seed("Alice", None),
725
28
            get_authority_keys_from_seed("Bob", None),
726
28
        ]),
727
28
        get_account_id_from_seed::<sr25519::Public>("Alice"),
728
28
        None,
729
28
        container_chains,
730
28
        invulnerables,
731
28
        HostConfiguration {
732
28
            max_collators: 100u32,
733
28
            min_orchestrator_collators: 0u32,
734
28
            max_orchestrator_collators: 0u32,
735
28
            collators_per_container: 2u32,
736
28
            full_rotation_period: runtime_common::prod_or_fast!(24u32, 5u32),
737
28
            max_parachain_cores_percentage: Some(Perbill::from_percent(60)),
738
28
            ..Default::default()
739
28
        },
740
28
    )
741
28
}
742

            
743
/// Provides the JSON representation of predefined genesis config for given `id`.
744
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
745
    let patch = match id.as_ref() {
746
        "local_testnet" => dancelight_local_testnet_genesis(vec![], vec![]),
747
        "development" => dancelight_development_config_genesis(vec![], vec![]),
748
        "staging_testnet" => dancelight_staging_testnet_config_genesis(),
749
        _ => return None,
750
    };
751
    Some(
752
        serde_json::to_string(&patch)
753
            .expect("serialization to json is expected to work. qed.")
754
            .into_bytes(),
755
    )
756
}