referrerpolicy=no-referrer-when-downgrade

bridge_hub_westend_runtime/
genesis_config_presets.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! # Bridge Hub Westend Runtime genesis config presets
17
18use crate::*;
19use alloc::{vec, vec::Vec};
20use cumulus_primitives_core::ParaId;
21use frame_support::build_struct_json_patch;
22use parachains_common::{AccountId, AuraId};
23use sp_genesis_builder::PresetId;
24use sp_keyring::Sr25519Keyring;
25use testnet_parachains_constants::westend::xcm_version::SAFE_XCM_VERSION;
26use xcm::latest::ROCOCO_GENESIS_HASH;
27
28const BRIDGE_HUB_WESTEND_ED: Balance = ExistentialDeposit::get();
29
30fn bridge_hub_westend_genesis(
31	invulnerables: Vec<(AccountId, AuraId)>,
32	endowed_accounts: Vec<AccountId>,
33	id: ParaId,
34	bridges_pallet_owner: Option<AccountId>,
35	asset_hub_para_id: ParaId,
36	opened_bridges: Vec<(Location, InteriorLocation, Option<bp_messages::LegacyLaneId>)>,
37) -> serde_json::Value {
38	build_struct_json_patch!(RuntimeGenesisConfig {
39		balances: BalancesConfig {
40			balances: endowed_accounts
41				.iter()
42				.cloned()
43				.map(|k| (k, 1u128 << 60))
44				.collect::<Vec<_>>(),
45		},
46		parachain_info: ParachainInfoConfig { parachain_id: id },
47		collator_selection: CollatorSelectionConfig {
48			invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
49			candidacy_bond: BRIDGE_HUB_WESTEND_ED * 16,
50		},
51		session: SessionConfig {
52			keys: invulnerables
53				.into_iter()
54				.map(|(acc, aura)| {
55					(
56						acc.clone(),          // account id
57						acc,                  // validator id
58						SessionKeys { aura }, // session keys
59					)
60				})
61				.collect(),
62		},
63		polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
64		bridge_rococo_grandpa: BridgeRococoGrandpaConfig { owner: bridges_pallet_owner.clone() },
65		bridge_rococo_messages: BridgeRococoMessagesConfig { owner: bridges_pallet_owner.clone() },
66		xcm_over_bridge_hub_rococo: XcmOverBridgeHubRococoConfig { opened_bridges },
67		ethereum_system: EthereumSystemConfig { para_id: id, asset_hub_para_id },
68	})
69}
70
71/// Provides the JSON representation of predefined genesis config for given `id`.
72pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
73	let patch = match id.as_ref() {
74		sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => bridge_hub_westend_genesis(
75			// initial collators.
76			vec![
77				(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
78				(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
79			],
80			Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
81			1002.into(),
82			Some(Sr25519Keyring::Bob.to_account_id()),
83			westend_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
84			vec![(
85				Location::new(1, [Parachain(1000)]),
86				Junctions::from([
87					NetworkId::ByGenesis(ROCOCO_GENESIS_HASH).into(),
88					Parachain(1000),
89				]),
90				Some(bp_messages::LegacyLaneId([0, 0, 0, 2])),
91			)],
92		),
93		sp_genesis_builder::DEV_RUNTIME_PRESET => bridge_hub_westend_genesis(
94			// initial collators.
95			vec![
96				(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
97				(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
98			],
99			Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
100			1002.into(),
101			Some(Sr25519Keyring::Bob.to_account_id()),
102			westend_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
103			vec![],
104		),
105		_ => return None,
106	};
107	Some(
108		serde_json::to_string(&patch)
109			.expect("serialization to json is expected to work. qed.")
110			.into_bytes(),
111	)
112}
113
114/// List of supported presets.
115pub fn preset_names() -> Vec<PresetId> {
116	vec![
117		PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
118		PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
119	]
120}