Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polkadot-parachain: one chain-spec for all #2457

Merged
merged 7 commits into from
Nov 25, 2023
Merged
65 changes: 28 additions & 37 deletions cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,15 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::chain_spec::{
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION,
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec,
SAFE_XCM_VERSION,
};
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance as AssetHubBalance};
use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type AssetHubPolkadotChainSpec =
sc_service::GenericChainSpec<asset_hub_polkadot_runtime::RuntimeGenesisConfig, Extensions>;
pub type AssetHubKusamaChainSpec =
sc_service::GenericChainSpec<asset_hub_kusama_runtime::RuntimeGenesisConfig, Extensions>;
pub type AssetHubWestendChainSpec =
sc_service::GenericChainSpec<asset_hub_westend_runtime::RuntimeGenesisConfig, Extensions>;
pub type AssetHubRococoChainSpec =
sc_service::GenericChainSpec<asset_hub_rococo_runtime::RuntimeGenesisConfig, Extensions>;

const ASSET_HUB_POLKADOT_ED: AssetHubBalance =
parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT;
const ASSET_HUB_KUSAMA_ED: AssetHubBalance =
Expand Down Expand Up @@ -72,13 +63,13 @@ pub fn asset_hub_westend_session_keys(keys: AuraId) -> asset_hub_westend_runtime
asset_hub_westend_runtime::SessionKeys { aura: keys }
}

pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec {
pub fn asset_hub_polkadot_development_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());

AssetHubPolkadotChainSpec::builder(
GenericChainSpec::builder(
asset_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 },
Expand All @@ -104,13 +95,13 @@ pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec {
.build()
}

pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec {
pub fn asset_hub_polkadot_local_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());

AssetHubPolkadotChainSpec::builder(
GenericChainSpec::builder(
asset_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 },
Expand Down Expand Up @@ -152,13 +143,13 @@ pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec {
}

// Not used for syncing, but just to determine the genesis values set for the upgrade from shell.
pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec {
pub fn asset_hub_polkadot_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());

AssetHubPolkadotChainSpec::builder(
GenericChainSpec::builder(
asset_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "polkadot".into(), para_id: 1000 },
Expand Down Expand Up @@ -249,13 +240,13 @@ fn asset_hub_polkadot_genesis(
})
}

pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec {
pub fn asset_hub_kusama_development_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 2.into());
properties.insert("tokenSymbol".into(), "KSM".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubKusamaChainSpec::builder(
GenericChainSpec::builder(
asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 },
)
Expand All @@ -280,13 +271,13 @@ pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec {
.build()
}

pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec {
pub fn asset_hub_kusama_local_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 2.into());
properties.insert("tokenSymbol".into(), "KSM".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubKusamaChainSpec::builder(
GenericChainSpec::builder(
asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "kusama-local".into(), para_id: 1000 },
)
Expand Down Expand Up @@ -325,13 +316,13 @@ pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec {
.build()
}

pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec {
pub fn asset_hub_kusama_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 2.into());
properties.insert("tokenSymbol".into(), "KSM".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubKusamaChainSpec::builder(
GenericChainSpec::builder(
asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "kusama".into(), para_id: 1000 },
)
Expand Down Expand Up @@ -407,12 +398,12 @@ fn asset_hub_kusama_genesis(
})
}

pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec {
pub fn asset_hub_westend_development_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubWestendChainSpec::builder(
GenericChainSpec::builder(
asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend".into(), para_id: 1000 },
Expand All @@ -439,12 +430,12 @@ pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec {
.build()
}

pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec {
pub fn asset_hub_westend_local_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubWestendChainSpec::builder(
GenericChainSpec::builder(
asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend-local".into(), para_id: 1000 },
Expand Down Expand Up @@ -485,12 +476,12 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec {
.build()
}

pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec {
pub fn asset_hub_westend_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubWestendChainSpec::builder(
GenericChainSpec::builder(
asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend".into(), para_id: 1000 },
Expand Down Expand Up @@ -569,7 +560,7 @@ fn asset_hub_westend_genesis(
})
}

pub fn asset_hub_rococo_development_config() -> AssetHubRococoChainSpec {
pub fn asset_hub_rococo_development_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
properties.insert("tokenSymbol".into(), "ROC".into());
Expand All @@ -587,8 +578,8 @@ fn asset_hub_rococo_like_development_config(
name: &str,
chain_id: &str,
para_id: u32,
) -> AssetHubRococoChainSpec {
AssetHubRococoChainSpec::builder(
) -> GenericChainSpec {
GenericChainSpec::builder(
asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "rococo-dev".into(), para_id },
)
Expand All @@ -614,7 +605,7 @@ fn asset_hub_rococo_like_development_config(
.build()
}

pub fn asset_hub_rococo_local_config() -> AssetHubRococoChainSpec {
pub fn asset_hub_rococo_local_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
properties.insert("tokenSymbol".into(), "ROC".into());
Expand All @@ -632,8 +623,8 @@ fn asset_hub_rococo_like_local_config(
name: &str,
chain_id: &str,
para_id: u32,
) -> AssetHubRococoChainSpec {
AssetHubRococoChainSpec::builder(
) -> GenericChainSpec {
GenericChainSpec::builder(
asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "rococo-local".into(), para_id },
)
Expand Down Expand Up @@ -673,12 +664,12 @@ fn asset_hub_rococo_like_local_config(
.build()
}

pub fn asset_hub_rococo_genesis_config() -> AssetHubRococoChainSpec {
pub fn asset_hub_rococo_genesis_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "ROC".into());
properties.insert("tokenDecimals".into(), 12.into());
let para_id = 1000;
AssetHubRococoChainSpec::builder(
GenericChainSpec::builder(
asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "rococo".into(), para_id },
)
Expand Down
43 changes: 11 additions & 32 deletions cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cumulus_primitives_core::ParaId;
use parachains_common::Balance as BridgeHubBalance;
use sc_chain_spec::ChainSpec;
use sp_core::sr25519;
use std::{path::PathBuf, str::FromStr};
use std::str::FromStr;

/// Collects all supported BridgeHub configurations
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -71,27 +71,6 @@ impl FromStr for BridgeHubRuntimeType {
impl BridgeHubRuntimeType {
pub const ID_PREFIX: &'static str = "bridge-hub";

pub fn chain_spec_from_json_file(&self, path: PathBuf) -> Result<Box<dyn ChainSpec>, String> {
match self {
BridgeHubRuntimeType::Polkadot |
BridgeHubRuntimeType::PolkadotLocal |
BridgeHubRuntimeType::PolkadotDevelopment =>
Ok(Box::new(polkadot::BridgeHubChainSpec::from_json_file(path)?)),
BridgeHubRuntimeType::Kusama |
BridgeHubRuntimeType::KusamaLocal |
BridgeHubRuntimeType::KusamaDevelopment =>
Ok(Box::new(kusama::BridgeHubChainSpec::from_json_file(path)?)),
BridgeHubRuntimeType::Westend |
BridgeHubRuntimeType::WestendLocal |
BridgeHubRuntimeType::WestendDevelopment =>
Ok(Box::new(westend::BridgeHubChainSpec::from_json_file(path)?)),
BridgeHubRuntimeType::Rococo |
BridgeHubRuntimeType::RococoLocal |
BridgeHubRuntimeType::RococoDevelopment =>
Ok(Box::new(rococo::BridgeHubChainSpec::from_json_file(path)?)),
}
}

pub fn load_config(&self) -> Result<Box<dyn ChainSpec>, String> {
match self {
BridgeHubRuntimeType::Polkadot =>
Expand Down Expand Up @@ -184,7 +163,7 @@ fn ensure_id(id: &str) -> Result<&str, String> {
/// Sub-module for Rococo setup
pub mod rococo {
use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId};
use crate::chain_spec::{Extensions, SAFE_XCM_VERSION};
use crate::chain_spec::{Extensions, GenericChainSpec, SAFE_XCM_VERSION};
use parachains_common::{AccountId, AuraId};
use sc_chain_spec::ChainType;

Expand All @@ -197,8 +176,7 @@ pub mod rococo {
parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>;

pub type BridgeHubChainSpec = GenericChainSpec;
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
pub type RuntimeApi = bridge_hub_rococo_runtime::RuntimeApi;

pub fn local_config<ModifyProperties: Fn(&mut sc_chain_spec::Properties)>(
Expand Down Expand Up @@ -305,7 +283,8 @@ pub mod rococo {
pub mod kusama {
use super::{BridgeHubBalance, ParaId};
use crate::chain_spec::{
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION,
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec,
SAFE_XCM_VERSION,
};
use parachains_common::{AccountId, AuraId};
use sc_chain_spec::ChainType;
Expand All @@ -318,7 +297,7 @@ pub mod kusama {
parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>;
pub type BridgeHubChainSpec = GenericChainSpec;
pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi;

pub fn local_config(
Expand Down Expand Up @@ -414,7 +393,7 @@ pub mod kusama {
/// Sub-module for Westend setup.
pub mod westend {
use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId};
use crate::chain_spec::{Extensions, SAFE_XCM_VERSION};
use crate::chain_spec::{Extensions, GenericChainSpec, SAFE_XCM_VERSION};
use parachains_common::{AccountId, AuraId};
use sc_chain_spec::ChainType;

Expand All @@ -427,8 +406,7 @@ pub mod westend {
parachains_common::westend::currency::EXISTENTIAL_DEPOSIT;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type BridgeHubChainSpec =
sc_service::GenericChainSpec<bridge_hub_westend_runtime::RuntimeGenesisConfig, Extensions>;
pub type BridgeHubChainSpec = GenericChainSpec;
pub type RuntimeApi = bridge_hub_westend_runtime::RuntimeApi;

pub fn local_config(
Expand Down Expand Up @@ -531,7 +509,8 @@ pub mod westend {
pub mod polkadot {
use super::{BridgeHubBalance, ParaId};
use crate::chain_spec::{
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION,
get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec,
SAFE_XCM_VERSION,
};
use parachains_common::{AccountId, AuraId};
use sc_chain_spec::ChainType;
Expand All @@ -544,7 +523,7 @@ pub mod polkadot {
parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>;
pub type BridgeHubChainSpec = GenericChainSpec;
pub type RuntimeApi = bridge_hub_polkadot_runtime::RuntimeApi;

pub fn local_config(
Expand Down
Loading
Loading