Skip to content

Commit

Permalink
make polkadot-parachain chain-spec extension more relaxed (paritytech…
Browse files Browse the repository at this point in the history
…#4452)

A small step towards
https://forum.polkadot.network/t/polkadot-parachain-omni-node-gathering-ideas-and-feedback/7823
and paritytech#4352.

Many parachains use `camelCase` and/or `PascalCase`ing for their chain
spec extension. Sometimes the only reason polkadot-parachain cannot sync
them is because it cannot parse the chain spec extension. This PR
relaxes the requirement for the extension to be camel case.

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
  • Loading branch information
2 people authored and TarekkMA committed Aug 2, 2024
1 parent e26eb49 commit fa2aeaf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cumulus/polkadot-parachain/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

/// Generic extensions for Parachain ChainSpecs.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
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,
}

Expand Down Expand Up @@ -78,3 +79,22 @@ where
pub fn get_collator_keys_from_seed<AuraId: Public>(seed: &str) -> <AuraId::Pair as Pair>::Public {
get_from_seed::<AuraId>(seed)
}

#[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);
}
}
3 changes: 2 additions & 1 deletion templates/parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
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,
}

Expand Down

0 comments on commit fa2aeaf

Please sign in to comment.