diff --git a/cumulus/polkadot-omni-node/README.md b/cumulus/polkadot-omni-node/README.md index 0d3fdaaf4c2fe..9031ec375dee3 100644 --- a/cumulus/polkadot-omni-node/README.md +++ b/cumulus/polkadot-omni-node/README.md @@ -46,11 +46,11 @@ local variants are available only for a build of `polkadot-omni-node` with `westend-native` and `rococo-native` features respectively. - -Additionaly, although deprecated, the `--para-id` flag can still be used to set the JSON key named -`para_id`. The removal of the flag will happen starting with `stable2512`. The alternative of not using -it is to implement the `cumulus_primitives_core::GetParachainInfo` runtime API for the runtime, and -upgrade it on-chain as well, to be compatible with nodes released starting with `stable2512`. +Additionaly, the `--para-id` flag can be used to set the JSON key named `para_id`. This flag is used +by nodes to determine the parachain id, and it is especially useful when the parachain id can not be +fetched from the runtime, when the state points to a runtime that does not implement the +`cumulus_primitives_core::GetParachainInfo` runtime API. It is recommended for runtimes to implement +the runtime API and be upgraded on chain. Example command bellow: diff --git a/cumulus/polkadot-omni-node/lib/src/cli.rs b/cumulus/polkadot-omni-node/lib/src/cli.rs index 5f9f949ce7268..af9f6c00dd7d8 100644 --- a/cumulus/polkadot-omni-node/lib/src/cli.rs +++ b/cumulus/polkadot-omni-node/lib/src/cli.rs @@ -316,7 +316,7 @@ impl RelayChainCli { 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 chain_id = extension.map(|e| e.relay_chain()); let base_path = para_config.base_path.path().join("polkadot"); Self { base, chain_id, base_path: Some(base_path), _phantom: Default::default() } diff --git a/cumulus/polkadot-omni-node/lib/src/common/chain_spec.rs b/cumulus/polkadot-omni-node/lib/src/common/chain_spec.rs index 7107045c0f407..2a55d75785238 100644 --- a/cumulus/polkadot-omni-node/lib/src/common/chain_spec.rs +++ b/cumulus/polkadot-omni-node/lib/src/common/chain_spec.rs @@ -32,59 +32,52 @@ pub struct DiskChainSpecLoader; impl LoadSpec for DiskChainSpecLoader { fn load_spec(&self, path: &str) -> Result, String> { - Ok(Box::new(DeprecatedGenericChainSpec::from_json_file(path.into())?)) - } -} - -/// Generic extensions for Parachain ChainSpecs. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecExtension)] -pub struct Extensions { - /// The relay chain of the Parachain. - #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, -} - -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()) + Ok(Box::new(GenericChainSpec::from_json_file(path.into())?)) } } /// Generic extensions for Parachain ChainSpecs used for extracting the extensions from chain specs. -/// This is also used only while `para_id` is around the corner. -// TODO: https://github.com/paritytech/polkadot-sdk/issues/8747 -// TODO: https://github.com/paritytech/polkadot-sdk/issues/8740 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecExtension)] -pub struct DeprecatedExtensions { +pub struct Extensions { /// The relay chain of the Parachain. It is kept here only for compatibility reasons until /// people migrate to using the new `Extensions` struct and associated logic in the node /// corresponding to pulling the parachain id from the runtime. #[serde(alias = "relayChain", alias = "RelayChain")] - pub relay_chain: String, + relay_chain: String, /// The id of the Parachain. #[serde(alias = "paraId", alias = "ParaId")] - #[deprecated( - note = "The para_id information is not required anymore and will be removed starting with `stable2512`. Runtimes must implement a new API called `cumulus_primitives_core::GetParachainInfo` to still be compatible with node versions starting with `stable2512`." - )] - pub para_id: Option, + para_id: Option, } -impl DeprecatedExtensions { +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()) } + + /// Create the extensions only with the relay_chain. + pub fn new_with_relay_chain(relay_chain: String) -> Self { + Extensions { relay_chain, para_id: None } + } + + /// Initialize extensions based on given parameters. + pub fn new(relay_chain: String, para_id: u32) -> Self { + Extensions { relay_chain, para_id: Some(para_id) } + } + + /// Para id field getter + pub fn para_id(&self) -> Option { + self.para_id + } + + /// Relay chain field getter + pub fn relay_chain(&self) -> String { + self.relay_chain.clone() + } } /// Generic chain spec for all polkadot-parachain runtimes pub type GenericChainSpec = sc_service::GenericChainSpec; -/// Generic chain spec which keeps chain spec loading compatible for those who provide -/// `para_id` extension instead of implementing the runtime API -/// `cumulus_primitives_core::GetParachainInfo`. -// TODO: https://github.com/paritytech/polkadot-sdk/issues/8747 -// TODO: https://github.com/paritytech/polkadot-sdk/issues/8740 -pub type DeprecatedGenericChainSpec = sc_service::GenericChainSpec; #[cfg(test)] mod tests { @@ -97,21 +90,13 @@ mod tests { let pascal_case = r#"{"RelayChain":"relay","ParaId":1}"#; let para_id_missing = r#"{"RelayChain":"westend"}"#; - let camel_case_extension: DeprecatedExtensions = serde_json::from_str(camel_case).unwrap(); - let snake_case_extension: DeprecatedExtensions = serde_json::from_str(snake_case).unwrap(); - let pascal_case_extension: DeprecatedExtensions = - serde_json::from_str(pascal_case).unwrap(); + 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 missing_paraid_extension: Extensions = serde_json::from_str(para_id_missing).unwrap(); - let missing_paraid_deprecated: DeprecatedExtensions = - serde_json::from_str(para_id_missing).unwrap(); assert_eq!(camel_case_extension, snake_case_extension); assert_eq!(snake_case_extension, pascal_case_extension); assert_eq!(missing_paraid_extension.relay_chain, "westend".to_string()); - - // TODO: remove it once `para_id` is removed: https://github.com/paritytech/polkadot-sdk/issues/8740 - assert_eq!(missing_paraid_deprecated.relay_chain, "westend".to_string()); - #[allow(deprecated)] - let test = missing_paraid_deprecated.para_id.is_none(); - assert!(test); + assert!(missing_paraid_extension.para_id.is_none()); } } diff --git a/cumulus/polkadot-omni-node/lib/src/common/spec.rs b/cumulus/polkadot-omni-node/lib/src/common/spec.rs index 5331c7b461031..f0d4cc0e0a88d 100644 --- a/cumulus/polkadot-omni-node/lib/src/common/spec.rs +++ b/cumulus/polkadot-omni-node/lib/src/common/spec.rs @@ -15,7 +15,7 @@ // limitations under the License. use crate::{ - chain_spec::DeprecatedExtensions, + chain_spec::Extensions, common::{ command::NodeCommandRunner, rpc::BuildRpcExtensions, @@ -51,7 +51,7 @@ use sc_telemetry::{TelemetryHandle, TelemetryWorker}; use sc_tracing::tracing::Instrument; use sc_transaction_pool::TransactionPoolHandle; use sc_transaction_pool_api::OffchainTransactionPoolFactory; -use sp_api::ProvideRuntimeApi; +use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_keystore::KeystorePtr; use sp_runtime::traits::AccountIdConversion; use std::{future::Future, pin::Pin, sync::Arc, time::Duration}; @@ -157,19 +157,27 @@ pub(crate) trait BaseNodeSpec { parachain_config: &Configuration, ) -> Option { let best_hash = client.chain_info().best_hash; - let para_id = if let Ok(para_id) = client.runtime_api().parachain_id(best_hash) { - para_id + let para_id = if client + .runtime_api() + .has_api::>(best_hash) + .ok() + .filter(|has_api| *has_api) + .is_some() + { + client + .runtime_api() + .parachain_id(best_hash) + .inspect_err(|err| { + log::error!( + "`cumulus_primitives_core::GetParachainInfo` runtime API call errored with {}", + err + ); + }) + .ok()? } else { - // TODO: remove this once `para_id` extension is removed: https://github.com/paritytech/polkadot-sdk/issues/8740 - #[allow(deprecated)] - let id = ParaId::from( - DeprecatedExtensions::try_get(&*parachain_config.chain_spec) - .and_then(|ext| ext.para_id)?, - ); - // TODO: https://github.com/paritytech/polkadot-sdk/issues/8747 - // TODO: https://github.com/paritytech/polkadot-sdk/issues/8740 - log::info!("Deprecation notice: the parachain id was provided via the chain spec. This way of providing the parachain id to the node is not recommended. The alternative is to implement the `cumulus_primitives_core::GetParachainInfo` runtime API in the runtime, and upgrade it on-chain. Starting with `stable2512` providing the parachain id via the chain spec will not be supported anymore."); - id + ParaId::from( + Extensions::try_get(&*parachain_config.chain_spec).and_then(|ext| ext.para_id())?, + ) }; let parachain_account = diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index ead445979bf1a..adae8dc30962f 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -25,7 +25,7 @@ pub fn asset_hub_westend_development_config() -> GenericChainSpec { GenericChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend".into() }, + Extensions::new_with_relay_chain("westend".into()), ) .with_name("Westend Asset Hub Development") .with_id("asset-hub-westend-dev") @@ -43,7 +43,7 @@ pub fn asset_hub_westend_local_config() -> GenericChainSpec { GenericChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend-local".into() }, + Extensions::new_with_relay_chain("westend-local".into()), ) .with_name("Westend Asset Hub Local") .with_id("asset-hub-westend-local") @@ -61,7 +61,7 @@ pub fn asset_hub_westend_config() -> GenericChainSpec { GenericChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend".into() }, + Extensions::new_with_relay_chain("westend".into()), ) .with_name("Westend Asset Hub") .with_id("asset-hub-westend") @@ -80,7 +80,6 @@ pub fn asset_hub_rococo_development_config() -> GenericChainSpec { properties, "Rococo Asset Hub Development", "asset-hub-rococo-dev", - 1000, ) } @@ -88,21 +87,15 @@ fn asset_hub_rococo_like_development_config( properties: sc_chain_spec::Properties, name: &str, chain_id: &str, - para_id: u32, ) -> GenericChainSpec { GenericChainSpec::builder( asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-dev".into() }, + Extensions::new_with_relay_chain("rococo-dev".into()), ) .with_name(name) .with_id(chain_id) .with_chain_type(ChainType::Local) .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .with_properties(properties) .build() } @@ -116,7 +109,6 @@ pub fn asset_hub_rococo_local_config() -> GenericChainSpec { properties, "Rococo Asset Hub Local", "asset-hub-rococo-local", - 1000, ) } @@ -124,21 +116,15 @@ fn asset_hub_rococo_like_local_config( properties: sc_chain_spec::Properties, name: &str, chain_id: &str, - para_id: u32, ) -> GenericChainSpec { GenericChainSpec::builder( asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-local".into() }, + Extensions::new_with_relay_chain("rococo-local".into()), ) .with_name(name) .with_id(chain_id) .with_chain_type(ChainType::Local) .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .with_properties(properties) .build() } @@ -149,7 +135,7 @@ pub fn asset_hub_rococo_genesis_config() -> GenericChainSpec { properties.insert("tokenDecimals".into(), 12.into()); GenericChainSpec::builder( asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo".into() }, + Extensions::new_with_relay_chain("rococo".into()), ) .with_name("Rococo Asset Hub") .with_id("asset-hub-rococo") diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 2adeaf2c99215..4927dcba7be05 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -14,7 +14,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use cumulus_primitives_core::ParaId; use polkadot_omni_node_lib::chain_spec::GenericChainSpec; use sc_chain_spec::{ChainSpec, ChainType}; use std::str::FromStr; @@ -77,14 +76,12 @@ impl BridgeHubRuntimeType { westend::BRIDGE_HUB_WESTEND_LOCAL, "Westend BridgeHub Local", "westend-local", - ParaId::new(1002), ChainType::Local, ))), BridgeHubRuntimeType::WestendDevelopment => Ok(Box::new(westend::local_config( westend::BRIDGE_HUB_WESTEND_DEVELOPMENT, "Westend BridgeHub Development", "westend-dev", - ParaId::new(1002), ChainType::Development, ))), BridgeHubRuntimeType::Rococo => Ok(Box::new(GenericChainSpec::from_json_bytes( @@ -94,7 +91,6 @@ impl BridgeHubRuntimeType { rococo::BRIDGE_HUB_ROCOCO_LOCAL, "Rococo BridgeHub Local", "rococo-local", - ParaId::new(1013), |_| (), ChainType::Local, ))), @@ -102,7 +98,6 @@ impl BridgeHubRuntimeType { rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT, "Rococo BridgeHub Development", "rococo-dev", - ParaId::new(1013), |_| (), ChainType::Development, ))), @@ -126,7 +121,7 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup pub mod rococo { - use super::{ChainType, ParaId}; + use super::ChainType; use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; pub(crate) const BRIDGE_HUB_ROCOCO: &str = "bridge-hub-rococo"; @@ -137,7 +132,6 @@ pub mod rococo { id: &str, chain_name: &str, relay_chain: &str, - para_id: ParaId, modify_props: ModifyProperties, chain_type: ChainType, ) -> GenericChainSpec { @@ -151,7 +145,7 @@ pub mod rococo { GenericChainSpec::builder( bridge_hub_rococo_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay_chain.to_string() }, + Extensions::new_with_relay_chain(relay_chain.to_string()), ) .with_name(chain_name) .with_id(super::ensure_id(id).expect("invalid id")) @@ -161,11 +155,6 @@ pub mod rococo { ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, _ => panic!("chain_type: {chain_type:?} not supported here!"), }) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .with_properties(properties) .build() } @@ -179,7 +168,7 @@ pub mod kusama { /// Sub-module for Westend setup. pub mod westend { - use super::{ChainType, ParaId}; + use super::ChainType; use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; pub(crate) const BRIDGE_HUB_WESTEND: &str = "bridge-hub-westend"; @@ -190,7 +179,6 @@ pub mod westend { id: &str, chain_name: &str, relay_chain: &str, - para_id: ParaId, chain_type: ChainType, ) -> GenericChainSpec { let mut properties = sc_chain_spec::Properties::new(); @@ -200,7 +188,7 @@ pub mod westend { GenericChainSpec::builder( bridge_hub_westend_runtime::WASM_BINARY .expect("WASM binary was not build, please build it!"), - Extensions { relay_chain: relay_chain.to_string() }, + Extensions::new_with_relay_chain(relay_chain.to_string()), ) .with_name(chain_name) .with_id(super::ensure_id(id).expect("invalid id")) @@ -210,11 +198,6 @@ pub mod westend { ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, _ => panic!("chain_type: {chain_type:?} not supported here!"), }) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .with_properties(properties) .build() } diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index 5d2d57224f7b1..1e9a4489c99b0 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -27,7 +27,7 @@ pub fn collectives_westend_development_config() -> GenericChainSpec { GenericChainSpec::builder( collectives_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend-dev".into() }, + Extensions::new_with_relay_chain("westend-dev".into()), ) .with_name("Westend Collectives Development") .with_id("collectives_westend_dev") @@ -48,7 +48,7 @@ pub fn collectives_westend_local_config() -> GenericChainSpec { GenericChainSpec::builder( collectives_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend-local".into() }, + Extensions::new_with_relay_chain("westend-local".into()), ) .with_name("Westend Collectives Local") .with_id("collectives_westend_local") diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index 47cc66bdd4eca..e5cc4891d1f02 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -168,17 +168,20 @@ pub mod rococo { .expect("WASM binary was not built, please build it!") }; - GenericChainSpec::builder(wasm_binary, Extensions { relay_chain: relay_chain.to_string() }) - .with_name(&chain_name) - .with_id(runtime_type.into()) - .with_chain_type(chain_type.clone()) - .with_genesis_config_preset_name(match chain_type { - ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET, - ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, - _ => panic!("chain_type: {chain_type:?} not supported here!"), - }) - .with_properties(properties) - .build() + GenericChainSpec::builder( + wasm_binary, + Extensions::new_with_relay_chain(relay_chain.to_string()), + ) + .with_name(&chain_name) + .with_id(runtime_type.into()) + .with_chain_type(chain_type.clone()) + .with_genesis_config_preset_name(match chain_type { + ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET, + ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, + _ => panic!("chain_type: {chain_type:?} not supported here!"), + }) + .with_properties(properties) + .build() } } @@ -205,7 +208,7 @@ pub mod westend { GenericChainSpec::builder( coretime_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay_chain.to_string() }, + Extensions::new_with_relay_chain(relay_chain.to_string()), ) .with_name(&chain_name) .with_id(runtime_type.into()) diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index 346075207836c..71f12ca3af969 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -29,7 +29,7 @@ pub fn glutton_westend_config( GenericChainSpec::builder( glutton_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay_chain.into() }, + Extensions::new_with_relay_chain(relay_chain.into()), ) .with_name(&chain_type_name(para_id, &chain_type)) .with_id(&chain_id(para_id, &chain_type)) @@ -39,11 +39,6 @@ pub fn glutton_westend_config( ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, _ => panic!("chain_type: {chain_type:?} not supported here!"), }) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .build() } diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index c82f5c57f4b15..2d9cda5b68f42 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -27,9 +27,7 @@ pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> GenericChainSpec GenericChainSpec::builder( penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { - relay_chain: relay_chain.into(), // You MUST set this to the correct network! - }, + Extensions::new_with_relay_chain(relay_chain.into()), ) .with_name("Penpal Parachain") .with_id(&format!("penpal-{}", relay_chain.replace("-local", ""))) diff --git a/cumulus/polkadot-parachain/src/chain_spec/people.rs b/cumulus/polkadot-parachain/src/chain_spec/people.rs index fcd25d8127dbd..6735a15973df9 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/people.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/people.rs @@ -14,7 +14,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use cumulus_primitives_core::ParaId; use polkadot_omni_node_lib::chain_spec::GenericChainSpec; use sc_chain_spec::{ChainSpec, ChainType}; use std::str::FromStr; @@ -72,14 +71,12 @@ impl PeopleRuntimeType { rococo::PEOPLE_ROCOCO_LOCAL, "Rococo People Local", "rococo-local", - ParaId::new(1004), ChainType::Local, ))), PeopleRuntimeType::RococoDevelopment => Ok(Box::new(rococo::local_config( rococo::PEOPLE_ROCOCO_DEVELOPMENT, "Rococo People Development", "rococo-development", - ParaId::new(1004), ChainType::Development, ))), PeopleRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes( @@ -89,14 +86,12 @@ impl PeopleRuntimeType { westend::PEOPLE_WESTEND_LOCAL, "Westend People Local", "westend-local", - ParaId::new(1004), ChainType::Local, ))), PeopleRuntimeType::WestendDevelopment => Ok(Box::new(westend::local_config( westend::PEOPLE_WESTEND_DEVELOPMENT, "Westend People Development", "westend-development", - ParaId::new(1004), ChainType::Development, ))), other => Err(std::format!( @@ -122,7 +117,6 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup. pub mod rococo { - use super::ParaId; use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; @@ -131,10 +125,9 @@ pub mod rococo { pub(crate) const PEOPLE_ROCOCO_DEVELOPMENT: &str = "people-rococo-dev"; pub fn local_config( - id: &str, + spec_id: &str, chain_name: &str, relay_chain: &str, - para_id: ParaId, chain_type: ChainType, ) -> GenericChainSpec { let mut properties = sc_chain_spec::Properties::new(); @@ -145,21 +138,16 @@ pub mod rococo { GenericChainSpec::builder( people_rococo_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay_chain.to_string() }, + Extensions::new_with_relay_chain(relay_chain.to_string()), ) .with_name(chain_name) - .with_id(super::ensure_id(id).expect("invalid id")) + .with_id(super::ensure_id(spec_id).expect("invalid id")) .with_chain_type(chain_type.clone()) .with_genesis_config_preset_name(match chain_type { ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET, ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, _ => panic!("chain_type: {chain_type:?} not supported here!"), }) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .with_properties(properties) .build() } @@ -167,7 +155,6 @@ pub mod rococo { /// Sub-module for Westend setup. pub mod westend { - use super::ParaId; use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; @@ -176,10 +163,9 @@ pub mod westend { pub(crate) const PEOPLE_WESTEND_DEVELOPMENT: &str = "people-westend-dev"; pub fn local_config( - id: &str, + spec_id: &str, chain_name: &str, relay_chain: &str, - para_id: ParaId, chain_type: ChainType, ) -> GenericChainSpec { let mut properties = sc_chain_spec::Properties::new(); @@ -190,21 +176,16 @@ pub mod westend { GenericChainSpec::builder( people_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay_chain.to_string() }, + Extensions::new_with_relay_chain(relay_chain.to_string()), ) .with_name(chain_name) - .with_id(super::ensure_id(id).expect("invalid id")) + .with_id(super::ensure_id(spec_id).expect("invalid id")) .with_chain_type(chain_type.clone()) .with_genesis_config_preset_name(match chain_type { ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET, ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, _ => panic!("chain_type: {chain_type:?} not supported here!"), }) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { - "parachainId": para_id, - }, - })) .with_properties(properties) .build() } diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index 8d2dca95f111c..dc6a3b6666277 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -27,7 +27,7 @@ use sp_core::crypto::UncheckedInto; pub fn rococo_parachain_local_config() -> GenericChainSpec { GenericChainSpec::builder( rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-local".into() }, + Extensions::new_with_relay_chain("rococo-local".into()), ) .with_name("Rococo Parachain Local") .with_id("local_testnet") @@ -39,7 +39,7 @@ pub fn rococo_parachain_local_config() -> GenericChainSpec { pub fn staging_rococo_parachain_local_config() -> GenericChainSpec { GenericChainSpec::builder( rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-local".into() }, + Extensions::new_with_relay_chain("rococo-local".into()), ) .with_name("Staging Rococo Parachain Local") .with_id("staging_testnet") diff --git a/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs index fb1a6adfcdf2f..3905f8d62b7a0 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs @@ -86,7 +86,7 @@ pub fn yet_another_parachain_config( GenericChainSpec::builder( yet_another_parachain_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay.into() }, + Extensions::new_with_relay_chain(relay.into()), ) .with_name("Yet Another Parachain") .with_id("yet_another_parachain") diff --git a/prdoc/pr_9201.prdoc b/prdoc/pr_9201.prdoc new file mode 100644 index 0000000000000..c08444c78683d --- /dev/null +++ b/prdoc/pr_9201.prdoc @@ -0,0 +1,16 @@ +title: '`polkadot-parachain`: fixes and changes related to GetParachainInfo' +doc: +- audience: Node Dev + description: |- + - Provides some updated to the asset-hub-westend-local chain specification, by adding appropriate genesis patch for parachainInfo. + - refactors the logic related to fetching `para_id` with the node, so that when failing to use `GetParachainInfo::parachain_id` we also get a log with the error (before defaulting to `para_id` extracted from chain spec). + - removes comments/deprecation notices throughout the code that introduce para-id flag removal (from chain-spec-builder and support for parsing it from chain specifications) +crates: +- name: polkadot-parachain-bin + bump: patch +- name: polkadot-omni-node-lib + bump: major +- name: polkadot-omni-node + bump: patch +- name: staging-chain-spec-builder + bump: patch diff --git a/substrate/bin/utils/chain-spec-builder/README.docify.md b/substrate/bin/utils/chain-spec-builder/README.docify.md index 091814bdc8043..1b0f78d278c55 100644 --- a/substrate/bin/utils/chain-spec-builder/README.docify.md +++ b/substrate/bin/utils/chain-spec-builder/README.docify.md @@ -26,18 +26,19 @@ _Note:_ `chain-spec-builder` binary is published on [crates.io](https://crates.i Please note that below usage is backed by integration tests. The commands' examples are wrapped around by the `bash!(...)` macro calls. - -### Deprecation notice for `CreateCmd`'s `para-id` flag +### Note for `CreateCmd`'s `para-id` flag -`para-id` flag is deprecated. Runtimes relying on generating the chain -specification with this tool should implement `cumulus_primitives_core::GetParachainInfo` -trait, a new runtime API designed to provide the parachain ID from the `parachain-info` -pallet. The `para-id` flag will be removed and nodes support for extracting the -parachain id from the chain specification will stop from `stable2512`. - -For reference, generating a chain specification with a `para_id` field can still -be done until `stable2512` like below: +Runtimes relying on generating the chain specification with this tool should +implement `cumulus_primitives_core::GetParachainInfo` trait, a new runtime API +designed to provide the parachain ID from the `parachain-info` +pallet. The `para-id` flag can be used though if the runtime does not implement +the runtime API, and the parachain id will be fetched by the node from chain +specification. This can be especially useful when syncing a node from a state +where the runtime does not implement `cumulus_primitives_core::GetParachainInfo`. + +For reference, generating a chain specification with a `para_id` field can be +done like below: ```bash chain-spec-builder -c "/dev/stdout" create --relay-chain "dev" --para-id 1000 -r $runtime_path named-preset "staging" diff --git a/substrate/bin/utils/chain-spec-builder/README.md b/substrate/bin/utils/chain-spec-builder/README.md index 509b0fe03bee4..31e8430776497 100644 --- a/substrate/bin/utils/chain-spec-builder/README.md +++ b/substrate/bin/utils/chain-spec-builder/README.md @@ -26,18 +26,19 @@ _Note:_ `chain-spec-builder` binary is published on [crates.io](https://crates.i Please note that below usage is backed by integration tests. The commands' examples are wrapped around by the `bash!(...)` macro calls. - -### Deprecation notice for `CreateCmd`'s `para-id` flag +### Note for `CreateCmd`'s `para-id` flag -`para-id` flag is deprecated. Runtimes relying on generating the chain -specification with this tool should implement `cumulus_primitives_core::GetParachainInfo` -trait, a new runtime API designed to provide the parachain ID from the `parachain-info` -pallet. The `para-id` flag will be removed and nodes support for extracting the -parachain id from the chain specification will stop from `stable2512`. - -For reference, generating a chain specification with a `para_id` field can still -be done until `stable2512` like below: +Runtimes relying on generating the chain specification with this tool should +implement `cumulus_primitives_core::GetParachainInfo` trait, a new runtime API +designed to provide the parachain ID from the `parachain-info` +pallet. The `para-id` flag can be used though if the runtime does not implement +the runtime API, and the parachain id will be fetched by the node from chain +specification. This can be especially useful when syncing a node from a state +where the runtime does not implement `cumulus_primitives_core::GetParachainInfo`. + +For reference, generating a chain specification with a `para_id` field can be +done like below: ```bash chain-spec-builder -c "/dev/stdout" create --relay-chain "dev" --para-id 1000 -r $runtime_path named-preset "staging" diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 69986aea80737..116f90d31931e 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -67,17 +67,8 @@ pub struct CreateCmd { /// The chain type. #[arg(value_enum, short = 't', default_value = "live")] chain_type: ChainType, - /// DEPRECATED: The para ID for your chain. - /// - /// This flag will be removed starting with `stable2512`. Runtimes must implement a new API - /// called `cumulus_primitives_core::GetParachainInfo` to still be compatible with node - /// versions starting with `stable2512`. - // TODO: https://github.com/paritytech/polkadot-sdk/issues/8747 - // TODO: https://github.com/paritytech/polkadot-sdk/issues/8740 + /// The para ID for your chain. #[arg(long, value_enum, short = 'p', requires = "relay_chain")] - #[deprecated( - note = "The para_id information is not required anymore and will be removed starting with `stable2512`. Runtimes must implement a new API called `cumulus_primitives_core::GetParachainInfo` to still be compatible with node versions starting with `stable2512`." - )] pub para_id: Option, /// The relay chain you wish to connect to. #[arg(long, value_enum, short = 'c')] @@ -226,11 +217,6 @@ pub struct ParachainExtension { /// The relay chain of the Parachain. pub relay_chain: String, /// The id of the Parachain. - // TODO: https://github.com/paritytech/polkadot-sdk/issues/8747 --> - // TODO: https://github.com/paritytech/polkadot-sdk/issues/8740 --> - #[deprecated( - note = "The para_id information is not required anymore and will be removed starting with `stable2512`. Runtimes must implement a new API called `cumulus_primitives_core::GetParachainInfo` to still be compatible with node versions starting with `stable2512`." - )] pub para_id: Option, } @@ -458,12 +444,8 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result - eprintln!("Note: usage of deprecated `para-id` flag is not recommended. Please consider implementing the `cumulus_primitives_core::GetParachainInfo` runtime API for your runtime. The `para-id` flag will be removed starting with `stable2512`."); serde_json::json!({ "relay_chain": rc, "para_id": para_id,