From 5061e06113398ec6d48b3000cb8f004334d8f8af Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 7 Aug 2024 11:50:43 +0300 Subject: [PATCH 01/14] Support customizations --- .../src/chain_spec/asset_hubs.rs | 6 +- .../src/chain_spec/bridge_hubs.rs | 15 +- .../src/chain_spec/collectives.rs | 6 +- .../src/chain_spec/contracts.rs | 136 ++--- .../src/chain_spec/coretime.rs | 12 +- .../src/chain_spec/glutton.rs | 5 +- .../polkadot-parachain/src/chain_spec/mod.rs | 356 ++++++++++- .../src/chain_spec/penpal.rs | 6 +- .../src/chain_spec/people.rs | 14 +- .../src/chain_spec/rococo_parachain.rs | 5 +- .../src/chain_spec/seedling.rs | 5 +- .../src/chain_spec/shell.rs | 2 +- cumulus/polkadot-parachain/src/cli.rs | 85 ++- cumulus/polkadot-parachain/src/command.rs | 561 +++--------------- .../src/common/chain_spec.rs | 63 ++ cumulus/polkadot-parachain/src/common/mod.rs | 2 + .../polkadot-parachain/src/common/runtime.rs | 44 ++ cumulus/polkadot-parachain/src/main.rs | 9 +- 18 files changed, 712 insertions(+), 620 deletions(-) create mode 100644 cumulus/polkadot-parachain/src/common/chain_spec.rs create mode 100644 cumulus/polkadot-parachain/src/common/runtime.rs diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index af5bccdc416f..571ffc197690 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec, - SAFE_XCM_VERSION, +use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, }; use cumulus_primitives_core::ParaId; use hex_literal::hex; diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 3b7376d045b8..35e14a4aa5c5 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, GenericChainSpec}; +use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}, + common::chain_spec::GenericChainSpec, +}; use cumulus_primitives_core::ParaId; use parachains_common::Balance as BridgeHubBalance; use sc_chain_spec::ChainSpec; @@ -129,7 +132,10 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup pub mod rococo { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::chain_spec::{Extensions, GenericChainSpec, SAFE_XCM_VERSION}; + use crate::{ + chain_spec::SAFE_XCM_VERSION, + common::chain_spec::{Extensions, GenericChainSpec}, + }; use parachains_common::{AccountId, AuraId}; use sc_chain_spec::ChainType; @@ -254,7 +260,10 @@ pub mod kusama { /// Sub-module for Westend setup. pub mod westend { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::chain_spec::{Extensions, GenericChainSpec, SAFE_XCM_VERSION}; + use crate::{ + chain_spec::SAFE_XCM_VERSION, + common::chain_spec::{Extensions, GenericChainSpec}, + }; use parachains_common::{AccountId, AuraId}; use sc_chain_spec::ChainType; diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index c0a9f195d89b..ab8e98bb52c3 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec, - SAFE_XCM_VERSION, +use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, }; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId, Balance as CollectivesBalance}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs index 4e89b81d1be4..2cd098a4cc24 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec, - SAFE_XCM_VERSION, +use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, }; use cumulus_primitives_core::ParaId; use hex_literal::hex; @@ -132,71 +132,71 @@ pub fn contracts_rococo_config() -> GenericChainSpec { properties.insert("tokenDecimals".into(), 12.into()); GenericChainSpec::builder( - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID } - ) - .with_name("Contracts on Rococo") - .with_id("contracts-rococo") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(contracts_rococo_genesis( - vec![ - // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 - ( - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .into(), - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .unchecked_into(), - ), - // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 - ( - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .into(), - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .unchecked_into(), - ), - // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM - ( - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .into(), - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .unchecked_into(), - ), - // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF - ( - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .into(), - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .unchecked_into(), - ), - ], - // Warning: The configuration for a production chain should not contain - // any endowed accounts here, otherwise it'll be minting extra native tokens - // from the relay chain on the parachain. - vec![ - // NOTE: Remove endowed accounts if deployed on other relay chains. - // Endowed accounts - hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), - // AccountId of an account which `ink-waterfall` uses for automated testing - hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), - ], - CONTRACTS_PARACHAIN_ID.into(), - )) - .with_boot_nodes(vec![ - "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" - .parse() - .expect("MultiaddrWithPeerId"), - ]) - .with_properties(properties) - .build() + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, + ) + .with_name("Contracts on Rococo") + .with_id("contracts-rococo") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(contracts_rococo_genesis( + vec![ + // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 + ( + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .into(), + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .unchecked_into(), + ), + // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 + ( + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .into(), + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .unchecked_into(), + ), + // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM + ( + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .into(), + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .unchecked_into(), + ), + // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF + ( + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .into(), + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .unchecked_into(), + ), + ], + // Warning: The configuration for a production chain should not contain + // any endowed accounts here, otherwise it'll be minting extra native tokens + // from the relay chain on the parachain. + vec![ + // NOTE: Remove endowed accounts if deployed on other relay chains. + // Endowed accounts + hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), + // AccountId of an account which `ink-waterfall` uses for automated testing + hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), + ], + CONTRACTS_PARACHAIN_ID.into(), + )) + .with_boot_nodes(vec![ + "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" + .parse() + .expect("MultiaddrWithPeerId"), + ]) + .with_properties(properties) + .build() } fn contracts_rococo_genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index fe60b09fd8b2..9e3f1506456d 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::GenericChainSpec; +use crate::common::chain_spec::GenericChainSpec; use cumulus_primitives_core::ParaId; use sc_chain_spec::{ChainSpec, ChainType}; use std::{borrow::Cow, str::FromStr}; @@ -145,8 +145,9 @@ pub fn chain_type_name(chain_type: &ChainType) -> Cow { /// Sub-module for Rococo setup. pub mod rococo { use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec, ParaId}; - use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, + use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::Extensions, }; use parachains_common::{AccountId, AuraId, Balance}; use sc_chain_spec::ChainType; @@ -242,8 +243,9 @@ pub mod rococo { /// Sub-module for Westend setup. pub mod westend { use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec, ParaId}; - use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, + use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::Extensions, }; use parachains_common::{AccountId, AuraId, Balance}; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index 77a4123b13ee..b96432d1d60b 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{get_account_id_from_seed, Extensions, GenericChainSpec}; +use crate::{ + chain_spec::get_account_id_from_seed, + common::chain_spec::{Extensions, GenericChainSpec}, +}; use cumulus_primitives_core::ParaId; use parachains_common::AuraId; use sc_service::ChainType; diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index 19047b073b05..cf8f1209d1d8 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -14,9 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use crate::common::{ + chain_spec::{GenericChainSpec, LoadSpec}, + runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT}, +}; +use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, Signature}; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; -use serde::{Deserialize, Serialize}; +use sc_chain_spec::ChainSpec; use sp_core::{Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -35,27 +39,6 @@ pub mod shell; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; -/// Generic extensions for Parachain ChainSpecs. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct Extensions { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, - /// The id of the Parachain. - #[serde(alias = "paraId", alias = "ParaId")] - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - -/// Generic chain spec for all polkadot-parachain runtimes -pub type GenericChainSpec = sc_service::GenericChainSpec; - /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { TPublic::Pair::from_string(&format!("//{}", seed), None) @@ -80,21 +63,330 @@ pub fn get_collator_keys_from_seed(seed: &str) -> (seed) } +/// Extracts the normalized chain id and parachain id from the input chain id. +/// (H/T to Phala for the idea) +/// E.g. "penpal-kusama-2004" yields ("penpal-kusama", Some(2004)) +fn extract_parachain_id<'a>( + id: &'a str, + para_prefixes: &[&str], +) -> (&'a str, &'a str, Option) { + for para_prefix in para_prefixes { + if let Some(suffix) = id.strip_prefix(para_prefix) { + let para_id: u32 = suffix.parse().expect("Invalid parachain-id suffix"); + return (&id[..para_prefix.len() - 1], id, Some(para_id.into())); + } + } + + (id, id, None) +} + +#[derive(Debug)] +pub(crate) struct ChainSpecLoader; + +impl LoadSpec for ChainSpecLoader { + fn load_spec(&self, id: &str) -> Result, String> { + Ok(match id { + // - Default-like + "staging" => Box::new(rococo_parachain::staging_rococo_parachain_local_config()), + "tick" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/tick.json")[..], + )?), + "trick" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/trick.json")[..], + )?), + "track" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/track.json")[..], + )?), + + // -- Starters + "shell" => Box::new(shell::get_shell_chain_spec()), + "seedling" => Box::new(seedling::get_seedling_chain_spec()), + + // -- Asset Hub Polkadot + "asset-hub-polkadot" | "statemint" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/asset-hub-polkadot.json")[..], + )?), + + // -- Asset Hub Kusama + "asset-hub-kusama" | "statemine" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/asset-hub-kusama.json")[..], + )?), + + // -- Asset Hub Rococo + "asset-hub-rococo-dev" => Box::new(asset_hubs::asset_hub_rococo_development_config()), + "asset-hub-rococo-local" => Box::new(asset_hubs::asset_hub_rococo_local_config()), + // the chain spec as used for generating the upgrade genesis values + "asset-hub-rococo-genesis" => Box::new(asset_hubs::asset_hub_rococo_genesis_config()), + "asset-hub-rococo" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/asset-hub-rococo.json")[..], + )?), + + // -- Asset Hub Westend + "asset-hub-westend-dev" | "westmint-dev" => + Box::new(asset_hubs::asset_hub_westend_development_config()), + "asset-hub-westend-local" | "westmint-local" => + Box::new(asset_hubs::asset_hub_westend_local_config()), + // the chain spec as used for generating the upgrade genesis values + "asset-hub-westend-genesis" | "westmint-genesis" => + Box::new(asset_hubs::asset_hub_westend_config()), + // the shell-based chain spec as used for syncing + "asset-hub-westend" | "westmint" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/asset-hub-westend.json")[..], + )?), + + // -- Polkadot Collectives + "collectives-polkadot" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/collectives-polkadot.json")[..], + )?), + + // -- Westend Collectives + "collectives-westend-dev" => + Box::new(collectives::collectives_westend_development_config()), + "collectives-westend-local" => + Box::new(collectives::collectives_westend_local_config()), + "collectives-westend" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/collectives-westend.json")[..], + )?), + + // -- Contracts on Rococo + "contracts-rococo-dev" => Box::new(contracts::contracts_rococo_development_config()), + "contracts-rococo-local" => Box::new(contracts::contracts_rococo_local_config()), + "contracts-rococo-genesis" => Box::new(contracts::contracts_rococo_config()), + "contracts-rococo" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/contracts-rococo.json")[..], + )?), + + // -- BridgeHub + bridge_like_id + if bridge_like_id.starts_with(bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) => + bridge_like_id + .parse::() + .expect("invalid value") + .load_config()?, + + // -- Coretime + coretime_like_id + if coretime_like_id.starts_with(coretime::CoretimeRuntimeType::ID_PREFIX) => + coretime_like_id + .parse::() + .expect("invalid value") + .load_config()?, + + // -- Penpal + id if id.starts_with("penpal-rococo") => { + let (_, _, para_id) = extract_parachain_id(&id, &["penpal-rococo-"]); + Box::new(penpal::get_penpal_chain_spec( + para_id.expect("Must specify parachain id"), + "rococo-local", + )) + }, + id if id.starts_with("penpal-westend") => { + let (_, _, para_id) = extract_parachain_id(&id, &["penpal-westend-"]); + Box::new(penpal::get_penpal_chain_spec( + para_id.expect("Must specify parachain id"), + "westend-local", + )) + }, + + // -- Glutton Westend + id if id.starts_with("glutton-westend-dev") => { + let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-dev-"]); + Box::new(glutton::glutton_westend_development_config( + para_id.expect("Must specify parachain id"), + )) + }, + id if id.starts_with("glutton-westend-local") => { + let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-local-"]); + Box::new(glutton::glutton_westend_local_config( + para_id.expect("Must specify parachain id"), + )) + }, + // the chain spec as used for generating the upgrade genesis values + id if id.starts_with("glutton-westend-genesis") => { + let (_, _, para_id) = extract_parachain_id(&id, &["glutton-westend-genesis-"]); + Box::new(glutton::glutton_westend_config( + para_id.expect("Must specify parachain id"), + )) + }, + + // -- People + people_like_id if people_like_id.starts_with(people::PeopleRuntimeType::ID_PREFIX) => + people_like_id + .parse::() + .expect("invalid value") + .load_config()?, + + // -- Fallback (generic chainspec) + "" => { + log::warn!("No ChainSpec.id specified, so using default one, based on rococo-parachain runtime"); + Box::new(rococo_parachain::rococo_parachain_local_config()) + }, + + // -- Loading a specific spec from disk + path => Box::new(GenericChainSpec::from_json_file(path.into())?), + }) + } +} + +/// Helper enum that is used for better distinction of different parachain/runtime configuration +/// (it is based/calculated on ChainSpec's ID attribute) +#[derive(Debug, PartialEq)] +enum LegacyRuntime { + Omni, + Shell, + Seedling, + AssetHubPolkadot, + AssetHub, + Penpal, + ContractsRococo, + Collectives, + Glutton, + BridgeHub(bridge_hubs::BridgeHubRuntimeType), + Coretime(coretime::CoretimeRuntimeType), + People(people::PeopleRuntimeType), +} + +impl LegacyRuntime { + fn from_id(id: &str) -> LegacyRuntime { + let id = id.replace('_', "-"); + + if id.starts_with("shell") { + LegacyRuntime::Shell + } else if id.starts_with("seedling") { + LegacyRuntime::Seedling + } else if id.starts_with("asset-hub-polkadot") | id.starts_with("statemint") { + LegacyRuntime::AssetHubPolkadot + } else if id.starts_with("asset-hub-kusama") | + id.starts_with("statemine") | + id.starts_with("asset-hub-rococo") | + id.starts_with("rockmine") | + id.starts_with("asset-hub-westend") | + id.starts_with("westmint") + { + LegacyRuntime::AssetHub + } else if id.starts_with("penpal") { + LegacyRuntime::Penpal + } else if id.starts_with("contracts-rococo") { + LegacyRuntime::ContractsRococo + } else if id.starts_with("collectives-polkadot") || id.starts_with("collectives-westend") { + LegacyRuntime::Collectives + } else if id.starts_with(bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) { + LegacyRuntime::BridgeHub( + id.parse::().expect("Invalid value"), + ) + } else if id.starts_with(coretime::CoretimeRuntimeType::ID_PREFIX) { + LegacyRuntime::Coretime( + id.parse::().expect("Invalid value"), + ) + } else if id.starts_with("glutton") { + LegacyRuntime::Glutton + } else if id.starts_with(people::PeopleRuntimeType::ID_PREFIX) { + LegacyRuntime::People(id.parse::().expect("Invalid value")) + } else { + log::warn!( + "No specific runtime was recognized for ChainSpec's id: '{}', \ + so Runtime::Omni(Consensus::Aura) will be used", + id + ); + LegacyRuntime::Omni + } + } +} + +#[derive(Debug)] +pub(crate) struct RuntimeResolver; + +impl RuntimeResolverT for RuntimeResolver { + fn runtime(&self, chain_spec: &dyn ChainSpec) -> sc_cli::Result { + let legacy_runtime = LegacyRuntime::from_id(chain_spec.id()); + Ok(match legacy_runtime { + LegacyRuntime::AssetHubPolkadot => + Runtime::Omni(Consensus::Aura(AuraConsensusId::Ed25519)), + LegacyRuntime::AssetHub | + LegacyRuntime::BridgeHub(_) | + LegacyRuntime::Collectives | + LegacyRuntime::Coretime(_) | + LegacyRuntime::People(_) | + LegacyRuntime::ContractsRococo | + LegacyRuntime::Glutton | + LegacyRuntime::Penpal => Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519)), + LegacyRuntime::Shell | LegacyRuntime::Seedling => Runtime::Shell, + LegacyRuntime::Omni => Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519)), + }) + } +} + #[cfg(test)] mod tests { use super::*; + use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup, ChainType, Extension}; + use serde::{Deserialize, Serialize}; + use sp_core::sr25519; + + #[derive( + Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension, Default, + )] + #[serde(deny_unknown_fields)] + pub struct Extensions1 { + pub attribute1: String, + pub attribute2: u32, + } + + #[derive( + Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension, Default, + )] + #[serde(deny_unknown_fields)] + pub struct Extensions2 { + pub attribute_x: String, + pub attribute_y: String, + pub attribute_z: u32, + } + + pub type DummyChainSpec = sc_service::GenericChainSpec; + + pub fn create_default_with_extensions( + id: &str, + extension: E, + ) -> DummyChainSpec { + DummyChainSpec::builder( + rococo_parachain_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!"), + extension, + ) + .with_name("Dummy local testnet") + .with_id(id) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(crate::chain_spec::rococo_parachain::testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![ + get_from_seed::("Alice"), + get_from_seed::("Bob"), + ], + vec![get_account_id_from_seed::("Alice")], + 1000.into(), + )) + .build() + } #[test] - fn can_decode_extension_camel_and_snake_case() { - let camel_case = r#"{"relayChain":"relay","paraId":1}"#; - let snake_case = r#"{"relay_chain":"relay","para_id":1}"#; - let pascal_case = r#"{"RelayChain":"relay","ParaId":1}"#; + fn test_legacy_runtime_for_different_chain_specs() { + let chain_spec = create_default_with_extensions("shell-1", Extensions1::default()); + assert_eq!(LegacyRuntime::Shell, LegacyRuntime::from_id(chain_spec.id())); + + let chain_spec = create_default_with_extensions("shell-2", Extensions2::default()); + assert_eq!(LegacyRuntime::Shell, LegacyRuntime::from_id(chain_spec.id())); + + let chain_spec = create_default_with_extensions("seedling", Extensions2::default()); + assert_eq!(LegacyRuntime::Seedling, LegacyRuntime::from_id(chain_spec.id())); + + let chain_spec = + create_default_with_extensions("penpal-rococo-1000", Extensions2::default()); + assert_eq!(LegacyRuntime::Penpal, LegacyRuntime::from_id(chain_spec.id())); - let camel_case_extension: Extensions = serde_json::from_str(camel_case).unwrap(); - let snake_case_extension: Extensions = serde_json::from_str(snake_case).unwrap(); - let pascal_case_extension: Extensions = serde_json::from_str(pascal_case).unwrap(); + let chain_spec = crate::chain_spec::contracts::contracts_rococo_local_config(); + assert_eq!(LegacyRuntime::ContractsRococo, LegacyRuntime::from_id(chain_spec.id())); - assert_eq!(camel_case_extension, snake_case_extension); - assert_eq!(snake_case_extension, pascal_case_extension); + let chain_spec = crate::chain_spec::rococo_parachain::rococo_parachain_local_config(); + assert_eq!(LegacyRuntime::Omni, LegacyRuntime::from_id(chain_spec.id())); } } diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index cb1cb632d638..d43a5363db6a 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec, - SAFE_XCM_VERSION, +use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, }; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/people.rs b/cumulus/polkadot-parachain/src/chain_spec/people.rs index 6100a15018cb..0e66a50ca88e 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/people.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/people.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::GenericChainSpec; +use crate::common::chain_spec::GenericChainSpec; use cumulus_primitives_core::ParaId; use parachains_common::Balance as PeopleBalance; use sc_chain_spec::ChainSpec; @@ -120,9 +120,9 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup. pub mod rococo { use super::{ParaId, PeopleBalance}; - use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec, - SAFE_XCM_VERSION, + use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, }; use parachains_common::{AccountId, AuraId}; use sc_chain_spec::ChainType; @@ -230,9 +230,9 @@ pub mod rococo { /// Sub-module for Westend setup. pub mod westend { use super::{ParaId, PeopleBalance}; - use crate::chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, GenericChainSpec, - SAFE_XCM_VERSION, + use crate::{ + chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, }; use parachains_common::{AccountId, AuraId}; use sc_chain_spec::ChainType; diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index 0434e5f7be8f..d132f796f261 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -16,7 +16,10 @@ //! ChainSpecs dedicated to Rococo parachain setups (for testing and example purposes) -use crate::chain_spec::{get_from_seed, Extensions, GenericChainSpec, SAFE_XCM_VERSION}; +use crate::{ + chain_spec::{get_from_seed, SAFE_XCM_VERSION}, + common::chain_spec::{Extensions, GenericChainSpec}, +}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::AccountId; diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs index 32d516220545..1e6b15c460b5 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{get_account_id_from_seed, Extensions, GenericChainSpec}; +use crate::{ + chain_spec::get_account_id_from_seed, + common::chain_spec::{Extensions, GenericChainSpec}, +}; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId}; use sc_service::ChainType; diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index e0a9875fb96f..c6c6074cb4a7 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::chain_spec::{Extensions, GenericChainSpec}; +use crate::common::chain_spec::{Extensions, GenericChainSpec}; use cumulus_primitives_core::ParaId; use parachains_common::AuraId; use sc_service::ChainType; diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index a5fe33dffc96..23c31fff6e3f 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::common::NodeExtraArgs; +use crate::common::{ + chain_spec::{Extensions, GenericChainSpec, LoadSpec}, + NodeExtraArgs, +}; use clap::{Command, CommandFactory, FromArgMatches}; +use sc_chain_spec::ChainSpec; use sc_cli::SubstrateCli; -use std::path::PathBuf; +use std::{fmt::Debug, path::PathBuf}; /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] @@ -68,6 +72,9 @@ pub enum Subcommand { after_help = crate::examples(Self::executable_name()) )] pub struct Cli { + #[arg(skip)] + pub(crate) chain_spec_loader: Option>, + #[command(subcommand)] pub subcommand: Option, @@ -111,6 +118,48 @@ impl Cli { } } +impl SubstrateCli for Cli { + fn impl_name() -> String { + Self::executable_name() + } + + fn impl_version() -> String { + env!("SUBSTRATE_CLI_IMPL_VERSION").into() + } + + fn description() -> String { + format!( + "The command-line arguments provided first will be passed to the parachain node, \n\ + and the arguments provided after -- will be passed to the relay chain node. \n\ + \n\ + Example: \n\ + \n\ + {} [parachain-args] -- [relay-chain-args]", + Self::executable_name() + ) + } + + fn author() -> String { + env!("CARGO_PKG_AUTHORS").into() + } + + fn support_url() -> String { + "https://github.com/paritytech/polkadot-sdk/issues/new".into() + } + + fn copyright_start_year() -> i32 { + 2017 + } + + fn load_spec(&self, id: &str) -> std::result::Result, String> { + if let Some(chain_spec_loader) = &self.chain_spec_loader { + return chain_spec_loader.load_spec(id); + } + + Ok(Box::new(GenericChainSpec::from_json_file(id.into())?)) + } +} + #[derive(Debug)] pub struct RelayChainCli { /// The actual relay chain cli object. @@ -123,6 +172,36 @@ pub struct RelayChainCli { pub base_path: Option, } +impl SubstrateCli for RelayChainCli { + fn impl_name() -> String { + Cli::impl_name() + } + + fn impl_version() -> String { + Cli::impl_version() + } + + fn description() -> String { + Cli::description() + } + + fn author() -> String { + Cli::author() + } + + fn support_url() -> String { + Cli::support_url() + } + + fn copyright_start_year() -> i32 { + Cli::copyright_start_year() + } + + fn load_spec(&self, id: &str) -> std::result::Result, String> { + polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) + } +} + impl RelayChainCli { fn polkadot_cmd() -> Command { let help_template = color_print::cformat!( @@ -146,7 +225,7 @@ impl RelayChainCli { let matches = polkadot_cmd.get_matches_from(relay_chain_args); let base = FromArgMatches::from_arg_matches(&matches).unwrap_or_else(|e| e.exit()); - let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); + let extension = Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); let base_path = para_config.base_path.path().join("polkadot"); diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 3df90c889e8e..10d54fb37062 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -17,9 +17,15 @@ #[cfg(feature = "runtime-benchmarks")] use crate::service::Block; use crate::{ - chain_spec::{self, GenericChainSpec}, cli::{Cli, RelayChainCli, Subcommand}, - common::NodeExtraArgs, + common::{ + chain_spec::{Extensions, LoadSpec}, + runtime::{ + AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT, + RuntimeResolver, + }, + NodeExtraArgs, + }, fake_runtime_api::{ asset_hub_polkadot_aura::RuntimeApi as AssetHubPolkadotRuntimeApi, aura::RuntimeApi as AuraRuntimeApi, @@ -40,378 +46,39 @@ use sc_service::config::{BasePath, PrometheusConfig}; use sp_runtime::traits::AccountIdConversion; #[cfg(feature = "runtime-benchmarks")] use sp_runtime::traits::HashingFor; -use std::{net::SocketAddr, path::PathBuf}; - -/// The choice of consensus for the parachain omni-node. -#[derive(PartialEq, Eq, Debug, Default)] -pub enum Consensus { - /// Aura consensus. - #[default] - Aura, - /// Use the relay chain consensus. - // TODO: atm this is just a demonstration, not really reach-able. We can add it to the CLI, - // env, or the chain spec. Or, just don't, and when we properly refactor this mess we will - // re-introduce it. - #[allow(unused)] - Relay, -} - -/// Helper enum that is used for better distinction of different parachain/runtime configuration -/// (it is based/calculated on ChainSpec's ID attribute) -#[derive(Debug, PartialEq)] -enum Runtime { - /// None of the system-chain runtimes, rather the node will act agnostic to the runtime ie. be - /// an omni-node, and simply run a node with the given consensus algorithm. - Omni(Consensus), - Shell, - Seedling, - AssetHubPolkadot, - AssetHub, - Penpal(ParaId), - ContractsRococo, - Collectives, - Glutton, - BridgeHub(chain_spec::bridge_hubs::BridgeHubRuntimeType), - Coretime(chain_spec::coretime::CoretimeRuntimeType), - People(chain_spec::people::PeopleRuntimeType), -} - -trait RuntimeResolver { - fn runtime(&self) -> Result; -} - -impl RuntimeResolver for dyn ChainSpec { - fn runtime(&self) -> Result { - Ok(runtime(self.id())) - } -} - -/// Implementation, that can resolve [`Runtime`] from any json configuration file -impl RuntimeResolver for PathBuf { - fn runtime(&self) -> Result { - #[derive(Debug, serde::Deserialize)] - struct EmptyChainSpecWithId { - id: String, - } - - let file = std::fs::File::open(self)?; - let reader = std::io::BufReader::new(file); - let chain_spec: EmptyChainSpecWithId = - serde_json::from_reader(reader).map_err(|e| sc_cli::Error::Application(Box::new(e)))?; - - Ok(runtime(&chain_spec.id)) - } -} - -fn runtime(id: &str) -> Runtime { - let id = id.replace('_', "-"); - let (_, id, para_id) = extract_parachain_id(&id); - - if id.starts_with("shell") { - Runtime::Shell - } else if id.starts_with("seedling") { - Runtime::Seedling - } else if id.starts_with("asset-hub-polkadot") | id.starts_with("statemint") { - Runtime::AssetHubPolkadot - } else if id.starts_with("asset-hub-kusama") | - id.starts_with("statemine") | - id.starts_with("asset-hub-rococo") | - id.starts_with("rockmine") | - id.starts_with("asset-hub-westend") | - id.starts_with("westmint") - { - Runtime::AssetHub - } else if id.starts_with("penpal") { - Runtime::Penpal(para_id.unwrap_or(ParaId::new(0))) - } else if id.starts_with("contracts-rococo") { - Runtime::ContractsRococo - } else if id.starts_with("collectives-polkadot") || id.starts_with("collectives-westend") { - Runtime::Collectives - } else if id.starts_with(chain_spec::bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) { - Runtime::BridgeHub( - id.parse::() - .expect("Invalid value"), - ) - } else if id.starts_with(chain_spec::coretime::CoretimeRuntimeType::ID_PREFIX) { - Runtime::Coretime( - id.parse::().expect("Invalid value"), - ) - } else if id.starts_with("glutton") { - Runtime::Glutton - } else if id.starts_with(chain_spec::people::PeopleRuntimeType::ID_PREFIX) { - Runtime::People(id.parse::().expect("Invalid value")) - } else { - log::warn!( - "No specific runtime was recognized for ChainSpec's id: '{}', \ - so Runtime::Omni(Consensus::Aura) will be used", - id - ); - Runtime::Omni(Consensus::Aura) - } -} - -fn load_spec(id: &str) -> std::result::Result, String> { - let (id, _, para_id) = extract_parachain_id(id); - Ok(match id { - // - Default-like - "staging" => - Box::new(chain_spec::rococo_parachain::staging_rococo_parachain_local_config()), - "tick" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/tick.json")[..], - )?), - "trick" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/trick.json")[..], - )?), - "track" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/track.json")[..], - )?), - - // -- Starters - "shell" => Box::new(chain_spec::shell::get_shell_chain_spec()), - "seedling" => Box::new(chain_spec::seedling::get_seedling_chain_spec()), - - // -- Asset Hub Polkadot - "asset-hub-polkadot" | "statemint" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/asset-hub-polkadot.json")[..], - )?), - - // -- Asset Hub Kusama - "asset-hub-kusama" | "statemine" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/asset-hub-kusama.json")[..], - )?), - - // -- Asset Hub Rococo - "asset-hub-rococo-dev" => - Box::new(chain_spec::asset_hubs::asset_hub_rococo_development_config()), - "asset-hub-rococo-local" => - Box::new(chain_spec::asset_hubs::asset_hub_rococo_local_config()), - // the chain spec as used for generating the upgrade genesis values - "asset-hub-rococo-genesis" => - Box::new(chain_spec::asset_hubs::asset_hub_rococo_genesis_config()), - "asset-hub-rococo" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/asset-hub-rococo.json")[..], - )?), - - // -- Asset Hub Westend - "asset-hub-westend-dev" | "westmint-dev" => - Box::new(chain_spec::asset_hubs::asset_hub_westend_development_config()), - "asset-hub-westend-local" | "westmint-local" => - Box::new(chain_spec::asset_hubs::asset_hub_westend_local_config()), - // the chain spec as used for generating the upgrade genesis values - "asset-hub-westend-genesis" | "westmint-genesis" => - Box::new(chain_spec::asset_hubs::asset_hub_westend_config()), - // the shell-based chain spec as used for syncing - "asset-hub-westend" | "westmint" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/asset-hub-westend.json")[..], - )?), - - // -- Polkadot Collectives - "collectives-polkadot" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/collectives-polkadot.json")[..], - )?), - - // -- Westend Collectives - "collectives-westend-dev" => - Box::new(chain_spec::collectives::collectives_westend_development_config()), - "collectives-westend-local" => - Box::new(chain_spec::collectives::collectives_westend_local_config()), - "collectives-westend" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/collectives-westend.json")[..], - )?), - - // -- Contracts on Rococo - "contracts-rococo-dev" => - Box::new(chain_spec::contracts::contracts_rococo_development_config()), - "contracts-rococo-local" => - Box::new(chain_spec::contracts::contracts_rococo_local_config()), - "contracts-rococo-genesis" => Box::new(chain_spec::contracts::contracts_rococo_config()), - "contracts-rococo" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../chain-specs/contracts-rococo.json")[..], - )?), - - // -- BridgeHub - bridge_like_id - if bridge_like_id - .starts_with(chain_spec::bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) => - bridge_like_id - .parse::() - .expect("invalid value") - .load_config()?, - - // -- Coretime - coretime_like_id - if coretime_like_id - .starts_with(chain_spec::coretime::CoretimeRuntimeType::ID_PREFIX) => - coretime_like_id - .parse::() - .expect("invalid value") - .load_config()?, - - // -- Penpal - "penpal-rococo" => Box::new(chain_spec::penpal::get_penpal_chain_spec( - para_id.expect("Must specify parachain id"), - "rococo-local", - )), - "penpal-westend" => Box::new(chain_spec::penpal::get_penpal_chain_spec( - para_id.expect("Must specify parachain id"), - "westend-local", - )), - - // -- Glutton Westend - "glutton-westend-dev" => Box::new(chain_spec::glutton::glutton_westend_development_config( - para_id.expect("Must specify parachain id"), - )), - "glutton-westend-local" => Box::new(chain_spec::glutton::glutton_westend_local_config( - para_id.expect("Must specify parachain id"), - )), - // the chain spec as used for generating the upgrade genesis values - "glutton-westend-genesis" => Box::new(chain_spec::glutton::glutton_westend_config( - para_id.expect("Must specify parachain id"), - )), - - // -- People - people_like_id - if people_like_id.starts_with(chain_spec::people::PeopleRuntimeType::ID_PREFIX) => - people_like_id - .parse::() - .expect("invalid value") - .load_config()?, - - // -- Fallback (generic chainspec) - "" => { - log::warn!("No ChainSpec.id specified, so using default one, based on rococo-parachain runtime"); - Box::new(chain_spec::rococo_parachain::rococo_parachain_local_config()) - }, - - // -- Loading a specific spec from disk - path => Box::new(GenericChainSpec::from_json_file(path.into())?), - }) -} - -/// Extracts the normalized chain id and parachain id from the input chain id. -/// (H/T to Phala for the idea) -/// E.g. "penpal-kusama-2004" yields ("penpal-kusama", Some(2004)) -fn extract_parachain_id(id: &str) -> (&str, &str, Option) { - let para_prefixes = [ - // Penpal - "penpal-rococo-", - "penpal-westend-", - "penpal-kusama-", - "penpal-polkadot-", - // Glutton Kusama - "glutton-kusama-dev-", - "glutton-kusama-local-", - "glutton-kusama-genesis-", - // Glutton Westend - "glutton-westend-dev-", - "glutton-westend-local-", - "glutton-westend-genesis-", - ]; - - for para_prefix in para_prefixes { - if let Some(suffix) = id.strip_prefix(para_prefix) { - let para_id: u32 = suffix.parse().expect("Invalid parachain-id suffix"); - return (&id[..para_prefix.len() - 1], id, Some(para_id.into())) - } - } - - (id, id, None) -} - -impl SubstrateCli for Cli { - fn impl_name() -> String { - Self::executable_name() - } - - fn impl_version() -> String { - env!("SUBSTRATE_CLI_IMPL_VERSION").into() - } - - fn description() -> String { - format!( - "The command-line arguments provided first will be passed to the parachain node, \n\ - and the arguments provided after -- will be passed to the relay chain node. \n\ - \n\ - Example: \n\ - \n\ - {} [parachain-args] -- [relay-chain-args]", - Self::executable_name() - ) - } - - fn author() -> String { - env!("CARGO_PKG_AUTHORS").into() - } - - fn support_url() -> String { - "https://github.com/paritytech/polkadot-sdk/issues/new".into() - } - - fn copyright_start_year() -> i32 { - 2017 - } +use std::net::SocketAddr; - fn load_spec(&self, id: &str) -> std::result::Result, String> { - load_spec(id) - } -} - -impl SubstrateCli for RelayChainCli { - fn impl_name() -> String { - Cli::impl_name() - } - - fn impl_version() -> String { - Cli::impl_version() - } - - fn description() -> String { - Cli::description() - } - - fn author() -> String { - Cli::author() - } - - fn support_url() -> String { - Cli::support_url() - } - - fn copyright_start_year() -> i32 { - Cli::copyright_start_year() - } - - fn load_spec(&self, id: &str) -> std::result::Result, String> { - polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) - } +#[derive(Debug, Default)] +pub struct CommandConfig { + pub chain_spec_loader: Option>, + pub runtime_resolver: Option>, } fn new_node_spec( config: &sc_service::Configuration, + maybe_runtime_resolver: Option<&Box>, extra_args: &NodeExtraArgs, ) -> std::result::Result, sc_cli::Error> { - Ok(match config.chain_spec.runtime()? { - Runtime::AssetHubPolkadot => - new_aura_node_spec::(extra_args), - Runtime::AssetHub | - Runtime::BridgeHub(_) | - Runtime::Collectives | - Runtime::Coretime(_) | - Runtime::People(_) | - Runtime::ContractsRococo | - Runtime::Glutton | - Runtime::Penpal(_) => new_aura_node_spec::(extra_args), - Runtime::Shell | Runtime::Seedling => Box::new(ShellNode), + let runtime_resolver = match maybe_runtime_resolver { + Some(runtime_resolver) => runtime_resolver, + None => return Ok(new_aura_node_spec::(extra_args)), + }; + + Ok(match runtime_resolver.runtime(config.chain_spec.as_ref())? { + Runtime::Shell => Box::new(ShellNode), Runtime::Omni(consensus) => match consensus { - Consensus::Aura => new_aura_node_spec::(extra_args), - Consensus::Relay => Box::new(ShellNode), + Consensus::Aura(AuraConsensusId::Sr25519) => + new_aura_node_spec::(extra_args), + Consensus::Aura(AuraConsensusId::Ed25519) => + new_aura_node_spec::(extra_args), }, }) } /// Parse command line arguments into service configuration. -pub fn run() -> Result<()> { - let cli = Cli::from_args(); +pub fn run(cmd_config: CommandConfig) -> Result<()> { + let mut cli = Cli::from_args(); + cli.chain_spec_loader = cmd_config.chain_spec_loader; match &cli.subcommand { Some(Subcommand::BuildSpec(cmd)) => { @@ -421,35 +88,55 @@ pub fn run() -> Result<()> { Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.prepare_check_block_cmd(config, cmd) }) }, Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.prepare_export_blocks_cmd(config, cmd) }) }, Some(Subcommand::ExportState(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.prepare_export_state_cmd(config, cmd) }) }, Some(Subcommand::ImportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.prepare_import_blocks_cmd(config, cmd) }) }, Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.prepare_revert_cmd(config, cmd) }) }, @@ -471,7 +158,11 @@ pub fn run() -> Result<()> { Some(Subcommand::ExportGenesisHead(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.run_export_genesis_head_cmd(config, cmd) }) }, @@ -494,12 +185,20 @@ pub fn run() -> Result<()> { )) }), BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.run_benchmark_block_cmd(config, cmd) }), #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { - let node = new_node_spec(&config, &cli.node_extra_args())?; + let node = new_node_spec( + &config, + cmd_config.runtime_resolver.as_ref(), + &cli.node_extra_args(), + )?; node.run_benchmark_storage_cmd(config, cmd) }), BenchmarkCmd::Machine(cmd) => @@ -542,7 +241,7 @@ pub fn run() -> Result<()> { old_path.display(), new_path.display() ) - .into()) + .into()); } if old_path.exists() { @@ -564,7 +263,7 @@ pub fn run() -> Result<()> { })) .flatten(); - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) + let para_id = Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) .ok_or("Could not find parachain extension in chain-spec.")?; @@ -586,6 +285,7 @@ pub fn run() -> Result<()> { start_node( config, + cmd_config.runtime_resolver.as_ref(), polkadot_config, collator_options, id, @@ -601,13 +301,14 @@ pub fn run() -> Result<()> { #[sc_tracing::logging::prefix_logs_with("Parachain")] async fn start_node( config: sc_service::Configuration, + runtime_resolver: Option<&Box>, polkadot_config: sc_service::Configuration, collator_options: cumulus_client_cli::CollatorOptions, id: ParaId, extra_args: NodeExtraArgs, hwbench: Option, ) -> Result { - let node_spec = new_node_spec(&config, &extra_args)?; + let node_spec = new_node_spec(&config, runtime_resolver, &extra_args)?; node_spec .start_node(config, polkadot_config, collator_options, id, hwbench, extra_args) .await @@ -738,119 +439,3 @@ impl CliConfiguration for RelayChainCli { self.base.base.node_name() } } - -#[cfg(test)] -mod tests { - use crate::{ - chain_spec::{get_account_id_from_seed, get_from_seed}, - command::{Consensus, Runtime, RuntimeResolver}, - }; - use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup, ChainType, Extension}; - use serde::{Deserialize, Serialize}; - use sp_core::sr25519; - use std::path::PathBuf; - use tempfile::TempDir; - - #[derive( - Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension, Default, - )] - #[serde(deny_unknown_fields)] - pub struct Extensions1 { - pub attribute1: String, - pub attribute2: u32, - } - - #[derive( - Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension, Default, - )] - #[serde(deny_unknown_fields)] - pub struct Extensions2 { - pub attribute_x: String, - pub attribute_y: String, - pub attribute_z: u32, - } - - fn store_configuration(dir: &TempDir, spec: &dyn ChainSpec) -> PathBuf { - let raw_output = true; - let json = sc_service::chain_ops::build_spec(spec, raw_output) - .expect("Failed to build json string"); - let mut cfg_file_path = dir.path().to_path_buf(); - cfg_file_path.push(spec.id()); - cfg_file_path.set_extension("json"); - std::fs::write(&cfg_file_path, json).expect("Failed to write to json file"); - cfg_file_path - } - - pub type DummyChainSpec = sc_service::GenericChainSpec; - - pub fn create_default_with_extensions( - id: &str, - extension: E, - ) -> DummyChainSpec { - DummyChainSpec::builder( - rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - extension, - ) - .with_name("Dummy local testnet") - .with_id(id) - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(crate::chain_spec::rococo_parachain::testnet_genesis( - get_account_id_from_seed::("Alice"), - vec![ - get_from_seed::("Alice"), - get_from_seed::("Bob"), - ], - vec![get_account_id_from_seed::("Alice")], - 1000.into(), - )) - .build() - } - - #[test] - fn test_resolve_runtime_for_different_configuration_files() { - let temp_dir = tempfile::tempdir().expect("Failed to access tempdir"); - - let path = store_configuration( - &temp_dir, - &create_default_with_extensions("shell-1", Extensions1::default()), - ); - assert_eq!(Runtime::Shell, path.runtime().unwrap()); - - let path = store_configuration( - &temp_dir, - &create_default_with_extensions("shell-2", Extensions2::default()), - ); - assert_eq!(Runtime::Shell, path.runtime().unwrap()); - - let path = store_configuration( - &temp_dir, - &create_default_with_extensions("seedling", Extensions2::default()), - ); - assert_eq!(Runtime::Seedling, path.runtime().unwrap()); - - let path = store_configuration( - &temp_dir, - &create_default_with_extensions("penpal-rococo-1000", Extensions2::default()), - ); - assert_eq!(Runtime::Penpal(1000.into()), path.runtime().unwrap()); - - let path = store_configuration( - &temp_dir, - &create_default_with_extensions("penpal-polkadot-2000", Extensions2::default()), - ); - assert_eq!(Runtime::Penpal(2000.into()), path.runtime().unwrap()); - - let path = store_configuration( - &temp_dir, - &crate::chain_spec::contracts::contracts_rococo_local_config(), - ); - assert_eq!(Runtime::ContractsRococo, path.runtime().unwrap()); - - let path = store_configuration( - &temp_dir, - &crate::chain_spec::rococo_parachain::rococo_parachain_local_config(), - ); - assert_eq!(Runtime::Omni(Consensus::Aura), path.runtime().unwrap()); - } -} diff --git a/cumulus/polkadot-parachain/src/common/chain_spec.rs b/cumulus/polkadot-parachain/src/common/chain_spec.rs new file mode 100644 index 000000000000..7f9bfbb4f55f --- /dev/null +++ b/cumulus/polkadot-parachain/src/common/chain_spec.rs @@ -0,0 +1,63 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use frame_support::{Deserialize, Serialize}; +use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup}; +use std::fmt::Debug; + +pub trait LoadSpec: Debug { + fn load_spec(&self, id: &str) -> Result, String>; +} + +/// Generic extensions for Parachain ChainSpecs. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +pub struct Extensions { + /// The relay chain of the Parachain. + #[serde(alias = "relayChain", alias = "RelayChain")] + pub relay_chain: String, + /// The id of the Parachain. + #[serde(alias = "paraId", alias = "ParaId")] + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + +/// Generic chain spec for all polkadot-parachain runtimes +pub type GenericChainSpec = sc_service::GenericChainSpec; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn can_decode_extension_camel_and_snake_case() { + let camel_case = r#"{"relayChain":"relay","paraId":1}"#; + let snake_case = r#"{"relay_chain":"relay","para_id":1}"#; + let pascal_case = r#"{"RelayChain":"relay","ParaId":1}"#; + + let camel_case_extension: Extensions = serde_json::from_str(camel_case).unwrap(); + let snake_case_extension: Extensions = serde_json::from_str(snake_case).unwrap(); + let pascal_case_extension: Extensions = serde_json::from_str(pascal_case).unwrap(); + + assert_eq!(camel_case_extension, snake_case_extension); + assert_eq!(snake_case_extension, pascal_case_extension); + } +} diff --git a/cumulus/polkadot-parachain/src/common/mod.rs b/cumulus/polkadot-parachain/src/common/mod.rs index d7718931b872..fd2bea700465 100644 --- a/cumulus/polkadot-parachain/src/common/mod.rs +++ b/cumulus/polkadot-parachain/src/common/mod.rs @@ -19,6 +19,8 @@ #![warn(missing_docs)] pub mod aura; +pub mod chain_spec; +pub mod runtime; use cumulus_primitives_core::CollectCollationInfo; use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata}; diff --git a/cumulus/polkadot-parachain/src/common/runtime.rs b/cumulus/polkadot-parachain/src/common/runtime.rs new file mode 100644 index 000000000000..e9a8f06a7772 --- /dev/null +++ b/cumulus/polkadot-parachain/src/common/runtime.rs @@ -0,0 +1,44 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use sc_chain_spec::ChainSpec; +use std::fmt::Debug; + +#[derive(Debug, PartialEq)] +pub enum AuraConsensusId { + Ed25519, + Sr25519, +} + +/// The choice of consensus for the parachain omni-node. +#[derive(Debug, PartialEq)] +pub enum Consensus { + /// Aura consensus. + Aura(AuraConsensusId), +} + +/// Helper enum listing the supported Runtime types +#[derive(Debug, PartialEq)] +pub enum Runtime { + /// None of the system-chain runtimes, rather the node will act agnostic to the runtime ie. be + /// an omni-node, and simply run a node with the given consensus algorithm. + Omni(Consensus), + Shell, +} + +pub trait RuntimeResolver: Debug { + fn runtime(&self, chain_spec: &dyn ChainSpec) -> sc_cli::Result; +} diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index 84e41fc347d9..f6bfabc91a2e 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -19,6 +19,8 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] +use crate::command::CommandConfig; + pub(crate) fn examples(executable_name: String) -> String { color_print::cformat!( r#"Examples: @@ -52,5 +54,10 @@ mod service; fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; - Ok(command::run()?) + + let config = CommandConfig { + chain_spec_loader: Some(Box::new(chain_spec::ChainSpecLoader)), + runtime_resolver: Some(Box::new(chain_spec::RuntimeResolver)), + }; + Ok(command::run(config)?) } From 650f007d4167347342f0f33b88b1501acc91ea99 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 8 Aug 2024 11:45:23 +0300 Subject: [PATCH 02/14] Separate lib from bin --- .gitlab/pipeline/build.yml | 8 +- Cargo.lock | 1 + Cargo.toml | 1 + bridges/testing/README.md | 13 +- cumulus/README.md | 26 +++- .../parachains/runtimes/bridge-hubs/README.md | 67 +++++++---- cumulus/polkadot-parachain/Cargo.toml | 113 +++++++++++------- .../src/chain_spec/asset_hubs.rs | 6 +- .../src/chain_spec/bridge_hubs.rs | 18 +-- .../src/chain_spec/collectives.rs | 6 +- .../src/chain_spec/contracts.rs | 6 +- .../src/chain_spec/coretime.rs | 16 +-- .../src/chain_spec/glutton.rs | 6 +- .../polkadot-parachain/src/chain_spec/mod.rs | 8 +- .../src/chain_spec/penpal.rs | 6 +- .../src/chain_spec/people.rs | 14 +-- .../src/chain_spec/rococo_parachain.rs | 6 +- .../src/chain_spec/seedling.rs | 6 +- .../src/chain_spec/shell.rs | 2 +- cumulus/polkadot-parachain/src/cli.rs | 25 +++- .../src/common/chain_spec.rs | 8 +- cumulus/polkadot-parachain/src/common/mod.rs | 4 +- .../polkadot-parachain/src/common/runtime.rs | 6 + cumulus/polkadot-parachain/src/lib.rs | 28 +++++ cumulus/polkadot-parachain/src/main.rs | 35 +----- .../polkadot-parachain_builder.Dockerfile | 2 +- .../test-parachain-collator.Dockerfile | 2 +- docs/contributor/container.md | 2 +- scripts/lib/bench-all-cumulus.sh | 2 +- umbrella/Cargo.toml | 9 +- umbrella/src/lib.rs | 4 + 31 files changed, 269 insertions(+), 187 deletions(-) create mode 100644 cumulus/polkadot-parachain/src/lib.rs diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index 8658e92efc8f..af1a0e632880 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -171,7 +171,7 @@ build-linux-stable-cumulus: RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" script: - echo "___Building a binary, please refrain from using it in production since it goes with the debug assertions.___" - - time cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain + - time cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary - echo "___Packing the artifacts___" - mkdir -p ./artifacts - mv ./target/release/polkadot-parachain ./artifacts/. @@ -288,7 +288,7 @@ build-short-benchmark-cumulus: - .run-immediately - .collect-artifacts script: - - cargo build --profile release --locked --features=runtime-benchmarks,on-chain-release-build -p polkadot-parachain-bin --bin polkadot-parachain --workspace + - cargo build --profile release --locked --features=binary,runtime-benchmarks,on-chain-release-build -p polkadot-parachain-bin --bin polkadot-parachain --workspace - mkdir -p artifacts - target/release/polkadot-parachain --version - cp ./target/release/polkadot-parachain ./artifacts/ @@ -313,7 +313,7 @@ build-linux-substrate: # tldr: we need to checkout the branch HEAD explicitly because of our dynamic versioning approach while building the substrate binary # see https://github.com/paritytech/ci_cd/issues/682#issuecomment-1340953589 - git checkout -B "$CI_COMMIT_REF_NAME" "$CI_COMMIT_SHA" - - !reference [.forklift-cache, before_script] + - !reference [ .forklift-cache, before_script ] script: - time WASM_BUILD_NO_COLOR=1 cargo build --locked --release -p staging-node-cli - mv $CARGO_TARGET_DIR/release/substrate-node ./artifacts/substrate/substrate @@ -353,7 +353,7 @@ build-runtimes-polkavm: CARGO_TARGET_DIR: "$CI_PROJECT_DIR/target" before_script: - mkdir -p ./artifacts/subkey - - !reference [.forklift-cache, before_script] + - !reference [ .forklift-cache, before_script ] script: - cd ./substrate/bin/utils/subkey - time SKIP_WASM_BUILD=1 cargo build --locked --release diff --git a/Cargo.lock b/Cargo.lock index 54a01f12f35c..d7dd0c85b87d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14387,6 +14387,7 @@ dependencies = [ "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-overseer", + "polkadot-parachain-bin", "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-rpc", diff --git a/Cargo.toml b/Cargo.toml index 7ae7c3bd1811..92941d8ee0a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -536,6 +536,7 @@ members = [ ] default-members = [ + "cumulus/polkadot-parachain", "polkadot", "substrate/bin/node/cli", ] diff --git a/bridges/testing/README.md b/bridges/testing/README.md index bd467a410d01..d2b461fa2ed4 100644 --- a/bridges/testing/README.md +++ b/bridges/testing/README.md @@ -10,21 +10,22 @@ To start those tests, you need to: - download latest [zombienet release](https://github.com/paritytech/zombienet/releases); - build Polkadot binary by running `cargo build -p polkadot --release --features fast-runtime` command in the -[`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; + [`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; -- build Polkadot Parachain binary by running `cargo build -p polkadot-parachain-bin --release` command in the -[`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; +- build Polkadot Parachain binary by running + `cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --features binary` + command in the [`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; - ensure that you have [`node`](https://nodejs.org/en) installed. Additionally, we'll need globally installed -`polkadot/api-cli` package (use `npm install -g @polkadot/api-cli@beta` to install it); + `polkadot/api-cli` package (use `npm install -g @polkadot/api-cli@beta` to install it); - build Substrate relay by running `cargo build -p substrate-relay --release` command in the -[`parity-bridges-common`](https://github.com/paritytech/parity-bridges-common) repository clone. + [`parity-bridges-common`](https://github.com/paritytech/parity-bridges-common) repository clone. - copy fresh `substrate-relay` binary, built in previous point, to the `~/local_bridge_testing/bin/substrate-relay`; - change the `POLKADOT_SDK_PATH` and `ZOMBIENET_BINARY_PATH` (and ensure that the nearby variables -have correct values) in the `./run-tests.sh`. + have correct values) in the `./run-tests.sh`. After that, you could run tests with the `./run-tests.sh` command. Hopefully, it'll show the "All tests have completed successfully" message in the end. Otherwise, it'll print paths to zombienet diff --git a/cumulus/README.md b/cumulus/README.md index 7e145ad7b4ab..25fea88ecad1 100644 --- a/cumulus/README.md +++ b/cumulus/README.md @@ -4,7 +4,8 @@ This repository contains both the Cumulus SDK and also specific chains implemented on top of this SDK. -If you only want to run a **Polkadot Parachain Node**, check out our [container section](./docs/contributor/container.md). +If you only want to run a **Polkadot Parachain Node**, check out +our [container section](./docs/contributor/container.md). ## Cumulus SDK @@ -22,7 +23,8 @@ Cumulus clouds are shaped sort of like dots; together they form a system that is ### Consensus -[`parachain-consensus`](https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/client/consensus/common/src/parachain_consensus.rs) +[ +`parachain-consensus`](https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/client/consensus/common/src/parachain_consensus.rs) is a [consensus engine](https://docs.substrate.io/v3/advanced/consensus) for Substrate that follows a Polkadot [relay chain](https://wiki.polkadot.network/docs/en/learn-architecture#relay-chain). This will run a Polkadot node internally, and dictate to the client and synchronization algorithms which chain to follow, @@ -37,13 +39,16 @@ You may run `polkadot-parachain` locally after building it or using one of the c [here](./docs/contributor/container.md). ### Relay Chain Interaction + To operate a parachain node, a connection to the corresponding relay chain is necessary. This can be achieved in one of three ways: + 1. Run a full relay chain node within the parachain node (default) 2. Connect to an external relay chain node via WebSocket RPC 3. Run a light client for the relay chain #### In-process Relay Chain Node + If an external relay chain node is not specified (default behavior), then a full relay chain node is spawned within the same process. @@ -51,6 +56,7 @@ This node has all of the typical components of a regular Polkadot node and will to work. ##### Example command + ```bash polkadot-parachain \ --chain parachain-chainspec.json \ @@ -60,6 +66,7 @@ polkadot-parachain \ ``` #### External Relay Chain Node + An external relay chain node is connected via WebsSocket RPC by using the `--relay-chain-rpc-urls` command line argument. This option accepts one or more space-separated WebSocket URLs to a full relay chain node. By default, only the first URL will be used, with the rest as a backup in case the connection to the first node is lost. @@ -85,6 +92,7 @@ polkadot-parachain \ ``` #### Relay Chain Light Client + An internal relay chain light client provides a fast and lightweight approach for connecting to the relay chain network. It provides relay chain notifications and facilitates runtime calls. @@ -95,8 +103,8 @@ relay chain arguments. node in-process. Even though they lack the majority of normal Polkadot subsystems, they will still need to connect directly to the relay chain network. - ##### Example command + ```bash polkadot-parachain \ --chain parachain-chainspec.json \ @@ -107,6 +115,7 @@ polkadot-parachain \ ``` ## Installation and Setup + Before building Cumulus SDK based nodes / runtimes prepare your environment by following Substrate [installation instructions](https://docs.substrate.io/main-docs/install/). @@ -114,19 +123,24 @@ To launch a local network, you can use [zombienet](https://github.com/paritytech experimentation or follow the [manual setup](#manual-setup). ### Zombienet + We use Zombienet to spin up networks for integration tests and local networks. Follow [these installation steps](https://github.com/paritytech/zombienet#requirements-by-provider) to set it up on your machine. A simple network specification with two relay chain nodes and one collator is located at [zombienet/examples/small_network.toml](zombienet/examples/small_network.toml). #### Which provider should I use? + Zombienet offers multiple providers to run networks. Choose the one that best fits your needs: + - **Podman:** Choose this if you want to spin up a network quick and easy. - **Native:** Choose this if you want to develop and deploy your changes. Requires compilation of the binaries. - **Kubernetes:** Choose this for advanced use-cases or running on cloud-infrastructure. #### How to run + To run the example network, use the following commands: + ```bash # Podman provider zombienet --provider podman spawn ./zombienet/examples/small_network.toml @@ -136,6 +150,7 @@ zombienet --provider native spawn ./zombienet/examples/small_network.toml ``` ### Manual Setup + #### Launch the Relay Chain ```bash @@ -159,7 +174,7 @@ cargo build --release -p polkadot ```bash # Compile -cargo build --release -p polkadot-parachain-bin +cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --features binary # Export genesis state ./target/release/polkadot-parachain export-genesis-state > genesis-state @@ -184,7 +199,6 @@ cargo build --release -p polkadot-parachain-bin ![image](https://user-images.githubusercontent.com/2915325/99548884-1be13580-2987-11eb-9a8b-20be658d34f9.png) - ## Asset Hub 🪙 This repository also contains the Asset Hub runtimes. Asset Hub is a system parachain providing an asset store for the @@ -216,6 +230,7 @@ See [the `contracts-rococo` readme](parachains/runtimes/contracts/contracts-roco See [the `bridge-hubs` readme](parachains/runtimes/bridge-hubs/README.md) for details. ## Rococo 👑 + [Rococo](https://polkadot.js.org/apps/?rpc=wss://rococo-rpc.polkadot.io) is becoming a [Community Parachain Testbed](https://polkadot.network/blog/rococo-revamp-becoming-a-community-parachain-testbed/) for parachain teams in the Polkadot ecosystem. It supports multiple parachains with the differentiation of long-term connections and recurring @@ -231,7 +246,6 @@ the relay chain for a parachain. To run a Rococo collator you will need to compile the following binary: - ```bash cargo build --release --locked --bin polkadot-parachain ``` diff --git a/cumulus/parachains/runtimes/bridge-hubs/README.md b/cumulus/parachains/runtimes/bridge-hubs/README.md index a9f1f98d142d..93639d7af348 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/README.md +++ b/cumulus/parachains/runtimes/bridge-hubs/README.md @@ -1,27 +1,28 @@ - [Bridge-hub Parachains](#bridge-hub-parachains) - - [Requirements for local run/testing](#requirements-for-local-runtesting) - - [How to test local Rococo <-> Westend bridge](#how-to-test-local-rococo---westend-bridge) - - [Run Rococo/Westend chains with zombienet](#run-rococowestend-chains-with-zombienet) - - [Init bridge and run relayer between BridgeHubRococo and - BridgeHubWestend](#init-bridge-and-run-relayer-between-bridgehubrococo-and-bridgehubwestend) - - [Initialize configuration for transfer asset over bridge - (ROCs/WNDs)](#initialize-configuration-for-transfer-asset-over-bridge-rocswnds) - - [Send messages - transfer asset over bridge (ROCs/WNDs)](#send-messages---transfer-asset-over-bridge-rocswnds) - - [Claim relayer's rewards on BridgeHubRococo and - BridgeHubWestend](#claim-relayers-rewards-on-bridgehubrococo-and-bridgehubwestend) - - [How to test local BridgeHubKusama/BridgeHubPolkadot](#how-to-test-local-bridgehubkusamabridgehubpolkadot) + - [Requirements for local run/testing](#requirements-for-local-runtesting) + - [How to test local Rococo <-> Westend bridge](#how-to-test-local-rococo---westend-bridge) + - [Run Rococo/Westend chains with zombienet](#run-rococowestend-chains-with-zombienet) + - [Init bridge and run relayer between BridgeHubRococo and + BridgeHubWestend](#init-bridge-and-run-relayer-between-bridgehubrococo-and-bridgehubwestend) + - [Initialize configuration for transfer asset over bridge + (ROCs/WNDs)](#initialize-configuration-for-transfer-asset-over-bridge-rocswnds) + - [Send messages - transfer asset over bridge (ROCs/WNDs)](#send-messages---transfer-asset-over-bridge-rocswnds) + - [Claim relayer's rewards on BridgeHubRococo and + BridgeHubWestend](#claim-relayers-rewards-on-bridgehubrococo-and-bridgehubwestend) + - [How to test local BridgeHubKusama/BridgeHubPolkadot](#how-to-test-local-bridgehubkusamabridgehubpolkadot) # Bridge-hub Parachains _BridgeHub(s)_ are **_system parachains_** that will house trustless bridges from the local ecosystem to others. The current trustless bridges planned for the BridgeHub(s) are: + - `BridgeHubPolkadot` system parachain: - 1. Polkadot <-> Kusama bridge - 2. Polkadot <-> Ethereum bridge (Snowbridge) + 1. Polkadot <-> Kusama bridge + 2. Polkadot <-> Ethereum bridge (Snowbridge) - `BridgeHubKusama` system parachain: - 1. Kusama <-> Polkadot bridge - 2. Kusama <-> Ethereum bridge The high-level - responsibilities of each bridge living on BridgeHub: + 1. Kusama <-> Polkadot bridge + 2. Kusama <-> Ethereum bridge The high-level + responsibilities of each bridge living on BridgeHub: - sync finality proofs between relay chains (or equivalent) - sync finality proofs between BridgeHub parachains - pass (XCM) messages between different BridgeHub parachains @@ -76,7 +77,7 @@ cp target/release/substrate-relay ~/local_bridge_testing/bin/substrate-relay # 4. Build cumulus polkadot-parachain binary cd -cargo build --release -p polkadot-parachain-bin +cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --features binary cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain-asset-hub ``` @@ -106,9 +107,11 @@ POLKADOT_PARACHAIN_BINARY=~/local_bridge_testing/bin/polkadot-parachain \ ### Init bridge and run relayer between BridgeHubRococo and BridgeHubWestend **Accounts of BridgeHub parachains:** + - `Bob` is pallet owner of all bridge pallets #### Run with script + ``` cd @@ -116,12 +119,14 @@ cd ``` **Check relay-chain headers relaying:** + - Rococo parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8943#/chainstate - Pallet: **bridgeWestendGrandpa** - Keys: **bestFinalized()** - Westend parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8945#/chainstate - Pallet: **bridgeRococoGrandpa** - Keys: **bestFinalized()** **Check parachain headers relaying:** + - Rococo parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8943#/chainstate - Pallet: **bridgeWestendParachains** - Keys: **parasInfo(None)** - Westend parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8945#/chainstate - Pallet: @@ -130,8 +135,10 @@ cd ### Initialize configuration for transfer asset over bridge (ROCs/WNDs) This initialization does several things: + - creates `ForeignAssets` for wrappedROCs/wrappedWNDs - drips SA for AssetHubRococo on AssetHubWestend (and vice versa) which holds reserved assets on source chains + ``` cd @@ -144,12 +151,14 @@ cd ### Send messages - transfer asset over bridge (ROCs/WNDs) Do reserve-backed transfers: + ``` cd # ROCs from Rococo's Asset Hub to Westend's. ./bridges/testing/environments/rococo-westend/bridges_rococo_westend.sh reserve-transfer-assets-from-asset-hub-rococo-local ``` + ``` cd @@ -158,19 +167,26 @@ cd ``` - open explorers: (see zombienets) - - AssetHubRococo (see events `xcmpQueue.XcmpMessageSent`, `polkadotXcm.Attempted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9910#/explorer - - BridgeHubRococo (see `bridgeWestendMessages.MessageAccepted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer - - BridgeHubWestend (see `bridgeRococoMessages.MessagesReceived`, `xcmpQueue.XcmpMessageSent`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer - - AssetHubWestend (see `foreignAssets.Issued`, `xcmpQueue.Success`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9010#/explorer - - BridgeHubRocococ (see `bridgeWestendMessages.MessagesDelivered`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer + - AssetHubRococo (see events `xcmpQueue.XcmpMessageSent`, + `polkadotXcm.Attempted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9910#/explorer + - BridgeHubRococo (see + `bridgeWestendMessages.MessageAccepted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer + - BridgeHubWestend (see `bridgeRococoMessages.MessagesReceived`, + `xcmpQueue.XcmpMessageSent`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer + - AssetHubWestend (see `foreignAssets.Issued`, + `xcmpQueue.Success`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9010#/explorer + - BridgeHubRocococ (see + `bridgeWestendMessages.MessagesDelivered`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer Do reserve withdraw transfers: (when previous is finished) + ``` cd # wrappedWNDs from Rococo's Asset Hub to Westend's. ./bridges/testing/environments/rococo-westend/bridges_rococo_westend.sh withdraw-reserve-assets-from-asset-hub-rococo-local ``` + ``` cd @@ -181,6 +197,7 @@ cd ### Claim relayer's rewards on BridgeHubRococo and BridgeHubWestend **Accounts of BridgeHub parachains:** + - `//Charlie` is relayer account on BridgeHubRococo - `//Charlie` is relayer account on BridgeHubWestend @@ -195,8 +212,10 @@ cd ``` - open explorers: (see zombienets) - - BridgeHubRococo (see 2x `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer - - BridgeHubWestend (see 2x `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer + - BridgeHubRococo (see 2x + `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer + - BridgeHubWestend (see 2x + `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer ## How to test local BridgeHubKusama/BridgeHubPolkadot diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 5d6548447463..7992e724fad8 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -10,9 +10,13 @@ license = "Apache-2.0" [lints] workspace = true +[lib] +path = "src/lib.rs" + [[bin]] name = "polkadot-parachain" path = "src/main.rs" +required-features = ["binary"] [dependencies] async-trait = { workspace = true } @@ -28,22 +32,22 @@ serde_json = { workspace = true, default-features = true } docify = { workspace = true } # Local -rococo-parachain-runtime = { workspace = true } -shell-runtime = { workspace = true } -glutton-westend-runtime = { workspace = true } -seedling-runtime = { workspace = true } -asset-hub-rococo-runtime = { workspace = true, default-features = true } -asset-hub-westend-runtime = { workspace = true } -collectives-westend-runtime = { workspace = true } -contracts-rococo-runtime = { workspace = true } -bridge-hub-rococo-runtime = { workspace = true, default-features = true } -coretime-rococo-runtime = { workspace = true } -coretime-westend-runtime = { workspace = true } -bridge-hub-westend-runtime = { workspace = true, default-features = true } -penpal-runtime = { workspace = true } +rococo-parachain-runtime = { optional = true, workspace = true } +shell-runtime = { optional = true, workspace = true } +glutton-westend-runtime = { optional = true, workspace = true } +seedling-runtime = { optional = true, workspace = true } +asset-hub-rococo-runtime = { optional = true, workspace = true, default-features = true } +asset-hub-westend-runtime = { optional = true, workspace = true } +collectives-westend-runtime = { optional = true, workspace = true } +contracts-rococo-runtime = { optional = true, workspace = true } +bridge-hub-rococo-runtime = { optional = true, workspace = true, default-features = true } +coretime-rococo-runtime = { optional = true, workspace = true } +coretime-westend-runtime = { optional = true, workspace = true } +bridge-hub-westend-runtime = { optional = true, workspace = true, default-features = true } +penpal-runtime = { optional = true, workspace = true } jsonrpsee = { features = ["server"], workspace = true } -people-rococo-runtime = { workspace = true } -people-westend-runtime = { workspace = true } +people-rococo-runtime = { optional = true, workspace = true } +people-westend-runtime = { optional = true, workspace = true } parachains-common = { workspace = true, default-features = true } testnet-parachains-constants = { features = [ "rococo", @@ -127,55 +131,74 @@ wait-timeout = { workspace = true } [features] default = [] +binary = [ + "asset-hub-rococo-runtime", + "asset-hub-westend-runtime", + "bridge-hub-rococo-runtime", + "bridge-hub-westend-runtime", + "collectives-westend-runtime", + "contracts-rococo-runtime", + "coretime-rococo-runtime", + "coretime-westend-runtime", + "glutton-westend-runtime", + "penpal-runtime", + "people-rococo-runtime", + "people-westend-runtime", + "rococo-parachain-runtime", + "seedling-runtime", + "shell-runtime", +] runtime-benchmarks = [ - "asset-hub-rococo-runtime/runtime-benchmarks", - "asset-hub-westend-runtime/runtime-benchmarks", - "bridge-hub-rococo-runtime/runtime-benchmarks", - "bridge-hub-westend-runtime/runtime-benchmarks", - "collectives-westend-runtime/runtime-benchmarks", - "contracts-rococo-runtime/runtime-benchmarks", - "coretime-rococo-runtime/runtime-benchmarks", - "coretime-westend-runtime/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "frame-benchmarking-cli/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", - "glutton-westend-runtime/runtime-benchmarks", "parachains-common/runtime-benchmarks", - "penpal-runtime/runtime-benchmarks", - "people-rococo-runtime/runtime-benchmarks", - "people-westend-runtime/runtime-benchmarks", "polkadot-cli/runtime-benchmarks", "polkadot-primitives/runtime-benchmarks", "polkadot-service/runtime-benchmarks", - "rococo-parachain-runtime/runtime-benchmarks", "sc-service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + + "asset-hub-rococo-runtime?/runtime-benchmarks", + "asset-hub-westend-runtime?/runtime-benchmarks", + "bridge-hub-rococo-runtime?/runtime-benchmarks", + "bridge-hub-westend-runtime?/runtime-benchmarks", + "collectives-westend-runtime?/runtime-benchmarks", + "contracts-rococo-runtime?/runtime-benchmarks", + "coretime-rococo-runtime?/runtime-benchmarks", + "coretime-westend-runtime?/runtime-benchmarks", + "glutton-westend-runtime?/runtime-benchmarks", + "penpal-runtime?/runtime-benchmarks", + "people-rococo-runtime?/runtime-benchmarks", + "people-westend-runtime?/runtime-benchmarks", + "rococo-parachain-runtime?/runtime-benchmarks", ] try-runtime = [ - "asset-hub-rococo-runtime/try-runtime", - "asset-hub-westend-runtime/try-runtime", - "bridge-hub-rococo-runtime/try-runtime", - "bridge-hub-westend-runtime/try-runtime", - "collectives-westend-runtime/try-runtime", - "contracts-rococo-runtime/try-runtime", - "coretime-rococo-runtime/try-runtime", - "coretime-westend-runtime/try-runtime", "frame-support/try-runtime", "frame-try-runtime/try-runtime", - "glutton-westend-runtime/try-runtime", "pallet-transaction-payment/try-runtime", - "penpal-runtime/try-runtime", - "people-rococo-runtime/try-runtime", - "people-westend-runtime/try-runtime", "polkadot-cli/try-runtime", "polkadot-service/try-runtime", - "shell-runtime/try-runtime", "sp-runtime/try-runtime", + + "asset-hub-rococo-runtime?/try-runtime", + "asset-hub-westend-runtime?/try-runtime", + "bridge-hub-rococo-runtime?/try-runtime", + "bridge-hub-westend-runtime?/try-runtime", + "collectives-westend-runtime?/try-runtime", + "contracts-rococo-runtime?/try-runtime", + "coretime-rococo-runtime?/try-runtime", + "coretime-westend-runtime?/try-runtime", + "glutton-westend-runtime?/try-runtime", + "penpal-runtime?/try-runtime", + "people-rococo-runtime?/try-runtime", + "people-westend-runtime?/try-runtime", + "shell-runtime?/try-runtime", ] fast-runtime = [ - "bridge-hub-rococo-runtime/fast-runtime", - "bridge-hub-westend-runtime/fast-runtime", - "coretime-rococo-runtime/fast-runtime", - "coretime-westend-runtime/fast-runtime", + "bridge-hub-rococo-runtime?/fast-runtime", + "bridge-hub-westend-runtime?/fast-runtime", + "coretime-rococo-runtime?/fast-runtime", + "coretime-westend-runtime?/fast-runtime", ] diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 571ffc197690..14c552165519 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{AccountId, AuraId, Balance as AssetHubBalance}; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 35e14a4aa5c5..4ea88501c60c 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}, - common::chain_spec::GenericChainSpec, -}; +use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}; use cumulus_primitives_core::ParaId; use parachains_common::Balance as BridgeHubBalance; +use polkadot_parachain_bin::chain_spec::GenericChainSpec; use sc_chain_spec::ChainSpec; use sp_core::sr25519; use std::str::FromStr; @@ -132,11 +130,9 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup pub mod rococo { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::{ - chain_spec::SAFE_XCM_VERSION, - common::chain_spec::{Extensions, GenericChainSpec}, - }; + use crate::chain_spec::SAFE_XCM_VERSION; use parachains_common::{AccountId, AuraId}; + use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use super::BridgeHubBalance; @@ -260,11 +256,9 @@ pub mod kusama { /// Sub-module for Westend setup. pub mod westend { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::{ - chain_spec::SAFE_XCM_VERSION, - common::chain_spec::{Extensions, GenericChainSpec}, - }; + use crate::chain_spec::SAFE_XCM_VERSION; use parachains_common::{AccountId, AuraId}; + use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use super::BridgeHubBalance; diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index ab8e98bb52c3..b44cca235546 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId, Balance as CollectivesBalance}; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs index 2cd098a4cc24..00abc12c8074 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{AccountId, AuraId}; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index 9e3f1506456d..b537067ab274 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::common::chain_spec::GenericChainSpec; use cumulus_primitives_core::ParaId; +use polkadot_parachain_bin::chain_spec::GenericChainSpec; use sc_chain_spec::{ChainSpec, ChainType}; use std::{borrow::Cow, str::FromStr}; @@ -144,12 +144,12 @@ pub fn chain_type_name(chain_type: &ChainType) -> Cow { /// Sub-module for Rococo setup. pub mod rococo { - use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec, ParaId}; - use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::Extensions, + use super::{chain_type_name, CoretimeRuntimeType, ParaId}; + use crate::chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId, Balance}; + use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use sp_core::sr25519; @@ -243,11 +243,11 @@ pub mod rococo { /// Sub-module for Westend setup. pub mod westend { use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec, ParaId}; - use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::Extensions, + use crate::chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId, Balance}; + use polkadot_parachain_bin::chain_spec::Extensions; use sp_core::sr25519; pub(crate) const CORETIME_WESTEND: &str = "coretime-westend"; diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index b96432d1d60b..e8f6e2d475a0 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::get_account_id_from_seed, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::get_account_id_from_seed; use cumulus_primitives_core::ParaId; use parachains_common::AuraId; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index cf8f1209d1d8..4e39bd60f595 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::common::{ - chain_spec::{GenericChainSpec, LoadSpec}, - runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT}, -}; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, Signature}; +use polkadot_parachain_bin::{ + chain_spec::{GenericChainSpec, LoadSpec}, + AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT, +}; use sc_chain_spec::ChainSpec; use sp_core::{Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index d43a5363db6a..f3ed5cc6111c 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId}; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/people.rs b/cumulus/polkadot-parachain/src/chain_spec/people.rs index 0e66a50ca88e..385f67f52362 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/people.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/people.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::common::chain_spec::GenericChainSpec; use cumulus_primitives_core::ParaId; use parachains_common::Balance as PeopleBalance; +use polkadot_parachain_bin::chain_spec::GenericChainSpec; use sc_chain_spec::ChainSpec; use std::str::FromStr; @@ -120,11 +120,11 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup. pub mod rococo { use super::{ParaId, PeopleBalance}; - use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, + use crate::chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId}; + use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use sp_core::sr25519; @@ -230,11 +230,11 @@ pub mod rococo { /// Sub-module for Westend setup. pub mod westend { use super::{ParaId, PeopleBalance}; - use crate::{ - chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, + use crate::chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId}; + use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index d132f796f261..eba236522aff 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -16,13 +16,11 @@ //! ChainSpecs dedicated to Rococo parachain setups (for testing and example purposes) -use crate::{ - chain_spec::{get_from_seed, SAFE_XCM_VERSION}, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::{get_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::AccountId; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use polkadot_service::chain_spec::get_account_id_from_seed; use rococo_parachain_runtime::AuraId; use sc_chain_spec::ChainType; diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs index 1e6b15c460b5..b70be5552122 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ - chain_spec::get_account_id_from_seed, - common::chain_spec::{Extensions, GenericChainSpec}, -}; +use crate::chain_spec::get_account_id_from_seed; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId}; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index c6c6074cb4a7..0aae2003065a 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::common::chain_spec::{Extensions, GenericChainSpec}; use cumulus_primitives_core::ParaId; use parachains_common::AuraId; +use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use super::get_collator_keys_from_seed; diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/src/cli.rs index 23c31fff6e3f..622fab34f444 100644 --- a/cumulus/polkadot-parachain/src/cli.rs +++ b/cumulus/polkadot-parachain/src/cli.rs @@ -64,12 +64,35 @@ pub enum Subcommand { Benchmark(frame_benchmarking_cli::BenchmarkCmd), } +fn examples(executable_name: String) -> String { + color_print::cformat!( + r#"Examples: + + {0} --chain para.json --sync warp -- --chain relay.json --sync warp + Launch a warp-syncing full node of a given para's chain-spec, and a given relay's chain-spec. + + The above approach is the most flexible, and the most forward-compatible way to spawn an omni-node. + + You can find the chain-spec of some networks in: + https://paritytech.github.io/chainspecs + + {0} --chain asset-hub-polkadot --sync warp -- --chain polkadot --sync warp + Launch a warp-syncing full node of the Asset Hub parachain on the Polkadot Relay Chain. + + {0} --chain asset-hub-kusama --sync warp --relay-chain-rpc-url ws://rpc.example.com -- --chain kusama + Launch a warp-syncing full node of the Asset Hub parachain on the Kusama Relay Chain. + Uses ws://rpc.example.com as remote relay chain node. + "#, + executable_name, + ) +} + #[derive(Debug, clap::Parser)] #[command( propagate_version = true, args_conflicts_with_subcommands = true, subcommand_negates_reqs = true, - after_help = crate::examples(Self::executable_name()) + after_help = examples(Self::executable_name()) )] pub struct Cli { #[arg(skip)] diff --git a/cumulus/polkadot-parachain/src/common/chain_spec.rs b/cumulus/polkadot-parachain/src/common/chain_spec.rs index 7f9bfbb4f55f..58af66f7fbda 100644 --- a/cumulus/polkadot-parachain/src/common/chain_spec.rs +++ b/cumulus/polkadot-parachain/src/common/chain_spec.rs @@ -14,16 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +//! Chain spec primitives. + use frame_support::{Deserialize, Serialize}; -use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup}; +use sc_chain_spec::{ChainSpec, ChainSpecExtension}; use std::fmt::Debug; +/// Helper trait used for loading/building a chain spec starting from the chain ID. pub trait LoadSpec: Debug { + /// Load/Build a chain spec starting from the chain ID. fn load_spec(&self, id: &str) -> Result, String>; } /// Generic extensions for Parachain ChainSpecs. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecExtension)] pub struct Extensions { /// The relay chain of the Parachain. #[serde(alias = "relayChain", alias = "RelayChain")] diff --git a/cumulus/polkadot-parachain/src/common/mod.rs b/cumulus/polkadot-parachain/src/common/mod.rs index fd2bea700465..9ba6d4a88095 100644 --- a/cumulus/polkadot-parachain/src/common/mod.rs +++ b/cumulus/polkadot-parachain/src/common/mod.rs @@ -18,9 +18,9 @@ #![warn(missing_docs)] -pub mod aura; +pub(crate) mod aura; pub mod chain_spec; -pub mod runtime; +pub(crate) mod runtime; use cumulus_primitives_core::CollectCollationInfo; use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata}; diff --git a/cumulus/polkadot-parachain/src/common/runtime.rs b/cumulus/polkadot-parachain/src/common/runtime.rs index e9a8f06a7772..606f87cc03f0 100644 --- a/cumulus/polkadot-parachain/src/common/runtime.rs +++ b/cumulus/polkadot-parachain/src/common/runtime.rs @@ -17,9 +17,12 @@ use sc_chain_spec::ChainSpec; use std::fmt::Debug; +/// The Aura ID used by the Aura consensus #[derive(Debug, PartialEq)] pub enum AuraConsensusId { + /// Ed25519 Ed25519, + /// Sr25519 Sr25519, } @@ -36,9 +39,12 @@ pub enum Runtime { /// None of the system-chain runtimes, rather the node will act agnostic to the runtime ie. be /// an omni-node, and simply run a node with the given consensus algorithm. Omni(Consensus), + /// Shell Shell, } +/// Helper trait used for extracting the Runtime variant from the chain spec ID. pub trait RuntimeResolver: Debug { + /// Extract the Runtime variant from the chain spec ID. fn runtime(&self, chain_spec: &dyn ChainSpec) -> sc_cli::Result; } diff --git a/cumulus/polkadot-parachain/src/lib.rs b/cumulus/polkadot-parachain/src/lib.rs new file mode 100644 index 000000000000..a877880482ac --- /dev/null +++ b/cumulus/polkadot-parachain/src/lib.rs @@ -0,0 +1,28 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +mod cli; +mod command; +mod common; +mod fake_runtime_api; +mod rpc; +mod service; + +pub use command::{run, CommandConfig}; +pub use common::{ + chain_spec, + runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver}, +}; diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index f6bfabc91a2e..0186dc6eae9f 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -19,38 +19,9 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] -use crate::command::CommandConfig; - -pub(crate) fn examples(executable_name: String) -> String { - color_print::cformat!( - r#"Examples: - - {0} --chain para.json --sync warp -- --chain relay.json --sync warp - Launch a warp-syncing full node of a given para's chain-spec, and a given relay's chain-spec. - - The above approach is the most flexible, and the most forward-compatible way to spawn an omni-node. - - You can find the chain-spec of some networks in: - https://paritytech.github.io/chainspecs - - {0} --chain asset-hub-polkadot --sync warp -- --chain polkadot --sync warp - Launch a warp-syncing full node of the Asset Hub parachain on the Polkadot Relay Chain. - - {0} --chain asset-hub-kusama --sync warp --relay-chain-rpc-url ws://rpc.example.com -- --chain kusama - Launch a warp-syncing full node of the Asset Hub parachain on the Kusama Relay Chain. - Uses ws://rpc.example.com as remote relay chain node. - "#, - executable_name, - ) -} - mod chain_spec; -mod cli; -mod command; -mod common; -mod fake_runtime_api; -mod rpc; -mod service; + +use polkadot_parachain_bin::{run, CommandConfig}; fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; @@ -59,5 +30,5 @@ fn main() -> color_eyre::eyre::Result<()> { chain_spec_loader: Some(Box::new(chain_spec::ChainSpecLoader)), runtime_resolver: Some(Box::new(chain_spec::RuntimeResolver)), }; - Ok(command::run(config)?) + Ok(run(config)?) } diff --git a/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile b/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile index b56b8c1a1ef8..31c86e51854d 100644 --- a/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile +++ b/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile @@ -5,7 +5,7 @@ FROM docker.io/paritytech/ci-linux:production as builder WORKDIR /cumulus COPY . /cumulus -RUN cargo build --release --locked -p polkadot-parachain +RUN cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary # This is the 2nd stage: a very small image where we copy the Polkadot binary." FROM docker.io/library/ubuntu:20.04 diff --git a/docker/dockerfiles/test-parachain-collator.Dockerfile b/docker/dockerfiles/test-parachain-collator.Dockerfile index 116520284dd3..2bc10da37b77 100644 --- a/docker/dockerfiles/test-parachain-collator.Dockerfile +++ b/docker/dockerfiles/test-parachain-collator.Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/paritytech/ci-linux:production as builder WORKDIR /cumulus COPY . /cumulus -RUN cargo build --release --locked -p polkadot-parachain +RUN cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary # the collator stage is normally built once, cached, and then ignored, but can # be specified with the --target build flag. This adds some extra tooling to the diff --git a/docs/contributor/container.md b/docs/contributor/container.md index ec51b8b9d7cc..5a789d4d37de 100644 --- a/docs/contributor/container.md +++ b/docs/contributor/container.md @@ -25,7 +25,7 @@ docker run --rm -it \ -w /polkadot-sdk \ -v $(pwd):/polkadot-sdk \ docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408 \ - cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain + cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary sudo chown -R $(id -u):$(id -g) target/ ``` diff --git a/scripts/lib/bench-all-cumulus.sh b/scripts/lib/bench-all-cumulus.sh index f4c2a35c6b6b..e1db2e97165b 100755 --- a/scripts/lib/bench-all-cumulus.sh +++ b/scripts/lib/bench-all-cumulus.sh @@ -75,7 +75,7 @@ run_cumulus_bench() { echo "[+] Compiling benchmarks..." -cargo build --profile $profile --locked --features=runtime-benchmarks -p polkadot-parachain-bin +cargo build --profile $profile --locked --features=runtime-benchmarks -p polkadot-parachain-bin --features binary # Run benchmarks for all pallets of a given runtime if runtime argument provided get_arg optional --runtime "$@" diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 65ff9a81e474..302d5413521a 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -330,6 +330,7 @@ runtime-benchmarks = [ "parachains-common?/runtime-benchmarks", "polkadot-cli?/runtime-benchmarks", "polkadot-node-metrics?/runtime-benchmarks", + "polkadot-parachain-bin?/runtime-benchmarks", "polkadot-parachain-primitives?/runtime-benchmarks", "polkadot-primitives?/runtime-benchmarks", "polkadot-runtime-common?/runtime-benchmarks", @@ -459,6 +460,7 @@ try-runtime = [ "pallet-xcm-bridge-hub?/try-runtime", "pallet-xcm?/try-runtime", "polkadot-cli?/try-runtime", + "polkadot-parachain-bin?/try-runtime", "polkadot-runtime-common?/try-runtime", "polkadot-runtime-parachains?/try-runtime", "polkadot-sdk-frame?/try-runtime", @@ -755,7 +757,7 @@ runtime = [ "xcm-procedural", "xcm-runtime-apis", ] -node = ["asset-test-utils", "bridge-hub-test-utils", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", "cumulus-client-consensus-common", "cumulus-client-consensus-proposer", "cumulus-client-consensus-relay-chain", "cumulus-client-network", "cumulus-client-parachain-inherent", "cumulus-client-pov-recovery", "cumulus-client-service", "cumulus-relay-chain-inprocess-interface", "cumulus-relay-chain-interface", "cumulus-relay-chain-minimal-node", "cumulus-relay-chain-rpc-interface", "cumulus-test-relay-sproof-builder", "emulated-integration-tests-common", "fork-tree", "frame-benchmarking-cli", "frame-remote-externalities", "frame-support-procedural-tools", "generate-bags", "mmr-gadget", "mmr-rpc", "pallet-contracts-mock-network", "pallet-transaction-payment-rpc", "parachains-runtimes-test-utils", "polkadot-approval-distribution", "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", "polkadot-cli", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-erasure-coding", "polkadot-gossip-support", "polkadot-network-bridge", "polkadot-node-collation-generation", "polkadot-node-core-approval-voting", "polkadot-node-core-av-store", "polkadot-node-core-backing", "polkadot-node-core-bitfield-signing", "polkadot-node-core-candidate-validation", "polkadot-node-core-chain-api", "polkadot-node-core-chain-selection", "polkadot-node-core-dispute-coordinator", "polkadot-node-core-parachains-inherent", "polkadot-node-core-prospective-parachains", "polkadot-node-core-provisioner", "polkadot-node-core-pvf", "polkadot-node-core-pvf-checker", "polkadot-node-core-pvf-common", "polkadot-node-core-pvf-execute-worker", "polkadot-node-core-pvf-prepare-worker", "polkadot-node-core-runtime-api", "polkadot-node-jaeger", "polkadot-node-metrics", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-rpc", "polkadot-service", "polkadot-statement-distribution", "polkadot-statement-table", "sc-allocator", "sc-authority-discovery", "sc-basic-authorship", "sc-block-builder", "sc-chain-spec", "sc-cli", "sc-client-api", "sc-client-db", "sc-consensus", "sc-consensus-aura", "sc-consensus-babe", "sc-consensus-babe-rpc", "sc-consensus-beefy", "sc-consensus-beefy-rpc", "sc-consensus-epochs", "sc-consensus-grandpa", "sc-consensus-grandpa-rpc", "sc-consensus-manual-seal", "sc-consensus-pow", "sc-consensus-slots", "sc-executor", "sc-executor-common", "sc-executor-polkavm", "sc-executor-wasmtime", "sc-informant", "sc-keystore", "sc-mixnet", "sc-network", "sc-network-common", "sc-network-gossip", "sc-network-light", "sc-network-statement", "sc-network-sync", "sc-network-transactions", "sc-network-types", "sc-offchain", "sc-proposer-metrics", "sc-rpc", "sc-rpc-api", "sc-rpc-server", "sc-rpc-spec-v2", "sc-service", "sc-state-db", "sc-statement-store", "sc-storage-monitor", "sc-sync-state-rpc", "sc-sysinfo", "sc-telemetry", "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", "sc-utils", "snowbridge-runtime-test-common", "sp-blockchain", "sp-consensus", "sp-core-hashing", "sp-core-hashing-proc-macro", "sp-database", "sp-maybe-compressed-blob", "sp-panic-handler", "sp-rpc", "staging-chain-spec-builder", "staging-node-inspect", "staging-tracking-allocator", "std", "subkey", "substrate-build-script-utils", "substrate-frame-rpc-support", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-rpc-client", "substrate-state-trie-migration-rpc", "substrate-wasm-builder", "tracing-gum", "xcm-emulator", "xcm-simulator"] +node = ["asset-test-utils", "bridge-hub-test-utils", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", "cumulus-client-consensus-common", "cumulus-client-consensus-proposer", "cumulus-client-consensus-relay-chain", "cumulus-client-network", "cumulus-client-parachain-inherent", "cumulus-client-pov-recovery", "cumulus-client-service", "cumulus-relay-chain-inprocess-interface", "cumulus-relay-chain-interface", "cumulus-relay-chain-minimal-node", "cumulus-relay-chain-rpc-interface", "cumulus-test-relay-sproof-builder", "emulated-integration-tests-common", "fork-tree", "frame-benchmarking-cli", "frame-remote-externalities", "frame-support-procedural-tools", "generate-bags", "mmr-gadget", "mmr-rpc", "pallet-contracts-mock-network", "pallet-transaction-payment-rpc", "parachains-runtimes-test-utils", "polkadot-approval-distribution", "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", "polkadot-cli", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-erasure-coding", "polkadot-gossip-support", "polkadot-network-bridge", "polkadot-node-collation-generation", "polkadot-node-core-approval-voting", "polkadot-node-core-av-store", "polkadot-node-core-backing", "polkadot-node-core-bitfield-signing", "polkadot-node-core-candidate-validation", "polkadot-node-core-chain-api", "polkadot-node-core-chain-selection", "polkadot-node-core-dispute-coordinator", "polkadot-node-core-parachains-inherent", "polkadot-node-core-prospective-parachains", "polkadot-node-core-provisioner", "polkadot-node-core-pvf", "polkadot-node-core-pvf-checker", "polkadot-node-core-pvf-common", "polkadot-node-core-pvf-execute-worker", "polkadot-node-core-pvf-prepare-worker", "polkadot-node-core-runtime-api", "polkadot-node-jaeger", "polkadot-node-metrics", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-parachain-bin", "polkadot-rpc", "polkadot-service", "polkadot-statement-distribution", "polkadot-statement-table", "sc-allocator", "sc-authority-discovery", "sc-basic-authorship", "sc-block-builder", "sc-chain-spec", "sc-cli", "sc-client-api", "sc-client-db", "sc-consensus", "sc-consensus-aura", "sc-consensus-babe", "sc-consensus-babe-rpc", "sc-consensus-beefy", "sc-consensus-beefy-rpc", "sc-consensus-epochs", "sc-consensus-grandpa", "sc-consensus-grandpa-rpc", "sc-consensus-manual-seal", "sc-consensus-pow", "sc-consensus-slots", "sc-executor", "sc-executor-common", "sc-executor-polkavm", "sc-executor-wasmtime", "sc-informant", "sc-keystore", "sc-mixnet", "sc-network", "sc-network-common", "sc-network-gossip", "sc-network-light", "sc-network-statement", "sc-network-sync", "sc-network-transactions", "sc-network-types", "sc-offchain", "sc-proposer-metrics", "sc-rpc", "sc-rpc-api", "sc-rpc-server", "sc-rpc-spec-v2", "sc-service", "sc-state-db", "sc-statement-store", "sc-storage-monitor", "sc-sync-state-rpc", "sc-sysinfo", "sc-telemetry", "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", "sc-utils", "snowbridge-runtime-test-common", "sp-blockchain", "sp-consensus", "sp-core-hashing", "sp-core-hashing-proc-macro", "sp-database", "sp-maybe-compressed-blob", "sp-panic-handler", "sp-rpc", "staging-chain-spec-builder", "staging-node-inspect", "staging-tracking-allocator", "std", "subkey", "substrate-build-script-utils", "substrate-frame-rpc-support", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-rpc-client", "substrate-state-trie-migration-rpc", "substrate-wasm-builder", "tracing-gum", "xcm-emulator", "xcm-simulator"] tuples-96 = [ "frame-support-procedural?/tuples-96", "frame-support?/tuples-96", @@ -2212,6 +2214,11 @@ path = "../polkadot/node/overseer" default-features = false optional = true +[dependencies.polkadot-parachain-bin] +path = "../cumulus/polkadot-parachain" +default-features = false +optional = true + [dependencies.polkadot-rpc] path = "../polkadot/rpc" default-features = false diff --git a/umbrella/src/lib.rs b/umbrella/src/lib.rs index 07f1cbad1262..29356734c7cb 100644 --- a/umbrella/src/lib.rs +++ b/umbrella/src/lib.rs @@ -882,6 +882,10 @@ pub use polkadot_node_subsystem_util; #[cfg(feature = "polkadot-overseer")] pub use polkadot_overseer; +/// Runs a polkadot parachain node which could be a collator. +#[cfg(feature = "polkadot-parachain-bin")] +pub use polkadot_parachain_bin; + /// Types and utilities for creating and working with parachains. #[cfg(feature = "polkadot-parachain-primitives")] pub use polkadot_parachain_primitives; From 6e233bb5cf9a42d5a405c8d77b19553e6d71dd09 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 12 Aug 2024 10:17:02 +0300 Subject: [PATCH 03/14] Docs --- cumulus/polkadot-parachain/src/lib.rs | 24 ++++++++++++++++++++++-- umbrella/src/lib.rs | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cumulus/polkadot-parachain/src/lib.rs b/cumulus/polkadot-parachain/src/lib.rs index a877880482ac..6140b2687264 100644 --- a/cumulus/polkadot-parachain/src/lib.rs +++ b/cumulus/polkadot-parachain/src/lib.rs @@ -14,6 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +//! Helper library that can be used to run a parachain node. +//! +//! ## Overview +//! +//! This library can be used to run a parachain node while also customizing the chain specs +//! that are supported by default by the `--chain-spec` argument of the node's `CLI` +//! and the parameters of the runtime that is associated with each of these chain specs. +//! +//! ## API +//! +//! The library exposes the possibility to provide a [`CommandConfig`]. Through this structure +//! 2 optional configurations can be provided: +//! - a chain spec loader (an implementation of ['chain_spec::LoadSpec']): this can be used for +//! providing the chain specs that are supported by default by the `--chain-spec` argument of the +//! node's `CLI` and the actual chain config associated with each one. +//! - a runtime resolver (an implementation of [`chain_spec::RuntimeResolver`]): this can be used +//! for providing the parameters of the runtime that is associated with each of the chain specs + mod cli; mod command; mod common; @@ -21,8 +39,10 @@ mod fake_runtime_api; mod rpc; mod service; +use crate::chain_spec::GenericChainSpec; pub use command::{run, CommandConfig}; pub use common::{ - chain_spec, - runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver}, + chain_spec, + runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver}, }; +use sc_chain_spec::ChainSpec; diff --git a/umbrella/src/lib.rs b/umbrella/src/lib.rs index 29356734c7cb..fb60a5c21ac4 100644 --- a/umbrella/src/lib.rs +++ b/umbrella/src/lib.rs @@ -882,7 +882,7 @@ pub use polkadot_node_subsystem_util; #[cfg(feature = "polkadot-overseer")] pub use polkadot_overseer; -/// Runs a polkadot parachain node which could be a collator. +/// Helper library that can be used to run a parachain node. #[cfg(feature = "polkadot-parachain-bin")] pub use polkadot_parachain_bin; From 75fecd158899200687f256faf9c1ecf0bf938f01 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 12 Aug 2024 12:15:41 +0300 Subject: [PATCH 04/14] Move lib to separate crate --- .gitlab/pipeline/build.yml | 8 +- Cargo.lock | 58 +++--- Cargo.toml | 2 + bridges/testing/README.md | 13 +- cumulus/README.md | 26 +-- .../parachains/runtimes/bridge-hubs/README.md | 67 +++--- cumulus/polkadot-parachain/Cargo.toml | 190 +++++------------- .../polkadot-parachain-lib/Cargo.toml | 115 +++++++++++ .../{ => polkadot-parachain-lib}/build.rs | 0 .../{ => polkadot-parachain-lib}/src/cli.rs | 0 .../src/command.rs | 0 .../src/common/aura.rs | 0 .../src/common/chain_spec.rs | 0 .../src/common/mod.rs | 0 .../src/common/runtime.rs | 0 .../asset_hub_polkadot_aura.rs | 0 .../src/fake_runtime_api/aura.rs | 0 .../src/fake_runtime_api/mod.rs | 0 .../{ => polkadot-parachain-lib}/src/lib.rs | 10 +- .../{ => polkadot-parachain-lib}/src/rpc.rs | 0 .../src/service.rs | 0 .../src}/tests/benchmark_storage_works.rs | 0 .../src}/tests/common.rs | 0 .../src}/tests/polkadot_argument_parsing.rs | 0 .../src}/tests/polkadot_mdns_issue.rs | 0 .../src}/tests/purge_chain_works.rs | 0 .../tests/running_the_node_and_interrupt.rs | 0 .../src/chain_spec/asset_hubs.rs | 2 +- .../src/chain_spec/bridge_hubs.rs | 6 +- .../src/chain_spec/collectives.rs | 2 +- .../src/chain_spec/contracts.rs | 2 +- .../src/chain_spec/coretime.rs | 6 +- .../src/chain_spec/glutton.rs | 2 +- .../polkadot-parachain/src/chain_spec/mod.rs | 2 +- .../src/chain_spec/penpal.rs | 2 +- .../src/chain_spec/people.rs | 6 +- .../src/chain_spec/rococo_parachain.rs | 2 +- .../src/chain_spec/seedling.rs | 2 +- .../src/chain_spec/shell.rs | 2 +- cumulus/polkadot-parachain/src/main.rs | 2 +- .../polkadot-parachain_builder.Dockerfile | 2 +- .../test-parachain-collator.Dockerfile | 2 +- docs/contributor/container.md | 2 +- scripts/lib/bench-all-cumulus.sh | 2 +- umbrella/Cargo.toml | 10 +- umbrella/src/lib.rs | 6 +- 46 files changed, 277 insertions(+), 274 deletions(-) create mode 100644 cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/build.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/cli.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/command.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/common/aura.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/common/chain_spec.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/common/mod.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/common/runtime.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/fake_runtime_api/asset_hub_polkadot_aura.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/fake_runtime_api/aura.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/fake_runtime_api/mod.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/lib.rs (92%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/rpc.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib}/src/service.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib/src}/tests/benchmark_storage_works.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib/src}/tests/common.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib/src}/tests/polkadot_argument_parsing.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib/src}/tests/polkadot_mdns_issue.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib/src}/tests/purge_chain_works.rs (100%) rename cumulus/polkadot-parachain/{ => polkadot-parachain-lib/src}/tests/running_the_node_and_interrupt.rs (100%) diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index af1a0e632880..8658e92efc8f 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -171,7 +171,7 @@ build-linux-stable-cumulus: RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" script: - echo "___Building a binary, please refrain from using it in production since it goes with the debug assertions.___" - - time cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary + - time cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain - echo "___Packing the artifacts___" - mkdir -p ./artifacts - mv ./target/release/polkadot-parachain ./artifacts/. @@ -288,7 +288,7 @@ build-short-benchmark-cumulus: - .run-immediately - .collect-artifacts script: - - cargo build --profile release --locked --features=binary,runtime-benchmarks,on-chain-release-build -p polkadot-parachain-bin --bin polkadot-parachain --workspace + - cargo build --profile release --locked --features=runtime-benchmarks,on-chain-release-build -p polkadot-parachain-bin --bin polkadot-parachain --workspace - mkdir -p artifacts - target/release/polkadot-parachain --version - cp ./target/release/polkadot-parachain ./artifacts/ @@ -313,7 +313,7 @@ build-linux-substrate: # tldr: we need to checkout the branch HEAD explicitly because of our dynamic versioning approach while building the substrate binary # see https://github.com/paritytech/ci_cd/issues/682#issuecomment-1340953589 - git checkout -B "$CI_COMMIT_REF_NAME" "$CI_COMMIT_SHA" - - !reference [ .forklift-cache, before_script ] + - !reference [.forklift-cache, before_script] script: - time WASM_BUILD_NO_COLOR=1 cargo build --locked --release -p staging-node-cli - mv $CARGO_TARGET_DIR/release/substrate-node ./artifacts/substrate/substrate @@ -353,7 +353,7 @@ build-runtimes-polkavm: CARGO_TARGET_DIR: "$CI_PROJECT_DIR/target" before_script: - mkdir -p ./artifacts/subkey - - !reference [ .forklift-cache, before_script ] + - !reference [.forklift-cache, before_script] script: - cd ./substrate/bin/utils/subkey - time SKIP_WASM_BUILD=1 cargo build --locked --release diff --git a/Cargo.lock b/Cargo.lock index d7dd0c85b87d..456fd00c9423 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13865,19 +13865,48 @@ dependencies = [ name = "polkadot-parachain-bin" version = "4.0.0" dependencies = [ - "assert_cmd", "asset-hub-rococo-runtime", "asset-hub-westend-runtime", - "async-trait", "bridge-hub-rococo-runtime", "bridge-hub-westend-runtime", - "clap 4.5.11", "collectives-westend-runtime", "color-eyre", - "color-print", "contracts-rococo-runtime", "coretime-rococo-runtime", "coretime-westend-runtime", + "cumulus-primitives-core", + "glutton-westend-runtime", + "hex-literal", + "log", + "parachains-common", + "penpal-runtime", + "people-rococo-runtime", + "people-westend-runtime", + "polkadot-parachain-lib", + "polkadot-service", + "rococo-parachain-runtime", + "sc-chain-spec", + "sc-cli", + "sc-service", + "seedling-runtime", + "serde", + "serde_json", + "shell-runtime", + "sp-core", + "sp-runtime", + "staging-xcm", + "substrate-build-script-utils", + "testnet-parachains-constants", +] + +[[package]] +name = "polkadot-parachain-lib" +version = "0.0.1" +dependencies = [ + "assert_cmd", + "async-trait", + "clap 4.5.11", + "color-print", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -13896,8 +13925,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "futures", - "glutton-westend-runtime", - "hex-literal", "jsonrpsee", "log", "nix 0.28.0", @@ -13906,13 +13933,8 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parachains-common", "parity-scale-codec", - "penpal-runtime", - "people-rococo-runtime", - "people-westend-runtime", "polkadot-cli", "polkadot-primitives", - "polkadot-service", - "rococo-parachain-runtime", "sc-basic-authorship", "sc-chain-spec", "sc-cli", @@ -13920,42 +13942,30 @@ dependencies = [ "sc-consensus", "sc-executor", "sc-network", - "sc-network-sync", "sc-rpc", "sc-service", "sc-sysinfo", "sc-telemetry", "sc-tracing", "sc-transaction-pool", - "sc-transaction-pool-api", - "seedling-runtime", "serde", "serde_json", - "shell-runtime", "sp-api", "sp-block-builder", - "sp-blockchain", "sp-consensus-aura", "sp-core", "sp-genesis-builder", "sp-inherents", - "sp-io", "sp-keystore", - "sp-offchain", "sp-runtime", "sp-session", - "sp-std 14.0.0", "sp-timestamp", - "sp-tracing 16.0.0", "sp-transaction-pool", "sp-version", - "staging-xcm", "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-state-trie-migration-rpc", - "tempfile", - "testnet-parachains-constants", "tokio", "wait-timeout", ] @@ -14387,7 +14397,7 @@ dependencies = [ "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-parachain-bin", + "polkadot-parachain-lib", "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-rpc", diff --git a/Cargo.toml b/Cargo.toml index 92941d8ee0a2..69f95ebea8dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,6 +136,7 @@ members = [ "cumulus/parachains/runtimes/testing/penpal", "cumulus/parachains/runtimes/testing/rococo-parachain", "cumulus/polkadot-parachain", + "cumulus/polkadot-parachain/polkadot-parachain-lib", "cumulus/primitives/aura", "cumulus/primitives/core", "cumulus/primitives/parachain-inherent", @@ -1043,6 +1044,7 @@ polkadot-node-subsystem-test-helpers = { path = "polkadot/node/subsystem-test-he polkadot-node-subsystem-types = { path = "polkadot/node/subsystem-types", default-features = false } polkadot-node-subsystem-util = { path = "polkadot/node/subsystem-util", default-features = false } polkadot-overseer = { path = "polkadot/node/overseer", default-features = false } +polkadot-parachain-lib = { path = "cumulus/polkadot-parachain/polkadot-parachain-lib", default-features = false } polkadot-parachain-primitives = { path = "polkadot/parachain", default-features = false } polkadot-primitives = { path = "polkadot/primitives", default-features = false } polkadot-primitives-test-helpers = { path = "polkadot/primitives/test-helpers" } diff --git a/bridges/testing/README.md b/bridges/testing/README.md index d2b461fa2ed4..bd467a410d01 100644 --- a/bridges/testing/README.md +++ b/bridges/testing/README.md @@ -10,22 +10,21 @@ To start those tests, you need to: - download latest [zombienet release](https://github.com/paritytech/zombienet/releases); - build Polkadot binary by running `cargo build -p polkadot --release --features fast-runtime` command in the - [`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; +[`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; -- build Polkadot Parachain binary by running - `cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --features binary` - command in the [`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; +- build Polkadot Parachain binary by running `cargo build -p polkadot-parachain-bin --release` command in the +[`polkadot-sdk`](https://github.com/paritytech/polkadot-sdk) repository clone; - ensure that you have [`node`](https://nodejs.org/en) installed. Additionally, we'll need globally installed - `polkadot/api-cli` package (use `npm install -g @polkadot/api-cli@beta` to install it); +`polkadot/api-cli` package (use `npm install -g @polkadot/api-cli@beta` to install it); - build Substrate relay by running `cargo build -p substrate-relay --release` command in the - [`parity-bridges-common`](https://github.com/paritytech/parity-bridges-common) repository clone. +[`parity-bridges-common`](https://github.com/paritytech/parity-bridges-common) repository clone. - copy fresh `substrate-relay` binary, built in previous point, to the `~/local_bridge_testing/bin/substrate-relay`; - change the `POLKADOT_SDK_PATH` and `ZOMBIENET_BINARY_PATH` (and ensure that the nearby variables - have correct values) in the `./run-tests.sh`. +have correct values) in the `./run-tests.sh`. After that, you could run tests with the `./run-tests.sh` command. Hopefully, it'll show the "All tests have completed successfully" message in the end. Otherwise, it'll print paths to zombienet diff --git a/cumulus/README.md b/cumulus/README.md index 25fea88ecad1..7e145ad7b4ab 100644 --- a/cumulus/README.md +++ b/cumulus/README.md @@ -4,8 +4,7 @@ This repository contains both the Cumulus SDK and also specific chains implemented on top of this SDK. -If you only want to run a **Polkadot Parachain Node**, check out -our [container section](./docs/contributor/container.md). +If you only want to run a **Polkadot Parachain Node**, check out our [container section](./docs/contributor/container.md). ## Cumulus SDK @@ -23,8 +22,7 @@ Cumulus clouds are shaped sort of like dots; together they form a system that is ### Consensus -[ -`parachain-consensus`](https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/client/consensus/common/src/parachain_consensus.rs) +[`parachain-consensus`](https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/client/consensus/common/src/parachain_consensus.rs) is a [consensus engine](https://docs.substrate.io/v3/advanced/consensus) for Substrate that follows a Polkadot [relay chain](https://wiki.polkadot.network/docs/en/learn-architecture#relay-chain). This will run a Polkadot node internally, and dictate to the client and synchronization algorithms which chain to follow, @@ -39,16 +37,13 @@ You may run `polkadot-parachain` locally after building it or using one of the c [here](./docs/contributor/container.md). ### Relay Chain Interaction - To operate a parachain node, a connection to the corresponding relay chain is necessary. This can be achieved in one of three ways: - 1. Run a full relay chain node within the parachain node (default) 2. Connect to an external relay chain node via WebSocket RPC 3. Run a light client for the relay chain #### In-process Relay Chain Node - If an external relay chain node is not specified (default behavior), then a full relay chain node is spawned within the same process. @@ -56,7 +51,6 @@ This node has all of the typical components of a regular Polkadot node and will to work. ##### Example command - ```bash polkadot-parachain \ --chain parachain-chainspec.json \ @@ -66,7 +60,6 @@ polkadot-parachain \ ``` #### External Relay Chain Node - An external relay chain node is connected via WebsSocket RPC by using the `--relay-chain-rpc-urls` command line argument. This option accepts one or more space-separated WebSocket URLs to a full relay chain node. By default, only the first URL will be used, with the rest as a backup in case the connection to the first node is lost. @@ -92,7 +85,6 @@ polkadot-parachain \ ``` #### Relay Chain Light Client - An internal relay chain light client provides a fast and lightweight approach for connecting to the relay chain network. It provides relay chain notifications and facilitates runtime calls. @@ -103,8 +95,8 @@ relay chain arguments. node in-process. Even though they lack the majority of normal Polkadot subsystems, they will still need to connect directly to the relay chain network. -##### Example command +##### Example command ```bash polkadot-parachain \ --chain parachain-chainspec.json \ @@ -115,7 +107,6 @@ polkadot-parachain \ ``` ## Installation and Setup - Before building Cumulus SDK based nodes / runtimes prepare your environment by following Substrate [installation instructions](https://docs.substrate.io/main-docs/install/). @@ -123,24 +114,19 @@ To launch a local network, you can use [zombienet](https://github.com/paritytech experimentation or follow the [manual setup](#manual-setup). ### Zombienet - We use Zombienet to spin up networks for integration tests and local networks. Follow [these installation steps](https://github.com/paritytech/zombienet#requirements-by-provider) to set it up on your machine. A simple network specification with two relay chain nodes and one collator is located at [zombienet/examples/small_network.toml](zombienet/examples/small_network.toml). #### Which provider should I use? - Zombienet offers multiple providers to run networks. Choose the one that best fits your needs: - - **Podman:** Choose this if you want to spin up a network quick and easy. - **Native:** Choose this if you want to develop and deploy your changes. Requires compilation of the binaries. - **Kubernetes:** Choose this for advanced use-cases or running on cloud-infrastructure. #### How to run - To run the example network, use the following commands: - ```bash # Podman provider zombienet --provider podman spawn ./zombienet/examples/small_network.toml @@ -150,7 +136,6 @@ zombienet --provider native spawn ./zombienet/examples/small_network.toml ``` ### Manual Setup - #### Launch the Relay Chain ```bash @@ -174,7 +159,7 @@ cargo build --release -p polkadot ```bash # Compile -cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --features binary +cargo build --release -p polkadot-parachain-bin # Export genesis state ./target/release/polkadot-parachain export-genesis-state > genesis-state @@ -199,6 +184,7 @@ cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --featu ![image](https://user-images.githubusercontent.com/2915325/99548884-1be13580-2987-11eb-9a8b-20be658d34f9.png) + ## Asset Hub 🪙 This repository also contains the Asset Hub runtimes. Asset Hub is a system parachain providing an asset store for the @@ -230,7 +216,6 @@ See [the `contracts-rococo` readme](parachains/runtimes/contracts/contracts-roco See [the `bridge-hubs` readme](parachains/runtimes/bridge-hubs/README.md) for details. ## Rococo 👑 - [Rococo](https://polkadot.js.org/apps/?rpc=wss://rococo-rpc.polkadot.io) is becoming a [Community Parachain Testbed](https://polkadot.network/blog/rococo-revamp-becoming-a-community-parachain-testbed/) for parachain teams in the Polkadot ecosystem. It supports multiple parachains with the differentiation of long-term connections and recurring @@ -246,6 +231,7 @@ the relay chain for a parachain. To run a Rococo collator you will need to compile the following binary: + ```bash cargo build --release --locked --bin polkadot-parachain ``` diff --git a/cumulus/parachains/runtimes/bridge-hubs/README.md b/cumulus/parachains/runtimes/bridge-hubs/README.md index 93639d7af348..a9f1f98d142d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/README.md +++ b/cumulus/parachains/runtimes/bridge-hubs/README.md @@ -1,28 +1,27 @@ - [Bridge-hub Parachains](#bridge-hub-parachains) - - [Requirements for local run/testing](#requirements-for-local-runtesting) - - [How to test local Rococo <-> Westend bridge](#how-to-test-local-rococo---westend-bridge) - - [Run Rococo/Westend chains with zombienet](#run-rococowestend-chains-with-zombienet) - - [Init bridge and run relayer between BridgeHubRococo and - BridgeHubWestend](#init-bridge-and-run-relayer-between-bridgehubrococo-and-bridgehubwestend) - - [Initialize configuration for transfer asset over bridge - (ROCs/WNDs)](#initialize-configuration-for-transfer-asset-over-bridge-rocswnds) - - [Send messages - transfer asset over bridge (ROCs/WNDs)](#send-messages---transfer-asset-over-bridge-rocswnds) - - [Claim relayer's rewards on BridgeHubRococo and - BridgeHubWestend](#claim-relayers-rewards-on-bridgehubrococo-and-bridgehubwestend) - - [How to test local BridgeHubKusama/BridgeHubPolkadot](#how-to-test-local-bridgehubkusamabridgehubpolkadot) + - [Requirements for local run/testing](#requirements-for-local-runtesting) + - [How to test local Rococo <-> Westend bridge](#how-to-test-local-rococo---westend-bridge) + - [Run Rococo/Westend chains with zombienet](#run-rococowestend-chains-with-zombienet) + - [Init bridge and run relayer between BridgeHubRococo and + BridgeHubWestend](#init-bridge-and-run-relayer-between-bridgehubrococo-and-bridgehubwestend) + - [Initialize configuration for transfer asset over bridge + (ROCs/WNDs)](#initialize-configuration-for-transfer-asset-over-bridge-rocswnds) + - [Send messages - transfer asset over bridge (ROCs/WNDs)](#send-messages---transfer-asset-over-bridge-rocswnds) + - [Claim relayer's rewards on BridgeHubRococo and + BridgeHubWestend](#claim-relayers-rewards-on-bridgehubrococo-and-bridgehubwestend) + - [How to test local BridgeHubKusama/BridgeHubPolkadot](#how-to-test-local-bridgehubkusamabridgehubpolkadot) # Bridge-hub Parachains _BridgeHub(s)_ are **_system parachains_** that will house trustless bridges from the local ecosystem to others. The current trustless bridges planned for the BridgeHub(s) are: - - `BridgeHubPolkadot` system parachain: - 1. Polkadot <-> Kusama bridge - 2. Polkadot <-> Ethereum bridge (Snowbridge) + 1. Polkadot <-> Kusama bridge + 2. Polkadot <-> Ethereum bridge (Snowbridge) - `BridgeHubKusama` system parachain: - 1. Kusama <-> Polkadot bridge - 2. Kusama <-> Ethereum bridge The high-level - responsibilities of each bridge living on BridgeHub: + 1. Kusama <-> Polkadot bridge + 2. Kusama <-> Ethereum bridge The high-level + responsibilities of each bridge living on BridgeHub: - sync finality proofs between relay chains (or equivalent) - sync finality proofs between BridgeHub parachains - pass (XCM) messages between different BridgeHub parachains @@ -77,7 +76,7 @@ cp target/release/substrate-relay ~/local_bridge_testing/bin/substrate-relay # 4. Build cumulus polkadot-parachain binary cd -cargo build --release -p polkadot-parachain-bin --bin polkadot-parachain --features binary +cargo build --release -p polkadot-parachain-bin cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain-asset-hub ``` @@ -107,11 +106,9 @@ POLKADOT_PARACHAIN_BINARY=~/local_bridge_testing/bin/polkadot-parachain \ ### Init bridge and run relayer between BridgeHubRococo and BridgeHubWestend **Accounts of BridgeHub parachains:** - - `Bob` is pallet owner of all bridge pallets #### Run with script - ``` cd @@ -119,14 +116,12 @@ cd ``` **Check relay-chain headers relaying:** - - Rococo parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8943#/chainstate - Pallet: **bridgeWestendGrandpa** - Keys: **bestFinalized()** - Westend parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8945#/chainstate - Pallet: **bridgeRococoGrandpa** - Keys: **bestFinalized()** **Check parachain headers relaying:** - - Rococo parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8943#/chainstate - Pallet: **bridgeWestendParachains** - Keys: **parasInfo(None)** - Westend parachain: - https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A8945#/chainstate - Pallet: @@ -135,10 +130,8 @@ cd ### Initialize configuration for transfer asset over bridge (ROCs/WNDs) This initialization does several things: - - creates `ForeignAssets` for wrappedROCs/wrappedWNDs - drips SA for AssetHubRococo on AssetHubWestend (and vice versa) which holds reserved assets on source chains - ``` cd @@ -151,14 +144,12 @@ cd ### Send messages - transfer asset over bridge (ROCs/WNDs) Do reserve-backed transfers: - ``` cd # ROCs from Rococo's Asset Hub to Westend's. ./bridges/testing/environments/rococo-westend/bridges_rococo_westend.sh reserve-transfer-assets-from-asset-hub-rococo-local ``` - ``` cd @@ -167,26 +158,19 @@ cd ``` - open explorers: (see zombienets) - - AssetHubRococo (see events `xcmpQueue.XcmpMessageSent`, - `polkadotXcm.Attempted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9910#/explorer - - BridgeHubRococo (see - `bridgeWestendMessages.MessageAccepted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer - - BridgeHubWestend (see `bridgeRococoMessages.MessagesReceived`, - `xcmpQueue.XcmpMessageSent`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer - - AssetHubWestend (see `foreignAssets.Issued`, - `xcmpQueue.Success`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9010#/explorer - - BridgeHubRocococ (see - `bridgeWestendMessages.MessagesDelivered`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer + - AssetHubRococo (see events `xcmpQueue.XcmpMessageSent`, `polkadotXcm.Attempted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9910#/explorer + - BridgeHubRococo (see `bridgeWestendMessages.MessageAccepted`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer + - BridgeHubWestend (see `bridgeRococoMessages.MessagesReceived`, `xcmpQueue.XcmpMessageSent`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer + - AssetHubWestend (see `foreignAssets.Issued`, `xcmpQueue.Success`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9010#/explorer + - BridgeHubRocococ (see `bridgeWestendMessages.MessagesDelivered`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer Do reserve withdraw transfers: (when previous is finished) - ``` cd # wrappedWNDs from Rococo's Asset Hub to Westend's. ./bridges/testing/environments/rococo-westend/bridges_rococo_westend.sh withdraw-reserve-assets-from-asset-hub-rococo-local ``` - ``` cd @@ -197,7 +181,6 @@ cd ### Claim relayer's rewards on BridgeHubRococo and BridgeHubWestend **Accounts of BridgeHub parachains:** - - `//Charlie` is relayer account on BridgeHubRococo - `//Charlie` is relayer account on BridgeHubWestend @@ -212,10 +195,8 @@ cd ``` - open explorers: (see zombienets) - - BridgeHubRococo (see 2x - `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer - - BridgeHubWestend (see 2x - `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer + - BridgeHubRococo (see 2x `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8943#/explorer + - BridgeHubWestend (see 2x `bridgeRelayers.RewardPaid`) https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:8945#/explorer ## How to test local BridgeHubKusama/BridgeHubPolkadot diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 7992e724fad8..735e30b2c75e 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -2,52 +2,41 @@ name = "polkadot-parachain-bin" version = "4.0.0" authors.workspace = true -build = "build.rs" edition.workspace = true -description = "Runs a polkadot parachain node which could be a collator." +description = "Runs a polkadot parachain node" license = "Apache-2.0" [lints] workspace = true -[lib] -path = "src/lib.rs" - [[bin]] name = "polkadot-parachain" path = "src/main.rs" -required-features = ["binary"] [dependencies] -async-trait = { workspace = true } -clap = { features = ["derive"], workspace = true } -codec = { workspace = true, default-features = true } color-eyre = { workspace = true } -color-print = { workspace = true } -futures = { workspace = true } hex-literal = { workspace = true, default-features = true } log = { workspace = true, default-features = true } serde = { features = ["derive"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } -docify = { workspace = true } # Local -rococo-parachain-runtime = { optional = true, workspace = true } -shell-runtime = { optional = true, workspace = true } -glutton-westend-runtime = { optional = true, workspace = true } -seedling-runtime = { optional = true, workspace = true } -asset-hub-rococo-runtime = { optional = true, workspace = true, default-features = true } -asset-hub-westend-runtime = { optional = true, workspace = true } -collectives-westend-runtime = { optional = true, workspace = true } -contracts-rococo-runtime = { optional = true, workspace = true } -bridge-hub-rococo-runtime = { optional = true, workspace = true, default-features = true } -coretime-rococo-runtime = { optional = true, workspace = true } -coretime-westend-runtime = { optional = true, workspace = true } -bridge-hub-westend-runtime = { optional = true, workspace = true, default-features = true } -penpal-runtime = { optional = true, workspace = true } -jsonrpsee = { features = ["server"], workspace = true } -people-rococo-runtime = { optional = true, workspace = true } -people-westend-runtime = { optional = true, workspace = true } +polkadot-parachain-lib = { workspace = true } +rococo-parachain-runtime = { workspace = true } +shell-runtime = { workspace = true } +glutton-westend-runtime = { workspace = true } +seedling-runtime = { workspace = true } +asset-hub-rococo-runtime = { workspace = true, default-features = true } +asset-hub-westend-runtime = { workspace = true } +collectives-westend-runtime = { workspace = true } +contracts-rococo-runtime = { workspace = true } +bridge-hub-rococo-runtime = { workspace = true, default-features = true } +coretime-rococo-runtime = { workspace = true } +coretime-westend-runtime = { workspace = true } +bridge-hub-westend-runtime = { workspace = true, default-features = true } +penpal-runtime = { workspace = true } +people-rococo-runtime = { workspace = true } +people-westend-runtime = { workspace = true } parachains-common = { workspace = true, default-features = true } testnet-parachains-constants = { features = [ "rococo", @@ -55,150 +44,69 @@ testnet-parachains-constants = { features = [ ], workspace = true } # Substrate -frame-benchmarking = { workspace = true, default-features = true } -frame-benchmarking-cli = { workspace = true, default-features = true } sp-runtime = { workspace = true } -sp-io = { workspace = true, default-features = true } sp-core = { workspace = true, default-features = true } -sp-session = { workspace = true, default-features = true } -frame-try-runtime = { optional = true, workspace = true, default-features = true } -sc-consensus = { workspace = true, default-features = true } -sp-tracing = { workspace = true, default-features = true } -frame-support = { workspace = true, default-features = true } sc-cli = { workspace = true, default-features = true } -sc-client-api = { workspace = true, default-features = true } -sc-executor = { workspace = true, default-features = true } sc-service = { workspace = true, default-features = true } -sc-telemetry = { workspace = true, default-features = true } -sc-transaction-pool = { workspace = true, default-features = true } -sp-transaction-pool = { workspace = true, default-features = true } -sc-network = { workspace = true, default-features = true } -sc-network-sync = { workspace = true, default-features = true } -sc-basic-authorship = { workspace = true, default-features = true } -sp-timestamp = { workspace = true, default-features = true } -sp-blockchain = { workspace = true, default-features = true } -sp-genesis-builder = { workspace = true } -sp-block-builder = { workspace = true, default-features = true } -sp-keystore = { workspace = true, default-features = true } sc-chain-spec = { workspace = true, default-features = true } -sc-rpc = { workspace = true, default-features = true } -sp-version = { workspace = true, default-features = true } -sc-tracing = { workspace = true, default-features = true } -sp-offchain = { workspace = true, default-features = true } -frame-system-rpc-runtime-api = { workspace = true, default-features = true } -pallet-transaction-payment = { workspace = true, default-features = true } -pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = true } -sp-std = { workspace = true, default-features = true } -sp-inherents = { workspace = true, default-features = true } -sp-api = { workspace = true, default-features = true } -sp-consensus-aura = { workspace = true, default-features = true } -sc-sysinfo = { workspace = true, default-features = true } -prometheus-endpoint = { workspace = true, default-features = true } -sc-transaction-pool-api = { workspace = true, default-features = true } -substrate-frame-rpc-system = { workspace = true, default-features = true } -pallet-transaction-payment-rpc = { workspace = true, default-features = true } -substrate-state-trie-migration-rpc = { workspace = true, default-features = true } # Polkadot # Use rococo-native as this is currently the default "local" relay chain -polkadot-cli = { features = ["rococo-native", "westend-native"], workspace = true, default-features = true } -polkadot-primitives = { workspace = true, default-features = true } polkadot-service = { workspace = true, default-features = true } xcm = { workspace = true, default-features = true } # Cumulus -cumulus-client-cli = { workspace = true, default-features = true } -cumulus-client-collator = { workspace = true, default-features = true } -cumulus-client-consensus-aura = { workspace = true, default-features = true } -cumulus-client-consensus-relay-chain = { workspace = true, default-features = true } -cumulus-client-consensus-common = { workspace = true, default-features = true } -cumulus-client-consensus-proposer = { workspace = true, default-features = true } -cumulus-client-parachain-inherent = { workspace = true, default-features = true } -cumulus-client-service = { workspace = true, default-features = true } -cumulus-primitives-aura = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } -cumulus-relay-chain-interface = { workspace = true, default-features = true } [build-dependencies] substrate-build-script-utils = { workspace = true, default-features = true } -[dev-dependencies] -assert_cmd = { workspace = true } -nix = { features = ["signal"], workspace = true } -tempfile = { workspace = true } -tokio = { version = "1.32.0", features = ["macros", "parking_lot", "time"] } -wait-timeout = { workspace = true } - [features] default = [] -binary = [ - "asset-hub-rococo-runtime", - "asset-hub-westend-runtime", - "bridge-hub-rococo-runtime", - "bridge-hub-westend-runtime", - "collectives-westend-runtime", - "contracts-rococo-runtime", - "coretime-rococo-runtime", - "coretime-westend-runtime", - "glutton-westend-runtime", - "penpal-runtime", - "people-rococo-runtime", - "people-westend-runtime", - "rococo-parachain-runtime", - "seedling-runtime", - "shell-runtime", -] runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", - "frame-benchmarking-cli/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", "parachains-common/runtime-benchmarks", - "polkadot-cli/runtime-benchmarks", - "polkadot-primitives/runtime-benchmarks", + "polkadot-parachain-lib/runtime-benchmarks", "polkadot-service/runtime-benchmarks", "sc-service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "asset-hub-rococo-runtime?/runtime-benchmarks", - "asset-hub-westend-runtime?/runtime-benchmarks", - "bridge-hub-rococo-runtime?/runtime-benchmarks", - "bridge-hub-westend-runtime?/runtime-benchmarks", - "collectives-westend-runtime?/runtime-benchmarks", - "contracts-rococo-runtime?/runtime-benchmarks", - "coretime-rococo-runtime?/runtime-benchmarks", - "coretime-westend-runtime?/runtime-benchmarks", - "glutton-westend-runtime?/runtime-benchmarks", - "penpal-runtime?/runtime-benchmarks", - "people-rococo-runtime?/runtime-benchmarks", - "people-westend-runtime?/runtime-benchmarks", - "rococo-parachain-runtime?/runtime-benchmarks", + "asset-hub-rococo-runtime/runtime-benchmarks", + "asset-hub-westend-runtime/runtime-benchmarks", + "bridge-hub-rococo-runtime/runtime-benchmarks", + "bridge-hub-westend-runtime/runtime-benchmarks", + "collectives-westend-runtime/runtime-benchmarks", + "contracts-rococo-runtime/runtime-benchmarks", + "coretime-rococo-runtime/runtime-benchmarks", + "coretime-westend-runtime/runtime-benchmarks", + "glutton-westend-runtime/runtime-benchmarks", + "penpal-runtime/runtime-benchmarks", + "people-rococo-runtime/runtime-benchmarks", + "people-westend-runtime/runtime-benchmarks", + "rococo-parachain-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-transaction-payment/try-runtime", - "polkadot-cli/try-runtime", + "polkadot-parachain-lib/try-runtime", "polkadot-service/try-runtime", "sp-runtime/try-runtime", - "asset-hub-rococo-runtime?/try-runtime", - "asset-hub-westend-runtime?/try-runtime", - "bridge-hub-rococo-runtime?/try-runtime", - "bridge-hub-westend-runtime?/try-runtime", - "collectives-westend-runtime?/try-runtime", - "contracts-rococo-runtime?/try-runtime", - "coretime-rococo-runtime?/try-runtime", - "coretime-westend-runtime?/try-runtime", - "glutton-westend-runtime?/try-runtime", - "penpal-runtime?/try-runtime", - "people-rococo-runtime?/try-runtime", - "people-westend-runtime?/try-runtime", - "shell-runtime?/try-runtime", + "asset-hub-rococo-runtime/try-runtime", + "asset-hub-westend-runtime/try-runtime", + "bridge-hub-rococo-runtime/try-runtime", + "bridge-hub-westend-runtime/try-runtime", + "collectives-westend-runtime/try-runtime", + "contracts-rococo-runtime/try-runtime", + "coretime-rococo-runtime/try-runtime", + "coretime-westend-runtime/try-runtime", + "glutton-westend-runtime/try-runtime", + "penpal-runtime/try-runtime", + "people-rococo-runtime/try-runtime", + "people-westend-runtime/try-runtime", + "shell-runtime/try-runtime", ] fast-runtime = [ - "bridge-hub-rococo-runtime?/fast-runtime", - "bridge-hub-westend-runtime?/fast-runtime", - "coretime-rococo-runtime?/fast-runtime", - "coretime-westend-runtime?/fast-runtime", + "bridge-hub-rococo-runtime/fast-runtime", + "bridge-hub-westend-runtime/fast-runtime", + "coretime-rococo-runtime/fast-runtime", + "coretime-westend-runtime/fast-runtime", ] diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml new file mode 100644 index 000000000000..3f69d1579ea8 --- /dev/null +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml @@ -0,0 +1,115 @@ +[package] +name = "polkadot-parachain-lib" +version = "0.0.1" +authors.workspace = true +build = "build.rs" +edition.workspace = true +description = "Helper library that can be used to build a parachain node" +license = "Apache-2.0" + +[lints] +workspace = true + +[lib] +path = "src/lib.rs" + +[dependencies] +async-trait = { workspace = true } +clap = { features = ["derive"], workspace = true } +codec = { workspace = true, default-features = true } +color-print = { workspace = true } +futures = { workspace = true } +log = { workspace = true, default-features = true } +serde = { features = ["derive"], workspace = true, default-features = true } +serde_json = { workspace = true, default-features = true } +docify = { workspace = true } + +# Local +jsonrpsee = { features = ["server"], workspace = true } +parachains-common = { workspace = true, default-features = true } + +# Substrate +frame-benchmarking = { workspace = true, default-features = true } +frame-benchmarking-cli = { workspace = true, default-features = true } +sp-runtime = { workspace = true } +sp-core = { workspace = true, default-features = true } +sp-session = { workspace = true, default-features = true } +frame-try-runtime = { optional = true, workspace = true, default-features = true } +sc-consensus = { workspace = true, default-features = true } +frame-support = { workspace = true, default-features = true } +sc-cli = { workspace = true, default-features = true } +sc-client-api = { workspace = true, default-features = true } +sc-executor = { workspace = true, default-features = true } +sc-service = { workspace = true, default-features = true } +sc-telemetry = { workspace = true, default-features = true } +sc-transaction-pool = { workspace = true, default-features = true } +sp-transaction-pool = { workspace = true, default-features = true } +sc-network = { workspace = true, default-features = true } +sc-basic-authorship = { workspace = true, default-features = true } +sp-timestamp = { workspace = true, default-features = true } +sp-genesis-builder = { workspace = true } +sp-block-builder = { workspace = true, default-features = true } +sp-keystore = { workspace = true, default-features = true } +sc-chain-spec = { workspace = true, default-features = true } +sc-rpc = { workspace = true, default-features = true } +sp-version = { workspace = true, default-features = true } +sc-tracing = { workspace = true, default-features = true } +frame-system-rpc-runtime-api = { workspace = true, default-features = true } +pallet-transaction-payment = { workspace = true, default-features = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = true } +sp-inherents = { workspace = true, default-features = true } +sp-api = { workspace = true, default-features = true } +sp-consensus-aura = { workspace = true, default-features = true } +sc-sysinfo = { workspace = true, default-features = true } +prometheus-endpoint = { workspace = true, default-features = true } +substrate-frame-rpc-system = { workspace = true, default-features = true } +pallet-transaction-payment-rpc = { workspace = true, default-features = true } +substrate-state-trie-migration-rpc = { workspace = true, default-features = true } + +# Polkadot +# Use rococo-native as this is currently the default "local" relay chain +polkadot-cli = { features = ["rococo-native", "westend-native"], workspace = true, default-features = true } +polkadot-primitives = { workspace = true, default-features = true } + +# Cumulus +cumulus-client-cli = { workspace = true, default-features = true } +cumulus-client-collator = { workspace = true, default-features = true } +cumulus-client-consensus-aura = { workspace = true, default-features = true } +cumulus-client-consensus-relay-chain = { workspace = true, default-features = true } +cumulus-client-consensus-common = { workspace = true, default-features = true } +cumulus-client-consensus-proposer = { workspace = true, default-features = true } +cumulus-client-parachain-inherent = { workspace = true, default-features = true } +cumulus-client-service = { workspace = true, default-features = true } +cumulus-primitives-aura = { workspace = true, default-features = true } +cumulus-primitives-core = { workspace = true, default-features = true } +cumulus-relay-chain-interface = { workspace = true, default-features = true } + +[build-dependencies] +substrate-build-script-utils = { workspace = true, default-features = true } + +[dev-dependencies] +assert_cmd = { workspace = true } +nix = { features = ["signal"], workspace = true } +tokio = { version = "1.32.0", features = ["macros", "parking_lot", "time"] } +wait-timeout = { workspace = true } + +[features] +default = [] +runtime-benchmarks = [ + "cumulus-primitives-core/runtime-benchmarks", + "frame-benchmarking-cli/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "polkadot-cli/runtime-benchmarks", + "polkadot-primitives/runtime-benchmarks", + "sc-service/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-try-runtime/try-runtime", + "pallet-transaction-payment/try-runtime", + "polkadot-cli/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/cumulus/polkadot-parachain/build.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/build.rs similarity index 100% rename from cumulus/polkadot-parachain/build.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/build.rs diff --git a/cumulus/polkadot-parachain/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs similarity index 100% rename from cumulus/polkadot-parachain/src/cli.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs similarity index 100% rename from cumulus/polkadot-parachain/src/command.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs diff --git a/cumulus/polkadot-parachain/src/common/aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/aura.rs similarity index 100% rename from cumulus/polkadot-parachain/src/common/aura.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/aura.rs diff --git a/cumulus/polkadot-parachain/src/common/chain_spec.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs similarity index 100% rename from cumulus/polkadot-parachain/src/common/chain_spec.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs diff --git a/cumulus/polkadot-parachain/src/common/mod.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs similarity index 100% rename from cumulus/polkadot-parachain/src/common/mod.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs diff --git a/cumulus/polkadot-parachain/src/common/runtime.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs similarity index 100% rename from cumulus/polkadot-parachain/src/common/runtime.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs similarity index 100% rename from cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs similarity index 100% rename from cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/mod.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs similarity index 100% rename from cumulus/polkadot-parachain/src/fake_runtime_api/mod.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs diff --git a/cumulus/polkadot-parachain/src/lib.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs similarity index 92% rename from cumulus/polkadot-parachain/src/lib.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs index 6140b2687264..1bd091b43d5c 100644 --- a/cumulus/polkadot-parachain/src/lib.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs @@ -31,6 +31,10 @@ //! node's `CLI` and the actual chain config associated with each one. //! - a runtime resolver (an implementation of [`chain_spec::RuntimeResolver`]): this can be used //! for providing the parameters of the runtime that is associated with each of the chain specs +//! +//! ## Examples +//! +//! For examples, see the `polkadot-parachain` crate. mod cli; mod command; @@ -39,10 +43,8 @@ mod fake_runtime_api; mod rpc; mod service; -use crate::chain_spec::GenericChainSpec; pub use command::{run, CommandConfig}; pub use common::{ - chain_spec, - runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver}, + chain_spec, + runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver}, }; -use sc_chain_spec::ChainSpec; diff --git a/cumulus/polkadot-parachain/src/rpc.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/rpc.rs similarity index 100% rename from cumulus/polkadot-parachain/src/rpc.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/rpc.rs diff --git a/cumulus/polkadot-parachain/src/service.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs similarity index 100% rename from cumulus/polkadot-parachain/src/service.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs diff --git a/cumulus/polkadot-parachain/tests/benchmark_storage_works.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/benchmark_storage_works.rs similarity index 100% rename from cumulus/polkadot-parachain/tests/benchmark_storage_works.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/benchmark_storage_works.rs diff --git a/cumulus/polkadot-parachain/tests/common.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/common.rs similarity index 100% rename from cumulus/polkadot-parachain/tests/common.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/common.rs diff --git a/cumulus/polkadot-parachain/tests/polkadot_argument_parsing.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/polkadot_argument_parsing.rs similarity index 100% rename from cumulus/polkadot-parachain/tests/polkadot_argument_parsing.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/polkadot_argument_parsing.rs diff --git a/cumulus/polkadot-parachain/tests/polkadot_mdns_issue.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/polkadot_mdns_issue.rs similarity index 100% rename from cumulus/polkadot-parachain/tests/polkadot_mdns_issue.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/polkadot_mdns_issue.rs diff --git a/cumulus/polkadot-parachain/tests/purge_chain_works.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/purge_chain_works.rs similarity index 100% rename from cumulus/polkadot-parachain/tests/purge_chain_works.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/purge_chain_works.rs diff --git a/cumulus/polkadot-parachain/tests/running_the_node_and_interrupt.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/running_the_node_and_interrupt.rs similarity index 100% rename from cumulus/polkadot-parachain/tests/running_the_node_and_interrupt.rs rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/tests/running_the_node_and_interrupt.rs diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 14c552165519..f6bf6375a353 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -18,7 +18,7 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, S use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{AccountId, AuraId, Balance as AssetHubBalance}; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 4ea88501c60c..754bd851b40a 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -17,7 +17,7 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}; use cumulus_primitives_core::ParaId; use parachains_common::Balance as BridgeHubBalance; -use polkadot_parachain_bin::chain_spec::GenericChainSpec; +use polkadot_parachain_lib::chain_spec::GenericChainSpec; use sc_chain_spec::ChainSpec; use sp_core::sr25519; use std::str::FromStr; @@ -132,7 +132,7 @@ pub mod rococo { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; use crate::chain_spec::SAFE_XCM_VERSION; use parachains_common::{AccountId, AuraId}; - use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; + use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use super::BridgeHubBalance; @@ -258,7 +258,7 @@ pub mod westend { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; use crate::chain_spec::SAFE_XCM_VERSION; use parachains_common::{AccountId, AuraId}; - use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; + use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use super::BridgeHubBalance; diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index b44cca235546..865a2a917086 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -17,7 +17,7 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId, Balance as CollectivesBalance}; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs index 00abc12c8074..eb10a43ffbea 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -18,7 +18,7 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, S use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{AccountId, AuraId}; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index b537067ab274..742f41f39e9d 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -15,7 +15,7 @@ // along with Cumulus. If not, see . use cumulus_primitives_core::ParaId; -use polkadot_parachain_bin::chain_spec::GenericChainSpec; +use polkadot_parachain_lib::chain_spec::GenericChainSpec; use sc_chain_spec::{ChainSpec, ChainType}; use std::{borrow::Cow, str::FromStr}; @@ -149,7 +149,7 @@ pub mod rococo { get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId, Balance}; - use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; + use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use sp_core::sr25519; @@ -247,7 +247,7 @@ pub mod westend { get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId, Balance}; - use polkadot_parachain_bin::chain_spec::Extensions; + use polkadot_parachain_lib::chain_spec::Extensions; use sp_core::sr25519; pub(crate) const CORETIME_WESTEND: &str = "coretime-westend"; diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index e8f6e2d475a0..136411b93e8b 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -17,7 +17,7 @@ use crate::chain_spec::get_account_id_from_seed; use cumulus_primitives_core::ParaId; use parachains_common::AuraId; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index 4e39bd60f595..d60fdeffce69 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -16,7 +16,7 @@ use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, Signature}; -use polkadot_parachain_bin::{ +use polkadot_parachain_lib::{ chain_spec::{GenericChainSpec, LoadSpec}, AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT, }; diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index f3ed5cc6111c..5645bf06b67b 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -17,7 +17,7 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId}; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/people.rs b/cumulus/polkadot-parachain/src/chain_spec/people.rs index 385f67f52362..3c1150d95422 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/people.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/people.rs @@ -16,7 +16,7 @@ use cumulus_primitives_core::ParaId; use parachains_common::Balance as PeopleBalance; -use polkadot_parachain_bin::chain_spec::GenericChainSpec; +use polkadot_parachain_lib::chain_spec::GenericChainSpec; use sc_chain_spec::ChainSpec; use std::str::FromStr; @@ -124,7 +124,7 @@ pub mod rococo { get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId}; - use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; + use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use sp_core::sr25519; @@ -234,7 +234,7 @@ pub mod westend { get_account_id_from_seed, get_collator_keys_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, AuraId}; - use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; + use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index eba236522aff..9f4a162e67f8 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -20,7 +20,7 @@ use crate::chain_spec::{get_from_seed, SAFE_XCM_VERSION}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::AccountId; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use polkadot_service::chain_spec::get_account_id_from_seed; use rococo_parachain_runtime::AuraId; use sc_chain_spec::ChainType; diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs index b70be5552122..a104b58db5d2 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -17,7 +17,7 @@ use crate::chain_spec::get_account_id_from_seed; use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, AuraId}; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::sr25519; diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index 0aae2003065a..0a7816ab3193 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -16,7 +16,7 @@ use cumulus_primitives_core::ParaId; use parachains_common::AuraId; -use polkadot_parachain_bin::chain_spec::{Extensions, GenericChainSpec}; +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use super::get_collator_keys_from_seed; diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index 0186dc6eae9f..353999539bf0 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -21,7 +21,7 @@ mod chain_spec; -use polkadot_parachain_bin::{run, CommandConfig}; +use polkadot_parachain_lib::{run, CommandConfig}; fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; diff --git a/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile b/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile index 31c86e51854d..b56b8c1a1ef8 100644 --- a/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile +++ b/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile @@ -5,7 +5,7 @@ FROM docker.io/paritytech/ci-linux:production as builder WORKDIR /cumulus COPY . /cumulus -RUN cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary +RUN cargo build --release --locked -p polkadot-parachain # This is the 2nd stage: a very small image where we copy the Polkadot binary." FROM docker.io/library/ubuntu:20.04 diff --git a/docker/dockerfiles/test-parachain-collator.Dockerfile b/docker/dockerfiles/test-parachain-collator.Dockerfile index 2bc10da37b77..116520284dd3 100644 --- a/docker/dockerfiles/test-parachain-collator.Dockerfile +++ b/docker/dockerfiles/test-parachain-collator.Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/paritytech/ci-linux:production as builder WORKDIR /cumulus COPY . /cumulus -RUN cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary +RUN cargo build --release --locked -p polkadot-parachain # the collator stage is normally built once, cached, and then ignored, but can # be specified with the --target build flag. This adds some extra tooling to the diff --git a/docs/contributor/container.md b/docs/contributor/container.md index 5a789d4d37de..ec51b8b9d7cc 100644 --- a/docs/contributor/container.md +++ b/docs/contributor/container.md @@ -25,7 +25,7 @@ docker run --rm -it \ -w /polkadot-sdk \ -v $(pwd):/polkadot-sdk \ docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408 \ - cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain --features binary + cargo build --release --locked -p polkadot-parachain-bin --bin polkadot-parachain sudo chown -R $(id -u):$(id -g) target/ ``` diff --git a/scripts/lib/bench-all-cumulus.sh b/scripts/lib/bench-all-cumulus.sh index e1db2e97165b..f4c2a35c6b6b 100755 --- a/scripts/lib/bench-all-cumulus.sh +++ b/scripts/lib/bench-all-cumulus.sh @@ -75,7 +75,7 @@ run_cumulus_bench() { echo "[+] Compiling benchmarks..." -cargo build --profile $profile --locked --features=runtime-benchmarks -p polkadot-parachain-bin --features binary +cargo build --profile $profile --locked --features=runtime-benchmarks -p polkadot-parachain-bin # Run benchmarks for all pallets of a given runtime if runtime argument provided get_arg optional --runtime "$@" diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 302d5413521a..2bfed05cd178 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -330,7 +330,7 @@ runtime-benchmarks = [ "parachains-common?/runtime-benchmarks", "polkadot-cli?/runtime-benchmarks", "polkadot-node-metrics?/runtime-benchmarks", - "polkadot-parachain-bin?/runtime-benchmarks", + "polkadot-parachain-lib?/runtime-benchmarks", "polkadot-parachain-primitives?/runtime-benchmarks", "polkadot-primitives?/runtime-benchmarks", "polkadot-runtime-common?/runtime-benchmarks", @@ -460,7 +460,7 @@ try-runtime = [ "pallet-xcm-bridge-hub?/try-runtime", "pallet-xcm?/try-runtime", "polkadot-cli?/try-runtime", - "polkadot-parachain-bin?/try-runtime", + "polkadot-parachain-lib?/try-runtime", "polkadot-runtime-common?/try-runtime", "polkadot-runtime-parachains?/try-runtime", "polkadot-sdk-frame?/try-runtime", @@ -757,7 +757,7 @@ runtime = [ "xcm-procedural", "xcm-runtime-apis", ] -node = ["asset-test-utils", "bridge-hub-test-utils", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", "cumulus-client-consensus-common", "cumulus-client-consensus-proposer", "cumulus-client-consensus-relay-chain", "cumulus-client-network", "cumulus-client-parachain-inherent", "cumulus-client-pov-recovery", "cumulus-client-service", "cumulus-relay-chain-inprocess-interface", "cumulus-relay-chain-interface", "cumulus-relay-chain-minimal-node", "cumulus-relay-chain-rpc-interface", "cumulus-test-relay-sproof-builder", "emulated-integration-tests-common", "fork-tree", "frame-benchmarking-cli", "frame-remote-externalities", "frame-support-procedural-tools", "generate-bags", "mmr-gadget", "mmr-rpc", "pallet-contracts-mock-network", "pallet-transaction-payment-rpc", "parachains-runtimes-test-utils", "polkadot-approval-distribution", "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", "polkadot-cli", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-erasure-coding", "polkadot-gossip-support", "polkadot-network-bridge", "polkadot-node-collation-generation", "polkadot-node-core-approval-voting", "polkadot-node-core-av-store", "polkadot-node-core-backing", "polkadot-node-core-bitfield-signing", "polkadot-node-core-candidate-validation", "polkadot-node-core-chain-api", "polkadot-node-core-chain-selection", "polkadot-node-core-dispute-coordinator", "polkadot-node-core-parachains-inherent", "polkadot-node-core-prospective-parachains", "polkadot-node-core-provisioner", "polkadot-node-core-pvf", "polkadot-node-core-pvf-checker", "polkadot-node-core-pvf-common", "polkadot-node-core-pvf-execute-worker", "polkadot-node-core-pvf-prepare-worker", "polkadot-node-core-runtime-api", "polkadot-node-jaeger", "polkadot-node-metrics", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-parachain-bin", "polkadot-rpc", "polkadot-service", "polkadot-statement-distribution", "polkadot-statement-table", "sc-allocator", "sc-authority-discovery", "sc-basic-authorship", "sc-block-builder", "sc-chain-spec", "sc-cli", "sc-client-api", "sc-client-db", "sc-consensus", "sc-consensus-aura", "sc-consensus-babe", "sc-consensus-babe-rpc", "sc-consensus-beefy", "sc-consensus-beefy-rpc", "sc-consensus-epochs", "sc-consensus-grandpa", "sc-consensus-grandpa-rpc", "sc-consensus-manual-seal", "sc-consensus-pow", "sc-consensus-slots", "sc-executor", "sc-executor-common", "sc-executor-polkavm", "sc-executor-wasmtime", "sc-informant", "sc-keystore", "sc-mixnet", "sc-network", "sc-network-common", "sc-network-gossip", "sc-network-light", "sc-network-statement", "sc-network-sync", "sc-network-transactions", "sc-network-types", "sc-offchain", "sc-proposer-metrics", "sc-rpc", "sc-rpc-api", "sc-rpc-server", "sc-rpc-spec-v2", "sc-service", "sc-state-db", "sc-statement-store", "sc-storage-monitor", "sc-sync-state-rpc", "sc-sysinfo", "sc-telemetry", "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", "sc-utils", "snowbridge-runtime-test-common", "sp-blockchain", "sp-consensus", "sp-core-hashing", "sp-core-hashing-proc-macro", "sp-database", "sp-maybe-compressed-blob", "sp-panic-handler", "sp-rpc", "staging-chain-spec-builder", "staging-node-inspect", "staging-tracking-allocator", "std", "subkey", "substrate-build-script-utils", "substrate-frame-rpc-support", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-rpc-client", "substrate-state-trie-migration-rpc", "substrate-wasm-builder", "tracing-gum", "xcm-emulator", "xcm-simulator"] +node = ["asset-test-utils", "bridge-hub-test-utils", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", "cumulus-client-consensus-common", "cumulus-client-consensus-proposer", "cumulus-client-consensus-relay-chain", "cumulus-client-network", "cumulus-client-parachain-inherent", "cumulus-client-pov-recovery", "cumulus-client-service", "cumulus-relay-chain-inprocess-interface", "cumulus-relay-chain-interface", "cumulus-relay-chain-minimal-node", "cumulus-relay-chain-rpc-interface", "cumulus-test-relay-sproof-builder", "emulated-integration-tests-common", "fork-tree", "frame-benchmarking-cli", "frame-remote-externalities", "frame-support-procedural-tools", "generate-bags", "mmr-gadget", "mmr-rpc", "pallet-contracts-mock-network", "pallet-transaction-payment-rpc", "parachains-runtimes-test-utils", "polkadot-approval-distribution", "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", "polkadot-cli", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-erasure-coding", "polkadot-gossip-support", "polkadot-network-bridge", "polkadot-node-collation-generation", "polkadot-node-core-approval-voting", "polkadot-node-core-av-store", "polkadot-node-core-backing", "polkadot-node-core-bitfield-signing", "polkadot-node-core-candidate-validation", "polkadot-node-core-chain-api", "polkadot-node-core-chain-selection", "polkadot-node-core-dispute-coordinator", "polkadot-node-core-parachains-inherent", "polkadot-node-core-prospective-parachains", "polkadot-node-core-provisioner", "polkadot-node-core-pvf", "polkadot-node-core-pvf-checker", "polkadot-node-core-pvf-common", "polkadot-node-core-pvf-execute-worker", "polkadot-node-core-pvf-prepare-worker", "polkadot-node-core-runtime-api", "polkadot-node-jaeger", "polkadot-node-metrics", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-parachain-lib", "polkadot-rpc", "polkadot-service", "polkadot-statement-distribution", "polkadot-statement-table", "sc-allocator", "sc-authority-discovery", "sc-basic-authorship", "sc-block-builder", "sc-chain-spec", "sc-cli", "sc-client-api", "sc-client-db", "sc-consensus", "sc-consensus-aura", "sc-consensus-babe", "sc-consensus-babe-rpc", "sc-consensus-beefy", "sc-consensus-beefy-rpc", "sc-consensus-epochs", "sc-consensus-grandpa", "sc-consensus-grandpa-rpc", "sc-consensus-manual-seal", "sc-consensus-pow", "sc-consensus-slots", "sc-executor", "sc-executor-common", "sc-executor-polkavm", "sc-executor-wasmtime", "sc-informant", "sc-keystore", "sc-mixnet", "sc-network", "sc-network-common", "sc-network-gossip", "sc-network-light", "sc-network-statement", "sc-network-sync", "sc-network-transactions", "sc-network-types", "sc-offchain", "sc-proposer-metrics", "sc-rpc", "sc-rpc-api", "sc-rpc-server", "sc-rpc-spec-v2", "sc-service", "sc-state-db", "sc-statement-store", "sc-storage-monitor", "sc-sync-state-rpc", "sc-sysinfo", "sc-telemetry", "sc-tracing", "sc-transaction-pool", "sc-transaction-pool-api", "sc-utils", "snowbridge-runtime-test-common", "sp-blockchain", "sp-consensus", "sp-core-hashing", "sp-core-hashing-proc-macro", "sp-database", "sp-maybe-compressed-blob", "sp-panic-handler", "sp-rpc", "staging-chain-spec-builder", "staging-node-inspect", "staging-tracking-allocator", "std", "subkey", "substrate-build-script-utils", "substrate-frame-rpc-support", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-rpc-client", "substrate-state-trie-migration-rpc", "substrate-wasm-builder", "tracing-gum", "xcm-emulator", "xcm-simulator"] tuples-96 = [ "frame-support-procedural?/tuples-96", "frame-support?/tuples-96", @@ -2214,8 +2214,8 @@ path = "../polkadot/node/overseer" default-features = false optional = true -[dependencies.polkadot-parachain-bin] -path = "../cumulus/polkadot-parachain" +[dependencies.polkadot-parachain-lib] +path = "../cumulus/polkadot-parachain/polkadot-parachain-lib" default-features = false optional = true diff --git a/umbrella/src/lib.rs b/umbrella/src/lib.rs index fb60a5c21ac4..95e404792a16 100644 --- a/umbrella/src/lib.rs +++ b/umbrella/src/lib.rs @@ -882,9 +882,9 @@ pub use polkadot_node_subsystem_util; #[cfg(feature = "polkadot-overseer")] pub use polkadot_overseer; -/// Helper library that can be used to run a parachain node. -#[cfg(feature = "polkadot-parachain-bin")] -pub use polkadot_parachain_bin; +/// Helper library that can be used to build a parachain node. +#[cfg(feature = "polkadot-parachain-lib")] +pub use polkadot_parachain_lib; /// Types and utilities for creating and working with parachains. #[cfg(feature = "polkadot-parachain-primitives")] From d58d28fceac55ded20dd605e2bebd8920ce24c21 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 12 Aug 2024 13:57:56 +0300 Subject: [PATCH 05/14] Fix build --- docs/sdk/src/guides/enable_elastic_scaling_mvp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sdk/src/guides/enable_elastic_scaling_mvp.rs b/docs/sdk/src/guides/enable_elastic_scaling_mvp.rs index 939043b53529..38ef18b88e0d 100644 --- a/docs/sdk/src/guides/enable_elastic_scaling_mvp.rs +++ b/docs/sdk/src/guides/enable_elastic_scaling_mvp.rs @@ -85,7 +85,7 @@ //! This phase consists of plugging in the new slot-based collator. //! //! 1. In `node/src/service.rs` import the slot based collator instead of the lookahead collator. -#![doc = docify::embed!("../../cumulus/polkadot-parachain/src/service.rs", slot_based_colator_import)] +#![doc = docify::embed!("../../cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs", slot_based_colator_import)] //! //! 2. In `start_consensus()` //! - Remove the `overseer_handle` param (also remove the @@ -94,7 +94,7 @@ //! `slot_drift` field with a value of `Duration::from_secs(1)`. //! - Replace the single future returned by `aura::run` with the two futures returned by it and //! spawn them as separate tasks: -#![doc = docify::embed!("../../cumulus/polkadot-parachain/src/service.rs", launch_slot_based_collator)] +#![doc = docify::embed!("../../cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs", launch_slot_based_collator)] //! //! 3. In `start_parachain_node()` remove the `overseer_handle` param passed to `start_consensus`. //! From 0a4b113637cbd340f4ecb22de79a0feb3e142969 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 12 Aug 2024 14:04:52 +0300 Subject: [PATCH 06/14] PRdoc --- .../polkadot-parachain-lib/Cargo.toml | 2 +- prdoc/pr_5288.prdoc | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_5288.prdoc diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml index 3f69d1579ea8..b2fc337f1fea 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-parachain-lib" -version = "0.0.1" +version = "0.1.0" authors.workspace = true build = "build.rs" edition.workspace = true diff --git a/prdoc/pr_5288.prdoc b/prdoc/pr_5288.prdoc new file mode 100644 index 000000000000..374543544d1e --- /dev/null +++ b/prdoc/pr_5288.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Added `polkadot-parachain-lib` helper library that can be used to build a parachain node + +doc: + - audience: Node Dev + description: | + This PR adds the `polkadot-parachain-lib` helper library that can be used to build a parachain node. + +crates: + - name: polkadot-parachain + bump: minor + - name: polkadot-parachain-lib + bump: minor + - name: polkadot-sdk + bump: major From 3ee572b69bc0ac7bb693403c7f93b71603135ec4 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 12 Aug 2024 14:12:24 +0300 Subject: [PATCH 07/14] Fix PRdoc --- Cargo.lock | 2 +- prdoc/pr_5288.prdoc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2013cf8ddb0a..1045fa37db5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13898,7 +13898,7 @@ dependencies = [ [[package]] name = "polkadot-parachain-lib" -version = "0.0.1" +version = "0.1.0" dependencies = [ "assert_cmd", "async-trait", diff --git a/prdoc/pr_5288.prdoc b/prdoc/pr_5288.prdoc index 374543544d1e..8241e75876f1 100644 --- a/prdoc/pr_5288.prdoc +++ b/prdoc/pr_5288.prdoc @@ -9,9 +9,9 @@ doc: This PR adds the `polkadot-parachain-lib` helper library that can be used to build a parachain node. crates: - - name: polkadot-parachain - bump: minor + - name: polkadot-parachain-bin + bump: patch - name: polkadot-parachain-lib - bump: minor + bump: patch - name: polkadot-sdk - bump: major + bump: patch From 75fa0e4f50d577db9ab91aa3661b84ed49c0a925 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 12 Aug 2024 14:29:17 +0300 Subject: [PATCH 08/14] Fix rust doc --- .../polkadot-parachain-lib/src/common/mod.rs | 2 +- .../polkadot-parachain-lib/src/common/runtime.rs | 2 ++ .../polkadot-parachain-lib/src/lib.rs | 13 +++++-------- cumulus/polkadot-parachain/src/chain_spec/mod.rs | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs index 9ba6d4a88095..89bc7511dac3 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs @@ -20,7 +20,7 @@ pub(crate) mod aura; pub mod chain_spec; -pub(crate) mod runtime; +pub mod runtime; use cumulus_primitives_core::CollectCollationInfo; use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata}; diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs index 606f87cc03f0..5576e05cd34d 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +//! Runtime parameters. + use sc_chain_spec::ChainSpec; use std::fmt::Debug; diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs index 1bd091b43d5c..af0c21ac78f1 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs @@ -26,15 +26,15 @@ //! //! The library exposes the possibility to provide a [`CommandConfig`]. Through this structure //! 2 optional configurations can be provided: -//! - a chain spec loader (an implementation of ['chain_spec::LoadSpec']): this can be used for +//! - a chain spec loader (an implementation of [`chain_spec::LoadSpec`]): this can be used for //! providing the chain specs that are supported by default by the `--chain-spec` argument of the //! node's `CLI` and the actual chain config associated with each one. -//! - a runtime resolver (an implementation of [`chain_spec::RuntimeResolver`]): this can be used -//! for providing the parameters of the runtime that is associated with each of the chain specs +//! - a runtime resolver (an implementation of [`runtime::RuntimeResolver`]): this can be used for +//! providing the parameters of the runtime that is associated with each of the chain specs //! //! ## Examples //! -//! For examples, see the `polkadot-parachain` crate. +//! For an example, see the `polkadot-parachain-bin` crate. mod cli; mod command; @@ -44,7 +44,4 @@ mod rpc; mod service; pub use command::{run, CommandConfig}; -pub use common::{ - chain_spec, - runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver}, -}; +pub use common::{chain_spec, runtime}; diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index d60fdeffce69..46ec36c9fa84 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -18,7 +18,7 @@ use cumulus_primitives_core::ParaId; use parachains_common::{AccountId, Signature}; use polkadot_parachain_lib::{ chain_spec::{GenericChainSpec, LoadSpec}, - AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT, + runtime::{AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT}, }; use sc_chain_spec::ChainSpec; use sp_core::{Pair, Public}; From 4027fe375ba7e7c24a6a6b6727bc4500a8e26e44 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 14 Aug 2024 09:31:32 +0300 Subject: [PATCH 09/14] small fixes --- Cargo.lock | 1 + cumulus/polkadot-parachain/Cargo.toml | 3 +-- .../polkadot-parachain-lib/Cargo.toml | 14 ++++++++++---- .../polkadot-parachain-lib/src/common/aura.rs | 6 ++++-- .../src/common/chain_spec.rs | 5 +++-- .../fake_runtime_api/asset_hub_polkadot_aura.rs | 5 ++--- .../src/fake_runtime_api/aura.rs | 5 ++--- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1045fa37db5d..8743f88c7376 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13959,6 +13959,7 @@ dependencies = [ "sp-timestamp", "sp-transaction-pool", "sp-version", + "sp-weights", "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 735e30b2c75e..4a466496d795 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -21,7 +21,7 @@ serde = { features = ["derive"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } # Local -polkadot-parachain-lib = { workspace = true } +polkadot-parachain-lib = { features = ["rococo-native", "westend-native"], workspace = true } rococo-parachain-runtime = { workspace = true } shell-runtime = { workspace = true } glutton-westend-runtime = { workspace = true } @@ -51,7 +51,6 @@ sc-service = { workspace = true, default-features = true } sc-chain-spec = { workspace = true, default-features = true } # Polkadot -# Use rococo-native as this is currently the default "local" relay chain polkadot-service = { workspace = true, default-features = true } xcm = { workspace = true, default-features = true } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml index b2fc337f1fea..be97e09142ac 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml @@ -29,14 +29,14 @@ jsonrpsee = { features = ["server"], workspace = true } parachains-common = { workspace = true, default-features = true } # Substrate -frame-benchmarking = { workspace = true, default-features = true } +frame-benchmarking = { optional = true, workspace = true, default-features = true } frame-benchmarking-cli = { workspace = true, default-features = true } sp-runtime = { workspace = true } sp-core = { workspace = true, default-features = true } sp-session = { workspace = true, default-features = true } frame-try-runtime = { optional = true, workspace = true, default-features = true } sc-consensus = { workspace = true, default-features = true } -frame-support = { workspace = true, default-features = true } +frame-support = { optional = true, workspace = true, default-features = true } sc-cli = { workspace = true, default-features = true } sc-client-api = { workspace = true, default-features = true } sc-executor = { workspace = true, default-features = true } @@ -53,6 +53,7 @@ sp-keystore = { workspace = true, default-features = true } sc-chain-spec = { workspace = true, default-features = true } sc-rpc = { workspace = true, default-features = true } sp-version = { workspace = true, default-features = true } +sp-weights = { workspace = true, default-features = true } sc-tracing = { workspace = true, default-features = true } frame-system-rpc-runtime-api = { workspace = true, default-features = true } pallet-transaction-payment = { workspace = true, default-features = true } @@ -67,8 +68,7 @@ pallet-transaction-payment-rpc = { workspace = true, default-features = true } substrate-state-trie-migration-rpc = { workspace = true, default-features = true } # Polkadot -# Use rococo-native as this is currently the default "local" relay chain -polkadot-cli = { features = ["rococo-native", "westend-native"], workspace = true, default-features = true } +polkadot-cli = { workspace = true, default-features = true } polkadot-primitives = { workspace = true, default-features = true } # Cumulus @@ -95,6 +95,12 @@ wait-timeout = { workspace = true } [features] default = [] +rococo-native = [ + "polkadot-cli/rococo-native", +] +westend-native = [ + "polkadot-cli/westend-native", +] runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", "frame-benchmarking-cli/runtime-benchmarks", diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/aura.rs index 9f72d847926f..9e8837de7f87 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/aura.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/aura.rs @@ -18,9 +18,11 @@ use codec::Codec; use cumulus_primitives_aura::AuraUnincludedSegmentApi; -use cumulus_primitives_core::BlockT; use sp_consensus_aura::AuraApi; -use sp_runtime::app_crypto::{AppCrypto, AppPair, AppSignature, Pair}; +use sp_runtime::{ + app_crypto::{AppCrypto, AppPair, AppSignature, Pair}, + traits::Block as BlockT, +}; /// Convenience trait for defining the basic bounds of an `AuraId`. pub trait AuraIdT: AppCrypto + Codec + Send { diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs index 58af66f7fbda..b20deea1618a 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs @@ -16,8 +16,9 @@ //! Chain spec primitives. -use frame_support::{Deserialize, Serialize}; -use sc_chain_spec::{ChainSpec, ChainSpecExtension}; +pub use sc_chain_spec::ChainSpec; +use sc_chain_spec::ChainSpecExtension; +use serde::{Deserialize, Serialize}; use std::fmt::Debug; /// Helper trait used for loading/building a chain spec starting from the chain ID. diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 7d54e9b4be04..f2b8b4d562b9 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -17,15 +17,14 @@ //! These are used to provide a type that implements these runtime APIs without requiring to import //! the native runtimes. -use frame_support::weights::Weight; -use parachains_common::{AccountId, AssetHubPolkadotAuraId, Balance, Nonce}; -use polkadot_primitives::Block; +use parachains_common::{AccountId, AssetHubPolkadotAuraId, Balance, Block, Nonce}; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ traits::Block as BlockT, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; +use sp_weights::Weight; pub struct Runtime; diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs index ca5fc8bdf119..eb6d3fafa3d6 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs @@ -17,15 +17,14 @@ //! These are used to provide a type that implements these runtime APIs without requiring to import //! the native runtimes. -use frame_support::weights::Weight; -use parachains_common::{AccountId, AuraId, Balance, Nonce}; -use polkadot_primitives::Block; +use parachains_common::{AccountId, AuraId, Balance, Block, Nonce}; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ traits::Block as BlockT, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; +use sp_weights::Weight; pub struct Runtime; From d4139a44b63a1ce96fc464c87de6382cd04702a5 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 14 Aug 2024 12:20:00 +0300 Subject: [PATCH 10/14] Move RelayChainCli related logic under cli.rs --- .../polkadot-parachain-lib/src/cli.rs | 182 +++++++++++++++--- .../polkadot-parachain-lib/src/command.rs | 132 +------------ 2 files changed, 158 insertions(+), 156 deletions(-) diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs index 622fab34f444..1259788c6cf1 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs @@ -20,8 +20,12 @@ use crate::common::{ }; use clap::{Command, CommandFactory, FromArgMatches}; use sc_chain_spec::ChainSpec; -use sc_cli::SubstrateCli; -use std::{fmt::Debug, path::PathBuf}; +use sc_cli::{ + CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, + SharedParams, SubstrateCli, +}; +use sc_service::{config::PrometheusConfig, BasePath}; +use std::{fmt::Debug, net::SocketAddr, path::PathBuf}; /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] @@ -195,6 +199,37 @@ pub struct RelayChainCli { pub base_path: Option, } +impl RelayChainCli { + fn polkadot_cmd() -> Command { + let help_template = color_print::cformat!( + "The arguments that are passed to the relay chain node. \n\ + \n\ + RELAY_CHAIN_ARGS: \n\ + {{options}}", + ); + + polkadot_cli::RunCmd::command() + .no_binary_name(true) + .help_template(help_template) + } + + /// Parse the relay chain CLI parameters using the parachain `Configuration`. + pub fn new<'a>( + para_config: &sc_service::Configuration, + relay_chain_args: impl Iterator, + ) -> Self { + let polkadot_cmd = Self::polkadot_cmd(); + let matches = polkadot_cmd.get_matches_from(relay_chain_args); + let base = FromArgMatches::from_arg_matches(&matches).unwrap_or_else(|e| e.exit()); + + let extension = Extensions::try_get(&*para_config.chain_spec); + let chain_id = extension.map(|e| e.relay_chain.clone()); + + let base_path = para_config.base_path.path().join("polkadot"); + Self { base, chain_id, base_path: Some(base_path) } + } +} + impl SubstrateCli for RelayChainCli { fn impl_name() -> String { Cli::impl_name() @@ -225,33 +260,130 @@ impl SubstrateCli for RelayChainCli { } } -impl RelayChainCli { - fn polkadot_cmd() -> Command { - let help_template = color_print::cformat!( - "The arguments that are passed to the relay chain node. \n\ - \n\ - RELAY_CHAIN_ARGS: \n\ - {{options}}", - ); +impl DefaultConfigurationValues for RelayChainCli { + fn p2p_listen_port() -> u16 { + 30334 + } - polkadot_cli::RunCmd::command() - .no_binary_name(true) - .help_template(help_template) + fn rpc_listen_port() -> u16 { + 9945 } - /// Parse the relay chain CLI parameters using the parachain `Configuration`. - pub fn new<'a>( - para_config: &sc_service::Configuration, - relay_chain_args: impl Iterator, - ) -> Self { - let polkadot_cmd = Self::polkadot_cmd(); - let matches = polkadot_cmd.get_matches_from(relay_chain_args); - let base = FromArgMatches::from_arg_matches(&matches).unwrap_or_else(|e| e.exit()); + fn prometheus_listen_port() -> u16 { + 9616 + } +} - let extension = Extensions::try_get(&*para_config.chain_spec); - let chain_id = extension.map(|e| e.relay_chain.clone()); +impl CliConfiguration for RelayChainCli { + fn shared_params(&self) -> &SharedParams { + self.base.base.shared_params() + } - let base_path = para_config.base_path.path().join("polkadot"); - Self { base, chain_id, base_path: Some(base_path) } + fn import_params(&self) -> Option<&ImportParams> { + self.base.base.import_params() + } + + fn network_params(&self) -> Option<&NetworkParams> { + self.base.base.network_params() + } + + fn keystore_params(&self) -> Option<&KeystoreParams> { + self.base.base.keystore_params() + } + + fn base_path(&self) -> sc_cli::Result> { + Ok(self + .shared_params() + .base_path()? + .or_else(|| self.base_path.clone().map(Into::into))) + } + + fn rpc_addr(&self, default_listen_port: u16) -> sc_cli::Result> { + self.base.base.rpc_addr(default_listen_port) + } + + fn prometheus_config( + &self, + default_listen_port: u16, + chain_spec: &Box, + ) -> sc_cli::Result> { + self.base.base.prometheus_config(default_listen_port, chain_spec) + } + + fn init( + &self, + _support_url: &String, + _impl_version: &String, + _logger_hook: F, + _config: &sc_service::Configuration, + ) -> sc_cli::Result<()> + where + F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), + { + unreachable!("PolkadotCli is never initialized; qed"); + } + + fn chain_id(&self, is_dev: bool) -> sc_cli::Result { + let chain_id = self.base.base.chain_id(is_dev)?; + + Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id }) + } + + fn role(&self, is_dev: bool) -> sc_cli::Result { + self.base.base.role(is_dev) + } + + fn transaction_pool( + &self, + is_dev: bool, + ) -> sc_cli::Result { + self.base.base.transaction_pool(is_dev) + } + + fn trie_cache_maximum_size(&self) -> sc_cli::Result> { + self.base.base.trie_cache_maximum_size() + } + + fn rpc_methods(&self) -> sc_cli::Result { + self.base.base.rpc_methods() + } + + fn rpc_max_connections(&self) -> sc_cli::Result { + self.base.base.rpc_max_connections() + } + + fn rpc_cors(&self, is_dev: bool) -> sc_cli::Result>> { + self.base.base.rpc_cors(is_dev) + } + + fn default_heap_pages(&self) -> sc_cli::Result> { + self.base.base.default_heap_pages() + } + + fn force_authoring(&self) -> sc_cli::Result { + self.base.base.force_authoring() + } + + fn disable_grandpa(&self) -> sc_cli::Result { + self.base.base.disable_grandpa() + } + + fn max_runtime_instances(&self) -> sc_cli::Result> { + self.base.base.max_runtime_instances() + } + + fn announce_block(&self) -> sc_cli::Result { + self.base.base.announce_block() + } + + fn telemetry_endpoints( + &self, + chain_spec: &Box, + ) -> sc_cli::Result> { + self.base.base.telemetry_endpoints(chain_spec) + } + + fn node_name(&self) -> sc_cli::Result { + self.base.base.node_name() } } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs index 10d54fb37062..581d57c0c137 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs @@ -38,15 +38,10 @@ use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use log::info; use parachains_common::{AssetHubPolkadotAuraId, AuraId}; -use sc_cli::{ - ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, - NetworkParams, Result, SharedParams, SubstrateCli, -}; -use sc_service::config::{BasePath, PrometheusConfig}; +use sc_cli::{Result, SubstrateCli}; use sp_runtime::traits::AccountIdConversion; #[cfg(feature = "runtime-benchmarks")] use sp_runtime::traits::HashingFor; -use std::net::SocketAddr; #[derive(Debug, Default)] pub struct CommandConfig { @@ -314,128 +309,3 @@ async fn start_node( .await .map_err(Into::into) } - -impl DefaultConfigurationValues for RelayChainCli { - fn p2p_listen_port() -> u16 { - 30334 - } - - fn rpc_listen_port() -> u16 { - 9945 - } - - fn prometheus_listen_port() -> u16 { - 9616 - } -} - -impl CliConfiguration for RelayChainCli { - fn shared_params(&self) -> &SharedParams { - self.base.base.shared_params() - } - - fn import_params(&self) -> Option<&ImportParams> { - self.base.base.import_params() - } - - fn network_params(&self) -> Option<&NetworkParams> { - self.base.base.network_params() - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - self.base.base.keystore_params() - } - - fn base_path(&self) -> Result> { - Ok(self - .shared_params() - .base_path()? - .or_else(|| self.base_path.clone().map(Into::into))) - } - - fn rpc_addr(&self, default_listen_port: u16) -> Result> { - self.base.base.rpc_addr(default_listen_port) - } - - fn prometheus_config( - &self, - default_listen_port: u16, - chain_spec: &Box, - ) -> Result> { - self.base.base.prometheus_config(default_listen_port, chain_spec) - } - - fn init( - &self, - _support_url: &String, - _impl_version: &String, - _logger_hook: F, - _config: &sc_service::Configuration, - ) -> Result<()> - where - F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), - { - unreachable!("PolkadotCli is never initialized; qed"); - } - - fn chain_id(&self, is_dev: bool) -> Result { - let chain_id = self.base.base.chain_id(is_dev)?; - - Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id }) - } - - fn role(&self, is_dev: bool) -> Result { - self.base.base.role(is_dev) - } - - fn transaction_pool(&self, is_dev: bool) -> Result { - self.base.base.transaction_pool(is_dev) - } - - fn trie_cache_maximum_size(&self) -> Result> { - self.base.base.trie_cache_maximum_size() - } - - fn rpc_methods(&self) -> Result { - self.base.base.rpc_methods() - } - - fn rpc_max_connections(&self) -> Result { - self.base.base.rpc_max_connections() - } - - fn rpc_cors(&self, is_dev: bool) -> Result>> { - self.base.base.rpc_cors(is_dev) - } - - fn default_heap_pages(&self) -> Result> { - self.base.base.default_heap_pages() - } - - fn force_authoring(&self) -> Result { - self.base.base.force_authoring() - } - - fn disable_grandpa(&self) -> Result { - self.base.base.disable_grandpa() - } - - fn max_runtime_instances(&self) -> Result> { - self.base.base.max_runtime_instances() - } - - fn announce_block(&self) -> Result { - self.base.base.announce_block() - } - - fn telemetry_endpoints( - &self, - chain_spec: &Box, - ) -> Result> { - self.base.base.telemetry_endpoints(chain_spec) - } - - fn node_name(&self) -> Result { - self.base.base.node_name() - } -} From 728ad1041dea60fba84d34cf3ca10075fade0362 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 14 Aug 2024 12:23:41 +0300 Subject: [PATCH 11/14] add CliConfig --- Cargo.lock | 1 - cumulus/polkadot-parachain/Cargo.toml | 1 + .../{polkadot-parachain-lib => }/build.rs | 0 .../polkadot-parachain-lib/Cargo.toml | 4 - .../polkadot-parachain-lib/src/cli.rs | 105 +++++++++--------- .../polkadot-parachain-lib/src/command.rs | 10 +- .../polkadot-parachain-lib/src/lib.rs | 1 + cumulus/polkadot-parachain/src/main.rs | 24 +++- 8 files changed, 80 insertions(+), 66 deletions(-) rename cumulus/polkadot-parachain/{polkadot-parachain-lib => }/build.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 8743f88c7376..774cd231771e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13960,7 +13960,6 @@ dependencies = [ "sp-transaction-pool", "sp-version", "sp-weights", - "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "substrate-state-trie-migration-rpc", diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 4a466496d795..383e0f158bf4 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -3,6 +3,7 @@ name = "polkadot-parachain-bin" version = "4.0.0" authors.workspace = true edition.workspace = true +build = "build.rs" description = "Runs a polkadot parachain node" license = "Apache-2.0" diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/build.rs b/cumulus/polkadot-parachain/build.rs similarity index 100% rename from cumulus/polkadot-parachain/polkadot-parachain-lib/build.rs rename to cumulus/polkadot-parachain/build.rs diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml index be97e09142ac..09bde034cf26 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml @@ -2,7 +2,6 @@ name = "polkadot-parachain-lib" version = "0.1.0" authors.workspace = true -build = "build.rs" edition.workspace = true description = "Helper library that can be used to build a parachain node" license = "Apache-2.0" @@ -84,9 +83,6 @@ cumulus-primitives-aura = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } cumulus-relay-chain-interface = { workspace = true, default-features = true } -[build-dependencies] -substrate-build-script-utils = { workspace = true, default-features = true } - [dev-dependencies] assert_cmd = { workspace = true } nix = { features = ["signal"], workspace = true } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs index 1259788c6cf1..8cd2532cb4f3 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs @@ -25,7 +25,29 @@ use sc_cli::{ SharedParams, SubstrateCli, }; use sc_service::{config::PrometheusConfig, BasePath}; -use std::{fmt::Debug, net::SocketAddr, path::PathBuf}; +use std::{fmt::Debug, marker::PhantomData, net::SocketAddr, path::PathBuf}; + +pub trait CliConfig { + fn impl_version() -> String; + + fn description(executable_name: String) -> String { + format!( + "The command-line arguments provided first will be passed to the parachain node, \n\ + and the arguments provided after -- will be passed to the relay chain node. \n\ + \n\ + Example: \n\ + \n\ + {} [parachain-args] -- [relay-chain-args]", + executable_name + ) + } + + fn author() -> String; + + fn support_url() -> String; + + fn copyright_start_year() -> i32; +} /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] @@ -68,37 +90,13 @@ pub enum Subcommand { Benchmark(frame_benchmarking_cli::BenchmarkCmd), } -fn examples(executable_name: String) -> String { - color_print::cformat!( - r#"Examples: - - {0} --chain para.json --sync warp -- --chain relay.json --sync warp - Launch a warp-syncing full node of a given para's chain-spec, and a given relay's chain-spec. - - The above approach is the most flexible, and the most forward-compatible way to spawn an omni-node. - - You can find the chain-spec of some networks in: - https://paritytech.github.io/chainspecs - - {0} --chain asset-hub-polkadot --sync warp -- --chain polkadot --sync warp - Launch a warp-syncing full node of the Asset Hub parachain on the Polkadot Relay Chain. - - {0} --chain asset-hub-kusama --sync warp --relay-chain-rpc-url ws://rpc.example.com -- --chain kusama - Launch a warp-syncing full node of the Asset Hub parachain on the Kusama Relay Chain. - Uses ws://rpc.example.com as remote relay chain node. - "#, - executable_name, - ) -} - #[derive(Debug, clap::Parser)] #[command( propagate_version = true, args_conflicts_with_subcommands = true, - subcommand_negates_reqs = true, - after_help = examples(Self::executable_name()) + subcommand_negates_reqs = true )] -pub struct Cli { +pub struct Cli { #[arg(skip)] pub(crate) chain_spec_loader: Option>, @@ -134,9 +132,12 @@ pub struct Cli { /// Relay chain arguments #[arg(raw = true)] pub relay_chain_args: Vec, + + #[arg(skip)] + pub(crate) _phantom: PhantomData, } -impl Cli { +impl Cli { pub(crate) fn node_extra_args(&self) -> NodeExtraArgs { NodeExtraArgs { use_slot_based_consensus: self.experimental_use_slot_based, @@ -145,37 +146,29 @@ impl Cli { } } -impl SubstrateCli for Cli { +impl SubstrateCli for Cli { fn impl_name() -> String { Self::executable_name() } fn impl_version() -> String { - env!("SUBSTRATE_CLI_IMPL_VERSION").into() + Config::impl_version() } fn description() -> String { - format!( - "The command-line arguments provided first will be passed to the parachain node, \n\ - and the arguments provided after -- will be passed to the relay chain node. \n\ - \n\ - Example: \n\ - \n\ - {} [parachain-args] -- [relay-chain-args]", - Self::executable_name() - ) + Config::description(Self::executable_name()) } fn author() -> String { - env!("CARGO_PKG_AUTHORS").into() + Config::author() } fn support_url() -> String { - "https://github.com/paritytech/polkadot-sdk/issues/new".into() + Config::support_url() } fn copyright_start_year() -> i32 { - 2017 + Config::copyright_start_year() } fn load_spec(&self, id: &str) -> std::result::Result, String> { @@ -188,7 +181,7 @@ impl SubstrateCli for Cli { } #[derive(Debug)] -pub struct RelayChainCli { +pub struct RelayChainCli { /// The actual relay chain cli object. pub base: polkadot_cli::RunCmd, @@ -197,9 +190,11 @@ pub struct RelayChainCli { /// The base path that should be used by the relay chain. pub base_path: Option, + + _phantom: PhantomData, } -impl RelayChainCli { +impl RelayChainCli { fn polkadot_cmd() -> Command { let help_template = color_print::cformat!( "The arguments that are passed to the relay chain node. \n\ @@ -226,41 +221,41 @@ impl RelayChainCli { let chain_id = extension.map(|e| e.relay_chain.clone()); let base_path = para_config.base_path.path().join("polkadot"); - Self { base, chain_id, base_path: Some(base_path) } + Self { base, chain_id, base_path: Some(base_path), _phantom: Default::default() } } } -impl SubstrateCli for RelayChainCli { +impl SubstrateCli for RelayChainCli { fn impl_name() -> String { - Cli::impl_name() + Cli::::impl_name() } fn impl_version() -> String { - Cli::impl_version() + Cli::::impl_version() } fn description() -> String { - Cli::description() + Cli::::description() } fn author() -> String { - Cli::author() + Cli::::author() } fn support_url() -> String { - Cli::support_url() + Cli::::support_url() } fn copyright_start_year() -> i32 { - Cli::copyright_start_year() + Cli::::copyright_start_year() } fn load_spec(&self, id: &str) -> std::result::Result, String> { - polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) + polkadot_cli::Cli::from_iter([Self::executable_name()].iter()).load_spec(id) } } -impl DefaultConfigurationValues for RelayChainCli { +impl DefaultConfigurationValues for RelayChainCli { fn p2p_listen_port() -> u16 { 30334 } @@ -274,7 +269,7 @@ impl DefaultConfigurationValues for RelayChainCli { } } -impl CliConfiguration for RelayChainCli { +impl CliConfiguration for RelayChainCli { fn shared_params(&self) -> &SharedParams { self.base.base.shared_params() } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs index 581d57c0c137..f8ecd07c55ab 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs @@ -71,8 +71,8 @@ fn new_node_spec( } /// Parse command line arguments into service configuration. -pub fn run(cmd_config: CommandConfig) -> Result<()> { - let mut cli = Cli::from_args(); +pub fn run(cmd_config: CommandConfig) -> Result<()> { + let mut cli = Cli::::from_args(); cli.chain_spec_loader = cmd_config.chain_spec_loader; match &cli.subcommand { @@ -137,7 +137,8 @@ pub fn run(cmd_config: CommandConfig) -> Result<()> { }, Some(Subcommand::PurgeChain(cmd)) => { let runner = cli.create_runner(cmd)?; - let polkadot_cli = RelayChainCli::new(runner.config(), cli.relay_chain_args.iter()); + let polkadot_cli = + RelayChainCli::::new(runner.config(), cli.relay_chain_args.iter()); runner.sync_run(|config| { let polkadot_config = SubstrateCli::create_configuration( @@ -208,7 +209,8 @@ pub fn run(cmd_config: CommandConfig) -> Result<()> { Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?), None => { let runner = cli.create_runner(&cli.run.normalize())?; - let polkadot_cli = RelayChainCli::new(runner.config(), cli.relay_chain_args.iter()); + let polkadot_cli = + RelayChainCli::::new(runner.config(), cli.relay_chain_args.iter()); let collator_options = cli.run.collator_options(); runner.run_node_until_exit(|config| async move { diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs index af0c21ac78f1..645c7f4d3caa 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs @@ -43,5 +43,6 @@ mod fake_runtime_api; mod rpc; mod service; +pub use cli::CliConfig; pub use command::{run, CommandConfig}; pub use common::{chain_spec, runtime}; diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index 353999539bf0..96fd400ec8e6 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -21,7 +21,27 @@ mod chain_spec; -use polkadot_parachain_lib::{run, CommandConfig}; +use polkadot_parachain_lib::{run, CliConfig as CliConfigT, CommandConfig}; + +struct CliConfig; + +impl CliConfigT for CliConfig { + fn impl_version() -> String { + env!("SUBSTRATE_CLI_IMPL_VERSION").into() + } + + fn author() -> String { + env!("CARGO_PKG_AUTHORS").into() + } + + fn support_url() -> String { + "https://github.com/paritytech/polkadot-sdk/issues/new".into() + } + + fn copyright_start_year() -> i32 { + 2017 + } +} fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; @@ -30,5 +50,5 @@ fn main() -> color_eyre::eyre::Result<()> { chain_spec_loader: Some(Box::new(chain_spec::ChainSpecLoader)), runtime_resolver: Some(Box::new(chain_spec::RuntimeResolver)), }; - Ok(run(config)?) + Ok(run::(config)?) } From de75e86bc9d1f200b51aa4bf90459f3d117c9057 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 14 Aug 2024 13:05:27 +0300 Subject: [PATCH 12/14] small changes CommandConfig -> RunConfig copyright start year -> u16 --- .../polkadot-parachain/polkadot-parachain-lib/src/cli.rs | 4 ++-- .../polkadot-parachain-lib/src/command.rs | 4 ++-- .../polkadot-parachain/polkadot-parachain-lib/src/lib.rs | 4 ++-- cumulus/polkadot-parachain/src/main.rs | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs index 8cd2532cb4f3..87aae76684b3 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs @@ -46,7 +46,7 @@ pub trait CliConfig { fn support_url() -> String; - fn copyright_start_year() -> i32; + fn copyright_start_year() -> u16; } /// Sub-commands supported by the collator. @@ -168,7 +168,7 @@ impl SubstrateCli for Cli { } fn copyright_start_year() -> i32 { - Config::copyright_start_year() + Config::copyright_start_year() as i32 } fn load_spec(&self, id: &str) -> std::result::Result, String> { diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs index f8ecd07c55ab..3e69c1c874cd 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs @@ -44,7 +44,7 @@ use sp_runtime::traits::AccountIdConversion; use sp_runtime::traits::HashingFor; #[derive(Debug, Default)] -pub struct CommandConfig { +pub struct RunConfig { pub chain_spec_loader: Option>, pub runtime_resolver: Option>, } @@ -71,7 +71,7 @@ fn new_node_spec( } /// Parse command line arguments into service configuration. -pub fn run(cmd_config: CommandConfig) -> Result<()> { +pub fn run(cmd_config: RunConfig) -> Result<()> { let mut cli = Cli::::from_args(); cli.chain_spec_loader = cmd_config.chain_spec_loader; diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs index 645c7f4d3caa..f39c60bc6c73 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs @@ -24,7 +24,7 @@ //! //! ## API //! -//! The library exposes the possibility to provide a [`CommandConfig`]. Through this structure +//! The library exposes the possibility to provide a [`RunConfig`]. Through this structure //! 2 optional configurations can be provided: //! - a chain spec loader (an implementation of [`chain_spec::LoadSpec`]): this can be used for //! providing the chain specs that are supported by default by the `--chain-spec` argument of the @@ -44,5 +44,5 @@ mod rpc; mod service; pub use cli::CliConfig; -pub use command::{run, CommandConfig}; +pub use command::{run, RunConfig}; pub use common::{chain_spec, runtime}; diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index 96fd400ec8e6..9dd1b5f585b8 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -21,7 +21,7 @@ mod chain_spec; -use polkadot_parachain_lib::{run, CliConfig as CliConfigT, CommandConfig}; +use polkadot_parachain_lib::{run, CliConfig as CliConfigT, RunConfig}; struct CliConfig; @@ -38,7 +38,7 @@ impl CliConfigT for CliConfig { "https://github.com/paritytech/polkadot-sdk/issues/new".into() } - fn copyright_start_year() -> i32 { + fn copyright_start_year() -> u16 { 2017 } } @@ -46,7 +46,7 @@ impl CliConfigT for CliConfig { fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; - let config = CommandConfig { + let config = RunConfig { chain_spec_loader: Some(Box::new(chain_spec::ChainSpecLoader)), runtime_resolver: Some(Box::new(chain_spec::RuntimeResolver)), }; From d277c0a1ba458460dc4bbc17ae45a800bda88d50 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 20 Aug 2024 11:49:59 +0300 Subject: [PATCH 13/14] Update docs --- cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs index f39c60bc6c73..fc164a9d8907 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs @@ -32,6 +32,9 @@ //! - a runtime resolver (an implementation of [`runtime::RuntimeResolver`]): this can be used for //! providing the parameters of the runtime that is associated with each of the chain specs //! +//! Apart from this, a [`CliConfig`] can also be provided, that can be used to customize some +//! user-facing binary author, support url, etc. +//! //! ## Examples //! //! For an example, see the `polkadot-parachain-bin` crate. From a9a7cde5980209cc9f62811f787293b3edd62650 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 21 Aug 2024 17:11:32 +0300 Subject: [PATCH 14/14] Address CR comments --- .../polkadot-parachain-lib/src/cli.rs | 25 ++++--- .../polkadot-parachain-lib/src/command.rs | 68 +++++++------------ .../src/common/chain_spec.rs | 11 ++- .../src/common/runtime.rs | 19 ++++-- .../polkadot-parachain/src/chain_spec/mod.rs | 4 +- cumulus/polkadot-parachain/src/main.rs | 4 +- 6 files changed, 68 insertions(+), 63 deletions(-) diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs index 87aae76684b3..2aa2b10fbb67 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::common::{ - chain_spec::{Extensions, GenericChainSpec, LoadSpec}, - NodeExtraArgs, +use crate::{ + chain_spec::DiskChainSpecLoader, + common::{ + chain_spec::{Extensions, LoadSpec}, + NodeExtraArgs, + }, }; use clap::{Command, CommandFactory, FromArgMatches}; use sc_chain_spec::ChainSpec; @@ -27,6 +30,11 @@ use sc_cli::{ use sc_service::{config::PrometheusConfig, BasePath}; use std::{fmt::Debug, marker::PhantomData, net::SocketAddr, path::PathBuf}; +/// Trait that can be used to customize some of the customer-facing info related to the node binary +/// that is being built using this library. +/// +/// The related info is shown to the customer as part of logs or help messages. +/// It does not impact functionality. pub trait CliConfig { fn impl_version() -> String; @@ -90,7 +98,7 @@ pub enum Subcommand { Benchmark(frame_benchmarking_cli::BenchmarkCmd), } -#[derive(Debug, clap::Parser)] +#[derive(clap::Parser)] #[command( propagate_version = true, args_conflicts_with_subcommands = true, @@ -171,12 +179,11 @@ impl SubstrateCli for Cli { Config::copyright_start_year() as i32 } - fn load_spec(&self, id: &str) -> std::result::Result, String> { - if let Some(chain_spec_loader) = &self.chain_spec_loader { - return chain_spec_loader.load_spec(id); + fn load_spec(&self, id: &str) -> Result, String> { + match &self.chain_spec_loader { + Some(chain_spec_loader) => chain_spec_loader.load_spec(id), + None => DiskChainSpecLoader.load_spec(id), } - - Ok(Box::new(GenericChainSpec::from_json_file(id.into())?)) } } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs index 3e69c1c874cd..7f915b729e0a 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs @@ -43,23 +43,21 @@ use sp_runtime::traits::AccountIdConversion; #[cfg(feature = "runtime-benchmarks")] use sp_runtime::traits::HashingFor; -#[derive(Debug, Default)] +/// Structure that can be used in order to provide customizers for different functionalities of the +/// node binary that is being built using this library. pub struct RunConfig { - pub chain_spec_loader: Option>, - pub runtime_resolver: Option>, + pub chain_spec_loader: Box, + pub runtime_resolver: Box, } fn new_node_spec( config: &sc_service::Configuration, - maybe_runtime_resolver: Option<&Box>, + runtime_resolver: &Box, extra_args: &NodeExtraArgs, ) -> std::result::Result, sc_cli::Error> { - let runtime_resolver = match maybe_runtime_resolver { - Some(runtime_resolver) => runtime_resolver, - None => return Ok(new_aura_node_spec::(extra_args)), - }; + let runtime = runtime_resolver.runtime(config.chain_spec.as_ref())?; - Ok(match runtime_resolver.runtime(config.chain_spec.as_ref())? { + Ok(match runtime { Runtime::Shell => Box::new(ShellNode), Runtime::Omni(consensus) => match consensus { Consensus::Aura(AuraConsensusId::Sr25519) => @@ -73,7 +71,7 @@ fn new_node_spec( /// Parse command line arguments into service configuration. pub fn run(cmd_config: RunConfig) -> Result<()> { let mut cli = Cli::::from_args(); - cli.chain_spec_loader = cmd_config.chain_spec_loader; + cli.chain_spec_loader = Some(cmd_config.chain_spec_loader); match &cli.subcommand { Some(Subcommand::BuildSpec(cmd)) => { @@ -83,55 +81,40 @@ pub fn run(cmd_config: RunConfig) -> Result<() Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec( - &config, - cmd_config.runtime_resolver.as_ref(), - &cli.node_extra_args(), - )?; + let node = + new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?; node.prepare_check_block_cmd(config, cmd) }) }, Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec( - &config, - cmd_config.runtime_resolver.as_ref(), - &cli.node_extra_args(), - )?; + let node = + new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?; node.prepare_export_blocks_cmd(config, cmd) }) }, Some(Subcommand::ExportState(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec( - &config, - cmd_config.runtime_resolver.as_ref(), - &cli.node_extra_args(), - )?; + let node = + new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?; node.prepare_export_state_cmd(config, cmd) }) }, Some(Subcommand::ImportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec( - &config, - cmd_config.runtime_resolver.as_ref(), - &cli.node_extra_args(), - )?; + let node = + new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?; node.prepare_import_blocks_cmd(config, cmd) }) }, Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - let node = new_node_spec( - &config, - cmd_config.runtime_resolver.as_ref(), - &cli.node_extra_args(), - )?; + let node = + new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?; node.prepare_revert_cmd(config, cmd) }) }, @@ -154,11 +137,8 @@ pub fn run(cmd_config: RunConfig) -> Result<() Some(Subcommand::ExportGenesisHead(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { - let node = new_node_spec( - &config, - cmd_config.runtime_resolver.as_ref(), - &cli.node_extra_args(), - )?; + let node = + new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?; node.run_export_genesis_head_cmd(config, cmd) }) }, @@ -183,7 +163,7 @@ pub fn run(cmd_config: RunConfig) -> Result<() BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { let node = new_node_spec( &config, - cmd_config.runtime_resolver.as_ref(), + &cmd_config.runtime_resolver, &cli.node_extra_args(), )?; node.run_benchmark_block_cmd(config, cmd) @@ -192,7 +172,7 @@ pub fn run(cmd_config: RunConfig) -> Result<() BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let node = new_node_spec( &config, - cmd_config.runtime_resolver.as_ref(), + &cmd_config.runtime_resolver, &cli.node_extra_args(), )?; node.run_benchmark_storage_cmd(config, cmd) @@ -282,7 +262,7 @@ pub fn run(cmd_config: RunConfig) -> Result<() start_node( config, - cmd_config.runtime_resolver.as_ref(), + &cmd_config.runtime_resolver, polkadot_config, collator_options, id, @@ -298,7 +278,7 @@ pub fn run(cmd_config: RunConfig) -> Result<() #[sc_tracing::logging::prefix_logs_with("Parachain")] async fn start_node( config: sc_service::Configuration, - runtime_resolver: Option<&Box>, + runtime_resolver: &Box, polkadot_config: sc_service::Configuration, collator_options: cumulus_client_cli::CollatorOptions, id: ParaId, diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs index b20deea1618a..974d6ef2b611 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/chain_spec.rs @@ -22,11 +22,20 @@ use serde::{Deserialize, Serialize}; use std::fmt::Debug; /// Helper trait used for loading/building a chain spec starting from the chain ID. -pub trait LoadSpec: Debug { +pub trait LoadSpec { /// Load/Build a chain spec starting from the chain ID. fn load_spec(&self, id: &str) -> Result, String>; } +/// Default implementation for `LoadSpec` that just reads a chain spec from the disk. +pub struct DiskChainSpecLoader; + +impl LoadSpec for DiskChainSpecLoader { + fn load_spec(&self, path: &str) -> Result, String> { + Ok(Box::new(GenericChainSpec::from_json_file(path.into())?)) + } +} + /// Generic extensions for Parachain ChainSpecs. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecExtension)] pub struct Extensions { diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs index 5576e05cd34d..c64eda12d5ef 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs @@ -17,10 +17,9 @@ //! Runtime parameters. use sc_chain_spec::ChainSpec; -use std::fmt::Debug; /// The Aura ID used by the Aura consensus -#[derive(Debug, PartialEq)] +#[derive(PartialEq)] pub enum AuraConsensusId { /// Ed25519 Ed25519, @@ -29,14 +28,14 @@ pub enum AuraConsensusId { } /// The choice of consensus for the parachain omni-node. -#[derive(Debug, PartialEq)] +#[derive(PartialEq)] pub enum Consensus { /// Aura consensus. Aura(AuraConsensusId), } /// Helper enum listing the supported Runtime types -#[derive(Debug, PartialEq)] +#[derive(PartialEq)] pub enum Runtime { /// None of the system-chain runtimes, rather the node will act agnostic to the runtime ie. be /// an omni-node, and simply run a node with the given consensus algorithm. @@ -46,7 +45,17 @@ pub enum Runtime { } /// Helper trait used for extracting the Runtime variant from the chain spec ID. -pub trait RuntimeResolver: Debug { +pub trait RuntimeResolver { /// Extract the Runtime variant from the chain spec ID. fn runtime(&self, chain_spec: &dyn ChainSpec) -> sc_cli::Result; } + +/// Default implementation for `RuntimeResolver` that just returns +/// `Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519))`. +pub struct DefaultRuntimeResolver; + +impl RuntimeResolver for DefaultRuntimeResolver { + fn runtime(&self, _chain_spec: &dyn ChainSpec) -> sc_cli::Result { + Ok(Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519))) + } +} diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index 46ec36c9fa84..de9c6a889ed0 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -309,9 +309,9 @@ impl RuntimeResolverT for RuntimeResolver { LegacyRuntime::People(_) | LegacyRuntime::ContractsRococo | LegacyRuntime::Glutton | - LegacyRuntime::Penpal => Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519)), - LegacyRuntime::Shell | LegacyRuntime::Seedling => Runtime::Shell, + LegacyRuntime::Penpal | LegacyRuntime::Omni => Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519)), + LegacyRuntime::Shell | LegacyRuntime::Seedling => Runtime::Shell, }) } } diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index 9dd1b5f585b8..f2dce552c51a 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -47,8 +47,8 @@ fn main() -> color_eyre::eyre::Result<()> { color_eyre::install()?; let config = RunConfig { - chain_spec_loader: Some(Box::new(chain_spec::ChainSpecLoader)), - runtime_resolver: Some(Box::new(chain_spec::RuntimeResolver)), + chain_spec_loader: Box::new(chain_spec::ChainSpecLoader), + runtime_resolver: Box::new(chain_spec::RuntimeResolver), }; Ok(run::(config)?) }