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 7 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,70 @@
// 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.
///
/// The parachain binary does not yet utilize genesis presets,
/// as it must obtain the para-id from the CLI to support multiple
/// gluttons with different para-ids connecting to a relay chain.
/// Currently, genesis presets do not allow dynamic para-ids.
pub const DEFAULT_GLUTTON_PARA_ID: ParaId = ParaId::new(1000);

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