From 482bf08290c2ff2812eb1235f551740f0e6576df Mon Sep 17 00:00:00 2001
From: Shawn Tabrizi <shawntabrizi@gmail.com>
Date: Fri, 13 Dec 2024 10:07:58 -0500
Subject: [PATCH] Only one ParaId variable in the Parachain Template (#6744)

Many problems can occur when building and testing a Parachain caused by
misconfiguring the paraid.

This can happen when there are 3 different places you need to update!

This PR makes it so a SINGLE location is the source of truth for the
ParaId.
---
 templates/parachain/node/src/chain_spec.rs         | 14 ++++----------
 .../runtime/src/genesis_config_presets.rs          |  4 ++--
 templates/parachain/runtime/src/lib.rs             |  1 +
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/templates/parachain/node/src/chain_spec.rs b/templates/parachain/node/src/chain_spec.rs
index 7ae3c4900e4..d4b3a41b896 100644
--- a/templates/parachain/node/src/chain_spec.rs
+++ b/templates/parachain/node/src/chain_spec.rs
@@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
 
 /// Specialized `ChainSpec` for the normal parachain runtime.
 pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
+/// The relay chain that you want to configure this parachain to connect to.
+pub const RELAY_CHAIN: &str = "rococo-local";
 
 /// The extensions for the [`ChainSpec`].
 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
@@ -35,11 +37,7 @@ pub fn development_chain_spec() -> ChainSpec {
 
 	ChainSpec::builder(
 		runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
-		Extensions {
-			relay_chain: "rococo-local".into(),
-			// You MUST set this to the correct network!
-			para_id: 1000,
-		},
+		Extensions { relay_chain: RELAY_CHAIN.into(), para_id: runtime::PARACHAIN_ID },
 	)
 	.with_name("Development")
 	.with_id("dev")
@@ -59,11 +57,7 @@ pub fn local_chain_spec() -> ChainSpec {
 	#[allow(deprecated)]
 	ChainSpec::builder(
 		runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
-		Extensions {
-			relay_chain: "rococo-local".into(),
-			// You MUST set this to the correct network!
-			para_id: 1000,
-		},
+		Extensions { relay_chain: RELAY_CHAIN.into(), para_id: runtime::PARACHAIN_ID },
 	)
 	.with_name("Local Testnet")
 	.with_id("local_testnet")
diff --git a/templates/parachain/runtime/src/genesis_config_presets.rs b/templates/parachain/runtime/src/genesis_config_presets.rs
index aa1ff7895eb..f1b24e43724 100644
--- a/templates/parachain/runtime/src/genesis_config_presets.rs
+++ b/templates/parachain/runtime/src/genesis_config_presets.rs
@@ -16,8 +16,8 @@ use sp_keyring::Sr25519Keyring;
 
 /// The default XCM version to set in genesis config.
 const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
-/// Parachain id used for gensis config presets of parachain template.
-const PARACHAIN_ID: u32 = 1000;
+/// Parachain id used for genesis config presets of parachain template.
+pub const PARACHAIN_ID: u32 = 1000;
 
 /// Generate the session keys from individual elements.
 ///
diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs
index 43e76dba059..9669237af78 100644
--- a/templates/parachain/runtime/src/lib.rs
+++ b/templates/parachain/runtime/src/lib.rs
@@ -33,6 +33,7 @@ use frame_support::weights::{
 	constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
 	WeightToFeePolynomial,
 };
+pub use genesis_config_presets::PARACHAIN_ID;
 pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
 pub use sp_runtime::{MultiAddress, Perbill, Permill};
 
-- 
GitLab