|
| 1 | +// KILT Blockchain – https://botlabs.org |
| 2 | +// Copyright (C) 2019-2022 BOTLabs GmbH |
| 3 | + |
| 4 | +// The KILT Blockchain 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 | +// The KILT Blockchain 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 this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +// If you feel like getting in touch with us, you can do so at [email protected] |
| 18 | + |
| 19 | +//! KILT chain specification |
| 20 | +
|
| 21 | +use clone_runtime::{ |
| 22 | + BalancesConfig, CollatorSelectionConfig, GenesisConfig, ParachainInfoConfig, PolkadotXcmConfig, SessionConfig, |
| 23 | + SudoConfig, SystemConfig, WASM_BINARY, |
| 24 | +}; |
| 25 | +use cumulus_primitives_core::ParaId; |
| 26 | +use hex_literal::hex; |
| 27 | +use runtime_common::{ |
| 28 | + constants::{staking::MinCollatorStake, KILT}, |
| 29 | + AccountId, AuthorityId, Balance, |
| 30 | +}; |
| 31 | +use sc_service::ChainType; |
| 32 | +use sc_telemetry::TelemetryEndpoints; |
| 33 | +use sp_core::{crypto::UncheckedInto, sr25519}; |
| 34 | + |
| 35 | +use crate::chain_spec::{get_account_id_from_seed, get_from_seed, DEFAULT_PARA_ID, TELEMETRY_URL}; |
| 36 | + |
| 37 | +use super::{get_properties, Extensions}; |
| 38 | + |
| 39 | +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; |
| 40 | + |
| 41 | +/// Specialized `ChainSpec` for the normal parachain runtime. |
| 42 | +pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>; |
| 43 | + |
| 44 | +pub fn get_chain_spec_dev() -> Result<ChainSpec, String> { |
| 45 | + let properties = get_properties("KILT", 15, 38); |
| 46 | + let wasm = WASM_BINARY.ok_or("No WASM")?; |
| 47 | + |
| 48 | + Ok(ChainSpec::from_genesis( |
| 49 | + "KILT clone Develop", |
| 50 | + "cln_kilt_dev", |
| 51 | + ChainType::Local, |
| 52 | + move || { |
| 53 | + testnet_genesis( |
| 54 | + wasm, |
| 55 | + vec![ |
| 56 | + ( |
| 57 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 58 | + None, |
| 59 | + 2 * MinCollatorStake::get(), |
| 60 | + ), |
| 61 | + ( |
| 62 | + get_account_id_from_seed::<sr25519::Public>("Bob"), |
| 63 | + None, |
| 64 | + 2 * MinCollatorStake::get(), |
| 65 | + ), |
| 66 | + ], |
| 67 | + vec![ |
| 68 | + ( |
| 69 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 70 | + get_from_seed::<AuthorityId>("Alice"), |
| 71 | + ), |
| 72 | + ( |
| 73 | + get_account_id_from_seed::<sr25519::Public>("Bob"), |
| 74 | + get_from_seed::<AuthorityId>("Bob"), |
| 75 | + ), |
| 76 | + ], |
| 77 | + vec![ |
| 78 | + (get_account_id_from_seed::<sr25519::Public>("Alice"), 10000000 * KILT), |
| 79 | + (get_account_id_from_seed::<sr25519::Public>("Bob"), 10000000 * KILT), |
| 80 | + (get_account_id_from_seed::<sr25519::Public>("Charlie"), 10000000 * KILT), |
| 81 | + (get_account_id_from_seed::<sr25519::Public>("Dave"), 10000000 * KILT), |
| 82 | + (get_account_id_from_seed::<sr25519::Public>("Eve"), 10000000 * KILT), |
| 83 | + (get_account_id_from_seed::<sr25519::Public>("Ferdie"), 10000000 * KILT), |
| 84 | + ( |
| 85 | + get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
| 86 | + 10000000 * KILT, |
| 87 | + ), |
| 88 | + ( |
| 89 | + get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
| 90 | + 10000000 * KILT, |
| 91 | + ), |
| 92 | + ( |
| 93 | + get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), |
| 94 | + 10000000 * KILT, |
| 95 | + ), |
| 96 | + ( |
| 97 | + get_account_id_from_seed::<sr25519::Public>("Dave//stash"), |
| 98 | + 10000000 * KILT, |
| 99 | + ), |
| 100 | + ( |
| 101 | + get_account_id_from_seed::<sr25519::Public>("Eve//stash"), |
| 102 | + 10000000 * KILT, |
| 103 | + ), |
| 104 | + ( |
| 105 | + get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), |
| 106 | + 10000000 * KILT, |
| 107 | + ), |
| 108 | + ], |
| 109 | + get_account_id_from_seed::<sr25519::Public>("Alice"), |
| 110 | + DEFAULT_PARA_ID, |
| 111 | + ) |
| 112 | + }, |
| 113 | + vec![], |
| 114 | + None, |
| 115 | + None, |
| 116 | + None, |
| 117 | + Some(properties), |
| 118 | + Extensions { |
| 119 | + relay_chain: "rococo_local_testnet".into(), |
| 120 | + para_id: DEFAULT_PARA_ID.into(), |
| 121 | + }, |
| 122 | + )) |
| 123 | +} |
| 124 | + |
| 125 | +const CLN_SUDO: [u8; 32] = hex!["14ab94d42fb790854e7c4813af55722e2007ce2070177bbe93d64cabe5f6ca6f"]; |
| 126 | +const CLN_COL_ACC_1: [u8; 32] = hex!["d8f775301891bc245f2cbf2d64cf1c0e64d16632c02268fd2199c84b09ff7f7b"]; |
| 127 | +const CLN_COL_SESSION_1: [u8; 32] = hex!["88245cdf5b5b517c48b0057e17c94c7ff71eeb7ba4665b3d07accdc0c3064915"]; |
| 128 | +const CLN_COL_ACC_2: [u8; 32] = hex!["5c7c70470cb16b4702921f0b4e2a7109277354bd3d8e11b63bd7ed70510cf57f"]; |
| 129 | +const CLN_COL_SESSION_2: [u8; 32] = hex!["487cf837b45261c45c45a38e66be1fb80dc7d755094b44661632ec30d3a5db01"]; |
| 130 | + |
| 131 | +pub fn get_chain_spec_cln() -> Result<ChainSpec, String> { |
| 132 | + let properties = get_properties("KILT", 15, 38); |
| 133 | + let wasm = WASM_BINARY.ok_or("No WASM")?; |
| 134 | + let id: ParaId = 2057.into(); |
| 135 | + |
| 136 | + Ok(ChainSpec::from_genesis( |
| 137 | + "KILT", |
| 138 | + "cln_kilt", |
| 139 | + ChainType::Live, |
| 140 | + move || { |
| 141 | + testnet_genesis( |
| 142 | + wasm, |
| 143 | + vec![ |
| 144 | + (CLN_COL_ACC_1.into(), None, 30000 * KILT), |
| 145 | + (CLN_COL_ACC_2.into(), None, 30000 * KILT), |
| 146 | + ], |
| 147 | + vec![ |
| 148 | + (CLN_COL_ACC_1.into(), CLN_COL_SESSION_1.unchecked_into()), |
| 149 | + (CLN_COL_ACC_2.into(), CLN_COL_SESSION_2.unchecked_into()), |
| 150 | + ], |
| 151 | + vec![ |
| 152 | + (CLN_COL_ACC_1.into(), 40000 * KILT), |
| 153 | + (CLN_COL_ACC_2.into(), 40000 * KILT), |
| 154 | + ], |
| 155 | + CLN_SUDO.into(), |
| 156 | + id, |
| 157 | + ) |
| 158 | + }, |
| 159 | + vec![ |
| 160 | + "/dns4/bootnode.kilt.io/tcp/30360/p2p/12D3KooWAyk4ZQe4RU7A6H8hFLjQGsXyNPTbfYW1qE2Atd4p8fN8" |
| 161 | + .parse() |
| 162 | + .expect("bootnode address is formatted correctly; qed"), |
| 163 | + "/dns4/bootnode.kilt.io/tcp/30361/p2p/12D3KooWHootMhedfGJAHWu8Bn8DVjmMLA8qnSP4jKJr7u27sU6w" |
| 164 | + .parse() |
| 165 | + .expect("bootnode address is formatted correctly; qed"), |
| 166 | + ], |
| 167 | + Some(TelemetryEndpoints::new(vec![(TELEMETRY_URL.to_string(), 0)]).expect("telemetry url is valid; qed")), |
| 168 | + None, |
| 169 | + None, |
| 170 | + Some(properties), |
| 171 | + Extensions { |
| 172 | + relay_chain: "polkadot".into(), |
| 173 | + para_id: id.into(), |
| 174 | + }, |
| 175 | + )) |
| 176 | +} |
| 177 | + |
| 178 | +pub fn load_clone_spec() -> Result<ChainSpec, String> { |
| 179 | + ChainSpec::from_json_bytes(&include_bytes!("../../res/clone.json")[..]) |
| 180 | +} |
| 181 | + |
| 182 | +#[allow(clippy::too_many_arguments)] |
| 183 | +fn testnet_genesis( |
| 184 | + wasm_binary: &[u8], |
| 185 | + stakers: Vec<(AccountId, Option<AccountId>, Balance)>, |
| 186 | + initial_authorities: Vec<(AccountId, AuthorityId)>, |
| 187 | + endowed_accounts: Vec<(AccountId, Balance)>, |
| 188 | + sudo: AccountId, |
| 189 | + id: ParaId, |
| 190 | +) -> GenesisConfig { |
| 191 | + GenesisConfig { |
| 192 | + system: SystemConfig { |
| 193 | + code: wasm_binary.to_vec(), |
| 194 | + }, |
| 195 | + balances: BalancesConfig { |
| 196 | + balances: endowed_accounts.iter().cloned().collect(), |
| 197 | + }, |
| 198 | + parachain_info: ParachainInfoConfig { parachain_id: id }, |
| 199 | + aura: Default::default(), |
| 200 | + aura_ext: Default::default(), |
| 201 | + parachain_system: Default::default(), |
| 202 | + collator_selection: CollatorSelectionConfig { |
| 203 | + invulnerables: stakers.iter().map(|(acc, _, _)| acc).cloned().collect(), |
| 204 | + candidacy_bond: MinCollatorStake::get(), |
| 205 | + desired_candidates: 2, |
| 206 | + }, |
| 207 | + session: SessionConfig { |
| 208 | + keys: initial_authorities |
| 209 | + .iter() |
| 210 | + .map(|(acc, key)| { |
| 211 | + ( |
| 212 | + acc.clone(), |
| 213 | + acc.clone(), |
| 214 | + clone_runtime::SessionKeys { aura: key.clone() }, |
| 215 | + ) |
| 216 | + }) |
| 217 | + .collect::<Vec<_>>(), |
| 218 | + }, |
| 219 | + sudo: SudoConfig { key: Some(sudo) }, |
| 220 | + polkadot_xcm: PolkadotXcmConfig { |
| 221 | + safe_xcm_version: Some(SAFE_XCM_VERSION), |
| 222 | + }, |
| 223 | + } |
| 224 | +} |
0 commit comments