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

add genesis presets for glutton westend #7481

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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
},
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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),
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -494,11 +495,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()
}
}
}
Expand Down
102 changes: 39 additions & 63 deletions cumulus/polkadot-parachain/src/chain_spec/glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
12 changes: 9 additions & 3 deletions cumulus/polkadot-parachain/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,21 +151,27 @@ 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
id if id.starts_with("glutton-westend-genesis") => {
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",
))
},

Expand Down
14 changes: 14 additions & 0 deletions prdoc/pr_7481.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
Loading