Skip to content

Commit

Permalink
[parachain-bin] revert unnecessary chain-spec changes
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Feb 5, 2025
1 parent 2ce767d commit 2aa136a
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 72 deletions.
271 changes: 212 additions & 59 deletions cumulus/polkadot-parachain/src/chain_spec/coretime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,230 @@

use cumulus_primitives_core::ParaId;
use polkadot_omni_node_lib::chain_spec::GenericChainSpec;
use sc_chain_spec::{ChainType, GenericChainSpec};
use sc_chain_spec::{ChainSpec, ChainType};
use std::{borrow::Cow, str::FromStr};

pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005);
/// Collects all supported Coretime configurations.
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum CoretimeRuntimeType {
Kusama,
KusamaLocal,

pub fn coretime_westend_development_config() -> GenericChainSpec {
GenericChainSpec::builder(
coretime_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend".into(), para_id: CORETIME_PARA_ID },
)
.with_name("Westend Coretime Development")
.with_id("coretime-westend-dev")
.with_chain_type(ChainType::Local)
.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
.with_properties(westend_properties())
.build()
Polkadot,
PolkadotLocal,

// Live
Rococo,
// Local
RococoLocal,
// Benchmarks
RococoDevelopment,

// Live
Westend,
// Local
WestendLocal,
// Benchmarks
WestendDevelopment,
}

pub fn coretime_westend_local_config() -> GenericChainSpec {
GenericChainSpec::builder(
coretime_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend-local".into(), para_id: CORETIME_PARA_ID },
)
.with_name("Westend Coretime Local")
.with_id("coretime-westend-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
.with_properties(westend_properties())
.build()
impl FromStr for CoretimeRuntimeType {
type Err = String;

fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
kusama::CORETIME_KUSAMA => Ok(CoretimeRuntimeType::Kusama),
kusama::CORETIME_KUSAMA_LOCAL => Ok(CoretimeRuntimeType::KusamaLocal),
polkadot::CORETIME_POLKADOT => Ok(CoretimeRuntimeType::Polkadot),
polkadot::CORETIME_POLKADOT_LOCAL => Ok(CoretimeRuntimeType::PolkadotLocal),
rococo::CORETIME_ROCOCO => Ok(CoretimeRuntimeType::Rococo),
rococo::CORETIME_ROCOCO_LOCAL => Ok(CoretimeRuntimeType::RococoLocal),
rococo::CORETIME_ROCOCO_DEVELOPMENT => Ok(CoretimeRuntimeType::RococoDevelopment),
westend::CORETIME_WESTEND => Ok(CoretimeRuntimeType::Westend),
westend::CORETIME_WESTEND_LOCAL => Ok(CoretimeRuntimeType::WestendLocal),
westend::CORETIME_WESTEND_DEVELOPMENT => Ok(CoretimeRuntimeType::WestendDevelopment),
_ => Err(format!("Value '{}' is not configured yet", value)),
}
}
}

pub fn coretime_rococo_development_config() -> GenericChainSpec {
GenericChainSpec::builder(
coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "rococo-dev".into(), CORETIME_PARA_ID },
)
.with_name("Rococo Coretime Development")
.with_id("coretime-rococo-dev")
.with_chain_type(ChainType::Local)
.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
.with_properties(rococo_properties())
.build()
impl From<CoretimeRuntimeType> for &str {
fn from(runtime_type: CoretimeRuntimeType) -> Self {
match runtime_type {
CoretimeRuntimeType::Kusama => kusama::CORETIME_KUSAMA,
CoretimeRuntimeType::KusamaLocal => kusama::CORETIME_KUSAMA_LOCAL,
CoretimeRuntimeType::Polkadot => polkadot::CORETIME_POLKADOT,
CoretimeRuntimeType::PolkadotLocal => polkadot::CORETIME_POLKADOT_LOCAL,
CoretimeRuntimeType::Rococo => rococo::CORETIME_ROCOCO,
CoretimeRuntimeType::RococoLocal => rococo::CORETIME_ROCOCO_LOCAL,
CoretimeRuntimeType::RococoDevelopment => rococo::CORETIME_ROCOCO_DEVELOPMENT,
CoretimeRuntimeType::Westend => westend::CORETIME_WESTEND,
CoretimeRuntimeType::WestendLocal => westend::CORETIME_WESTEND_LOCAL,
CoretimeRuntimeType::WestendDevelopment => westend::CORETIME_WESTEND_DEVELOPMENT,
}
}
}

impl From<CoretimeRuntimeType> for ChainType {
fn from(runtime_type: CoretimeRuntimeType) -> Self {
match runtime_type {
CoretimeRuntimeType::Kusama |
CoretimeRuntimeType::Polkadot |
CoretimeRuntimeType::Rococo |
CoretimeRuntimeType::Westend => ChainType::Live,
CoretimeRuntimeType::KusamaLocal |
CoretimeRuntimeType::PolkadotLocal |
CoretimeRuntimeType::RococoLocal |
CoretimeRuntimeType::WestendLocal => ChainType::Local,
CoretimeRuntimeType::RococoDevelopment | CoretimeRuntimeType::WestendDevelopment =>
ChainType::Development,
}
}
}

pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005);

impl CoretimeRuntimeType {
pub const ID_PREFIX: &'static str = "coretime";

pub fn load_config(&self) -> Result<Box<dyn ChainSpec>, String> {
match self {
CoretimeRuntimeType::Kusama => Ok(Box::new(GenericChainSpec::from_json_bytes(
&include_bytes!("../../chain-specs/coretime-kusama.json")[..],
)?)),
CoretimeRuntimeType::Polkadot => Ok(Box::new(GenericChainSpec::from_json_bytes(
&include_bytes!("../../chain-specs/coretime-polkadot.json")[..],
)?)),
CoretimeRuntimeType::Rococo => Ok(Box::new(GenericChainSpec::from_json_bytes(
&include_bytes!("../../chain-specs/coretime-rococo.json")[..],
)?)),
CoretimeRuntimeType::RococoLocal =>
Ok(Box::new(rococo::local_config(*self, "rococo-local"))),
CoretimeRuntimeType::RococoDevelopment =>
Ok(Box::new(rococo::local_config(*self, "rococo-dev"))),
CoretimeRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes(
&include_bytes!("../../../parachains/chain-specs/coretime-westend.json")[..],
)?)),
CoretimeRuntimeType::WestendLocal =>
Ok(Box::new(westend::local_config(*self, "westend-local"))),
CoretimeRuntimeType::WestendDevelopment =>
Ok(Box::new(westend::local_config(*self, "westend-dev"))),
other => Err(std::format!(
"No default config present for {:?}, you should provide a chain-spec as json file!",
other
)),
}
}
}

pub fn coretime_rococo_local_config() -> GenericChainSpec {
GenericChainSpec::builder(
coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "rococo-local".into(), CORETIME_PARA_ID },
)
.with_name("Rococo Coretime Local")
.with_id("coretime-rococo-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
.with_properties(rococo_properties())
/// Generate the name directly from the ChainType
pub fn chain_type_name(chain_type: &ChainType) -> Cow<str> {
match chain_type {
ChainType::Development => "Development",
ChainType::Local => "Local",
ChainType::Live => "Live",
ChainType::Custom(name) => name,
}
.into()
}

/// Sub-module for Rococo setup.
pub mod rococo {
use super::{chain_type_name, CoretimeRuntimeType};
use parachains_common::Balance;
use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
use sc_chain_spec::ChainType;
use sp_keyring::Sr25519Keyring;

pub(crate) const CORETIME_ROCOCO: &str = "coretime-rococo";
pub(crate) const CORETIME_ROCOCO_LOCAL: &str = "coretime-rococo-local";
pub(crate) const CORETIME_ROCOCO_DEVELOPMENT: &str = "coretime-rococo-dev";
const CORETIME_ROCOCO_ED: Balance = coretime_rococo_runtime::ExistentialDeposit::get();

pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
// Rococo defaults
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
properties.insert("tokenSymbol".into(), "ROC".into());
properties.insert("tokenDecimals".into(), 12.into());

let chain_type = runtime_type.into();
let chain_name = format!("Coretime Rococo {}", chain_type_name(&chain_type));
let para_id = super::CORETIME_PARA_ID;

let wasm_binary = if matches!(chain_type, ChainType::Local | ChainType::Development) {
coretime_rococo_runtime::fast_runtime_binary::WASM_BINARY
.expect("WASM binary was not built, please build it!")
} else {
coretime_rococo_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!")
};

GenericChainSpec::builder(
wasm_binary,
Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() },
)
.with_name(&chain_name)
.with_id(runtime_type.into())
.with_chain_type(chain_type.clone())
.with_genesis_config_preset_name(match chain_type {
ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
_ => panic!("chain_type: {chain_type:?} not supported here!"),
})
.with_properties(properties)
.build()
}
}

pub fn westend_properties() -> sc_chain_spec::Properties {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());
/// Sub-module for Westend setup.
pub mod westend {
use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec};
use parachains_common::Balance;
use polkadot_omni_node_lib::chain_spec::Extensions;
use sc_chain_spec::ChainType;
use sp_keyring::Sr25519Keyring;

properties
pub(crate) const CORETIME_WESTEND: &str = "coretime-westend";
pub(crate) const CORETIME_WESTEND_LOCAL: &str = "coretime-westend-local";
pub(crate) const CORETIME_WESTEND_DEVELOPMENT: &str = "coretime-westend-dev";
const CORETIME_WESTEND_ED: Balance = coretime_westend_runtime::ExistentialDeposit::get();

pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec {
// westend defaults
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());

let chain_type = runtime_type.into();
let chain_name = format!("Coretime Westend {}", chain_type_name(&chain_type));
let para_id = super::CORETIME_PARA_ID;

GenericChainSpec::builder(
coretime_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() },
)
.with_name(&chain_name)
.with_id(runtime_type.into())
.with_chain_type(chain_type.clone())
.with_genesis_config_preset_name(match chain_type {
ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
_ => panic!("chain_type: {chain_type:?} not supported here!"),
})
.with_properties(properties)
.build()
}
}

pub fn rococo_properties() -> sc_chain_spec::Properties {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
properties.insert("tokenSymbol".into(), "ROC".into());
properties.insert("tokenDecimals".into(), 12.into());
pub mod kusama {
pub(crate) const CORETIME_KUSAMA: &str = "coretime-kusama";
pub(crate) const CORETIME_KUSAMA_LOCAL: &str = "coretime-kusama-local";
}

properties
}
pub mod polkadot {
pub(crate) const CORETIME_POLKADOT: &str = "coretime-polkadot";
pub(crate) const CORETIME_POLKADOT_LOCAL: &str = "coretime-polkadot-local";
}
19 changes: 6 additions & 13 deletions cumulus/polkadot-parachain/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,12 @@ impl LoadSpec for ChainSpecLoader {
.load_config()?,

// -- Coretime
// -- Coretime Rococo
"coretime-rococo-dev" => Box::new(asset_hubs::asset_hub_rococo_development_config()),
"coretime-rococo-local" => Box::new(asset_hubs::asset_hub_rococo_local_config()),
"coretime-rococo" => Box::new(GenericChainSpec::from_json_bytes(
&include_bytes!("../../chain-specs/coretime-rococo.json")[..],
)?),

// -- Coretime Westend
"coretime-westend-dev" => Box::new(asset_hubs::asset_hub_westend_development_config()),
"coretime-westend-local" => Box::new(asset_hubs::asset_hub_westend_local_config()),
"coretime-westend" => Box::new(GenericChainSpec::from_json_bytes(
&include_bytes!("../../chain-specs/coretime-westend.json")[..],
)?),
coretime_like_id
if coretime_like_id.starts_with(coretime::CoretimeRuntimeType::ID_PREFIX) =>
coretime_like_id
.parse::<coretime::CoretimeRuntimeType>()
.expect("invalid value")
.load_config()?,

// -- Penpal
id if id.starts_with("penpal-rococo") => {
Expand Down

0 comments on commit 2aa136a

Please sign in to comment.