From 39bb0ce2b09a58588ea1dabfd617151347ec907f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:50:14 +0200 Subject: [PATCH 01/83] GenesisBuilder: new function --- substrate/client/chain-spec/src/lib.rs | 2 +- substrate/primitives/genesis-builder/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 6a922e7b40b2..a80c380803d7 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -325,7 +325,7 @@ mod chain_spec; mod extension; mod genesis_block; mod genesis_config_builder; -mod json_patch; +pub mod json_patch; pub use self::{ chain_spec::{ diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index e002cd3aa6f7..17172311d832 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -41,6 +41,7 @@ sp_api::decl_runtime_apis! { /// This function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON /// blob. It returns a `Vec` containing the JSON representation of the default `GenesisConfig`. fn create_default_config() -> sp_std::vec::Vec; + fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec; /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. /// From d7ed0bb93148384a38550d0e4bc0c02e4fa6078c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:02:34 +0200 Subject: [PATCH 02/83] rococo: some initial thing --- polkadot/runtime/rococo/Cargo.toml | 3 +- polkadot/runtime/rococo/src/lib.rs | 629 ++++++++++++++++++++++++++--- 2 files changed, 568 insertions(+), 64 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index c7236572ed7d..346bb6a7c365 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -104,6 +104,7 @@ polkadot-parachain-primitives = { path = "../../parachain", default-features = f xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } +serde_json = { version = "1.0.108", default-features = false, features = ["alloc"] } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } @@ -111,7 +112,6 @@ keyring = { package = "sp-keyring", path = "../../../substrate/primitives/keyrin remote-externalities = { package = "frame-remote-externalities", path = "../../../substrate/utils/frame/remote-externalities" } sp-trie = { path = "../../../substrate/primitives/trie" } separator = "0.4.1" -serde_json = "1.0.108" sp-tracing = { path = "../../../substrate/primitives/tracing", default-features = false } tokio = { version = "1.24.2", features = ["macros"] } @@ -191,6 +191,7 @@ std = [ "scale-info/std", "serde/std", "serde_derive", + "serde_json/std", "sp-api/std", "sp-arithmetic/std", "sp-core/std", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index acc3f723cddf..ff033094f629 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1727,6 +1727,407 @@ mod benches { [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] ); } +fn default_parachains_host_configuration( +) -> runtime_parachains::configuration::HostConfiguration { + use primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + + 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() + } +} + +use babe_primitives::AuthorityId as BabeId; +use primitives::AssignmentId; +use sp_core::crypto::Public; +// use sp_core::{sr25519, Pair, 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() +// } +// +// 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"), +// ] +// } +// +fn rococo_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> SessionKeys { + SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + beefy, + } +} +pub fn rococo_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + root_key: AccountId, + endowed_accounts: Option>, +) -> serde_json::Value { + let endowed_accounts: Vec = endowed_accounts.unwrap(); + + const ENDOWMENT: u128 = 1_000_000 * UNITS; + + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), + }, + "session": { + "keys": initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + rococo_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + x.8.clone(), + ), + ) + }) + .collect::>(), + }, + "babe": { + "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), + }, + "sudo": { "key": Some(root_key.clone()) }, + "configuration": { + "config": runtime_parachains::configuration::HostConfiguration { + max_validators_per_core: Some(1), + ..default_parachains_host_configuration() + }, + }, + "registrar": { + "nextFreeParaId": primitives::LOWEST_PUBLIC_ID, + } + }) +} + +fn rococo_testnet_genesis_staging() -> serde_json::Value { + let endowed_accounts: sp_std::vec::Vec = vec![ + // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs + hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(), + ]; + + // ./scripts/prepare-test-net.sh 8 + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )> = vec![ + ( + //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei + hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(), + //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd + hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(), + //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H + hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"] + .unchecked_into(), + //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 + hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] + .unchecked_into(), + //5F7BEa1LGFksUihyatf3dCDYneB8pWzVyavnByCsm5nBgezi + hex!["86975a37211f8704e947a365b720f7a3e2757988eaa7d0f197e83dba355ef743"] + .unchecked_into(), + //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz + hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] + .unchecked_into(), + //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b + hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"] + .unchecked_into(), + //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq + hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"] + .unchecked_into(), + //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu + hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"] + .unchecked_into(), + ), + ( + //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG + hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(), + //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3 + hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(), + //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM + hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"] + .unchecked_into(), + //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao + hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] + .unchecked_into(), + //5DhyXZiuB1LvqYKFgT5tRpgGsN3is2cM9QxgW7FikvakbAZP + hex!["48a910c0af90898f11bd57d37ceaea53c78994f8e1833a7ade483c9a84bde055"] + .unchecked_into(), + //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF + hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] + .unchecked_into(), + //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ + hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"] + .unchecked_into(), + //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw + hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"] + .unchecked_into(), + //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5 + hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"] + .unchecked_into(), + ), + ( + //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S + hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(), + //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx + hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(), + //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY + hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"] + .unchecked_into(), + //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP + hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] + .unchecked_into(), + //5HTXBf36LXmkFWJLokNUK6fPxVpkr2ToUnB1pvaagdGu4c1T + hex!["ee93e26259decb89afcf17ef2aa0fa2db2e1042fb8f56ecfb24d19eae8629878"] + .unchecked_into(), + //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU + hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] + .unchecked_into(), + //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV + hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"] + .unchecked_into(), + //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa + hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"] + .unchecked_into(), + //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF + hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"] + .unchecked_into(), + ), + ( + //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR + hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(), + //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v + hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(), + //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1 + hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"] + .unchecked_into(), + //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte + hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] + .unchecked_into(), + //5FHf8kpK4fPjEJeYcYon2gAPwEBubRvtwpzkUbhMWSweKPUY + hex!["8e95b9b5b4dc69790b67b566567ca8bf8cdef3a3a8bb65393c0d1d1c87cd2d2c"] + .unchecked_into(), + //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA + hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] + .unchecked_into(), + //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP + hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"] + .unchecked_into(), + //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA + hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"] + .unchecked_into(), + //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz + hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"] + .unchecked_into(), + ), + ( + //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N + hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(), + //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa + hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(), + //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7 + hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"] + .unchecked_into(), + //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG + hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] + .unchecked_into(), + //5GqL8RbVAuNXpDhjQi1KrS1MyNuKhvus2AbmQwRGjpuGZmFu + hex!["d2f9d537ffa59919a4028afdb627c14c14c97a1547e13e8e82203d2049b15b1a"] + .unchecked_into(), + //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N + hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] + .unchecked_into(), + //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG + hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"] + .unchecked_into(), + //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ + hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"] + .unchecked_into(), + //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ + hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"] + .unchecked_into(), + ), + ( + //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF + hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(), + //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM + hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(), + //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD + hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"] + .unchecked_into(), + //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB + hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] + .unchecked_into(), + //5GWZbVkJEfWZ7fRca39YAQeqri2Z7pkeHyd7rUctUHyQifLp + hex!["c4a980da30939d5bb9e4a734d12bf81259ae286aa21fa4b65405347fa40eff35"] + .unchecked_into(), + //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE + hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] + .unchecked_into(), + //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS + hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"] + .unchecked_into(), + //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd + hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"] + .unchecked_into(), + //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT + hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"] + .unchecked_into(), + ), + ( + //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM + hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(), + //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7 + hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(), + //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96 + hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"] + .unchecked_into(), + //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N + hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] + .unchecked_into(), + //5E1Y1FJ7dVP7qtE3wm241pTm72rTMcDT5Jd8Czv7Pwp7N3AH + hex!["560d90ca51e9c9481b8a9810060e04d0708d246714960439f804e5c6f40ca651"] + .unchecked_into(), + //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT + hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] + .unchecked_into(), + //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa + hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"] + .unchecked_into(), + //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7 + hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"] + .unchecked_into(), + //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx + hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"] + .unchecked_into(), + ), + ( + //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di + hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(), + //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV + hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(), + //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8 + hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"] + .unchecked_into(), + //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF + hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] + .unchecked_into(), + //5FNFDUGNLUtqg5LgrwYLNmBiGoP8KRxsvQpBkc7GQP6qaBUG + hex!["92156f54a114ee191415898f2da013d9db6a5362d6b36330d5fc23e27360ab66"] + .unchecked_into(), + //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F + hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] + .unchecked_into(), + //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx + hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"] + .unchecked_into(), + //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T + hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"] + .unchecked_into(), + //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7 + hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"] + .unchecked_into(), + ), + ]; + let root_key = endowed_accounts[0].clone(); + + //patch + rococo_testnet_genesis(initial_authorities, root_key, Some(endowed_accounts)) +} + +use serde_json::Value; +pub fn merge(a: &mut Value, b: Value) { + match (a, b) { + (Value::Object(a), Value::Object(b)) => + for (k, v) in b { + if v.is_null() { + a.remove(&k); + } else { + merge(a.entry(k).or_insert(Value::Null), v); + } + }, + (a, b) => *a = b, + }; +} +use hex_literal::hex; +use sp_core::crypto::UncheckedInto; sp_api::impl_runtime_apis! { impl sp_api::Core for Runtime { @@ -1773,7 +2174,7 @@ sp_api::impl_runtime_apis! { fn check_inherents( block: Block, data: inherents::InherentData, - ) -> inherents::CheckInherentsResult { + ) -> inherents::CheckInherentsResult { data.check_extrinsics(&block) } } @@ -1783,7 +2184,7 @@ sp_api::impl_runtime_apis! { source: TransactionSource, tx: ::Extrinsic, block_hash: ::Hash, - ) -> TransactionValidity { + ) -> TransactionValidity { Executive::validate_transaction(source, tx, block_hash) } } @@ -1810,23 +2211,23 @@ sp_api::impl_runtime_apis! { fn persisted_validation_data(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option> { - parachains_runtime_api_impl::persisted_validation_data::(para_id, assumption) - } + parachains_runtime_api_impl::persisted_validation_data::(para_id, assumption) + } fn assumed_validation_data( para_id: ParaId, expected_persisted_validation_data_hash: Hash, - ) -> Option<(PersistedValidationData, ValidationCodeHash)> { + ) -> Option<(PersistedValidationData, ValidationCodeHash)> { parachains_runtime_api_impl::assumed_validation_data::( para_id, expected_persisted_validation_data_hash, - ) + ) } fn check_validation_outputs( para_id: ParaId, outputs: primitives::CandidateCommitments, - ) -> bool { + ) -> bool { parachains_runtime_api_impl::check_validation_outputs::(para_id, outputs) } @@ -1836,8 +2237,8 @@ sp_api::impl_runtime_apis! { fn validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option { - parachains_runtime_api_impl::validation_code::(para_id, assumption) - } + parachains_runtime_api_impl::validation_code::(para_id, assumption) + } fn candidate_pending_availability(para_id: ParaId) -> Option> { parachains_runtime_api_impl::candidate_pending_availability::(para_id) @@ -1868,7 +2269,7 @@ sp_api::impl_runtime_apis! { fn inbound_hrmp_channels_contents( recipient: ParaId - ) -> BTreeMap>> { + ) -> BTreeMap>> { parachains_runtime_api_impl::inbound_hrmp_channels_contents::(recipient) } @@ -1883,7 +2284,7 @@ sp_api::impl_runtime_apis! { fn submit_pvf_check_statement( stmt: primitives::PvfCheckStatement, signature: primitives::ValidatorSignature - ) { + ) { parachains_runtime_api_impl::submit_pvf_check_statement::(stmt, signature) } @@ -1893,22 +2294,22 @@ sp_api::impl_runtime_apis! { fn validation_code_hash(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option - { - parachains_runtime_api_impl::validation_code_hash::(para_id, assumption) - } + { + parachains_runtime_api_impl::validation_code_hash::(para_id, assumption) + } fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState)> { parachains_runtime_api_impl::get_session_disputes::() } fn unapplied_slashes( - ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { parachains_runtime_api_impl::unapplied_slashes::() } fn key_ownership_proof( validator_id: ValidatorId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) @@ -1919,11 +2320,11 @@ sp_api::impl_runtime_apis! { fn submit_report_dispute_lost( dispute_proof: slashing::DisputeProof, key_ownership_proof: slashing::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { parachains_runtime_api_impl::submit_unsigned_slashing_report::( dispute_proof, key_ownership_proof, - ) + ) } fn minimum_backing_votes() -> u32 { @@ -1963,24 +2364,24 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: beefy_primitives::EquivocationProof< - BlockNumber, - BeefyId, - BeefySignature, + BlockNumber, + BeefyId, + BeefySignature, >, key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; Beefy::submit_unsigned_equivocation_report( equivocation_proof, key_owner_proof, - ) + ) } fn generate_key_ownership_proof( _set_id: beefy_primitives::ValidatorSetId, authority_id: BeefyId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((beefy_primitives::KEY_TYPE, authority_id)) @@ -2002,35 +2403,35 @@ sp_api::impl_runtime_apis! { fn generate_proof( block_numbers: Vec, best_known_block_number: Option, - ) -> Result<(Vec, mmr::Proof), mmr::Error> { + ) -> Result<(Vec, mmr::Proof), mmr::Error> { Mmr::generate_proof(block_numbers, best_known_block_number).map( |(leaves, proof)| { ( leaves - .into_iter() - .map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)) - .collect(), + .into_iter() + .map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)) + .collect(), proof, - ) + ) }, - ) + ) } fn verify_proof(leaves: Vec, proof: mmr::Proof) -> Result<(), mmr::Error> - { - let leaves = leaves.into_iter().map(|leaf| - leaf.into_opaque_leaf() - .try_decode() - .ok_or(mmr::Error::Verify)).collect::, mmr::Error>>()?; - Mmr::verify_leaves(leaves, proof) - } + { + let leaves = leaves.into_iter().map(|leaf| + leaf.into_opaque_leaf() + .try_decode() + .ok_or(mmr::Error::Verify)).collect::, mmr::Error>>()?; + Mmr::verify_leaves(leaves, proof) + } fn verify_proof_stateless( root: mmr::Hash, leaves: Vec, proof: mmr::Proof - ) -> Result<(), mmr::Error> { + ) -> Result<(), mmr::Error> { let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect(); pallet_mmr::verify_leaves_proof::(root, nodes, proof) } @@ -2047,23 +2448,23 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: fg_primitives::EquivocationProof< - ::Hash, - sp_runtime::traits::NumberFor, + ::Hash, + sp_runtime::traits::NumberFor, >, key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; Grandpa::submit_unsigned_equivocation_report( equivocation_proof, key_owner_proof, - ) + ) } fn generate_key_ownership_proof( _set_id: fg_primitives::SetId, authority_id: fg_primitives::AuthorityId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((fg_primitives::KEY_TYPE, authority_id)) @@ -2100,7 +2501,7 @@ sp_api::impl_runtime_apis! { fn generate_key_ownership_proof( _slot: babe_primitives::Slot, authority_id: babe_primitives::AuthorityId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((babe_primitives::KEY_TYPE, authority_id)) @@ -2111,13 +2512,13 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: babe_primitives::EquivocationProof<::Header>, key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; Babe::submit_unsigned_equivocation_report( equivocation_proof, key_owner_proof, - ) + ) } } @@ -2134,7 +2535,7 @@ sp_api::impl_runtime_apis! { fn decode_session_keys( encoded: Vec, - ) -> Option, sp_core::crypto::KeyTypeId)>> { + ) -> Option, sp_core::crypto::KeyTypeId)>> { SessionKeys::decode_into_raw_public_keys(&encoded) } } @@ -2148,20 +2549,20 @@ sp_api::impl_runtime_apis! { impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< Block, Balance, - > for Runtime { - fn query_info(uxt: ::Extrinsic, len: u32) -> RuntimeDispatchInfo { - TransactionPayment::query_info(uxt, len) - } - fn query_fee_details(uxt: ::Extrinsic, len: u32) -> FeeDetails { - TransactionPayment::query_fee_details(uxt, len) - } - fn query_weight_to_fee(weight: Weight) -> Balance { - TransactionPayment::weight_to_fee(weight) - } - fn query_length_to_fee(length: u32) -> Balance { - TransactionPayment::length_to_fee(length) + > for Runtime { + fn query_info(uxt: ::Extrinsic, len: u32) -> RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details(uxt: ::Extrinsic, len: u32) -> FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } } - } impl pallet_beefy_mmr::BeefyMmrApi for RuntimeApi { fn authority_set_proof() -> beefy_primitives::mmr::BeefyAuthoritySet { @@ -2186,7 +2587,7 @@ sp_api::impl_runtime_apis! { state_root_check: bool, signature_check: bool, select: frame_try_runtime::TryStateSelect, - ) -> Weight { + ) -> Weight { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() @@ -2198,7 +2599,7 @@ sp_api::impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, - ) { + ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2216,7 +2617,7 @@ sp_api::impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig, - ) -> Result< + ) -> Result< Vec, sp_runtime::RuntimeString, > { @@ -2325,6 +2726,89 @@ sp_api::impl_runtime_apis! { fun: Fungible(1 * UNITS), } } + + parameter_types! { + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + AssetHub::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, + )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + } + + impl pallet_xcm_benchmarks::fungible::Config for Runtime { + type TransactAsset = Balances; + + type CheckedAccount = LocalCheckAccount; + type TrustedTeleporter = TrustedTeleporter; + type TrustedReserve = TrustedReserve; + + fn get_multi_asset() -> MultiAsset { + MultiAsset { + id: Concrete(TokenLocation::get()), + fun: Fungible(1 * UNITS), + } + } + } + + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type RuntimeCall = RuntimeCall; + + fn worst_case_response() -> (u64, Response) { + (0u64, Response::Version(Default::default())) + } + + fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { + // Rococo doesn't support asset exchanges + Err(BenchmarkError::Skip) + } + + fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { + // The XCM executor of Rococo doesn't have a configured `UniversalAliases` + Err(BenchmarkError::Skip) + } + + fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { + Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + } + + fn subscribe_origin() -> Result { + Ok(AssetHub::get()) + } + + fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { + let origin = AssetHub::get(); + let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into(); + let ticket = MultiLocation { parents: 0, interior: Here }; + Ok((origin, ticket, assets)) + } + + fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { + // Rococo doesn't support asset locking + Err(BenchmarkError::Skip) + } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // Rococo doesn't support exporting messages + Err(BenchmarkError::Skip) + } + + fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> { + // The XCM executor of Rococo doesn't have a configured `Aliasers` + Err(BenchmarkError::Skip) + } + } + + let mut whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); + let treasury_key = frame_system::Account::::hashed_key_for(Treasury::account_id()); + whitelist.push(treasury_key.to_vec().into()); + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + + add_benchmarks!(params, batches); + + Ok(batches) } impl pallet_xcm_benchmarks::generic::Config for Runtime { @@ -2398,6 +2882,25 @@ sp_api::impl_runtime_apis! { fn build_config(config: Vec) -> sp_genesis_builder::Result { build_config::(config) } + + fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec { + let default = serde_json::to_string(&RuntimeGenesisConfig::default()) + .expect("serialization to json is expected to work. qed.") + .into_bytes(); + let mut default = + serde_json::from_slice(&default[..]).expect("returned value is json. qed."); + + log::info!("xxx: create_default_config2: {:?} {:?}", params, "staging".as_bytes()); + if params == "staging".as_bytes() { + let patch = rococo_testnet_genesis_staging(); + merge(&mut default, patch); + } + + + serde_json::to_string(&default) + .expect("serialization to json is expected to work. qed.") + .into_bytes() + } } } From 8eb684d94fec02abe4f1f749327dad67391dc157 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:40:58 +0200 Subject: [PATCH 03/83] sc-chain-spec: some ground work --- Cargo.lock | 1 + substrate/client/chain-spec/Cargo.toml | 1 + substrate/client/chain-spec/src/chain_spec.rs | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b5df40a5d177..7bc757e6e63c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15096,6 +15096,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-state-machine", + "sp-tracing 10.0.0", "substrate-test-runtime", ] diff --git a/substrate/client/chain-spec/Cargo.toml b/substrate/client/chain-spec/Cargo.toml index c870ff19b2ad..90018f36eb6c 100644 --- a/substrate/client/chain-spec/Cargo.toml +++ b/substrate/client/chain-spec/Cargo.toml @@ -31,6 +31,7 @@ sp-core = { path = "../../primitives/core" } sp-genesis-builder = { path = "../../primitives/genesis-builder" } sp-runtime = { path = "../../primitives/runtime" } sp-state-machine = { path = "../../primitives/state-machine" } +sp-tracing = { path = "../../primitives/tracing" } log = { version = "0.4.17", default-features = false } array-bytes = { version = "6.1" } docify = "0.2.0" diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 8d97d9410229..463bb362e008 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -45,6 +45,8 @@ use std::{ enum GenesisBuildAction { Patch(json::Value), Full(json::Value), + // name of the patch, runtime code (todo: shared ref) + NamedPatch(String), } #[allow(deprecated)] @@ -118,6 +120,13 @@ impl GenesisSource { json_blob: RuntimeGenesisConfigJson::Patch(patch.clone()), code: code.clone(), })), + Self::GenesisBuilderApi(GenesisBuildAction::NamedPatch(name), code) => { + let patch = RuntimeCaller::new(&code[..]).get_named_patch(name)?; + Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Patch(patch), + code: code.clone(), + })) + }, } } } @@ -425,6 +434,12 @@ impl ChainSpecBuilder { self } + /// Sets the name of runtime-provided JSON patch for runtime's GenesisConfig. + pub fn with_genesis_config_patch_name(mut self, name: String) -> Self { + self.genesis_build_action = GenesisBuildAction::NamedPatch(name); + self + } + /// Sets the full runtime's GenesisConfig JSON. pub fn with_genesis_config(mut self, config: json::Value) -> Self { self.genesis_build_action = GenesisBuildAction::Full(config); @@ -1012,6 +1027,30 @@ mod tests { } #[docify::export] + #[test] + fn generate_chain_spec_with_named_patch_works() { + sp_tracing::try_init_simple(); + let output: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch_name("staging".to_string()) + .build(); + + let actual = output.as_json(false).unwrap(); + let expected = + from_str::(include_str!("../res/substrate_test_runtime_from_named_patch.json")) + .unwrap(); + + //wasm blob may change overtime so let's zero it. Also ensure it is there: + let actual = zeroize_code_key_in_json(false, actual.as_str()); + + assert_eq!(actual, expected); + } + #[test] fn generate_chain_spec_with_patch_works() { let output = ChainSpec::<()>::builder( From 24f33f264a7e63bba811e2356eea9d31797b9361 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:48:28 +0200 Subject: [PATCH 04/83] chain-spec: genesis-builder improvements --- .../chain-spec/src/genesis_config_builder.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 68f3d8860495..385010390207 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -98,6 +98,18 @@ where /// /// Calls [`GenesisBuilder::build_config`](sp_genesis_builder::GenesisBuilder::build_config) /// provided by the `runtime`. + pub fn get_named_patch(&self, name: &String) -> core::result::Result { + let mut t = BasicExternalities::new_empty(); + let call_result = self + .call(&mut t, "GenesisBuilder_create_default_config2", &name.as_bytes().encode()) + .map_err(|e| format!("wasm call error {e}"))?; + + let named_patch = Vec::::decode(&mut &call_result[..]) + .map_err(|e| format!("scale codec error: {e}"))?; + Ok(from_slice(&named_patch[..]).expect("returned value is json. qed.")) + } + + /// Calls [`sp_genesis_builder::GenesisBuilder::build_config`] provided by runtime. pub fn get_storage_for_config(&self, config: Value) -> core::result::Result { let mut ext = BasicExternalities::new_empty(); @@ -135,6 +147,13 @@ where crate::json_patch::merge(&mut config, patch); self.get_storage_for_config(config) } + + pub fn get_storage_for_named_patch( + &self, + name: String, + ) -> core::result::Result { + self.get_storage_for_patch(self.get_named_patch(&name)?) + } } #[cfg(test)] @@ -153,6 +172,17 @@ mod tests { assert_eq!(from_str::(expected).unwrap(), config); } + #[test] + fn get_named_patch_works() { + sp_tracing::try_init_simple(); + let config = + GenesisConfigBuilderRuntimeCaller::new(substrate_test_runtime::wasm_binary_unwrap()) + .get_named_patch(&"foobar".to_string()) + .unwrap(); + let expected = r#"{"foo":"bar"}"#; + assert_eq!(from_str::(expected).unwrap(), config); + } + #[test] fn get_storage_for_patch_works() { let patch = json!({ From c54368a55b4f192c744afa65f3c23312260cf26b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:25:04 +0200 Subject: [PATCH 05/83] test-runtime: patch in runtime --- substrate/test-utils/runtime/Cargo.toml | 2 + substrate/test-utils/runtime/src/lib.rs | 52 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 881a77f1f928..29d78f04e9b8 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -51,6 +51,8 @@ sp-externalities = { path = "../../primitives/externalities", default-features = # 3rd party array-bytes = { version = "6.1", optional = true } log = { version = "0.4.17", default-features = false } +serde_json = { version = "1.0.107", default-features = false, features = ["alloc"] } +hex-literal = { version = "0.4.1" } [dev-dependencies] futures = "0.3.21" diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 16ab467772f2..8ad7dae17555 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -470,6 +470,44 @@ pub const TEST_RUNTIME_BABE_EPOCH_CONFIGURATION: BabeEpochConfiguration = BabeEp allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots, }; +use hex_literal::hex; +use serde_json::json; +use sp_core::crypto::UncheckedInto; +fn substrate_test_genesis_config_patch() -> serde_json::Value { + let endowed_accounts: sp_std::vec::Vec = vec![ + // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs + hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].unchecked_into(), + //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei + hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].unchecked_into(), + //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG + hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].unchecked_into(), + //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S + hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].unchecked_into(), + ]; + + let patch = json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), 10 * currency::DOLLARS)).collect::>(), + }, + "babe": { + "epochConfig": { + "c": [ + 7, + 10 + ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" + } + }, + // "substrateTest": { + // "authorities": [ + // AccountKeyring::Ferdie.public().to_ss58check(), + // AccountKeyring::Alice.public().to_ss58check() + // ], + // } + }); + patch +} + impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { @@ -730,6 +768,20 @@ impl_runtime_apis! { fn build_config(config: Vec) -> sp_genesis_builder::Result { build_config::(config) } + + + fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec { + log::info!("xxx: create_default_config2: {:?} {:?}", params, "staging".as_bytes()); + let patch = match params { + s if s == "staging".as_bytes() => substrate_test_genesis_config_patch(), + s if s == "foobar".as_bytes() => json!({"foo":"bar"}), + _ => json!({}), + }; + + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes() + } } } From f58e4eb1d0a4c9993e57a68b42d73376e8a2e7e1 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:53:45 +0100 Subject: [PATCH 06/83] sc-chain-spec: testing --- substrate/client/chain-spec/src/chain_spec.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 463bb362e008..93e1d6c4f054 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -1041,6 +1041,14 @@ mod tests { .build(); let actual = output.as_json(false).unwrap(); + let mut file = std::fs::OpenOptions::new() + .create(true) + .write(true) + .open("/tmp/default_genesis_config.json") + .unwrap(); + use std::io::Write; + file.write_all(actual.clone().as_bytes()).unwrap(); + let expected = from_str::(include_str!("../res/substrate_test_runtime_from_named_patch.json")) .unwrap(); From 05ff32d55cc8f548cb955bfe56ca1b614635eeaa Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:05:28 +0100 Subject: [PATCH 07/83] test-runtime: dev --- substrate/test-utils/runtime/Cargo.toml | 1 - substrate/test-utils/runtime/src/lib.rs | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 29d78f04e9b8..f8c4850a4e58 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -99,7 +99,6 @@ std = [ "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", - "sp-keyring", "sp-offchain/std", "sp-runtime/std", "sp-session/std", diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 8ad7dae17555..7992074f1182 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -472,7 +472,9 @@ pub const TEST_RUNTIME_BABE_EPOCH_CONFIGURATION: BabeEpochConfiguration = BabeEp use hex_literal::hex; use serde_json::json; +use sp_application_crypto::Ss58Codec; use sp_core::crypto::UncheckedInto; +use sp_keyring::AccountKeyring; fn substrate_test_genesis_config_patch() -> serde_json::Value { let endowed_accounts: sp_std::vec::Vec = vec![ // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs @@ -484,6 +486,7 @@ fn substrate_test_genesis_config_patch() -> serde_json::Value { //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].unchecked_into(), ]; + log::info!("xxx: {} {}", file!(), line!()); let patch = json!({ "balances": { @@ -498,12 +501,12 @@ fn substrate_test_genesis_config_patch() -> serde_json::Value { "allowed_slots": "PrimaryAndSecondaryPlainSlots" } }, - // "substrateTest": { - // "authorities": [ - // AccountKeyring::Ferdie.public().to_ss58check(), - // AccountKeyring::Alice.public().to_ss58check() - // ], - // } + "substrateTest": { + "authorities": [ + AccountKeyring::Ferdie.public().to_ss58check(), + AccountKeyring::Alice.public().to_ss58check() + ], + } }); patch } From 6e8214ebcee2b56e02b3e1d8a39d4ca794c80f01 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:49:38 +0100 Subject: [PATCH 08/83] sc-chain-spec: EHF + named patch fixes --- substrate/client/chain-spec/src/chain_spec.rs | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 93e1d6c4f054..122bddddee9b 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -40,17 +40,26 @@ use std::{ sync::Arc, }; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -enum GenesisBuildAction { +enum GenesisBuildAction { Patch(json::Value), Full(json::Value), - // name of the patch, runtime code (todo: shared ref) - NamedPatch(String), + NamedPatch(String, PhantomData), +} + +impl Clone for GenesisBuildAction { + fn clone(&self) -> Self { + match self { + Self::Patch(ref p) => Self::Patch(p.clone()), + Self::Full(ref f) => Self::Full(f.clone()), + Self::NamedPatch(ref p, _) => Self::NamedPatch(p.clone(), Default::default()), + } + } } #[allow(deprecated)] -enum GenesisSource { +enum GenesisSource { File(PathBuf), Binary(Cow<'static, [u8]>), /// factory function + code @@ -58,10 +67,10 @@ enum GenesisSource { Factory(Arc G + Send + Sync>, Vec), Storage(Storage), /// build action + code - GenesisBuilderApi(GenesisBuildAction, Vec), + GenesisBuilderApi(GenesisBuildAction, Vec), } -impl Clone for GenesisSource { +impl Clone for GenesisSource { fn clone(&self) -> Self { match *self { Self::File(ref path) => Self::File(path.clone()), @@ -73,7 +82,7 @@ impl Clone for GenesisSource { } } -impl GenesisSource { +impl GenesisSource { fn resolve(&self) -> Result, String> { /// helper container for deserializing genesis from the JSON file (ChainSpec JSON file is /// also supported here) @@ -120,8 +129,8 @@ impl GenesisSource { json_blob: RuntimeGenesisConfigJson::Patch(patch.clone()), code: code.clone(), })), - Self::GenesisBuilderApi(GenesisBuildAction::NamedPatch(name), code) => { - let patch = RuntimeCaller::new(&code[..]).get_named_patch(name)?; + Self::GenesisBuilderApi(GenesisBuildAction::NamedPatch(name, _), code) => { + let patch = RuntimeCaller::::new(&code[..]).get_named_patch(name)?; Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { json_blob: RuntimeGenesisConfigJson::Patch(patch), code: code.clone(), @@ -340,13 +349,13 @@ pub struct ChainSpecBuilder { name: String, id: String, chain_type: ChainType, - genesis_build_action: GenesisBuildAction, + genesis_build_action: GenesisBuildAction, boot_nodes: Option>, telemetry_endpoints: Option, protocol_id: Option, fork_id: Option, properties: Option, - _genesis: PhantomData<(G, EHF)>, + _genesis: PhantomData, } impl ChainSpecBuilder { @@ -436,7 +445,7 @@ impl ChainSpecBuilder { /// Sets the name of runtime-provided JSON patch for runtime's GenesisConfig. pub fn with_genesis_config_patch_name(mut self, name: String) -> Self { - self.genesis_build_action = GenesisBuildAction::NamedPatch(name); + self.genesis_build_action = GenesisBuildAction::NamedPatch(name, Default::default()); self } @@ -478,7 +487,7 @@ impl ChainSpecBuilder { /// runtime is using the non-standard host function during genesis state creation. pub struct ChainSpec { client_spec: ClientSpec, - genesis: GenesisSource, + genesis: GenesisSource, _host_functions: PhantomData, } From f339fe9b683c41d141a3a1af465cb9a27018d87c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:14:19 +0100 Subject: [PATCH 09/83] test-runtime: testing --- substrate/test-utils/runtime/Cargo.toml | 2 +- substrate/test-utils/runtime/src/lib.rs | 50 ++++++++++++++----------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index f8c4850a4e58..5bd95452880b 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -24,7 +24,7 @@ sp-block-builder = { path = "../../primitives/block-builder", default-features = codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } sp-inherents = { path = "../../primitives/inherents", default-features = false } -sp-keyring = { path = "../../primitives/keyring", optional = true } +sp-keyring = { path = "../../primitives/keyring", default-features = false } sp-offchain = { path = "../../primitives/offchain", default-features = false } sp-core = { path = "../../primitives/core", default-features = false } sp-std = { path = "../../primitives/std", default-features = false } diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 7992074f1182..3271586381c2 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -90,7 +90,7 @@ pub mod wasm_binary_logging_disabled { #[cfg(feature = "std")] pub fn wasm_binary_unwrap() -> &'static [u8] { WASM_BINARY.expect( - "Development wasm binary is not available. Testing is only supported with the flag \ + "Development wasm binary is not available. Testing is only supported with the flag disabled.", ) } @@ -99,7 +99,7 @@ pub fn wasm_binary_unwrap() -> &'static [u8] { #[cfg(feature = "std")] pub fn wasm_binary_logging_disabled_unwrap() -> &'static [u8] { wasm_binary_logging_disabled::WASM_BINARY.expect( - "Development wasm binary is not available. Testing is only supported with the flag \ + "Development wasm binary is not available. Testing is only supported with the flag disabled.", ) } @@ -476,31 +476,14 @@ use sp_application_crypto::Ss58Codec; use sp_core::crypto::UncheckedInto; use sp_keyring::AccountKeyring; fn substrate_test_genesis_config_patch() -> serde_json::Value { - let endowed_accounts: sp_std::vec::Vec = vec![ - // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs - hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].unchecked_into(), - //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei - hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].unchecked_into(), - //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG - hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].unchecked_into(), - //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S - hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].unchecked_into(), - ]; + let endowed_accounts: sp_std::vec::Vec = + vec![AccountKeyring::Ferdie.public().into(), AccountKeyring::Alice.public().into()]; log::info!("xxx: {} {}", file!(), line!()); let patch = json!({ "balances": { "balances": endowed_accounts.iter().map(|k| (k.clone(), 10 * currency::DOLLARS)).collect::>(), }, - "babe": { - "epochConfig": { - "c": [ - 7, - 10 - ], - "allowed_slots": "PrimaryAndSecondaryPlainSlots" - } - }, "substrateTest": { "authorities": [ AccountKeyring::Ferdie.public().to_ss58check(), @@ -1351,6 +1334,31 @@ mod tests { assert_eq!(expected.to_string(), json); } + #[test] + fn named_config_works() { + let f = |cfg_name: &str, expected: &str| { + sp_tracing::try_init_simple(); + let mut t = BasicExternalities::new_empty(); + let name = cfg_name.to_string(); + let r = executor_call( + &mut t, + "GenesisBuilder_create_default_config2", + &name.as_bytes().encode(), + ) + .unwrap(); + let r = Vec::::decode(&mut &r[..]).unwrap(); + let json = String::from_utf8(r.into()).expect("returned value is json. qed."); + log::info!("json: {:#?}", json); + assert_eq!(expected.to_string(), json); + }; + + f("foobar", r#"{"foo":"bar"}"#); + f( + "staging", + r#"{"babe":{"epochConfig":{"allowed_slots":"PrimaryAndSecondaryPlainSlots","c":[7,10]}},"balances":{"balances":[["5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs",1000000000000000],["5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei",1000000000000000],["5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG",1000000000000000],["5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S",1000000000000000]]},"substrateTest":{"authorities":["5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL","5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"]}}"#, + ); + } + #[test] fn build_config_from_json_works() { sp_tracing::try_init_simple(); From fde2be75eff089871dd4b156b50648b70d2967aa Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:27:15 +0100 Subject: [PATCH 10/83] test-runtime: testing --- substrate/test-utils/runtime/src/lib.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 3271586381c2..8acb4181fdb5 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -54,6 +54,7 @@ use sp_trie::{ }; use trie_db::{Trie, TrieMut}; +use serde_json::json; use sp_api::{decl_runtime_apis, impl_runtime_apis}; pub use sp_core::hash::H256; use sp_inherents::{CheckInherentsResult, InherentData}; @@ -470,14 +471,9 @@ pub const TEST_RUNTIME_BABE_EPOCH_CONFIGURATION: BabeEpochConfiguration = BabeEp allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots, }; -use hex_literal::hex; -use serde_json::json; -use sp_application_crypto::Ss58Codec; -use sp_core::crypto::UncheckedInto; -use sp_keyring::AccountKeyring; fn substrate_test_genesis_config_patch() -> serde_json::Value { let endowed_accounts: sp_std::vec::Vec = - vec![AccountKeyring::Ferdie.public().into(), AccountKeyring::Alice.public().into()]; + vec![AccountKeyring::Bob.public().into(), AccountKeyring::Charlie.public().into()]; log::info!("xxx: {} {}", file!(), line!()); let patch = json!({ @@ -486,8 +482,8 @@ fn substrate_test_genesis_config_patch() -> serde_json::Value { }, "substrateTest": { "authorities": [ - AccountKeyring::Ferdie.public().to_ss58check(), - AccountKeyring::Alice.public().to_ss58check() + AccountKeyring::Alice.public().to_ss58check(), + AccountKeyring::Ferdie.public().to_ss58check() ], } }); @@ -1355,7 +1351,7 @@ mod tests { f("foobar", r#"{"foo":"bar"}"#); f( "staging", - r#"{"babe":{"epochConfig":{"allowed_slots":"PrimaryAndSecondaryPlainSlots","c":[7,10]}},"balances":{"balances":[["5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs",1000000000000000],["5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei",1000000000000000],["5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG",1000000000000000],["5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S",1000000000000000]]},"substrateTest":{"authorities":["5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL","5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"]}}"#, + r#"{"balances":{"balances":[["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",1000000000000000],["5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",1000000000000000]]},"substrateTest":{"authorities":["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY","5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL"]}}"#, ); } From ed0bd96688f6723a2c327be49aab66ec29686404 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:19:01 +0100 Subject: [PATCH 11/83] sp-genesis-builder: APIv2 --- substrate/primitives/genesis-builder/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 17172311d832..0e64104343d5 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -35,13 +35,13 @@ pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; sp_api::decl_runtime_apis! { /// API to interact with GenesisConfig for the runtime + #[api_version(2)] pub trait GenesisBuilder { /// Creates the default `GenesisConfig` and returns it as a JSON blob. /// /// This function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON /// blob. It returns a `Vec` containing the JSON representation of the default `GenesisConfig`. fn create_default_config() -> sp_std::vec::Vec; - fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec; /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. /// @@ -50,6 +50,15 @@ sp_api::decl_runtime_apis! { /// It is recommended to log any errors encountered during the process. /// /// Please note that provided json blob must contain all `GenesisConfig` fields, no defaults will be used. - fn build_config(json: sp_std::vec::Vec) -> Result; + #[renamed("build_config", 2)] + fn build_state(json: sp_std::vec::Vec) -> Result; + + /// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. + /// + /// If `id` is `None` the function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON + /// blob. It returns a `Vec` containing the JSON representation of the default `GenesisConfig`. + /// Otherwise returns a JSON representation of the runtime provided, named, pre-configured `GenesisConfig`. + #[api_version(2)] + fn get_named_preset(params: Option>) -> sp_std::vec::Vec; } } From 51a3d0bb6099c19cd92be5feb9977e8c15da3b67 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:49:49 +0100 Subject: [PATCH 12/83] test-runtime: genesis-builder api v2 --- substrate/test-utils/runtime/src/lib.rs | 46 +++++++++++++------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 8acb4181fdb5..e5cb99a5d0cb 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -29,7 +29,7 @@ use codec::{Decode, Encode}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstU32, ConstU64}, weights::{ @@ -747,22 +747,24 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } - - fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec { + fn get_named_preset(params: Option>) -> sp_std::vec::Vec { log::info!("xxx: create_default_config2: {:?} {:?}", params, "staging".as_bytes()); - let patch = match params { - s if s == "staging".as_bytes() => substrate_test_genesis_config_patch(), - s if s == "foobar".as_bytes() => json!({"foo":"bar"}), - _ => json!({}), - }; - - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes() + if let Some(params) = params { + let patch = match params { + s if s == "staging".as_bytes() => substrate_test_genesis_config_patch(), + s if s == "foobar".as_bytes() => json!({"foo":"bar"}), + _ => json!({}), + }; + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes() + } else { + create_default_config::() + } } } } @@ -1274,7 +1276,7 @@ mod tests { let default_minimal_json = r#"{"system":{},"babe":{"authorities":[],"epochConfig":{"c": [ 3, 10 ],"allowed_slots":"PrimaryAndSecondaryPlainSlots"}},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; let mut t = BasicExternalities::new_empty(); - executor_call(&mut t, "GenesisBuilder_build_config", &default_minimal_json.encode()) + executor_call(&mut t, "GenesisBuilder_build_state", &default_minimal_json.encode()) .unwrap(); let mut keys = t.into_storages().top.keys().cloned().map(hex).collect::>(); @@ -1338,8 +1340,8 @@ mod tests { let name = cfg_name.to_string(); let r = executor_call( &mut t, - "GenesisBuilder_create_default_config2", - &name.as_bytes().encode(), + "GenesisBuilder_get_named_preset", + &Some(name.as_bytes()).encode(), ) .unwrap(); let r = Vec::::decode(&mut &r[..]).unwrap(); @@ -1361,7 +1363,7 @@ mod tests { let j = include_str!("../res/default_genesis_config.json"); let mut t = BasicExternalities::new_empty(); - let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); + let r = executor_call(&mut t, "GenesisBuilder_build_state", &j.encode()).unwrap(); let r = BuildResult::decode(&mut &r[..]); assert!(r.is_ok()); @@ -1380,7 +1382,7 @@ mod tests { sp_tracing::try_init_simple(); let j = include_str!("../res/default_genesis_config_invalid.json"); let mut t = BasicExternalities::new_empty(); - let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); + let r = executor_call(&mut t, "GenesisBuilder_build_state", &j.encode()).unwrap(); let r = BuildResult::decode(&mut &r[..]).unwrap(); log::info!("result: {:#?}", r); assert_eq!(r, Err( @@ -1395,7 +1397,7 @@ mod tests { sp_tracing::try_init_simple(); let j = include_str!("../res/default_genesis_config_invalid_2.json"); let mut t = BasicExternalities::new_empty(); - let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); + let r = executor_call(&mut t, "GenesisBuilder_build_state", &j.encode()).unwrap(); let r = BuildResult::decode(&mut &r[..]).unwrap(); assert_eq!(r, Err( sp_runtime::RuntimeString::Owned( @@ -1410,7 +1412,7 @@ mod tests { let j = include_str!("../res/default_genesis_config_incomplete.json"); let mut t = BasicExternalities::new_empty(); - let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); + let r = executor_call(&mut t, "GenesisBuilder_build_state", &j.encode()).unwrap(); let r = core::result::Result::<(), sp_runtime::RuntimeString>::decode(&mut &r[..]).unwrap(); assert_eq!( @@ -1475,7 +1477,7 @@ mod tests { let mut t = BasicExternalities::new_empty(); executor_call( &mut t, - "GenesisBuilder_build_config", + "GenesisBuilder_build_state", &default_config.to_string().encode(), ) .unwrap(); From 0bd44d712dd4514f11b3ae68e67e4a399c45febc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:08:49 +0100 Subject: [PATCH 13/83] build_condfig -> build_state --- cumulus/parachain-template/runtime/src/lib.rs | 6 +++--- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 6 +++--- .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 6 +++--- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 6 +++--- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 6 +++--- .../runtimes/collectives/collectives-westend/src/lib.rs | 6 +++--- .../runtimes/contracts/contracts-rococo/src/lib.rs | 6 +++--- .../parachains/runtimes/glutton/glutton-westend/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/starters/shell/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 6 +++--- .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 6 +++--- .../src/fake_runtime_api/asset_hub_polkadot_aura.rs | 2 +- cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs | 2 +- cumulus/test/runtime/src/lib.rs | 6 +++--- polkadot/runtime/rococo/src/lib.rs | 6 +++--- polkadot/runtime/test-runtime/src/lib.rs | 6 +++--- polkadot/runtime/westend/src/lib.rs | 6 +++--- substrate/bin/minimal/runtime/src/lib.rs | 6 +++--- substrate/bin/node-template/runtime/src/lib.rs | 6 +++--- substrate/bin/node/runtime/src/lib.rs | 6 +++--- substrate/bin/utils/chain-spec-builder/src/lib.rs | 6 +++--- substrate/client/chain-spec/src/genesis_config_builder.rs | 4 ++-- substrate/client/chain-spec/src/lib.rs | 2 +- substrate/frame/support/src/genesis_builder_helper.rs | 4 ++-- 25 files changed, 67 insertions(+), 67 deletions(-) diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 1ef018a8ca34..c85aeb72def7 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -30,7 +30,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ @@ -758,8 +758,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index e00327a3ef6d..4ba5cd12b75a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -54,7 +54,7 @@ use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, ord_parameter_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, @@ -1604,8 +1604,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index ceb021873505..75b4bb9c4a4f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -40,7 +40,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, ord_parameter_types, parameter_types, traits::{ tokens::nonfungibles_v2::Inspect, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, @@ -1681,8 +1681,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 75af5a8ef7b1..a7411fe4af3d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -53,7 +53,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -1196,8 +1196,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index a052cd929b73..e4da083b3fa7 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -52,7 +52,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -1087,8 +1087,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 9074323fe31f..a5ae0505478a 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -66,7 +66,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ fungible::HoldConsideration, ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, @@ -1035,8 +1035,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 79b6b6be299b..f56eae4bac47 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -48,7 +48,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8}, weights::{ConstantMultiplier, Weight}, @@ -764,8 +764,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 2c51791c0740..c23b866e8088 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -66,7 +66,7 @@ use cumulus_primitives_core::AggregateMessageOrigin; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, IsInVec, Randomness, @@ -509,8 +509,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index cb868627e799..972efbe4e56c 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -46,7 +46,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness}, weights::{ @@ -380,8 +380,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index de95969f71d1..4a1cd74457ae 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -54,7 +54,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness}, weights::{ @@ -437,8 +437,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 9387c454715f..5442d35041bd 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -37,7 +37,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, pallet_prelude::Weight, parameter_types, traits::{ @@ -866,8 +866,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 206e4970bae9..258e0a57f762 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -41,7 +41,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, match_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, @@ -826,8 +826,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 76dd7347ccbc..e1cd205a951e 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -193,7 +193,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn build_config(_: Vec) -> sp_genesis_builder::Result { + fn build_state(_: Vec) -> sp_genesis_builder::Result { unimplemented!() } } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index 0f01b85ebcf6..e6b495a6a184 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -193,7 +193,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn build_config(_: Vec) -> sp_genesis_builder::Result { + fn build_state(_: Vec) -> sp_genesis_builder::Result { unimplemented!() } } diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 3de77cb1e581..f63097ebf856 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -47,7 +47,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ConstU8, Randomness}, weights::{ @@ -467,8 +467,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index ff033094f629..75f19d12b236 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -66,7 +66,7 @@ use beefy_primitives::{ use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ fungible::HoldConsideration, Contains, EitherOf, EitherOfDiverse, EverythingBut, @@ -2879,8 +2879,8 @@ sp_api::impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec { diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index cd9590796ae0..2d3ee27e7674 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -43,7 +43,7 @@ use frame_election_provider_support::{ }; use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{KeyOwnerProofSystem, WithdrawReasons}, }; @@ -1139,8 +1139,8 @@ sp_api::impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 0f068b093f5a..9b666ee8c525 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -28,7 +28,7 @@ use beefy_primitives::{ use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, SequentialPhragmen}; use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, parameter_types, traits::{ fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, EverythingBut, @@ -2452,8 +2452,8 @@ sp_api::impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/substrate/bin/minimal/runtime/src/lib.rs b/substrate/bin/minimal/runtime/src/lib.rs index efee400c3f59..77a81a08e529 100644 --- a/substrate/bin/minimal/runtime/src/lib.rs +++ b/substrate/bin/minimal/runtime/src/lib.rs @@ -31,7 +31,7 @@ use frame::{ prelude::*, }, }; -use frame_support::genesis_builder_helper::{build_config, create_default_config}; +use frame_support::genesis_builder_helper::{build_state, create_default_config}; #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { @@ -217,8 +217,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 5f399edda987..d0555b90f279 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -21,7 +21,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use frame_support::genesis_builder_helper::{build_config, create_default_config}; +use frame_support::genesis_builder_helper::{build_state, create_default_config}; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, derive_impl, parameter_types, @@ -562,8 +562,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 4d0b253413a8..55aed6278eff 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -30,7 +30,7 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config}, instances::{Instance1, Instance2}, ord_parameter_types, pallet_prelude::Get, @@ -2837,8 +2837,8 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) } } } diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 60ec0f1a656b..4cb7f242bfe0 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -47,7 +47,7 @@ //! chain-spec-builder create -s -r runtime.wasm patch patch.json //! ``` //! -//! _Note:_ [`GenesisBuilder::build_config`][sp-genesis-builder-build] runtime function is called. +//! _Note:_ [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate raw storage chain spec using full genesis config. //! @@ -56,7 +56,7 @@ //! chain-spec-builder create -s -r runtime.wasm full full-genesis-config.json //! ``` //! -//! _Note_: [`GenesisBuilder::build_config`][sp-genesis-builder-build] runtime function is called. +//! _Note_: [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate human readable chain spec using provided genesis config patch. //! ```text @@ -75,7 +75,7 @@ //! [`node-cli`]: ../node_cli/index.html //! [`sp-genesis-builder`]: ../sp_genesis_builder/index.html //! [sp-genesis-builder-create]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.create_default_config -//! [sp-genesis-builder-build]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.build_config +//! [sp-genesis-builder-build]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.build_state use std::{fs, path::PathBuf}; diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 385010390207..4a2b6bebb4ae 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -96,7 +96,7 @@ where /// Build the given `GenesisConfig` and returns the genesis state. /// - /// Calls [`GenesisBuilder::build_config`](sp_genesis_builder::GenesisBuilder::build_config) + /// Calls [`GenesisBuilder::build_state`](sp_genesis_builder::GenesisBuilder::build_state) /// provided by the `runtime`. pub fn get_named_patch(&self, name: &String) -> core::result::Result { let mut t = BasicExternalities::new_empty(); @@ -109,7 +109,7 @@ where Ok(from_slice(&named_patch[..]).expect("returned value is json. qed.")) } - /// Calls [`sp_genesis_builder::GenesisBuilder::build_config`] provided by runtime. + /// Calls [`sp_genesis_builder::GenesisBuilder::build_state`] provided by runtime. pub fn get_storage_for_config(&self, config: Value) -> core::result::Result { let mut ext = BasicExternalities::new_empty(); diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index a80c380803d7..9465d3b6cf11 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -181,7 +181,7 @@ //! the node needs to interact with the runtime. //! //! This interaction involves passing the runtime genesis config JSON blob to the runtime using the -//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation, the +//! [`sp_genesis_builder::GenesisBuilder::build_state`] function. During this operation, the //! runtime converts the JSON representation of the genesis config into [`sp_io::storage`] items. It //! is a crucial step for computing the storage root hash, which is a key component in determining //! the genesis hash. diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index b2594d183ec5..28071e9049a3 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -35,8 +35,8 @@ where } /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. For -/// more info refer to [`sp_genesis_builder::GenesisBuilder::build_config`]. -pub fn build_config(json: sp_std::vec::Vec) -> BuildResult { +/// more info refer to [`sp_genesis_builder::GenesisBuilder::build_state`]. +pub fn build_state(json: sp_std::vec::Vec) -> BuildResult { let gc = serde_json::from_slice::(&json) .map_err(|e| format_runtime_string!("Invalid JSON blob: {}", e))?; ::build(&gc); From 53272c673ffde085b88ef3788522069320cc5b54 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:46:44 +0100 Subject: [PATCH 14/83] sp-genesis-builder: APIv2 c.d. --- substrate/primitives/genesis-builder/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 0e64104343d5..ce77786d752a 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -26,6 +26,8 @@ //! pallet's author. //! - deserialize the `GenesisConfig` from given json blob and put `GenesisConfig` into the state //! storage. Allows to build customized configuration. +//! - provide a named, built-in, predefined preset of `GenesisConfig`, +//! - provide the list of preset names, //! //! Providing externalities with empty storage and putting `GenesisConfig` into storage allows to //! catch and build the raw storage of `GenesisConfig` which is the foundation for genesis block. @@ -57,8 +59,15 @@ sp_api::decl_runtime_apis! { /// /// If `id` is `None` the function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON /// blob. It returns a `Vec` containing the JSON representation of the default `GenesisConfig`. - /// Otherwise returns a JSON representation of the runtime provided, named, pre-configured `GenesisConfig`. + /// Otherwise returns a JSON representation of the built-in, named, pre-configured `GenesisConfig` value. #[api_version(2)] - fn get_named_preset(params: Option>) -> sp_std::vec::Vec; + fn get_preset(id: Option>) -> Option>; + + /// Returns a list of available builtin `GenesisConfig` presets. + /// + /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If no named presets are + /// provided by the runtime the list is empty. + #[api_version(2)] + fn preset_names() -> sp_std::vec::Vec; } } From f7eb376d22a9b67560e3017ad4a7fd18de4fedfc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:47:41 +0100 Subject: [PATCH 15/83] genesis-builder-helper: get_preset added --- .../frame/support/src/genesis_builder_helper.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 28071e9049a3..750e41565f4b 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -42,3 +42,16 @@ pub fn build_state(json: sp_std::vec::Vec) -> BuildR ::build(&gc); Ok(()) } + +/// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. +/// For more info refer to [`sp_genesis_builder::GenesisBuilder::get_preset`]. +pub fn get_preset(id: Option>) -> Option> +where + GC: BuildGenesisConfig + Default, +{ + if id.is_none() { + Some(create_default_config::()) + } else { + None + } +} From 320523544c0f294ade87e7964158f80a607ba406 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:48:07 +0100 Subject: [PATCH 16/83] test-runtime: tests fixed --- substrate/test-utils/runtime/src/lib.rs | 32 ++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index e5cb99a5d0cb..10427c4e9899 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -42,6 +42,7 @@ use frame_system::{ CheckNonce, CheckWeight, }; use scale_info::TypeInfo; +use sp_runtime::RuntimeString; use sp_std::prelude::*; #[cfg(not(feature = "std"))] use sp_std::vec; @@ -751,20 +752,24 @@ impl_runtime_apis! { build_state::(config) } - fn get_named_preset(params: Option>) -> sp_std::vec::Vec { + fn get_preset(params: Option>) -> Option> { log::info!("xxx: create_default_config2: {:?} {:?}", params, "staging".as_bytes()); - if let Some(params) = params { + Some(if let Some(params) = params { let patch = match params { s if s == "staging".as_bytes() => substrate_test_genesis_config_patch(), s if s == "foobar".as_bytes() => json!({"foo":"bar"}), - _ => json!({}), + _ => return None, }; serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") .into_bytes() } else { create_default_config::() - } + }) + } + + fn preset_names() -> Vec { + vec![RuntimeString::from("foobar"), RuntimeString::from("staging")] } } } @@ -1332,20 +1337,31 @@ mod tests { assert_eq!(expected.to_string(), json); } + #[test] + fn preset_names_listing_works() { + sp_tracing::try_init_simple(); + let mut t = BasicExternalities::new_empty(); + let r = executor_call(&mut t, "GenesisBuilder_preset_names", &vec![]).unwrap(); + let r = Vec::::decode(&mut &r[..]).unwrap(); + assert_eq!(r, vec![RuntimeString::from("foobar"), RuntimeString::from("staging"),]); + log::info!("r: {:#?}", r); + } + #[test] fn named_config_works() { + sp_tracing::try_init_simple(); let f = |cfg_name: &str, expected: &str| { - sp_tracing::try_init_simple(); let mut t = BasicExternalities::new_empty(); let name = cfg_name.to_string(); let r = executor_call( &mut t, - "GenesisBuilder_get_named_preset", + "GenesisBuilder_get_preset", &Some(name.as_bytes()).encode(), ) .unwrap(); - let r = Vec::::decode(&mut &r[..]).unwrap(); - let json = String::from_utf8(r.into()).expect("returned value is json. qed."); + let r = Option::>::decode(&mut &r[..]).unwrap(); + let json = + String::from_utf8(r.unwrap().into()).expect("returned value is json. qed."); log::info!("json: {:#?}", json); assert_eq!(expected.to_string(), json); }; From 554dd169edb92f54dc89e38d87159bf8eb28fc5d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:58:02 +0100 Subject: [PATCH 17/83] kitchensink: genesis-builder fixes --- substrate/bin/node/runtime/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 55aed6278eff..52094d2bbdf5 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -30,7 +30,7 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, instances::{Instance1, Instance2}, ord_parameter_types, pallet_prelude::Get, @@ -2840,6 +2840,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } From df03313093b38f00f96eb3893f1742b06aed7966 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 16:27:46 +0100 Subject: [PATCH 18/83] sc-chain-spec: support for genesis-builder v2 --- ...bstrate_test_runtime_from_named_patch.json | 35 ++++++++++++++++++ substrate/client/chain-spec/src/chain_spec.rs | 2 +- .../chain-spec/src/genesis_config_builder.rs | 37 +++++++++---------- 3 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 substrate/client/chain-spec/res/substrate_test_runtime_from_named_patch.json diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_named_patch.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_named_patch.json new file mode 100644 index 000000000000..a98600a5577b --- /dev/null +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_named_patch.json @@ -0,0 +1,35 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "runtimeGenesis": { + "patch": { + "balances": { + "balances": [ + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1000000000000000 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1000000000000000 + ] + ] + }, + "substrateTest": { + "authorities": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" + ] + } + }, + "code": "0x0" + } + } +} diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 122bddddee9b..4b424f33f43d 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -130,7 +130,7 @@ impl GenesisSource { code: code.clone(), })), Self::GenesisBuilderApi(GenesisBuildAction::NamedPatch(name, _), code) => { - let patch = RuntimeCaller::::new(&code[..]).get_named_patch(name)?; + let patch = RuntimeCaller::::new(&code[..]).get_named_patch(Some(name))?; Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { json_blob: RuntimeGenesisConfigJson::Patch(patch), code: code.clone(), diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 4a2b6bebb4ae..5f279e77a460 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -84,29 +84,28 @@ where /// Returns the default `GenesisConfig` provided by the `runtime`. /// /// Calls [`GenesisBuilder::create_default_config`](sp_genesis_builder::GenesisBuilder::create_default_config) in the `runtime`. - pub fn get_default_config(&self) -> core::result::Result { - let mut t = BasicExternalities::new_empty(); - let call_result = self - .call(&mut t, "GenesisBuilder_create_default_config", &[]) - .map_err(|e| format!("wasm call error {e}"))?; - let default_config = Vec::::decode(&mut &call_result[..]) - .map_err(|e| format!("scale codec error: {e}"))?; - Ok(from_slice(&default_config[..]).expect("returned value is json. qed.")) + fn get_default_config(&self) -> core::result::Result { + self.get_named_patch(None) } - /// Build the given `GenesisConfig` and returns the genesis state. + /// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. /// - /// Calls [`GenesisBuilder::build_state`](sp_genesis_builder::GenesisBuilder::build_state) + /// Calls [`GenesisBuilder::get_preset`](sp_genesis_builder::GenesisBuilder::get_preset) /// provided by the `runtime`. - pub fn get_named_patch(&self, name: &String) -> core::result::Result { + pub fn get_named_patch(&self, id: Option<&String>) -> core::result::Result { let mut t = BasicExternalities::new_empty(); let call_result = self - .call(&mut t, "GenesisBuilder_create_default_config2", &name.as_bytes().encode()) + .call(&mut t, "GenesisBuilder_get_preset", &id.encode()) .map_err(|e| format!("wasm call error {e}"))?; - let named_patch = Vec::::decode(&mut &call_result[..]) + let named_patch = Option::>::decode(&mut &call_result[..]) .map_err(|e| format!("scale codec error: {e}"))?; - Ok(from_slice(&named_patch[..]).expect("returned value is json. qed.")) + + if let Some(named_patch) = named_patch { + Ok(from_slice(&named_patch[..]).expect("returned value is json. qed.")) + } else { + Err(format!("The preset with name {id:?} is not available.")) + } } /// Calls [`sp_genesis_builder::GenesisBuilder::build_state`] provided by runtime. @@ -114,7 +113,7 @@ where let mut ext = BasicExternalities::new_empty(); let call_result = self - .call(&mut ext, "GenesisBuilder_build_config", &config.to_string().encode()) + .call(&mut ext, "GenesisBuilder_build_state", &config.to_string().encode()) .map_err(|e| format!("wasm call error {e}"))?; BuildResult::decode(&mut &call_result[..]) @@ -150,9 +149,9 @@ where pub fn get_storage_for_named_patch( &self, - name: String, + name: Option<&String>, ) -> core::result::Result { - self.get_storage_for_patch(self.get_named_patch(&name)?) + self.get_storage_for_patch(self.get_named_patch(name)?) } } @@ -176,8 +175,8 @@ mod tests { fn get_named_patch_works() { sp_tracing::try_init_simple(); let config = - GenesisConfigBuilderRuntimeCaller::new(substrate_test_runtime::wasm_binary_unwrap()) - .get_named_patch(&"foobar".to_string()) + ::new(substrate_test_runtime::wasm_binary_unwrap()) + .get_named_patch(Some(&"foobar".to_string())) .unwrap(); let expected = r#"{"foo":"bar"}"#; assert_eq!(from_str::(expected).unwrap(), config); From 1fcb29859628ab140b3db93e74ce0f3485edd97c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:01:12 +0100 Subject: [PATCH 19/83] sc-chain-spec: little steps --- substrate/client/chain-spec/src/chain_spec.rs | 2 +- .../chain-spec/src/genesis_config_builder.rs | 33 ++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 4b424f33f43d..3fc0c5c65087 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -130,7 +130,7 @@ impl GenesisSource { code: code.clone(), })), Self::GenesisBuilderApi(GenesisBuildAction::NamedPatch(name, _), code) => { - let patch = RuntimeCaller::::new(&code[..]).get_named_patch(Some(name))?; + let patch = RuntimeCaller::::new(&code[..]).get_named_preset(Some(name))?; Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { json_blob: RuntimeGenesisConfigJson::Patch(patch), code: code.clone(), diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 5f279e77a460..c64a25448a14 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -84,15 +84,15 @@ where /// Returns the default `GenesisConfig` provided by the `runtime`. /// /// Calls [`GenesisBuilder::create_default_config`](sp_genesis_builder::GenesisBuilder::create_default_config) in the `runtime`. - fn get_default_config(&self) -> core::result::Result { - self.get_named_patch(None) + pub fn get_default_config(&self) -> core::result::Result { + self.get_named_preset(None) } /// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. /// /// Calls [`GenesisBuilder::get_preset`](sp_genesis_builder::GenesisBuilder::get_preset) /// provided by the `runtime`. - pub fn get_named_patch(&self, id: Option<&String>) -> core::result::Result { + pub fn get_named_preset(&self, id: Option<&String>) -> core::result::Result { let mut t = BasicExternalities::new_empty(); let call_result = self .call(&mut t, "GenesisBuilder_get_preset", &id.encode()) @@ -151,7 +151,19 @@ where &self, name: Option<&String>, ) -> core::result::Result { - self.get_storage_for_patch(self.get_named_patch(name)?) + self.get_storage_for_patch(self.get_named_preset(name)?) + } + + pub fn preset_names(&self) -> core::result::Result, String> { + let mut t = BasicExternalities::new_empty(); + let call_result = self + .call(&mut t, "GenesisBuilder_preset_names", &vec![]) + .map_err(|e| format!("wasm call error {e}"))?; + + let preset_names = Vec::::decode(&mut &call_result[..]) + .map_err(|e| format!("scale codec error: {e}"))?; + + Ok(preset_names) } } @@ -160,6 +172,17 @@ mod tests { use super::*; use serde_json::{from_str, json}; pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot}; + pub use sp_runtime::RuntimeString; + + #[test] + fn list_presets_works() { + sp_tracing::try_init_simple(); + let presets = + ::new(substrate_test_runtime::wasm_binary_unwrap()) + .preset_names() + .unwrap(); + assert_eq!(presets, vec![RuntimeString::from("foobar"), RuntimeString::from("staging"),]); + } #[test] fn get_default_config_works() { @@ -176,7 +199,7 @@ mod tests { sp_tracing::try_init_simple(); let config = ::new(substrate_test_runtime::wasm_binary_unwrap()) - .get_named_patch(Some(&"foobar".to_string())) + .get_named_preset(Some(&"foobar".to_string())) .unwrap(); let expected = r#"{"foo":"bar"}"#; assert_eq!(from_str::(expected).unwrap(), config); From 2b4626c365258062055877a0c6e9dfb82d3d1b6f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:22:09 +0100 Subject: [PATCH 20/83] chain-spec-builder: presets added --- .../bin/utils/chain-spec-builder/bin/main.rs | 27 +++++- .../bin/utils/chain-spec-builder/src/lib.rs | 95 +++++++++++++++---- 2 files changed, 103 insertions(+), 19 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 986293179a91..c709287ee078 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -18,10 +18,12 @@ use chain_spec_builder::{ generate_chain_spec_for_runtime, ChainSpecBuilder, ChainSpecBuilderCmd, ConvertToRawCmd, - UpdateCodeCmd, VerifyCmd, + DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, }; use clap::Parser; -use sc_chain_spec::{update_code_in_json_chain_spec, GenericChainSpec}; +use sc_chain_spec::{ + update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, +}; use staging_chain_spec_builder as chain_spec_builder; use std::fs; @@ -71,6 +73,27 @@ fn main() -> Result<(), String> { let _ = serde_json::from_str::(&chain_spec.as_json(true)?) .map_err(|e| format!("Conversion to json failed: {e}"))?; }, + ChainSpecBuilderCmd::ListPresets(ListPresetsCmd { runtime_wasm_path }) => { + let code = fs::read(runtime_wasm_path.as_path()) + .map_err(|e| format!("wasm blob shall be readable {e}"))?; + let caller: GenesisConfigBuilderRuntimeCaller = + GenesisConfigBuilderRuntimeCaller::new(&code[..]); + let presets = caller + .preset_names() + .map_err(|e| format!("getting default config from runtime should work: {e}"))?; + let presets: Vec = presets.into_iter().map(Into::into).collect(); + println!("Known presets are:\n{presets:#?}"); + }, + ChainSpecBuilderCmd::DisplayPreset(DisplayPresetCmd { runtime_wasm_path, preset_name }) => { + let code = fs::read(runtime_wasm_path.as_path()) + .map_err(|e| format!("wasm blob shall be readable {e}"))?; + let caller: GenesisConfigBuilderRuntimeCaller = + GenesisConfigBuilderRuntimeCaller::new(&code[..]); + let preset = caller + .get_named_preset(preset_name.as_ref()) + .map_err(|e| format!("getting default config from runtime should work: {e}"))?; + println!("{preset}"); + }, }; Ok(()) } diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 4cb7f242bfe0..a057dc4d75c1 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -28,17 +28,54 @@ //! See [`ChainSpecBuilderCmd`] for a list of available commands. //! //! ## Typical use-cases. -//! ##### Get default config from runtime. +//! ##### Generate chains-spec using default config from runtime. //! //! Query the default genesis config from the provided `runtime.wasm` and use it in the chain -//! spec. Tool can also store runtime's default genesis config in given file: +//! spec. //! ```text -//! chain-spec-builder create -r runtime.wasm default /dev/stdout +//! chain-spec-builder create -r runtime.wasm default //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::create_default_config`][sp-genesis-builder-create] runtime function is called. //! //! +//! ##### Display the runtime's default `GenesisConfig` +//! +//! Displays the content of the runtime's default `GenesisConfig` +//! ```text +//! chain-spec-builder display-preset -r runtime.wasm +//! ``` +//! +//! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. +//! +//! ##### Display the `GenesisConfig` preset with given name +//! +//! Displays the content of the `GenesisConfig` preset for given name +//! ```text +//! chain-spec-builder display-preset -r runtime.wasm -p "staging" +//! ``` +//! +//! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. +//! +//! ##### List the names of `GenesisConfig` presets provided by runtime. +//! +//! Displays the names of the presets of `GenesisConfigs` provided by runtime. +//! ```text +//! chain-spec-builder list-presets -r runtime.wasm +//! ``` +//! +//! _Note:_ [`GenesisBuilder::preset_names`][sp-genesis-builder-list] runtime function is called. +//! +//! ##### Generate chain spec using runtime provided genesis config preset. +//! +//! Patch the runtime's default genesis config with the named preset provided by the runtime and generate the plain +//! version of chain spec: +//! ```text +//! chain-spec-builder create -r runtime.wasm named-patch "staging" +//! ``` +//! +//! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] and [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime functions are called. +//! //! ##### Generate raw storage chain spec using genesis config patch. //! //! Patch the runtime's default genesis config with provided `patch.json` and generate raw @@ -46,7 +83,7 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm patch patch.json //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate raw storage chain spec using full genesis config. @@ -55,19 +92,19 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! _Note_: [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate human readable chain spec using provided genesis config patch. //! ```text //! chain-spec-builder create -r runtime.wasm patch patch.json //! ``` -//! +//! //! ##### Generate human readable chain spec using provided full genesis config. //! ```text //! chain-spec-builder create -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! ##### Extra tools. //! The `chain-spec-builder` provides also some extra utilities: [`VerifyCmd`], [`ConvertToRawCmd`], [`UpdateCodeCmd`]. //! @@ -76,6 +113,8 @@ //! [`sp-genesis-builder`]: ../sp_genesis_builder/index.html //! [sp-genesis-builder-create]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.create_default_config //! [sp-genesis-builder-build]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.build_state +//! [sp-genesis-builder-list]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.preset_names +//! [sp-genesis-builder-get-preset]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.get_preset use std::{fs, path::PathBuf}; @@ -101,6 +140,8 @@ pub enum ChainSpecBuilderCmd { Verify(VerifyCmd), UpdateCode(UpdateCodeCmd), ConvertToRaw(ConvertToRawCmd), + ListPresets(ListPresetsCmd), + DisplayPreset(DisplayPresetCmd), } /// Create a new chain spec by interacting with the provided runtime wasm blob. @@ -131,6 +172,7 @@ enum GenesisBuildAction { Patch(PatchCmd), Full(FullCmd), Default(DefaultCmd), + NamedPreset(NamedPresetCmd), } /// Patches the runtime's default genesis config with provided patch. @@ -151,10 +193,12 @@ struct FullCmd { /// default genesis config may not be valid. For some runtimes initial values should be added there /// (e.g. session keys, babe epoch). #[derive(Parser, Debug, Clone)] -struct DefaultCmd { - /// If provided stores the default genesis config json file at given path (in addition to - /// chain-spec). - default_config_path: Option, +struct DefaultCmd {} + +/// Uses named preset provided by runtime to build the chains spec. +#[derive(Parser, Debug, Clone)] +struct NamedPresetCmd { + preset_name: String, } /// Updates the code in the provided input chain spec. @@ -176,6 +220,25 @@ pub struct ConvertToRawCmd { pub input_chain_spec: PathBuf, } +/// Lists available presets +#[derive(Parser, Debug, Clone)] +pub struct ListPresetsCmd { + /// The path to runtime wasm blob. + #[arg(long, short)] + pub runtime_wasm_path: PathBuf, +} + +/// Displays given preset +#[derive(Parser, Debug, Clone)] +pub struct DisplayPresetCmd { + /// The path to runtime wasm blob. + #[arg(long, short)] + pub runtime_wasm_path: PathBuf, + /// Preset to be displayed. If none is given default will be displayed. + #[arg(long, short)] + pub preset_name: Option, +} + /// Verifies the provided input chain spec. /// /// Silently checks if given input chain spec can be converted to raw. It allows to check if all @@ -198,6 +261,8 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result + builder.with_genesis_config_patch_name(preset_name.clone()), GenesisBuildAction::Patch(PatchCmd { ref patch_path }) => { let patch = fs::read(patch_path.as_path()) .map_err(|e| format!("patch file {patch_path:?} shall be readable: {e}"))?; @@ -212,16 +277,12 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result { + GenesisBuildAction::Default(DefaultCmd {}) => { let caller: GenesisConfigBuilderRuntimeCaller = GenesisConfigBuilderRuntimeCaller::new(&code[..]); let default_config = caller .get_default_config() .map_err(|e| format!("getting default config from runtime should work: {e}"))?; - default_config_path.clone().map(|path| { - fs::write(path.as_path(), serde_json::to_string_pretty(&default_config).unwrap()) - .map_err(|err| err.to_string()) - }); builder.with_genesis_config(default_config) }, }; From 249b8136ad19addd97e73e01f426e990d543718a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:22:34 +0100 Subject: [PATCH 21/83] sp-genesis-builder: some doc added --- substrate/primitives/genesis-builder/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index ce77786d752a..85ad81458e55 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -19,6 +19,11 @@ //! Substrate genesis config builder //! +//! The runtime may provide a number of partial `GenesisConfig` configurations in form of patches +//! which shall be applied on top of the default GenesisConfig. This presets are sometimes refered +//! to as patches. This allows the runtime to provide a number of predefined configuration (e.g. for +//! different testnets) without leaking the runtime types outside the runtime. +//! //! This Runtime API allows to construct `GenesisConfig`, in particular: //! - serialize the runtime default `GenesisConfig` struct into json format, //! - put the GenesisConfig struct into the storage. Internally this operation calls From b597ccc4fdb2e4e0d86159571189ecff8b2fb314 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 10:29:00 +0100 Subject: [PATCH 22/83] doc fixed --- .../support/src/genesis_builder_helper.rs | 6 +- .../primitives/genesis-builder/src/lib.rs | 73 +++++++++++-------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 750e41565f4b..5cc279d48e07 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -43,8 +43,10 @@ pub fn build_state(json: sp_std::vec::Vec) -> BuildR Ok(()) } -/// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. -/// For more info refer to [`sp_genesis_builder::GenesisBuilder::get_preset`]. +/// Get the default `GenesisConfig` as a JSON blob if `id` is None. +/// +/// No named presets are supported. For more info refer to +/// [`sp_genesis_builder::GenesisBuilder::get_preset`]. pub fn get_preset(id: Option>) -> Option> where GC: BuildGenesisConfig + Default, diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 85ad81458e55..85a5d875cf18 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -19,59 +19,68 @@ //! Substrate genesis config builder //! -//! The runtime may provide a number of partial `GenesisConfig` configurations in form of patches -//! which shall be applied on top of the default GenesisConfig. This presets are sometimes refered -//! to as patches. This allows the runtime to provide a number of predefined configuration (e.g. for -//! different testnets) without leaking the runtime types outside the runtime. +//! The runtime may provide a number of partial `RuntimeGenesisConfig` configurations in form of +//! patches which shall be applied on top of the default `RuntimeGenesisConfig`. Thus presets are +//! sometimes refered to as patches. This allows the runtime to provide a number of predefined +//! configuration (e.g. for different testnets) without leaking the runtime types outside the +//! runtime. //! -//! This Runtime API allows to construct `GenesisConfig`, in particular: -//! - serialize the runtime default `GenesisConfig` struct into json format, -//! - put the GenesisConfig struct into the storage. Internally this operation calls -//! `GenesisBuild::build` function for all runtime pallets, which is typically provided by -//! pallet's author. -//! - deserialize the `GenesisConfig` from given json blob and put `GenesisConfig` into the state -//! storage. Allows to build customized configuration. -//! - provide a named, built-in, predefined preset of `GenesisConfig`, -//! - provide the list of preset names, +//! This Runtime API allows to interact with `RuntimeGenesisConfig`, in particular: +//! - provide the list of available preset names, +//! - provide a number of named, built-in, presets of `RuntimeGenesisConfig`, +//! - serialize the default `RuntimeGenesisConfig` struct into json format, +//! - deserialize the `RuntimeGenesisConfig` from given json blob and put the resulting +//! `RuntimeGenesisConfig` into the state storage creating the initial runtime's state. Allows to +//! build customized genesis. This operation internally calls `GenesisBuild::build` function for +//! all runtime pallets. //! -//! Providing externalities with empty storage and putting `GenesisConfig` into storage allows to -//! catch and build the raw storage of `GenesisConfig` which is the foundation for genesis block. +//! Providing externalities with empty storage and putting `RuntimeGenesisConfig` into storage +//! allows to catch and build the raw storage of `RuntimeGenesisConfig` which is the foundation for +//! genesis block. /// The result type alias, used in build methods. `Err` contains formatted error message. pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; sp_api::decl_runtime_apis! { - /// API to interact with GenesisConfig for the runtime + /// API to interact with RuntimeGenesisConfig for the runtime #[api_version(2)] pub trait GenesisBuilder { - /// Creates the default `GenesisConfig` and returns it as a JSON blob. + /// Creates the default `RuntimeGenesisConfig` and returns it as a JSON blob. /// - /// This function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON - /// blob. It returns a `Vec` containing the JSON representation of the default `GenesisConfig`. + /// This function instantiates the default `RuntimeGenesisConfig` struct for the runtime and + /// serializes it into a JSON blob. It returns a `Vec` containing the JSON + /// representation of the default `RuntimeGenesisConfig`. fn create_default_config() -> sp_std::vec::Vec; - /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. + /// Build `RuntimeGenesisConfig` from a JSON blob not using any defaults and store it in the + /// storage. /// - /// This function deserializes the full `GenesisConfig` from the given JSON blob and puts it into the storage. - /// If the provided JSON blob is incorrect or incomplete or the deserialization fails, an error is returned. - /// It is recommended to log any errors encountered during the process. + /// This function deserializes the full `RuntimeGenesisConfig` from the given JSON blob and + /// puts it into the storage. If the provided JSON blob is incorrect or incomplete or the + /// deserialization fails, an error is returned. /// - /// Please note that provided json blob must contain all `GenesisConfig` fields, no defaults will be used. + /// Please note that provided json blob must contain all `RuntimeGenesisConfig` fields, no + /// defaults will be used. #[renamed("build_config", 2)] fn build_state(json: sp_std::vec::Vec) -> Result; - /// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. + /// Returns a JSON blob representation of the built-in `RuntimeGenesisConfig` identified by + /// `id`. /// - /// If `id` is `None` the function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON - /// blob. It returns a `Vec` containing the JSON representation of the default `GenesisConfig`. - /// Otherwise returns a JSON representation of the built-in, named, pre-configured `GenesisConfig` value. + /// If `id` is `None` the function returns JSON blob representation of the default + /// `RuntimeGenesisConfig` struct of the runtime. Implementation must provide default + /// `RuntimeGenesisConfig`. + /// + /// Otherwise function returns a JSON representation of the built-in, named + /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not + /// exists. Returned `Vec` contains bytes of JSON blob. #[api_version(2)] - fn get_preset(id: Option>) -> Option>; + fn get_preset(id: Option) -> Option>; - /// Returns a list of available builtin `GenesisConfig` presets. + /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. /// - /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If no named presets are - /// provided by the runtime the list is empty. + /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If + /// no named presets are provided by the runtime the list is empty. #[api_version(2)] fn preset_names() -> sp_std::vec::Vec; } From c23859510daf4cf78985b9c19c2c08690a1b7729 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:54:32 +0100 Subject: [PATCH 23/83] Revert "rococo: some initial thing" This reverts commit 262bd70bcd73fbcb1fd5f709823f1a511a61f14e. --- polkadot/runtime/rococo/Cargo.toml | 3 +- polkadot/runtime/rococo/src/lib.rs | 629 +++-------------------------- 2 files changed, 64 insertions(+), 568 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 346bb6a7c365..c7236572ed7d 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -104,7 +104,6 @@ polkadot-parachain-primitives = { path = "../../parachain", default-features = f xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -serde_json = { version = "1.0.108", default-features = false, features = ["alloc"] } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } @@ -112,6 +111,7 @@ keyring = { package = "sp-keyring", path = "../../../substrate/primitives/keyrin remote-externalities = { package = "frame-remote-externalities", path = "../../../substrate/utils/frame/remote-externalities" } sp-trie = { path = "../../../substrate/primitives/trie" } separator = "0.4.1" +serde_json = "1.0.108" sp-tracing = { path = "../../../substrate/primitives/tracing", default-features = false } tokio = { version = "1.24.2", features = ["macros"] } @@ -191,7 +191,6 @@ std = [ "scale-info/std", "serde/std", "serde_derive", - "serde_json/std", "sp-api/std", "sp-arithmetic/std", "sp-core/std", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 75f19d12b236..11c1cdaaed9f 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1727,407 +1727,6 @@ mod benches { [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] ); } -fn default_parachains_host_configuration( -) -> runtime_parachains::configuration::HostConfiguration { - use primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; - - 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() - } -} - -use babe_primitives::AuthorityId as BabeId; -use primitives::AssignmentId; -use sp_core::crypto::Public; -// use sp_core::{sr25519, Pair, 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() -// } -// -// 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"), -// ] -// } -// -fn rococo_session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, -) -> SessionKeys { - SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } -} -pub fn rococo_testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )>, - root_key: AccountId, - endowed_accounts: Option>, -) -> serde_json::Value { - let endowed_accounts: Vec = endowed_accounts.unwrap(); - - const ENDOWMENT: u128 = 1_000_000 * UNITS; - - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), - }, - "session": { - "keys": initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - rococo_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - "babe": { - "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), - }, - "sudo": { "key": Some(root_key.clone()) }, - "configuration": { - "config": runtime_parachains::configuration::HostConfiguration { - max_validators_per_core: Some(1), - ..default_parachains_host_configuration() - }, - }, - "registrar": { - "nextFreeParaId": primitives::LOWEST_PUBLIC_ID, - } - }) -} - -fn rococo_testnet_genesis_staging() -> serde_json::Value { - let endowed_accounts: sp_std::vec::Vec = vec![ - // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs - hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(), - ]; - - // ./scripts/prepare-test-net.sh 8 - let initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )> = vec![ - ( - //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei - hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(), - //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd - hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(), - //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H - hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"] - .unchecked_into(), - //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 - hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] - .unchecked_into(), - //5F7BEa1LGFksUihyatf3dCDYneB8pWzVyavnByCsm5nBgezi - hex!["86975a37211f8704e947a365b720f7a3e2757988eaa7d0f197e83dba355ef743"] - .unchecked_into(), - //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz - hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] - .unchecked_into(), - //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b - hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"] - .unchecked_into(), - //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq - hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"] - .unchecked_into(), - //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu - hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"] - .unchecked_into(), - ), - ( - //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG - hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(), - //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3 - hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(), - //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM - hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"] - .unchecked_into(), - //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao - hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] - .unchecked_into(), - //5DhyXZiuB1LvqYKFgT5tRpgGsN3is2cM9QxgW7FikvakbAZP - hex!["48a910c0af90898f11bd57d37ceaea53c78994f8e1833a7ade483c9a84bde055"] - .unchecked_into(), - //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF - hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] - .unchecked_into(), - //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ - hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"] - .unchecked_into(), - //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw - hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"] - .unchecked_into(), - //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5 - hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"] - .unchecked_into(), - ), - ( - //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S - hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(), - //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx - hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(), - //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY - hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"] - .unchecked_into(), - //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP - hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] - .unchecked_into(), - //5HTXBf36LXmkFWJLokNUK6fPxVpkr2ToUnB1pvaagdGu4c1T - hex!["ee93e26259decb89afcf17ef2aa0fa2db2e1042fb8f56ecfb24d19eae8629878"] - .unchecked_into(), - //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU - hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] - .unchecked_into(), - //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV - hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"] - .unchecked_into(), - //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa - hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"] - .unchecked_into(), - //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF - hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"] - .unchecked_into(), - ), - ( - //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR - hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(), - //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v - hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(), - //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1 - hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"] - .unchecked_into(), - //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte - hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] - .unchecked_into(), - //5FHf8kpK4fPjEJeYcYon2gAPwEBubRvtwpzkUbhMWSweKPUY - hex!["8e95b9b5b4dc69790b67b566567ca8bf8cdef3a3a8bb65393c0d1d1c87cd2d2c"] - .unchecked_into(), - //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA - hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] - .unchecked_into(), - //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP - hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"] - .unchecked_into(), - //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA - hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"] - .unchecked_into(), - //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz - hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"] - .unchecked_into(), - ), - ( - //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N - hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(), - //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa - hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(), - //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7 - hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"] - .unchecked_into(), - //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG - hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] - .unchecked_into(), - //5GqL8RbVAuNXpDhjQi1KrS1MyNuKhvus2AbmQwRGjpuGZmFu - hex!["d2f9d537ffa59919a4028afdb627c14c14c97a1547e13e8e82203d2049b15b1a"] - .unchecked_into(), - //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N - hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] - .unchecked_into(), - //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG - hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"] - .unchecked_into(), - //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ - hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"] - .unchecked_into(), - //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ - hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"] - .unchecked_into(), - ), - ( - //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF - hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(), - //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM - hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(), - //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD - hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"] - .unchecked_into(), - //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB - hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] - .unchecked_into(), - //5GWZbVkJEfWZ7fRca39YAQeqri2Z7pkeHyd7rUctUHyQifLp - hex!["c4a980da30939d5bb9e4a734d12bf81259ae286aa21fa4b65405347fa40eff35"] - .unchecked_into(), - //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE - hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] - .unchecked_into(), - //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS - hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"] - .unchecked_into(), - //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd - hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"] - .unchecked_into(), - //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT - hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"] - .unchecked_into(), - ), - ( - //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM - hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(), - //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7 - hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(), - //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96 - hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"] - .unchecked_into(), - //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N - hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] - .unchecked_into(), - //5E1Y1FJ7dVP7qtE3wm241pTm72rTMcDT5Jd8Czv7Pwp7N3AH - hex!["560d90ca51e9c9481b8a9810060e04d0708d246714960439f804e5c6f40ca651"] - .unchecked_into(), - //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT - hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] - .unchecked_into(), - //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa - hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"] - .unchecked_into(), - //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7 - hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"] - .unchecked_into(), - //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx - hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"] - .unchecked_into(), - ), - ( - //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di - hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(), - //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV - hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(), - //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8 - hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"] - .unchecked_into(), - //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF - hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] - .unchecked_into(), - //5FNFDUGNLUtqg5LgrwYLNmBiGoP8KRxsvQpBkc7GQP6qaBUG - hex!["92156f54a114ee191415898f2da013d9db6a5362d6b36330d5fc23e27360ab66"] - .unchecked_into(), - //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F - hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] - .unchecked_into(), - //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx - hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"] - .unchecked_into(), - //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T - hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"] - .unchecked_into(), - //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7 - hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"] - .unchecked_into(), - ), - ]; - let root_key = endowed_accounts[0].clone(); - - //patch - rococo_testnet_genesis(initial_authorities, root_key, Some(endowed_accounts)) -} - -use serde_json::Value; -pub fn merge(a: &mut Value, b: Value) { - match (a, b) { - (Value::Object(a), Value::Object(b)) => - for (k, v) in b { - if v.is_null() { - a.remove(&k); - } else { - merge(a.entry(k).or_insert(Value::Null), v); - } - }, - (a, b) => *a = b, - }; -} -use hex_literal::hex; -use sp_core::crypto::UncheckedInto; sp_api::impl_runtime_apis! { impl sp_api::Core for Runtime { @@ -2174,7 +1773,7 @@ sp_api::impl_runtime_apis! { fn check_inherents( block: Block, data: inherents::InherentData, - ) -> inherents::CheckInherentsResult { + ) -> inherents::CheckInherentsResult { data.check_extrinsics(&block) } } @@ -2184,7 +1783,7 @@ sp_api::impl_runtime_apis! { source: TransactionSource, tx: ::Extrinsic, block_hash: ::Hash, - ) -> TransactionValidity { + ) -> TransactionValidity { Executive::validate_transaction(source, tx, block_hash) } } @@ -2211,23 +1810,23 @@ sp_api::impl_runtime_apis! { fn persisted_validation_data(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option> { - parachains_runtime_api_impl::persisted_validation_data::(para_id, assumption) - } + parachains_runtime_api_impl::persisted_validation_data::(para_id, assumption) + } fn assumed_validation_data( para_id: ParaId, expected_persisted_validation_data_hash: Hash, - ) -> Option<(PersistedValidationData, ValidationCodeHash)> { + ) -> Option<(PersistedValidationData, ValidationCodeHash)> { parachains_runtime_api_impl::assumed_validation_data::( para_id, expected_persisted_validation_data_hash, - ) + ) } fn check_validation_outputs( para_id: ParaId, outputs: primitives::CandidateCommitments, - ) -> bool { + ) -> bool { parachains_runtime_api_impl::check_validation_outputs::(para_id, outputs) } @@ -2237,8 +1836,8 @@ sp_api::impl_runtime_apis! { fn validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option { - parachains_runtime_api_impl::validation_code::(para_id, assumption) - } + parachains_runtime_api_impl::validation_code::(para_id, assumption) + } fn candidate_pending_availability(para_id: ParaId) -> Option> { parachains_runtime_api_impl::candidate_pending_availability::(para_id) @@ -2269,7 +1868,7 @@ sp_api::impl_runtime_apis! { fn inbound_hrmp_channels_contents( recipient: ParaId - ) -> BTreeMap>> { + ) -> BTreeMap>> { parachains_runtime_api_impl::inbound_hrmp_channels_contents::(recipient) } @@ -2284,7 +1883,7 @@ sp_api::impl_runtime_apis! { fn submit_pvf_check_statement( stmt: primitives::PvfCheckStatement, signature: primitives::ValidatorSignature - ) { + ) { parachains_runtime_api_impl::submit_pvf_check_statement::(stmt, signature) } @@ -2294,22 +1893,22 @@ sp_api::impl_runtime_apis! { fn validation_code_hash(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option - { - parachains_runtime_api_impl::validation_code_hash::(para_id, assumption) - } + { + parachains_runtime_api_impl::validation_code_hash::(para_id, assumption) + } fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState)> { parachains_runtime_api_impl::get_session_disputes::() } fn unapplied_slashes( - ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { parachains_runtime_api_impl::unapplied_slashes::() } fn key_ownership_proof( validator_id: ValidatorId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((PARACHAIN_KEY_TYPE_ID, validator_id)) @@ -2320,11 +1919,11 @@ sp_api::impl_runtime_apis! { fn submit_report_dispute_lost( dispute_proof: slashing::DisputeProof, key_ownership_proof: slashing::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { parachains_runtime_api_impl::submit_unsigned_slashing_report::( dispute_proof, key_ownership_proof, - ) + ) } fn minimum_backing_votes() -> u32 { @@ -2364,24 +1963,24 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: beefy_primitives::EquivocationProof< - BlockNumber, - BeefyId, - BeefySignature, + BlockNumber, + BeefyId, + BeefySignature, >, key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; Beefy::submit_unsigned_equivocation_report( equivocation_proof, key_owner_proof, - ) + ) } fn generate_key_ownership_proof( _set_id: beefy_primitives::ValidatorSetId, authority_id: BeefyId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((beefy_primitives::KEY_TYPE, authority_id)) @@ -2403,35 +2002,35 @@ sp_api::impl_runtime_apis! { fn generate_proof( block_numbers: Vec, best_known_block_number: Option, - ) -> Result<(Vec, mmr::Proof), mmr::Error> { + ) -> Result<(Vec, mmr::Proof), mmr::Error> { Mmr::generate_proof(block_numbers, best_known_block_number).map( |(leaves, proof)| { ( leaves - .into_iter() - .map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)) - .collect(), + .into_iter() + .map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)) + .collect(), proof, - ) + ) }, - ) + ) } fn verify_proof(leaves: Vec, proof: mmr::Proof) -> Result<(), mmr::Error> - { - let leaves = leaves.into_iter().map(|leaf| - leaf.into_opaque_leaf() - .try_decode() - .ok_or(mmr::Error::Verify)).collect::, mmr::Error>>()?; - Mmr::verify_leaves(leaves, proof) - } + { + let leaves = leaves.into_iter().map(|leaf| + leaf.into_opaque_leaf() + .try_decode() + .ok_or(mmr::Error::Verify)).collect::, mmr::Error>>()?; + Mmr::verify_leaves(leaves, proof) + } fn verify_proof_stateless( root: mmr::Hash, leaves: Vec, proof: mmr::Proof - ) -> Result<(), mmr::Error> { + ) -> Result<(), mmr::Error> { let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect(); pallet_mmr::verify_leaves_proof::(root, nodes, proof) } @@ -2448,23 +2047,23 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: fg_primitives::EquivocationProof< - ::Hash, - sp_runtime::traits::NumberFor, + ::Hash, + sp_runtime::traits::NumberFor, >, key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; Grandpa::submit_unsigned_equivocation_report( equivocation_proof, key_owner_proof, - ) + ) } fn generate_key_ownership_proof( _set_id: fg_primitives::SetId, authority_id: fg_primitives::AuthorityId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((fg_primitives::KEY_TYPE, authority_id)) @@ -2501,7 +2100,7 @@ sp_api::impl_runtime_apis! { fn generate_key_ownership_proof( _slot: babe_primitives::Slot, authority_id: babe_primitives::AuthorityId, - ) -> Option { + ) -> Option { use parity_scale_codec::Encode; Historical::prove((babe_primitives::KEY_TYPE, authority_id)) @@ -2512,13 +2111,13 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: babe_primitives::EquivocationProof<::Header>, key_owner_proof: babe_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { + ) -> Option<()> { let key_owner_proof = key_owner_proof.decode()?; Babe::submit_unsigned_equivocation_report( equivocation_proof, key_owner_proof, - ) + ) } } @@ -2535,7 +2134,7 @@ sp_api::impl_runtime_apis! { fn decode_session_keys( encoded: Vec, - ) -> Option, sp_core::crypto::KeyTypeId)>> { + ) -> Option, sp_core::crypto::KeyTypeId)>> { SessionKeys::decode_into_raw_public_keys(&encoded) } } @@ -2549,20 +2148,20 @@ sp_api::impl_runtime_apis! { impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< Block, Balance, - > for Runtime { - fn query_info(uxt: ::Extrinsic, len: u32) -> RuntimeDispatchInfo { - TransactionPayment::query_info(uxt, len) - } - fn query_fee_details(uxt: ::Extrinsic, len: u32) -> FeeDetails { - TransactionPayment::query_fee_details(uxt, len) - } - fn query_weight_to_fee(weight: Weight) -> Balance { - TransactionPayment::weight_to_fee(weight) - } - fn query_length_to_fee(length: u32) -> Balance { - TransactionPayment::length_to_fee(length) - } + > for Runtime { + fn query_info(uxt: ::Extrinsic, len: u32) -> RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details(uxt: ::Extrinsic, len: u32) -> FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) } + } impl pallet_beefy_mmr::BeefyMmrApi for RuntimeApi { fn authority_set_proof() -> beefy_primitives::mmr::BeefyAuthoritySet { @@ -2587,7 +2186,7 @@ sp_api::impl_runtime_apis! { state_root_check: bool, signature_check: bool, select: frame_try_runtime::TryStateSelect, - ) -> Weight { + ) -> Weight { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() @@ -2599,7 +2198,7 @@ sp_api::impl_runtime_apis! { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, - ) { + ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; @@ -2617,7 +2216,7 @@ sp_api::impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig, - ) -> Result< + ) -> Result< Vec, sp_runtime::RuntimeString, > { @@ -2726,89 +2325,6 @@ sp_api::impl_runtime_apis! { fun: Fungible(1 * UNITS), } } - - parameter_types! { - pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - AssetHub::get(), - MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, - )); - pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; - } - - impl pallet_xcm_benchmarks::fungible::Config for Runtime { - type TransactAsset = Balances; - - type CheckedAccount = LocalCheckAccount; - type TrustedTeleporter = TrustedTeleporter; - type TrustedReserve = TrustedReserve; - - fn get_multi_asset() -> MultiAsset { - MultiAsset { - id: Concrete(TokenLocation::get()), - fun: Fungible(1 * UNITS), - } - } - } - - impl pallet_xcm_benchmarks::generic::Config for Runtime { - type RuntimeCall = RuntimeCall; - - fn worst_case_response() -> (u64, Response) { - (0u64, Response::Version(Default::default())) - } - - fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { - // Rococo doesn't support asset exchanges - Err(BenchmarkError::Skip) - } - - fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { - // The XCM executor of Rococo doesn't have a configured `UniversalAliases` - Err(BenchmarkError::Skip) - } - - fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { - Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) - } - - fn subscribe_origin() -> Result { - Ok(AssetHub::get()) - } - - fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { - let origin = AssetHub::get(); - let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into(); - let ticket = MultiLocation { parents: 0, interior: Here }; - Ok((origin, ticket, assets)) - } - - fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { - // Rococo doesn't support asset locking - Err(BenchmarkError::Skip) - } - - fn export_message_origin_and_destination( - ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { - // Rococo doesn't support exporting messages - Err(BenchmarkError::Skip) - } - - fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> { - // The XCM executor of Rococo doesn't have a configured `Aliasers` - Err(BenchmarkError::Skip) - } - } - - let mut whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); - let treasury_key = frame_system::Account::::hashed_key_for(Treasury::account_id()); - whitelist.push(treasury_key.to_vec().into()); - - let mut batches = Vec::::new(); - let params = (&config, &whitelist); - - add_benchmarks!(params, batches); - - Ok(batches) } impl pallet_xcm_benchmarks::generic::Config for Runtime { @@ -2882,25 +2398,6 @@ sp_api::impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } - - fn create_default_config2(params: sp_std::vec::Vec) -> sp_std::vec::Vec { - let default = serde_json::to_string(&RuntimeGenesisConfig::default()) - .expect("serialization to json is expected to work. qed.") - .into_bytes(); - let mut default = - serde_json::from_slice(&default[..]).expect("returned value is json. qed."); - - log::info!("xxx: create_default_config2: {:?} {:?}", params, "staging".as_bytes()); - if params == "staging".as_bytes() { - let patch = rococo_testnet_genesis_staging(); - merge(&mut default, patch); - } - - - serde_json::to_string(&default) - .expect("serialization to json is expected to work. qed.") - .into_bytes() - } } } From a76dffe9252c14336e103d259cb8f31d162990b4 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:57:35 +0100 Subject: [PATCH 24/83] test-runtime: fix --- .../primitives/genesis-builder/src/lib.rs | 2 +- substrate/test-utils/runtime/src/lib.rs | 39 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 85a5d875cf18..ae44189b7751 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -75,7 +75,7 @@ sp_api::decl_runtime_apis! { /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not /// exists. Returned `Vec` contains bytes of JSON blob. #[api_version(2)] - fn get_preset(id: Option) -> Option>; + fn get_preset(id: Option>) -> Option>; /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. /// diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 10427c4e9899..27a43843a5ba 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -472,25 +472,6 @@ pub const TEST_RUNTIME_BABE_EPOCH_CONFIGURATION: BabeEpochConfiguration = BabeEp allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots, }; -fn substrate_test_genesis_config_patch() -> serde_json::Value { - let endowed_accounts: sp_std::vec::Vec = - vec![AccountKeyring::Bob.public().into(), AccountKeyring::Charlie.public().into()]; - log::info!("xxx: {} {}", file!(), line!()); - - let patch = json!({ - "balances": { - "balances": endowed_accounts.iter().map(|k| (k.clone(), 10 * currency::DOLLARS)).collect::>(), - }, - "substrateTest": { - "authorities": [ - AccountKeyring::Alice.public().to_ss58check(), - AccountKeyring::Ferdie.public().to_ss58check() - ], - } - }); - patch -} - impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { @@ -753,10 +734,26 @@ impl_runtime_apis! { } fn get_preset(params: Option>) -> Option> { - log::info!("xxx: create_default_config2: {:?} {:?}", params, "staging".as_bytes()); Some(if let Some(params) = params { let patch = match params { - s if s == "staging".as_bytes() => substrate_test_genesis_config_patch(), + s if s == "staging".as_bytes() => { + let endowed_accounts: sp_std::vec::Vec = vec![ + AccountKeyring::Bob.public().into(), + AccountKeyring::Charlie.public().into(), + ]; + + json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), 10 * currency::DOLLARS)).collect::>(), + }, + "substrateTest": { + "authorities": [ + AccountKeyring::Alice.public().to_ss58check(), + AccountKeyring::Ferdie.public().to_ss58check() + ], + } + }) + }, s if s == "foobar".as_bytes() => json!({"foo":"bar"}), _ => return None, }; From 0a51ea8a7f8137603c09c04ed436dffea135745e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:53:41 +0100 Subject: [PATCH 25/83] rococo-runtime: presets added --- polkadot/node/service/src/chain_spec.rs | 283 +--------- polkadot/runtime/rococo/Cargo.toml | 3 +- .../runtime/rococo/src/genesis_configs.rs | 496 ++++++++++++++++++ polkadot/runtime/rococo/src/lib.rs | 23 +- 4 files changed, 521 insertions(+), 284 deletions(-) create mode 100644 polkadot/runtime/rococo/src/genesis_configs.rs diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index fd35a4aaf6ab..99a080648adf 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -372,265 +372,6 @@ fn westend_staging_testnet_config_genesis() -> serde_json::Value { }) } -#[cfg(feature = "rococo-native")] -fn rococo_staging_testnet_config_genesis() -> serde_json::Value { - use hex_literal::hex; - use sp_core::crypto::UncheckedInto; - - // subkey inspect "$SECRET" - let endowed_accounts = vec![ - // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs - hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(), - ]; - - // ./scripts/prepare-test-net.sh 8 - let initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )> = vec![ - ( - //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei - hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(), - //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd - hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(), - //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H - hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"] - .unchecked_into(), - //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 - hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] - .unchecked_into(), - //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz - hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] - .unchecked_into(), - //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b - hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"] - .unchecked_into(), - //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq - hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"] - .unchecked_into(), - //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu - hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"] - .unchecked_into(), - ), - ( - //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG - hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(), - //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3 - hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(), - //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM - hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"] - .unchecked_into(), - //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao - hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] - .unchecked_into(), - //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF - hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] - .unchecked_into(), - //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ - hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"] - .unchecked_into(), - //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw - hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"] - .unchecked_into(), - //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5 - hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"] - .unchecked_into(), - ), - ( - //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S - hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(), - //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx - hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(), - //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY - hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"] - .unchecked_into(), - //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP - hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] - .unchecked_into(), - //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU - hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] - .unchecked_into(), - //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV - hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"] - .unchecked_into(), - //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa - hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"] - .unchecked_into(), - //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF - hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"] - .unchecked_into(), - ), - ( - //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR - hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(), - //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v - hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(), - //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1 - hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"] - .unchecked_into(), - //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte - hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] - .unchecked_into(), - //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA - hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] - .unchecked_into(), - //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP - hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"] - .unchecked_into(), - //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA - hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"] - .unchecked_into(), - //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz - hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"] - .unchecked_into(), - ), - ( - //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N - hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(), - //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa - hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(), - //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7 - hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"] - .unchecked_into(), - //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG - hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] - .unchecked_into(), - //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N - hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] - .unchecked_into(), - //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG - hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"] - .unchecked_into(), - //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ - hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"] - .unchecked_into(), - //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ - hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"] - .unchecked_into(), - ), - ( - //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF - hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(), - //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM - hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(), - //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD - hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"] - .unchecked_into(), - //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB - hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] - .unchecked_into(), - //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE - hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] - .unchecked_into(), - //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS - hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"] - .unchecked_into(), - //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd - hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"] - .unchecked_into(), - //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT - hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"] - .unchecked_into(), - ), - ( - //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM - hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(), - //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7 - hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(), - //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96 - hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"] - .unchecked_into(), - //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N - hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] - .unchecked_into(), - //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT - hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] - .unchecked_into(), - //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa - hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"] - .unchecked_into(), - //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7 - hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"] - .unchecked_into(), - //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx - hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"] - .unchecked_into(), - ), - ( - //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di - hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(), - //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV - hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(), - //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8 - hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"] - .unchecked_into(), - //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF - hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] - .unchecked_into(), - //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F - hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] - .unchecked_into(), - //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx - hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"] - .unchecked_into(), - //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T - hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"] - .unchecked_into(), - //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7 - hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"] - .unchecked_into(), - ), - ]; - - const ENDOWMENT: u128 = 1_000_000 * ROC; - const STASH: u128 = 100 * ROC; - - serde_json::json!({ - "balances": { - "balances": endowed_accounts - .iter() - .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect::>(), - }, - "session": { - "keys": initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - rococo_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - ), - ) - }) - .collect::>(), - }, - "babe": { - "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - }, - "sudo": { "key": Some(endowed_accounts[0].clone()) }, - "configuration": { - "config": default_parachains_host_configuration(), - }, - "registrar": { - "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, - }, - }) -} - /// Westend staging testnet config. #[cfg(feature = "westend-native")] pub fn westend_staging_testnet_config() -> Result { @@ -660,7 +401,7 @@ pub fn rococo_staging_testnet_config() -> Result { .with_name("Rococo Staging Testnet") .with_id("rococo_staging_testnet") .with_chain_type(ChainType::Live) - .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) + .with_genesis_config_patch_name("staging_testnet") .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Rococo Staging telemetry url is valid; qed"), @@ -901,15 +642,6 @@ fn westend_development_config_genesis() -> serde_json::Value { ) } -#[cfg(feature = "rococo-native")] -fn rococo_development_config_genesis() -> serde_json::Value { - rococo_testnet_genesis( - vec![get_authority_keys_from_seed("Alice")], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// Westend development config (single validator Alice) #[cfg(feature = "westend-native")] pub fn westend_development_config() -> Result { @@ -935,7 +667,7 @@ pub fn rococo_development_config() -> Result { .with_name("Development") .with_id("rococo_dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(rococo_development_config_genesis()) + .with_genesis_config_patch_name("development") .with_protocol_id(DEFAULT_PROTOCOL_ID) .build()) } @@ -995,15 +727,6 @@ pub fn westend_local_testnet_config() -> Result { .build()) } -#[cfg(feature = "rococo-native")] -fn rococo_local_testnet_genesis() -> serde_json::Value { - rococo_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// Rococo local testnet config (multivalidator Alice + Bob) #[cfg(feature = "rococo-native")] pub fn rococo_local_testnet_config() -> Result { @@ -1014,7 +737,7 @@ pub fn rococo_local_testnet_config() -> Result { .with_name("Rococo Local Testnet") .with_id("rococo_local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(rococo_local_testnet_genesis()) + .with_genesis_config_patch_name("local_testnet") .with_protocol_id(DEFAULT_PROTOCOL_ID) .build()) } diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index c7236572ed7d..d3d40af32069 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -16,12 +16,14 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive log = { version = "0.4.17", default-features = false } serde = { version = "1.0.193", default-features = false } serde_derive = { version = "1.0.117", optional = true } +serde_json = { version = "1.0.108", default-features = false, features = ["alloc"] } static_assertions = "1.1.0" smallvec = "1.8.0" authority-discovery-primitives = { package = "sp-authority-discovery", path = "../../../substrate/primitives/authority-discovery", default-features = false } babe-primitives = { package = "sp-consensus-babe", path = "../../../substrate/primitives/consensus/babe", default-features = false } beefy-primitives = { package = "sp-consensus-beefy", path = "../../../substrate/primitives/consensus/beefy", default-features = false } +grandpa_primitives = { package = "sp-consensus-grandpa", path = "../../../substrate/primitives/consensus/grandpa" , default-features = false } binary-merkle-tree = { path = "../../../substrate/utils/binary-merkle-tree", default-features = false } rococo-runtime-constants = { package = "rococo-runtime-constants", path = "constants", default-features = false } sp-api = { path = "../../../substrate/primitives/api", default-features = false } @@ -111,7 +113,6 @@ keyring = { package = "sp-keyring", path = "../../../substrate/primitives/keyrin remote-externalities = { package = "frame-remote-externalities", path = "../../../substrate/utils/frame/remote-externalities" } sp-trie = { path = "../../../substrate/primitives/trie" } separator = "0.4.1" -serde_json = "1.0.108" sp-tracing = { path = "../../../substrate/primitives/tracing", default-features = false } tokio = { version = "1.24.2", features = ["macros"] } diff --git a/polkadot/runtime/rococo/src/genesis_configs.rs b/polkadot/runtime/rococo/src/genesis_configs.rs new file mode 100644 index 000000000000..376d860d80f6 --- /dev/null +++ b/polkadot/runtime/rococo/src/genesis_configs.rs @@ -0,0 +1,496 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Genesis configs presets for the Rococo runtime + +use crate::{SessionKeys, BABE_GENESIS_EPOCH_CONFIG}; +use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; +use babe_primitives::AuthorityId as BabeId; +use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; +use grandpa_primitives::AuthorityId as GrandpaId; +use primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +use rococo_runtime_constants::currency::UNITS as ROC; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::traits::IdentifyAccount; +#[cfg(not(feature = "std"))] +use sp_std::alloc::format; +use sp_std::vec::Vec; + +/// 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, + 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, 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, 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), + ) +} + +fn testnet_accounts() -> Vec { + Vec::from([ + 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"), + ]) +} + +fn rococo_session_keys( + babe: BabeId, + grandpa: GrandpaId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> SessionKeys { + SessionKeys { babe, grandpa, para_validator, para_assignment, authority_discovery, beefy } +} + +fn default_parachains_host_configuration( +) -> runtime_parachains::configuration::HostConfiguration { + use primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + + 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() + } +} + +#[test] +fn default_parachains_host_configuration_is_consistent() { + default_parachains_host_configuration().panic_if_not_consistent(); +} + +fn rococo_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + root_key: AccountId, + endowed_accounts: Option>, +) -> serde_json::Value { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * ROC; + + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), + }, + "session": { + "keys": initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + rococo_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect::>(), + }, + "babe": { + "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), + }, + "sudo": { "key": Some(root_key.clone()) }, + "configuration": { + "config": runtime_parachains::configuration::HostConfiguration { + max_validators_per_core: Some(1), + ..default_parachains_host_configuration() + }, + }, + "registrar": { + "nextFreeParaId": primitives::LOWEST_PUBLIC_ID, + } + }) +} + +// staging_testnet +fn rococo_staging_testnet_config_genesis() -> serde_json::Value { + use hex_literal::hex; + use sp_core::crypto::UncheckedInto; + + // subkey inspect "$SECRET" + let endowed_accounts = Vec::from([ + // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs + hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(), + ]); + + // ./scripts/prepare-test-net.sh 8 + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )> = Vec::from([ + ( + //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei + hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(), + //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd + hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(), + //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H + hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"] + .unchecked_into(), + //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 + hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] + .unchecked_into(), + //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz + hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] + .unchecked_into(), + //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b + hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"] + .unchecked_into(), + //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq + hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"] + .unchecked_into(), + //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu + hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"] + .unchecked_into(), + ), + ( + //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG + hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(), + //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3 + hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(), + //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM + hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"] + .unchecked_into(), + //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao + hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] + .unchecked_into(), + //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF + hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] + .unchecked_into(), + //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ + hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"] + .unchecked_into(), + //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw + hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"] + .unchecked_into(), + //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5 + hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"] + .unchecked_into(), + ), + ( + //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S + hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(), + //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx + hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(), + //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY + hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"] + .unchecked_into(), + //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP + hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] + .unchecked_into(), + //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU + hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] + .unchecked_into(), + //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV + hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"] + .unchecked_into(), + //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa + hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"] + .unchecked_into(), + //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF + hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"] + .unchecked_into(), + ), + ( + //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR + hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(), + //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v + hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(), + //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1 + hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"] + .unchecked_into(), + //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte + hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] + .unchecked_into(), + //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA + hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] + .unchecked_into(), + //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP + hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"] + .unchecked_into(), + //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA + hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"] + .unchecked_into(), + //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz + hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"] + .unchecked_into(), + ), + ( + //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N + hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(), + //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa + hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(), + //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7 + hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"] + .unchecked_into(), + //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG + hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] + .unchecked_into(), + //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N + hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] + .unchecked_into(), + //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG + hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"] + .unchecked_into(), + //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ + hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"] + .unchecked_into(), + //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ + hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"] + .unchecked_into(), + ), + ( + //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF + hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(), + //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM + hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(), + //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD + hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"] + .unchecked_into(), + //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB + hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] + .unchecked_into(), + //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE + hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] + .unchecked_into(), + //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS + hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"] + .unchecked_into(), + //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd + hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"] + .unchecked_into(), + //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT + hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"] + .unchecked_into(), + ), + ( + //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM + hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(), + //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7 + hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(), + //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96 + hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"] + .unchecked_into(), + //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N + hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] + .unchecked_into(), + //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT + hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] + .unchecked_into(), + //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa + hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"] + .unchecked_into(), + //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7 + hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"] + .unchecked_into(), + //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx + hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"] + .unchecked_into(), + ), + ( + //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di + hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(), + //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV + hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(), + //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8 + hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"] + .unchecked_into(), + //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF + hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] + .unchecked_into(), + //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F + hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] + .unchecked_into(), + //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx + hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"] + .unchecked_into(), + //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T + hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"] + .unchecked_into(), + //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7 + hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"] + .unchecked_into(), + ), + ]); + + const ENDOWMENT: u128 = 1_000_000 * ROC; + const STASH: u128 = 100 * ROC; + + serde_json::json!({ + "balances": { + "balances": endowed_accounts + .iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) + .collect::>(), + }, + "session": { + "keys": initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + rococo_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect::>(), + }, + "babe": { + "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), + }, + "sudo": { "key": Some(endowed_accounts[0].clone()) }, + "configuration": { + "config": default_parachains_host_configuration(), + }, + "registrar": { + "nextFreeParaId": primitives::LOWEST_PUBLIC_ID, + }, + }) +} + +//development +fn rococo_development_config_genesis() -> serde_json::Value { + rococo_testnet_genesis( + Vec::from([get_authority_keys_from_seed("Alice")]), + get_account_id_from_seed::("Alice"), + None, + ) +} + +//local_testnet +fn rococo_local_testnet_genesis() -> serde_json::Value { + rococo_testnet_genesis( + Vec::from([get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")]), + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: sp_std::vec::Vec) -> Option> { + let patch = match id { + s if s == "local_testnet".as_bytes() => rococo_local_testnet_genesis(), + s if s == "development".as_bytes() => rococo_development_config_genesis(), + s if s == "staging_testnet".as_bytes() => rococo_staging_testnet_config_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 11c1cdaaed9f..f13144a5acb2 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -39,9 +39,6 @@ use runtime_common::{ paras_registrar, paras_sudo_wrapper, prod_or_fast, slots, BlockHashCount, BlockLength, SlowAdjustingFeeUpdate, }; -use scale_info::TypeInfo; -use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*}; - use runtime_parachains::{ assigner as parachains_assigner, assigner_on_demand as parachains_assigner_on_demand, assigner_parachains as parachains_assigner_parachains, @@ -57,6 +54,9 @@ use runtime_parachains::{ scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, }; +use scale_info::TypeInfo; +use sp_runtime::RuntimeString; +use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*}; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::{ @@ -128,6 +128,7 @@ use governance::{ #[cfg(test)] mod tests; +mod genesis_configs; mod validator_manager; impl_runtime_weights!(rococo_runtime_constants); @@ -2398,6 +2399,22 @@ sp_api::impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + if let Some(id) = id { + genesis_configs::get_preset(id) + } else { + Some(create_default_config::()) + } + } + + fn preset_names() -> Vec { + vec![ + RuntimeString::from("local_testnet"), + RuntimeString::from("development"), + RuntimeString::from("staging_testnet"), + ] + } } } From ffddbfab51f9474d328cbb5de2e1d200c600d0e7 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:01:38 +0100 Subject: [PATCH 26/83] Cargo.lock updated --- Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7bc757e6e63c..36e246baee91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14627,6 +14627,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-babe", "sp-consensus-beefy", + "sp-consensus-grandpa", "sp-core", "sp-genesis-builder", "sp-inherents", @@ -18868,6 +18869,7 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "futures", + "hex-literal", "json-patch", "log", "pallet-babe", From 7c6bccb04599caa88fdc5e07e59739f6930ddbff Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:51:43 +0100 Subject: [PATCH 27/83] naming: named_patch -> named_preset --- substrate/bin/utils/chain-spec-builder/src/lib.rs | 2 +- ...=> substrate_test_runtime_from_named_preset.json} | 0 substrate/client/chain-spec/src/chain_spec.rs | 12 ++++++------ .../client/chain-spec/src/genesis_config_builder.rs | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) rename substrate/client/chain-spec/res/{substrate_test_runtime_from_named_patch.json => substrate_test_runtime_from_named_preset.json} (100%) diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index a057dc4d75c1..6d6ccb9accf7 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -71,7 +71,7 @@ //! Patch the runtime's default genesis config with the named preset provided by the runtime and generate the plain //! version of chain spec: //! ```text -//! chain-spec-builder create -r runtime.wasm named-patch "staging" +//! chain-spec-builder create -r runtime.wasm named-preset "staging" //! ``` //! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] and [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime functions are called. diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_named_patch.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_named_preset.json similarity index 100% rename from substrate/client/chain-spec/res/substrate_test_runtime_from_named_patch.json rename to substrate/client/chain-spec/res/substrate_test_runtime_from_named_preset.json diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 3fc0c5c65087..0f749ab73591 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -45,7 +45,7 @@ use std::{ enum GenesisBuildAction { Patch(json::Value), Full(json::Value), - NamedPatch(String, PhantomData), + NamedPreset(String, PhantomData), } impl Clone for GenesisBuildAction { @@ -53,7 +53,7 @@ impl Clone for GenesisBuildAction { match self { Self::Patch(ref p) => Self::Patch(p.clone()), Self::Full(ref f) => Self::Full(f.clone()), - Self::NamedPatch(ref p, _) => Self::NamedPatch(p.clone(), Default::default()), + Self::NamedPreset(ref p, _) => Self::NamedPreset(p.clone(), Default::default()), } } } @@ -129,7 +129,7 @@ impl GenesisSource { json_blob: RuntimeGenesisConfigJson::Patch(patch.clone()), code: code.clone(), })), - Self::GenesisBuilderApi(GenesisBuildAction::NamedPatch(name, _), code) => { + Self::GenesisBuilderApi(GenesisBuildAction::NamedPreset(name, _), code) => { let patch = RuntimeCaller::::new(&code[..]).get_named_preset(Some(name))?; Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { json_blob: RuntimeGenesisConfigJson::Patch(patch), @@ -445,7 +445,7 @@ impl ChainSpecBuilder { /// Sets the name of runtime-provided JSON patch for runtime's GenesisConfig. pub fn with_genesis_config_patch_name(mut self, name: String) -> Self { - self.genesis_build_action = GenesisBuildAction::NamedPatch(name, Default::default()); + self.genesis_build_action = GenesisBuildAction::NamedPreset(name, Default::default()); self } @@ -1037,7 +1037,7 @@ mod tests { #[docify::export] #[test] - fn generate_chain_spec_with_named_patch_works() { + fn generate_chain_spec_with_named_preset_works() { sp_tracing::try_init_simple(); let output: ChainSpec<()> = ChainSpec::builder( substrate_test_runtime::wasm_binary_unwrap().into(), @@ -1059,7 +1059,7 @@ mod tests { file.write_all(actual.clone().as_bytes()).unwrap(); let expected = - from_str::(include_str!("../res/substrate_test_runtime_from_named_patch.json")) + from_str::(include_str!("../res/substrate_test_runtime_from_named_preset.json")) .unwrap(); //wasm blob may change overtime so let's zero it. Also ensure it is there: diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index c64a25448a14..bf297c4764b2 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -98,11 +98,11 @@ where .call(&mut t, "GenesisBuilder_get_preset", &id.encode()) .map_err(|e| format!("wasm call error {e}"))?; - let named_patch = Option::>::decode(&mut &call_result[..]) + let named_preset = Option::>::decode(&mut &call_result[..]) .map_err(|e| format!("scale codec error: {e}"))?; - if let Some(named_patch) = named_patch { - Ok(from_slice(&named_patch[..]).expect("returned value is json. qed.")) + if let Some(named_preset) = named_preset { + Ok(from_slice(&named_preset[..]).expect("returned value is json. qed.")) } else { Err(format!("The preset with name {id:?} is not available.")) } @@ -147,7 +147,7 @@ where self.get_storage_for_config(config) } - pub fn get_storage_for_named_patch( + pub fn get_storage_for_named_preset( &self, name: Option<&String>, ) -> core::result::Result { @@ -195,7 +195,7 @@ mod tests { } #[test] - fn get_named_patch_works() { + fn get_named_preset_works() { sp_tracing::try_init_simple(); let config = ::new(substrate_test_runtime::wasm_binary_unwrap()) From 2caffaae803e08a3d5b46c860e8016da023ff4ce Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:07:36 +0100 Subject: [PATCH 28/83] naming: patch_name -> preset_name --- polkadot/node/service/src/chain_spec.rs | 6 +++--- substrate/bin/utils/chain-spec-builder/src/lib.rs | 2 +- substrate/client/chain-spec/src/chain_spec.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 99a080648adf..3e5415bff938 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -401,7 +401,7 @@ pub fn rococo_staging_testnet_config() -> Result { .with_name("Rococo Staging Testnet") .with_id("rococo_staging_testnet") .with_chain_type(ChainType::Live) - .with_genesis_config_patch_name("staging_testnet") + .with_genesis_config_preset_name("staging_testnet") .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Rococo Staging telemetry url is valid; qed"), @@ -667,7 +667,7 @@ pub fn rococo_development_config() -> Result { .with_name("Development") .with_id("rococo_dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch_name("development") + .with_genesis_config_preset_name("development") .with_protocol_id(DEFAULT_PROTOCOL_ID) .build()) } @@ -737,7 +737,7 @@ pub fn rococo_local_testnet_config() -> Result { .with_name("Rococo Local Testnet") .with_id("rococo_local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch_name("local_testnet") + .with_genesis_config_preset_name("local_testnet") .with_protocol_id(DEFAULT_PROTOCOL_ID) .build()) } diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 6d6ccb9accf7..39d0fb7d45b5 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -262,7 +262,7 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result - builder.with_genesis_config_patch_name(preset_name.clone()), + builder.with_genesis_config_preset_name(preset_name.clone()), GenesisBuildAction::Patch(PatchCmd { ref patch_path }) => { let patch = fs::read(patch_path.as_path()) .map_err(|e| format!("patch file {patch_path:?} shall be readable: {e}"))?; diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 0f749ab73591..b02279f8b4d8 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -444,7 +444,7 @@ impl ChainSpecBuilder { } /// Sets the name of runtime-provided JSON patch for runtime's GenesisConfig. - pub fn with_genesis_config_patch_name(mut self, name: String) -> Self { + pub fn with_genesis_config_preset_name(mut self, name: String) -> Self { self.genesis_build_action = GenesisBuildAction::NamedPreset(name, Default::default()); self } @@ -1046,7 +1046,7 @@ mod tests { .with_name("TestName") .with_id("test_id") .with_chain_type(ChainType::Local) - .with_genesis_config_patch_name("staging".to_string()) + .with_genesis_config_preset_name("staging".to_string()) .build(); let actual = output.as_json(false).unwrap(); From 9ce209c5d855c2dd53bcbe400fc8e58c2a435189 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:14:58 +0100 Subject: [PATCH 29/83] fmt --- .../bin/utils/chain-spec-builder/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 39d0fb7d45b5..b7290eae6227 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -35,7 +35,7 @@ //! ```text //! chain-spec-builder create -r runtime.wasm default //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::create_default_config`][sp-genesis-builder-create] runtime function is called. //! //! @@ -45,7 +45,7 @@ //! ```text //! chain-spec-builder display-preset -r runtime.wasm //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. //! //! ##### Display the `GenesisConfig` preset with given name @@ -54,7 +54,7 @@ //! ```text //! chain-spec-builder display-preset -r runtime.wasm -p "staging" //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. //! //! ##### List the names of `GenesisConfig` presets provided by runtime. @@ -63,7 +63,7 @@ //! ```text //! chain-spec-builder list-presets -r runtime.wasm //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::preset_names`][sp-genesis-builder-list] runtime function is called. //! //! ##### Generate chain spec using runtime provided genesis config preset. @@ -73,7 +73,7 @@ //! ```text //! chain-spec-builder create -r runtime.wasm named-preset "staging" //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] and [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime functions are called. //! //! ##### Generate raw storage chain spec using genesis config patch. @@ -83,7 +83,7 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm patch patch.json //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate raw storage chain spec using full genesis config. @@ -92,19 +92,19 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! _Note_: [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate human readable chain spec using provided genesis config patch. //! ```text //! chain-spec-builder create -r runtime.wasm patch patch.json //! ``` -//! +//! //! ##### Generate human readable chain spec using provided full genesis config. //! ```text //! chain-spec-builder create -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! ##### Extra tools. //! The `chain-spec-builder` provides also some extra utilities: [`VerifyCmd`], [`ConvertToRawCmd`], [`UpdateCodeCmd`]. //! From 0c98000bc3602df92182cc5b14e9e395114080fa Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:34:43 +0100 Subject: [PATCH 30/83] preset_names/get_preset implemented for runtimes --- cumulus/parachain-template/runtime/src/lib.rs | 10 +++++++++- .../runtimes/assets/asset-hub-rococo/src/lib.rs | 10 +++++++++- .../runtimes/assets/asset-hub-westend/src/lib.rs | 10 +++++++++- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 10 +++++++++- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 10 +++++++++- .../collectives/collectives-westend/src/lib.rs | 10 +++++++++- .../runtimes/contracts/contracts-rococo/src/lib.rs | 10 +++++++++- .../runtimes/glutton/glutton-westend/src/lib.rs | 10 +++++++++- .../parachains/runtimes/starters/seedling/src/lib.rs | 10 +++++++++- cumulus/parachains/runtimes/starters/shell/src/lib.rs | 10 +++++++++- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 10 +++++++++- .../runtimes/testing/rococo-parachain/src/lib.rs | 10 +++++++++- .../src/fake_runtime_api/asset_hub_polkadot_aura.rs | 8 ++++++++ .../polkadot-parachain/src/fake_runtime_api/aura.rs | 8 ++++++++ cumulus/test/runtime/src/lib.rs | 10 +++++++++- polkadot/runtime/test-runtime/src/lib.rs | 10 +++++++++- polkadot/runtime/westend/src/lib.rs | 10 +++++++++- substrate/bin/minimal/runtime/src/lib.rs | 10 +++++++++- substrate/bin/node-template/runtime/src/lib.rs | 10 +++++++++- 19 files changed, 169 insertions(+), 17 deletions(-) diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index c85aeb72def7..643957c7bea5 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -30,7 +30,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ @@ -761,6 +761,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 4ba5cd12b75a..cc1e80a017e9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -54,7 +54,7 @@ use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, ord_parameter_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, @@ -1607,6 +1607,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 75b4bb9c4a4f..f49435c2e6e0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -40,7 +40,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, ord_parameter_types, parameter_types, traits::{ tokens::nonfungibles_v2::Inspect, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, @@ -1684,6 +1684,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index a7411fe4af3d..52983a7d7470 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -53,7 +53,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -1199,6 +1199,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index e4da083b3fa7..61edc5dd9b4c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -52,7 +52,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -1090,6 +1090,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index a5ae0505478a..214bd130fab8 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -66,7 +66,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ fungible::HoldConsideration, ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, @@ -1038,6 +1038,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index f56eae4bac47..9c03ff6ceb87 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -48,7 +48,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8}, weights::{ConstantMultiplier, Weight}, @@ -767,6 +767,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index c23b866e8088..16608516fef6 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -66,7 +66,7 @@ use cumulus_primitives_core::AggregateMessageOrigin; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, IsInVec, Randomness, @@ -512,6 +512,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 972efbe4e56c..4749bb327483 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -46,7 +46,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness}, weights::{ @@ -383,6 +383,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 4a1cd74457ae..f9af27838059 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -54,7 +54,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness}, weights::{ @@ -440,6 +440,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 5442d35041bd..4602e9b157a2 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -37,7 +37,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, pallet_prelude::Weight, parameter_types, traits::{ @@ -869,6 +869,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 258e0a57f762..5641535cec20 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -41,7 +41,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, match_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, @@ -829,6 +829,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index e1cd205a951e..d179fcd499de 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -196,5 +196,13 @@ sp_api::impl_runtime_apis! { fn build_state(_: Vec) -> sp_genesis_builder::Result { unimplemented!() } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index e6b495a6a184..c7ef1641b137 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -196,5 +196,13 @@ sp_api::impl_runtime_apis! { fn build_state(_: Vec) -> sp_genesis_builder::Result { unimplemented!() } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index f63097ebf856..5c4c61569d45 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -47,7 +47,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstU8, Randomness}, weights::{ @@ -470,6 +470,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index 2d3ee27e7674..209b3d6133fc 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -43,7 +43,7 @@ use frame_election_provider_support::{ }; use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{KeyOwnerProofSystem, WithdrawReasons}, }; @@ -1142,5 +1142,13 @@ sp_api::impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9b666ee8c525..ee4a489a3b29 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -28,7 +28,7 @@ use beefy_primitives::{ use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, SequentialPhragmen}; use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, EverythingBut, @@ -2455,6 +2455,14 @@ sp_api::impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/substrate/bin/minimal/runtime/src/lib.rs b/substrate/bin/minimal/runtime/src/lib.rs index 77a81a08e529..b34940955165 100644 --- a/substrate/bin/minimal/runtime/src/lib.rs +++ b/substrate/bin/minimal/runtime/src/lib.rs @@ -31,7 +31,7 @@ use frame::{ prelude::*, }, }; -use frame_support::genesis_builder_helper::{build_state, create_default_config}; +use frame_support::genesis_builder_helper::{build_state, create_default_config, get_preset}; #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { @@ -220,6 +220,14 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index d0555b90f279..460eda184442 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -21,7 +21,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use frame_support::genesis_builder_helper::{build_state, create_default_config}; +use frame_support::genesis_builder_helper::{build_state, create_default_config, get_preset}; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, derive_impl, parameter_types, @@ -565,5 +565,13 @@ impl_runtime_apis! { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] + } } } From 0353773605c1b205a31b33823d2f3c97403af0fd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:35:21 +0100 Subject: [PATCH 31/83] polkadot-service: rococo-based chain-spec fixes --- polkadot/node/service/src/chain_spec.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 3e5415bff938..89b3fd54ea60 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -431,7 +431,7 @@ pub fn versi_staging_testnet_config() -> Result { .with_name("Versi Staging Testnet") .with_id("versi_staging_testnet") .with_chain_type(ChainType::Live) - .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) + .with_genesis_config_preset_name("staging_testnet") .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Versi Staging telemetry url is valid; qed"), @@ -682,7 +682,7 @@ pub fn versi_development_config() -> Result { .with_name("Development") .with_id("versi_dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(rococo_development_config_genesis()) + .with_genesis_config_preset_name("development") .with_protocol_id("versi") .build()) } @@ -698,7 +698,7 @@ pub fn wococo_development_config() -> Result { .with_name("Development") .with_id("wococo_dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(rococo_development_config_genesis()) + .with_genesis_config_preset_name("development") .with_protocol_id(WOCOCO_DEV_PROTOCOL_ID) .build()) } From 6e4dcb2b6fb99b7b93e7d08cc557d6b50458a612 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:35:46 +0100 Subject: [PATCH 32/83] String -> &str --- .../bin/utils/chain-spec-builder/src/lib.rs | 20 +++++++++---------- substrate/client/chain-spec/src/chain_spec.rs | 7 ++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index b7290eae6227..112c3556bacb 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -35,7 +35,7 @@ //! ```text //! chain-spec-builder create -r runtime.wasm default //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::create_default_config`][sp-genesis-builder-create] runtime function is called. //! //! @@ -45,7 +45,7 @@ //! ```text //! chain-spec-builder display-preset -r runtime.wasm //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. //! //! ##### Display the `GenesisConfig` preset with given name @@ -54,7 +54,7 @@ //! ```text //! chain-spec-builder display-preset -r runtime.wasm -p "staging" //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. //! //! ##### List the names of `GenesisConfig` presets provided by runtime. @@ -63,7 +63,7 @@ //! ```text //! chain-spec-builder list-presets -r runtime.wasm //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::preset_names`][sp-genesis-builder-list] runtime function is called. //! //! ##### Generate chain spec using runtime provided genesis config preset. @@ -73,7 +73,7 @@ //! ```text //! chain-spec-builder create -r runtime.wasm named-preset "staging" //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] and [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime functions are called. //! //! ##### Generate raw storage chain spec using genesis config patch. @@ -83,7 +83,7 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm patch patch.json //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate raw storage chain spec using full genesis config. @@ -92,19 +92,19 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! _Note_: [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate human readable chain spec using provided genesis config patch. //! ```text //! chain-spec-builder create -r runtime.wasm patch patch.json //! ``` -//! +//! //! ##### Generate human readable chain spec using provided full genesis config. //! ```text //! chain-spec-builder create -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! ##### Extra tools. //! The `chain-spec-builder` provides also some extra utilities: [`VerifyCmd`], [`ConvertToRawCmd`], [`UpdateCodeCmd`]. //! @@ -262,7 +262,7 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result - builder.with_genesis_config_preset_name(preset_name.clone()), + builder.with_genesis_config_preset_name(&preset_name), GenesisBuildAction::Patch(PatchCmd { ref patch_path }) => { let patch = fs::read(patch_path.as_path()) .map_err(|e| format!("patch file {patch_path:?} shall be readable: {e}"))?; diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index b02279f8b4d8..87f7607db155 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -444,8 +444,9 @@ impl ChainSpecBuilder { } /// Sets the name of runtime-provided JSON patch for runtime's GenesisConfig. - pub fn with_genesis_config_preset_name(mut self, name: String) -> Self { - self.genesis_build_action = GenesisBuildAction::NamedPreset(name, Default::default()); + pub fn with_genesis_config_preset_name(mut self, name: &str) -> Self { + self.genesis_build_action = + GenesisBuildAction::NamedPreset(name.to_string(), Default::default()); self } @@ -1046,7 +1047,7 @@ mod tests { .with_name("TestName") .with_id("test_id") .with_chain_type(ChainType::Local) - .with_genesis_config_preset_name("staging".to_string()) + .with_genesis_config_preset_name("staging") .build(); let actual = output.as_json(false).unwrap(); From 02e6b24c0c929281ea8e462d283fe3b19d97a80b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:45:02 +0100 Subject: [PATCH 33/83] fmt --- polkadot/runtime/rococo/Cargo.toml | 4 +++- .../bin/utils/chain-spec-builder/src/lib.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index d3d40af32069..a40801b67dee 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -23,7 +23,7 @@ smallvec = "1.8.0" authority-discovery-primitives = { package = "sp-authority-discovery", path = "../../../substrate/primitives/authority-discovery", default-features = false } babe-primitives = { package = "sp-consensus-babe", path = "../../../substrate/primitives/consensus/babe", default-features = false } beefy-primitives = { package = "sp-consensus-beefy", path = "../../../substrate/primitives/consensus/beefy", default-features = false } -grandpa_primitives = { package = "sp-consensus-grandpa", path = "../../../substrate/primitives/consensus/grandpa" , default-features = false } +grandpa_primitives = { package = "sp-consensus-grandpa", path = "../../../substrate/primitives/consensus/grandpa", default-features = false } binary-merkle-tree = { path = "../../../substrate/utils/binary-merkle-tree", default-features = false } rococo-runtime-constants = { package = "rococo-runtime-constants", path = "constants", default-features = false } sp-api = { path = "../../../substrate/primitives/api", default-features = false } @@ -135,6 +135,7 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime/std", + "grandpa_primitives/std", "inherents/std", "log/std", "offchain-primitives/std", @@ -192,6 +193,7 @@ std = [ "scale-info/std", "serde/std", "serde_derive", + "serde_json/std", "sp-api/std", "sp-arithmetic/std", "sp-core/std", diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 112c3556bacb..e4bb8f71de9b 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -35,7 +35,7 @@ //! ```text //! chain-spec-builder create -r runtime.wasm default //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::create_default_config`][sp-genesis-builder-create] runtime function is called. //! //! @@ -45,7 +45,7 @@ //! ```text //! chain-spec-builder display-preset -r runtime.wasm //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. //! //! ##### Display the `GenesisConfig` preset with given name @@ -54,7 +54,7 @@ //! ```text //! chain-spec-builder display-preset -r runtime.wasm -p "staging" //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is called. //! //! ##### List the names of `GenesisConfig` presets provided by runtime. @@ -63,7 +63,7 @@ //! ```text //! chain-spec-builder list-presets -r runtime.wasm //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::preset_names`][sp-genesis-builder-list] runtime function is called. //! //! ##### Generate chain spec using runtime provided genesis config preset. @@ -73,7 +73,7 @@ //! ```text //! chain-spec-builder create -r runtime.wasm named-preset "staging" //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] and [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime functions are called. //! //! ##### Generate raw storage chain spec using genesis config patch. @@ -83,7 +83,7 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm patch patch.json //! ``` -//! +//! //! _Note:_ [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate raw storage chain spec using full genesis config. @@ -92,19 +92,19 @@ //! ```text //! chain-spec-builder create -s -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! _Note_: [`GenesisBuilder::build_state`][sp-genesis-builder-build] runtime function is called. //! //! ##### Generate human readable chain spec using provided genesis config patch. //! ```text //! chain-spec-builder create -r runtime.wasm patch patch.json //! ``` -//! +//! //! ##### Generate human readable chain spec using provided full genesis config. //! ```text //! chain-spec-builder create -r runtime.wasm full full-genesis-config.json //! ``` -//! +//! //! ##### Extra tools. //! The `chain-spec-builder` provides also some extra utilities: [`VerifyCmd`], [`ConvertToRawCmd`], [`UpdateCodeCmd`]. //! From 618fd1b5a812f14d9b30e6379bc88533ff637038 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 18:04:45 +0100 Subject: [PATCH 34/83] fixes --- .../src/fake_runtime_api/asset_hub_polkadot_aura.rs | 6 +++--- cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs | 6 +++--- substrate/bin/minimal/runtime/Cargo.toml | 4 +++- substrate/test-utils/runtime/src/lib.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index d179fcd499de..7f2bbd92f65f 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -197,12 +197,12 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn get_preset(id: Option>) -> Option> { - get_preset::(id) + fn get_preset(_id: Option>) -> Option> { + unimplemented!() } fn preset_names() -> Vec { - vec![] + unimplemented!() } } } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index c7ef1641b137..635afc29acdc 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -197,12 +197,12 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn get_preset(id: Option>) -> Option> { - get_preset::(id) + fn get_preset(_id: Option>) -> Option> { + unimplemented!() } fn preset_names() -> Vec { - vec![] + unimplemented!() } } } diff --git a/substrate/bin/minimal/runtime/Cargo.toml b/substrate/bin/minimal/runtime/Cargo.toml index 296106544bbf..37708c580e86 100644 --- a/substrate/bin/minimal/runtime/Cargo.toml +++ b/substrate/bin/minimal/runtime/Cargo.toml @@ -26,8 +26,9 @@ pallet-timestamp = { path = "../../../frame/timestamp", default-features = false pallet-transaction-payment = { path = "../../../frame/transaction-payment", default-features = false } pallet-transaction-payment-rpc-runtime-api = { path = "../../../frame/transaction-payment/rpc/runtime-api", default-features = false } -# genesis builder that allows us to interacto with runtime genesis config +# genesis builder that allows us to interact with runtime genesis config sp-genesis-builder = { path = "../../../primitives/genesis-builder", default-features = false } +sp-runtime = { path = "../../../primitives/runtime", default-features = false, features = ["serde"] } [build-dependencies] @@ -46,5 +47,6 @@ std = [ "parity-scale-codec/std", "scale-info/std", "sp-genesis-builder/std", + "sp-runtime/std", "substrate-wasm-builder", ] diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 27a43843a5ba..e6f4902bbec4 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -744,7 +744,7 @@ impl_runtime_apis! { json!({ "balances": { - "balances": endowed_accounts.iter().map(|k| (k.clone(), 10 * currency::DOLLARS)).collect::>(), + "balances": endowed_accounts.into_iter().map(|k| (k, 10 * currency::DOLLARS)).collect::>(), }, "substrateTest": { "authorities": [ From 9ba33b64f050a45ed11a6a55b38db7acc619962d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 20:29:54 +0100 Subject: [PATCH 35/83] Cargo.lock updated --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 36e246baee91..908e7bd31b2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8074,6 +8074,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-genesis-builder", + "sp-runtime", "substrate-wasm-builder", ] From ceeca1299b98596aa97000ba0dfa1e72738fb7a5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 16 Dec 2023 13:20:47 +0100 Subject: [PATCH 36/83] wococo, versi presets added --- polkadot/node/service/src/chain_spec.rs | 110 +----------------- ...s_configs.rs => genesis_config_presets.rs} | 40 ++++++- polkadot/runtime/rococo/src/lib.rs | 6 +- 3 files changed, 41 insertions(+), 115 deletions(-) rename polkadot/runtime/rococo/src/{genesis_configs.rs => genesis_config_presets.rs} (93%) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 89b3fd54ea60..098d223d8d93 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -176,25 +176,6 @@ fn westend_session_keys( } } -#[cfg(feature = "rococo-native")] -fn rococo_session_keys( - babe: BabeId, - grandpa: GrandpaId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, -) -> rococo_runtime::SessionKeys { - rococo_runtime::SessionKeys { - babe, - grandpa, - para_validator, - para_assignment, - authority_discovery, - beefy, - } -} - #[cfg(feature = "westend-native")] fn westend_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; @@ -574,65 +555,6 @@ pub fn westend_testnet_genesis( }) } -/// Helper function to create rococo runtime `GenesisConfig` patch for testing -#[cfg(feature = "rococo-native")] -pub fn rococo_testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )>, - root_key: AccountId, - endowed_accounts: Option>, -) -> serde_json::Value { - let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); - - const ENDOWMENT: u128 = 1_000_000 * ROC; - - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), - }, - "session": { - "keys": initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - rococo_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - ), - ) - }) - .collect::>(), - }, - "babe": { - "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - }, - "sudo": { "key": Some(root_key.clone()) }, - "configuration": { - "config": polkadot_runtime_parachains::configuration::HostConfiguration { - max_validators_per_core: Some(1), - ..default_parachains_host_configuration() - }, - }, - "registrar": { - "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, - } - }) -} - #[cfg(feature = "westend-native")] fn westend_development_config_genesis() -> serde_json::Value { westend_testnet_genesis( @@ -742,21 +664,6 @@ pub fn rococo_local_testnet_config() -> Result { .build()) } -/// Wococo is a temporary testnet that uses almost the same runtime as rococo. -#[cfg(feature = "rococo-native")] -fn wococo_local_testnet_genesis() -> serde_json::Value { - rococo_testnet_genesis( - vec![ - get_authority_keys_from_seed("Alice"), - get_authority_keys_from_seed("Bob"), - get_authority_keys_from_seed("Charlie"), - get_authority_keys_from_seed("Dave"), - ], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// Wococo local testnet config (multivalidator Alice + Bob + Charlie + Dave) #[cfg(feature = "rococo-native")] pub fn wococo_local_testnet_config() -> Result { @@ -767,26 +674,11 @@ pub fn wococo_local_testnet_config() -> Result { .with_name("Wococo Local Testnet") .with_id("wococo_local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(wococo_local_testnet_genesis()) + .with_genesis_config_preset_name("wococo_local_testnet") .with_protocol_id(DEFAULT_PROTOCOL_ID) .build()) } -/// `Versi` is a temporary testnet that uses the same runtime as rococo. -#[cfg(feature = "rococo-native")] -fn versi_local_testnet_genesis() -> serde_json::Value { - rococo_testnet_genesis( - vec![ - get_authority_keys_from_seed("Alice"), - get_authority_keys_from_seed("Bob"), - get_authority_keys_from_seed("Charlie"), - get_authority_keys_from_seed("Dave"), - ], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// `Versi` local testnet config (multivalidator Alice + Bob + Charlie + Dave) #[cfg(feature = "rococo-native")] pub fn versi_local_testnet_config() -> Result { diff --git a/polkadot/runtime/rococo/src/genesis_configs.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs similarity index 93% rename from polkadot/runtime/rococo/src/genesis_configs.rs rename to polkadot/runtime/rococo/src/genesis_config_presets.rs index 376d860d80f6..21553819bfaf 100644 --- a/polkadot/runtime/rococo/src/genesis_configs.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -30,14 +30,14 @@ use sp_std::alloc::format; use sp_std::vec::Vec; /// Helper function to generate a crypto pair from seed -pub fn get_from_seed(seed: &str) -> ::Public { +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 +fn get_account_id_from_seed(seed: &str) -> AccountId where AccountPublic: From<::Public>, { @@ -45,7 +45,7 @@ where } /// Helper function to generate stash, controller and session key from seed -pub fn get_authority_keys_from_seed( +fn get_authority_keys_from_seed( seed: &str, ) -> ( AccountId, @@ -62,7 +62,7 @@ pub fn get_authority_keys_from_seed( } /// Helper function to generate stash, controller and session key from seed -pub fn get_authority_keys_from_seed_no_beefy( +fn get_authority_keys_from_seed_no_beefy( seed: &str, ) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { ( @@ -480,12 +480,44 @@ fn rococo_local_testnet_genesis() -> serde_json::Value { ) } +/// `Versi` is a temporary testnet that uses the same runtime as rococo. +// versi_local_testnet +fn versi_local_testnet_genesis() -> serde_json::Value { + rococo_testnet_genesis( + Vec::from([ + get_authority_keys_from_seed("Alice"), + get_authority_keys_from_seed("Bob"), + get_authority_keys_from_seed("Charlie"), + get_authority_keys_from_seed("Dave"), + ]), + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Wococo is a temporary testnet that uses almost the same runtime as rococo. +//wococo_local_testnet +fn wococo_local_testnet_genesis() -> serde_json::Value { + rococo_testnet_genesis( + Vec::from([ + get_authority_keys_from_seed("Alice"), + get_authority_keys_from_seed("Bob"), + get_authority_keys_from_seed("Charlie"), + get_authority_keys_from_seed("Dave"), + ]), + get_account_id_from_seed::("Alice"), + None, + ) +} + /// Provides the JSON representation of predefined genesis config for given `id`. pub fn get_preset(id: sp_std::vec::Vec) -> Option> { let patch = match id { s if s == "local_testnet".as_bytes() => rococo_local_testnet_genesis(), s if s == "development".as_bytes() => rococo_development_config_genesis(), s if s == "staging_testnet".as_bytes() => rococo_staging_testnet_config_genesis(), + s if s == "wococo_local_testnet".as_bytes() => wococo_local_testnet_genesis(), + s if s == "versi_local_testnet".as_bytes() => versi_local_testnet_genesis(), _ => return None, }; Some( diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index f13144a5acb2..a2cf977dfde2 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -128,7 +128,7 @@ use governance::{ #[cfg(test)] mod tests; -mod genesis_configs; +mod genesis_config_presets; mod validator_manager; impl_runtime_weights!(rococo_runtime_constants); @@ -2402,7 +2402,7 @@ sp_api::impl_runtime_apis! { fn get_preset(id: Option>) -> Option> { if let Some(id) = id { - genesis_configs::get_preset(id) + genesis_config_presets::get_preset(id) } else { Some(create_default_config::()) } @@ -2413,6 +2413,8 @@ sp_api::impl_runtime_apis! { RuntimeString::from("local_testnet"), RuntimeString::from("development"), RuntimeString::from("staging_testnet"), + RuntimeString::from("wococo_local_testnet"), + RuntimeString::from("versi_local_testnet"), ] } } From 7bf267b4f9408a9d323ec55fe6fde975af1383c7 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:34:01 +0100 Subject: [PATCH 37/83] merging to master leftovers --- .../rococo/src/genesis_config_presets.rs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/polkadot/runtime/rococo/src/genesis_config_presets.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs index 21553819bfaf..50952d3884b0 100644 --- a/polkadot/runtime/rococo/src/genesis_config_presets.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -21,7 +21,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use babe_primitives::AuthorityId as BabeId; use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa_primitives::AuthorityId as GrandpaId; -use primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +use primitives::{vstaging::SchedulerParams, AccountId, AccountPublic, AssignmentId, ValidatorId}; use rococo_runtime_constants::currency::UNITS as ROC; use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::IdentifyAccount; @@ -106,7 +106,9 @@ fn rococo_session_keys( fn default_parachains_host_configuration( ) -> runtime_parachains::configuration::HostConfiguration { - use primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + use primitives::{ + vstaging::node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE, + }; runtime_parachains::configuration::HostConfiguration { validation_upgrade_cooldown: 2u32, @@ -115,8 +117,6 @@ fn default_parachains_host_configuration( 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, @@ -137,6 +137,19 @@ fn default_parachains_host_configuration( relay_vrf_modulo_samples: 2, zeroth_delay_tranche_width: 0, minimum_validation_upgrade_delay: 5, + async_backing_params: AsyncBackingParams { + max_candidate_depth: 3, + allowed_ancestry_len: 2, + }, + node_features: bitvec::vec::BitVec::from_element( + 1u8 << (FeatureIndex::ElasticScalingMVP as usize), + ), + scheduler_params: SchedulerParams { + lookahead: 2, + group_rotation_frequency: 20, + paras_availability_period: 4, + ..Default::default() + }, ..Default::default() } } @@ -193,7 +206,10 @@ fn rococo_testnet_genesis( "sudo": { "key": Some(root_key.clone()) }, "configuration": { "config": runtime_parachains::configuration::HostConfiguration { - max_validators_per_core: Some(1), + scheduler_params: SchedulerParams { + max_validators_per_core: Some(1), + ..default_parachains_host_configuration().scheduler_params + }, ..default_parachains_host_configuration() }, }, From 8d65c040bc426ef30c486ced26e1808c22453e18 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:34:34 +0100 Subject: [PATCH 38/83] Cargo.lock --- Cargo.lock | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 37c5a5177c04..c7e28dac2bd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15125,6 +15125,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-babe", "sp-consensus-beefy", + "sp-consensus-grandpa", "sp-core", "sp-genesis-builder", "sp-inherents", @@ -15677,6 +15678,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "sp-state-machine", + "sp-tracing 16.0.0", "substrate-test-runtime", ] @@ -19980,6 +19982,7 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "futures", + "hex-literal", "log", "pallet-babe", "pallet-balances", From 0d45b9417cfb2374c5c9bbf8706aebb1909edad5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:02:33 +0100 Subject: [PATCH 39/83] fixes --- Cargo.lock | 2 ++ polkadot/runtime/rococo/Cargo.toml | 1 + templates/minimal/runtime/Cargo.toml | 2 ++ 3 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c7e28dac2bd4..58bc1b16ee3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8164,6 +8164,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-genesis-builder", + "sp-runtime", "substrate-wasm-builder", ] @@ -15052,6 +15053,7 @@ name = "rococo-runtime" version = "7.0.0" dependencies = [ "binary-merkle-tree", + "bitvec", "frame-benchmarking", "frame-executive", "frame-remote-externalities", diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 38b1d140fad4..9b425f804f5b 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -19,6 +19,7 @@ serde_derive = { optional = true, workspace = true } serde_json = { features = ["alloc"], workspace = true } static_assertions = "1.1.0" smallvec = "1.8.0" +bitvec = { version = "1.0.1", optional = true } authority-discovery-primitives = { package = "sp-authority-discovery", path = "../../../substrate/primitives/authority-discovery", default-features = false } babe-primitives = { package = "sp-consensus-babe", path = "../../../substrate/primitives/consensus/babe", default-features = false } diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 20ffb706eb49..f75d0271999a 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -31,6 +31,7 @@ pallet-transaction-payment-rpc-runtime-api = { path = "../../../substrate/frame/ # genesis builder that allows us to interacto with runtime genesis config sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } +sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false, features = ["serde"] } # local pallet templates pallet-minimal-template = { path = "../pallets/template", default-features = false } @@ -55,5 +56,6 @@ std = [ "pallet-minimal-template/std", "sp-genesis-builder/std", + "sp-runtime/std", "substrate-wasm-builder", ] From a4d61fc4d3d02f03730a13027488319f874f87d0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:06:17 +0100 Subject: [PATCH 40/83] fix --- templates/minimal/runtime/Cargo.toml | 2 +- templates/minimal/runtime/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index f75d0271999a..c4e342e1cad5 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -29,7 +29,7 @@ pallet-timestamp = { path = "../../../substrate/frame/timestamp", default-featur pallet-transaction-payment = { path = "../../../substrate/frame/transaction-payment", default-features = false } pallet-transaction-payment-rpc-runtime-api = { path = "../../../substrate/frame/transaction-payment/rpc/runtime-api", default-features = false } -# genesis builder that allows us to interacto with runtime genesis config +# genesis builder that allows us to interact with runtime genesis config sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false, features = ["serde"] } diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 48cad7df4c1c..3bb573d74fc0 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -23,7 +23,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use frame::{ deps::frame_support::{ - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, weights::{FixedFee, NoFee}, }, prelude::*, @@ -35,7 +35,6 @@ use frame::{ prelude::*, }, }; -use frame_support::genesis_builder_helper::{build_state, create_default_config, get_preset}; #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { From 8ef837f4febca85924728ca4bd889d73b2e1f804 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:02:09 +0100 Subject: [PATCH 41/83] coretime/people westend/rococo fixes --- .../runtimes/coretime/coretime-rococo/src/lib.rs | 14 +++++++++++--- .../runtimes/coretime/coretime-westend/src/lib.rs | 14 +++++++++++--- .../runtimes/people/people-rococo/src/lib.rs | 14 +++++++++++--- .../runtimes/people/people-westend/src/lib.rs | 14 +++++++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 9913e47a93ab..098a1e23d434 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -38,7 +38,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -887,8 +887,16 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] } } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 1a330821d3fc..52218fff81f6 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -38,7 +38,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -878,8 +878,16 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] } } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index c5e420785de5..724aad6e6c63 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -27,7 +27,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, @@ -860,8 +860,16 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] } } } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index dea079a4a98a..d0c998d9db6a 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -27,7 +27,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_config, create_default_config}, + genesis_builder_helper::{build_state, create_default_config, get_preset}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, @@ -859,8 +859,16 @@ impl_runtime_apis! { create_default_config::() } - fn build_config(config: Vec) -> sp_genesis_builder::Result { - build_config::(config) + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: Option>) -> Option> { + get_preset::(id) + } + + fn preset_names() -> Vec { + vec![] } } } From 67e8af88ef4ef56ba35e239f3d67fd92b3a496b7 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:28:12 +0100 Subject: [PATCH 42/83] rococo: bitvec fix --- polkadot/runtime/rococo/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 9b425f804f5b..05ef3b8ab84e 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -19,7 +19,7 @@ serde_derive = { optional = true, workspace = true } serde_json = { features = ["alloc"], workspace = true } static_assertions = "1.1.0" smallvec = "1.8.0" -bitvec = { version = "1.0.1", optional = true } +bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] } authority-discovery-primitives = { package = "sp-authority-discovery", path = "../../../substrate/primitives/authority-discovery", default-features = false } babe-primitives = { package = "sp-consensus-babe", path = "../../../substrate/primitives/consensus/babe", default-features = false } @@ -129,6 +129,7 @@ std = [ "babe-primitives/std", "beefy-primitives/std", "binary-merkle-tree/std", + "bitvec/std", "block-builder-api/std", "frame-benchmarking?/std", "frame-executive/std", From 0b51cfd0ff283ff77644665ca2183cc731143175 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:53:01 +0100 Subject: [PATCH 43/83] substrate-test-runtime: fixes --- substrate/test-utils/runtime/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index bfe00984f385..de6a767f9f27 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -42,6 +42,8 @@ use frame_system::{ CheckNonce, CheckWeight, }; use scale_info::TypeInfo; +use sp_application_crypto::Ss58Codec; +use sp_keyring::AccountKeyring; use sp_runtime::RuntimeString; use sp_std::prelude::*; #[cfg(not(feature = "std"))] @@ -870,7 +872,6 @@ fn test_witness(proof: StorageProof, root: crate::Hash) { pub mod storage_key_generator { use super::*; use sp_core::Pair; - use sp_keyring::AccountKeyring; /// Generate hex string without prefix pub(super) fn hex(x: T) -> String @@ -1060,7 +1061,6 @@ mod tests { use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_consensus::BlockOrigin; use sp_core::{storage::well_known_keys::HEAP_PAGES, traits::CallContext}; - use sp_keyring::AccountKeyring; use sp_runtime::{ traits::{DispatchTransaction, Hash as _}, transaction_validity::{InvalidTransaction, ValidTransaction}, @@ -1211,7 +1211,7 @@ mod tests { fn check_substrate_check_signed_extension_works() { sp_tracing::try_init_simple(); new_test_ext().execute_with(|| { - let x: AccountId = sp_keyring::AccountKeyring::Alice.into(); + let x: AccountId = AccountKeyring::Alice.into(); let info = DispatchInfo::default(); let len = 0_usize; assert_eq!( @@ -1508,8 +1508,8 @@ mod tests { let authority_key_vec = Vec::::decode(&mut &value[..]).unwrap(); assert_eq!(authority_key_vec.len(), 2); - assert_eq!(authority_key_vec[0], sp_keyring::AccountKeyring::Ferdie.public()); - assert_eq!(authority_key_vec[1], sp_keyring::AccountKeyring::Alice.public()); + assert_eq!(authority_key_vec[0], AccountKeyring::Ferdie.public()); + assert_eq!(authority_key_vec[1], AccountKeyring::Alice.public()); //Babe|Authorities let value: Vec = get_from_storage( From 410c0421c1e828f4dfe3f95e8e88870d7d7aaf57 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:01:53 +0100 Subject: [PATCH 44/83] fix --- polkadot/node/service/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index e659993836ad..5743c0957e7c 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -708,7 +708,7 @@ pub fn versi_local_testnet_config() -> Result { .with_name("Versi Local Testnet") .with_id("versi_local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(versi_local_testnet_genesis()) + .with_genesis_config_preset_name("versi_local_testnet") .with_protocol_id("versi") .build()) } From e1726d20a82b8aaeb6b6518bdb6104f19d625133 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:37:00 +0100 Subject: [PATCH 45/83] one more --- substrate/client/chain-spec/src/genesis_config_builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 368cc7a7ed10..9223185e4be7 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -173,7 +173,7 @@ where mod tests { use super::*; use serde_json::{from_str, json}; - pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot}; + pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration}; pub use sp_runtime::RuntimeString; #[test] From d77e59e71dd0cc75e3888591c6c89161c033a650 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:51:19 +0100 Subject: [PATCH 46/83] ... --- polkadot/node/service/src/chain_spec.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 5743c0957e7c..105b53e05d1b 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -28,8 +28,6 @@ use sp_consensus_babe::AuthorityId as BabeId; use polkadot_primitives::vstaging::SchedulerParams; #[cfg(feature = "rococo-native")] use rococo_runtime as rococo; -#[cfg(feature = "rococo-native")] -use rococo_runtime_constants::currency::UNITS as ROC; use sc_chain_spec::ChainSpecExtension; #[cfg(any(feature = "westend-native", feature = "rococo-native"))] use sc_chain_spec::ChainType; From 22ea184536e92fb5ffeda90ef60c37d12d52d7b3 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:47:58 +0100 Subject: [PATCH 47/83] polkadot-parachain: compilation fix --- polkadot/node/service/src/chain_spec.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 105b53e05d1b..706136f3ae6e 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -24,7 +24,7 @@ use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; -#[cfg(any(feature = "rococo-native", feature = "westend-native",))] +#[cfg(feature = "westend-native")] use polkadot_primitives::vstaging::SchedulerParams; #[cfg(feature = "rococo-native")] use rococo_runtime as rococo; @@ -116,7 +116,7 @@ pub fn wococo_config() -> Result { } /// The default parachains host configuration. -#[cfg(any(feature = "rococo-native", feature = "westend-native",))] +#[cfg(feature = "westend-native")] fn default_parachains_host_configuration( ) -> polkadot_runtime_parachains::configuration::HostConfiguration { @@ -168,7 +168,7 @@ fn default_parachains_host_configuration( } } -#[cfg(any(feature = "rococo-native", feature = "westend-native",))] +#[cfg(feature = "westend-native")] #[test] fn default_parachains_host_configuration_is_consistent() { default_parachains_host_configuration().panic_if_not_consistent(); @@ -486,7 +486,7 @@ pub fn get_authority_keys_from_seed_no_beefy( ) } -#[cfg(any(feature = "westend-native", feature = "rococo-native"))] +#[cfg(feature = "westend-native")] fn testnet_accounts() -> Vec { vec![ get_account_id_from_seed::("Alice"), From 7419a0be6178091c114fca1f3bd0617d10dadb6f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:34:37 +0100 Subject: [PATCH 48/83] GenesisBuilder: api: create_default_config and v2 removed --- .../support/src/genesis_builder_helper.rs | 24 ++++++++----------- .../primitives/genesis-builder/src/lib.rs | 11 --------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 5cc279d48e07..6ba71b6243e2 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -19,24 +19,16 @@ //! //! Provides common logic. For more info refer to [`sp_genesis_builder::GenesisBuilder`]. +extern crate alloc; + +use alloc::vec::Vec; use frame_support::traits::BuildGenesisConfig; use sp_genesis_builder::Result as BuildResult; use sp_runtime::format_runtime_string; -/// Get the default `GenesisConfig` as a JSON blob. For more info refer to -/// [`sp_genesis_builder::GenesisBuilder::create_default_config`] -pub fn create_default_config() -> sp_std::vec::Vec -where - GC: BuildGenesisConfig + Default, -{ - serde_json::to_string(&GC::default()) - .expect("serialization to json is expected to work. qed.") - .into_bytes() -} - /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. For /// more info refer to [`sp_genesis_builder::GenesisBuilder::build_state`]. -pub fn build_state(json: sp_std::vec::Vec) -> BuildResult { +pub fn build_state(json: Vec) -> BuildResult { let gc = serde_json::from_slice::(&json) .map_err(|e| format_runtime_string!("Invalid JSON blob: {}", e))?; ::build(&gc); @@ -47,12 +39,16 @@ pub fn build_state(json: sp_std::vec::Vec) -> BuildR /// /// No named presets are supported. For more info refer to /// [`sp_genesis_builder::GenesisBuilder::get_preset`]. -pub fn get_preset(id: Option>) -> Option> +pub fn get_preset(id: Option>) -> Option> where GC: BuildGenesisConfig + Default, { if id.is_none() { - Some(create_default_config::()) + Some( + serde_json::to_string(&GC::default()) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) } else { None } diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 218a4aec3f7a..1be8b042586c 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -49,15 +49,7 @@ pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; sp_api::decl_runtime_apis! { /// API to interact with RuntimeGenesisConfig for the runtime - #[api_version(2)] pub trait GenesisBuilder { - /// Creates the default `RuntimeGenesisConfig` and returns it as a JSON blob. - /// - /// This function instantiates the default `RuntimeGenesisConfig` struct for the runtime and - /// serializes it into a JSON blob. It returns a `Vec` containing the JSON - /// representation of the default `RuntimeGenesisConfig`. - fn create_default_config() -> alloc::vec::Vec; - /// Build `RuntimeGenesisConfig` from a JSON blob not using any defaults and store it in the /// storage. /// @@ -67,7 +59,6 @@ sp_api::decl_runtime_apis! { /// /// Please note that provided json blob must contain all `RuntimeGenesisConfig` fields, no /// defaults will be used. - #[renamed("build_config", 2)] fn build_state(json: alloc::vec::Vec) -> Result; /// Returns a JSON blob representation of the built-in `RuntimeGenesisConfig` identified by @@ -80,14 +71,12 @@ sp_api::decl_runtime_apis! { /// Otherwise function returns a JSON representation of the built-in, named /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not /// exists. Returned `Vec` contains bytes of JSON blob. - #[api_version(2)] fn get_preset(id: Option>) -> Option>; /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. /// /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If /// no named presets are provided by the runtime the list is empty. - #[api_version(2)] fn preset_names() -> alloc::vec::Vec; } } From d1b812609a598b86f9dde702e08e03c0ba2aa7d6 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:36:06 +0100 Subject: [PATCH 49/83] GenesisBuilder: impls: create_default_config removed --- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 4 ---- .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 4 ---- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ---- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 4 ---- .../runtimes/collectives/collectives-westend/src/lib.rs | 4 ---- .../parachains/runtimes/contracts/contracts-rococo/src/lib.rs | 4 ---- .../parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 4 ---- .../parachains/runtimes/coretime/coretime-westend/src/lib.rs | 4 ---- .../parachains/runtimes/glutton/glutton-westend/src/lib.rs | 4 ---- cumulus/parachains/runtimes/people/people-rococo/src/lib.rs | 4 ---- cumulus/parachains/runtimes/people/people-westend/src/lib.rs | 4 ---- cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 4 ---- cumulus/parachains/runtimes/starters/shell/src/lib.rs | 4 ---- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 4 ---- .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 4 ---- .../src/fake_runtime_api/asset_hub_polkadot_aura.rs | 4 ---- cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs | 4 ---- cumulus/test/runtime/src/lib.rs | 4 ---- polkadot/runtime/rococo/src/lib.rs | 4 ---- polkadot/runtime/test-runtime/src/lib.rs | 4 ---- polkadot/runtime/westend/src/lib.rs | 4 ---- substrate/bin/node/runtime/src/lib.rs | 4 ---- substrate/test-utils/runtime/src/lib.rs | 4 ---- templates/minimal/runtime/src/lib.rs | 4 ---- templates/parachain/runtime/src/lib.rs | 4 ---- templates/solochain/runtime/src/lib.rs | 4 ---- 26 files changed, 104 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index ae47b0b5eff9..5e6e9d1eb626 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1647,10 +1647,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 31d2fddf7f5f..8bd36ba8b9ca 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1724,10 +1724,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index bb48f3397562..9cf06b3e8b62 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1453,10 +1453,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index d1c784b2a132..c77564fc9d39 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -1110,10 +1110,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 427a87f50664..8abbfd33dc5f 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -1060,10 +1060,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index b4169476845d..04869e3c33f1 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -792,10 +792,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index e345174e11b3..40ef8fb7db17 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -876,10 +876,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 9f5c29f3a271..9ecec4154cf2 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -867,10 +867,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index c43df63a04ac..f333e8fb0b91 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -473,10 +473,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index b7407f0c44c4..30f27efbe46e 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -849,10 +849,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index acdf9b5f45d8..07403cf11f19 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -849,10 +849,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index a4fa7963b83f..8e9c52b803c5 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -370,10 +370,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index d8b973d38349..9f7d8d9a55ec 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -427,10 +427,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index d9dd4c94b135..e85c679fefd9 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -897,10 +897,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index e2b25a393650..03b93d0a3c50 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -822,10 +822,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 438ac6dc0daa..7a73b643c970 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -189,10 +189,6 @@ sp_api::impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - unimplemented!() - } - fn build_state(_: Vec) -> sp_genesis_builder::Result { unimplemented!() } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index 1a417e1ee699..4c9f1d8768d8 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -189,10 +189,6 @@ sp_api::impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - unimplemented!() - } - fn build_state(_: Vec) -> sp_genesis_builder::Result { unimplemented!() } diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index d32fe1549b68..345386e77e26 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -463,10 +463,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4b6b7e26257a..c9399d935643 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2461,10 +2461,6 @@ sp_api::impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index b5785f188190..da97eed109a9 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -1146,10 +1146,6 @@ sp_api::impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 0922ff6842cc..bfad954e5c09 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2546,10 +2546,6 @@ sp_api::impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index f86eb4f93587..cd16ccf96bda 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -3181,10 +3181,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 5a8787ff073e..c2084fc0b0e2 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -728,10 +728,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 02be4e5f105c..462c2addbb43 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -221,10 +221,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs index 6e9f5c23757f..27aceb688bd7 100644 --- a/templates/parachain/runtime/src/lib.rs +++ b/templates/parachain/runtime/src/lib.rs @@ -756,10 +756,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 3ac343cb96b4..3a7dcf5ced3f 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -575,10 +575,6 @@ impl_runtime_apis! { } impl sp_genesis_builder::GenesisBuilder for Runtime { - fn create_default_config() -> Vec { - create_default_config::() - } - fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) } From c186869fa09fe14daa6bf0eb33dbb311f73c8699 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:36:16 +0100 Subject: [PATCH 50/83] fmt --- substrate/test-utils/runtime/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index c2084fc0b0e2..050445da876a 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -27,6 +27,9 @@ pub mod extrinsic; pub mod genesismap; pub mod substrate_test_pallet; +use alloc::boxed::Box; +#[cfg(not(feature = "std"))] +use alloc::{vec, vec::Vec}; use codec::{Decode, Encode}; use frame_support::{ construct_runtime, derive_impl, @@ -47,9 +50,6 @@ use scale_info::TypeInfo; use sp_application_crypto::Ss58Codec; use sp_keyring::AccountKeyring; use sp_runtime::RuntimeString; -use alloc::boxed::Box; -#[cfg(not(feature = "std"))] -use alloc::{vec, vec::Vec}; use sp_application_crypto::{ecdsa, ed25519, sr25519, RuntimeAppPublic}; use sp_core::{OpaqueMetadata, RuntimeDebug}; From 699224c8c5e2529ddc2683b9514402135e349ff6 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:16:53 +0100 Subject: [PATCH 51/83] GenesisBuilder: api: PresetId added --- .../support/src/genesis_builder_helper.rs | 4 +-- .../primitives/genesis-builder/Cargo.toml | 3 +++ .../primitives/genesis-builder/src/lib.rs | 26 ++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 6ba71b6243e2..6d5713b2df83 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -23,7 +23,7 @@ extern crate alloc; use alloc::vec::Vec; use frame_support::traits::BuildGenesisConfig; -use sp_genesis_builder::Result as BuildResult; +use sp_genesis_builder::{Result as BuildResult, PresetId}; use sp_runtime::format_runtime_string; /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. For @@ -39,7 +39,7 @@ pub fn build_state(json: Vec) -> BuildResult { /// /// No named presets are supported. For more info refer to /// [`sp_genesis_builder::GenesisBuilder::get_preset`]. -pub fn get_preset(id: Option>) -> Option> +pub fn get_preset(id: Option) -> Option> where GC: BuildGenesisConfig + Default, { diff --git a/substrate/primitives/genesis-builder/Cargo.toml b/substrate/primitives/genesis-builder/Cargo.toml index 5a8f1c2962ce..63c88a20930d 100644 --- a/substrate/primitives/genesis-builder/Cargo.toml +++ b/substrate/primitives/genesis-builder/Cargo.toml @@ -16,6 +16,9 @@ workspace = true targets = ["x86_64-unknown-linux-gnu"] [dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["bytes"] } +scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } + sp-api = { path = "../api", default-features = false } sp-runtime = { path = "../runtime", default-features = false } serde_json = { features = ["alloc", "arbitrary_precision"], workspace = true } diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 1be8b042586c..377098265a11 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -43,10 +43,30 @@ //! genesis block. extern crate alloc; +use alloc::vec::Vec; +use codec::{Decode, Encode}; +use scale_info::TypeInfo; /// The result type alias, used in build methods. `Err` contains formatted error message. pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; +/// Wrapper representing preset id. +#[derive(Decode, Encode, Debug, TypeInfo)] +pub struct PresetId(Vec); + +impl From<&str> for PresetId { + fn from(v: &str) -> Self { + Self(v.as_bytes().to_vec()) + } +} + +impl<'a> TryFrom<&'a PresetId> for &'a str { + type Error = core::str::Utf8Error; + fn try_from(v: &'a PresetId) -> core::result::Result<&'a str, Self::Error> { + core::str::from_utf8(&v.0) + } +} + sp_api::decl_runtime_apis! { /// API to interact with RuntimeGenesisConfig for the runtime pub trait GenesisBuilder { @@ -59,7 +79,7 @@ sp_api::decl_runtime_apis! { /// /// Please note that provided json blob must contain all `RuntimeGenesisConfig` fields, no /// defaults will be used. - fn build_state(json: alloc::vec::Vec) -> Result; + fn build_state(json: Vec) -> Result; /// Returns a JSON blob representation of the built-in `RuntimeGenesisConfig` identified by /// `id`. @@ -71,12 +91,12 @@ sp_api::decl_runtime_apis! { /// Otherwise function returns a JSON representation of the built-in, named /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not /// exists. Returned `Vec` contains bytes of JSON blob. - fn get_preset(id: Option>) -> Option>; + fn get_preset(id: Option) -> Option>; /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. /// /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If /// no named presets are provided by the runtime the list is empty. - fn preset_names() -> alloc::vec::Vec; + fn preset_names() -> Vec; } } From 50aaee1af7c6f249c03377227143588ef3e38d75 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:17:30 +0100 Subject: [PATCH 52/83] GenesisBuilder: test-runtime: PresetId added --- substrate/test-utils/runtime/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 050445da876a..ff8aa291d22a 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -34,7 +34,7 @@ use codec::{Decode, Encode}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstU32, ConstU64}, weights::{ @@ -49,7 +49,6 @@ use frame_system::{ use scale_info::TypeInfo; use sp_application_crypto::Ss58Codec; use sp_keyring::AccountKeyring; -use sp_runtime::RuntimeString; use sp_application_crypto::{ecdsa, ed25519, sr25519, RuntimeAppPublic}; use sp_core::{OpaqueMetadata, RuntimeDebug}; @@ -62,6 +61,7 @@ use trie_db::{Trie, TrieMut}; use serde_json::json; use sp_api::{decl_runtime_apis, impl_runtime_apis}; pub use sp_core::hash::H256; +use sp_genesis_builder::PresetId; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ create_runtime_str, impl_opaque_keys, @@ -732,10 +732,10 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(params: Option>) -> Option> { + fn get_preset(params: Option) -> Option> { Some(if let Some(params) = params { - let patch = match params { - s if s == "staging".as_bytes() => { + let patch = match (¶ms).try_into() { + Ok("staging") => { let endowed_accounts: Vec = vec![ AccountKeyring::Bob.public().into(), AccountKeyring::Charlie.public().into(), @@ -753,19 +753,19 @@ impl_runtime_apis! { } }) }, - s if s == "foobar".as_bytes() => json!({"foo":"bar"}), + Ok("foobar") => json!({"foo":"bar"}), _ => return None, }; serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") .into_bytes() } else { - create_default_config::() + get_preset::(None)? }) } - fn preset_names() -> Vec { - vec![RuntimeString::from("foobar"), RuntimeString::from("staging")] + fn preset_names() -> Vec { + vec![PresetId::from("foobar"), PresetId::from("staging")] } } } From d50a3729d0eb7040bcc532d192238910abbed8b8 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:24:56 +0100 Subject: [PATCH 53/83] GenesisBuilder: &PresetId --- substrate/frame/support/src/genesis_builder_helper.rs | 2 +- substrate/primitives/genesis-builder/src/lib.rs | 2 +- substrate/test-utils/runtime/src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 6d5713b2df83..43e4ac512081 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -39,7 +39,7 @@ pub fn build_state(json: Vec) -> BuildResult { /// /// No named presets are supported. For more info refer to /// [`sp_genesis_builder::GenesisBuilder::get_preset`]. -pub fn get_preset(id: Option) -> Option> +pub fn get_preset(id: &Option) -> Option> where GC: BuildGenesisConfig + Default, { diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 377098265a11..841bf652cb39 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -91,7 +91,7 @@ sp_api::decl_runtime_apis! { /// Otherwise function returns a JSON representation of the built-in, named /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not /// exists. Returned `Vec` contains bytes of JSON blob. - fn get_preset(id: Option) -> Option>; + fn get_preset(id: &Option) -> Option>; /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. /// diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index ff8aa291d22a..64ce5a2dfe6d 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -732,9 +732,9 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(params: Option) -> Option> { + fn get_preset(params: &Option) -> Option> { Some(if let Some(params) = params { - let patch = match (¶ms).try_into() { + let patch = match params.try_into() { Ok("staging") => { let endowed_accounts: Vec = vec![ AccountKeyring::Bob.public().into(), @@ -760,7 +760,7 @@ impl_runtime_apis! { .expect("serialization to json is expected to work. qed.") .into_bytes() } else { - get_preset::(None)? + get_preset::(&None)? }) } From 458d45800ff83feb75843eb18fc1f4d843b8080c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:36:25 +0100 Subject: [PATCH 54/83] GenesisBuilder: runtimes update --- Cargo.lock | 2 ++ .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 6 +++--- .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 6 +++--- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 6 +++--- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 6 +++--- .../runtimes/collectives/collectives-westend/src/lib.rs | 6 +++--- .../runtimes/contracts/contracts-rococo/src/lib.rs | 6 +++--- .../parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 6 +++--- .../runtimes/coretime/coretime-westend/src/lib.rs | 6 +++--- .../parachains/runtimes/glutton/glutton-westend/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/people/people-rococo/src/lib.rs | 6 +++--- .../parachains/runtimes/people/people-westend/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/starters/shell/src/lib.rs | 6 +++--- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 6 +++--- .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 6 +++--- .../src/fake_runtime_api/asset_hub_polkadot_aura.rs | 2 +- cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs | 2 +- cumulus/test/runtime/src/lib.rs | 6 +++--- polkadot/runtime/rococo/src/lib.rs | 4 ++-- polkadot/runtime/test-runtime/src/lib.rs | 6 +++--- polkadot/runtime/westend/src/lib.rs | 6 +++--- substrate/bin/node/runtime/src/lib.rs | 6 +++--- templates/minimal/runtime/src/lib.rs | 6 +++--- templates/parachain/runtime/src/lib.rs | 6 +++--- templates/solochain/runtime/src/lib.rs | 6 +++--- 26 files changed, 72 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 985ef4be6c65..fed3784bd60e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18781,6 +18781,8 @@ dependencies = [ name = "sp-genesis-builder" version = "0.7.0" dependencies = [ + "parity-scale-codec", + "scale-info", "serde_json", "sp-api", "sp-runtime", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 5e6e9d1eb626..8c703707c87b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -55,7 +55,7 @@ use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, ord_parameter_types, parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, @@ -1651,11 +1651,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 8bd36ba8b9ca..da74d53c3a7b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -37,7 +37,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, ord_parameter_types, parameter_types, traits::{ fungible, fungibles, @@ -1728,11 +1728,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 9cf06b3e8b62..5f8817a3a891 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -59,7 +59,7 @@ use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -1457,11 +1457,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index c77564fc9d39..50fb71dc0e9e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -55,7 +55,7 @@ use bridge_hub_common::{ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -1114,11 +1114,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 8abbfd33dc5f..f305cf8f0bfc 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -66,7 +66,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ fungible::HoldConsideration, ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, @@ -1064,11 +1064,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 04869e3c33f1..d4fa83372e09 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -48,7 +48,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU16, ConstU32, ConstU64, ConstU8}, weights::{ConstantMultiplier, Weight}, @@ -796,11 +796,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 40ef8fb7db17..0819c6686216 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -38,7 +38,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -880,11 +880,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 9ecec4154cf2..51601d8ff350 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -38,7 +38,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ConstantMultiplier, Weight}, @@ -871,11 +871,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index f333e8fb0b91..670c62915083 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -66,7 +66,7 @@ use cumulus_primitives_core::AggregateMessageOrigin; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, IsInVec, Randomness, @@ -477,11 +477,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 30f27efbe46e..e05482ca595f 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -27,7 +27,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, @@ -853,11 +853,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 07403cf11f19..fea7fa3382ed 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -27,7 +27,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin, @@ -853,11 +853,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 8e9c52b803c5..638aa9332951 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -46,7 +46,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness}, weights::{ @@ -374,11 +374,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 9f7d8d9a55ec..7f1c0e63ee4b 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -54,7 +54,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness}, weights::{ @@ -431,11 +431,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index e85c679fefd9..e750e17621fc 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -37,7 +37,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, pallet_prelude::Weight, parameter_types, traits::{ @@ -901,11 +901,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 03b93d0a3c50..e68d3c8abf7d 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -41,7 +41,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, @@ -826,11 +826,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 7a73b643c970..f971912f1b93 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -197,7 +197,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn preset_names() -> Vec { + fn preset_names() -> Vec { unimplemented!() } } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index 4c9f1d8768d8..050724b4c3bd 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -197,7 +197,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn preset_names() -> Vec { + fn preset_names() -> Vec { unimplemented!() } } diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 345386e77e26..b5493f37fb13 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -47,7 +47,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstU8, Randomness}, weights::{ @@ -467,11 +467,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index c9399d935643..4e4cac8c0fc2 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2465,7 +2465,7 @@ sp_api::impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { if let Some(id) = id { genesis_config_presets::get_preset(id) } else { @@ -2473,7 +2473,7 @@ sp_api::impl_runtime_apis! { } } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![ RuntimeString::from("local_testnet"), RuntimeString::from("development"), diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index da97eed109a9..a2662ee904be 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -43,7 +43,7 @@ use frame_election_provider_support::{ }; use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{KeyOwnerProofSystem, WithdrawReasons}, }; @@ -1150,11 +1150,11 @@ sp_api::impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index bfad954e5c09..cda179a78209 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -28,7 +28,7 @@ use beefy_primitives::{ use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, SequentialPhragmen}; use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, EverythingBut, @@ -2550,11 +2550,11 @@ sp_api::impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index cd16ccf96bda..bfee815f5fea 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -31,7 +31,7 @@ use frame_support::{ derive_impl, dispatch::DispatchClass, dynamic_params::{dynamic_pallet_params, dynamic_params}, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, instances::{Instance1, Instance2}, ord_parameter_types, pallet_prelude::Get, @@ -3185,11 +3185,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 462c2addbb43..ee6f32bbb659 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -23,7 +23,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use frame::{ deps::frame_support::{ - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, weights::{FixedFee, NoFee}, }, prelude::*, @@ -225,11 +225,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs index 27aceb688bd7..a9e84f171416 100644 --- a/templates/parachain/runtime/src/lib.rs +++ b/templates/parachain/runtime/src/lib.rs @@ -30,7 +30,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, create_default_config, get_preset}, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin}, weights::{ @@ -760,11 +760,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 3a7dcf5ced3f..09e12ee9766a 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -18,7 +18,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use frame_support::genesis_builder_helper::{build_state, create_default_config, get_preset}; +use frame_support::genesis_builder_helper::{build_state, get_preset}; pub use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{ @@ -579,11 +579,11 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: Option>) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } From d397a72cc4494900f4ab0f8b93215a103f6c2bad Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:38:43 +0100 Subject: [PATCH 55/83] GenesisBuilder: runtimes update 2 --- .../src/fake_runtime_api/asset_hub_polkadot_aura.rs | 2 +- cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index f971912f1b93..82c02943c5fc 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -193,7 +193,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn get_preset(_id: Option>) -> Option> { + fn get_preset(_id: &Option) -> Option> { unimplemented!() } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index 050724b4c3bd..6b718e912164 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -193,7 +193,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn get_preset(_id: Option>) -> Option> { + fn get_preset(_id: &Option) -> Option> { unimplemented!() } From 686f5b8865e6da8e15301c08c73a17f3f5a37cef Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:54:40 +0100 Subject: [PATCH 56/83] taplo happy --- substrate/primitives/genesis-builder/Cargo.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/substrate/primitives/genesis-builder/Cargo.toml b/substrate/primitives/genesis-builder/Cargo.toml index 63c88a20930d..9e879e0d00f4 100644 --- a/substrate/primitives/genesis-builder/Cargo.toml +++ b/substrate/primitives/genesis-builder/Cargo.toml @@ -25,4 +25,10 @@ serde_json = { features = ["alloc", "arbitrary_precision"], workspace = true } [features] default = ["std"] -std = ["serde_json/std", "sp-api/std", "sp-runtime/std"] +std = [ + "codec/std", + "scale-info/std", + "serde_json/std", + "sp-api/std", + "sp-runtime/std", +] From 5fc94e0be4cdc9c2a26f20fd301d2b1b86bb8954 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:55:17 +0100 Subject: [PATCH 57/83] fixes --- polkadot/runtime/rococo/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4e4cac8c0fc2..df6af50798da 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -68,7 +68,7 @@ use beefy_primitives::{ use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::{build_state, create_default_config}, + genesis_builder_helper::build_state, parameter_types, traits::{ fungible::HoldConsideration, Contains, EitherOf, EitherOfDiverse, EverythingBut, @@ -2469,7 +2469,7 @@ sp_api::impl_runtime_apis! { if let Some(id) = id { genesis_config_presets::get_preset(id) } else { - Some(create_default_config::()) + get_preset::(None) } } From 53a79a7187c284d36b2d0beb2fe5e2589411656f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:33:55 +0100 Subject: [PATCH 58/83] GenesisBuilder: rococo: PresetId added --- .../rococo/src/genesis_config_presets.rs | 14 ++++----- polkadot/runtime/rococo/src/lib.rs | 31 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/polkadot/runtime/rococo/src/genesis_config_presets.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs index 50952d3884b0..d496ddce7139 100644 --- a/polkadot/runtime/rococo/src/genesis_config_presets.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -527,13 +527,13 @@ fn wococo_local_testnet_genesis() -> serde_json::Value { } /// Provides the JSON representation of predefined genesis config for given `id`. -pub fn get_preset(id: sp_std::vec::Vec) -> Option> { - let patch = match id { - s if s == "local_testnet".as_bytes() => rococo_local_testnet_genesis(), - s if s == "development".as_bytes() => rococo_development_config_genesis(), - s if s == "staging_testnet".as_bytes() => rococo_staging_testnet_config_genesis(), - s if s == "wococo_local_testnet".as_bytes() => wococo_local_testnet_genesis(), - s if s == "versi_local_testnet".as_bytes() => versi_local_testnet_genesis(), +pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { + let patch = match id.try_into() { + Ok("local_testnet") => rococo_local_testnet_genesis(), + Ok("development") => rococo_development_config_genesis(), + Ok("staging_testnet") => rococo_staging_testnet_config_genesis(), + Ok("wococo_local_testnet") => wococo_local_testnet_genesis(), + Ok("versi_local_testnet") => versi_local_testnet_genesis(), _ => return None, }; Some( diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index df6af50798da..fe57a108165a 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -20,6 +20,11 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit. #![recursion_limit = "512"] +use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; +use beefy_primitives::{ + ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature}, + mmr::{BeefyDataProvider, MmrLeafVersion}, +}; use pallet_nis::WithMaximumOf; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::{ @@ -57,18 +62,12 @@ use runtime_parachains::{ shared as parachains_shared, }; use scale_info::TypeInfo; -use sp_runtime::RuntimeString; +use sp_genesis_builder::PresetId; use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*}; -use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; -use beefy_primitives::{ - ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature}, - mmr::{BeefyDataProvider, MmrLeafVersion}, -}; - use frame_support::{ construct_runtime, derive_impl, - genesis_builder_helper::build_state, + genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ fungible::HoldConsideration, Contains, EitherOf, EitherOfDiverse, EverythingBut, @@ -2465,21 +2464,21 @@ sp_api::impl_runtime_apis! { build_state::(config) } - fn get_preset(id: &Option) -> Option> { + fn get_preset(id: &Option) -> Option> { if let Some(id) = id { genesis_config_presets::get_preset(id) } else { - get_preset::(None) + get_preset::(&None) } } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![ - RuntimeString::from("local_testnet"), - RuntimeString::from("development"), - RuntimeString::from("staging_testnet"), - RuntimeString::from("wococo_local_testnet"), - RuntimeString::from("versi_local_testnet"), + PresetId::from("local_testnet"), + PresetId::from("development"), + PresetId::from("staging_testnet"), + PresetId::from("wococo_local_testnet"), + PresetId::from("versi_local_testnet"), ] } } From 08885a56d0d7a1f7fca60cfa39e4db94da05e550 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:39:02 +0100 Subject: [PATCH 59/83] GenesisBuilder: tests and doc fixes --- substrate/bin/node/cli/tests/basic.rs | 14 ++++++++++---- .../bin/utils/chain-spec-builder/bin/main.rs | 11 ++++++++++- .../bin/utils/chain-spec-builder/src/lib.rs | 3 +-- .../chain-spec/src/genesis_config_builder.rs | 13 +++++++------ .../support/src/genesis_builder_helper.rs | 2 +- .../primitives/genesis-builder/src/lib.rs | 2 +- substrate/test-utils/runtime/src/lib.rs | 18 ++++++++++++------ 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/substrate/bin/node/cli/tests/basic.rs b/substrate/bin/node/cli/tests/basic.rs index 525ab2e39c12..a9eea84d9260 100644 --- a/substrate/bin/node/cli/tests/basic.rs +++ b/substrate/bin/node/cli/tests/basic.rs @@ -838,10 +838,16 @@ fn should_import_block_with_test_client() { #[test] fn default_config_as_json_works() { let mut t = new_test_ext(compact_code_unwrap()); - let r = executor_call(&mut t, "GenesisBuilder_create_default_config", &vec![]) - .0 - .unwrap(); - let r = Vec::::decode(&mut &r[..]).unwrap(); + let r = executor_call( + &mut t, + "GenesisBuilder_get_preset", + &None::<&sp_genesis_builder::PresetId>.encode(), + ) + .0 + .unwrap(); + let r = Option::>::decode(&mut &r[..]) + .unwrap() + .expect("default config is there"); let json = String::from_utf8(r.into()).expect("returned value is json. qed."); let expected = include_str!("res/default_genesis_config.json").to_string(); diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index c709287ee078..8eacdb4e4918 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -81,7 +81,16 @@ fn main() -> Result<(), String> { let presets = caller .preset_names() .map_err(|e| format!("getting default config from runtime should work: {e}"))?; - let presets: Vec = presets.into_iter().map(Into::into).collect(); + let presets: Vec = presets + .into_iter() + .map(|preset| { + String::from( + TryInto::<&str>::try_into(&preset) + .unwrap_or_else(|_| "cannot display preset id") + .to_string(), + ) + }) + .collect(); println!("Known presets are:\n{presets:#?}"); }, ChainSpecBuilderCmd::DisplayPreset(DisplayPresetCmd { runtime_wasm_path, preset_name }) => { diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 9409565d57cd..24073fc838c5 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -36,7 +36,7 @@ //! chain-spec-builder create -r runtime.wasm default //! ``` //! -//! _Note:_ [`GenesisBuilder::create_default_config`][sp-genesis-builder-create] runtime function is +//! _Note:_ [`GenesisBuilder::get_preset`][sp-genesis-builder-get-preset] runtime function is //! called. //! //! @@ -113,7 +113,6 @@ //! [`sc-chain-spec`]: ../sc_chain_spec/index.html //! [`node-cli`]: ../node_cli/index.html //! [`sp-genesis-builder`]: ../sp_genesis_builder/index.html -//! [sp-genesis-builder-create]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.create_default_config //! [sp-genesis-builder-build]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.build_state //! [sp-genesis-builder-list]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.preset_names //! [sp-genesis-builder-get-preset]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.get_preset diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 9223185e4be7..7df05acd27d0 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -26,7 +26,7 @@ use sp_core::{ storage::Storage, traits::{CallContext, CodeExecutor, Externalities, FetchRuntimeCode, RuntimeCode}, }; -use sp_genesis_builder::Result as BuildResult; +use sp_genesis_builder::{PresetId, Result as BuildResult}; use sp_state_machine::BasicExternalities; use std::borrow::Cow; @@ -84,7 +84,8 @@ where /// Returns a json representation of the default `RuntimeGenesisConfig` provided by the /// `runtime`. /// - /// Calls [`GenesisBuilder::create_default_config`](sp_genesis_builder::GenesisBuilder::create_default_config) in the `runtime`. + /// Calls [`GenesisBuilder::get_preset`](sp_genesis_builder::GenesisBuilder::get_preset) in the + /// `runtime` with `None` argument. pub fn get_default_config(&self) -> core::result::Result { self.get_named_preset(None) } @@ -156,13 +157,13 @@ where self.get_storage_for_patch(self.get_named_preset(name)?) } - pub fn preset_names(&self) -> core::result::Result, String> { + pub fn preset_names(&self) -> core::result::Result, String> { let mut t = BasicExternalities::new_empty(); let call_result = self .call(&mut t, "GenesisBuilder_preset_names", &vec![]) .map_err(|e| format!("wasm call error {e}"))?; - let preset_names = Vec::::decode(&mut &call_result[..]) + let preset_names = Vec::::decode(&mut &call_result[..]) .map_err(|e| format!("scale codec error: {e}"))?; Ok(preset_names) @@ -174,7 +175,7 @@ mod tests { use super::*; use serde_json::{from_str, json}; pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration}; - pub use sp_runtime::RuntimeString; + pub use sp_genesis_builder::PresetId; #[test] fn list_presets_works() { @@ -183,7 +184,7 @@ mod tests { ::new(substrate_test_runtime::wasm_binary_unwrap()) .preset_names() .unwrap(); - assert_eq!(presets, vec![RuntimeString::from("foobar"), RuntimeString::from("staging"),]); + assert_eq!(presets, vec![PresetId::from("foobar"), PresetId::from("staging"),]); } #[test] diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 43e4ac512081..9fa88c054564 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -23,7 +23,7 @@ extern crate alloc; use alloc::vec::Vec; use frame_support::traits::BuildGenesisConfig; -use sp_genesis_builder::{Result as BuildResult, PresetId}; +use sp_genesis_builder::{PresetId, Result as BuildResult}; use sp_runtime::format_runtime_string; /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. For diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 841bf652cb39..fb788c035935 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -51,7 +51,7 @@ use scale_info::TypeInfo; pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; /// Wrapper representing preset id. -#[derive(Decode, Encode, Debug, TypeInfo)] +#[derive(Decode, Encode, Debug, TypeInfo, PartialEq)] pub struct PresetId(Vec); impl From<&str> for PresetId { diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 64ce5a2dfe6d..f3ea14f6b3d2 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -1323,8 +1323,11 @@ mod tests { fn default_config_as_json_works() { sp_tracing::try_init_simple(); let mut t = BasicExternalities::new_empty(); - let r = executor_call(&mut t, "GenesisBuilder_create_default_config", &vec![]).unwrap(); - let r = Vec::::decode(&mut &r[..]).unwrap(); + let r = executor_call(&mut t, "GenesisBuilder_get_preset", &None::<&PresetId>.encode()) + .unwrap(); + let r = Option::>::decode(&mut &r[..]) + .unwrap() + .expect("defuault config is there"); let json = String::from_utf8(r.into()).expect("returned value is json. qed."); let expected = r#"{"system":{},"babe":{"authorities":[],"epochConfig":{"c":[1,4],"allowed_slots":"PrimaryAndSecondaryVRFSlots"}},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; @@ -1336,8 +1339,8 @@ mod tests { sp_tracing::try_init_simple(); let mut t = BasicExternalities::new_empty(); let r = executor_call(&mut t, "GenesisBuilder_preset_names", &vec![]).unwrap(); - let r = Vec::::decode(&mut &r[..]).unwrap(); - assert_eq!(r, vec![RuntimeString::from("foobar"), RuntimeString::from("staging"),]); + let r = Vec::::decode(&mut &r[..]).unwrap(); + assert_eq!(r, vec![PresetId::from("foobar"), PresetId::from("staging"),]); log::info!("r: {:#?}", r); } @@ -1457,8 +1460,11 @@ mod tests { sp_tracing::try_init_simple(); let mut t = BasicExternalities::new_empty(); - let r = executor_call(&mut t, "GenesisBuilder_create_default_config", &vec![]).unwrap(); - let r = Vec::::decode(&mut &r[..]).unwrap(); + let r = executor_call(&mut t, "GenesisBuilder_get_preset", &None::<&PresetId>.encode()) + .unwrap(); + let r = Option::>::decode(&mut &r[..]) + .unwrap() + .expect("default config is there"); let mut default_config: serde_json::Value = serde_json::from_slice(&r[..]).expect("returned value is json. qed."); From 74869da876dcaf6c9f987af4baf7e299752e92ae Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:12:18 +0100 Subject: [PATCH 60/83] fix --- substrate/bin/node/cli/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/bin/node/cli/Cargo.toml b/substrate/bin/node/cli/Cargo.toml index 8bddbbe04828..eb5ecd22c435 100644 --- a/substrate/bin/node/cli/Cargo.toml +++ b/substrate/bin/node/cli/Cargo.toml @@ -58,6 +58,7 @@ sp-api = { path = "../../../primitives/api" } sp-core = { path = "../../../primitives/core" } sp-runtime = { path = "../../../primitives/runtime" } sp-timestamp = { path = "../../../primitives/timestamp" } +sp-genesis-builder = { path = "../../../primitives/genesis-builder" } sp-inherents = { path = "../../../primitives/inherents" } sp-keyring = { path = "../../../primitives/keyring" } sp-keystore = { path = "../../../primitives/keystore" } From 1932cf19b4d0f86142eb5a6e3d1ea9b6a2ed1dd0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:26:32 +0100 Subject: [PATCH 61/83] Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index fed3784bd60e..5bd168174b4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19513,6 +19513,7 @@ dependencies = [ "sp-core", "sp-crypto-hashing", "sp-externalities 0.25.0", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", From 5a954c98482c391dfa5270497f5d5e798ce29183 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:51:56 +0100 Subject: [PATCH 62/83] doc --- substrate/primitives/genesis-builder/src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index fb788c035935..500b1ada72b0 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -24,7 +24,9 @@ //! //! Additionally the runtime may provide a number of partial predefined `RuntimeGenesisConfig` //! configurations in the form of patches which shall be applied on top of the default -//! `RuntimeGenesisConfig`. These predefined configurations are refered to as presets. +//! `RuntimeGenesisConfig`. The patch is a JSON blob, which essentially comprises the list of +//! key-value pairs that are to be customized in the default runtime genesis config. +//! These predefined configurations are refered to as presets. //! //! This allows the runtime to provide a number of predefined configs (e.g. for different //! testnets) without neccessity to leak the runtime types outside the itself. @@ -88,9 +90,11 @@ sp_api::decl_runtime_apis! { /// `RuntimeGenesisConfig` struct of the runtime. Implementation must provide default /// `RuntimeGenesisConfig`. /// - /// Otherwise function returns a JSON representation of the built-in, named - /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not - /// exists. Returned `Vec` contains bytes of JSON blob. + /// Otherwise function returns a JSON representation of the built-in, named `RuntimeGenesisConfig` preset + /// identified by `id`, or `None` if such preset does not exists. Returned `Vec` contains bytes of JSON blob + /// (patch) which comprises a list of (potentially nested) key-value pairs that are intended for custimizing the + /// default runtime genesis config. The patch shall be merged (rfc7386) with default genesis config in order to + /// obtain a full representation of genesis config that can be used in `build_state` method. fn get_preset(id: &Option) -> Option>; /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. From 3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 20 Mar 2024 14:10:25 +0100 Subject: [PATCH 63/83] doc --- .../primitives/genesis-builder/src/lib.rs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 500b1ada72b0..b9baf98d21e2 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -20,29 +20,31 @@ //! Substrate genesis config builder //! //! This module provides means to interact with `RuntimeGenesisConfig`. Runtime provides a default -//! `RuntimeGenesisConfig` structire in form of json blob. +//! `RuntimeGenesisConfig` structure in a form of the JSON blob. //! //! Additionally the runtime may provide a number of partial predefined `RuntimeGenesisConfig` //! configurations in the form of patches which shall be applied on top of the default //! `RuntimeGenesisConfig`. The patch is a JSON blob, which essentially comprises the list of //! key-value pairs that are to be customized in the default runtime genesis config. -//! These predefined configurations are refered to as presets. +//! These predefined configurations are referred to as presets. //! //! This allows the runtime to provide a number of predefined configs (e.g. for different -//! testnets) without neccessity to leak the runtime types outside the itself. +//! testnets or development) without neccessity to leak the runtime types outside the itself (e.g. +//! node or chain-spec related tools). //! //! This Runtime API allows to interact with `RuntimeGenesisConfig`, in particular: //! - provide the list of available preset names, -//! - provide a number of named, built-in, presets of `RuntimeGenesisConfig`, -//! - serialize the default `RuntimeGenesisConfig` struct into json format, -//! - deserialize the `RuntimeGenesisConfig` from given json blob and put the resulting -//! `RuntimeGenesisConfig` into the state storage creating the initial runtime's state. Allows to -//! build customized genesis. This operation internally calls `GenesisBuild::build` function for -//! all runtime pallets. +//! - provide a number of named presets of `RuntimeGenesisConfig`, +//! - provide a JSON represention of the default `RuntimeGenesisConfig` (by simply serializing the +//! default `RuntimeGenesisConfig` struct into JSON format), +//! - deserialize the full `RuntimeGenesisConfig` from given JSON blob and put the resulting +//! `RuntimeGenesisConfig` structure into the state storage creating the initial runtime's state. +//! Allows to build customized genesis. This operation internally calls `GenesisBuild::build` +//! function for all runtime pallets. //! -//! Providing externalities with empty storage and putting `RuntimeGenesisConfig` into storage -//! allows to catch and build the raw storage of `RuntimeGenesisConfig` which is the foundation for -//! genesis block. +//! Providing externalities with an empty storage and putting `RuntimeGenesisConfig` into storage +//! (by calling `build_state`) allows to construct the raw storage of `RuntimeGenesisConfig` +//! which is the foundation for genesis block. extern crate alloc; use alloc::vec::Vec; @@ -79,7 +81,7 @@ sp_api::decl_runtime_apis! { /// puts it into the storage. If the provided JSON blob is incorrect or incomplete or the /// deserialization fails, an error is returned. /// - /// Please note that provided json blob must contain all `RuntimeGenesisConfig` fields, no + /// Please note that provided JSON blob must contain all `RuntimeGenesisConfig` fields, no /// defaults will be used. fn build_state(json: Vec) -> Result; @@ -92,12 +94,12 @@ sp_api::decl_runtime_apis! { /// /// Otherwise function returns a JSON representation of the built-in, named `RuntimeGenesisConfig` preset /// identified by `id`, or `None` if such preset does not exists. Returned `Vec` contains bytes of JSON blob - /// (patch) which comprises a list of (potentially nested) key-value pairs that are intended for custimizing the + /// (patch) which comprises a list of (potentially nested) key-value pairs that are intended for customizing the /// default runtime genesis config. The patch shall be merged (rfc7386) with default genesis config in order to /// obtain a full representation of genesis config that can be used in `build_state` method. fn get_preset(id: &Option) -> Option>; - /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. + /// Returns a list of identifiers for available builtin `RuntimeGenesisConfig` presets. /// /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If /// no named presets are provided by the runtime the list is empty. From 5a430f8f268511d6debdd6c5122030fe529955ed Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:58:09 +0100 Subject: [PATCH 64/83] better error handling Error message now contains the json passed to the runtime. --- substrate/bin/utils/chain-spec-builder/bin/main.rs | 10 +++++++++- .../client/chain-spec/src/genesis_config_builder.rs | 8 ++++++-- substrate/primitives/genesis-builder/src/lib.rs | 12 +++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 8eacdb4e4918..63f737005d20 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -27,7 +27,15 @@ use sc_chain_spec::{ use staging_chain_spec_builder as chain_spec_builder; use std::fs; -fn main() -> Result<(), String> { +//avoid error message escaping +fn main() { + match inner_main() { + Err(e) => eprintln!("{}", format!("{e}")), + _ => {}, + } +} + +fn inner_main() -> Result<(), String> { sp_tracing::try_init_simple(); let builder = ChainSpecBuilder::parse(); diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 7df05acd27d0..10077ab51d38 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -114,12 +114,16 @@ where pub fn get_storage_for_config(&self, config: Value) -> core::result::Result { let mut ext = BasicExternalities::new_empty(); + let json_pretty_str = serde_json::to_string_pretty(&config) + .map_err(|e| format!("json to string failed: {e}"))?; + let call_result = self - .call(&mut ext, "GenesisBuilder_build_state", &config.to_string().encode()) + .call(&mut ext, "GenesisBuilder_build_state", &json_pretty_str.encode()) .map_err(|e| format!("wasm call error {e}"))?; BuildResult::decode(&mut &call_result[..]) - .map_err(|e| format!("scale codec error: {e}"))??; + .map_err(|e| format!("scale codec error: {e}"))? + .map_err(|e| format!("{e} for blob:\n{}", json_pretty_str))?; Ok(ext.into_storages()) } diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index b9baf98d21e2..c833ca2435a0 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -92,11 +92,13 @@ sp_api::decl_runtime_apis! { /// `RuntimeGenesisConfig` struct of the runtime. Implementation must provide default /// `RuntimeGenesisConfig`. /// - /// Otherwise function returns a JSON representation of the built-in, named `RuntimeGenesisConfig` preset - /// identified by `id`, or `None` if such preset does not exists. Returned `Vec` contains bytes of JSON blob - /// (patch) which comprises a list of (potentially nested) key-value pairs that are intended for customizing the - /// default runtime genesis config. The patch shall be merged (rfc7386) with default genesis config in order to - /// obtain a full representation of genesis config that can be used in `build_state` method. + /// Otherwise function returns a JSON representation of the built-in, named + /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not + /// exists. Returned `Vec` contains bytes of JSON blob (patch) which comprises a list of + /// (potentially nested) key-value pairs that are intended for customizing the default + /// runtime genesis config. The patch shall be merged (rfc7386) with the JSON representation + /// of the default `RuntimeGenesisConfig` to create a comprehensive genesis config that can + /// be used in `build_state` method. fn get_preset(id: &Option) -> Option>; /// Returns a list of identifiers for available builtin `RuntimeGenesisConfig` presets. From 730cc87a51a3161c506a880e18eef0e63b063113 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 08:58:27 +0100 Subject: [PATCH 65/83] test fixed --- ...spec_as_json_fails_with_invalid_config.err | 114 ++++++++++++++++++ substrate/client/chain-spec/src/chain_spec.rs | 18 +-- 2 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 substrate/client/chain-spec/res/chain_spec_as_json_fails_with_invalid_config.err diff --git a/substrate/client/chain-spec/res/chain_spec_as_json_fails_with_invalid_config.err b/substrate/client/chain-spec/res/chain_spec_as_json_fails_with_invalid_config.err new file mode 100644 index 000000000000..826b515b77d3 --- /dev/null +++ b/substrate/client/chain-spec/res/chain_spec_as_json_fails_with_invalid_config.err @@ -0,0 +1,114 @@ +Invalid JSON blob: unknown field `babex`, expected one of `system`, `babe`, `substrateTest`, `balances` at line 2 column 9 for blob: +{ + "babex": { + "authorities": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1 + ] + ], + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 3, + 10 + ] + } + }, + "balances": { + "balances": [ + [ + "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", + 100000000000000000 + ], + [ + "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", + 100000000000000000 + ], + [ + "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", + 100000000000000000 + ], + [ + "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", + 100000000000000000 + ], + [ + "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", + 100000000000000000 + ], + [ + "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", + 100000000000000000 + ], + [ + "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", + 100000000000000000 + ], + [ + "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", + 100000000000000000 + ], + [ + "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", + 100000000000000000 + ], + [ + "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", + 100000000000000000 + ], + [ + "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", + 100000000000000000 + ], + [ + "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", + 100000000000000000 + ], + [ + "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", + 100000000000000000 + ], + [ + "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", + 100000000000000000 + ], + [ + "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", + 100000000000000000 + ], + [ + "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", + 100000000000000000 + ], + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 100000000000000000 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 100000000000000000 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 100000000000000000 + ] + ] + }, + "substrateTest": { + "authorities": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" + ] + }, + "system": {} +} \ No newline at end of file diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index a9925cf69685..998df1970781 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -1034,7 +1034,6 @@ mod tests { assert!(raw_chain_spec.is_ok()); } - #[docify::export] #[test] fn generate_chain_spec_with_named_preset_works() { sp_tracing::try_init_simple(); @@ -1049,14 +1048,6 @@ mod tests { .build(); let actual = output.as_json(false).unwrap(); - let mut file = std::fs::OpenOptions::new() - .create(true) - .write(true) - .open("/tmp/default_genesis_config.json") - .unwrap(); - use std::io::Write; - file.write_all(actual.clone().as_bytes()).unwrap(); - let expected = from_str::(include_str!("../res/substrate_test_runtime_from_named_preset.json")) .unwrap(); @@ -1146,6 +1137,8 @@ mod tests { #[test] fn chain_spec_as_json_fails_with_invalid_config() { + let expected_error_message = + include_str!("../res/chain_spec_as_json_fails_with_invalid_config.err"); let j = include_str!("../../../test-utils/runtime/res/default_genesis_config_invalid_2.json"); let output = ChainSpec::<()>::builder( @@ -1158,10 +1151,9 @@ mod tests { .with_genesis_config(from_str(j).unwrap()) .build(); - assert_eq!( - output.as_json(true), - Err("Invalid JSON blob: unknown field `babex`, expected one of `system`, `babe`, `substrateTest`, `balances` at line 1 column 8".to_string()) - ); + let result = output.as_json(true); + + assert_eq!(result.err().unwrap(), expected_error_message); } #[test] From 23067cdc4fe165d4686f527f1aff63e4e665eb96 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:00:50 +0100 Subject: [PATCH 66/83] chain-spec-builder: list preset output fixed --- substrate/bin/utils/chain-spec-builder/bin/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 63f737005d20..8d6425a46c77 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -99,7 +99,7 @@ fn inner_main() -> Result<(), String> { ) }) .collect(); - println!("Known presets are:\n{presets:#?}"); + println!("{presets:#?}"); }, ChainSpecBuilderCmd::DisplayPreset(DisplayPresetCmd { runtime_wasm_path, preset_name }) => { let code = fs::read(runtime_wasm_path.as_path()) From 71589d9ef0a65539e51efbd32a3484712f155faf Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:18:53 +0100 Subject: [PATCH 67/83] PresetId: BoundedVec used --- substrate/primitives/genesis-builder/src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index c833ca2435a0..3fcdfebd9806 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -54,13 +54,21 @@ use scale_info::TypeInfo; /// The result type alias, used in build methods. `Err` contains formatted error message. pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; -/// Wrapper representing preset id. +/// Wrapper type representing preset ID. +/// +/// Preset ID length is limited to 64 bytes. For user convenience, it is recommended that the ID be +/// `utf8` string, as some tooling may not support arbitrary bytes array. #[derive(Decode, Encode, Debug, TypeInfo, PartialEq)] -pub struct PresetId(Vec); +pub struct PresetId(sp_runtime::BoundedVec>); impl From<&str> for PresetId { fn from(v: &str) -> Self { - Self(v.as_bytes().to_vec()) + Self( + v.as_bytes() + .to_vec() + .try_into() + .expect("Preset name length shall be less than 64. qed."), + ) } } From 3fbbb8991a1fcc566d86a1b1efa70db133bf912e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:19:58 +0100 Subject: [PATCH 68/83] Update polkadot/runtime/rococo/src/genesis_config_presets.rs Co-authored-by: Sebastian Kunert --- .../rococo/src/genesis_config_presets.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/rococo/src/genesis_config_presets.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs index d496ddce7139..c8558c1ebf13 100644 --- a/polkadot/runtime/rococo/src/genesis_config_presets.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -448,20 +448,19 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { }, "session": { "keys": initial_authorities - .iter() + .into_iter() .map(|x| { ( x.0.clone(), - x.0.clone(), + x.0, rococo_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), + x.2, + x.3, + x.4, + x.5, + x.6, + x.7, ), - ) }) .collect::>(), }, From 758fd45eb1595cd5ef7570f21a427dc160033dd8 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:21:28 +0100 Subject: [PATCH 69/83] Update substrate/primitives/genesis-builder/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/primitives/genesis-builder/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 3fcdfebd9806..371008989244 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -85,7 +85,7 @@ sp_api::decl_runtime_apis! { /// Build `RuntimeGenesisConfig` from a JSON blob not using any defaults and store it in the /// storage. /// - /// This function deserializes the full `RuntimeGenesisConfig` from the given JSON blob and + /// In the case of a FRAME-based runtime, this function deserializes the full `RuntimeGenesisConfig` from the given JSON blob and /// puts it into the storage. If the provided JSON blob is incorrect or incomplete or the /// deserialization fails, an error is returned. /// From 92e6824b1a2ba8387052639652d965b5b0f06a11 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:42:38 +0100 Subject: [PATCH 70/83] doc: non-frame runtime mentioned --- .../primitives/genesis-builder/src/lib.rs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 371008989244..99922d25a24a 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -19,14 +19,21 @@ //! Substrate genesis config builder //! -//! This module provides means to interact with `RuntimeGenesisConfig`. Runtime provides a default -//! `RuntimeGenesisConfig` structure in a form of the JSON blob. +//! For FRAME based runtimes, this runtime interface provides means to interact with +//! `RuntimeGenesisConfig`. Runtime provides a default `RuntimeGenesisConfig` structure in a form of +//! the JSON blob. //! -//! Additionally the runtime may provide a number of partial predefined `RuntimeGenesisConfig` -//! configurations in the form of patches which shall be applied on top of the default -//! `RuntimeGenesisConfig`. The patch is a JSON blob, which essentially comprises the list of -//! key-value pairs that are to be customized in the default runtime genesis config. -//! These predefined configurations are referred to as presets. +//! For non-FRAME runtimes this interface is intended to build genesis state of the runtime basing +//! on some input arbitrary bytes array. This documentation uses term `RuntimeGenesisConfig`, which +//! for non-FRAME runtimes may be understood as the runtime-side entity representing initial runtime +//! configuration. The representation of the preset is an arbitrary `Vec` and does not +//! necessarily have to represent a JSON blob. +//! +//! The runtime may provide a number of partial predefined `RuntimeGenesisConfig` configurations in +//! the form of patches which shall be applied on top of the default `RuntimeGenesisConfig`. The +//! patch is a JSON blob, which essentially comprises the list of key-value pairs that are to be +//! customized in the default runtime genesis config. These predefined configurations are referred +//! to as presets. //! //! This allows the runtime to provide a number of predefined configs (e.g. for different //! testnets or development) without neccessity to leak the runtime types outside the itself (e.g. From c3c1452c37d837724e0fae7fef81e6b64c9b9aaf Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:20:36 +0100 Subject: [PATCH 71/83] fix --- polkadot/runtime/rococo/src/genesis_config_presets.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/runtime/rococo/src/genesis_config_presets.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs index c8558c1ebf13..c0b9c6b4b27c 100644 --- a/polkadot/runtime/rococo/src/genesis_config_presets.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -461,6 +461,7 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { x.6, x.7, ), + ) }) .collect::>(), }, From 671d52a7615ab5cb844070cca98a9e9ee88a00ff Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:24:59 +0100 Subject: [PATCH 72/83] fmt --- polkadot/runtime/rococo/src/genesis_config_presets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/genesis_config_presets.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs index c0b9c6b4b27c..03a123145fa6 100644 --- a/polkadot/runtime/rococo/src/genesis_config_presets.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -461,7 +461,7 @@ fn rococo_staging_testnet_config_genesis() -> serde_json::Value { x.6, x.7, ), - ) + ) }) .collect::>(), }, From f990e643f7fac9ffd684596654ad40cba9d9737b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:49:15 +0100 Subject: [PATCH 73/83] prdoc + bump crates versions --- Cargo.lock | 6 +++--- prdoc/pr_2714.prdoc | 20 +++++++++++++++++++ .../bin/utils/chain-spec-builder/Cargo.toml | 2 +- substrate/client/chain-spec/Cargo.toml | 2 +- .../primitives/genesis-builder/Cargo.toml | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 prdoc/pr_2714.prdoc diff --git a/Cargo.lock b/Cargo.lock index 5da6bd60e77c..73ecfb687b19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15624,7 +15624,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" -version = "27.0.0" +version = "28.0.0" dependencies = [ "array-bytes 6.1.0", "docify 0.2.7", @@ -18788,7 +18788,7 @@ dependencies = [ [[package]] name = "sp-genesis-builder" -version = "0.7.0" +version = "0.8.0" dependencies = [ "parity-scale-codec", "scale-info", @@ -19427,7 +19427,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "staging-chain-spec-builder" -version = "2.0.0" +version = "3.0.0" dependencies = [ "clap 4.5.3", "log", diff --git a/prdoc/pr_2714.prdoc b/prdoc/pr_2714.prdoc new file mode 100644 index 000000000000..2ad888a83ed9 --- /dev/null +++ b/prdoc/pr_2714.prdoc @@ -0,0 +1,20 @@ +title: GenesisConfig presets for runtime + +doc: + - audience: Runtime Dev + description: | + The runtime now can provide a number of predefined presets of `RuntimeGenesisConfig` struct. This presets are intended to be used in different deployments, e.g.: `local`, `staging`, etc, and should be included into the corresponding chain-specs. + Having `GenesisConfig` presets in runtime allows to fully decouple node from runtime types (the problem is described in #1984). + + Summary of changes: + - The `GenesisBuilder` API was adjusted to enable this functionality, + - (Breaking change) Old `create_default_config` method was removed, `build_config` was renamed to `build_state`. As a consequence a node won't be able to interact with genesis config for older runtimes. The cleanup was made for sake of API simplicity. + + - audience: Node Dev + description: | + The `ChainSpecBuilder` is extended with `with_genesis_config_preset_name` method which allows to build chain-spec using named preset provided by the runtime. + +crates: + - name: sp-genesis-builder + - name: chain-spec-builder + - name: sc-chain-spec diff --git a/substrate/bin/utils/chain-spec-builder/Cargo.toml b/substrate/bin/utils/chain-spec-builder/Cargo.toml index c126a76b763f..5c8a3ab4e89a 100644 --- a/substrate/bin/utils/chain-spec-builder/Cargo.toml +++ b/substrate/bin/utils/chain-spec-builder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "staging-chain-spec-builder" -version = "2.0.0" +version = "3.0.0" authors.workspace = true edition.workspace = true build = "build.rs" diff --git a/substrate/client/chain-spec/Cargo.toml b/substrate/client/chain-spec/Cargo.toml index fbdc2b5f70ec..cbda9606cf50 100644 --- a/substrate/client/chain-spec/Cargo.toml +++ b/substrate/client/chain-spec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sc-chain-spec" -version = "27.0.0" +version = "28.0.0" authors.workspace = true edition.workspace = true license = "GPL-3.0-or-later WITH Classpath-exception-2.0" diff --git a/substrate/primitives/genesis-builder/Cargo.toml b/substrate/primitives/genesis-builder/Cargo.toml index 9e879e0d00f4..96e995532941 100644 --- a/substrate/primitives/genesis-builder/Cargo.toml +++ b/substrate/primitives/genesis-builder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sp-genesis-builder" -version = "0.7.0" +version = "0.8.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" From a234e5915b19bd5d0ca2e8cad61cab1747c66925 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:11:19 +0100 Subject: [PATCH 74/83] prdoc fixed --- prdoc/pr_2714.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_2714.prdoc b/prdoc/pr_2714.prdoc index 2ad888a83ed9..282945ee8f44 100644 --- a/prdoc/pr_2714.prdoc +++ b/prdoc/pr_2714.prdoc @@ -16,5 +16,5 @@ doc: crates: - name: sp-genesis-builder - - name: chain-spec-builder + - name: staging-chain-spec-builder - name: sc-chain-spec From 0028492d6e90197bd82c14719d17ab773175a306 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:52:15 +0100 Subject: [PATCH 75/83] made taplo happy --- polkadot/node/subsystem-bench/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/node/subsystem-bench/Cargo.toml b/polkadot/node/subsystem-bench/Cargo.toml index 2570fe9cfa23..05907e428f92 100644 --- a/polkadot/node/subsystem-bench/Cargo.toml +++ b/polkadot/node/subsystem-bench/Cargo.toml @@ -56,7 +56,7 @@ bitvec = "1.0.1" kvdb-memorydb = "0.13.0" parity-scale-codec = { version = "3.6.1", features = ["derive", "std"] } -tokio = { version = "1.24.2", features = ["rt-multi-thread", "parking_lot"] } +tokio = { version = "1.24.2", features = ["parking_lot", "rt-multi-thread"] } clap-num = "1.0.2" polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" } sp-keyring = { path = "../../../substrate/primitives/keyring" } From 468ed2df07acbafce56e8586b2055fea9a719ebd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:52:29 +0200 Subject: [PATCH 76/83] prdoc fix --- prdoc/pr_2714.prdoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prdoc/pr_2714.prdoc b/prdoc/pr_2714.prdoc index 282945ee8f44..f5f6e61c656e 100644 --- a/prdoc/pr_2714.prdoc +++ b/prdoc/pr_2714.prdoc @@ -16,5 +16,8 @@ doc: crates: - name: sp-genesis-builder + bump: minor - name: staging-chain-spec-builder + bump: major - name: sc-chain-spec + bump: major From 1a3fcb3afc9f532cd24396d38a73117b501143d5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:15:49 +0200 Subject: [PATCH 77/83] fix --- polkadot/runtime/rococo/src/genesis_config_presets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/genesis_config_presets.rs b/polkadot/runtime/rococo/src/genesis_config_presets.rs index 03a123145fa6..bac6902383e3 100644 --- a/polkadot/runtime/rococo/src/genesis_config_presets.rs +++ b/polkadot/runtime/rococo/src/genesis_config_presets.rs @@ -107,7 +107,7 @@ fn rococo_session_keys( fn default_parachains_host_configuration( ) -> runtime_parachains::configuration::HostConfiguration { use primitives::{ - vstaging::node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE, + node_features::FeatureIndex, AsyncBackingParams, MAX_CODE_SIZE, MAX_POV_SIZE, }; runtime_parachains::configuration::HostConfiguration { From c374a37d82b9ea9b988bf8ffccaf116074d34e84 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:47:30 +0200 Subject: [PATCH 78/83] PresetId is RuntimeString --- .../primitives/genesis-builder/src/lib.rs | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 99922d25a24a..2cbac305b4d9 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -55,36 +55,12 @@ extern crate alloc; use alloc::vec::Vec; -use codec::{Decode, Encode}; -use scale_info::TypeInfo; /// The result type alias, used in build methods. `Err` contains formatted error message. pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; -/// Wrapper type representing preset ID. -/// -/// Preset ID length is limited to 64 bytes. For user convenience, it is recommended that the ID be -/// `utf8` string, as some tooling may not support arbitrary bytes array. -#[derive(Decode, Encode, Debug, TypeInfo, PartialEq)] -pub struct PresetId(sp_runtime::BoundedVec>); - -impl From<&str> for PresetId { - fn from(v: &str) -> Self { - Self( - v.as_bytes() - .to_vec() - .try_into() - .expect("Preset name length shall be less than 64. qed."), - ) - } -} - -impl<'a> TryFrom<&'a PresetId> for &'a str { - type Error = core::str::Utf8Error; - fn try_from(v: &'a PresetId) -> core::result::Result<&'a str, Self::Error> { - core::str::from_utf8(&v.0) - } -} +/// The type representing preset ID. +pub type PresetId = sp_runtime::RuntimeString; sp_api::decl_runtime_apis! { /// API to interact with RuntimeGenesisConfig for the runtime From b1e52307ca1227a8db56a558704b330cfede838b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:48:08 +0200 Subject: [PATCH 79/83] genesis_builder_helper: closure added --- .../support/src/genesis_builder_helper.rs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 9fa88c054564..7389c5a787d7 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -35,21 +35,23 @@ pub fn build_state(json: Vec) -> BuildResult { Ok(()) } -/// Get the default `GenesisConfig` as a JSON blob if `id` is None. +/// Get the default `GenesisConfig` as a JSON blob if `name` is None. /// -/// No named presets are supported. For more info refer to -/// [`sp_genesis_builder::GenesisBuilder::get_preset`]. -pub fn get_preset(id: &Option) -> Option> +/// Query of named presets is delegetaed to provided `preset_for_name` closure. For more info refer +/// to [`sp_genesis_builder::GenesisBuilder::get_preset`]. +pub fn get_preset( + name: &Option, + preset_for_name: impl FnOnce(&sp_genesis_builder::PresetId) -> Option>, +) -> Option> where GC: BuildGenesisConfig + Default, { - if id.is_none() { + name.as_ref().map_or( Some( serde_json::to_string(&GC::default()) .expect("serialization to json is expected to work. qed.") .into_bytes(), - ) - } else { - None - } + ), + preset_for_name, + ) } From a39c4bb66f65d2d2c8992fbbb0f14120d1b0361f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:13:51 +0200 Subject: [PATCH 80/83] test-runtime: fix --- substrate/test-utils/runtime/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index f3ea14f6b3d2..00e7d0667e04 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -732,9 +732,9 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(params: &Option) -> Option> { - Some(if let Some(params) = params { - let patch = match params.try_into() { + fn get_preset(name: &Option) -> Option> { + get_preset::(name, |name| { + let patch = match name.try_into() { Ok("staging") => { let endowed_accounts: Vec = vec![ AccountKeyring::Bob.public().into(), @@ -756,11 +756,9 @@ impl_runtime_apis! { Ok("foobar") => json!({"foo":"bar"}), _ => return None, }; - serde_json::to_string(&patch) + Some(serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") - .into_bytes() - } else { - get_preset::(&None)? + .into_bytes()) }) } From 436494e70866434d3ebcf1652d3d75bd4fb3a67c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:48:22 +0200 Subject: [PATCH 81/83] rococo: fixes --- polkadot/runtime/rococo/src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 734bcd208294..e870b3db5ea4 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2368,11 +2368,7 @@ sp_api::impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - if let Some(id) = id { - genesis_config_presets::get_preset(id) - } else { - get_preset::(&None) - } + get_preset::(id, &genesis_config_presets::get_preset) } fn preset_names() -> Vec { From a7734944fb001b04f5ff3c032f361a0928062512 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:17:59 +0200 Subject: [PATCH 82/83] runtimes: closure added --- cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 2 +- cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 2 +- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 2 +- .../runtimes/collectives/collectives-westend/src/lib.rs | 2 +- .../parachains/runtimes/contracts/contracts-rococo/src/lib.rs | 2 +- cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 2 +- .../parachains/runtimes/coretime/coretime-westend/src/lib.rs | 2 +- cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs | 2 +- cumulus/parachains/runtimes/people/people-rococo/src/lib.rs | 2 +- cumulus/parachains/runtimes/people/people-westend/src/lib.rs | 2 +- cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 2 +- cumulus/parachains/runtimes/starters/shell/src/lib.rs | 2 +- cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 2 +- cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs | 2 +- cumulus/test/runtime/src/lib.rs | 2 +- polkadot/runtime/test-runtime/src/lib.rs | 2 +- polkadot/runtime/westend/src/lib.rs | 2 +- substrate/bin/node/runtime/src/lib.rs | 2 +- templates/minimal/runtime/src/lib.rs | 2 +- templates/parachain/runtime/src/apis.rs | 2 +- templates/solochain/runtime/src/lib.rs | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index a44f1a354d53..cded643de098 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1653,7 +1653,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 7752bd5fbd9d..41cd94361116 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1730,7 +1730,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 8b3fd4fdb1a6..794681dfc74f 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1455,7 +1455,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 14161b9bea0a..ca54f9faeb08 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -1116,7 +1116,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index aa458ca540b8..f51db5e8456f 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -1066,7 +1066,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 14e78706259f..82a9da045a6b 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -798,7 +798,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index f0a6a563e0e6..950a3e99ae2d 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -882,7 +882,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index cd112c74ebb7..0ba6a74911b0 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -873,7 +873,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 61d7ad9868c2..3391ab0e79c2 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -479,7 +479,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 017bc7debaf5..f3c7c433888a 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -855,7 +855,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 9347a168495e..01098a41efd2 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -855,7 +855,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 638aa9332951..461133f6cfc0 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -375,7 +375,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 84f1763c2087..a3d1629bbe5e 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -433,7 +433,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 24f02915f6d8..9339fc6f0b45 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -916,7 +916,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 650a14126548..0808a8362924 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -829,7 +829,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index f5867816974b..db889fef345f 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -468,7 +468,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index 5d17779ab81f..a1a5029adc14 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -1176,7 +1176,7 @@ sp_api::impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 965a595cb1e6..54dc614fffc1 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2520,7 +2520,7 @@ sp_api::impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 3f699aa1f8a8..044a69552be8 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -3187,7 +3187,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index ee6f32bbb659..5788cdeaf73b 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -226,7 +226,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/templates/parachain/runtime/src/apis.rs b/templates/parachain/runtime/src/apis.rs index 41fc19a45845..b13ba278fae6 100644 --- a/templates/parachain/runtime/src/apis.rs +++ b/templates/parachain/runtime/src/apis.rs @@ -269,7 +269,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 09e12ee9766a..89cdf1107e1e 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -580,7 +580,7 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id) + get_preset::(id, |_| None) } fn preset_names() -> Vec { From f273a87cdf1958b68b62aa6d57ec552ba22a31d1 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:33:46 +0200 Subject: [PATCH 83/83] Update substrate/test-utils/runtime/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/test-utils/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 00e7d0667e04..370aa0034fcd 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -1325,7 +1325,7 @@ mod tests { .unwrap(); let r = Option::>::decode(&mut &r[..]) .unwrap() - .expect("defuault config is there"); + .expect("default config is there"); let json = String::from_utf8(r.into()).expect("returned value is json. qed."); let expected = r#"{"system":{},"babe":{"authorities":[],"epochConfig":{"c":[1,4],"allowed_slots":"PrimaryAndSecondaryVRFSlots"}},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#;