Skip to content

Commit

Permalink
Polkadot People Chain (polkadot-fellows#319)
Browse files Browse the repository at this point in the history
Polkadot People Chain

To verify prior to release: People Chain `poke_deposit` weight must be
less than 2x Relay's. E.g.:

```python
>>> weight_per_nano = 1_000
>>> relay_read = 20_499 * weight_per_nano
>>> relay_write = 83_471 * weight_per_nano
>>> para_read = 25_000 * weight_per_nano
>>> para_write = 100_000 * weight_per_nano
>>>
>>> def relay():
...     time = 145_781_000 + (3 * relay_read) + (3 * relay_write)
...     pov = 11_037
...     return (time, pov)
...
>>> def para():
...     time = 52_060_000 + (3 * para_read) + (3 * para_write)
...     pov = 6_723
...     return (time, pov)
...
>>>
>>> (relay_time, relay_pov) = relay()
>>> (para_time, para_pov) = para()
>>>
>>> (2 * relay_time) > para_time
True
>>> (2 * relay_pov) > para_pov
True
```

---------

Co-authored-by: Dónal Murray <[email protected]>
Co-authored-by: Branislav Kontur <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent c05dbd1 commit 329ceca
Show file tree
Hide file tree
Showing 63 changed files with 7,167 additions and 121 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/integration-tests-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"name": "people-kusama",
"package": "people-kusama-integration-tests"
},
{
"name": "people-polkadot",
"package": "people-polkadot-integration-tests"
},
{
"name": "collectives-polkadot",
"package": "collectives-polkadot-integration-tests"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
"path": "system-parachains/people/people-kusama",
"is_relay": false
},
{
"name": "people-polkadot",
"package": "people-polkadot-runtime",
"path": "system-parachains/people/people-polkadot",
"is_relay": false
},
{
"name": "encointer-kusama",
"package": "encointer-kusama-runtime",
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- Add the Polkadot People Chain ([polkadot-fellows/runtimes#319](https://github.com/polkadot-fellows/runtimes/pull/319))

### Changed

- Set max asset ID restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346))
Expand All @@ -24,7 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Staking runtime api to check if reward is pending for an era ([polkadot-fellows/runtimes#318](https://github.com/polkadot-fellows/runtimes/pull/318))
- Allow any parachain to have bidirectional channel with any system parachains ([polkadot-fellows/runtimes#329](https://github.com/polkadot-fellows/runtimes/pull/329))
- Update price controller of broker pallet to use higher leadin, without adjusting the minimum price too much ([polkadot-fellows/runtimes#334](https://github.com/polkadot-fellows/runtimes/pull/334)
- Update price controller of broker pallet to use higher leadin, without adjusting the minimum price too much ([polkadot-fellows/runtimes#334](https://github.com/polkadot-fellows/runtimes/pull/334))
- Enable support for new hardware signers like the generic ledger app ([polkadot-fellows/runtimes#337](https://github.com/polkadot-fellows/runtimes/pull/337))

### Changed
Expand Down
104 changes: 104 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ penpal-emulated-chain = { path = "integration-tests/emulated/chains/parachains/t
penpal-runtime = { version = "0.15.1" }
people-kusama-emulated-chain = { path = "integration-tests/emulated/chains/parachains/people/people-kusama" }
people-kusama-runtime = { path = "system-parachains/people/people-kusama" }
people-polkadot-emulated-chain = { path = "integration-tests/emulated/chains/parachains/people/people-polkadot" }
people-polkadot-runtime = { path = "system-parachains/people/people-polkadot" }
polkadot-core-primitives = { version = "8.0.0", default-features = false }
polkadot-emulated-chain = { path = "integration-tests/emulated/chains/relays/polkadot" }
polkadot-parachain-primitives = { version = "7.0.0", default-features = false }
Expand Down Expand Up @@ -246,6 +248,7 @@ members = [
"integration-tests/emulated/chains/parachains/bridges/bridge-hub-polkadot",
"integration-tests/emulated/chains/parachains/collectives/collectives-polkadot",
"integration-tests/emulated/chains/parachains/people/people-kusama",
"integration-tests/emulated/chains/parachains/people/people-polkadot",
"integration-tests/emulated/chains/parachains/testing/penpal",
"integration-tests/emulated/chains/relays/kusama",
"integration-tests/emulated/chains/relays/polkadot",
Expand All @@ -259,6 +262,7 @@ members = [
"integration-tests/emulated/tests/bridges/bridge-hub-polkadot",
"integration-tests/emulated/tests/collectives/collectives-polkadot",
"integration-tests/emulated/tests/people/people-kusama",
"integration-tests/emulated/tests/people/people-polkadot",
"relay/kusama",
"relay/kusama/constants",
"relay/polkadot",
Expand All @@ -278,6 +282,7 @@ members = [
"system-parachains/encointer",
"system-parachains/gluttons/glutton-kusama",
"system-parachains/people/people-kusama",
"system-parachains/people/people-polkadot",
"integration-tests/zombienet",
]

Expand Down
2 changes: 2 additions & 0 deletions chain-spec-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ encointer-kusama-runtime = { workspace = true }
glutton-kusama-runtime = { workspace = true }
coretime-kusama-runtime = { workspace = true }
people-kusama-runtime = { workspace = true }
people-polkadot-runtime = { workspace = true }

[features]
fast-runtime = ["kusama-runtime/fast-runtime", "polkadot-runtime/fast-runtime"]
Expand All @@ -56,6 +57,7 @@ runtime-benchmarks = [
"pallet-staking/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"people-kusama-runtime/runtime-benchmarks",
"people-polkadot-runtime/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime/runtime-benchmarks",
"runtime-parachains/runtime-benchmarks",
Expand Down
6 changes: 5 additions & 1 deletion chain-spec-generator/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
system_parachains_specs::{
AssetHubKusamaChainSpec, AssetHubPolkadotChainSpec, BridgeHubKusamaChainSpec,
BridgeHubPolkadotChainSpec, CollectivesPolkadotChainSpec, EncointerKusamaChainSpec,
GluttonKusamaChainSpec,
GluttonKusamaChainSpec, PeopleKusamaChainSpec, PeoplePolkadotChainSpec,
},
ChainSpec,
};
Expand Down Expand Up @@ -90,6 +90,10 @@ pub fn from_json_file(filepath: &str, supported: String) -> Result<Box<dyn Chain
Ok(Box::new(GluttonKusamaChainSpec::from_json_file(path)?)),
x if x.starts_with("encointer-kusama") =>
Ok(Box::new(EncointerKusamaChainSpec::from_json_file(path)?)),
x if x.starts_with("people-kusama") =>
Ok(Box::new(PeopleKusamaChainSpec::from_json_file(path)?)),
x if x.starts_with("people-polkadot") =>
Ok(Box::new(PeoplePolkadotChainSpec::from_json_file(path)?)),
_ => Err(format!("Unknown chain 'id' in json file. Only supported: {supported}'")),
}
}
4 changes: 4 additions & 0 deletions chain-spec-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ fn main() -> Result<(), String> {
"people-kusama-local",
Box::new(system_parachains_specs::people_kusama_local_testnet_config) as Box<_>,
),
(
"people-polkadot-local",
Box::new(system_parachains_specs::people_polkadot_local_testnet_config) as Box<_>,
),
]);

if let Some(function) = supported_chains.get(&*cli.chain) {
Expand Down
85 changes: 85 additions & 0 deletions chain-spec-generator/src/system_parachains_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub type CoretimeKusamaChainSpec = sc_chain_spec::GenericChainSpec<(), Extension

pub type PeopleKusamaChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions>;

pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions>;

const ASSET_HUB_POLKADOT_ED: Balance = asset_hub_polkadot_runtime::ExistentialDeposit::get();

const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposit::get();
Expand All @@ -66,6 +68,8 @@ const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit:

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

const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit::get();

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

Expand Down Expand Up @@ -144,6 +148,13 @@ pub fn people_kusama_session_keys(keys: AuraId) -> people_kusama_runtime::Sessio
people_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 people_polkadot_session_keys(keys: AuraId) -> people_polkadot_runtime::SessionKeys {
people_polkadot_runtime::SessionKeys { aura: keys }
}

// AssetHubPolkadot
fn asset_hub_polkadot_genesis(
invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>,
Expand Down Expand Up @@ -758,3 +769,77 @@ pub fn people_kusama_local_testnet_config() -> Result<Box<dyn ChainSpec>, String
.build(),
))
}

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

pub fn people_polkadot_local_testnet_config() -> Result<Box<dyn ChainSpec>, String> {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());

Ok(Box::new(
PeoplePolkadotChainSpec::builder(
people_polkadot_runtime::WASM_BINARY.expect("PeoplePolkadot wasm not available!"),
Extensions { relay_chain: "polkadot-local".into(), para_id: 1004 },
)
.with_name("Polkadot People Local")
.with_id("people-polkadot-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(crate::system_parachains_specs::people_polkadot_local_genesis(
1004.into(),
))
.with_properties(properties)
.build(),
))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "people-polkadot-emulated-chain"
authors.workspace = true
edition.workspace = true
version.workspace = true
license = "Apache-2.0"
description = "People Polkadot emulated chain used for integration tests"
publish = false

[dependencies]

# Substrate
sp-core = { workspace = true, default-features = true }
frame-support = { workspace = true, default-features = true }

# Cumulus
parachains-common = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true, default-features = true }
emulated-integration-tests-common = { workspace = true }

# Local
people-polkadot-runtime = { workspace = true }
polkadot-emulated-chain = { workspace = true }
Loading

0 comments on commit 329ceca

Please sign in to comment.