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 people chain runtime #122

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
67 changes: 67 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ members = [
"system-parachains/asset-hub-paseo/primitives",
"system-parachains/bridge-hub-paseo",
"system-parachains/bridge-hub-paseo/primitives",
"system-parachains/people-paseo",
"system-parachains/constants"
]

Expand Down
4 changes: 4 additions & 0 deletions chain-spec-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ paseo-runtime = { path = "../relay/paseo" }
paseo-runtime-constants = { path = "../relay/paseo/constants", default-features = true }
asset-hub-paseo-runtime = { path = "../system-parachains/asset-hub-paseo", default-features = true }
bridge-hub-paseo-runtime = { path = "../system-parachains/bridge-hub-paseo", default-features = true }
people-paseo-runtime = { path = "../system-parachains/people-paseo", default-features = true }
system-parachains-constants = { path = "../system-parachains/constants", default-features = true }

# External dependencies
Expand All @@ -36,6 +37,9 @@ cumulus-primitives-core = { workspace = true, default-features = true }
[features]
fast-runtime = ["paseo-runtime/fast-runtime"]
runtime-benchmarks = [
"people-paseo-runtime/runtime-benchmarks",
"asset-hub-paseo-runtime/runtime-benchmarks",
"bridge-hub-paseo-runtime/runtime-benchmarks",
"paseo-runtime/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
Expand Down
9 changes: 9 additions & 0 deletions chain-spec-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ fn main() -> Result<(), String> {
Box::new(|| system_parachains_specs::bridge_hub_paseo_local_testnet_config())
as Box<_>,
),
(
"people-paseo",
Box::new(|| system_parachains_specs::people_paseo_testnet_config()) as Box<_>,
),
(
"people-paseo-local",
Box::new(|| system_parachains_specs::people_paseo_local_testnet_config())
as Box<_>,
),
]);

if let Some(function) = supported_chains.get(&*cli.chain) {
Expand Down
108 changes: 108 additions & 0 deletions chain-spec-generator/src/system_parachains_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ pub type AssetHubPaseoChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions

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

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


const ASSET_HUB_PASEO_ED: Balance = asset_hub_paseo_runtime::ExistentialDeposit::get();

const BRIDGE_HUB_PASEO_ED: Balance = bridge_hub_paseo_runtime::ExistentialDeposit::get();

const PEOPLE_PASEO_ED: Balance = people_paseo_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 @@ -81,6 +86,13 @@ pub fn bridge_hub_paseo_session_keys(keys: AuraId) -> bridge_hub_paseo_runtime::
bridge_hub_paseo_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_paseo_session_keys(keys: AuraId) -> people_paseo_runtime::SessionKeys {
people_paseo_runtime::SessionKeys { aura: keys }
}

// AssetHubPaseo
fn asset_hub_paseo_genesis(
invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>,
Expand Down Expand Up @@ -252,3 +264,99 @@ pub fn bridge_hub_paseo_local_testnet_config() -> Result<Box<dyn ChainSpec>, Str
.build(),
))
}

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

pub fn people_paseo_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(), "PAS".into());
properties.insert("tokenDecimals".into(), 10.into());

Ok(Box::new(
PeoplePaseoChainSpec::builder(
people_paseo_runtime::WASM_BINARY.expect("PeoplePaseo wasm not available!"),
Extensions { relay_chain: "paseo-local".into(), para_id: 1004 },
)
.with_name("Paseo People Local")
.with_id("people-paseo-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(crate::system_parachains_specs::people_paseo_local_genesis(
1004.into(),
))
.with_properties(properties)
.build(),
))
}

pub fn people_paseo_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(), "PAS".into());
properties.insert("tokenDecimals".into(), 10.into());

Ok(Box::new(
PeoplePaseoChainSpec::builder(
people_paseo_runtime::WASM_BINARY.expect("PeoplePaseo wasm not available!"),
Extensions { relay_chain: "paseo".into(), para_id: 1004 },
)
.with_name("Paseo People")
.with_id("people-paseo")
.with_chain_type(ChainType::Live)
.with_genesis_config_patch(crate::system_parachains_specs::people_paseo_local_genesis(
1004.into(),
))
.with_properties(properties)
.build(),
))
}
144 changes: 144 additions & 0 deletions scripts/create_people_paseo_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/usr/bin/env bash
set -euo pipefail

# This script generates the people-polkadot base chainspec at genesis. This is then modified by the
# script in polkadot-sdk on the nacho/people-chain-spec-with-migation branch, which also generates
# the genesis wasm and head data.

## Configure
para_id=1004
version="v1.2.6"
release_wasm="people-paseo_runtime-v1002006.compact.compressed.wasm"
build_level="release"

## Download
if [ ! -f $release_wasm ]; then
curl -OL "https://github.com/polkadot-fellows/runtimes/releases/download/$version/$release_wasm"
fi

if [ -d runtimes ]; then
cd runtimes
git fetch --tags
cd -
else
git clone https://github.com/polkadot-fellows/runtimes
fi

if [ -d polkadot-sdk ]; then
cd polkadot-sdk
git checkout master && git pull
cd -
else
git clone --branch master --single-branch https://github.com/paritytech/polkadot-sdk
fi

## Prepare
cd runtimes
git checkout tags/$version --force
cargo build -p chain-spec-generator --$build_level
cd -
chain_spec_generator="./runtimes/target/$build_level/chain-spec-generator"


cd polkadot-sdk
# After people-polkadot was supported, but before the breaking change which expects additional runtime api.
git checkout 68cdb12 --force
cargo build -p polkadot-parachain-bin --$build_level
cd -
polkadot_parachain="./polkadot-sdk/target/$build_level/polkadot-parachain"

# Dump the runtime to hex.
cat $release_wasm | od -A n -v -t x1 | tr -d ' \n' >rt-hex.txt

# Generate the local chainspec to manipulate.
$chain_spec_generator people-polkadot-local >chain-spec-plain.json

## Patch
# Related issue for Parity bootNodes, invulnerables, and session keys: https://github.com/paritytech/infrastructure/issues/6
cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesis.code = ("0x" + $code)' |
jq '.name = "Polkadot People"' |
al3mart marked this conversation as resolved.
Show resolved Hide resolved
jq '.id = "people-polkadot"' |
al3mart marked this conversation as resolved.
Show resolved Hide resolved
jq '.chainType = "Live"' |
jq '.bootNodes = [
al3mart marked this conversation as resolved.
Show resolved Hide resolved
"/dns/polkadot-people-connect-0.polkadot.io/tcp/30334/p2p/12D3KooWP7BoJ7nAF9QnsreN8Eft1yHNUhvhxFiQyKFEUePi9mu3",
"/dns/polkadot-people-connect-1.polkadot.io/tcp/30334/p2p/12D3KooWSSfWY3fTGJvGkuNUNBSNVCdLLNJnwkZSNQt7GCRYXu4o",
"/dns/polkadot-people-connect-0.polkadot.io/tcp/443/wss/p2p/12D3KooWP7BoJ7nAF9QnsreN8Eft1yHNUhvhxFiQyKFEUePi9mu3",
"/dns/polkadot-people-connect-1.polkadot.io/tcp/443/wss/p2p/12D3KooWSSfWY3fTGJvGkuNUNBSNVCdLLNJnwkZSNQt7GCRYXu4o"
]' |
jq '.relay_chain = "polkadot"' |
al3mart marked this conversation as resolved.
Show resolved Hide resolved
jq --argjson para_id $para_id '.para_id = $para_id' |
jq --argjson para_id $para_id '.genesis.runtimeGenesis.patch.parachainInfo.parachainId = $para_id' |
jq '.genesis.runtimeGenesis.patch.balances.balances = []' |
jq '.genesis.runtimeGenesis.patch.collatorSelection.invulnerables = [
al3mart marked this conversation as resolved.
Show resolved Hide resolved
"1CVdL7sb6AQGMQYZb8NfQhcBQMhmTLN3e7NDEby8rZkjyJo",
"14QhqUX7kux5PggbBwUFFZNuLvfX2CjzUQ9V56m4d4S67Pgn",
"112FKz5UNxjXqe3Wowe73a8FHnR5B4R9qi2pbMaXJczGNJsx",
"16FyxKfMF3LnX4CmDsv1PUDPNwqDYiR7rKurwuJxSGgnTsH2",
"14EQvBy9h8xGbh2R3ustnkfkF514E7wpmHtg27gDaTLM2str",
"14sD2iYm1HsFPoHaT2GJNUMD2KJzvJNfVe9PBrG1KGyDBeHn",
"1bLdd7zvNvjGpseQ8BGbGJekCppb1X5Gb228c9MQfHfmmBr"
]' |
jq '.genesis.runtimeGenesis.patch.session.keys = [
[
"1CVdL7sb6AQGMQYZb8NfQhcBQMhmTLN3e7NDEby8rZkjyJo",
"1CVdL7sb6AQGMQYZb8NfQhcBQMhmTLN3e7NDEby8rZkjyJo",
{
"aura": "1WyMcPD9qNrweNu6SKR1TTE2MybFiG8QsZSYxTMsFomuL1o"
}
],
[
"14QhqUX7kux5PggbBwUFFZNuLvfX2CjzUQ9V56m4d4S67Pgn",
"14QhqUX7kux5PggbBwUFFZNuLvfX2CjzUQ9V56m4d4S67Pgn",
{
"aura": "15wq6YmW6panxKmFaLEmrKpsypM2eT4VDY3JvrATnA6eMqvk"
}
],
[
"112FKz5UNxjXqe3Wowe73a8FHnR5B4R9qi2pbMaXJczGNJsx",
"112FKz5UNxjXqe3Wowe73a8FHnR5B4R9qi2pbMaXJczGNJsx",
{
"aura": "13Th3imMymWAXD54sMyTYAVyuWsz2GSix5SMAyHKszdFtSxc"
}
],
[
"16FyxKfMF3LnX4CmDsv1PUDPNwqDYiR7rKurwuJxSGgnTsH2",
"16FyxKfMF3LnX4CmDsv1PUDPNwqDYiR7rKurwuJxSGgnTsH2",
{
"aura": "14ii4R1kDMf4X1nLVHN2nGEu85ptTiFbAAaFzMGu2wcrCAJ5"
}
],
[
"14EQvBy9h8xGbh2R3ustnkfkF514E7wpmHtg27gDaTLM2str",
"14EQvBy9h8xGbh2R3ustnkfkF514E7wpmHtg27gDaTLM2str",
{
"aura": "12sBnnQpA3pV98pakjbc23cVSmpYdYxCEEs83FSybwWpS4Ub"
}
],
[
"14sD2iYm1HsFPoHaT2GJNUMD2KJzvJNfVe9PBrG1KGyDBeHn",
"14sD2iYm1HsFPoHaT2GJNUMD2KJzvJNfVe9PBrG1KGyDBeHn",
{
"aura": "12uVrDhFxe6Lx8U1eZtmfjsyohjB5TwLszij2pu4uiH4NGbF"
}
],
[
"1bLdd7zvNvjGpseQ8BGbGJekCppb1X5Gb228c9MQfHfmmBr",
"1bLdd7zvNvjGpseQ8BGbGJekCppb1X5Gb228c9MQfHfmmBr",
{
"aura": "14QNHMVxTUFs4HfPZoZtLpZXR9cvPhEDGvUyNPusznKVpCzC"
}
]
]' |
jq '.genesis.runtimeGenesis.patch.polkadotXcm.safeXcmVersion = 3' \
> people-polkadot-genesis.json


## Convert to raw
$polkadot_parachain build-spec --raw --chain ./people-polkadot-genesis.json > people-polkadot.json

## Cleanup
rm -f rt-hex.txt
rm -f chain-spec-plain.json

echo "The genesis wasm and head data can now be generated using the script in polkadot-sdk on the nacho/people-chain-spec-with-migation branch. This will also modify the chainspec"
echo "See https://github.com/paritytech/polkadot-sdk/blob/0887f9ace688005ed78b21044b1b23bdab748c6d/cumulus/scripts/migrate_storage_to_genesis/README.md"
Loading