Skip to content

Commit

Permalink
Only one ParaId variable in the Parachain Template (#6744)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shawntabrizi authored Dec 13, 2024
1 parent 6d92ded commit 482bf08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
14 changes: 4 additions & 10 deletions templates/parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions templates/parachain/runtime/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
1 change: 1 addition & 0 deletions templates/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit 482bf08

Please sign in to comment.