Skip to content

Commit

Permalink
Added to chain-spec-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Mar 21, 2024
1 parent c3dcc7a commit ff15598
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions chain-spec-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bridge-hub-polkadot-runtime = { path = "../system-parachains/bridge-hubs/bridge-
bridge-hub-kusama-runtime = { path = "../system-parachains/bridge-hubs/bridge-hub-kusama" }
encointer-kusama-runtime = { path = "../system-parachains/encointer" }
glutton-kusama-runtime = { path = "../system-parachains/gluttons/glutton-kusama" }
coretime-kusama-runtime = { path = "../system-parachains/coretime/coretime-kusama" }

[features]
fast-runtime = [
Expand All @@ -53,4 +54,5 @@ runtime-benchmarks = [
"polkadot-runtime/runtime-benchmarks",
"encointer-kusama-runtime/runtime-benchmarks",
"glutton-kusama-runtime/runtime-benchmarks",
"coretime-kusama-runtime/runtime-benchmarks",
]
5 changes: 5 additions & 0 deletions chain-spec-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ fn main() -> Result<(), String> {
Box::new(|| system_parachains_specs::encointer_kusama_local_testnet_config())
as Box<_>,
),
(
"coretime-kusama-local",
Box::new(|| system_parachains_specs::coretime_kusama_local_testnet_config())
as Box<_>,
),
]);

if let Some(function) = supported_chains.get(&*cli.chain) {
Expand Down
83 changes: 83 additions & 0 deletions chain-spec-generator/src/system_parachains_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub type GluttonKusamaChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions

pub type EncointerKusamaChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions>;

pub type CoretimeKusamaChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions>;

const ASSET_HUB_POLKADOT_ED: Balance = asset_hub_polkadot_runtime::ExistentialDeposit::get();

const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposit::get();
Expand All @@ -58,6 +60,8 @@ const BRIDGE_HUB_KUSAMA_ED: Balance = bridge_hub_kusama_runtime::ExistentialDepo

const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get();

const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit::get();

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

Expand All @@ -83,6 +87,13 @@ pub fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAur
]
}

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
pub fn coretime_kusama_session_keys(keys: AuraId) -> coretime_kusama_runtime::SessionKeys {
coretime_kusama_runtime::SessionKeys { aura: keys }
}

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
Expand Down Expand Up @@ -564,3 +575,75 @@ pub fn encointer_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, Str
.build(),
))
}

// CoretimeKusama
fn coretime_kusama_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": coretime_kusama_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, CORETIME_KUSAMA_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": coretime_kusama_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": coretime_kusama_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: CORETIME_KUSAMA_ED * 16,
..Default::default()
},
"session": coretime_kusama_runtime::SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
coretime_kusama_session_keys(aura), // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
}

fn coretime_kusama_local_genesis(para_id: ParaId) -> serde_json::Value {
coretime_kusama_genesis(
// initial collators.
invulnerables(),
testnet_accounts(),
para_id,
)
}

pub fn coretime_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, String> {
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());

Ok(Box::new(
CoretimeKusamaChainSpec::builder(
coretime_kusama_runtime::WASM_BINARY.expect("CoretimeKusama wasm not available!"),
Extensions { relay_chain: "kusama-local".into(), para_id: 1005 },
)
.with_name("Kusama Coretime Local")
.with_id("coretime-kusama-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(coretime_kusama_local_genesis(1005.into()))
.with_properties(properties)
.build(),
))
}

0 comments on commit ff15598

Please sign in to comment.