Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Revamp parachain-selection part 2 #43

Merged
merged 19 commits into from
Apr 26, 2021
Merged
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
10 changes: 10 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'

[dependencies.sp-consensus-aura]
git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '0.9.0'

[dependencies.sp-block-builder]
git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
Expand Down
146 changes: 114 additions & 32 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
// Copyright (C) 2021 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.use cumulus_primitives_core::ParaId;

use cumulus_primitives_core::ParaId;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_core::{sr25519, crypto::UncheckedInto, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use statemint_runtime::{AccountId, Signature};
use statemine_runtime;
use statemint_runtime::{AccountId, Signature, Balance};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use hex_literal::hex;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<statemint_runtime::GenesisConfig, Extensions>;
pub type StatemineChainSpec = sc_service::GenericChainSpec<statemine_runtime::GenesisConfig, Extensions>;

const STATEMINT_ED: Balance = statemint_runtime::EXISTENTIAL_DEPOSIT;
const STATEMINE_ED: Balance = statemine_runtime::EXISTENTIAL_DEPOSIT;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
pub fn get_pair_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain in tuple format.
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_pair_from_seed::<AuraId>(seed)
}

/// 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 statemint_session_keys(keys: AuraId) -> statemint_runtime::opaque::SessionKeys {
statemint_runtime::opaque::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).
pub fn statemine_session_keys(keys: AuraId) -> statemine_runtime::opaque::SessionKeys {
statemine_runtime::opaque::SessionKeys { aura: keys }
}

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
Expand All @@ -36,13 +76,12 @@ impl Extensions {
}

type AccountPublic = <Signature as Verify>::Signer;

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
AccountPublic::from(get_pair_from_seed::<TPublic>(seed)).into_account()
}

pub fn statemint_development_config(id: ParaId) -> ChainSpec {
Expand All @@ -54,13 +93,20 @@ pub fn statemint_development_config(id: ParaId) -> ChainSpec {
ChainType::Local,
move || {
statemint_testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
)
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
id,
)
},
Expand All @@ -84,13 +130,19 @@ pub fn statemint_local_config(id: ParaId) -> ChainSpec {
ChainType::Local,
move || {
statemint_testnet_genesis(
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
vec![
(
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").unchecked_into()
)
],
vec![
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
hex!("c8f226d8a15b8d23241596862ce10d2db8359f816d45efb01c65524725543219").into(),
hex!("dee1e2a19c2f7ddee43e66373d58768c6dc9ba4424af6101a5497b2e4a945371").into(),
hex!("6a9099150aa91fd6cb5ec1a497e0d6b0e14cca7a863ed5608f6aa6a4970c6169").into(),
],
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
id,
)
},
Expand All @@ -106,8 +158,9 @@ pub fn statemint_local_config(id: ParaId) -> ChainSpec {
}

fn statemint_testnet_genesis(
root_key: AccountId,
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root_key: AccountId,
id: ParaId,
) -> statemint_runtime::GenesisConfig {
statemint_runtime::GenesisConfig {
Expand All @@ -121,17 +174,29 @@ fn statemint_testnet_genesis(
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.map(|k| (k, STATEMINT_ED * 4096))
.collect(),
},
pallet_sudo: statemint_runtime::SudoConfig { key: root_key.clone() },
pallet_sudo: statemint_runtime::SudoConfig { key: root_key },
parachain_info: statemint_runtime::ParachainInfoConfig { parachain_id: id },
pallet_collator_selection: statemint_runtime::CollatorSelectionConfig { invulnerables: vec![root_key] },
pallet_collator_selection: statemint_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: STATEMINT_ED * 16,
..Default::default()
},
pallet_session: statemint_runtime::SessionConfig {
keys: invulnerables.iter().cloned().map(|(acc, aura)| (
acc.clone(), // account id
acc.clone(), // validator id
statemint_session_keys(aura), // session keys
)).collect()
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this.
pallet_aura: Default::default(),
}
}



pub fn statemine_development_config(id: ParaId) -> StatemineChainSpec {
StatemineChainSpec::from_genesis(
// Name
Expand All @@ -141,13 +206,20 @@ pub fn statemine_development_config(id: ParaId) -> StatemineChainSpec {
ChainType::Local,
move || {
statemine_testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
)
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
id,
)
},
Expand All @@ -171,21 +243,19 @@ pub fn statemine_local_config(id: ParaId) -> StatemineChainSpec {
ChainType::Local,
move || {
statemine_testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
(
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").unchecked_into()
)
],
vec![
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
hex!("c8f226d8a15b8d23241596862ce10d2db8359f816d45efb01c65524725543219").into(),
hex!("dee1e2a19c2f7ddee43e66373d58768c6dc9ba4424af6101a5497b2e4a945371").into(),
hex!("6a9099150aa91fd6cb5ec1a497e0d6b0e14cca7a863ed5608f6aa6a4970c6169").into(),
],
hex!("2241c74de78435b5f21fb95e40b919c30a73cb4a32776dffce87a062a05ff665").into(),
id,
)
},
Expand All @@ -200,10 +270,10 @@ pub fn statemine_local_config(id: ParaId) -> StatemineChainSpec {
)
}


fn statemine_testnet_genesis(
root_key: AccountId,
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root_key: AccountId,
id: ParaId,
) -> statemine_runtime::GenesisConfig {
statemine_runtime::GenesisConfig {
Expand All @@ -217,11 +287,23 @@ fn statemine_testnet_genesis(
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.map(|k| (k, STATEMINE_ED * 4096))
.collect(),
},
pallet_sudo: statemine_runtime::SudoConfig { key: root_key.clone() },
parachain_info: statemine_runtime::ParachainInfoConfig { parachain_id: id },
pallet_collator_selection: statemine_runtime::CollatorSelectionConfig { invulnerables: vec![root_key] },
pallet_collator_selection: statemine_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: STATEMINE_ED * 16,
..Default::default()
},
pallet_session: statemine_runtime::SessionConfig {
keys: invulnerables.iter().cloned().map(|(acc, aura)| (
acc.clone(), // account id
acc.clone(), // validator id
statemine_session_keys(aura), // session keys
)).collect()
},
pallet_aura: Default::default(),
}
}
Loading