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 coretime parachains #7476

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"header": "cumulus/file_header.txt",
"template": "cumulus/templates/xcm-bench-template.hbs",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
"bench_flags": "",
"uri": "wss://rococo-coretime-rpc.polkadot.io:443",
"is_relay": false
},
Expand All @@ -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 --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
"bench_flags": "",
"uri": "wss://westend-coretime-rpc.polkadot.io:443",
"is_relay": false
},
Expand Down
4 changes: 4 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 @@ -20,6 +20,7 @@ hex-literal = { workspace = true, default-features = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
serde_json = { features = ["alloc"], workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
Expand Down Expand Up @@ -49,6 +50,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 @@ -131,12 +133,14 @@ std = [
"rococo-runtime-constants/std",
"scale-info/std",
"serde",
"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,101 @@
// 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.

//! # Coretime Rococo Runtime genesis config presets

use crate::*;
use alloc::{vec, vec::Vec};
use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use parachains_common::{AccountId, AuraId};
use sp_genesis_builder::PresetId;
use sp_keyring::Sr25519Keyring;
use testnet_parachains_constants::rococo::{currency::UNITS as ROC, xcm_version::SAFE_XCM_VERSION};

const CORETIME_ROCOCO_ED: Balance = ExistentialDeposit::get();

fn coretime_rococo_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
endowment: Balance,
id: ParaId,
) -> serde_json::Value {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: CORETIME_ROCOCO_ED * 16,
},
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
})
}

/// 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 => coretime_rococo_genesis(
// initial collators.
vec![
(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
],
Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect(),
testnet_parachains_constants::rococo::currency::UNITS * 1_000_000,
1000.into(),
),
sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_rococo_genesis(
// initial collators.
vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())],
vec![
Sr25519Keyring::Alice.to_account_id(),
Sr25519Keyring::Bob.to_account_id(),
Sr25519Keyring::AliceStash.to_account_id(),
Sr25519Keyring::BobStash.to_account_id(),
],
ROC * 1_000_000,
1000.into(),
),
_ => 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 @@ -30,6 +30,7 @@ pub mod fast_runtime_binary {
}

mod coretime;
mod genesis_config_presets;
mod weights;
pub mod xcm_config;

Expand Down Expand Up @@ -1166,11 +1167,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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hex-literal = { workspace = true, default-features = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
serde_json = { features = ["alloc"], workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
Expand Down Expand Up @@ -48,6 +49,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 @@ -128,12 +130,14 @@ std = [
"polkadot-runtime-common/std",
"scale-info/std",
"serde",
"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,103 @@
// 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.

//! # Coretime Westend Runtime genesis config presets

use crate::*;
use alloc::{vec, vec::Vec};
use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use parachains_common::{AccountId, AuraId};
use sp_genesis_builder::PresetId;
use sp_keyring::Sr25519Keyring;
use testnet_parachains_constants::westend::{
currency::UNITS as WND, xcm_version::SAFE_XCM_VERSION,
};

const CORETIME_WESTEND_ED: Balance = ExistentialDeposit::get();

fn coretime_westend_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
endowment: Balance,
id: ParaId,
) -> serde_json::Value {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(),
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: CORETIME_WESTEND_ED * 16,
},
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
})
}

/// 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 => coretime_westend_genesis(
// initial collators.
vec![
(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()),
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
],
Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
WND * 1_000_000,
1000.into(),
),
sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_westend_genesis(
// initial collators.
vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())],
vec![
Sr25519Keyring::Alice.to_account_id(),
Sr25519Keyring::Bob.to_account_id(),
Sr25519Keyring::AliceStash.to_account_id(),
Sr25519Keyring::BobStash.to_account_id(),
],
WND * 1_000_000,
1000.into(),
),
_ => 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 @@ -30,6 +30,7 @@ pub mod fast_runtime_binary {
}

mod coretime;
mod genesis_config_presets;
mod weights;
pub mod xcm_config;

Expand Down Expand Up @@ -1161,11 +1162,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
Loading
Loading