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
use {
20
    crate::{SessionKeys, BABE_GENESIS_EPOCH_CONFIG},
21
    alloc::{format, vec::Vec},
22
    authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId,
23
    babe_primitives::AuthorityId as BabeId,
24
    beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId,
25
    core::cmp::max,
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, 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::AccountIdConversion,
43
    tp_traits::ParaId,
44
};
45

            
46
use keyring::Sr25519Keyring;
47

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

            
52
use sp_core::crypto::{get_public_from_string_or_panic, AccountId32};
53

            
54
14
pub fn insert_authority_keys_into_keystore(seed: &str, keystore: &KeystorePtr) {
55
14
    insert_into_keystore::<BabeId>(seed, keystore, key_types::BABE);
56
14
    insert_into_keystore::<GrandpaId>(seed, keystore, key_types::GRANDPA);
57
14
    insert_into_keystore::<ValidatorId>(seed, keystore, PARACHAIN_KEY_TYPE_ID);
58
14
    insert_into_keystore::<AssignmentId>(seed, keystore, ASSIGNMENT_KEY_TYPE_ID);
59
14
    insert_into_keystore::<AuthorityDiscoveryId>(seed, keystore, key_types::AUTHORITY_DISCOVERY);
60
14
}
61

            
62
70
fn insert_into_keystore<TPublic: Public>(seed: &str, keystore: &KeystorePtr, key_type: KeyTypeId) {
63
70
    let public = get_public_from_string_or_panic::<TPublic>(seed);
64
70

            
65
70
    let secret_uri = format!("//{}", seed);
66
70
    keystore
67
70
        .insert(key_type, &secret_uri, &public.to_raw_vec())
68
70
        .unwrap();
69
70
}
70

            
71
#[derive(Clone, Debug)]
72
pub struct AuthorityKeys {
73
    pub stash: AccountId,
74
    pub controller: AccountId,
75
    pub babe: BabeId,
76
    pub grandpa: GrandpaId,
77
    pub para_validator: ValidatorId,
78
    pub para_assignment: AssignmentId,
79
    pub authority_discovery: AuthorityDiscoveryId,
80
    pub beefy: BeefyId,
81
    pub nimbus: NimbusId,
82
}
83

            
84
/// Helper function to generate stash, controller and session key from seed
85
764
pub fn get_authority_keys_from_seed(seed: &str) -> AuthorityKeys {
86
764
    let keys = get_authority_keys_from_seed_no_beefy(seed);
87
764

            
88
764
    AuthorityKeys {
89
764
        stash: keys.0,
90
764
        controller: keys.1,
91
764
        babe: keys.2,
92
764
        grandpa: keys.3,
93
764
        para_validator: keys.4,
94
764
        para_assignment: keys.5,
95
764
        authority_discovery: keys.6,
96
764
        beefy: get_public_from_string_or_panic::<BeefyId>(seed),
97
764
        nimbus: get_aura_id_from_seed(seed),
98
764
    }
99
764
}
100

            
101
/// Helper function to generate a crypto pair from seed
102
764
pub fn get_aura_id_from_seed(seed: &str) -> NimbusId {
103
764
    sp_core::sr25519::Pair::from_string(&format!("//{}", seed), None)
104
764
        .expect("static values are valid; qed")
105
764
        .public()
106
764
        .into()
107
764
}
108

            
109
/// Helper function to generate stash, controller and session key from seed
110
764
fn get_authority_keys_from_seed_no_beefy(
111
764
    seed: &str,
112
764
) -> (
113
764
    AccountId,
114
764
    AccountId,
115
764
    BabeId,
116
764
    GrandpaId,
117
764
    ValidatorId,
118
764
    AssignmentId,
119
764
    AuthorityDiscoveryId,
120
764
) {
121
764
    (
122
764
        get_public_from_string_or_panic::<sr25519::Public>(&format!("{}//stash", seed)).into(),
123
764
        get_public_from_string_or_panic::<sr25519::Public>(seed).into(),
124
764
        get_public_from_string_or_panic::<BabeId>(seed),
125
764
        get_public_from_string_or_panic::<GrandpaId>(seed),
126
764
        get_public_from_string_or_panic::<ValidatorId>(seed),
127
764
        get_public_from_string_or_panic::<AssignmentId>(seed),
128
764
        get_public_from_string_or_panic::<AuthorityDiscoveryId>(seed),
129
764
    )
130
764
}
131

            
132
42
fn testnet_accounts() -> Vec<AccountId> {
133
42
    Sr25519Keyring::well_known()
134
504
        .map(|k| k.to_account_id())
135
42
        .collect()
136
42
}
137

            
138
120
fn dancelight_session_keys(
139
120
    babe: BabeId,
140
120
    grandpa: GrandpaId,
141
120
    para_validator: ValidatorId,
142
120
    para_assignment: AssignmentId,
143
120
    authority_discovery: AuthorityDiscoveryId,
144
120
    beefy: BeefyId,
145
120
    nimbus: NimbusId,
146
120
) -> SessionKeys {
147
120
    SessionKeys {
148
120
        babe,
149
120
        grandpa,
150
120
        para_validator,
151
120
        para_assignment,
152
120
        authority_discovery,
153
120
        beefy,
154
120
        nimbus,
155
120
    }
156
120
}
157

            
158
165
pub fn default_parachains_host_configuration(
159
165
) -> runtime_parachains::configuration::HostConfiguration<primitives::BlockNumber> {
160
    use primitives::{
161
        node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE,
162
    };
163

            
164
165
    runtime_parachains::configuration::HostConfiguration {
165
165
        validation_upgrade_cooldown: 2u32,
166
165
        validation_upgrade_delay: 2,
167
165
        code_retention_period: 1200,
168
165
        max_code_size: MAX_CODE_SIZE,
169
165
        max_pov_size: MAX_POV_SIZE,
170
165
        max_head_data_size: 32 * 1024,
171
165
        max_upward_queue_count: 8,
172
165
        max_upward_queue_size: 1024 * 1024,
173
165
        max_downward_message_size: 1024 * 1024,
174
165
        max_upward_message_size: 50 * 1024,
175
165
        max_upward_message_num_per_candidate: 5,
176
165
        hrmp_sender_deposit: 0,
177
165
        hrmp_recipient_deposit: 0,
178
165
        hrmp_channel_max_capacity: 8,
179
165
        hrmp_channel_max_total_size: 8 * 1024,
180
165
        hrmp_max_parachain_inbound_channels: 4,
181
165
        hrmp_channel_max_message_size: 1024 * 1024,
182
165
        hrmp_max_parachain_outbound_channels: 4,
183
165
        hrmp_max_message_num_per_candidate: 5,
184
165
        dispute_period: 6,
185
165
        no_show_slots: 2,
186
165
        n_delay_tranches: 25,
187
165
        needed_approvals: 2,
188
165
        relay_vrf_modulo_samples: 2,
189
165
        zeroth_delay_tranche_width: 0,
190
165
        minimum_validation_upgrade_delay: 5,
191
165
        async_backing_params: AsyncBackingParams {
192
165
            max_candidate_depth: 3,
193
165
            allowed_ancestry_len: 2,
194
165
        },
195
165
        node_features: bitvec::vec::BitVec::from_element(
196
165
            (1u8 << (FeatureIndex::ElasticScalingMVP as usize)) |
197
165
            // TODO: this may not be needed, we could still support v1 only
198
165
                           (1u8 << (FeatureIndex::CandidateReceiptV2 as usize)),
199
165
        ),
200
165
        scheduler_params: SchedulerParams {
201
165
            lookahead: 2,
202
165
            group_rotation_frequency: 20,
203
165
            paras_availability_period: 4,
204
165
            ..Default::default()
205
165
        },
206
165
        ..Default::default()
207
165
    }
208
165
}
209

            
210
#[test]
211
1
fn default_parachains_host_configuration_is_consistent() {
212
1
    default_parachains_host_configuration().panic_if_not_consistent();
213
1
}
214

            
215
42
fn dancelight_testnet_genesis(
216
42
    initial_authorities: Vec<AuthorityKeys>,
217
42
    root_key: AccountId,
218
42
    endowed_accounts: Option<Vec<AccountId>>,
219
42
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
220
42
    invulnerables: Vec<String>,
221
42
    host_configuration: HostConfiguration,
222
42
) -> serde_json::Value {
223
42
    let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);
224
42

            
225
42
    let invulnerable_keys: Vec<_> = invulnerables
226
42
        .iter()
227
48
        .map(|seed| get_authority_keys_from_seed(seed))
228
42
        .collect();
229
42

            
230
42
    let invulnerable_accounts: Vec<AccountId32> = invulnerables
231
42
        .iter()
232
48
        .map(|seed| get_public_from_string_or_panic::<sr25519::Public>(seed).into())
233
42
        .collect();
234
42

            
235
42
    let data_preservers_bootnodes: Vec<_> = container_chains
236
42
        .iter()
237
84
        .flat_map(|(para_id, _genesis_data, bootnodes)| {
238
84
            bootnodes.clone().into_iter().map(|bootnode| {
239
                (
240
                    *para_id,
241
                    AccountId::from([0u8; 32]),
242
                    bootnode,
243
                    tp_data_preservers_common::ProviderRequest::Free,
244
                    tp_data_preservers_common::AssignmentWitness::Free,
245
                )
246
84
            })
247
84
        })
248
42
        .collect();
249
42

            
250
42
    let para_ids: Vec<_> = container_chains
251
42
        .iter()
252
42
        .cloned()
253
84
        .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None))
254
42
        .collect();
255
42

            
256
42
    // In order to register container-chains from genesis, we need to register their
257
42
    // head on the relay registrar. However there is no easy way to do that unless we touch all the code
258
42
    // so we generate a dummy head state for it. This can be then overriden (as zombienet does) and everything would work
259
42
    // TODO: make this cleaner
260
42
    let registrar_para_ids_info: Vec<_> = container_chains
261
42
        .into_iter()
262
84
        .filter_map(|(para_id, genesis_data, _boot_nodes)| {
263
            // Check if the wasm code is present in storage
264
            // If not present, we ignore it
265
84
            let validation_code = match genesis_data
266
84
                .storage
267
84
                .into_iter()
268
84
                .find(|item| item.key == crate::StorageWellKnownKeys::CODE)
269
            {
270
84
                Some(item) => Some(crate::ValidationCode(item.value.clone())),
271
                None => None,
272
            }?;
273
84
            let genesis_args = runtime_parachains::paras::ParaGenesisArgs {
274
84
                genesis_head: vec![0x01].into(),
275
84
                validation_code,
276
84
                para_kind: runtime_parachains::paras::ParaKind::Parachain,
277
84
            };
278
84

            
279
84
            Some((
280
84
                para_id,
281
84
                (
282
84
                    genesis_args.genesis_head,
283
84
                    genesis_args.validation_code,
284
84
                    genesis_args.para_kind,
285
84
                ),
286
84
            ))
287
84
        })
288
42
        .collect();
289
42

            
290
42
    // Assign 1000 block credits to all container chains registered in genesis
291
42
    // Assign 100 collator assignment credits to all container chains registered in genesis
292
42
    let para_id_credits: Vec<_> = para_ids
293
42
        .iter()
294
84
        .map(|(para_id, _genesis_data, _boot_nodes)| (*para_id, 1000, 100).into())
295
42
        .collect();
296

            
297
    const ENDOWMENT: u128 = 1_000_000 * STAR;
298

            
299
42
    let core_percentage_for_pool_paras = Perbill::from_percent(100).saturating_sub(
300
42
        host_configuration
301
42
            .max_parachain_cores_percentage
302
42
            .unwrap_or(Perbill::from_percent(50)),
303
42
    );
304
42

            
305
42
    // don't go below 4 cores
306
42
    let num_cores = max(
307
42
        para_ids.len() as u32 + core_percentage_for_pool_paras.mul_ceil(para_ids.len() as u32),
308
42
        4,
309
42
    );
310
42

            
311
42
    // Initialize nextFreeParaId to a para id that is greater than all registered para ids.
312
42
    // This is needed for Registrar::reserve.
313
42
    let max_para_id = para_ids
314
42
        .iter()
315
84
        .map(|(para_id, _genesis_data, _boot_nodes)| para_id)
316
42
        .max();
317
42
    let next_free_para_id = max_para_id
318
42
        .map(|x| ParaId::from(u32::from(*x) + 1))
319
42
        .unwrap_or(primitives::LOWEST_PUBLIC_ID);
320
42
    let accounts_with_ed = [
321
42
        crate::StakingAccount::get(),
322
42
        crate::DancelightBondAccount::get(),
323
42
        crate::PendingRewardsAccount::get(),
324
42
        crate::EthereumSovereignAccount::get(),
325
42
        crate::SnowbridgeFeesAccount::get(),
326
42
        crate::TreasuryPalletId::get().into_account_truncating(),
327
42
    ];
328
42

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

            
432
// staging_testnet
433
fn dancelight_staging_testnet_config_genesis() -> serde_json::Value {
434
    use {hex_literal::hex, sp_core::crypto::UncheckedInto};
435

            
436
    // subkey inspect "$SECRET"
437
    let endowed_accounts = Vec::from([
438
        // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs
439
        hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(),
440
    ]);
441

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

            
635
    const ENDOWMENT: u128 = 1_000_000 * STAR;
636
    const STASH: u128 = 100 * STAR;
637

            
638
    serde_json::json!({
639
        "balances": {
640
            "balances": endowed_accounts
641
                .iter()
642
                .map(|k: &AccountId| (k.clone(), ENDOWMENT))
643
                .chain(initial_authorities.iter().map(|x| (x.stash.clone(), STASH)))
644
                .collect::<Vec<_>>(),
645
        },
646
        "session": {
647
            "keys": initial_authorities
648
                .into_iter()
649
                .map(|x| {
650
                    (
651
                        x.stash.clone(),
652
                        x.stash,
653
                        dancelight_session_keys(
654
                            x.babe,
655
                            x.grandpa,
656
                            x.para_validator,
657
                            x.para_assignment,
658
                            x.authority_discovery,
659
                            x.beefy,
660
                            x.nimbus,
661
                        ),
662
                    )
663
                })
664
                .collect::<Vec<_>>(),
665
        },
666
        "babe": {
667
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG),
668
        },
669
        "sudo": { "key": Some(endowed_accounts[0].clone()) },
670
        "configuration": {
671
            "config": default_parachains_host_configuration(),
672
        },
673
        "registrar": {
674
            "nextFreeParaId": primitives::LOWEST_PUBLIC_ID,
675
        },
676
    })
677
}
678

            
679
//development
680
12
pub fn dancelight_development_config_genesis(
681
12
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
682
12
    invulnerables: Vec<String>,
683
12
) -> serde_json::Value {
684
12
    dancelight_testnet_genesis(
685
12
        Vec::from([get_authority_keys_from_seed("Alice")]),
686
12
        Sr25519Keyring::Alice.to_account_id(),
687
12
        None,
688
12
        container_chains,
689
12
        invulnerables,
690
12
        HostConfiguration {
691
12
            max_collators: 100u32,
692
12
            min_orchestrator_collators: 0u32,
693
12
            max_orchestrator_collators: 0u32,
694
12
            collators_per_container: 2u32,
695
12
            full_rotation_period: runtime_common::prod_or_fast!(24u32, 5u32),
696
12
            max_parachain_cores_percentage: Some(Perbill::from_percent(60)),
697
12
            ..Default::default()
698
12
        },
699
12
    )
700
12
}
701

            
702
//local_testnet
703
30
pub fn dancelight_local_testnet_genesis(
704
30
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
705
30
    invulnerables: Vec<String>,
706
30
) -> serde_json::Value {
707
30
    dancelight_testnet_genesis(
708
30
        Vec::from([
709
30
            get_authority_keys_from_seed("Alice"),
710
30
            get_authority_keys_from_seed("Bob"),
711
30
        ]),
712
30
        Sr25519Keyring::Alice.to_account_id(),
713
30
        None,
714
30
        container_chains,
715
30
        invulnerables,
716
30
        HostConfiguration {
717
30
            max_collators: 100u32,
718
30
            min_orchestrator_collators: 0u32,
719
30
            max_orchestrator_collators: 0u32,
720
30
            collators_per_container: 2u32,
721
30
            full_rotation_period: runtime_common::prod_or_fast!(24u32, 5u32),
722
30
            max_parachain_cores_percentage: Some(Perbill::from_percent(60)),
723
30
            ..Default::default()
724
30
        },
725
30
    )
726
30
}
727

            
728
/// Provides the JSON representation of predefined genesis config for given `id`.
729
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<alloc::vec::Vec<u8>> {
730
    let patch = match id.as_ref() {
731
        "local_testnet" => dancelight_local_testnet_genesis(vec![], vec![]),
732
        "development" => dancelight_development_config_genesis(vec![], vec![]),
733
        "staging_testnet" => dancelight_staging_testnet_config_genesis(),
734
        _ => return None,
735
    };
736
    Some(
737
        serde_json::to_string(&patch)
738
            .expect("serialization to json is expected to work. qed.")
739
            .into_bytes(),
740
    )
741
}