referrerpolicy=no-referrer-when-downgrade

polkadot_service/
chain_spec.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot 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// Polkadot 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 Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Polkadot chain configurations.
18
19#[cfg(feature = "rococo-native")]
20use rococo_runtime as rococo;
21use sc_chain_spec::ChainSpecExtension;
22#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
23use sc_chain_spec::ChainType;
24#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
25use sc_telemetry::TelemetryEndpoints;
26use serde::{Deserialize, Serialize};
27#[cfg(feature = "westend-native")]
28use westend_runtime as westend;
29
30#[cfg(feature = "westend-native")]
31const WESTEND_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
32#[cfg(feature = "rococo-native")]
33const ROCOCO_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
34#[cfg(feature = "rococo-native")]
35const VERSI_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
36#[cfg(any(feature = "westend-native", feature = "rococo-native"))]
37const DEFAULT_PROTOCOL_ID: &str = "dot";
38
39/// Node `ChainSpec` extensions.
40///
41/// Additional parameters for some Substrate core modules,
42/// customizable from the chain spec.
43#[derive(Default, Clone, Serialize, Deserialize, ChainSpecExtension)]
44#[serde(rename_all = "camelCase")]
45pub struct Extensions {
46	/// Block numbers with known hashes.
47	pub fork_blocks: sc_client_api::ForkBlocks<polkadot_primitives::Block>,
48	/// Known bad block hashes.
49	pub bad_blocks: sc_client_api::BadBlocks<polkadot_primitives::Block>,
50	/// The light sync state.
51	///
52	/// This value will be set by the `sync-state rpc` implementation.
53	pub light_sync_state: sc_sync_state_rpc::LightSyncStateExtension,
54}
55
56// Generic chain spec, in case when we don't have the native runtime.
57pub type GenericChainSpec = sc_service::GenericChainSpec<Extensions>;
58
59/// The `ChainSpec` parameterized for the westend runtime.
60#[cfg(feature = "westend-native")]
61pub type WestendChainSpec = sc_service::GenericChainSpec<Extensions>;
62
63/// The `ChainSpec` parameterized for the westend runtime.
64// Dummy chain spec, but that is fine when we don't have the native runtime.
65#[cfg(not(feature = "westend-native"))]
66pub type WestendChainSpec = GenericChainSpec;
67
68/// The `ChainSpec` parameterized for the rococo runtime.
69#[cfg(feature = "rococo-native")]
70pub type RococoChainSpec = sc_service::GenericChainSpec<Extensions>;
71
72/// The `ChainSpec` parameterized for the rococo runtime.
73// Dummy chain spec, but that is fine when we don't have the native runtime.
74#[cfg(not(feature = "rococo-native"))]
75pub type RococoChainSpec = GenericChainSpec;
76
77pub fn polkadot_config() -> Result<GenericChainSpec, String> {
78	GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..])
79}
80
81pub fn kusama_config() -> Result<GenericChainSpec, String> {
82	GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/kusama.json")[..])
83}
84
85pub fn westend_config() -> Result<WestendChainSpec, String> {
86	WestendChainSpec::from_json_bytes(&include_bytes!("../chain-specs/westend.json")[..])
87}
88
89pub fn paseo_config() -> Result<GenericChainSpec, String> {
90	GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/paseo.json")[..])
91}
92
93pub fn rococo_config() -> Result<RococoChainSpec, String> {
94	RococoChainSpec::from_json_bytes(&include_bytes!("../chain-specs/rococo.json")[..])
95}
96
97/// Westend staging testnet config.
98#[cfg(feature = "westend-native")]
99pub fn westend_staging_testnet_config() -> Result<WestendChainSpec, String> {
100	Ok(WestendChainSpec::builder(
101		westend::WASM_BINARY.ok_or("Westend development wasm not available")?,
102		Default::default(),
103	)
104	.with_name("Westend Staging Testnet")
105	.with_id("westend_staging_testnet")
106	.with_chain_type(ChainType::Live)
107	.with_genesis_config_preset_name("staging_testnet")
108	.with_telemetry_endpoints(
109		TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)])
110			.expect("Westend Staging telemetry url is valid; qed"),
111	)
112	.with_protocol_id(DEFAULT_PROTOCOL_ID)
113	.build())
114}
115
116/// Rococo staging testnet config.
117#[cfg(feature = "rococo-native")]
118pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
119	Ok(RococoChainSpec::builder(
120		rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?,
121		Default::default(),
122	)
123	.with_name("Rococo Staging Testnet")
124	.with_id("rococo_staging_testnet")
125	.with_chain_type(ChainType::Live)
126	.with_genesis_config_preset_name("staging_testnet")
127	.with_telemetry_endpoints(
128		TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)])
129			.expect("Rococo Staging telemetry url is valid; qed"),
130	)
131	.with_protocol_id(DEFAULT_PROTOCOL_ID)
132	.build())
133}
134
135pub fn versi_chain_spec_properties() -> serde_json::map::Map<String, serde_json::Value> {
136	serde_json::json!({
137		"ss58Format": 42,
138		"tokenDecimals": 12,
139		"tokenSymbol": "VRS",
140	})
141	.as_object()
142	.expect("Map given; qed")
143	.clone()
144}
145
146/// Versi staging testnet config.
147#[cfg(feature = "rococo-native")]
148pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
149	Ok(RococoChainSpec::builder(
150		rococo::WASM_BINARY.ok_or("Versi development wasm not available")?,
151		Default::default(),
152	)
153	.with_name("Versi Staging Testnet")
154	.with_id("versi_staging_testnet")
155	.with_chain_type(ChainType::Live)
156	.with_genesis_config_preset_name("staging_testnet")
157	.with_telemetry_endpoints(
158		TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)])
159			.expect("Versi Staging telemetry url is valid; qed"),
160	)
161	.with_protocol_id("versi")
162	.with_properties(versi_chain_spec_properties())
163	.build())
164}
165
166/// Westend development config (single validator Alice)
167#[cfg(feature = "westend-native")]
168pub fn westend_development_config() -> Result<WestendChainSpec, String> {
169	Ok(WestendChainSpec::builder(
170		westend::WASM_BINARY.ok_or("Westend development wasm not available")?,
171		Default::default(),
172	)
173	.with_name("Development")
174	.with_id("westend_dev")
175	.with_chain_type(ChainType::Development)
176	.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
177	.with_protocol_id(DEFAULT_PROTOCOL_ID)
178	.build())
179}
180
181/// Rococo development config (single validator Alice)
182#[cfg(feature = "rococo-native")]
183pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
184	Ok(RococoChainSpec::builder(
185		rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?,
186		Default::default(),
187	)
188	.with_name("Development")
189	.with_id("rococo_dev")
190	.with_chain_type(ChainType::Development)
191	.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
192	.with_protocol_id(DEFAULT_PROTOCOL_ID)
193	.build())
194}
195
196/// `Versi` development config (single validator Alice)
197#[cfg(feature = "rococo-native")]
198pub fn versi_development_config() -> Result<RococoChainSpec, String> {
199	Ok(RococoChainSpec::builder(
200		rococo::WASM_BINARY.ok_or("Versi development wasm not available")?,
201		Default::default(),
202	)
203	.with_name("Development")
204	.with_id("versi_dev")
205	.with_chain_type(ChainType::Development)
206	.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
207	.with_protocol_id("versi")
208	.build())
209}
210
211/// Westend local testnet config (multivalidator Alice + Bob)
212#[cfg(feature = "westend-native")]
213pub fn westend_local_testnet_config() -> Result<WestendChainSpec, String> {
214	Ok(WestendChainSpec::builder(
215		westend::fast_runtime_binary::WASM_BINARY
216			.ok_or("Westend development wasm not available")?,
217		Default::default(),
218	)
219	.with_name("Westend Local Testnet")
220	.with_id("westend_local_testnet")
221	.with_chain_type(ChainType::Local)
222	.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
223	.with_protocol_id(DEFAULT_PROTOCOL_ID)
224	.build())
225}
226
227/// Rococo local testnet config (multivalidator Alice + Bob)
228#[cfg(feature = "rococo-native")]
229pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
230	Ok(RococoChainSpec::builder(
231		rococo::fast_runtime_binary::WASM_BINARY.ok_or("Rococo development wasm not available")?,
232		Default::default(),
233	)
234	.with_name("Rococo Local Testnet")
235	.with_id("rococo_local_testnet")
236	.with_chain_type(ChainType::Local)
237	.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
238	.with_protocol_id(DEFAULT_PROTOCOL_ID)
239	.build())
240}
241
242/// `Versi` local testnet config (multivalidator Alice + Bob + Charlie + Dave)
243#[cfg(feature = "rococo-native")]
244pub fn versi_local_testnet_config() -> Result<RococoChainSpec, String> {
245	Ok(RococoChainSpec::builder(
246		rococo::WASM_BINARY.ok_or("Rococo development wasm (used for versi) not available")?,
247		Default::default(),
248	)
249	.with_name("Versi Local Testnet")
250	.with_id("versi_local_testnet")
251	.with_chain_type(ChainType::Local)
252	.with_genesis_config_preset_name("versi_local_testnet")
253	.with_protocol_id("versi")
254	.build())
255}