Skip to content

Commit

Permalink
Set get_preset for Encointer
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Jul 17, 2024
1 parent 7dd3c60 commit 8a531c9
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 299 deletions.
51 changes: 1 addition & 50 deletions chain-spec-generator/src/system_parachains_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub type PeopleKusamaChainSpec = sc_chain_spec::GenericChainSpec<Extensions>;

pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec<Extensions>;

const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get();

const PEOPLE_KUSAMA_ED: Balance = people_kusama_runtime::ExistentialDeposit::get();

const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit::get();
Expand Down Expand Up @@ -195,53 +193,6 @@ pub fn glutton_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, Strin
))
}

// EncointerKusama
fn encointer_kusama_genesis(endowed_accounts: Vec<AccountId>, id: u32) -> serde_json::Value {
serde_json::json!({
"balances": asset_hub_kusama_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ENCOINTER_KUSAMA_ED * 4096))
.collect(),
},
"parachainInfo": encointer_kusama_runtime::ParachainInfoConfig {
parachain_id: id.into(),
..Default::default()
},
"collatorSelection": encointer_kusama_runtime::CollatorSelectionConfig {
invulnerables: invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ENCOINTER_KUSAMA_ED * 16,
..Default::default()
},
"session": asset_hub_kusama_runtime::SessionConfig {
keys: invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
asset_hub_kusama_session_keys(aura), // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
}

fn encointer_kusama_local_genesis(para_id: u32) -> serde_json::Value {
encointer_kusama_genesis(
// initial collators.
testnet_accounts(),
para_id,
)
}

pub fn encointer_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 2.into());
Expand All @@ -256,7 +207,7 @@ pub fn encointer_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, Str
.with_name("Kusama Encointer Local")
.with_id("encointer-kusama-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(encointer_kusama_local_genesis(1001))
.with_genesis_config_patch(encointer_kusama_runtime::genesis_config_presets::encointer_kusama_local_testnet_genesis(1001))
.with_properties(properties)
.build(),
))
Expand Down
9 changes: 4 additions & 5 deletions system-parachains/encointer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hex-literal = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
smallvec = { workspace = true }
serde_json = { features = ["alloc"], workspace = true }


# Encointer pallet versioning follows these rules:
Expand Down Expand Up @@ -99,17 +100,13 @@ parachain-info = { workspace = true }
parachains-common = { workspace = true }
polkadot-core-primitives = { workspace = true }
polkadot-primitives = { workspace = true }
system-parachains-constants = { workspace = true }

[build-dependencies]
substrate-wasm-builder = { optional = true, workspace = true }

[dev-dependencies]
# The Encointer pallets might not have compatible versions of `polkadot-sdk` with the rest of the system parachains,
# so we need to copy all the contents from `system-parachains-constants` and `kusama-runtime-constants`.
# We use these crates only for testing to ensure compatible values.
# NOTE: Do not add this to the `[dependencies]`
kusama-runtime-constants = { workspace = true, default-features = true }
system-parachains-constants = { workspace = true, default-features = true }

[features]
default = ["std"]
Expand Down Expand Up @@ -208,6 +205,7 @@ std = [
"polkadot-primitives/std",
"polkadot-runtime-common/std",
"scale-info/std",
"serde_json/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand All @@ -221,6 +219,7 @@ std = [
"sp-transaction-pool/std",
"sp-version/std",
"substrate-wasm-builder",
"system-parachains-constants/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
Expand Down
87 changes: 87 additions & 0 deletions system-parachains/encointer/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Genesis configs presets for the EincointerKusama runtime
use crate::*;
use sp_std::vec::Vec;
use system_parachains_constants::genesis_presets::*;

const ENCOINTER_KUSAMA_ED: Balance = crate::ExistentialDeposit::get();

fn encointer_kusama_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ENCOINTER_KUSAMA_ED * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id.into(),
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ENCOINTER_KUSAMA_ED * 16,
..Default::default()
},
"session": SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
}

pub fn encointer_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
encointer_kusama_genesis(invulnerables(), testnet_accounts(), para_id)
}

fn encointer_kusama_development_genesis(para_id: ParaId) -> serde_json::Value {
encointer_kusama_local_testnet_genesis(para_id)
}

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
let patch = match id.try_into() {
Ok("development") => encointer_kusama_development_genesis(1001.into()),
Ok("local_testnet") => encointer_kusama_local_testnet_genesis(1001.into()),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}
Loading

0 comments on commit 8a531c9

Please sign in to comment.