From 7515fc0385f8d48f2d08b2182a24174148e70135 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 17 Jan 2024 21:55:02 +1100 Subject: [PATCH] Introduce `chain-spec-generator` and document Weight Generation process (#127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://github.com/polkadot-fellows/runtimes/issues/50 - Adds the `chain-spec-generator` from https://github.com/polkadot-fellows/runtimes/pull/78 and https://github.com/polkadot-fellows/runtimes/pull/81, updated to work with `master`. - Adds detailed instructions to the `README.md` for generating weights for fellowship runtimes I am currently generating weights and will add them in a seperate PR when they are ready. TODO - [x] Add step for checking weight outputs using https://github.com/ggwpez/substrate-weight-compare in readme - [ ] Fix encointer chain spec defaults, or open new issue for it ### Why not use the `polkadot-sdk` generic chain-spec-builder? The genesis state configs generated by this CLI are unusable for benchmarking, due to poor defaults. We need better defaults for our pallet genesis state before we can use this CLI. See also https://github.com/paritytech/polkadot-sdk/issues/2713. --------- Co-authored-by: Bastian Köcher Co-authored-by: Javier Viola Co-authored-by: NachoPal Co-authored-by: Svyatoslav Nikolsky Co-authored-by: Branislav Kontur Co-authored-by: Oliver Tale-Yazdi Co-authored-by: Bastian Köcher --- CHANGELOG.md | 2 + Cargo.lock | 357 ++++++--- Cargo.toml | 1 + README.md | 1 + chain-spec-generator/Cargo.toml | 54 ++ chain-spec-generator/src/common.rs | 95 +++ chain-spec-generator/src/main.rs | 108 +++ chain-spec-generator/src/relay_chain_specs.rs | 493 ++++++++++++ .../src/system_parachains_specs.rs | 710 ++++++++++++++++++ docs/weight-generation.md | 88 +++ 10 files changed, 1814 insertions(+), 95 deletions(-) create mode 100644 chain-spec-generator/Cargo.toml create mode 100644 chain-spec-generator/src/common.rs create mode 100644 chain-spec-generator/src/main.rs create mode 100644 chain-spec-generator/src/relay_chain_specs.rs create mode 100644 chain-spec-generator/src/system_parachains_specs.rs create mode 100644 docs/weight-generation.md diff --git a/CHANGELOG.md b/CHANGELOG.md index d28e030feb..f9fb769526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added + +- Introduce chain spec generator ([polkadot-fellows/runtimes#127](https://github.com/polkadot-fellows/runtimes/pull/127)) - Add [Encointer](https://encointer.org) system parachain runtime, completing [RFC22](https://github.com/polkadot-fellows/RFCs/blob/main/text/0022-adopt-encointer-runtime.md) ([polkadot-fellows/runtimes#80](https://github.com/polkadot-fellows/runtimes/pull/80)) ## [1.1.0] 10.01.2024 diff --git a/Cargo.lock b/Cargo.lock index f51de76060..51ad1c2b9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,9 +211,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" dependencies = [ "anstyle", "anstyle-parse", @@ -249,12 +249,12 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "3.0.1" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -840,7 +840,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -976,7 +976,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -1869,6 +1869,41 @@ dependencies = [ "zeroize", ] +[[package]] +name = "chain-spec-generator" +version = "1.0.0" +dependencies = [ + "asset-hub-kusama-runtime", + "asset-hub-polkadot-runtime", + "bridge-hub-kusama-runtime", + "bridge-hub-polkadot-runtime", + "clap", + "collectives-polkadot-runtime", + "cumulus-primitives-core", + "encointer-kusama-runtime", + "glutton-kusama-runtime", + "hex-literal", + "kusama-runtime-constants", + "pallet-im-online", + "pallet-staking", + "parachains-common", + "polkadot-primitives", + "polkadot-runtime", + "polkadot-runtime-constants", + "polkadot-runtime-parachains", + "sc-chain-spec", + "sc-consensus-grandpa", + "serde", + "serde_json", + "sp-authority-discovery", + "sp-consensus-babe", + "sp-consensus-beefy", + "sp-core", + "sp-runtime", + "staging-kusama-runtime", + "staging-xcm", +] + [[package]] name = "chrono" version = "0.4.27" @@ -1947,9 +1982,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.7" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" +checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" dependencies = [ "clap_builder", "clap_derive", @@ -1957,9 +1992,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.7" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" +checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" dependencies = [ "anstream", "anstyle", @@ -1976,7 +2011,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -2563,10 +2598,10 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84baea20d10325b2501b6fa06d4a7902a43d6a6c62c71b5309e75c3ad8ae1441" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -2788,7 +2823,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -2815,7 +2850,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -2832,7 +2867,7 @@ checksum = "50c49547d73ba8dcfd4ad7325d64c6d5391ff4224d498fc39a6f3f49825a530d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3103,23 +3138,23 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] name = "docify" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4235e9b248e2ba4b92007fe9c646f3adf0ffde16dc74713eacc92b8bc58d8d2f" +checksum = "7cc4fd38aaa9fb98ac70794c82a00360d1e165a87fbf96a8a91f9dfc602aaee2" dependencies = [ "docify_macros", ] [[package]] name = "docify_macros" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47020e12d7c7505670d1363dd53d6c23724f71a90a3ae32ff8eba40de8404626" +checksum = "63fa215f3a0d40fb2a221b3aa90d8e1fbb8379785a990cb60d62ac71ebdc6460" dependencies = [ "common-path", "derive-syn-parse", @@ -3127,9 +3162,9 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.38", + "syn 2.0.41", "termcolor", - "toml 0.7.6", + "toml 0.8.2", "walkdir", ] @@ -3466,7 +3501,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3477,7 +3512,7 @@ checksum = "c2ad8cef1d801a4686bfd8919f0b30eac4c8e48968c437a6405ded4fb5272d2b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3608,7 +3643,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3656,7 +3691,7 @@ checksum = "f5aa1e3ae159e592ad222dc90c5acbad632b527779ba88486abe92782ab268bd" dependencies = [ "expander 0.0.4", "indexmap 1.9.3", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -3836,10 +3871,10 @@ version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03911cf3675af64252a6de7b4f383eafa80d5ea5830184e7a0739aeb0b95272d" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3971,7 +4006,7 @@ dependencies = [ "proc-macro2", "quote", "sp-core-hashing", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3981,10 +4016,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3ac1266522a8c9a2d2d26d205ec3028b88582d5f3cd5cbc75d0ec8271d197b7" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -3995,7 +4030,7 @@ checksum = "d9c078db2242ea7265faa486004e7fd8daaf1a577cfcac0070ce55d926922883" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -4151,7 +4186,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -5078,7 +5113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44e8ab85614a08792b9bff6c8feee23be78c98d0182d4c622c05256ab553892a" dependencies = [ "heck", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -5884,7 +5919,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -5898,7 +5933,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -5909,7 +5944,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -5920,7 +5955,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -6183,7 +6218,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", @@ -6526,7 +6561,7 @@ dependencies = [ "indexmap 2.0.0", "itertools 0.11.0", "petgraph", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -7879,10 +7914,10 @@ version = "10.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8878e29f3d001ac1b1b714621f462e41a9d1fa8f385657f955e8a1ec0684d7" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -8250,9 +8285,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.9" +version = "3.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +checksum = "dd8e946cc0cc711189c0b0249fb8b599cbeeab9784d83c415719368bb8d4ac64" dependencies = [ "arrayvec 0.7.4", "bitvec", @@ -8265,11 +8300,11 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.9" +version = "3.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" dependencies = [ - "proc-macro-crate 2.0.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -8519,7 +8554,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -9127,7 +9162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c64d9ba0963cdcea2e1b2230fbae2bab30eb25a174be395c41e764bfb65dd62" dependencies = [ "proc-macro2", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -9171,15 +9206,6 @@ dependencies = [ "toml_edit 0.19.14", ] -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.2", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -9218,7 +9244,7 @@ checksum = "9b698b0b09d40e9b7c1a47b132d66a8b54bcd20583d9b6d06e4535e383b4405c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -9264,7 +9290,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -9591,7 +9617,7 @@ checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -10090,10 +10116,10 @@ version = "10.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f25158f791eb48715da9322375598b541cadd1f193674e8a4d77c79ffa3d95d" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -10218,6 +10244,48 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sc-consensus-grandpa" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cbc5db21ea2c4ba65b23315e73e69e8155630fb47c84b93d40b0e759c9d86d" +dependencies = [ + "ahash 0.8.3", + "array-bytes 6.1.0", + "async-trait", + "dyn-clone", + "finality-grandpa", + "fork-tree", + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.8.5", + "sc-block-builder", + "sc-chain-spec", + "sc-client-api", + "sc-consensus", + "sc-network", + "sc-network-common", + "sc-network-gossip", + "sc-telemetry", + "sc-transaction-pool-api", + "sc-utils", + "serde_json", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-consensus-grandpa", + "sp-core", + "sp-keystore", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror", +] + [[package]] name = "sc-executor" version = "0.29.0" @@ -10415,6 +10483,25 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "sc-network-gossip" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b884a9f7cd348c4c1899c0bbf95237e39dffba4baec48d4b98c1046f6bb04fa5" +dependencies = [ + "ahash 0.8.3", + "futures", + "futures-timer", + "libp2p", + "log", + "sc-network", + "sc-network-common", + "schnellru", + "sp-runtime", + "substrate-prometheus-endpoint", + "tracing", +] + [[package]] name = "sc-network-light" version = "0.30.0" @@ -10744,10 +10831,10 @@ version = "10.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c4ae9e4f957d7274ac6b59d667b66262caf6482dbb1b63f1c370528626b1272" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -10830,7 +10917,7 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -11037,29 +11124,29 @@ checksum = "f97841a747eef040fcd2e7b3b9a220a7205926e60488e673d9e4926d27772ce5" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" dependencies = [ "itoa", "ryu", @@ -11238,9 +11325,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" [[package]] name = "snap" @@ -11333,10 +11420,10 @@ dependencies = [ "Inflector", "blake2 0.10.6", "expander 2.0.0", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -11588,7 +11675,7 @@ checksum = "42ce3e6931303769197da81facefa86159fa1085dcd96ecb7e7407b5b93582a0" dependencies = [ "quote", "sp-core-hashing", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -11609,7 +11696,7 @@ checksum = "50535e1a5708d3ba5c1195b59ebefac61cc8679c2c24716b87a86e8b7ed2e4a1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -11852,10 +11939,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b2afcbd1bd18d323371111b66b7ac2870bdc1c86c3d7b0dae67b112ca52b4d8" dependencies = [ "Inflector", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -12061,7 +12148,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -12551,9 +12638,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" dependencies = [ "proc-macro2", "quote", @@ -12664,7 +12751,7 @@ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -12839,7 +12926,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -12911,6 +12998,18 @@ dependencies = [ "toml_edit 0.19.14", ] +[[package]] +name = "toml" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.20.2", +] + [[package]] name = "toml_datetime" version = "0.6.3" @@ -12940,6 +13039,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap 2.0.0", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] @@ -13006,7 +13107,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -13049,10 +13150,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35756d8c1a227ec525853a1080bf890d03d939deb2bc50d4d43c96516c795d0d" dependencies = [ "expander 2.0.0", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -13446,7 +13547,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", "wasm-bindgen-shared", ] @@ -13480,7 +13581,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -14136,6 +14237,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -14166,6 +14276,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -14178,6 +14303,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.34.0" @@ -14196,6 +14327,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.34.0" @@ -14214,6 +14351,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.34.0" @@ -14232,6 +14375,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.34.0" @@ -14250,6 +14399,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -14262,6 +14417,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.34.0" @@ -14280,6 +14441,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "winnow" version = "0.5.15" @@ -14410,7 +14577,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] @@ -14453,7 +14620,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.41", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ffa140147d..d27df9f555 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ license = "GPL-3.0-only" # TODO . + +use crate::{ + relay_chain_specs::{KusamaChainSpec, PolkadotChainSpec}, + system_parachains_specs::{ + AssetHubKusamaChainSpec, AssetHubPolkadotChainSpec, BridgeHubKusamaChainSpec, + BridgeHubPolkadotChainSpec, CollectivesPolkadotChainSpec, EncointerKusamaChainSpec, + GluttonKusamaChainSpec, + }, + ChainSpec, +}; +use polkadot_primitives::{AccountId, AccountPublic}; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::traits::IdentifyAccount; + +pub fn testnet_accounts() -> Vec { + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ] +} + +/// Helper function to generate a crypto pair from seed +pub fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// Helper function to generate an account ID from seed +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +#[derive(Debug, serde::Deserialize)] +struct EmptyChainSpecWithId { + id: String, +} + +pub fn from_json_file(filepath: &str, supported: String) -> Result, String> { + let path = std::path::PathBuf::from(&filepath); + let file = std::fs::File::open(&filepath).expect("Failed to open file"); + let reader = std::io::BufReader::new(file); + let chain_spec: EmptyChainSpecWithId = serde_json::from_reader(reader) + .expect("Failed to read 'json' file with ChainSpec configuration"); + match &chain_spec.id { + x if x.starts_with("polkadot") | x.starts_with("dot") => + Ok(Box::new(PolkadotChainSpec::from_json_file(path)?)), + x if x.starts_with("kusama") | x.starts_with("ksm") => + Ok(Box::new(KusamaChainSpec::from_json_file(path)?)), + x if x.starts_with("asset-hub-polkadot") => + Ok(Box::new(AssetHubPolkadotChainSpec::from_json_file(path)?)), + x if x.starts_with("asset-hub-kusama") => + Ok(Box::new(AssetHubKusamaChainSpec::from_json_file(path)?)), + x if x.starts_with("collectives-polkadot") => + Ok(Box::new(CollectivesPolkadotChainSpec::from_json_file(path)?)), + x if x.starts_with("bridge-hub-polkadot") => + Ok(Box::new(BridgeHubPolkadotChainSpec::from_json_file(path)?)), + x if x.starts_with("bridge-hub-kusama") => + Ok(Box::new(BridgeHubKusamaChainSpec::from_json_file(path)?)), + x if x.starts_with("glutton-kusama") => + Ok(Box::new(GluttonKusamaChainSpec::from_json_file(path)?)), + x if x.starts_with("encointer-kusama") => + Ok(Box::new(EncointerKusamaChainSpec::from_json_file(path)?)), + _ => Err(format!("Unknown chain 'id' in json file. Only supported: {supported}'")), + } +} diff --git a/chain-spec-generator/src/main.rs b/chain-spec-generator/src/main.rs new file mode 100644 index 0000000000..d24cc8766a --- /dev/null +++ b/chain-spec-generator/src/main.rs @@ -0,0 +1,108 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// 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 . + +use clap::Parser; +use sc_chain_spec::ChainSpec; +use std::collections::HashMap; + +mod common; +mod relay_chain_specs; +mod system_parachains_specs; + +#[derive(Parser)] +struct Cli { + /// The chain spec to generate. + chain: String, + + /// Generate the chain spec as raw? + #[arg(long)] + raw: bool, +} + +fn main() -> Result<(), String> { + let cli = Cli::parse(); + + let supported_chains = + HashMap::<_, Box Result, String>>>::from([ + ( + "polkadot-dev", + Box::new(|| relay_chain_specs::polkadot_development_config()) as Box<_>, + ), + ( + "polkadot-local", + Box::new(|| relay_chain_specs::polkadot_local_testnet_config()) as Box<_>, + ), + ("kusama-dev", Box::new(|| relay_chain_specs::kusama_development_config()) as Box<_>), + ( + "kusama-local", + Box::new(|| relay_chain_specs::kusama_local_testnet_config()) as Box<_>, + ), + ( + "asset-hub-kusama-local", + Box::new(|| system_parachains_specs::asset_hub_kusama_local_testnet_config()) + as Box<_>, + ), + ( + "asset-hub-polkadot-local", + Box::new(|| system_parachains_specs::asset_hub_polkadot_local_testnet_config()) + as Box<_>, + ), + ( + "collectives-polkadot-local", + Box::new(|| system_parachains_specs::collectives_polkadot_local_testnet_config()) + as Box<_>, + ), + ( + "bridge-hub-polkadot-local", + Box::new(|| system_parachains_specs::bridge_hub_polkadot_local_testnet_config()) + as Box<_>, + ), + ( + "bridge-hub-kusama-local", + Box::new(|| system_parachains_specs::bridge_hub_kusama_local_testnet_config()) + as Box<_>, + ), + ( + "glutton-kusama-local", + Box::new(|| system_parachains_specs::glutton_kusama_local_testnet_config()) + as Box<_>, + ), + ( + "encointer-kusama-local", + Box::new(|| system_parachains_specs::encointer_kusama_local_testnet_config()) + as Box<_>, + ), + ]); + + if let Some(function) = supported_chains.get(&*cli.chain) { + let chain_spec = (*function)()?.as_json(cli.raw)?; + print!("{chain_spec}"); + Ok(()) + } else { + let supported = supported_chains.keys().enumerate().fold(String::new(), |c, (n, k)| { + let extra = (n + 1 < supported_chains.len()).then(|| ", ").unwrap_or(""); + format!("{c}{k}{extra}") + }); + if cli.chain.ends_with(".json") { + let chain_spec = common::from_json_file(&cli.chain, supported)?.as_json(cli.raw)?; + print!("{chain_spec}"); + Ok(()) + } else { + Err(format!("Unknown chain, only supported: {supported} or a json file")) + } + } +} diff --git a/chain-spec-generator/src/relay_chain_specs.rs b/chain-spec-generator/src/relay_chain_specs.rs new file mode 100644 index 0000000000..b6b58ba5d8 --- /dev/null +++ b/chain-spec-generator/src/relay_chain_specs.rs @@ -0,0 +1,493 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// 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 . + +use kusama_runtime_constants::currency::UNITS as KSM; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use pallet_staking::Forcing; +use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +use polkadot_runtime_constants::currency::UNITS as DOT; +use polkadot_runtime_parachains::configuration::HostConfiguration; +use sc_chain_spec::{ChainSpec, ChainType, NoExtension}; +use sc_consensus_grandpa::AuthorityId as GrandpaId; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; +use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::{traits::IdentifyAccount, Perbill}; + +pub type PolkadotChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type KusamaChainSpec = + sc_chain_spec::GenericChainSpec; + +const DEFAULT_PROTOCOL_ID: &str = "dot"; + +/// Returns the properties for the [`PolkadotChainSpec`]. +pub fn polkadot_chain_spec_properties() -> serde_json::map::Map { + serde_json::json!({ + "tokenDecimals": 10, + }) + .as_object() + .expect("Map given; qed") + .clone() +} + +fn default_parachains_host_configuration() -> HostConfiguration { + use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + + polkadot_runtime_parachains::configuration::HostConfiguration { + validation_upgrade_cooldown: 2u32, + validation_upgrade_delay: 2, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + group_rotation_frequency: 20, + paras_availability_period: 4, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024 * 1024, + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + minimum_validation_upgrade_delay: 5, + ..Default::default() + } +} + +fn polkadot_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> polkadot_runtime::SessionKeys { + polkadot_runtime::SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + beefy, + } +} + +fn kusama_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> kusama_runtime::SessionKeys { + kusama_runtime::SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + beefy, + } +} + +/// Helper function to generate a crypto pair from seed +pub fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// Helper function to generate an account ID from seed +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +/// Helper function to generate stash, controller and session key from seed +pub fn get_authority_keys_from_seed( + seed: &str, +) -> ( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, +) { + let keys = get_authority_keys_from_seed_no_beefy(seed); + (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, keys.7, get_from_seed::(seed)) +} + +/// Helper function to generate stash, controller and session key from seed +pub fn get_authority_keys_from_seed_no_beefy( + seed: &str, +) -> ( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, +) { + ( + get_account_id_from_seed::(&format!("{}//stash", seed)), + get_account_id_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + ) +} + +fn testnet_accounts() -> Vec { + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ] +} + +pub fn polkadot_testnet_genesis( + wasm_binary: &[u8], + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> polkadot_runtime::RuntimeGenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * DOT; + const STASH: u128 = 100 * DOT; + + polkadot_runtime::RuntimeGenesisConfig { + beefy: Default::default(), + system: polkadot_runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + indices: polkadot_runtime::IndicesConfig { indices: vec![] }, + balances: polkadot_runtime::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }, + session: polkadot_runtime::SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + polkadot_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + x.8.clone(), + ), + ) + }) + .collect::>(), + }, + staking: polkadot_runtime::StakingConfig { + minimum_validator_count: 1, + validator_count: initial_authorities.len() as u32, + stakers: initial_authorities + .iter() + .map(|x| { + (x.0.clone(), x.0.clone(), STASH, polkadot_runtime::StakerStatus::Validator) + }) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: polkadot_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(polkadot_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: polkadot_runtime::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + claims: polkadot_runtime::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: polkadot_runtime::VestingConfig { vesting: vec![] }, + treasury: Default::default(), + hrmp: Default::default(), + configuration: polkadot_runtime::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + } +} + +/// Helper function to create kusama `RuntimeGenesisConfig` for testing +pub fn kusama_testnet_genesis( + wasm_binary: &[u8], + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> kusama_runtime::RuntimeGenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * KSM; + const STASH: u128 = 100 * KSM; + + kusama_runtime::RuntimeGenesisConfig { + system: kusama_runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + indices: kusama_runtime::IndicesConfig { indices: vec![] }, + balances: kusama_runtime::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }, + beefy: Default::default(), + session: kusama_runtime::SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + kusama_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + x.8.clone(), + ), + ) + }) + .collect::>(), + }, + staking: kusama_runtime::StakingConfig { + minimum_validator_count: 1, + validator_count: initial_authorities.len() as u32, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama_runtime::StakerStatus::Validator)) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: kusama_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(kusama_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: kusama_runtime::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + claims: kusama_runtime::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: kusama_runtime::VestingConfig { vesting: vec![] }, + treasury: Default::default(), + hrmp: Default::default(), + configuration: kusama_runtime::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + nis_counterpart_balances: Default::default(), + } +} + +fn polkadot_development_config_genesis( + wasm_binary: &[u8], +) -> polkadot_runtime::RuntimeGenesisConfig { + polkadot_testnet_genesis( + wasm_binary, + vec![get_authority_keys_from_seed("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +fn kusama_development_config_genesis(wasm_binary: &[u8]) -> kusama_runtime::RuntimeGenesisConfig { + kusama_testnet_genesis( + wasm_binary, + vec![get_authority_keys_from_seed("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Polkadot development config (single validator Alice) +pub fn polkadot_development_config() -> Result, String> { + let wasm_binary = + polkadot_runtime::WASM_BINARY.ok_or("Polkadot development wasm not available")?; + + Ok(Box::new(PolkadotChainSpec::from_genesis( + "Polakdot Development", + "polkadot-dev", + ChainType::Development, + move || polkadot_development_config_genesis(wasm_binary), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + Some(polkadot_chain_spec_properties()), + Default::default(), + ))) +} + +/// Kusama development config (single validator Alice) +pub fn kusama_development_config() -> Result, String> { + let wasm_binary = kusama_runtime::WASM_BINARY.ok_or("Kusama development wasm not available")?; + + Ok(Box::new(KusamaChainSpec::from_genesis( + "Kusama Development", + "kusama-dev", + ChainType::Development, + move || kusama_development_config_genesis(wasm_binary), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + ))) +} + +fn polkadot_local_testnet_genesis(wasm_binary: &[u8]) -> polkadot_runtime::RuntimeGenesisConfig { + polkadot_testnet_genesis( + wasm_binary, + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Polkadot local testnet config (multivalidator Alice + Bob) +pub fn polkadot_local_testnet_config() -> Result, String> { + let wasm_binary = + polkadot_runtime::WASM_BINARY.ok_or("Polkadot development wasm not available")?; + + Ok(Box::new(PolkadotChainSpec::from_genesis( + "Polkadot Local Testnet", + "polkadot-local", + ChainType::Local, + move || polkadot_local_testnet_genesis(wasm_binary), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + Some(polkadot_chain_spec_properties()), + Default::default(), + ))) +} + +fn kusama_local_testnet_genesis(wasm_binary: &[u8]) -> kusama_runtime::RuntimeGenesisConfig { + kusama_testnet_genesis( + wasm_binary, + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Kusama local testnet config (multivalidator Alice + Bob) +pub fn kusama_local_testnet_config() -> Result, String> { + let wasm_binary = kusama_runtime::WASM_BINARY.ok_or("Kusama development wasm not available")?; + + Ok(Box::new(KusamaChainSpec::from_genesis( + "Kusama Local Testnet", + "kusama-local", + ChainType::Local, + move || kusama_local_testnet_genesis(wasm_binary), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + ))) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn default_parachains_host_configuration_is_consistent() { + default_parachains_host_configuration().panic_if_not_consistent(); + } +} diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs new file mode 100644 index 0000000000..83d7caa0af --- /dev/null +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -0,0 +1,710 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// 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 . + +use crate::common::{get_account_id_from_seed, get_from_seed, testnet_accounts}; +use cumulus_primitives_core::ParaId; +use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance}; +use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup, ChainType}; +use serde::{Deserialize, Serialize}; +use sp_core::sr25519; + +/// Generic extensions for Parachain ChainSpecs. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +#[serde(deny_unknown_fields)] +pub struct Extensions { + /// The relay chain of the Parachain. + pub relay_chain: String, + /// The id of the Parachain. + pub para_id: u32, +} + +pub type AssetHubPolkadotChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type AssetHubKusamaChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type CollectivesPolkadotChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type BridgeHubPolkadotChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type BridgeHubKusamaChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type GluttonKusamaChainSpec = + sc_chain_spec::GenericChainSpec; + +pub type EncointerKusamaChainSpec = + sc_chain_spec::GenericChainSpec; + +const ASSET_HUB_POLKADOT_ED: Balance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; + +const ASSET_HUB_KUSAMA_ED: Balance = parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; + +const COLLECTIVES_POLKADOT_ED: Balance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; + +const BRIDGE_HUB_POLKADOT_ED: Balance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; + +const BRIDGE_HUB_KUSAMA_ED: Balance = parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; + +const ENCOINTER_KUSAMA_ED: Balance = parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; + +/// The default XCM version to set in genesis config. +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; + +/// Invulnerable Collators +pub fn invulnerables() -> Vec<(AccountId, AuraId)> { + vec![ + (get_account_id_from_seed::("Alice"), get_from_seed::("Alice")), + (get_account_id_from_seed::("Bob"), get_from_seed::("Bob")), + ] +} + +/// Invulnerable Collators for the particular case of AssetHubPolkadot +pub fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAuraId)> { + vec![ + ( + get_account_id_from_seed::("Alice"), + get_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_from_seed::("Bob"), + ), + ] +} + +/// 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 asset_hub_polkadot_session_keys( + keys: AssetHubPolkadotAuraId, +) -> asset_hub_polkadot_runtime::SessionKeys { + asset_hub_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). +pub fn asset_hub_kusama_session_keys(keys: AuraId) -> asset_hub_kusama_runtime::SessionKeys { + 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). +pub fn bridge_hub_polkadot_session_keys(keys: AuraId) -> bridge_hub_polkadot_runtime::SessionKeys { + bridge_hub_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). +pub fn bridge_hub_kusama_session_keys(keys: AuraId) -> bridge_hub_kusama_runtime::SessionKeys { + bridge_hub_kusama_runtime::SessionKeys { aura: keys } +} + +// AssetHubPolkadot +fn asset_hub_polkadot_genesis( + wasm_binary: &[u8], + invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> asset_hub_polkadot_runtime::RuntimeGenesisConfig { + asset_hub_polkadot_runtime::RuntimeGenesisConfig { + system: asset_hub_polkadot_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + balances: asset_hub_polkadot_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: asset_hub_polkadot_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_POLKADOT_ED * 16, + ..Default::default() + }, + session: asset_hub_polkadot_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_polkadot_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. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +fn asset_hub_polkadot_local_genesis( + wasm_binary: &[u8], +) -> asset_hub_polkadot_runtime::RuntimeGenesisConfig { + asset_hub_polkadot_genesis( + // initial collators. + wasm_binary, + invulnerables_asset_hub_polkadot(), + testnet_accounts(), + 1000.into(), + ) +} + +pub fn asset_hub_polkadot_local_testnet_config() -> Result, 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()); + + let wasm_binary = + asset_hub_polkadot_runtime::WASM_BINARY.ok_or("AssetHubPolkadot wasm not available")?; + + Ok(Box::new(AssetHubPolkadotChainSpec::from_genesis( + // Name + "Polkadot Asset Hub Local", + // ID + "asset-hub-polkadot-local", + ChainType::Local, + move || asset_hub_polkadot_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, + ))) +} + +// AssetHubKusama +fn asset_hub_kusama_genesis( + wasm_binary: &[u8], + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> asset_hub_kusama_runtime::RuntimeGenesisConfig { + asset_hub_kusama_runtime::RuntimeGenesisConfig { + system: asset_hub_kusama_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + balances: asset_hub_kusama_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_KUSAMA_ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: asset_hub_kusama_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_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(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +fn asset_hub_kusama_local_genesis( + wasm_binary: &[u8], +) -> asset_hub_kusama_runtime::RuntimeGenesisConfig { + asset_hub_kusama_genesis( + // initial collators. + wasm_binary, + invulnerables(), + testnet_accounts(), + 1000.into(), + ) +} + +pub fn asset_hub_kusama_local_testnet_config() -> Result, String> { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + let wasm_binary = + asset_hub_kusama_runtime::WASM_BINARY.ok_or("AssetHubKusama wasm not available")?; + + Ok(Box::new(AssetHubKusamaChainSpec::from_genesis( + // Name + "Kusama Asset Hub Local", + // ID + "asset-hub-kusama-local", + ChainType::Local, + move || asset_hub_kusama_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, + ))) +} + +// CollectivesPolkadot +fn collectives_polkadot_genesis( + wasm_binary: &[u8], + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> collectives_polkadot_runtime::RuntimeGenesisConfig { + collectives_polkadot_runtime::RuntimeGenesisConfig { + system: collectives_polkadot_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + balances: collectives_polkadot_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096)) + .collect(), + }, + parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: 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(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: collectives_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + alliance: Default::default(), + alliance_motion: Default::default(), + } +} + +fn collectives_polkadot_local_genesis( + wasm_binary: &[u8], +) -> collectives_polkadot_runtime::RuntimeGenesisConfig { + collectives_polkadot_genesis( + // initial collators. + wasm_binary, + invulnerables(), + testnet_accounts(), + 1001.into(), + ) +} + +pub fn collectives_polkadot_local_testnet_config() -> Result, 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()); + + let wasm_binary = collectives_polkadot_runtime::WASM_BINARY + .ok_or("CollectivesPolkadot wasm not available")?; + + Ok(Box::new(CollectivesPolkadotChainSpec::from_genesis( + // Name + "Polkadot Collectives Local", + // ID + "collectives-polkadot-local", + ChainType::Local, + move || collectives_polkadot_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1001 }, + ))) +} + +// BridgeHubPolkadot +fn bridge_hub_polkadot_genesis( + wasm_binary: &[u8], + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> bridge_hub_polkadot_runtime::RuntimeGenesisConfig { + bridge_hub_polkadot_runtime::RuntimeGenesisConfig { + system: bridge_hub_polkadot_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + balances: bridge_hub_polkadot_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, BRIDGE_HUB_POLKADOT_ED * 4096)) + .collect(), + }, + parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: bridge_hub_polkadot_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: BRIDGE_HUB_POLKADOT_ED * 16, + ..Default::default() + }, + session: bridge_hub_polkadot_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + bridge_hub_polkadot_session_keys(aura), // session keys + ) + }) + .collect(), + }, + bridge_kusama_grandpa: Default::default(), + bridge_kusama_messages: Default::default(), + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +fn bridge_hub_polkadot_local_genesis( + wasm_binary: &[u8], +) -> bridge_hub_polkadot_runtime::RuntimeGenesisConfig { + bridge_hub_polkadot_genesis( + // initial collators. + wasm_binary, + invulnerables(), + testnet_accounts(), + 1002.into(), + ) +} + +pub fn bridge_hub_polkadot_local_testnet_config() -> Result, 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()); + + let wasm_binary = + bridge_hub_polkadot_runtime::WASM_BINARY.ok_or("BridgeHubPolkadot wasm not available")?; + + Ok(Box::new(BridgeHubPolkadotChainSpec::from_genesis( + // Name + "Polkadot Bridge Hub Local", + // ID + "bridge-hub-polkadot-local", + ChainType::Local, + move || bridge_hub_polkadot_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, + ))) +} + +// BridgeHubKusama +fn bridge_hub_kusama_genesis( + wasm_binary: &[u8], + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> bridge_hub_kusama_runtime::RuntimeGenesisConfig { + bridge_hub_kusama_runtime::RuntimeGenesisConfig { + system: bridge_hub_kusama_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + balances: bridge_hub_kusama_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, BRIDGE_HUB_KUSAMA_ED * 4096)) + .collect(), + }, + parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: bridge_hub_kusama_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: BRIDGE_HUB_KUSAMA_ED * 16, + ..Default::default() + }, + session: bridge_hub_kusama_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + bridge_hub_kusama_session_keys(aura), // session keys + ) + }) + .collect(), + }, + bridge_polkadot_grandpa: Default::default(), + bridge_polkadot_messages: Default::default(), + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +fn bridge_hub_kusama_local_genesis( + wasm_binary: &[u8], +) -> bridge_hub_kusama_runtime::RuntimeGenesisConfig { + bridge_hub_kusama_genesis( + // initial collators. + wasm_binary, + invulnerables(), + testnet_accounts(), + 1002.into(), + ) +} + +pub fn bridge_hub_kusama_local_testnet_config() -> Result, String> { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + let wasm_binary = + bridge_hub_kusama_runtime::WASM_BINARY.ok_or("BridgeHubKusama wasm not available")?; + + Ok(Box::new(BridgeHubKusamaChainSpec::from_genesis( + // Name + "Kusama Bridge Hub Local", + // ID + "bridge-hub-kusama-local", + ChainType::Local, + move || bridge_hub_kusama_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama-local".into(), para_id: 1002 }, + ))) +} + +// GluttonKusama +fn glutton_kusama_genesis( + wasm_binary: &[u8], + id: ParaId, +) -> glutton_kusama_runtime::RuntimeGenesisConfig { + glutton_kusama_runtime::RuntimeGenesisConfig { + system: glutton_kusama_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + glutton: Default::default(), + sudo: Default::default(), + parachain_system: Default::default(), + parachain_info: glutton_kusama_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + } +} + +fn glutton_kusama_local_genesis( + wasm_binary: &[u8], +) -> glutton_kusama_runtime::RuntimeGenesisConfig { + glutton_kusama_genesis(wasm_binary, 1002.into()) +} + +pub fn glutton_kusama_local_testnet_config() -> Result, String> { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + let wasm_binary = + glutton_kusama_runtime::WASM_BINARY.ok_or("GluttonKusama wasm not available")?; + + Ok(Box::new(GluttonKusamaChainSpec::from_genesis( + // Name + "Glutton Kusama Local", + // ID + "glutton-kusama-local", + ChainType::Local, + move || glutton_kusama_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama-local".into(), para_id: 1002 }, + ))) +} + +// EncointerKusama +fn encointer_kusama_genesis( + wasm_binary: &[u8], + endowed_accounts: Vec, + id: ParaId, +) -> encointer_kusama_runtime::RuntimeGenesisConfig { + encointer_kusama_runtime::RuntimeGenesisConfig { + system: encointer_kusama_runtime::SystemConfig { + code: wasm_binary.to_vec(), + ..Default::default() + }, + balances: encointer_kusama_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ENCOINTER_KUSAMA_ED * 4096)) + .collect(), + }, + parachain_info: encointer_kusama_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collective: Default::default(), + encointer_balances: Default::default(), + encointer_ceremonies: Default::default(), + encointer_communities: Default::default(), + encointer_faucet: Default::default(), + encointer_scheduler: Default::default(), + membership: Default::default(), + treasury: Default::default(), + aura: encointer_kusama_runtime::AuraConfig { + authorities: vec![get_from_seed::("Alice").into()], + }, + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: encointer_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +fn encointer_kusama_local_genesis( + wasm_binary: &[u8], +) -> encointer_kusama_runtime::RuntimeGenesisConfig { + encointer_kusama_genesis( + // initial collators. + wasm_binary, + testnet_accounts(), + 1001.into(), + ) +} + +pub fn encointer_kusama_local_testnet_config() -> Result, String> { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + let wasm_binary = + encointer_kusama_runtime::WASM_BINARY.ok_or("EncointerKusama wasm not available")?; + + Ok(Box::new(EncointerKusamaChainSpec::from_genesis( + // Name + "Kusama Encointer Local", + // ID + "encointer-kusama-local", + ChainType::Local, + move || encointer_kusama_local_genesis(wasm_binary), + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama-local".into(), para_id: 1001 }, + ))) +} diff --git a/docs/weight-generation.md b/docs/weight-generation.md new file mode 100644 index 0000000000..9a1eae34e7 --- /dev/null +++ b/docs/weight-generation.md @@ -0,0 +1,88 @@ +# Weight Generation + +To generate weights for a runtime + +1. Build `chain-spec-generator` with `--profile production --features runtime-benchmarks` +2. Use it to build a chain spec for your runtime, e.g. `./target/production/chain-spec-generator --raw polkadot-local > polkadot-chain-spec.json` +3. Create `file_header.txt` + +```text +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// 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. +``` + +4. `rsync` chain spec/s and the file header to a benchmark machine + +5. Build `polkadot` binary from the latest release of `polkadot-sdk` with `--profile production --features runtime-benchmarks --bin polkadot` on the benchmark machine + +6. Run on the benchmark machine: + +```bash +#!/bin/bash + +# Default value is 'polkadot', but you can override it by passing a different value as an argument +CHAIN=${1:-polkadot} + +pallets=($( + ./target/production/polkadot benchmark pallet --list \ + --chain=./$CHAIN-chain-spec.json | + tail -n+2 | + cut -d',' -f1 | + sort | + uniq +)); + +mkdir -p ./$CHAIN-weights +for pallet in "${pallets[@]}"; do + output_file=./$CHAIN-weights/ + # a little hack for pallet_xcm_benchmarks - we want to output them to a nested directory + if [[ "$pallet" == "pallet_xcm_benchmarks::generic" ]] || [[ "$pallet" == "pallet_xcm_benchmarks::fungible" ]]; then + mkdir -p ./$CHAIN-weights/xcm + output_file="${output_file}xcm/${pallet//::/_}.rs" + fi + echo "Running benchmarks for $pallet to $output_file" + ./target/production/polkadot benchmark pallet \ + --chain=./$CHAIN-chain-spec.json \ + --steps=50 \ + --repeat=20 \ + --pallet=$pallet \ + --extrinsic=* \ + --wasm-execution=compiled \ + --heap-pages=4096 \ + --output="$output_file" \ + --header=./file_header.txt +done +``` + +You probably want to do this inside a `tmux` session or similar, as it will take a while. + +7. `rsync` the weights back to your local machine, replacing the existing weights. + +8. Manually fix XCM weights by +- Replacing `impl xxx::yyy::WeightInfo for WeightInfo {` with `impl WeightInfo {` +- Marking all functions `pub(crate)` +- Removing any unused functions + +9. Commit the weight changes. + +10. If not installed, `cargo install subweight`, and check the weight changes with `subweight compare commits --path-pattern "./**/weights/*.rs" --method asymptotic --ignore-errors HEAD origin/main`. Ensure the changes are reasonable. + +## FAQ + +### What benchmark machine spec should I use? + +See the [Polkadot Wiki Reference Hardware](https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#standard-hardware). +