Skip to content

Commit

Permalink
Set get_preset for CollectivesPolkadot
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Jul 16, 2024
1 parent f7dd41c commit 17d3e21
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 68 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ members = [
"integration-tests/emulated/tests/collectives/collectives-polkadot",
"integration-tests/emulated/tests/people/people-kusama",
"integration-tests/emulated/tests/people/people-polkadot",
"integration-tests/zombienet",
"relay/kusama",
"relay/kusama/constants",
"relay/polkadot",
Expand All @@ -286,7 +287,6 @@ members = [
"system-parachains/gluttons/glutton-kusama",
"system-parachains/people/people-kusama",
"system-parachains/people/people-polkadot",
"integration-tests/zombienet",
]

[profile.release]
Expand Down
65 changes: 1 addition & 64 deletions chain-spec-generator/src/system_parachains_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ const ASSET_HUB_POLKADOT_ED: Balance = asset_hub_polkadot_runtime::ExistentialDe

const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposit::get();

const COLLECTIVES_POLKADOT_ED: Balance = collectives_polkadot_runtime::ExistentialDeposit::get();

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

const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit::get();
Expand Down Expand Up @@ -114,15 +112,6 @@ pub fn asset_hub_kusama_session_keys(keys: AuraId) -> asset_hub_kusama_runtime::
asset_hub_kusama_runtime::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 collectives_polkadot_session_keys(
keys: AuraId,
) -> collectives_polkadot_runtime::SessionKeys {
collectives_polkadot_runtime::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).
Expand Down Expand Up @@ -281,58 +270,6 @@ pub fn asset_hub_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, Str
))
}

// CollectivesPolkadot
fn collectives_polkadot_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": collectives_polkadot_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": collectives_polkadot_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": collectives_polkadot_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: COLLECTIVES_POLKADOT_ED * 16,
..Default::default()
},
"session": collectives_polkadot_runtime::SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
collectives_polkadot_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 collectives_polkadot_local_genesis(para_id: ParaId) -> serde_json::Value {
collectives_polkadot_genesis(
// initial collators.
invulnerables(),
testnet_accounts(),
para_id,
)
}

pub fn collectives_polkadot_local_testnet_config() -> Result<Box<dyn ChainSpec>, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
Expand All @@ -348,7 +285,7 @@ pub fn collectives_polkadot_local_testnet_config() -> Result<Box<dyn ChainSpec>,
.with_name("Polkadot Collectives Local")
.with_id("collectives-polkadot-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(collectives_polkadot_local_genesis(1001.into()))
.with_genesis_config_patch(collectives_polkadot_runtime::genesis_config_presets::collectives_polkadot_local_testnet_genesis(1001.into()))
.with_properties(properties)
.build(),
))
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/zombienet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
subxt = { features = ["native"] , workspace = true }
subxt = { features = ["native"], workspace = true }
tokio = { workspace = true }
tracing-subscriber = { workspace = true }
zombienet-sdk = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions system-parachains/collectives/collectives-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ codec = { features = ["derive", "max-encoded-len"], workspace = true }
hex-literal = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde_json = { features = ["alloc"], workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
Expand Down Expand Up @@ -210,6 +211,7 @@ std = [
"polkadot-runtime-common/std",
"polkadot-runtime-constants/std",
"scale-info/std",
"serde_json/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-block-builder/std",
Expand Down
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 CollectivesPolkadot runtime
use crate::*;
use sp_std::vec::Vec;
use system_parachains_constants::genesis_presets::*;

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

fn collectives_polkadot_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, COLLECTIVES_POLKADOT_ED * 4096 * 4096))
.collect(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: COLLECTIVES_POLKADOT_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 collectives_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value {
collectives_polkadot_genesis(invulnerables(), testnet_accounts(), para_id)
}

fn collectives_polkadot_development_genesis(para_id: ParaId) -> serde_json::Value {
collectives_polkadot_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") => collectives_polkadot_development_genesis(1002.into()),
Ok("local_testnet") => collectives_polkadot_local_testnet_genesis(1002.into()),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}
8 changes: 6 additions & 2 deletions system-parachains/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod ambassador;
pub mod genesis_config_presets;
pub mod impls;
mod weights;
pub mod xcm_config;
Expand Down Expand Up @@ -963,11 +964,14 @@ 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![]
vec![
sp_genesis_builder::PresetId::from("local_testnet"),
sp_genesis_builder::PresetId::from("development"),
]
}
}

Expand Down

0 comments on commit 17d3e21

Please sign in to comment.