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

            
45
/// Helper function to generate a crypto pair from seed
46
14438
fn get_from_seed<TPublic: Public>(
47
14438
    seed: &str,
48
14438
    add_to_keystore: Option<(&KeystorePtr, KeyTypeId)>,
49
14438
) -> <TPublic::Pair as Pair>::Public {
50
14438
    let secret_uri = format!("//{}", seed);
51
14438
    let pair = TPublic::Pair::from_string(&secret_uri, None).expect("static values are valid; qed");
52
14438

            
53
14438
    let public = pair.public();
54

            
55
14438
    if let Some((keystore, key_type)) = add_to_keystore {
56
70
        keystore
57
70
            .insert(key_type, &secret_uri, &public.to_raw_vec())
58
70
            .unwrap();
59
14368
    }
60
14438
    public
61
14438
}
62

            
63
/// Helper function to generate an account ID from seed
64
6560
fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
65
6560
where
66
6560
    AccountPublic: From<<TPublic::Pair as Pair>::Public>,
67
6560
{
68
6560
    AccountPublic::from(get_from_seed::<TPublic>(seed, None)).into_account()
69
6560
}
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
1313
pub fn get_authority_keys_from_seed(seed: &str, keystore: Option<&KeystorePtr>) -> AuthorityKeys {
86
1313
    let keys = get_authority_keys_from_seed_no_beefy(seed, keystore);
87
1313

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

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

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

            
136
238
fn testnet_accounts() -> Vec<AccountId> {
137
238
    Vec::from([
138
238
        get_account_id_from_seed::<sr25519::Public>("Alice"),
139
238
        get_account_id_from_seed::<sr25519::Public>("Bob"),
140
238
        get_account_id_from_seed::<sr25519::Public>("Charlie"),
141
238
        get_account_id_from_seed::<sr25519::Public>("Dave"),
142
238
        get_account_id_from_seed::<sr25519::Public>("Eve"),
143
238
        get_account_id_from_seed::<sr25519::Public>("Ferdie"),
144
238
        get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
145
238
        get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
146
238
        get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
147
238
        get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
148
238
        get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
149
238
        get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
150
238
    ])
151
238
}
152

            
153
1106
fn dancelight_session_keys(
154
1106
    babe: BabeId,
155
1106
    grandpa: GrandpaId,
156
1106
    para_validator: ValidatorId,
157
1106
    para_assignment: AssignmentId,
158
1106
    authority_discovery: AuthorityDiscoveryId,
159
1106
    beefy: BeefyId,
160
1106
    nimbus: NimbusId,
161
1106
) -> SessionKeys {
162
1106
    SessionKeys {
163
1106
        babe,
164
1106
        grandpa,
165
1106
        para_validator,
166
1106
        para_assignment,
167
1106
        authority_discovery,
168
1106
        beefy,
169
1106
        nimbus,
170
1106
    }
171
1106
}
172

            
173
477
fn default_parachains_host_configuration(
174
477
) -> runtime_parachains::configuration::HostConfiguration<primitives::BlockNumber> {
175
    use primitives::{
176
        node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE,
177
    };
178

            
179
477
    runtime_parachains::configuration::HostConfiguration {
180
477
        validation_upgrade_cooldown: 2u32,
181
477
        validation_upgrade_delay: 2,
182
477
        code_retention_period: 1200,
183
477
        max_code_size: MAX_CODE_SIZE,
184
477
        max_pov_size: MAX_POV_SIZE,
185
477
        max_head_data_size: 32 * 1024,
186
477
        max_upward_queue_count: 8,
187
477
        max_upward_queue_size: 1024 * 1024,
188
477
        max_downward_message_size: 1024 * 1024,
189
477
        max_upward_message_size: 50 * 1024,
190
477
        max_upward_message_num_per_candidate: 5,
191
477
        hrmp_sender_deposit: 0,
192
477
        hrmp_recipient_deposit: 0,
193
477
        hrmp_channel_max_capacity: 8,
194
477
        hrmp_channel_max_total_size: 8 * 1024,
195
477
        hrmp_max_parachain_inbound_channels: 4,
196
477
        hrmp_channel_max_message_size: 1024 * 1024,
197
477
        hrmp_max_parachain_outbound_channels: 4,
198
477
        hrmp_max_message_num_per_candidate: 5,
199
477
        dispute_period: 6,
200
477
        no_show_slots: 2,
201
477
        n_delay_tranches: 25,
202
477
        needed_approvals: 2,
203
477
        relay_vrf_modulo_samples: 2,
204
477
        zeroth_delay_tranche_width: 0,
205
477
        minimum_validation_upgrade_delay: 5,
206
477
        async_backing_params: AsyncBackingParams {
207
477
            max_candidate_depth: 3,
208
477
            allowed_ancestry_len: 2,
209
477
        },
210
477
        node_features: bitvec::vec::BitVec::from_element(
211
477
            1u8 << (FeatureIndex::ElasticScalingMVP as usize),
212
477
        ),
213
477
        scheduler_params: SchedulerParams {
214
477
            lookahead: 2,
215
477
            group_rotation_frequency: 20,
216
477
            paras_availability_period: 4,
217
477
            ..Default::default()
218
477
        },
219
477
        ..Default::default()
220
477
    }
221
477
}
222

            
223
#[test]
224
1
fn default_parachains_host_configuration_is_consistent() {
225
1
    default_parachains_host_configuration().panic_if_not_consistent();
226
1
}
227

            
228
238
fn dancelight_testnet_genesis(
229
238
    initial_authorities: Vec<AuthorityKeys>,
230
238
    root_key: AccountId,
231
238
    endowed_accounts: Option<Vec<AccountId>>,
232
238
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
233
238
    invulnerables: Vec<String>,
234
238
    host_configuration: HostConfiguration,
235
238
) -> serde_json::Value {
236
238
    let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(testnet_accounts);
237
238
    let invulnerable_keys: Vec<_> = invulnerables
238
238
        .iter()
239
840
        .map(|seed| get_authority_keys_from_seed(seed, None))
240
238
        .collect();
241
238

            
242
238
    let invulnerable_accounts: Vec<_> = invulnerables
243
238
        .iter()
244
840
        .map(|seed| get_account_id_from_seed::<sr25519::Public>(seed))
245
238
        .collect();
246
238

            
247
238
    let data_preservers_bootnodes: Vec<_> = container_chains
248
238
        .iter()
249
476
        .flat_map(|(para_id, _genesis_data, bootnodes)| {
250
476
            bootnodes.clone().into_iter().map(|bootnode| {
251
                (
252
                    *para_id,
253
                    AccountId::from([0u8; 32]),
254
                    bootnode,
255
                    crate::PreserversAssignmentPaymentRequest::Free,
256
                    crate::PreserversAssignmentPaymentWitness::Free,
257
                )
258
476
            })
259
476
        })
260
238
        .collect();
261
238

            
262
238
    let para_ids: Vec<_> = container_chains
263
238
        .iter()
264
238
        .cloned()
265
476
        .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None))
266
238
        .collect();
267
238

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

            
291
476
            Some((
292
476
                para_id,
293
476
                (
294
476
                    genesis_args.genesis_head,
295
476
                    genesis_args.validation_code,
296
476
                    genesis_args.para_kind,
297
476
                ),
298
476
            ))
299
476
        })
300
238
        .collect();
301
238

            
302
238
    // Assign 1000 block credits to all container chains registered in genesis
303
238
    // Assign 100 collator assignment credits to all container chains registered in genesis
304
238
    let para_id_credits: Vec<_> = para_ids
305
238
        .iter()
306
476
        .map(|(para_id, _genesis_data, _boot_nodes)| (*para_id, 1000, 100).into())
307
238
        .collect();
308

            
309
    const ENDOWMENT: u128 = 1_000_000 * STAR;
310

            
311
238
    let core_percentage_for_pool_paras = Perbill::from_percent(100).saturating_sub(
312
238
        host_configuration
313
238
            .max_parachain_cores_percentage
314
238
            .unwrap_or(Perbill::from_percent(50)),
315
238
    );
316
238
    let num_cores =
317
238
        para_ids.len() as u32 + core_percentage_for_pool_paras.mul_ceil(para_ids.len() as u32);
318
238

            
319
238
    serde_json::json!({
320
238
        "balances": {
321
2856
            "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
322
238
        },
323
238
        "session": {
324
238
            "keys": initial_authorities
325
238
                .iter()
326
266
                .map(|x| {
327
266
                    (
328
266
                        x.stash.clone(),
329
266
                        x.stash.clone(),
330
266
                        dancelight_session_keys(
331
266
                            x.babe.clone(),
332
266
                            x.grandpa.clone(),
333
266
                            x.para_validator.clone(),
334
266
                            x.para_assignment.clone(),
335
266
                            x.authority_discovery.clone(),
336
266
                            x.beefy.clone(),
337
266
                            x.nimbus.clone(),
338
266
                        ),
339
266
                    )
340
266
                })
341
238
                .collect::<Vec<_>>(),
342
238
            "nonAuthorityKeys": invulnerable_keys
343
238
                .into_iter()
344
238
                .enumerate()
345
840
                .map(|(i, x)| {
346
840
                    (
347
840
                        invulnerable_accounts[i].clone(),
348
840
                        invulnerable_accounts[i].clone(),
349
840
                        dancelight_session_keys(
350
840
                            x.babe.clone(),
351
840
                            x.grandpa.clone(),
352
840
                            x.para_validator.clone(),
353
840
                            x.para_assignment.clone(),
354
840
                            x.authority_discovery.clone(),
355
840
                            x.beefy.clone(),
356
840
                            x.nimbus.clone(),
357
840
                        ),
358
840
                    )
359
840
                })
360
238
                .collect::<Vec<_>>(),
361
238
        },
362
238
        "babe": {
363
238
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG)
364
238
        },
365
238
        "sudo": { "key": Some(root_key.clone()) },
366
238
        "configuration": {
367
238
            "config": runtime_parachains::configuration::HostConfiguration {
368
238
                scheduler_params: SchedulerParams {
369
238
                    max_validators_per_core: Some(1),
370
238
                    num_cores,
371
238
                    ..default_parachains_host_configuration().scheduler_params
372
238
                },
373
238
                ..default_parachains_host_configuration()
374
238
            },
375
238
        },
376
238
        "registrar": {
377
238
            "nextFreeParaId": primitives::LOWEST_PUBLIC_ID,
378
238
        },
379
238
        "tanssiInvulnerables":  crate::TanssiInvulnerablesConfig {
380
238
            invulnerables: invulnerable_accounts,
381
238
        },
382
238
        "containerRegistrar": crate::ContainerRegistrarConfig { para_ids, ..Default::default() },
383
238
        "paras": {
384
238
            "paras": registrar_para_ids_info,
385
238
        },
386
238
        "servicesPayment": crate::ServicesPaymentConfig { para_id_credits },
387
238
            "dataPreservers": crate::DataPreserversConfig {
388
238
                bootnodes: data_preservers_bootnodes,
389
238
                ..Default::default()
390
238
        },
391
238
        "collatorConfiguration": crate::CollatorConfigurationConfig {
392
238
            config: host_configuration,
393
238
            ..Default::default()
394
238
        }
395
238
    })
396
238
}
397

            
398
// staging_testnet
399
fn dancelight_staging_testnet_config_genesis() -> serde_json::Value {
400
    use {hex_literal::hex, sp_core::crypto::UncheckedInto};
401

            
402
    // subkey inspect "$SECRET"
403
    let endowed_accounts = Vec::from([
404
        // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs
405
        hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(),
406
    ]);
407

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

            
601
    const ENDOWMENT: u128 = 1_000_000 * STAR;
602
    const STASH: u128 = 100 * STAR;
603

            
604
    serde_json::json!({
605
        "balances": {
606
            "balances": endowed_accounts
607
                .iter()
608
                .map(|k: &AccountId| (k.clone(), ENDOWMENT))
609
                .chain(initial_authorities.iter().map(|x| (x.stash.clone(), STASH)))
610
                .collect::<Vec<_>>(),
611
        },
612
        "session": {
613
            "keys": initial_authorities
614
                .into_iter()
615
                .map(|x| {
616
                    (
617
                        x.stash.clone(),
618
                        x.stash,
619
                        dancelight_session_keys(
620
                            x.babe,
621
                            x.grandpa,
622
                            x.para_validator,
623
                            x.para_assignment,
624
                            x.authority_discovery,
625
                            x.beefy,
626
                            x.nimbus,
627
                        ),
628
                    )
629
                })
630
                .collect::<Vec<_>>(),
631
        },
632
        "babe": {
633
            "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG),
634
        },
635
        "sudo": { "key": Some(endowed_accounts[0].clone()) },
636
        "configuration": {
637
            "config": default_parachains_host_configuration(),
638
        },
639
        "registrar": {
640
            "nextFreeParaId": primitives::LOWEST_PUBLIC_ID,
641
        },
642
    })
643
}
644

            
645
//development
646
210
pub fn dancelight_development_config_genesis(
647
210
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
648
210
    invulnerables: Vec<String>,
649
210
) -> serde_json::Value {
650
210
    dancelight_testnet_genesis(
651
210
        Vec::from([get_authority_keys_from_seed("Alice", None)]),
652
210
        get_account_id_from_seed::<sr25519::Public>("Alice"),
653
210
        None,
654
210
        container_chains,
655
210
        invulnerables,
656
210
        HostConfiguration {
657
210
            max_collators: 100u32,
658
210
            min_orchestrator_collators: 0u32,
659
210
            max_orchestrator_collators: 0u32,
660
210
            collators_per_container: 2u32,
661
210
            full_rotation_period: runtime_common::prod_or_fast!(24u32, 5u32),
662
210
            max_parachain_cores_percentage: Some(Perbill::from_percent(60)),
663
210
            ..Default::default()
664
210
        },
665
210
    )
666
210
}
667

            
668
//local_testnet
669
28
pub fn dancelight_local_testnet_genesis(
670
28
    container_chains: Vec<(ParaId, ContainerChainGenesisData, Vec<Vec<u8>>)>,
671
28
    invulnerables: Vec<String>,
672
28
) -> serde_json::Value {
673
28
    dancelight_testnet_genesis(
674
28
        Vec::from([
675
28
            get_authority_keys_from_seed("Alice", None),
676
28
            get_authority_keys_from_seed("Bob", None),
677
28
        ]),
678
28
        get_account_id_from_seed::<sr25519::Public>("Alice"),
679
28
        None,
680
28
        container_chains,
681
28
        invulnerables,
682
28
        HostConfiguration {
683
28
            max_collators: 100u32,
684
28
            min_orchestrator_collators: 0u32,
685
28
            max_orchestrator_collators: 0u32,
686
28
            collators_per_container: 2u32,
687
28
            full_rotation_period: runtime_common::prod_or_fast!(24u32, 5u32),
688
28
            max_parachain_cores_percentage: Some(Perbill::from_percent(60)),
689
28
            ..Default::default()
690
28
        },
691
28
    )
692
28
}
693

            
694
/// Provides the JSON representation of predefined genesis config for given `id`.
695
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
696
    let patch = match id.try_into() {
697
        Ok("local_testnet") => dancelight_local_testnet_genesis(vec![], vec![]),
698
        Ok("development") => dancelight_development_config_genesis(vec![], vec![]),
699
        Ok("staging_testnet") => dancelight_staging_testnet_config_genesis(),
700
        _ => return None,
701
    };
702
    Some(
703
        serde_json::to_string(&patch)
704
            .expect("serialization to json is expected to work. qed.")
705
            .into_bytes(),
706
    )
707
}