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] 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 c7236572ed7..346bb6a7c36 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 acc3f723cdd..ff033094f62 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::<Runtime>] ); } +fn default_parachains_host_configuration( +) -> runtime_parachains::configuration::HostConfiguration<primitives::BlockNumber> { + 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<TPublic: Public>(seed: &str) -> AccountId +// where +// AccountPublic: From<<TPublic::Pair as Pair>::Public>, +// { +// AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() +// } +// +// fn testnet_accounts() -> Vec<AccountId> { +// vec![ +// get_account_id_from_seed::<sr25519::Public>("Alice"), +// get_account_id_from_seed::<sr25519::Public>("Bob"), +// get_account_id_from_seed::<sr25519::Public>("Charlie"), +// get_account_id_from_seed::<sr25519::Public>("Dave"), +// get_account_id_from_seed::<sr25519::Public>("Eve"), +// get_account_id_from_seed::<sr25519::Public>("Ferdie"), +// get_account_id_from_seed::<sr25519::Public>("Alice//stash"), +// get_account_id_from_seed::<sr25519::Public>("Bob//stash"), +// get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), +// get_account_id_from_seed::<sr25519::Public>("Dave//stash"), +// get_account_id_from_seed::<sr25519::Public>("Eve//stash"), +// get_account_id_from_seed::<sr25519::Public>("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<Vec<AccountId>>, +) -> serde_json::Value { + let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap(); + + const ENDOWMENT: u128 = 1_000_000 * UNITS; + + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(), + }, + "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::<Vec<_>>(), + }, + "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<AccountId> = 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<Block> 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: <Block as BlockT>::Extrinsic, block_hash: <Block as BlockT>::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<PersistedValidationData<Hash, BlockNumber>> { - parachains_runtime_api_impl::persisted_validation_data::<Runtime>(para_id, assumption) - } + parachains_runtime_api_impl::persisted_validation_data::<Runtime>(para_id, assumption) + } fn assumed_validation_data( para_id: ParaId, expected_persisted_validation_data_hash: Hash, - ) -> Option<(PersistedValidationData<Hash, BlockNumber>, ValidationCodeHash)> { + ) -> Option<(PersistedValidationData<Hash, BlockNumber>, ValidationCodeHash)> { parachains_runtime_api_impl::assumed_validation_data::<Runtime>( 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::<Runtime>(para_id, outputs) } @@ -1836,8 +2237,8 @@ sp_api::impl_runtime_apis! { fn validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option<ValidationCode> { - parachains_runtime_api_impl::validation_code::<Runtime>(para_id, assumption) - } + parachains_runtime_api_impl::validation_code::<Runtime>(para_id, assumption) + } fn candidate_pending_availability(para_id: ParaId) -> Option<CommittedCandidateReceipt<Hash>> { parachains_runtime_api_impl::candidate_pending_availability::<Runtime>(para_id) @@ -1868,7 +2269,7 @@ sp_api::impl_runtime_apis! { fn inbound_hrmp_channels_contents( recipient: ParaId - ) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>> { + ) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>> { parachains_runtime_api_impl::inbound_hrmp_channels_contents::<Runtime>(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::<Runtime>(stmt, signature) } @@ -1893,22 +2294,22 @@ sp_api::impl_runtime_apis! { fn validation_code_hash(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option<ValidationCodeHash> - { - parachains_runtime_api_impl::validation_code_hash::<Runtime>(para_id, assumption) - } + { + parachains_runtime_api_impl::validation_code_hash::<Runtime>(para_id, assumption) + } fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)> { parachains_runtime_api_impl::get_session_disputes::<Runtime>() } fn unapplied_slashes( - ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { + ) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> { parachains_runtime_api_impl::unapplied_slashes::<Runtime>() } fn key_ownership_proof( validator_id: ValidatorId, - ) -> Option<slashing::OpaqueKeyOwnershipProof> { + ) -> Option<slashing::OpaqueKeyOwnershipProof> { 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::<Runtime>( 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<beefy_primitives::OpaqueKeyOwnershipProof> { + ) -> Option<beefy_primitives::OpaqueKeyOwnershipProof> { 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<BlockNumber>, best_known_block_number: Option<BlockNumber>, - ) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<mmr::Hash>), mmr::Error> { + ) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<mmr::Hash>), 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<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<mmr::Hash>) -> Result<(), mmr::Error> - { - let leaves = leaves.into_iter().map(|leaf| - leaf.into_opaque_leaf() - .try_decode() - .ok_or(mmr::Error::Verify)).collect::<Result<Vec<mmr::Leaf>, 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::<Result<Vec<mmr::Leaf>, mmr::Error>>()?; + Mmr::verify_leaves(leaves, proof) + } fn verify_proof_stateless( root: mmr::Hash, leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<mmr::Hash> - ) -> 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::<mmr::Hashing, _>(root, nodes, proof) } @@ -2047,23 +2448,23 @@ sp_api::impl_runtime_apis! { fn submit_report_equivocation_unsigned_extrinsic( equivocation_proof: fg_primitives::EquivocationProof< - <Block as BlockT>::Hash, - sp_runtime::traits::NumberFor<Block>, + <Block as BlockT>::Hash, + sp_runtime::traits::NumberFor<Block>, >, 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<fg_primitives::OpaqueKeyOwnershipProof> { + ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> { 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<babe_primitives::OpaqueKeyOwnershipProof> { + ) -> Option<babe_primitives::OpaqueKeyOwnershipProof> { 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<<Block as BlockT>::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<u8>, - ) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> { + ) -> Option<Vec<(Vec<u8>, 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: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> { - TransactionPayment::query_info(uxt, len) - } - fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> { - 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: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> { + 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<Block, Hash> for RuntimeApi { fn authority_set_proof() -> beefy_primitives::mmr::BeefyAuthoritySet<Hash> { @@ -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<frame_benchmarking::BenchmarkList>, Vec<frame_support::traits::StorageInfo>, - ) { + ) { 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<frame_benchmarking::BenchmarkBatch>, 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<MultiLocation, BenchmarkError> { + 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<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys(); + let treasury_key = frame_system::Account::<Runtime>::hashed_key_for(Treasury::account_id()); + whitelist.push(treasury_key.to_vec().into()); + + let mut batches = Vec::<BenchmarkBatch>::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<u8>) -> sp_genesis_builder::Result { build_config::<RuntimeGenesisConfig>(config) } + + fn create_default_config2(params: sp_std::vec::Vec<u8>) -> sp_std::vec::Vec<u8> { + 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() + } } } -- GitLab