Skip to content
Snippets Groups Projects
Unverified Commit cbc9b901 authored by clangenb's avatar clangenb Committed by GitHub
Browse files

add genesis presets for glutton westend (#7481)


Extracted from #7473.

Part of: https://github.com/paritytech/polkadot-sdk/issues/5704.

---------

Co-authored-by: default avatarcmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: default avatarBranislav Kontur <bkontur@gmail.com>
parent e9be92d6
Branches
No related merge requests found
Pipeline #517066 waiting for manual action with stages
in 1 hour, 50 minutes, and 41 seconds
......@@ -116,7 +116,7 @@
"header": "cumulus/file_header.txt",
"template": "cumulus/templates/xcm-bench-template.hbs",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none",
"bench_flags": "",
"uri": null,
"is_relay": false
},
......
......@@ -7291,12 +7291,14 @@ dependencies = [
"parachains-common",
"parity-scale-codec",
"scale-info",
"serde_json",
"sp-api 26.0.0",
"sp-block-builder",
"sp-consensus-aura",
"sp-core 28.0.0",
"sp-genesis-builder",
"sp-inherents",
"sp-keyring",
"sp-offchain",
"sp-runtime 31.0.1",
"sp-session",
......
......@@ -14,6 +14,7 @@ workspace = true
[dependencies]
codec = { features = ["derive"], workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde_json = { features = ["alloc"], workspace = true }
# Substrate
frame-benchmarking = { optional = true, workspace = true }
......@@ -34,6 +35,7 @@ sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-genesis-builder = { workspace = true }
sp-inherents = { workspace = true }
sp-keyring = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
......@@ -102,12 +104,14 @@ std = [
"parachain-info/std",
"parachains-common/std",
"scale-info/std",
"serde_json/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-keyring/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
......
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! # Glutton Westend Runtime genesis config presets
use crate::*;
use alloc::vec::Vec;
use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use parachains_common::AuraId;
use sp_genesis_builder::PresetId;
use sp_keyring::Sr25519Keyring;
/// Default value, unused in a testnet setup currently because
/// we want to supply varying para-ids from the CLI for Glutton.
/// However, the presets does not allow dynamic para-ids currently.
pub const DEFAULT_GLUTTON_PARA_ID: ParaId = ParaId::new(1300);
pub fn glutton_westend_genesis(authorities: Vec<AuraId>, id: ParaId) -> serde_json::Value {
build_struct_json_patch!(RuntimeGenesisConfig {
parachain_info: ParachainInfoConfig { parachain_id: id },
aura: AuraConfig { authorities },
})
}
/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
let patch = match id.as_ref() {
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => glutton_westend_genesis(
// initial collators.
vec![Sr25519Keyring::Alice.public().into(), Sr25519Keyring::Bob.public().into()],
DEFAULT_GLUTTON_PARA_ID,
),
sp_genesis_builder::DEV_RUNTIME_PRESET => glutton_westend_genesis(
// initial collators.
vec![Sr25519Keyring::Alice.public().into()],
DEFAULT_GLUTTON_PARA_ID,
),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}
/// List of supported presets.
pub fn preset_names() -> Vec<PresetId> {
vec![
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
]
}
......@@ -44,6 +44,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub mod genesis_config_presets;
pub mod weights;
pub mod xcm_config;
......@@ -495,11 +496,11 @@ impl_runtime_apis! {
}
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, |_| None)
get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
}
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
genesis_config_presets::preset_names()
}
}
}
......
......@@ -15,81 +15,57 @@
// limitations under the License.
use cumulus_primitives_core::ParaId;
use parachains_common::AuraId;
use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
use sc_service::ChainType;
use sp_keyring::Sr25519Keyring;
fn glutton_genesis(parachain_id: ParaId, collators: Vec<AuraId>) -> serde_json::Value {
serde_json::json!( {
"parachainInfo": {
"parachainId": parachain_id
},
"sudo": {
"key": Some(Sr25519Keyring::Alice.to_account_id()),
},
"aura": { "authorities": collators },
})
}
/// Generic Glutton Westend Config for all currently used setups.
pub fn glutton_westend_config(
para_id: ParaId,
chain_type: ChainType,
relay_chain: &str,
) -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
pub fn glutton_westend_development_config(para_id: ParaId) -> GenericChainSpec {
GenericChainSpec::builder(
glutton_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend-dev".into(), para_id: para_id.into() },
)
.with_name("Glutton Development")
.with_id("glutton_westend_dev")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(glutton_genesis(
para_id,
vec![Sr25519Keyring::Alice.public().into()],
))
.build()
}
let authorities = match chain_type {
ChainType::Development => vec![Sr25519Keyring::Alice.public().into()],
// Even the westend live setup does currently use Alice & Bob.
_ => vec![Sr25519Keyring::Alice.public().into(), Sr25519Keyring::Bob.public().into()],
};
pub fn glutton_westend_local_config(para_id: ParaId) -> GenericChainSpec {
GenericChainSpec::builder(
glutton_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend-local".into(), para_id: para_id.into() },
Extensions { relay_chain: relay_chain.into(), para_id: para_id.into() },
)
.with_name(&chain_type_name(para_id, &chain_type))
.with_id(&chain_id(para_id, &chain_type))
.with_chain_type(chain_type)
.with_genesis_config_patch(
glutton_westend_runtime::genesis_config_presets::glutton_westend_genesis(
authorities,
para_id,
),
)
.with_name("Glutton Local")
.with_id("glutton_westend_local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(glutton_genesis(
para_id,
vec![Sr25519Keyring::Alice.public().into(), Sr25519Keyring::Bob.public().into()],
))
.build()
}
pub fn glutton_westend_config(para_id: ParaId) -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 42.into());
GenericChainSpec::builder(
glutton_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend".into(), para_id: para_id.into() },
)
.with_name(format!("Glutton {}", para_id).as_str())
.with_id(format!("glutton-westend-{}", para_id).as_str())
.with_chain_type(ChainType::Live)
.with_genesis_config_patch(glutton_westend_genesis(
para_id,
vec![Sr25519Keyring::Alice.public().into(), Sr25519Keyring::Bob.public().into()],
))
.with_protocol_id(format!("glutton-westend-{}", para_id).as_str())
.with_properties(properties)
.build()
/// Generate the name directly from the ChainType
fn chain_type_name(para_id: ParaId, chain_type: &ChainType) -> String {
match chain_type {
ChainType::Development => format!("Glutton Development {}", para_id),
ChainType::Local => format!("Glutton Local {}", para_id),
ChainType::Live => format!("Glutton {}", para_id),
ChainType::Custom(name) => name.clone(),
}
}
fn glutton_westend_genesis(parachain_id: ParaId, collators: Vec<AuraId>) -> serde_json::Value {
serde_json::json!( {
"parachainInfo": {
"parachainId": parachain_id
},
"sudo": {
"key": Some(Sr25519Keyring::Alice.to_account_id()),
},
"aura": { "authorities": collators },
})
/// Generate the name directly from the ChainType
pub fn chain_id(para_id: ParaId, chain_type: &ChainType) -> String {
match chain_type {
ChainType::Development => format!("glutton-westend-dev-{}", para_id),
ChainType::Local => format!("glutton-westend-local-{}", para_id),
ChainType::Live => format!("glutton-westend-{}", para_id),
ChainType::Custom(_) => format!("glutton-westend-custom-{}", para_id),
}
}
......@@ -21,7 +21,7 @@ use polkadot_omni_node_lib::{
AuraConsensusId, BlockNumber, Consensus, Runtime, RuntimeResolver as RuntimeResolverT,
},
};
use sc_chain_spec::ChainSpec;
use sc_chain_spec::{ChainSpec, ChainType};
pub mod asset_hubs;
pub mod bridge_hubs;
......@@ -151,14 +151,18 @@ impl LoadSpec for ChainSpecLoader {
// -- Glutton Westend
id if id.starts_with("glutton-westend-dev") => {
let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-dev-"]);
Box::new(glutton::glutton_westend_development_config(
Box::new(glutton::glutton_westend_config(
para_id.expect("Must specify parachain id"),
ChainType::Development,
"westend-dev",
))
},
id if id.starts_with("glutton-westend-local") => {
let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-local-"]);
Box::new(glutton::glutton_westend_local_config(
Box::new(glutton::glutton_westend_config(
para_id.expect("Must specify parachain id"),
ChainType::Local,
"westend-local",
))
},
// the chain spec as used for generating the upgrade genesis values
......@@ -166,6 +170,8 @@ impl LoadSpec for ChainSpecLoader {
let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-genesis-"]);
Box::new(glutton::glutton_westend_config(
para_id.expect("Must specify parachain id"),
ChainType::Live,
"westend",
))
},
......
title: add genesis presets for glutton westend
doc:
- audience: Runtime Dev
description: |-
Extracted from #7473.
Part of: https://github.com/paritytech/polkadot-sdk/issues/5704.
I did not use the presets in the parachain-bin, as we rely on passing custom para-ids to the chains specs to launch many glutton chains on one relay chain. This is currently not compatible with the genesis presets, which hard code the para ID, see https://github.com/paritytech/polkadot-sdk/issues/7618 and https://github.com/paritytech/polkadot-sdk/issues/7384.
crates:
- name: glutton-westend-runtime
bump: minor
- name: polkadot-parachain-bin
bump: minor
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment